spirv: Assert sampler_dim is valid when building nir_tex_instr
authorCaio Oliveira <caio.oliveira@intel.com>
Tue, 21 Sep 2021 20:31:10 +0000 (13:31 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 31 May 2023 21:39:07 +0000 (21:39 +0000)
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14244>

src/compiler/spirv/spirv_to_nir.c

index e74fb0f..89b30ba 100644 (file)
@@ -25,6 +25,7 @@
  *
  */
 
+#include "glsl_types.h"
 #include "vtn_private.h"
 #include "nir/nir_vla.h"
 #include "nir/nir_control_flow.h"
@@ -2827,8 +2828,19 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
    case SpvOpImageSparseSampleImplicitLod:
    case SpvOpImageSampleDrefImplicitLod:
    case SpvOpImageSparseSampleDrefImplicitLod:
+      vtn_assert(sampler_dim != GLSL_SAMPLER_DIM_BUF &&
+                 sampler_dim != GLSL_SAMPLER_DIM_MS &&
+                 sampler_dim != GLSL_SAMPLER_DIM_SUBPASS_MS);
+      texop = nir_texop_tex;
+      break;
+
    case SpvOpImageSampleProjImplicitLod:
    case SpvOpImageSampleProjDrefImplicitLod:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_1D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_2D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_3D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_RECT);
+      vtn_assert(!is_array);
       texop = nir_texop_tex;
       break;
 
@@ -2836,13 +2848,25 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
    case SpvOpImageSparseSampleExplicitLod:
    case SpvOpImageSampleDrefExplicitLod:
    case SpvOpImageSparseSampleDrefExplicitLod:
+      vtn_assert(sampler_dim != GLSL_SAMPLER_DIM_BUF &&
+                 sampler_dim != GLSL_SAMPLER_DIM_MS &&
+                 sampler_dim != GLSL_SAMPLER_DIM_SUBPASS_MS);
+      texop = nir_texop_txl;
+      break;
+
    case SpvOpImageSampleProjExplicitLod:
    case SpvOpImageSampleProjDrefExplicitLod:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_1D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_2D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_3D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_RECT);
+      vtn_assert(!is_array);
       texop = nir_texop_txl;
       break;
 
    case SpvOpImageFetch:
    case SpvOpImageSparseFetch:
+      vtn_assert(sampler_dim != GLSL_SAMPLER_DIM_CUBE);
       if (sampler_dim == GLSL_SAMPLER_DIM_MS) {
          texop = nir_texop_txf_ms;
       } else {
@@ -2854,35 +2878,66 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
    case SpvOpImageSparseGather:
    case SpvOpImageDrefGather:
    case SpvOpImageSparseDrefGather:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_2D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_CUBE ||
+                 sampler_dim == GLSL_SAMPLER_DIM_RECT);
       texop = nir_texop_tg4;
       break;
 
    case SpvOpImageQuerySizeLod:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_1D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_2D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_3D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_CUBE);
+      texop = nir_texop_txs;
+      dest_type = nir_type_int32;
+      break;
+
    case SpvOpImageQuerySize:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_1D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_2D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_3D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_CUBE ||
+                 sampler_dim == GLSL_SAMPLER_DIM_RECT ||
+                 sampler_dim == GLSL_SAMPLER_DIM_MS ||
+                 sampler_dim == GLSL_SAMPLER_DIM_BUF);
       texop = nir_texop_txs;
       dest_type = nir_type_int32;
       break;
 
    case SpvOpImageQueryLod:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_1D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_2D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_3D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_CUBE);
       texop = nir_texop_lod;
       dest_type = nir_type_float32;
       break;
 
    case SpvOpImageQueryLevels:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_1D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_2D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_3D ||
+                 sampler_dim == GLSL_SAMPLER_DIM_CUBE);
       texop = nir_texop_query_levels;
       dest_type = nir_type_int32;
       break;
 
    case SpvOpImageQuerySamples:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_MS);
       texop = nir_texop_texture_samples;
       dest_type = nir_type_int32;
       break;
 
    case SpvOpFragmentFetchAMD:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_MS ||
+                 sampler_dim == GLSL_SAMPLER_DIM_SUBPASS_MS);
       texop = nir_texop_fragment_fetch_amd;
       break;
 
    case SpvOpFragmentMaskFetchAMD:
+      vtn_assert(sampler_dim == GLSL_SAMPLER_DIM_MS ||
+                 sampler_dim == GLSL_SAMPLER_DIM_SUBPASS_MS);
       texop = nir_texop_fragment_mask_fetch_amd;
       dest_type = nir_type_uint32;
       break;