From 6f3381a5d37bf08c58dfd8352409db97b9156e60 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 1 Jun 2017 16:29:39 -0400 Subject: [PATCH] Fixes from review of PR #190. --- spirv_cross.cpp | 4 ++++ spirv_glsl.cpp | 5 ----- spirv_msl.cpp | 12 ++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/spirv_cross.cpp b/spirv_cross.cpp index 4ac59eed..767f69ee 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -1469,6 +1469,10 @@ void Compiler::parse(const Instruction &instruction) type.image.sampled = ops[6]; type.image.format = static_cast(ops[7]); type.image.access = (length >= 9) ? static_cast(ops[8]) : AccessQualifierMax; + + if (type.image.sampled == 0) + SPIRV_CROSS_THROW("OpTypeImage Sampled parameter must not be zero."); + break; } diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 8b02e12b..e87ea609 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -2893,11 +2893,6 @@ void CompilerGLSL::emit_texture_op(const Instruction &i) auto &type = expression_type(img); auto &imgtype = get(type.self); - // Mark that this shader reads from this image - auto *p_var = maybe_get_backing_variable(img); - if (p_var) - unset_decoration(p_var->self, DecorationNonReadable); - uint32_t coord_components = 0; switch (imgtype.image.dim) { diff --git a/spirv_msl.cpp b/spirv_msl.cpp index faa69276..7c4e0a45 100644 --- a/spirv_msl.cpp +++ b/spirv_msl.cpp @@ -1179,10 +1179,18 @@ void CompilerMSL::emit_instruction(const Instruction &instruction) // Images - // Reads == fetches in Metal + // Reads == Fetches in Metal case OpImageRead: + { + // Mark that this shader reads from this image + uint32_t img_id = ops[2]; + auto *p_var = maybe_get_backing_variable(img_id); + if (p_var) + unset_decoration(p_var->self, DecorationNonReadable); + emit_texture_op(instruction); break; + } case OpImageWrite: { @@ -2490,7 +2498,7 @@ string CompilerMSL::image_type_glsl(const SPIRType &type, uint32_t id) // For unsampled images, append the sample/read/write access qualifier. // For kernel images, the access qualifier my be supplied directly by SPIR-V. // Otherwise it may be set based on whether the image is read from or written to within the shader. - if (type.basetype == SPIRType::Image) + if (type.basetype == SPIRType::Image && type.image.sampled == 2) { switch (img_type.access) {