[Mesa-dev] [PATCH] [rfc] spirv/nir: handle casting in OpSampledImage

Dave Airlie airlied at gmail.com
Tue Sep 26 02:36:46 UTC 2017


From: Dave Airlie <airlied at redhat.com>

%9903 = OpImageSampleDrefExplicitLod %float %14616 %14315 %16081 Lod %float_0
%14616 = OpSampledImage %510 %8499 %13137

%278 = OpTypeImage %float 2D 1 0 0 1 Unknown
%510 = OpTypeSampledImage %278

%8499 = OpLoad %150 %4159
%150 = OpTypeImage %float 2D 0 0 0 1 Unknown

Is being generated by a hlsl->spirv convertor.

So it appears that the 510 return type from sampledimage is a shadow sampler,
however the descriptor it's loading is for a 2D non-shadow image, which
makes it seems like OpSampledImage should cast appropriately.

Now I'm not sure enough to know if this is valid spir-v in the first place,
and I don't think this patch is good enough to fix it even if it is, but
let's use it to open discussions.
---
 src/compiler/spirv/spirv_to_nir.c | 6 +++++-
 src/compiler/spirv/vtn_private.h  | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 6ce9d1a..d962e93 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -1490,6 +1490,8 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
       struct vtn_value *val =
          vtn_push_value(b, w[2], vtn_value_type_sampled_image);
       val->sampled_image = ralloc(b, struct vtn_sampled_image);
+      val->sampled_image->ret_type =
+         vtn_value(b, w[1], vtn_value_type_type)->type;
       val->sampled_image->image =
          vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
       val->sampled_image->sampler =
@@ -1521,7 +1523,9 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
    }
 
    const struct glsl_type *image_type;
-   if (sampled.image) {
+   if (sampled.ret_type) {
+      image_type = sampled.ret_type->type;
+   } else if (sampled.image) {
       image_type = sampled.image->var->var->interface_type;
    } else {
       image_type = sampled.sampler->var->var->interface_type;
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
index 8458462..ce26326 100644
--- a/src/compiler/spirv/vtn_private.h
+++ b/src/compiler/spirv/vtn_private.h
@@ -413,6 +413,7 @@ struct vtn_image_pointer {
 struct vtn_sampled_image {
    struct vtn_pointer *image; /* Image or array of images */
    struct vtn_pointer *sampler; /* Sampler */
+   struct vtn_type *ret_type;
 };
 
 struct vtn_value {
-- 
2.9.5



More information about the mesa-dev mailing list