Mesa (staging/20.1): spirv: fix using OpSampledImage with OpUndef instead of OpType{Image,Sampler}
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Jun 16 19:47:55 UTC 2020
Module: Mesa
Branch: staging/20.1
Commit: 4e482262a7695f8c445091cc17823f75ae88b0de
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=4e482262a7695f8c445091cc17823f75ae88b0de
Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date: Tue May 26 13:54:34 2020 +0200
spirv: fix using OpSampledImage with OpUndef instead of OpType{Image,Sampler}
This seems valid per the SPIR-V spec to use OpSampledImage with
OpUndef instead of OpTypeImage or OpTypeSampler. When the image
operand is undefined, SPIRV->NIR emits an undef instruction that
can be removed later by the compiler.
This fixes shader compilation crashes with Red Dead Redemption II.
Cc: mesa-stable at lists.freedesktop.org>
Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5230>
(cherry picked from commit 9b6a8d17424ac5fa11ccf44c02da2a237088cb76)
---
.pick_status.json | 2 +-
src/compiler/spirv/spirv_to_nir.c | 26 ++++++++++++++++++++++----
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index 37ed2d774af..b4e548c06ed 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -517,7 +517,7 @@
"description": "spirv: fix using OpSampledImage with OpUndef instead of OpType{Image,Sampler}",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": null
},
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index e6f49ed87a8..795f4c8bdcf 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -2220,10 +2220,23 @@ 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->image =
- vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
- val->sampled_image->sampler =
- vtn_value(b, w[4], vtn_value_type_pointer)->pointer;
+
+ /* It seems valid to use OpSampledImage with OpUndef instead of
+ * OpTypeImage or OpTypeSampler.
+ */
+ if (vtn_untyped_value(b, w[3])->value_type == vtn_value_type_undef) {
+ val->sampled_image->image = NULL;
+ } else {
+ val->sampled_image->image =
+ vtn_value(b, w[3], vtn_value_type_pointer)->pointer;
+ }
+
+ if (vtn_untyped_value(b, w[4])->value_type == vtn_value_type_undef) {
+ val->sampled_image->sampler = NULL;
+ } else {
+ val->sampled_image->sampler =
+ vtn_value(b, w[4], vtn_value_type_pointer)->pointer;
+ }
return;
} else if (opcode == SpvOpImage) {
struct vtn_value *src_val = vtn_untyped_value(b, w[3]);
@@ -2248,6 +2261,11 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
image = sampled_val->pointer;
}
+ if (!image) {
+ vtn_push_value(b, w[2], vtn_value_type_undef);
+ return;
+ }
+
nir_deref_instr *image_deref = vtn_pointer_to_deref(b, image);
nir_deref_instr *sampler_deref =
sampler ? vtn_pointer_to_deref(b, sampler) : NULL;
More information about the mesa-commit
mailing list