summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2019-06-03 01:01:34 -0300
committerGravatar ReinUsesLisp2019-06-03 01:01:34 -0300
commit0935c2d97ba57d2c28f49c3bde7b89d355019357 (patch)
tree11fa8f58f40a04f5852d320802052dad70d57e82 /src
parentinput_common/sdl/sdl_impl: Silence sign conversion warnings (diff)
downloadyuzu-0935c2d97ba57d2c28f49c3bde7b89d355019357.tar.gz
yuzu-0935c2d97ba57d2c28f49c3bde7b89d355019357.tar.xz
yuzu-0935c2d97ba57d2c28f49c3bde7b89d355019357.zip
gl_shader_decompiler: Remove guest "position" varying
"position" was being written but not read anywhere besides geometry shaders, where it had the same value as gl_Position. This commit replaces "position" with gl_Position, reducing the complexity of our code and the emitted GLSL code.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp38
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp19
2 files changed, 21 insertions, 36 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index e9f8d40db..1ca9825b4 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -45,7 +45,6 @@ struct TextureAoffi {};
45using TextureArgument = std::pair<Type, Node>; 45using TextureArgument = std::pair<Type, Node>;
46using TextureIR = std::variant<TextureAoffi, TextureArgument>; 46using TextureIR = std::variant<TextureAoffi, TextureArgument>;
47 47
48enum : u32 { POSITION_VARYING_LOCATION = 0, GENERIC_VARYING_START_LOCATION = 1 };
49constexpr u32 MAX_CONSTBUFFER_ELEMENTS = 48constexpr u32 MAX_CONSTBUFFER_ELEMENTS =
50 static_cast<u32>(RasterizerOpenGL::MaxConstbufferSize) / (4 * sizeof(float)); 49 static_cast<u32>(RasterizerOpenGL::MaxConstbufferSize) / (4 * sizeof(float));
51 50
@@ -247,6 +246,12 @@ private:
247 code.AddLine("layout ({}, max_vertices = {}) out;", topology, max_vertices); 246 code.AddLine("layout ({}, max_vertices = {}) out;", topology, max_vertices);
248 code.AddNewLine(); 247 code.AddNewLine();
249 248
249 code.AddLine("in gl_PerVertex {{");
250 ++code.scope;
251 code.AddLine("vec4 gl_Position;");
252 --code.scope;
253 code.AddLine("}} gl_in[];");
254
250 DeclareVertexRedeclarations(); 255 DeclareVertexRedeclarations();
251 } 256 }
252 257
@@ -349,7 +354,7 @@ private:
349 } 354 }
350 355
351 void DeclareInputAttribute(Attribute::Index index, bool skip_unused) { 356 void DeclareInputAttribute(Attribute::Index index, bool skip_unused) {
352 const u32 generic_index{GetGenericAttributeIndex(index)}; 357 const u32 location{GetGenericAttributeIndex(index)};
353 358
354 std::string name{GetInputAttribute(index)}; 359 std::string name{GetInputAttribute(index)};
355 if (stage == ShaderStage::Geometry) { 360 if (stage == ShaderStage::Geometry) {
@@ -358,19 +363,13 @@ private:
358 363
359 std::string suffix; 364 std::string suffix;
360 if (stage == ShaderStage::Fragment) { 365 if (stage == ShaderStage::Fragment) {
361 const auto input_mode{header.ps.GetAttributeUse(generic_index)}; 366 const auto input_mode{header.ps.GetAttributeUse(location)};
362 if (skip_unused && input_mode == AttributeUse::Unused) { 367 if (skip_unused && input_mode == AttributeUse::Unused) {
363 return; 368 return;
364 } 369 }
365 suffix = GetInputFlags(input_mode); 370 suffix = GetInputFlags(input_mode);
366 } 371 }
367 372
368 u32 location = generic_index;
369 if (stage != ShaderStage::Vertex) {
370 // If inputs are varyings, add an offset
371 location += GENERIC_VARYING_START_LOCATION;
372 }
373
374 code.AddLine("layout (location = {}) {} in vec4 {};", location, suffix, name); 373 code.AddLine("layout (location = {}) {} in vec4 {};", location, suffix, name);
375 } 374 }
376 375
@@ -395,7 +394,7 @@ private:
395 } 394 }
396 395
397 void DeclareOutputAttribute(Attribute::Index index) { 396 void DeclareOutputAttribute(Attribute::Index index) {
398 const u32 location{GetGenericAttributeIndex(index) + GENERIC_VARYING_START_LOCATION}; 397 const u32 location{GetGenericAttributeIndex(index)};
399 code.AddLine("layout (location = {}) out vec4 {};", location, GetOutputAttribute(index)); 398 code.AddLine("layout (location = {}) out vec4 {};", location, GetOutputAttribute(index));
400 } 399 }
401 400
@@ -633,10 +632,14 @@ private:
633 632
634 switch (attribute) { 633 switch (attribute) {
635 case Attribute::Index::Position: 634 case Attribute::Index::Position:
636 if (stage != ShaderStage::Fragment) { 635 switch (stage) {
637 return GeometryPass("position") + GetSwizzle(element); 636 case ShaderStage::Geometry:
638 } else { 637 return fmt::format("gl_in[ftou({})].gl_Position{}", Visit(buffer),
638 GetSwizzle(element));
639 case ShaderStage::Fragment:
639 return element == 3 ? "1.0f" : ("gl_FragCoord"s + GetSwizzle(element)); 640 return element == 3 ? "1.0f" : ("gl_FragCoord"s + GetSwizzle(element));
641 default:
642 UNREACHABLE();
640 } 643 }
641 case Attribute::Index::PointCoord: 644 case Attribute::Index::PointCoord:
642 switch (element) { 645 switch (element) {
@@ -921,7 +924,7 @@ private:
921 target = [&]() -> std::string { 924 target = [&]() -> std::string {
922 switch (const auto attribute = abuf->GetIndex(); abuf->GetIndex()) { 925 switch (const auto attribute = abuf->GetIndex(); abuf->GetIndex()) {
923 case Attribute::Index::Position: 926 case Attribute::Index::Position:
924 return "position"s + GetSwizzle(abuf->GetElement()); 927 return "gl_Position"s + GetSwizzle(abuf->GetElement());
925 case Attribute::Index::PointSize: 928 case Attribute::Index::PointSize:
926 return "gl_PointSize"; 929 return "gl_PointSize";
927 case Attribute::Index::ClipDistances0123: 930 case Attribute::Index::ClipDistances0123:
@@ -1506,9 +1509,7 @@ private:
1506 1509
1507 // If a geometry shader is attached, it will always flip (it's the last stage before 1510 // If a geometry shader is attached, it will always flip (it's the last stage before
1508 // fragment). For more info about flipping, refer to gl_shader_gen.cpp. 1511 // fragment). For more info about flipping, refer to gl_shader_gen.cpp.
1509 code.AddLine("position.xy *= viewport_flip.xy;"); 1512 code.AddLine("gl_Position.xy *= viewport_flip.xy;");
1510 code.AddLine("gl_Position = position;");
1511 code.AddLine("position.w = 1.0;");
1512 code.AddLine("EmitVertex();"); 1513 code.AddLine("EmitVertex();");
1513 return {}; 1514 return {};
1514 } 1515 }
@@ -1746,8 +1747,7 @@ private:
1746 } 1747 }
1747 1748
1748 u32 GetNumPhysicalVaryings() const { 1749 u32 GetNumPhysicalVaryings() const {
1749 return std::min<u32>(device.GetMaxVaryings() - GENERIC_VARYING_START_LOCATION, 1750 return std::min<u32>(device.GetMaxVaryings(), Maxwell::NumVaryings);
1750 Maxwell::NumVaryings);
1751 } 1751 }
1752 1752
1753 const Device& device; 1753 const Device& device;
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index d2bb705a9..c845b29aa 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -23,8 +23,6 @@ ProgramResult GenerateVertexShader(const Device& device, const ShaderSetup& setu
23 out += GetCommonDeclarations(); 23 out += GetCommonDeclarations();
24 24
25 out += R"( 25 out += R"(
26layout (location = 0) out vec4 position;
27
28layout (std140, binding = EMULATION_UBO_BINDING) uniform vs_config { 26layout (std140, binding = EMULATION_UBO_BINDING) uniform vs_config {
29 vec4 viewport_flip; 27 vec4 viewport_flip;
30 uvec4 config_pack; // instance_id, flip_stage, y_direction, padding 28 uvec4 config_pack; // instance_id, flip_stage, y_direction, padding
@@ -48,7 +46,6 @@ layout (std140, binding = EMULATION_UBO_BINDING) uniform vs_config {
48 46
49 out += R"( 47 out += R"(
50void main() { 48void main() {
51 position = vec4(0.0, 0.0, 0.0, 0.0);
52 execute_vertex(); 49 execute_vertex();
53)"; 50)";
54 51
@@ -59,19 +56,12 @@ void main() {
59 out += R"( 56 out += R"(
60 57
61 // Set Position Y direction 58 // Set Position Y direction
62 position.y *= utof(config_pack[2]); 59 gl_Position.y *= utof(config_pack[2]);
63 // Check if the flip stage is VertexB 60 // Check if the flip stage is VertexB
64 // Config pack's second value is flip_stage 61 // Config pack's second value is flip_stage
65 if (config_pack[1] == 1) { 62 if (config_pack[1] == 1) {
66 // Viewport can be flipped, which is unsupported by glViewport 63 // Viewport can be flipped, which is unsupported by glViewport
67 position.xy *= viewport_flip.xy; 64 gl_Position.xy *= viewport_flip.xy;
68 }
69 gl_Position = position;
70
71 // TODO(bunnei): This is likely a hack, position.w should be interpolated as 1.0
72 // For now, this is here to bring order in lieu of proper emulation
73 if (config_pack[1] == 1) {
74 position.w = 1.0;
75 } 65 }
76})"; 66})";
77 67
@@ -85,9 +75,6 @@ ProgramResult GenerateGeometryShader(const Device& device, const ShaderSetup& se
85 out += GetCommonDeclarations(); 75 out += GetCommonDeclarations();
86 76
87 out += R"( 77 out += R"(
88layout (location = 0) in vec4 gs_position[];
89layout (location = 0) out vec4 position;
90
91layout (std140, binding = EMULATION_UBO_BINDING) uniform gs_config { 78layout (std140, binding = EMULATION_UBO_BINDING) uniform gs_config {
92 vec4 viewport_flip; 79 vec4 viewport_flip;
93 uvec4 config_pack; // instance_id, flip_stage, y_direction, padding 80 uvec4 config_pack; // instance_id, flip_stage, y_direction, padding
@@ -124,8 +111,6 @@ layout (location = 5) out vec4 FragColor5;
124layout (location = 6) out vec4 FragColor6; 111layout (location = 6) out vec4 FragColor6;
125layout (location = 7) out vec4 FragColor7; 112layout (location = 7) out vec4 FragColor7;
126 113
127layout (location = 0) in noperspective vec4 position;
128
129layout (std140, binding = EMULATION_UBO_BINDING) uniform fs_config { 114layout (std140, binding = EMULATION_UBO_BINDING) uniform fs_config {
130 vec4 viewport_flip; 115 vec4 viewport_flip;
131 uvec4 config_pack; // instance_id, flip_stage, y_direction, padding 116 uvec4 config_pack; // instance_id, flip_stage, y_direction, padding