freedreno: Use explicit *_NONE enum for undefined formats
authorKristian H. Kristensen <hoegsberg@google.com>
Fri, 22 May 2020 20:36:38 +0000 (13:36 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 26 May 2020 18:35:03 +0000 (18:35 +0000)
This adds RB, VFMT and TFMT NONE values for a3xx-a5xx and FMT6_NONE
for a6xx.  Use those values instead of open coded (enum xxx) ~0 or
sometimes even ~0, which triggers out-of-enum range warnings.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5173>

20 files changed:
src/freedreno/registers/a3xx.xml
src/freedreno/registers/a4xx.xml
src/freedreno/registers/a5xx.xml
src/freedreno/registers/a6xx.xml
src/freedreno/vulkan/tu_formats.c
src/gallium/drivers/freedreno/a2xx/fd2_util.h
src/gallium/drivers/freedreno/a3xx/fd3_emit.c
src/gallium/drivers/freedreno/a3xx/fd3_format.c
src/gallium/drivers/freedreno/a3xx/fd3_resource.c
src/gallium/drivers/freedreno/a3xx/fd3_screen.c
src/gallium/drivers/freedreno/a4xx/fd4_emit.c
src/gallium/drivers/freedreno/a4xx/fd4_format.c
src/gallium/drivers/freedreno/a5xx/fd5_blitter.c
src/gallium/drivers/freedreno/a5xx/fd5_emit.c
src/gallium/drivers/freedreno/a5xx/fd5_format.c
src/gallium/drivers/freedreno/a5xx/fd5_screen.c
src/gallium/drivers/freedreno/a6xx/fd6_blitter.c
src/gallium/drivers/freedreno/a6xx/fd6_emit.c
src/gallium/drivers/freedreno/a6xx/fd6_format.c
src/gallium/drivers/freedreno/a6xx/fd6_screen.c

index 6c92d44..5cfa1fe 100644 (file)
@@ -91,6 +91,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value name="VFMT_2_10_10_10_UNORM" value="0x3d"/>
        <value name="VFMT_2_10_10_10_SINT" value="0x3e"/>
        <value name="VFMT_2_10_10_10_SNORM" value="0x3f"/>
+
+       <value name="VFMT_NONE" value="0xff"/>
 </enum>
 
 <enum name="a3xx_tex_fmt">
@@ -210,6 +212,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value name="TFMT_ETC2_RGBA8" value="0x74"/>
        <value name="TFMT_ETC2_RGB8A1" value="0x75"/>
        <value name="TFMT_ETC2_RGB8" value="0x76"/>
+
+       <value name="TFMT_NONE" value="0xff"/>
 </enum>
 
 <enum name="a3xx_tex_fetchsize">
@@ -278,6 +282,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value name="RB_R32_UINT"           value="0x38"/>
        <value name="RB_R32G32_UINT"        value="0x39"/>
        <value name="RB_R32G32B32A32_UINT"  value="0x3b"/>
+
+       <value name="RB_NONE"               value="0xff"/>
 </enum>
 
 <enum name="a3xx_cp_perfcounter_select">
index 1c2c48c..284e491 100644 (file)
@@ -56,6 +56,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value name="RB4_R32G32B32A32_FLOAT" value="0x3c"/>
        <value name="RB4_R32G32B32A32_UINT" value="0x3d"/>
        <value name="RB4_R32G32B32A32_SINT" value="0x3e"/>
+
+       <value name="RB4_NONE" value="0xff"/>
 </enum>
 
 <enum name="a4xx_tile_mode">
@@ -135,6 +137,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value name="VFMT4_2_10_10_10_UNORM" value="0x3d"/>
        <value name="VFMT4_2_10_10_10_SINT" value="0x3e"/>
        <value name="VFMT4_2_10_10_10_SNORM" value="0x3f"/>
+
+       <value name="VFMT4_NONE" value="0xff"/>
 </enum>
 
 <enum name="a4xx_tex_fmt">
@@ -260,6 +264,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value name="TFMT4_ASTC_12x10"            value="0x7b"/>
        <value name="TFMT4_ASTC_12x12"            value="0x7c"/>
        <!-- 0x7d .. 0x7f -->
+
+       <value name="TFMT4_NONE"                  value="0xff"/>
 </enum>
 
 <enum name="a4xx_tex_fetchsize">
index c5fdb66..f954a7b 100644 (file)
@@ -51,6 +51,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value value="0x82" name="RB5_R32G32B32A32_FLOAT"/>
        <value value="0x83" name="RB5_R32G32B32A32_UINT"/>
        <value value="0x84" name="RB5_R32G32B32A32_SINT"/>
+
+       <value value="0xff" name="RB5_NONE"/>
 </enum>
 
 <enum name="a5xx_tile_mode">
@@ -138,6 +140,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value value="0x83" name="VFMT5_32_32_32_32_UINT"/>
        <value value="0x84" name="VFMT5_32_32_32_32_SINT"/>
        <value value="0x85" name="VFMT5_32_32_32_32_FIXED"/>
+
+       <value value="0xff" name="VFMT5_NONE"/>
 </enum>
 
 <enum name="a5xx_tex_fmt">
@@ -224,6 +228,8 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
        <value value="0xcc" name="TFMT5_ASTC_10x10"/>
        <value value="0xcd" name="TFMT5_ASTC_12x10"/>
        <value value="0xce" name="TFMT5_ASTC_12x12"/>
+
+       <value value="0xff" name="TFMT5_NONE"/>
 </enum>
 
 <enum name="a5xx_tex_fetchsize">
index 92cabb1..a718b24 100644 (file)
@@ -152,6 +152,10 @@ xsi:schemaLocation="http://nouveau.freedesktop.org/ rules-ng.xsd">
 
        <!-- same as X8Z24_UNORM but for sampling stencil (integer, 2nd channel) -->
        <value value="0xea" name="FMT6_S8Z24_UINT"/>
+
+       <!-- Not a hw enum, used internally in driver -->
+       <value value="0xff" name="FMT6_NONE"/>
+
 </enum>
 
 <enum name="a6xx_tex_fetchsize">
index a7d2d31..11c9d05 100644 (file)
@@ -32,8 +32,6 @@
 #include "vk_util.h"
 #include "drm-uapi/drm_fourcc.h"
 
-#define FMT6_x -1
-
 #define TU6_FMT(vkfmt, hwfmt, swapfmt, valid) \
    [VK_FORMAT_##vkfmt] = {                   \
       .fmt = FMT6_##hwfmt,                     \
@@ -45,7 +43,7 @@
 #define TU6_xTC(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_TEXTURE | FMT_COLOR)
 #define TU6_Vxx(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_VERTEX)
 #define TU6_xTx(vk, fmt, swap) TU6_FMT(vk, fmt, swap, FMT_TEXTURE)
-#define TU6_xxx(vk, fmt, swap) TU6_FMT(vk, x, WZYX, false)
+#define TU6_xxx(vk, fmt, swap) TU6_FMT(vk, NONE, WZYX, 0)
 
 static const struct tu_native_format tu6_format_table[] = {
    TU6_xxx(UNDEFINED,                  x,                 x),    /* 0 */
index cf945b1..b87ef41 100644 (file)
@@ -32,7 +32,8 @@
 #include "a2xx.xml.h"
 
 struct surface_format {
-#define FMT_INVALID 0x7f
+/* If enum is a signed type, 0x7f is out of range. Cast it to avoid warnings. */
+#define FMT_INVALID ((enum a2xx_sq_surfaceformat) 0x7f)
        enum a2xx_sq_surfaceformat format : 7;
        enum sq_tex_sign sign : 2;
        enum sq_tex_num_format num_format : 1;
index 2761358..f86d471 100644 (file)
@@ -441,7 +441,7 @@ fd3_emit_vertex_bufs(struct fd_ringbuffer *ring, struct fd3_emit *emit)
                                continue;
 #endif
 
-                       debug_assert(fmt != ~0);
+                       debug_assert(fmt != VFMT_NONE);
 
                        OUT_PKT0(ring, REG_A3XX_VFD_FETCH(j), 2);
                        OUT_RING(ring, A3XX_VFD_FETCH_INSTR_0_FETCHSIZE(fs - 1) |
index b5a5bb1..58df971 100644 (file)
@@ -39,8 +39,6 @@ struct fd3_format {
        boolean present;
 };
 
-#define RB_NONE ~0
-
 /* vertex + texture */
 #define VT(pipe, fmt, rbfmt, swapfmt) \
        [PIPE_FORMAT_ ## pipe] = { \
@@ -55,7 +53,7 @@ struct fd3_format {
 #define _T(pipe, fmt, rbfmt, swapfmt) \
        [PIPE_FORMAT_ ## pipe] = { \
                .present = 1, \
-               .vtx = ~0, \
+               .vtx = VFMT_NONE, \
                .tex = TFMT_ ## fmt, \
                .rb = RB_ ## rbfmt, \
                .swap = swapfmt \
@@ -66,7 +64,7 @@ struct fd3_format {
        [PIPE_FORMAT_ ## pipe] = { \
                .present = 1, \
                .vtx = VFMT_ ## fmt, \
-               .tex = ~0, \
+               .tex = TFMT_NONE, \
                .rb = RB_ ## rbfmt, \
                .swap = swapfmt \
        }
@@ -295,7 +293,7 @@ enum a3xx_vtx_fmt
 fd3_pipe2vtx(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return VFMT_NONE;
        return formats[format].vtx;
 }
 
@@ -303,7 +301,7 @@ enum a3xx_tex_fmt
 fd3_pipe2tex(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return TFMT_NONE;
        return formats[format].tex;
 }
 
@@ -311,7 +309,7 @@ enum a3xx_color_fmt
 fd3_pipe2color(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return RB_NONE;
        return formats[format].rb;
 }
 
index 0a58c16..49a7e0b 100644 (file)
@@ -116,7 +116,7 @@ ok_format(enum pipe_format pfmt)
 {
        enum a3xx_color_fmt fmt = fd3_pipe2color(pfmt);
 
-       if (fmt == ~0)
+       if (fmt == RB_NONE)
                return false;
 
        switch (pfmt) {
index bdf8eaa..772426c 100644 (file)
@@ -56,12 +56,12 @@ fd3_screen_is_format_supported(struct pipe_screen *pscreen,
                return false;
 
        if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
-                       (fd3_pipe2vtx(format) != (enum a3xx_vtx_fmt)~0)) {
+                       (fd3_pipe2vtx(format) != VFMT_NONE)) {
                retval |= PIPE_BIND_VERTEX_BUFFER;
        }
 
        if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
-                       (fd3_pipe2tex(format) != (enum a3xx_tex_fmt)~0)) {
+                       (fd3_pipe2tex(format) != TFMT_NONE)) {
                retval |= PIPE_BIND_SAMPLER_VIEW;
        }
 
@@ -70,8 +70,8 @@ fd3_screen_is_format_supported(struct pipe_screen *pscreen,
                                PIPE_BIND_SCANOUT |
                                PIPE_BIND_SHARED |
                                PIPE_BIND_BLENDABLE)) &&
-                       (fd3_pipe2color(format) != (enum a3xx_color_fmt)~0) &&
-                       (fd3_pipe2tex(format) != (enum a3xx_tex_fmt)~0)) {
+                       (fd3_pipe2color(format) != RB_NONE) &&
+                       (fd3_pipe2tex(format) != TFMT_NONE)) {
                retval |= usage & (PIPE_BIND_RENDER_TARGET |
                                PIPE_BIND_DISPLAY_TARGET |
                                PIPE_BIND_SCANOUT |
@@ -82,7 +82,7 @@ fd3_screen_is_format_supported(struct pipe_screen *pscreen,
 
        if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
                        (fd_pipe2depth(format) != (enum adreno_rb_depth_format)~0) &&
-                       (fd3_pipe2tex(format) != (enum a3xx_tex_fmt)~0)) {
+                       (fd3_pipe2tex(format) != TFMT_NONE)) {
                retval |= PIPE_BIND_DEPTH_STENCIL;
        }
 
index 0aff8fe..6f94733 100644 (file)
@@ -437,7 +437,7 @@ fd4_emit_vertex_bufs(struct fd_ringbuffer *ring, struct fd4_emit *emit)
                        uint32_t fs = util_format_get_blocksize(pfmt);
                        uint32_t off = vb->buffer_offset + elem->src_offset;
                        uint32_t size = fd_bo_size(rsc->bo) - off;
-                       debug_assert(fmt != ~0);
+                       debug_assert(fmt != VFMT4_NONE);
 
 #ifdef DEBUG
                        /* see dEQP-GLES31.stress.vertex_attribute_binding.buffer_bounds.bind_vertex_buffer_offset_near_wrap_10
index a9768ac..c410158 100644 (file)
@@ -42,8 +42,6 @@ struct fd4_format {
        boolean present;
 };
 
-#define RB4_NONE ~0
-
 /* vertex + texture */
 #define VT(pipe, fmt, rbfmt, swapfmt) \
        [PIPE_FORMAT_ ## pipe] = { \
@@ -58,7 +56,7 @@ struct fd4_format {
 #define _T(pipe, fmt, rbfmt, swapfmt) \
        [PIPE_FORMAT_ ## pipe] = { \
                .present = 1, \
-               .vtx = ~0, \
+               .vtx = VFMT4_NONE, \
                .tex = TFMT4_ ## fmt, \
                .rb = RB4_ ## rbfmt, \
                .swap = swapfmt \
@@ -69,7 +67,7 @@ struct fd4_format {
        [PIPE_FORMAT_ ## pipe] = { \
                .present = 1, \
                .vtx = VFMT4_ ## fmt, \
-               .tex = ~0, \
+               .tex = TFMT4_NONE, \
                .rb = RB4_ ## rbfmt, \
                .swap = swapfmt \
        }
index 7c00c3e..a1d846c 100644 (file)
@@ -72,7 +72,7 @@ ok_format(enum pipe_format fmt)
                break;
        }
 
-       if (fd5_pipe2color(fmt) == ~0)
+       if (fd5_pipe2color(fmt) == RB5_NONE)
                return false;
 
        return true;
index ac8a5f5..3670cba 100644 (file)
@@ -492,7 +492,7 @@ fd5_emit_vertex_bufs(struct fd_ringbuffer *ring, struct fd5_emit *emit)
                        bool isint = util_format_is_pure_integer(pfmt);
                        uint32_t off = vb->buffer_offset + elem->src_offset;
                        uint32_t size = fd_bo_size(rsc->bo) - off;
-                       debug_assert(fmt != ~0);
+                       debug_assert(fmt != VFMT5_NONE);
 
 #ifdef DEBUG
                        /* see dEQP-GLES31.stress.vertex_attribute_binding.buffer_bounds.bind_vertex_buffer_offset_near_wrap_10
index 3686f16..a201b64 100644 (file)
@@ -42,8 +42,6 @@ struct fd5_format {
        boolean present;
 };
 
-#define RB5_NONE ~0
-
 /* vertex + texture */
 #define VT(pipe, fmt, rbfmt, swapfmt) \
        [PIPE_FORMAT_ ## pipe] = { \
@@ -58,7 +56,7 @@ struct fd5_format {
 #define _T(pipe, fmt, rbfmt, swapfmt) \
        [PIPE_FORMAT_ ## pipe] = { \
                .present = 1, \
-               .vtx = ~0, \
+               .vtx = VFMT5_NONE, \
                .tex = TFMT5_ ## fmt, \
                .rb = RB5_ ## rbfmt, \
                .swap = swapfmt \
@@ -69,7 +67,7 @@ struct fd5_format {
        [PIPE_FORMAT_ ## pipe] = { \
                .present = 1, \
                .vtx = VFMT5_ ## fmt, \
-               .tex = ~0, \
+               .tex = TFMT5_NONE, \
                .rb = RB5_ ## rbfmt, \
                .swap = swapfmt \
        }
@@ -344,7 +342,7 @@ enum a5xx_vtx_fmt
 fd5_pipe2vtx(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return VFMT5_NONE;
        return formats[format].vtx;
 }
 
@@ -353,7 +351,7 @@ enum a5xx_tex_fmt
 fd5_pipe2tex(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return TFMT5_NONE;
        return formats[format].tex;
 }
 
@@ -362,7 +360,7 @@ enum a5xx_color_fmt
 fd5_pipe2color(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return RB5_NONE;
        return formats[format].rb;
 }
 
index 12dcb8a..9a4df4d 100644 (file)
@@ -71,12 +71,12 @@ fd5_screen_is_format_supported(struct pipe_screen *pscreen,
                return false;
 
        if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
-                       (fd5_pipe2vtx(format) != (enum a5xx_vtx_fmt)~0)) {
+                       (fd5_pipe2vtx(format) != VFMT5_NONE)) {
                retval |= PIPE_BIND_VERTEX_BUFFER;
        }
 
        if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&
-                       (fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0) &&
+                       (fd5_pipe2tex(format) != TFMT5_NONE) &&
                        (target == PIPE_BUFFER ||
                         util_format_get_blocksize(format) != 12)) {
                retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);
@@ -87,8 +87,8 @@ fd5_screen_is_format_supported(struct pipe_screen *pscreen,
                                PIPE_BIND_SCANOUT |
                                PIPE_BIND_SHARED |
                                PIPE_BIND_COMPUTE_RESOURCE)) &&
-                       (fd5_pipe2color(format) != (enum a5xx_color_fmt)~0) &&
-                       (fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0)) {
+                       (fd5_pipe2color(format) != RB5_NONE) &&
+                       (fd5_pipe2tex(format) != TFMT5_NONE)) {
                retval |= usage & (PIPE_BIND_RENDER_TARGET |
                                PIPE_BIND_DISPLAY_TARGET |
                                PIPE_BIND_SCANOUT |
@@ -103,7 +103,7 @@ fd5_screen_is_format_supported(struct pipe_screen *pscreen,
 
        if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
                        (fd5_pipe2depth(format) != (enum a5xx_depth_format)~0) &&
-                       (fd5_pipe2tex(format) != (enum a5xx_tex_fmt)~0)) {
+                       (fd5_pipe2tex(format) != TFMT5_NONE)) {
                retval |= PIPE_BIND_DEPTH_STENCIL;
        }
 
index 9b5231d..7bf9679 100644 (file)
@@ -77,7 +77,7 @@ ok_format(enum pipe_format pfmt)
                break;
        }
 
-       if (fmt == ~0)
+       if (fmt == FMT6_NONE)
                return false;
 
        if (fd6_ifmt(fmt) == 0)
index 52a44c6..2394187 100644 (file)
@@ -608,7 +608,7 @@ build_vbo_state(struct fd6_emit *emit, const struct ir3_shader_variant *vp)
                enum pipe_format pfmt = elem->src_format;
                enum a6xx_format fmt = fd6_pipe2vtx(pfmt);
                bool isint = util_format_is_pure_integer(pfmt);
-               debug_assert(fmt != ~0);
+               debug_assert(fmt != FMT6_NONE);
 
                OUT_RING(ring, A6XX_VFD_DECODE_INSTR_IDX(j) |
                                A6XX_VFD_DECODE_INSTR_FORMAT(fmt) |
index fbb1fb9..0cd7b39 100644 (file)
@@ -44,8 +44,6 @@ struct fd6_format {
        boolean present;
 };
 
-#define FMT6_NONE ~0
-
 #define FMT(pipe, vtxfmt, texfmt, rbfmt, swapfmt) \
        [PIPE_FORMAT_ ## pipe] = { \
                .present = 1, \
@@ -341,7 +339,7 @@ enum a6xx_format
 fd6_pipe2vtx(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return FMT6_NONE;
        return formats[format].vtx;
 }
 
@@ -350,7 +348,7 @@ enum a6xx_format
 fd6_pipe2tex(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return FMT6_NONE;
        return formats[format].tex;
 }
 
@@ -359,7 +357,7 @@ enum a6xx_format
 fd6_pipe2color(enum pipe_format format)
 {
        if (!formats[format].present)
-               return ~0;
+               return FMT6_NONE;
        return formats[format].rb;
 }
 
index 20383d4..bb46711 100644 (file)
@@ -77,12 +77,12 @@ fd6_screen_is_format_supported(struct pipe_screen *pscreen,
                return false;
 
        if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
-                       (fd6_pipe2vtx(format) != (enum a6xx_format)~0)) {
+                       (fd6_pipe2vtx(format) != FMT6_NONE)) {
                retval |= PIPE_BIND_VERTEX_BUFFER;
        }
 
        if ((usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE)) &&
-                       (fd6_pipe2tex(format) != (enum a6xx_format)~0) &&
+                       (fd6_pipe2tex(format) != FMT6_NONE) &&
                        (target == PIPE_BUFFER ||
                         util_format_get_blocksize(format) != 12)) {
                retval |= usage & (PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_SHADER_IMAGE);
@@ -93,8 +93,8 @@ fd6_screen_is_format_supported(struct pipe_screen *pscreen,
                                PIPE_BIND_SCANOUT |
                                PIPE_BIND_SHARED |
                                PIPE_BIND_COMPUTE_RESOURCE)) &&
-                       (fd6_pipe2color(format) != (enum a6xx_format)~0) &&
-                       (fd6_pipe2tex(format) != (enum a6xx_format)~0)) {
+                       (fd6_pipe2color(format) != FMT6_NONE) &&
+                       (fd6_pipe2tex(format) != FMT6_NONE)) {
                retval |= usage & (PIPE_BIND_RENDER_TARGET |
                                PIPE_BIND_DISPLAY_TARGET |
                                PIPE_BIND_SCANOUT |
@@ -109,7 +109,7 @@ fd6_screen_is_format_supported(struct pipe_screen *pscreen,
 
        if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
                        (fd6_pipe2depth(format) != (enum a6xx_depth_format)~0) &&
-                       (fd6_pipe2tex(format) != (enum a6xx_format)~0)) {
+                       (fd6_pipe2tex(format) != FMT6_NONE)) {
                retval |= PIPE_BIND_DEPTH_STENCIL;
        }