summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend
diff options
context:
space:
mode:
authorGravatar FernandoS272021-04-04 09:38:15 +0200
committerGravatar ameerj2021-07-22 21:51:26 -0400
commit73cb17f41bf019df504d2d2af4ebdf45aa3201c6 (patch)
tree97ca7cbbefaae73eb77d6e91bbcac4dbe4238c3a /src/shader_recompiler/backend
parentshader: Implement indexed attributes (diff)
downloadyuzu-73cb17f41bf019df504d2d2af4ebdf45aa3201c6.tar.gz
yuzu-73cb17f41bf019df504d2d2af4ebdf45aa3201c6.tar.xz
yuzu-73cb17f41bf019df504d2d2af4ebdf45aa3201c6.zip
shader: Implement indexed Position and ClipDistances
Diffstat (limited to 'src/shader_recompiler/backend')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp
index eadecb064..e22bb5371 100644
--- a/src/shader_recompiler/backend/spirv/emit_context.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_context.cpp
@@ -327,6 +327,10 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
327 const Id compare_index{OpShiftRightLogical(U32[1], base_index, Constant(U32[1], 2U))}; 327 const Id compare_index{OpShiftRightLogical(U32[1], base_index, Constant(U32[1], 2U))};
328 std::vector<Sirit::Literal> literals; 328 std::vector<Sirit::Literal> literals;
329 std::vector<Id> labels; 329 std::vector<Id> labels;
330 if (info.loads_position) {
331 literals.push_back(static_cast<u32>(IR::Attribute::PositionX) >> 2);
332 labels.push_back(OpLabel());
333 }
330 const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2; 334 const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
331 for (u32 i = 0; i < info.input_generics.size(); i++) { 335 for (u32 i = 0; i < info.input_generics.size(); i++) {
332 if (!info.input_generics[i].used) { 336 if (!info.input_generics[i].used) {
@@ -340,6 +344,12 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
340 AddLabel(default_label); 344 AddLabel(default_label);
341 OpReturnValue(Constant(F32[1], 0.0f)); 345 OpReturnValue(Constant(F32[1], 0.0f));
342 size_t label_index = 0; 346 size_t label_index = 0;
347 if (info.loads_position) {
348 AddLabel(labels[label_index]);
349 const Id result{OpLoad(F32[1], OpAccessChain(input_f32, input_position, masked_index))};
350 OpReturnValue(result);
351 label_index++;
352 }
343 for (u32 i = 0; i < info.input_generics.size(); i++) { 353 for (u32 i = 0; i < info.input_generics.size(); i++) {
344 if (!info.input_generics[i].used) { 354 if (!info.input_generics[i].used) {
345 continue; 355 continue;
@@ -377,6 +387,10 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
377 const Id compare_index{OpShiftRightLogical(U32[1], base_index, Constant(U32[1], 2U))}; 387 const Id compare_index{OpShiftRightLogical(U32[1], base_index, Constant(U32[1], 2U))};
378 std::vector<Sirit::Literal> literals; 388 std::vector<Sirit::Literal> literals;
379 std::vector<Id> labels; 389 std::vector<Id> labels;
390 if (info.stores_position) {
391 literals.push_back(static_cast<u32>(IR::Attribute::PositionX) >> 2);
392 labels.push_back(OpLabel());
393 }
380 const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2; 394 const u32 base_attribute_value = static_cast<u32>(IR::Attribute::Generic0X) >> 2;
381 for (u32 i = 0; i < info.stores_generics.size(); i++) { 395 for (u32 i = 0; i < info.stores_generics.size(); i++) {
382 if (!info.stores_generics[i]) { 396 if (!info.stores_generics[i]) {
@@ -385,11 +399,24 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
385 literals.push_back(base_attribute_value + i); 399 literals.push_back(base_attribute_value + i);
386 labels.push_back(OpLabel()); 400 labels.push_back(OpLabel());
387 } 401 }
402 if (info.stores_clip_distance) {
403 literals.push_back(static_cast<u32>(IR::Attribute::ClipDistance0) >> 2);
404 labels.push_back(OpLabel());
405 literals.push_back(static_cast<u32>(IR::Attribute::ClipDistance4) >> 2);
406 labels.push_back(OpLabel());
407 }
388 OpSelectionMerge(end_block, spv::SelectionControlMask::MaskNone); 408 OpSelectionMerge(end_block, spv::SelectionControlMask::MaskNone);
389 OpSwitch(compare_index, default_label, literals, labels); 409 OpSwitch(compare_index, default_label, literals, labels);
390 AddLabel(default_label); 410 AddLabel(default_label);
391 OpReturn(); 411 OpReturn();
392 size_t label_index = 0; 412 size_t label_index = 0;
413 if (info.stores_position) {
414 AddLabel(labels[label_index]);
415 const Id pointer{OpAccessChain(output_f32, output_position, masked_index)};
416 OpStore(pointer, store_value);
417 OpReturn();
418 label_index++;
419 }
393 for (u32 i = 0; i < info.stores_generics.size(); i++) { 420 for (u32 i = 0; i < info.stores_generics.size(); i++) {
394 if (!info.stores_generics[i]) { 421 if (!info.stores_generics[i]) {
395 continue; 422 continue;
@@ -401,6 +428,19 @@ void EmitContext::DefineAttributeMemAccess(const Info& info) {
401 OpReturn(); 428 OpReturn();
402 label_index++; 429 label_index++;
403 } 430 }
431 if (info.stores_clip_distance) {
432 AddLabel(labels[label_index]);
433 const Id pointer{OpAccessChain(output_f32, clip_distances, masked_index)};
434 OpStore(pointer, store_value);
435 OpReturn();
436 label_index++;
437 AddLabel(labels[label_index]);
438 const Id fixed_index{OpIAdd(U32[1], masked_index, Constant(U32[1], 4))};
439 const Id pointer2{OpAccessChain(output_f32, clip_distances, fixed_index)};
440 OpStore(pointer2, store_value);
441 OpReturn();
442 label_index++;
443 }
404 AddLabel(end_block); 444 AddLabel(end_block);
405 OpUnreachable(); 445 OpUnreachable();
406 OpFunctionEnd(); 446 OpFunctionEnd();