diff options
| author | 2021-06-02 20:37:24 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:37 -0400 | |
| commit | af9696059cc24e07fba2920814725e56c3c61df0 (patch) | |
| tree | 10e890e28242cefe7e45ee331fa767e1ff3436cb /src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | |
| parent | glsl: skip gl_ViewportIndex write if device does not support it (diff) | |
| download | yuzu-af9696059cc24e07fba2920814725e56c3c61df0.tar.gz yuzu-af9696059cc24e07fba2920814725e56c3c61df0.tar.xz yuzu-af9696059cc24e07fba2920814725e56c3c61df0.zip | |
glsl: Implement Images
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_image.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | 33 |
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 { | |||
| 14 | std::string Texture(EmitContext& ctx, const IR::TextureInstInfo& info, | 14 | std::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 | ||
| 23 | std::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 | |||
| 23 | std::string CastToIntVec(std::string_view value, const IR::TextureInstInfo& info) { | 32 | std::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 | |||
| 41 | std::string TexelFetchCastToInt(std::string_view value, const IR::TextureInstInfo& info) { | 51 | std::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 | |||
| 434 | void EmitImageRead([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 449 | void 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 | ||
| 440 | void EmitImageWrite([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, | 461 | void 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 | ||
| 447 | void EmitBindlessImageSampleImplicitLod(EmitContext&) { | 470 | void EmitBindlessImageSampleImplicitLod(EmitContext&) { |