summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_image.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_image.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
index c62451e23..8c54f0fb3 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp
@@ -14,15 +14,25 @@ namespace {
14std::string Texture(EmitContext& ctx, const IR::TextureInstInfo& info, 14std::string Texture(EmitContext& ctx, const IR::TextureInstInfo& info,
15 [[maybe_unused]] const IR::Value& index) { 15 [[maybe_unused]] const IR::Value& index) {
16 if (info.type == TextureType::Buffer) { 16 if (info.type == TextureType::Buffer) {
17 throw NotImplementedException("TextureType::Buffer"); 17 return fmt::format("tex{}", ctx.texture_buffer_bindings.at(info.descriptor_index));
18 } else { 18 } else {
19 return fmt::format("tex{}", ctx.texture_bindings.at(info.descriptor_index)); 19 return fmt::format("tex{}", ctx.texture_bindings.at(info.descriptor_index));
20 } 20 }
21} 21}
22 22
23std::string Image(EmitContext& ctx, const IR::TextureInstInfo& info,
24 [[maybe_unused]] const IR::Value& index) {
25 if (info.type == TextureType::Buffer) {
26 return fmt::format("img{}", ctx.image_buffer_bindings.at(info.descriptor_index));
27 } else {
28 return fmt::format("img{}", ctx.image_bindings.at(info.descriptor_index));
29 }
30}
31
23std::string CastToIntVec(std::string_view value, const IR::TextureInstInfo& info) { 32std::string CastToIntVec(std::string_view value, const IR::TextureInstInfo& info) {
24 switch (info.type) { 33 switch (info.type) {
25 case TextureType::Color1D: 34 case TextureType::Color1D:
35 case TextureType::Buffer:
26 return fmt::format("int({})", value); 36 return fmt::format("int({})", value);
27 case TextureType::ColorArray1D: 37 case TextureType::ColorArray1D:
28 case TextureType::Color2D: 38 case TextureType::Color2D:
@@ -41,6 +51,7 @@ std::string CastToIntVec(std::string_view value, const IR::TextureInstInfo& info
41std::string TexelFetchCastToInt(std::string_view value, const IR::TextureInstInfo& info) { 51std::string TexelFetchCastToInt(std::string_view value, const IR::TextureInstInfo& info) {
42 switch (info.type) { 52 switch (info.type) {
43 case TextureType::Color1D: 53 case TextureType::Color1D:
54 case TextureType::Buffer:
44 return fmt::format("int({})", value); 55 return fmt::format("int({})", value);
45 case TextureType::ColorArray1D: 56 case TextureType::ColorArray1D:
46 case TextureType::Color2D: 57 case TextureType::Color2D:
@@ -349,8 +360,12 @@ void EmitImageFetch([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst
349 ctx.Add("{}=texelFetchOffset({},{},int({}),{});", texel, texture, 360 ctx.Add("{}=texelFetchOffset({},{},int({}),{});", texel, texture,
350 TexelFetchCastToInt(coords, info), lod, TexelFetchCastToInt(offset, info)); 361 TexelFetchCastToInt(coords, info), lod, TexelFetchCastToInt(offset, info));
351 } else { 362 } else {
352 ctx.Add("{}=texelFetch({},{},int({}));", texel, texture, 363 if (info.type == TextureType::Buffer) {
353 TexelFetchCastToInt(coords, info), lod); 364 ctx.Add("{}=texelFetch({},int({}));", texel, texture, coords);
365 } else {
366 ctx.Add("{}=texelFetch({},{},int({}));", texel, texture,
367 TexelFetchCastToInt(coords, info), lod);
368 }
354 } 369 }
355 return; 370 return;
356 } 371 }
@@ -434,14 +449,22 @@ void EmitImageGradient([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::I
434void EmitImageRead([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 449void EmitImageRead([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
435 [[maybe_unused]] const IR::Value& index, 450 [[maybe_unused]] const IR::Value& index,
436 [[maybe_unused]] std::string_view coords) { 451 [[maybe_unused]] std::string_view coords) {
437 NotImplemented(); 452 const auto info{inst.Flags<IR::TextureInstInfo>()};
453 const auto sparse_inst{PrepareSparse(inst)};
454 if (sparse_inst) {
455 throw NotImplementedException("EmitImageRead Sparse");
456 }
457 const auto image{Image(ctx, info, index)};
458 ctx.AddU32x4("{}=uvec4(imageLoad({},{}));", inst, image, TexelFetchCastToInt(coords, info));
438} 459}
439 460
440void EmitImageWrite([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 461void EmitImageWrite([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
441 [[maybe_unused]] const IR::Value& index, 462 [[maybe_unused]] const IR::Value& index,
442 [[maybe_unused]] std::string_view coords, 463 [[maybe_unused]] std::string_view coords,
443 [[maybe_unused]] std::string_view color) { 464 [[maybe_unused]] std::string_view color) {
444 NotImplemented(); 465 const auto info{inst.Flags<IR::TextureInstInfo>()};
466 const auto image{Image(ctx, info, index)};
467 ctx.Add("imageStore({},{},{});", image, TexelFetchCastToInt(coords, info), color);
445} 468}
446 469
447void EmitBindlessImageSampleImplicitLod(EmitContext&) { 470void EmitBindlessImageSampleImplicitLod(EmitContext&) {