summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2020-02-13 20:25:28 -0300
committerGravatar ReinUsesLisp2020-02-13 20:25:28 -0300
commitcbea8c74de38dab25a927e6d217878cb8c98fbb4 (patch)
tree07c2624f689e8377cf3f37d5748c8f1291d8a536
parentMerge pull request #3405 from lioncash/thread (diff)
downloadyuzu-cbea8c74de38dab25a927e6d217878cb8c98fbb4.tar.gz
yuzu-cbea8c74de38dab25a927e6d217878cb8c98fbb4.tar.xz
yuzu-cbea8c74de38dab25a927e6d217878cb8c98fbb4.zip
vk_shader_decompiler: Fix vertex id and instance id
Vulkan's VertexIndex and InstanceIndex don't match with hardware. This is because Nvidia implements gl_VertexID and gl_InstanceID. The math that relates these is: gl_VertexIndex = gl_BaseVertex + gl_VertexID gl_InstanceIndex = gl_InstanceIndex + gl_InstanceID To emulate it using what Vulkan's SPIR-V offers (the *Index variants) this commit substracts gl_Base* from gl_*Index to obtain the OpenGL and hardware's equivalent.
-rw-r--r--src/video_core/renderer_vulkan/vk_shader_decompiler.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
index 24a658dce..f64f5da28 100644
--- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
+++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
@@ -275,12 +275,14 @@ public:
275 AddCapability(spv::Capability::ImageGatherExtended); 275 AddCapability(spv::Capability::ImageGatherExtended);
276 AddCapability(spv::Capability::SampledBuffer); 276 AddCapability(spv::Capability::SampledBuffer);
277 AddCapability(spv::Capability::StorageImageWriteWithoutFormat); 277 AddCapability(spv::Capability::StorageImageWriteWithoutFormat);
278 AddCapability(spv::Capability::DrawParameters);
278 AddCapability(spv::Capability::SubgroupBallotKHR); 279 AddCapability(spv::Capability::SubgroupBallotKHR);
279 AddCapability(spv::Capability::SubgroupVoteKHR); 280 AddCapability(spv::Capability::SubgroupVoteKHR);
280 AddExtension("SPV_KHR_shader_ballot"); 281 AddExtension("SPV_KHR_shader_ballot");
281 AddExtension("SPV_KHR_subgroup_vote"); 282 AddExtension("SPV_KHR_subgroup_vote");
282 AddExtension("SPV_KHR_storage_buffer_storage_class"); 283 AddExtension("SPV_KHR_storage_buffer_storage_class");
283 AddExtension("SPV_KHR_variable_pointers"); 284 AddExtension("SPV_KHR_variable_pointers");
285 AddExtension("SPV_KHR_shader_draw_parameters");
284 286
285 if (ir.UsesViewportIndex()) { 287 if (ir.UsesViewportIndex()) {
286 AddCapability(spv::Capability::MultiViewport); 288 AddCapability(spv::Capability::MultiViewport);
@@ -492,9 +494,11 @@ private:
492 interfaces.push_back(AddGlobalVariable(Name(out_vertex, "out_vertex"))); 494 interfaces.push_back(AddGlobalVariable(Name(out_vertex, "out_vertex")));
493 495
494 // Declare input attributes 496 // Declare input attributes
495 vertex_index = DeclareInputBuiltIn(spv::BuiltIn::VertexIndex, t_in_uint, "vertex_index"); 497 vertex_index = DeclareInputBuiltIn(spv::BuiltIn::VertexIndex, t_in_int, "vertex_index");
496 instance_index = 498 instance_index =
497 DeclareInputBuiltIn(spv::BuiltIn::InstanceIndex, t_in_uint, "instance_index"); 499 DeclareInputBuiltIn(spv::BuiltIn::InstanceIndex, t_in_int, "instance_index");
500 base_vertex = DeclareInputBuiltIn(spv::BuiltIn::BaseVertex, t_in_int, "base_vertex");
501 base_instance = DeclareInputBuiltIn(spv::BuiltIn::BaseInstance, t_in_int, "base_instance");
498 } 502 }
499 503
500 void DeclareTessControl() { 504 void DeclareTessControl() {
@@ -1068,9 +1072,12 @@ private:
1068 return {OpLoad(t_float, AccessElement(t_in_float, tess_coord, element)), 1072 return {OpLoad(t_float, AccessElement(t_in_float, tess_coord, element)),
1069 Type::Float}; 1073 Type::Float};
1070 case 2: 1074 case 2:
1071 return {OpLoad(t_uint, instance_index), Type::Uint}; 1075 return {
1076 OpISub(t_int, OpLoad(t_int, instance_index), OpLoad(t_int, base_instance)),
1077 Type::Int};
1072 case 3: 1078 case 3:
1073 return {OpLoad(t_uint, vertex_index), Type::Uint}; 1079 return {OpISub(t_int, OpLoad(t_int, vertex_index), OpLoad(t_int, base_vertex)),
1080 Type::Int};
1074 } 1081 }
1075 UNIMPLEMENTED_MSG("Unmanaged TessCoordInstanceIDVertexID element={}", element); 1082 UNIMPLEMENTED_MSG("Unmanaged TessCoordInstanceIDVertexID element={}", element);
1076 return {Constant(t_uint, 0U), Type::Uint}; 1083 return {Constant(t_uint, 0U), Type::Uint};
@@ -2542,6 +2549,8 @@ private:
2542 2549
2543 Id instance_index{}; 2550 Id instance_index{};
2544 Id vertex_index{}; 2551 Id vertex_index{};
2552 Id base_instance{};
2553 Id base_vertex{};
2545 std::array<Id, Maxwell::NumRenderTargets> frag_colors{}; 2554 std::array<Id, Maxwell::NumRenderTargets> frag_colors{};
2546 Id frag_depth{}; 2555 Id frag_depth{};
2547 Id frag_coord{}; 2556 Id frag_coord{};