summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_spirv_image.cpp')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_image.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
index 22ceca19c..800754554 100644
--- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp
@@ -214,16 +214,16 @@ Id TextureImage(EmitContext& ctx, IR::TextureInstInfo info, const IR::Value& ind
214 } 214 }
215} 215}
216 216
217Id Image(EmitContext& ctx, const IR::Value& index, IR::TextureInstInfo info) { 217std::pair<Id, bool> Image(EmitContext& ctx, const IR::Value& index, IR::TextureInstInfo info) {
218 if (!index.IsImmediate() || index.U32() != 0) { 218 if (!index.IsImmediate() || index.U32() != 0) {
219 throw NotImplementedException("Indirect image indexing"); 219 throw NotImplementedException("Indirect image indexing");
220 } 220 }
221 if (info.type == TextureType::Buffer) { 221 if (info.type == TextureType::Buffer) {
222 const ImageBufferDefinition def{ctx.image_buffers.at(info.descriptor_index)}; 222 const ImageBufferDefinition def{ctx.image_buffers.at(info.descriptor_index)};
223 return ctx.OpLoad(def.image_type, def.id); 223 return {ctx.OpLoad(def.image_type, def.id), def.is_integer};
224 } else { 224 } else {
225 const ImageDefinition def{ctx.images.at(info.descriptor_index)}; 225 const ImageDefinition def{ctx.images.at(info.descriptor_index)};
226 return ctx.OpLoad(def.image_type, def.id); 226 return {ctx.OpLoad(def.image_type, def.id), def.is_integer};
227 } 227 }
228} 228}
229 229
@@ -566,13 +566,23 @@ Id EmitImageRead(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id co
566 LOG_WARNING(Shader_SPIRV, "Typeless image read not supported by host"); 566 LOG_WARNING(Shader_SPIRV, "Typeless image read not supported by host");
567 return ctx.ConstantNull(ctx.U32[4]); 567 return ctx.ConstantNull(ctx.U32[4]);
568 } 568 }
569 return Emit(&EmitContext::OpImageSparseRead, &EmitContext::OpImageRead, ctx, inst, ctx.U32[4], 569 const auto [image, is_integer] = Image(ctx, index, info);
570 Image(ctx, index, info), coords, std::nullopt, std::span<const Id>{}); 570 const Id result_type{is_integer ? ctx.U32[4] : ctx.F32[4]};
571 Id color{Emit(&EmitContext::OpImageSparseRead, &EmitContext::OpImageRead, ctx, inst,
572 result_type, image, coords, std::nullopt, std::span<const Id>{})};
573 if (!is_integer) {
574 color = ctx.OpBitcast(ctx.U32[4], color);
575 }
576 return color;
571} 577}
572 578
573void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id color) { 579void EmitImageWrite(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id color) {
574 const auto info{inst->Flags<IR::TextureInstInfo>()}; 580 const auto info{inst->Flags<IR::TextureInstInfo>()};
575 ctx.OpImageWrite(Image(ctx, index, info), coords, color); 581 const auto [image, is_integer] = Image(ctx, index, info);
582 if (!is_integer) {
583 color = ctx.OpBitcast(ctx.F32[4], color);
584 }
585 ctx.OpImageWrite(image, coords, color);
576} 586}
577 587
578Id EmitIsTextureScaled(EmitContext& ctx, const IR::Value& index) { 588Id EmitIsTextureScaled(EmitContext& ctx, const IR::Value& index) {