summaryrefslogtreecommitdiff
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2020-04-16 01:34:45 -0300
committerGravatar ReinUsesLisp2020-04-23 18:00:06 -0300
commit72deb773fdcc59b1df9752de4e846422b7bb5280 (patch)
tree524006956b6dbb6789831652129013e54f185f16 /src/video_core/renderer_opengl
parentMerge pull request #3768 from H27CK/cmd-title-fmt (diff)
downloadyuzu-72deb773fdcc59b1df9752de4e846422b7bb5280.tar.gz
yuzu-72deb773fdcc59b1df9752de4e846422b7bb5280.tar.xz
yuzu-72deb773fdcc59b1df9752de4e846422b7bb5280.zip
shader_ir: Turn classes into data structures
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp24
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp52
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.h33
3 files changed, 44 insertions, 65 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 4c16c89d2..0719f2407 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -59,14 +59,12 @@ constexpr std::size_t NumSupportedVertexAttributes = 16;
59template <typename Engine, typename Entry> 59template <typename Engine, typename Entry>
60Tegra::Texture::FullTextureInfo GetTextureInfo(const Engine& engine, const Entry& entry, 60Tegra::Texture::FullTextureInfo GetTextureInfo(const Engine& engine, const Entry& entry,
61 ShaderType shader_type, std::size_t index = 0) { 61 ShaderType shader_type, std::size_t index = 0) {
62 if (entry.IsBindless()) { 62 if (entry.is_bindless) {
63 const Tegra::Texture::TextureHandle tex_handle = 63 const auto tex_handle = engine.AccessConstBuffer32(shader_type, entry.buffer, entry.offset);
64 engine.AccessConstBuffer32(shader_type, entry.GetBuffer(), entry.GetOffset());
65 return engine.GetTextureInfo(tex_handle); 64 return engine.GetTextureInfo(tex_handle);
66 } 65 }
67 const auto& gpu_profile = engine.AccessGuestDriverProfile(); 66 const auto& gpu_profile = engine.AccessGuestDriverProfile();
68 const u32 offset = 67 const u32 offset = entry.offset + static_cast<u32>(index * gpu_profile.GetTextureHandlerSize());
69 entry.GetOffset() + static_cast<u32>(index * gpu_profile.GetTextureHandlerSize());
70 if constexpr (std::is_same_v<Engine, Tegra::Engines::Maxwell3D>) { 68 if constexpr (std::is_same_v<Engine, Tegra::Engines::Maxwell3D>) {
71 return engine.GetStageTexture(shader_type, offset); 69 return engine.GetStageTexture(shader_type, offset);
72 } else { 70 } else {
@@ -829,9 +827,9 @@ void RasterizerOpenGL::SetupDrawGlobalMemory(std::size_t stage_index, const Shad
829 827
830 u32 binding = device.GetBaseBindings(stage_index).shader_storage_buffer; 828 u32 binding = device.GetBaseBindings(stage_index).shader_storage_buffer;
831 for (const auto& entry : shader->GetEntries().global_memory_entries) { 829 for (const auto& entry : shader->GetEntries().global_memory_entries) {
832 const auto addr{cbufs.const_buffers[entry.GetCbufIndex()].address + entry.GetCbufOffset()}; 830 const GPUVAddr addr{cbufs.const_buffers[entry.cbuf_index].address + entry.cbuf_offset};
833 const auto gpu_addr{memory_manager.Read<u64>(addr)}; 831 const GPUVAddr gpu_addr{memory_manager.Read<u64>(addr)};
834 const auto size{memory_manager.Read<u32>(addr + 8)}; 832 const u32 size{memory_manager.Read<u32>(addr + 8)};
835 SetupGlobalMemory(binding++, entry, gpu_addr, size); 833 SetupGlobalMemory(binding++, entry, gpu_addr, size);
836 } 834 }
837} 835}
@@ -843,7 +841,7 @@ void RasterizerOpenGL::SetupComputeGlobalMemory(const Shader& kernel) {
843 841
844 u32 binding = 0; 842 u32 binding = 0;
845 for (const auto& entry : kernel->GetEntries().global_memory_entries) { 843 for (const auto& entry : kernel->GetEntries().global_memory_entries) {
846 const auto addr{cbufs[entry.GetCbufIndex()].Address() + entry.GetCbufOffset()}; 844 const auto addr{cbufs[entry.cbuf_index].Address() + entry.cbuf_offset};
847 const auto gpu_addr{memory_manager.Read<u64>(addr)}; 845 const auto gpu_addr{memory_manager.Read<u64>(addr)};
848 const auto size{memory_manager.Read<u32>(addr + 8)}; 846 const auto size{memory_manager.Read<u32>(addr + 8)};
849 SetupGlobalMemory(binding++, entry, gpu_addr, size); 847 SetupGlobalMemory(binding++, entry, gpu_addr, size);
@@ -854,7 +852,7 @@ void RasterizerOpenGL::SetupGlobalMemory(u32 binding, const GlobalMemoryEntry& e
854 GPUVAddr gpu_addr, std::size_t size) { 852 GPUVAddr gpu_addr, std::size_t size) {
855 const auto alignment{device.GetShaderStorageBufferAlignment()}; 853 const auto alignment{device.GetShaderStorageBufferAlignment()};
856 const auto [ssbo, buffer_offset] = 854 const auto [ssbo, buffer_offset] =
857 buffer_cache.UploadMemory(gpu_addr, size, alignment, entry.IsWritten()); 855 buffer_cache.UploadMemory(gpu_addr, size, alignment, entry.is_written);
858 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, binding, ssbo, buffer_offset, 856 glBindBufferRange(GL_SHADER_STORAGE_BUFFER, binding, ssbo, buffer_offset,
859 static_cast<GLsizeiptr>(size)); 857 static_cast<GLsizeiptr>(size));
860} 858}
@@ -865,7 +863,7 @@ void RasterizerOpenGL::SetupDrawTextures(std::size_t stage_index, const Shader&
865 u32 binding = device.GetBaseBindings(stage_index).sampler; 863 u32 binding = device.GetBaseBindings(stage_index).sampler;
866 for (const auto& entry : shader->GetEntries().samplers) { 864 for (const auto& entry : shader->GetEntries().samplers) {
867 const auto shader_type = static_cast<ShaderType>(stage_index); 865 const auto shader_type = static_cast<ShaderType>(stage_index);
868 for (std::size_t i = 0; i < entry.Size(); ++i) { 866 for (std::size_t i = 0; i < entry.size; ++i) {
869 const auto texture = GetTextureInfo(maxwell3d, entry, shader_type, i); 867 const auto texture = GetTextureInfo(maxwell3d, entry, shader_type, i);
870 SetupTexture(binding++, texture, entry); 868 SetupTexture(binding++, texture, entry);
871 } 869 }
@@ -877,7 +875,7 @@ void RasterizerOpenGL::SetupComputeTextures(const Shader& kernel) {
877 const auto& compute = system.GPU().KeplerCompute(); 875 const auto& compute = system.GPU().KeplerCompute();
878 u32 binding = 0; 876 u32 binding = 0;
879 for (const auto& entry : kernel->GetEntries().samplers) { 877 for (const auto& entry : kernel->GetEntries().samplers) {
880 for (std::size_t i = 0; i < entry.Size(); ++i) { 878 for (std::size_t i = 0; i < entry.size; ++i) {
881 const auto texture = GetTextureInfo(compute, entry, ShaderType::Compute, i); 879 const auto texture = GetTextureInfo(compute, entry, ShaderType::Compute, i);
882 SetupTexture(binding++, texture, entry); 880 SetupTexture(binding++, texture, entry);
883 } 881 }
@@ -934,7 +932,7 @@ void RasterizerOpenGL::SetupImage(u32 binding, const Tegra::Texture::TICEntry& t
934 if (!tic.IsBuffer()) { 932 if (!tic.IsBuffer()) {
935 view->ApplySwizzle(tic.x_source, tic.y_source, tic.z_source, tic.w_source); 933 view->ApplySwizzle(tic.x_source, tic.y_source, tic.z_source, tic.w_source);
936 } 934 }
937 if (entry.IsWritten()) { 935 if (entry.is_written) {
938 view->MarkAsModified(texture_cache.Tick()); 936 view->MarkAsModified(texture_cache.Tick());
939 } 937 }
940 glBindImageTexture(binding, view->GetTexture(), 0, GL_TRUE, 0, GL_READ_WRITE, 938 glBindImageTexture(binding, view->GetTexture(), 0, GL_TRUE, 0, GL_READ_WRITE,
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 0cd3ad7e1..1b474337a 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -870,13 +870,13 @@ private:
870 for (const auto& sampler : ir.GetSamplers()) { 870 for (const auto& sampler : ir.GetSamplers()) {
871 const std::string name = GetSampler(sampler); 871 const std::string name = GetSampler(sampler);
872 const std::string description = fmt::format("layout (binding = {}) uniform", binding); 872 const std::string description = fmt::format("layout (binding = {}) uniform", binding);
873 binding += sampler.IsIndexed() ? sampler.Size() : 1; 873 binding += sampler.is_indexed ? sampler.size : 1;
874 874
875 std::string sampler_type = [&]() { 875 std::string sampler_type = [&]() {
876 if (sampler.IsBuffer()) { 876 if (sampler.is_buffer) {
877 return "samplerBuffer"; 877 return "samplerBuffer";
878 } 878 }
879 switch (sampler.GetType()) { 879 switch (sampler.type) {
880 case Tegra::Shader::TextureType::Texture1D: 880 case Tegra::Shader::TextureType::Texture1D:
881 return "sampler1D"; 881 return "sampler1D";
882 case Tegra::Shader::TextureType::Texture2D: 882 case Tegra::Shader::TextureType::Texture2D:
@@ -890,17 +890,17 @@ private:
890 return "sampler2D"; 890 return "sampler2D";
891 } 891 }
892 }(); 892 }();
893 if (sampler.IsArray()) { 893 if (sampler.is_array) {
894 sampler_type += "Array"; 894 sampler_type += "Array";
895 } 895 }
896 if (sampler.IsShadow()) { 896 if (sampler.is_shadow) {
897 sampler_type += "Shadow"; 897 sampler_type += "Shadow";
898 } 898 }
899 899
900 if (!sampler.IsIndexed()) { 900 if (!sampler.is_indexed) {
901 code.AddLine("{} {} {};", description, sampler_type, name); 901 code.AddLine("{} {} {};", description, sampler_type, name);
902 } else { 902 } else {
903 code.AddLine("{} {} {}[{}];", description, sampler_type, name, sampler.Size()); 903 code.AddLine("{} {} {}[{}];", description, sampler_type, name, sampler.size);
904 } 904 }
905 } 905 }
906 if (!ir.GetSamplers().empty()) { 906 if (!ir.GetSamplers().empty()) {
@@ -946,14 +946,14 @@ private:
946 u32 binding = device.GetBaseBindings(stage).image; 946 u32 binding = device.GetBaseBindings(stage).image;
947 for (const auto& image : ir.GetImages()) { 947 for (const auto& image : ir.GetImages()) {
948 std::string qualifier = "coherent volatile"; 948 std::string qualifier = "coherent volatile";
949 if (image.IsRead() && !image.IsWritten()) { 949 if (image.is_read && !image.is_written) {
950 qualifier += " readonly"; 950 qualifier += " readonly";
951 } else if (image.IsWritten() && !image.IsRead()) { 951 } else if (image.is_written && !image.is_read) {
952 qualifier += " writeonly"; 952 qualifier += " writeonly";
953 } 953 }
954 954
955 const char* format = image.IsAtomic() ? "r32ui, " : ""; 955 const char* format = image.is_atomic ? "r32ui, " : "";
956 const char* type_declaration = GetImageTypeDeclaration(image.GetType()); 956 const char* type_declaration = GetImageTypeDeclaration(image.type);
957 code.AddLine("layout ({}binding = {}) {} uniform uimage{} {};", format, binding++, 957 code.AddLine("layout ({}binding = {}) {} uniform uimage{} {};", format, binding++,
958 qualifier, type_declaration, GetImage(image)); 958 qualifier, type_declaration, GetImage(image));
959 } 959 }
@@ -1337,8 +1337,8 @@ private:
1337 ASSERT(meta); 1337 ASSERT(meta);
1338 1338
1339 const std::size_t count = operation.GetOperandsCount(); 1339 const std::size_t count = operation.GetOperandsCount();
1340 const bool has_array = meta->sampler.IsArray(); 1340 const bool has_array = meta->sampler.is_array;
1341 const bool has_shadow = meta->sampler.IsShadow(); 1341 const bool has_shadow = meta->sampler.is_shadow;
1342 1342
1343 std::string expr = "texture" + function_suffix; 1343 std::string expr = "texture" + function_suffix;
1344 if (!meta->aoffi.empty()) { 1344 if (!meta->aoffi.empty()) {
@@ -1346,7 +1346,7 @@ private:
1346 } else if (!meta->ptp.empty()) { 1346 } else if (!meta->ptp.empty()) {
1347 expr += "Offsets"; 1347 expr += "Offsets";
1348 } 1348 }
1349 if (!meta->sampler.IsIndexed()) { 1349 if (!meta->sampler.is_indexed) {
1350 expr += '(' + GetSampler(meta->sampler) + ", "; 1350 expr += '(' + GetSampler(meta->sampler) + ", ";
1351 } else { 1351 } else {
1352 expr += '(' + GetSampler(meta->sampler) + '[' + Visit(meta->index).AsUint() + "], "; 1352 expr += '(' + GetSampler(meta->sampler) + '[' + Visit(meta->index).AsUint() + "], ";
@@ -1974,7 +1974,7 @@ private:
1974 1974
1975 std::string expr = GenerateTexture( 1975 std::string expr = GenerateTexture(
1976 operation, "", {TextureOffset{}, TextureArgument{Type::Float, meta->bias}}); 1976 operation, "", {TextureOffset{}, TextureArgument{Type::Float, meta->bias}});
1977 if (meta->sampler.IsShadow()) { 1977 if (meta->sampler.is_shadow) {
1978 expr = "vec4(" + expr + ')'; 1978 expr = "vec4(" + expr + ')';
1979 } 1979 }
1980 return {expr + GetSwizzle(meta->element), Type::Float}; 1980 return {expr + GetSwizzle(meta->element), Type::Float};
@@ -1986,7 +1986,7 @@ private:
1986 1986
1987 std::string expr = GenerateTexture( 1987 std::string expr = GenerateTexture(
1988 operation, "Lod", {TextureArgument{Type::Float, meta->lod}, TextureOffset{}}); 1988 operation, "Lod", {TextureArgument{Type::Float, meta->lod}, TextureOffset{}});
1989 if (meta->sampler.IsShadow()) { 1989 if (meta->sampler.is_shadow) {
1990 expr = "vec4(" + expr + ')'; 1990 expr = "vec4(" + expr + ')';
1991 } 1991 }
1992 return {expr + GetSwizzle(meta->element), Type::Float}; 1992 return {expr + GetSwizzle(meta->element), Type::Float};
@@ -1995,11 +1995,11 @@ private:
1995 Expression TextureGather(Operation operation) { 1995 Expression TextureGather(Operation operation) {
1996 const auto& meta = std::get<MetaTexture>(operation.GetMeta()); 1996 const auto& meta = std::get<MetaTexture>(operation.GetMeta());
1997 1997
1998 const auto type = meta.sampler.IsShadow() ? Type::Float : Type::Int; 1998 const auto type = meta.sampler.is_shadow ? Type::Float : Type::Int;
1999 const bool separate_dc = meta.sampler.IsShadow(); 1999 const bool separate_dc = meta.sampler.is_shadow;
2000 2000
2001 std::vector<TextureIR> ir; 2001 std::vector<TextureIR> ir;
2002 if (meta.sampler.IsShadow()) { 2002 if (meta.sampler.is_shadow) {
2003 ir = {TextureOffset{}}; 2003 ir = {TextureOffset{}};
2004 } else { 2004 } else {
2005 ir = {TextureOffset{}, TextureArgument{type, meta.component}}; 2005 ir = {TextureOffset{}, TextureArgument{type, meta.component}};
@@ -2044,7 +2044,7 @@ private:
2044 constexpr std::array constructors = {"int", "ivec2", "ivec3", "ivec4"}; 2044 constexpr std::array constructors = {"int", "ivec2", "ivec3", "ivec4"};
2045 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta()); 2045 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta());
2046 ASSERT(meta); 2046 ASSERT(meta);
2047 UNIMPLEMENTED_IF(meta->sampler.IsArray()); 2047 UNIMPLEMENTED_IF(meta->sampler.is_array);
2048 const std::size_t count = operation.GetOperandsCount(); 2048 const std::size_t count = operation.GetOperandsCount();
2049 2049
2050 std::string expr = "texelFetch("; 2050 std::string expr = "texelFetch(";
@@ -2065,7 +2065,7 @@ private:
2065 } 2065 }
2066 expr += ')'; 2066 expr += ')';
2067 2067
2068 if (meta->lod && !meta->sampler.IsBuffer()) { 2068 if (meta->lod && !meta->sampler.is_buffer) {
2069 expr += ", "; 2069 expr += ", ";
2070 expr += Visit(meta->lod).AsInt(); 2070 expr += Visit(meta->lod).AsInt();
2071 } 2071 }
@@ -2076,12 +2076,10 @@ private:
2076 } 2076 }
2077 2077
2078 Expression TextureGradient(Operation operation) { 2078 Expression TextureGradient(Operation operation) {
2079 const auto meta = std::get_if<MetaTexture>(&operation.GetMeta()); 2079 const auto& meta = std::get<MetaTexture>(operation.GetMeta());
2080 ASSERT(meta);
2081
2082 std::string expr = 2080 std::string expr =
2083 GenerateTexture(operation, "Grad", {TextureDerivates{}, TextureOffset{}}); 2081 GenerateTexture(operation, "Grad", {TextureDerivates{}, TextureOffset{}});
2084 return {std::move(expr) + GetSwizzle(meta->element), Type::Float}; 2082 return {std::move(expr) + GetSwizzle(meta.element), Type::Float};
2085 } 2083 }
2086 2084
2087 Expression ImageLoad(Operation operation) { 2085 Expression ImageLoad(Operation operation) {
@@ -2598,11 +2596,11 @@ private:
2598 } 2596 }
2599 2597
2600 std::string GetSampler(const Sampler& sampler) const { 2598 std::string GetSampler(const Sampler& sampler) const {
2601 return AppendSuffix(static_cast<u32>(sampler.GetIndex()), "sampler"); 2599 return AppendSuffix(sampler.index, "sampler");
2602 } 2600 }
2603 2601
2604 std::string GetImage(const Image& image) const { 2602 std::string GetImage(const Image& image) const {
2605 return AppendSuffix(static_cast<u32>(image.GetIndex()), "image"); 2603 return AppendSuffix(image.index, "image");
2606 } 2604 }
2607 2605
2608 std::string AppendSuffix(u32 index, std::string_view name) const { 2606 std::string AppendSuffix(u32 index, std::string_view name) const {
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.h b/src/video_core/renderer_opengl/gl_shader_decompiler.h
index e7dbd810c..e8a178764 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.h
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.h
@@ -33,36 +33,19 @@ public:
33 } 33 }
34 34
35private: 35private:
36 u32 index{}; 36 u32 index = 0;
37}; 37};
38 38
39class GlobalMemoryEntry { 39struct GlobalMemoryEntry {
40public: 40 constexpr explicit GlobalMemoryEntry(u32 cbuf_index, u32 cbuf_offset, bool is_read,
41 explicit GlobalMemoryEntry(u32 cbuf_index, u32 cbuf_offset, bool is_read, bool is_written) 41 bool is_written)
42 : cbuf_index{cbuf_index}, cbuf_offset{cbuf_offset}, is_read{is_read}, is_written{ 42 : cbuf_index{cbuf_index}, cbuf_offset{cbuf_offset}, is_read{is_read}, is_written{
43 is_written} {} 43 is_written} {}
44 44
45 u32 GetCbufIndex() const { 45 u32 cbuf_index = 0;
46 return cbuf_index; 46 u32 cbuf_offset = 0;
47 } 47 bool is_read = false;
48 48 bool is_written = false;
49 u32 GetCbufOffset() const {
50 return cbuf_offset;
51 }
52
53 bool IsRead() const {
54 return is_read;
55 }
56
57 bool IsWritten() const {
58 return is_written;
59 }
60
61private:
62 u32 cbuf_index{};
63 u32 cbuf_offset{};
64 bool is_read{};
65 bool is_written{};
66}; 49};
67 50
68struct ShaderEntries { 51struct ShaderEntries {