summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_decompiler.cpp63
1 files changed, 57 insertions, 6 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
index 3adf7f0cb..f53d7021e 100644
--- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp
@@ -366,10 +366,19 @@ constexpr bool IsGenericAttribute(Attribute::Index index) {
366 return index >= Attribute::Index::Attribute_0 && index <= Attribute::Index::Attribute_31; 366 return index >= Attribute::Index::Attribute_0 && index <= Attribute::Index::Attribute_31;
367} 367}
368 368
369constexpr bool IsLegacyTexCoord(Attribute::Index index) {
370 return static_cast<int>(index) >= static_cast<int>(Attribute::Index::TexCoord_0) &&
371 static_cast<int>(index) <= static_cast<int>(Attribute::Index::TexCoord_7);
372}
373
369constexpr Attribute::Index ToGenericAttribute(u64 value) { 374constexpr Attribute::Index ToGenericAttribute(u64 value) {
370 return static_cast<Attribute::Index>(value + static_cast<u64>(Attribute::Index::Attribute_0)); 375 return static_cast<Attribute::Index>(value + static_cast<u64>(Attribute::Index::Attribute_0));
371} 376}
372 377
378constexpr int GetLegacyTexCoordIndex(Attribute::Index index) {
379 return static_cast<int>(index) - static_cast<int>(Attribute::Index::TexCoord_0);
380}
381
373u32 GetGenericAttributeIndex(Attribute::Index index) { 382u32 GetGenericAttributeIndex(Attribute::Index index) {
374 ASSERT(IsGenericAttribute(index)); 383 ASSERT(IsGenericAttribute(index));
375 return static_cast<u32>(index) - static_cast<u32>(Attribute::Index::Attribute_0); 384 return static_cast<u32>(index) - static_cast<u32>(Attribute::Index::Attribute_0);
@@ -502,7 +511,7 @@ private:
502 if (!identifier.empty()) { 511 if (!identifier.empty()) {
503 code.AddLine("// {}", identifier); 512 code.AddLine("// {}", identifier);
504 } 513 }
505 code.AddLine("#version 440 core"); 514 code.AddLine("#version 440 {}", ir.UsesLegacyVaryings() ? "compatibility" : "core");
506 code.AddLine("#extension GL_ARB_separate_shader_objects : enable"); 515 code.AddLine("#extension GL_ARB_separate_shader_objects : enable");
507 if (device.HasShaderBallot()) { 516 if (device.HasShaderBallot()) {
508 code.AddLine("#extension GL_ARB_shader_ballot : require"); 517 code.AddLine("#extension GL_ARB_shader_ballot : require");
@@ -564,6 +573,16 @@ private:
564 if (stage != ShaderType::Fragment) { 573 if (stage != ShaderType::Fragment) {
565 return; 574 return;
566 } 575 }
576 if (ir.UsesLegacyVaryings()) {
577 code.AddLine("in gl_PerFragment {{");
578 ++code.scope;
579 code.AddLine("vec4 gl_TexCoord[8];");
580 code.AddLine("vec4 gl_Color;");
581 code.AddLine("vec4 gl_SecondaryColor;");
582 --code.scope;
583 code.AddLine("}};");
584 }
585
567 for (u32 rt = 0; rt < Maxwell::NumRenderTargets; ++rt) { 586 for (u32 rt = 0; rt < Maxwell::NumRenderTargets; ++rt) {
568 code.AddLine("layout (location = {}) out vec4 frag_color{};", rt, rt); 587 code.AddLine("layout (location = {}) out vec4 frag_color{};", rt, rt);
569 } 588 }
@@ -628,6 +647,14 @@ private:
628 code.AddLine("int gl_VertexID;"); 647 code.AddLine("int gl_VertexID;");
629 } 648 }
630 649
650 if (ir.UsesLegacyVaryings()) {
651 code.AddLine("vec4 gl_TexCoord[8];");
652 code.AddLine("vec4 gl_FrontColor;");
653 code.AddLine("vec4 gl_FrontSecondaryColor;");
654 code.AddLine("vec4 gl_BackColor;");
655 code.AddLine("vec4 gl_BackSecondaryColor;");
656 }
657
631 --code.scope; 658 --code.scope;
632 code.AddLine("}};"); 659 code.AddLine("}};");
633 code.AddNewLine(); 660 code.AddNewLine();
@@ -1131,6 +1158,10 @@ private:
1131 default: 1158 default:
1132 UNREACHABLE(); 1159 UNREACHABLE();
1133 } 1160 }
1161 case Attribute::Index::FrontColor:
1162 return {"gl_Color"s + GetSwizzle(element), Type::Float};
1163 case Attribute::Index::FrontSecondaryColor:
1164 return {"gl_SecondaryColor"s + GetSwizzle(element), Type::Float};
1134 case Attribute::Index::PointCoord: 1165 case Attribute::Index::PointCoord:
1135 switch (element) { 1166 switch (element) {
1136 case 0: 1167 case 0:
@@ -1171,6 +1202,12 @@ private:
1171 return {GeometryPass(GetGenericInputAttribute(attribute)) + GetSwizzle(element), 1202 return {GeometryPass(GetGenericInputAttribute(attribute)) + GetSwizzle(element),
1172 Type::Float}; 1203 Type::Float};
1173 } 1204 }
1205 if (IsLegacyTexCoord(attribute)) {
1206 UNIMPLEMENTED_IF(stage == ShaderType::Geometry);
1207 return {fmt::format("gl_TexCoord[{}]{}", GetLegacyTexCoordIndex(attribute),
1208 GetSwizzle(element)),
1209 Type::Float};
1210 }
1174 break; 1211 break;
1175 } 1212 }
1176 UNIMPLEMENTED_MSG("Unhandled input attribute: {}", static_cast<u32>(attribute)); 1213 UNIMPLEMENTED_MSG("Unhandled input attribute: {}", static_cast<u32>(attribute));
@@ -1209,11 +1246,12 @@ private:
1209 } 1246 }
1210 1247
1211 std::optional<Expression> GetOutputAttribute(const AbufNode* abuf) { 1248 std::optional<Expression> GetOutputAttribute(const AbufNode* abuf) {
1249 const u32 element = abuf->GetElement();
1212 switch (const auto attribute = abuf->GetIndex()) { 1250 switch (const auto attribute = abuf->GetIndex()) {
1213 case Attribute::Index::Position: 1251 case Attribute::Index::Position:
1214 return {{"gl_Position"s + GetSwizzle(abuf->GetElement()), Type::Float}}; 1252 return {{"gl_Position"s + GetSwizzle(element), Type::Float}};
1215 case Attribute::Index::LayerViewportPointSize: 1253 case Attribute::Index::LayerViewportPointSize:
1216 switch (abuf->GetElement()) { 1254 switch (element) {
1217 case 0: 1255 case 0:
1218 UNIMPLEMENTED(); 1256 UNIMPLEMENTED();
1219 return {}; 1257 return {};
@@ -1231,13 +1269,26 @@ private:
1231 return {{"gl_PointSize", Type::Float}}; 1269 return {{"gl_PointSize", Type::Float}};
1232 } 1270 }
1233 return {}; 1271 return {};
1272 case Attribute::Index::FrontColor:
1273 return {{"gl_FrontColor"s + GetSwizzle(element), Type::Float}};
1274 case Attribute::Index::FrontSecondaryColor:
1275 return {{"gl_FrontSecondaryColor"s + GetSwizzle(element), Type::Float}};
1276 case Attribute::Index::BackColor:
1277 return {{"gl_BackColor"s + GetSwizzle(element), Type::Float}};
1278 case Attribute::Index::BackSecondaryColor:
1279 return {{"gl_BackSecondaryColor"s + GetSwizzle(element), Type::Float}};
1234 case Attribute::Index::ClipDistances0123: 1280 case Attribute::Index::ClipDistances0123:
1235 return {{fmt::format("gl_ClipDistance[{}]", abuf->GetElement()), Type::Float}}; 1281 return {{fmt::format("gl_ClipDistance[{}]", element), Type::Float}};
1236 case Attribute::Index::ClipDistances4567: 1282 case Attribute::Index::ClipDistances4567:
1237 return {{fmt::format("gl_ClipDistance[{}]", abuf->GetElement() + 4), Type::Float}}; 1283 return {{fmt::format("gl_ClipDistance[{}]", element + 4), Type::Float}};
1238 default: 1284 default:
1239 if (IsGenericAttribute(attribute)) { 1285 if (IsGenericAttribute(attribute)) {
1240 return {{GetGenericOutputAttribute(attribute, abuf->GetElement()), Type::Float}}; 1286 return {{GetGenericOutputAttribute(attribute, element), Type::Float}};
1287 }
1288 if (IsLegacyTexCoord(attribute)) {
1289 return {{fmt::format("gl_TexCoord[{}]{}", GetLegacyTexCoordIndex(attribute),
1290 GetSwizzle(element)),
1291 Type::Float}};
1241 } 1292 }
1242 UNIMPLEMENTED_MSG("Unhandled output attribute: {}", static_cast<u32>(attribute)); 1293 UNIMPLEMENTED_MSG("Unhandled output attribute: {}", static_cast<u32>(attribute));
1243 return {}; 1294 return {};