summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl/emit_context.cpp
diff options
context:
space:
mode:
authorGravatar ameerj2021-06-11 02:50:30 -0400
committerGravatar ameerj2021-07-22 21:51:38 -0400
commite81c73a8748ccfcde56acfee5630116c3950e479 (patch)
tree617a67d3512b228dbaa40b710700dfb79f7bc7bc /src/shader_recompiler/backend/glsl/emit_context.cpp
parentglsl: Remove Signed Integer variables (diff)
downloadyuzu-e81c73a8748ccfcde56acfee5630116c3950e479.tar.gz
yuzu-e81c73a8748ccfcde56acfee5630116c3950e479.tar.xz
yuzu-e81c73a8748ccfcde56acfee5630116c3950e479.zip
glsl: Address more feedback. Implement indexed texture reads
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index cbcf0a1eb..ed10eca8a 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -559,53 +559,45 @@ std::string EmitContext::DefineGlobalMemoryFunctions() {
559} 559}
560 560
561void EmitContext::SetupImages(Bindings& bindings) { 561void EmitContext::SetupImages(Bindings& bindings) {
562 image_buffer_bindings.reserve(info.image_buffer_descriptors.size()); 562 image_buffers.reserve(info.image_buffer_descriptors.size());
563 for (const auto& desc : info.image_buffer_descriptors) { 563 for (const auto& desc : info.image_buffer_descriptors) {
564 image_buffer_bindings.push_back(bindings.image); 564 image_buffers.push_back({bindings.image, desc.count});
565 const auto indices{bindings.image + desc.count};
566 const auto format{ImageFormatString(desc.format)}; 565 const auto format{ImageFormatString(desc.format)};
567 for (u32 index = bindings.image; index < indices; ++index) { 566 const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
568 header += fmt::format("layout(binding={}{}) uniform uimageBuffer img{};", 567 header += fmt::format("layout(binding={}{}) uniform uimageBuffer img{}{};", bindings.image,
569 bindings.image, format, index); 568 format, bindings.image, array_decorator);
570 }
571 bindings.image += desc.count; 569 bindings.image += desc.count;
572 } 570 }
573 image_bindings.reserve(info.image_descriptors.size()); 571 images.reserve(info.image_descriptors.size());
574 for (const auto& desc : info.image_descriptors) { 572 for (const auto& desc : info.image_descriptors) {
575 image_bindings.push_back(bindings.image); 573 images.push_back({bindings.image, desc.count});
576 const auto format{ImageFormatString(desc.format)}; 574 const auto format{ImageFormatString(desc.format)};
577 const auto image_type{ImageType(desc.type)}; 575 const auto image_type{ImageType(desc.type)};
578 const auto qualifier{desc.is_written ? "" : "readonly "}; 576 const auto qualifier{desc.is_written ? "" : "readonly "};
579 const auto indices{bindings.image + desc.count}; 577 const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
580 for (u32 index = bindings.image; index < indices; ++index) { 578 header += fmt::format("layout(binding={}{})uniform {}{} img{}{};", bindings.image, format,
581 header += fmt::format("layout(binding={}{})uniform {}{} img{};", bindings.image, format, 579 qualifier, image_type, bindings.image, array_decorator);
582 qualifier, image_type, index);
583 }
584 bindings.image += desc.count; 580 bindings.image += desc.count;
585 } 581 }
586} 582}
587 583
588void EmitContext::SetupTextures(Bindings& bindings) { 584void EmitContext::SetupTextures(Bindings& bindings) {
589 texture_buffer_bindings.reserve(info.texture_buffer_descriptors.size()); 585 texture_buffers.reserve(info.texture_buffer_descriptors.size());
590 for (const auto& desc : info.texture_buffer_descriptors) { 586 for (const auto& desc : info.texture_buffer_descriptors) {
591 texture_buffer_bindings.push_back(bindings.texture); 587 texture_buffers.push_back({bindings.texture, desc.count});
592 const auto sampler_type{SamplerType(TextureType::Buffer, false)}; 588 const auto sampler_type{SamplerType(TextureType::Buffer, false)};
593 const auto indices{bindings.texture + desc.count}; 589 const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
594 for (u32 index = bindings.texture; index < indices; ++index) { 590 header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture,
595 header += fmt::format("layout(binding={}) uniform {} tex{};", bindings.texture, 591 sampler_type, bindings.texture, array_decorator);
596 sampler_type, index);
597 }
598 bindings.texture += desc.count; 592 bindings.texture += desc.count;
599 } 593 }
600 texture_bindings.reserve(info.texture_descriptors.size()); 594 textures.reserve(info.texture_descriptors.size());
601 for (const auto& desc : info.texture_descriptors) { 595 for (const auto& desc : info.texture_descriptors) {
596 textures.push_back({bindings.texture, desc.count});
602 const auto sampler_type{SamplerType(desc.type, desc.is_depth)}; 597 const auto sampler_type{SamplerType(desc.type, desc.is_depth)};
603 texture_bindings.push_back(bindings.texture); 598 const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""};
604 const auto indices{bindings.texture + desc.count}; 599 header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture,
605 for (u32 index = bindings.texture; index < indices; ++index) { 600 sampler_type, bindings.texture, array_decorator);
606 header += fmt::format("layout(binding={}) uniform {} tex{};", bindings.texture,
607 sampler_type, index);
608 }
609 bindings.texture += desc.count; 601 bindings.texture += desc.count;
610 } 602 }
611} 603}