zink: use a macro for spir-v versions
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Mon, 7 Jun 2021 11:37:49 +0000 (13:37 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 7 Jun 2021 12:00:15 +0000 (12:00 +0000)
Instead of repeating constants over and over, let's use a macro for the
SPIR-V version definition instead.

Reviewed-by: Hoe Hao Cheng <haochengho12907@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11044>

src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.c
src/gallium/drivers/zink/nir_to_spirv/nir_to_spirv.h
src/gallium/drivers/zink/zink_screen.c

index 99a3ce9..8263d34 100644 (file)
@@ -3559,8 +3559,8 @@ nir_to_spirv(struct nir_shader *s, const struct zink_so_info *so_info, uint32_t
    struct ntv_context ctx = {};
    ctx.mem_ctx = ralloc_context(NULL);
    ctx.builder.mem_ctx = ctx.mem_ctx;
-   assert(spirv_version >= 0x10000);
-   ctx.spirv_1_4_interfaces = spirv_version >= 0x10400;
+   assert(spirv_version >= SPIRV_VERSION(1, 0));
+   ctx.spirv_1_4_interfaces = spirv_version >= SPIRV_VERSION(1, 4);
 
    ctx.glsl_types = _mesa_pointer_hash_table_create(ctx.mem_ctx);
    if (!ctx.glsl_types)
index 2c59f40..04b5594 100644 (file)
@@ -34,6 +34,8 @@
 
 #include "zink_compiler.h"
 
+#define SPIRV_VERSION(major, minor) (((major) << 16) | ((minor) << 8))
+
 struct spirv_shader {
    uint32_t *words;
    size_t num_words;
index 31fc2fb..c5fe1a9 100644 (file)
@@ -33,6 +33,7 @@
 #include "zink_instance.h"
 #include "zink_public.h"
 #include "zink_resource.h"
+#include "nir_to_spirv/nir_to_spirv.h" // for SPIRV_VERSION
 
 #include "os/os_process.h"
 #include "util/u_debug.h"
@@ -257,7 +258,7 @@ zink_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
       return 1;
 
    case PIPE_CAP_TGSI_VOTE:
-      return screen->spirv_version >= 0x00010300;
+      return screen->spirv_version >= SPIRV_VERSION(1, 3);
 
    case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
       return screen->info.have_EXT_provoking_vertex;
@@ -1054,11 +1055,11 @@ choose_pdev(struct zink_screen *screen)
 
    /* calculate SPIR-V version based on VK version */
    if (screen->vk_version >= VK_MAKE_VERSION(1, 2, 0))
-      screen->spirv_version = 0x00010500;
+      screen->spirv_version = SPIRV_VERSION(1, 5);
    else if (screen->vk_version >= VK_MAKE_VERSION(1, 1, 0))
-      screen->spirv_version = 0x00010300;
+      screen->spirv_version = SPIRV_VERSION(1, 3);
    else
-      screen->spirv_version = 0x00010000;
+      screen->spirv_version = SPIRV_VERSION(1, 0);
 }
 
 static void