summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-01-06 11:43:13 -0400
committerGravatar FernandoS272020-01-24 16:43:31 -0400
commit2b02f29a2ddfe40639ea0f855bdf257beca59e65 (patch)
treec0efeb4b23ecaf03b6f4fdd6b82f923dd7a01b20 /src
parentShader_IR: deduce size of indexed samplers (diff)
downloadyuzu-2b02f29a2ddfe40639ea0f855bdf257beca59e65.tar.gz
yuzu-2b02f29a2ddfe40639ea0f855bdf257beca59e65.tar.xz
yuzu-2b02f29a2ddfe40639ea0f855bdf257beca59e65.zip
GL Backend: Introduce indexed samplers into the GL backend
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp34
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp15
2 files changed, 39 insertions, 10 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index c428f06e4..362942e09 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -55,16 +55,20 @@ namespace {
55 55
56template <typename Engine, typename Entry> 56template <typename Engine, typename Entry>
57Tegra::Texture::FullTextureInfo GetTextureInfo(const Engine& engine, const Entry& entry, 57Tegra::Texture::FullTextureInfo GetTextureInfo(const Engine& engine, const Entry& entry,
58 Tegra::Engines::ShaderType shader_type) { 58 Tegra::Engines::ShaderType shader_type,
59 std::size_t index = 0) {
59 if (entry.IsBindless()) { 60 if (entry.IsBindless()) {
60 const Tegra::Texture::TextureHandle tex_handle = 61 const Tegra::Texture::TextureHandle tex_handle =
61 engine.AccessConstBuffer32(shader_type, entry.GetBuffer(), entry.GetOffset()); 62 engine.AccessConstBuffer32(shader_type, entry.GetBuffer(), entry.GetOffset());
62 return engine.GetTextureInfo(tex_handle); 63 return engine.GetTextureInfo(tex_handle);
63 } 64 }
65 const auto& gpu_profile = engine.AccessGuestDriverProfile();
66 const u32 offset =
67 entry.GetOffset() + static_cast<u32>(index * gpu_profile.GetTextureHandlerSize());
64 if constexpr (std::is_same_v<Engine, Tegra::Engines::Maxwell3D>) { 68 if constexpr (std::is_same_v<Engine, Tegra::Engines::Maxwell3D>) {
65 return engine.GetStageTexture(shader_type, entry.GetOffset()); 69 return engine.GetStageTexture(shader_type, offset);
66 } else { 70 } else {
67 return engine.GetTexture(entry.GetOffset()); 71 return engine.GetTexture(offset);
68 } 72 }
69} 73}
70 74
@@ -942,8 +946,15 @@ void RasterizerOpenGL::SetupDrawTextures(std::size_t stage_index, const Shader&
942 u32 binding = device.GetBaseBindings(stage_index).sampler; 946 u32 binding = device.GetBaseBindings(stage_index).sampler;
943 for (const auto& entry : shader->GetShaderEntries().samplers) { 947 for (const auto& entry : shader->GetShaderEntries().samplers) {
944 const auto shader_type = static_cast<Tegra::Engines::ShaderType>(stage_index); 948 const auto shader_type = static_cast<Tegra::Engines::ShaderType>(stage_index);
945 const auto texture = GetTextureInfo(maxwell3d, entry, shader_type); 949 if (!entry.IsIndexed()) {
946 SetupTexture(binding++, texture, entry); 950 const auto texture = GetTextureInfo(maxwell3d, entry, shader_type);
951 SetupTexture(binding++, texture, entry);
952 } else {
953 for (std::size_t i = 0; i < entry.Size(); ++i) {
954 const auto texture = GetTextureInfo(maxwell3d, entry, shader_type, i);
955 SetupTexture(binding++, texture, entry);
956 }
957 }
947 } 958 }
948} 959}
949 960
@@ -952,8 +963,17 @@ void RasterizerOpenGL::SetupComputeTextures(const Shader& kernel) {
952 const auto& compute = system.GPU().KeplerCompute(); 963 const auto& compute = system.GPU().KeplerCompute();
953 u32 binding = 0; 964 u32 binding = 0;
954 for (const auto& entry : kernel->GetShaderEntries().samplers) { 965 for (const auto& entry : kernel->GetShaderEntries().samplers) {
955 const auto texture = GetTextureInfo(compute, entry, Tegra::Engines::ShaderType::Compute); 966 if (!entry.IsIndexed()) {
956 SetupTexture(binding++, texture, entry); 967 const auto texture =
968 GetTextureInfo(compute, entry, Tegra::Engines::ShaderType::Compute);
969 SetupTexture(binding++, texture, entry);
970 } else {
971 for (std::size_t i = 0; i < entry.Size(); ++i) {
972 const auto texture =
973 GetTextureInfo(compute, entry, Tegra::Engines::ShaderType::Compute, i);
974 SetupTexture(binding++, texture, entry);
975 }
976 }
957 } 977 }
958} 978}
959 979
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 2996aaf08..4b35396f9 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -655,7 +655,8 @@ private:
655 u32 binding = device.GetBaseBindings(stage).sampler; 655 u32 binding = device.GetBaseBindings(stage).sampler;
656 for (const auto& sampler : ir.GetSamplers()) { 656 for (const auto& sampler : ir.GetSamplers()) {
657 const std::string name = GetSampler(sampler); 657 const std::string name = GetSampler(sampler);
658 const std::string description = fmt::format("layout (binding = {}) uniform", binding++); 658 const std::string description = fmt::format("layout (binding = {}) uniform", binding);
659 binding += sampler.IsIndexed() ? sampler.Size() : 1;
659 660
660 std::string sampler_type = [&]() { 661 std::string sampler_type = [&]() {
661 if (sampler.IsBuffer()) { 662 if (sampler.IsBuffer()) {
@@ -682,7 +683,11 @@ private:
682 sampler_type += "Shadow"; 683 sampler_type += "Shadow";
683 } 684 }
684 685
685 code.AddLine("{} {} {};", description, sampler_type, name); 686 if (!sampler.IsIndexed()) {
687 code.AddLine("{} {} {};", description, sampler_type, name);
688 } else {
689 code.AddLine("{} {} {}[{}];", description, sampler_type, name, sampler.Size());
690 }
686 } 691 }
687 if (!ir.GetSamplers().empty()) { 692 if (!ir.GetSamplers().empty()) {
688 code.AddNewLine(); 693 code.AddNewLine();
@@ -1099,7 +1104,11 @@ private:
1099 } else if (!meta->ptp.empty()) { 1104 } else if (!meta->ptp.empty()) {
1100 expr += "Offsets"; 1105 expr += "Offsets";
1101 } 1106 }
1102 expr += '(' + GetSampler(meta->sampler) + ", "; 1107 if (!meta->sampler.IsIndexed()) {
1108 expr += '(' + GetSampler(meta->sampler) + ", ";
1109 } else {
1110 expr += '(' + GetSampler(meta->sampler) + "[0], ";
1111 }
1103 expr += coord_constructors.at(count + (has_array ? 1 : 0) + 1112 expr += coord_constructors.at(count + (has_array ? 1 : 0) +
1104 (has_shadow && !separate_dc ? 1 : 0) - 1); 1113 (has_shadow && !separate_dc ? 1 : 0) - 1);
1105 expr += '('; 1114 expr += '(';