summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
authorGravatar bunnei2019-06-05 18:07:23 -0400
committerGravatar GitHub2019-06-05 18:07:23 -0400
commit55c50291711f320c64c852fb82706a66e161452e (patch)
tree77aa7363d17892fa4e304aba5b6a0a314d2cb1a0 /src/video_core
parentMerge pull request #2419 from DarkLordZach/srv-lr-iface (diff)
parentgl_shader_decompiler: Remove guest "position" varying (diff)
downloadyuzu-55c50291711f320c64c852fb82706a66e161452e.tar.gz
yuzu-55c50291711f320c64c852fb82706a66e161452e.tar.xz
yuzu-55c50291711f320c64c852fb82706a66e161452e.zip
Merge pull request #2540 from ReinUsesLisp/remove-guest-position
gl_shader_decompiler: Remove guest "position" varying
Diffstat (limited to 'src/video_core')
-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 3b61bf77f..29de5c9db 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
@@ -650,10 +649,14 @@ private:
650 649
651 switch (attribute) { 650 switch (attribute) {
652 case Attribute::Index::Position: 651 case Attribute::Index::Position:
653 if (stage != ShaderStage::Fragment) { 652 switch (stage) {
654 return GeometryPass("position") + GetSwizzle(element); 653 case ShaderStage::Geometry:
655 } else { 654 return fmt::format("gl_in[ftou({})].gl_Position{}", Visit(buffer),
655 GetSwizzle(element));
656 case ShaderStage::Fragment:
656 return element == 3 ? "1.0f" : ("gl_FragCoord"s + GetSwizzle(element)); 657 return element == 3 ? "1.0f" : ("gl_FragCoord"s + GetSwizzle(element));
658 default:
659 UNREACHABLE();
657 } 660 }
658 case Attribute::Index::PointCoord: 661 case Attribute::Index::PointCoord:
659 switch (element) { 662 switch (element) {
@@ -938,7 +941,7 @@ private:
938 target = [&]() -> std::string { 941 target = [&]() -> std::string {
939 switch (const auto attribute = abuf->GetIndex(); abuf->GetIndex()) { 942 switch (const auto attribute = abuf->GetIndex(); abuf->GetIndex()) {
940 case Attribute::Index::Position: 943 case Attribute::Index::Position:
941 return "position"s + GetSwizzle(abuf->GetElement()); 944 return "gl_Position"s + GetSwizzle(abuf->GetElement());
942 case Attribute::Index::PointSize: 945 case Attribute::Index::PointSize:
943 return "gl_PointSize"; 946 return "gl_PointSize";
944 case Attribute::Index::ClipDistances0123: 947 case Attribute::Index::ClipDistances0123:
@@ -1523,9 +1526,7 @@ private:
1523 1526
1524 // If a geometry shader is attached, it will always flip (it's the last stage before 1527 // If a geometry shader is attached, it will always flip (it's the last stage before
1525 // fragment). For more info about flipping, refer to gl_shader_gen.cpp. 1528 // fragment). For more info about flipping, refer to gl_shader_gen.cpp.
1526 code.AddLine("position.xy *= viewport_flip.xy;"); 1529 code.AddLine("gl_Position.xy *= viewport_flip.xy;");
1527 code.AddLine("gl_Position = position;");
1528 code.AddLine("position.w = 1.0;");
1529 code.AddLine("EmitVertex();"); 1530 code.AddLine("EmitVertex();");
1530 return {}; 1531 return {};
1531 } 1532 }
@@ -1763,8 +1764,7 @@ private:
1763 } 1764 }
1764 1765
1765 u32 GetNumPhysicalVaryings() const { 1766 u32 GetNumPhysicalVaryings() const {
1766 return std::min<u32>(device.GetMaxVaryings() - GENERIC_VARYING_START_LOCATION, 1767 return std::min<u32>(device.GetMaxVaryings(), Maxwell::NumVaryings);
1767 Maxwell::NumVaryings);
1768 } 1768 }
1769 1769
1770 const Device& device; 1770 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