diff options
| author | 2021-11-14 02:07:45 -0800 | |
|---|---|---|
| committer | 2021-11-14 02:07:45 -0800 | |
| commit | 30442d8a89fd42d9b7efea86e1b2461f09219936 (patch) | |
| tree | b30524b3c486c4e453cdbbaf319b4a8d03cfaaee /src/shader_recompiler/backend/spirv/emit_context.cpp | |
| parent | Merge pull request #7305 from Morph1984/ci (diff) | |
| parent | Simply legacy attribute implement (diff) | |
| download | yuzu-30442d8a89fd42d9b7efea86e1b2461f09219936.tar.gz yuzu-30442d8a89fd42d9b7efea86e1b2461f09219936.tar.xz yuzu-30442d8a89fd42d9b7efea86e1b2461f09219936.zip | |
Merge pull request #7260 from vonchenplus/spirv_support_legacy_attribute_v2
shader: Spirv support legacy attribute v2
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 143 |
1 files changed, 115 insertions, 28 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 2885e6799..3c84e6466 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -430,15 +430,33 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) { | |||
| 430 | } | 430 | } |
| 431 | } | 431 | } |
| 432 | 432 | ||
| 433 | size_t FindNextUnusedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations, | 433 | size_t FindAndSetNextUnusedLocation(std::bitset<IR::NUM_GENERICS>& used_locations, |
| 434 | size_t start_offset) { | 434 | size_t& start_offset) { |
| 435 | for (size_t location = start_offset; location < used_locations.size(); ++location) { | 435 | for (size_t location = start_offset; location < used_locations.size(); ++location) { |
| 436 | if (!used_locations.test(location)) { | 436 | if (!used_locations.test(location)) { |
| 437 | start_offset = location; | ||
| 438 | used_locations.set(location); | ||
| 437 | return location; | 439 | return location; |
| 438 | } | 440 | } |
| 439 | } | 441 | } |
| 440 | throw RuntimeError("Unable to get an unused location for legacy attribute"); | 442 | throw RuntimeError("Unable to get an unused location for legacy attribute"); |
| 441 | } | 443 | } |
| 444 | |||
| 445 | Id DefineLegacyInput(EmitContext& ctx, std::bitset<IR::NUM_GENERICS>& used_locations, | ||
| 446 | size_t& start_offset) { | ||
| 447 | const Id id{DefineInput(ctx, ctx.F32[4], true)}; | ||
| 448 | const size_t location = FindAndSetNextUnusedLocation(used_locations, start_offset); | ||
| 449 | ctx.Decorate(id, spv::Decoration::Location, location); | ||
| 450 | return id; | ||
| 451 | } | ||
| 452 | |||
| 453 | Id DefineLegacyOutput(EmitContext& ctx, std::bitset<IR::NUM_GENERICS>& used_locations, | ||
| 454 | size_t& start_offset, std::optional<u32> invocations) { | ||
| 455 | const Id id{DefineOutput(ctx, ctx.F32[4], invocations)}; | ||
| 456 | const size_t location = FindAndSetNextUnusedLocation(used_locations, start_offset); | ||
| 457 | ctx.Decorate(id, spv::Decoration::Location, location); | ||
| 458 | return id; | ||
| 459 | } | ||
| 442 | } // Anonymous namespace | 460 | } // Anonymous namespace |
| 443 | 461 | ||
| 444 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { | 462 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { |
| @@ -520,6 +538,64 @@ Id EmitContext::BitOffset16(const IR::Value& offset) { | |||
| 520 | return OpBitwiseAnd(U32[1], OpShiftLeftLogical(U32[1], Def(offset), Const(3u)), Const(16u)); | 538 | return OpBitwiseAnd(U32[1], OpShiftLeftLogical(U32[1], Def(offset), Const(3u)), Const(16u)); |
| 521 | } | 539 | } |
| 522 | 540 | ||
| 541 | Id EmitContext::InputLegacyAttribute(IR::Attribute attribute) { | ||
| 542 | if (attribute >= IR::Attribute::ColorFrontDiffuseR && | ||
| 543 | attribute <= IR::Attribute::ColorFrontDiffuseA) { | ||
| 544 | return input_front_color; | ||
| 545 | } | ||
| 546 | if (attribute >= IR::Attribute::ColorFrontSpecularR && | ||
| 547 | attribute <= IR::Attribute::ColorFrontSpecularA) { | ||
| 548 | return input_front_secondary_color; | ||
| 549 | } | ||
| 550 | if (attribute >= IR::Attribute::ColorBackDiffuseR && | ||
| 551 | attribute <= IR::Attribute::ColorBackDiffuseA) { | ||
| 552 | return input_back_color; | ||
| 553 | } | ||
| 554 | if (attribute >= IR::Attribute::ColorBackSpecularR && | ||
| 555 | attribute <= IR::Attribute::ColorBackSpecularA) { | ||
| 556 | return input_back_secondary_color; | ||
| 557 | } | ||
| 558 | if (attribute == IR::Attribute::FogCoordinate) { | ||
| 559 | return input_fog_frag_coord; | ||
| 560 | } | ||
| 561 | if (attribute >= IR::Attribute::FixedFncTexture0S && | ||
| 562 | attribute <= IR::Attribute::FixedFncTexture9Q) { | ||
| 563 | u32 index = | ||
| 564 | (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4; | ||
| 565 | return input_fixed_fnc_textures[index]; | ||
| 566 | } | ||
| 567 | throw InvalidArgument("Attribute is not legacy attribute {}", attribute); | ||
| 568 | } | ||
| 569 | |||
| 570 | Id EmitContext::OutputLegacyAttribute(IR::Attribute attribute) { | ||
| 571 | if (attribute >= IR::Attribute::ColorFrontDiffuseR && | ||
| 572 | attribute <= IR::Attribute::ColorFrontDiffuseA) { | ||
| 573 | return output_front_color; | ||
| 574 | } | ||
| 575 | if (attribute >= IR::Attribute::ColorFrontSpecularR && | ||
| 576 | attribute <= IR::Attribute::ColorFrontSpecularA) { | ||
| 577 | return output_front_secondary_color; | ||
| 578 | } | ||
| 579 | if (attribute >= IR::Attribute::ColorBackDiffuseR && | ||
| 580 | attribute <= IR::Attribute::ColorBackDiffuseA) { | ||
| 581 | return output_back_color; | ||
| 582 | } | ||
| 583 | if (attribute >= IR::Attribute::ColorBackSpecularR && | ||
| 584 | attribute <= IR::Attribute::ColorBackSpecularA) { | ||
| 585 | return output_back_secondary_color; | ||
| 586 | } | ||
| 587 | if (attribute == IR::Attribute::FogCoordinate) { | ||
| 588 | return output_fog_frag_coord; | ||
| 589 | } | ||
| 590 | if (attribute >= IR::Attribute::FixedFncTexture0S && | ||
| 591 | attribute <= IR::Attribute::FixedFncTexture9Q) { | ||
| 592 | u32 index = | ||
| 593 | (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4; | ||
| 594 | return output_fixed_fnc_textures[index]; | ||
| 595 | } | ||
| 596 | throw InvalidArgument("Attribute is not legacy attribute {}", attribute); | ||
| 597 | } | ||
| 598 | |||
| 523 | void EmitContext::DefineCommonTypes(const Info& info) { | 599 | void EmitContext::DefineCommonTypes(const Info& info) { |
| 524 | void_id = TypeVoid(); | 600 | void_id = TypeVoid(); |
| 525 | 601 | ||
| @@ -1279,22 +1355,26 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1279 | } | 1355 | } |
| 1280 | size_t previous_unused_location = 0; | 1356 | size_t previous_unused_location = 0; |
| 1281 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | 1357 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { |
| 1282 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | 1358 | input_front_color = DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1283 | previous_unused_location = location; | 1359 | } |
| 1284 | used_locations.set(location); | 1360 | if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { |
| 1285 | const Id id{DefineInput(*this, F32[4], true)}; | 1361 | input_front_secondary_color = |
| 1286 | Decorate(id, spv::Decoration::Location, location); | 1362 | DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1287 | input_front_color = id; | 1363 | } |
| 1364 | if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | ||
| 1365 | input_back_color = DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1366 | } | ||
| 1367 | if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | ||
| 1368 | input_back_secondary_color = | ||
| 1369 | DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1370 | } | ||
| 1371 | if (loads.AnyComponent(IR::Attribute::FogCoordinate)) { | ||
| 1372 | input_fog_frag_coord = DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1288 | } | 1373 | } |
| 1289 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | 1374 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { |
| 1290 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | 1375 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { |
| 1291 | const size_t location = | 1376 | input_fixed_fnc_textures[index] = |
| 1292 | FindNextUnusedLocation(used_locations, previous_unused_location); | 1377 | DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1293 | previous_unused_location = location; | ||
| 1294 | used_locations.set(location); | ||
| 1295 | const Id id{DefineInput(*this, F32[4], true)}; | ||
| 1296 | Decorate(id, spv::Decoration::Location, location); | ||
| 1297 | input_fixed_fnc_textures[index] = id; | ||
| 1298 | } | 1378 | } |
| 1299 | } | 1379 | } |
| 1300 | if (stage == Stage::TessellationEval) { | 1380 | if (stage == Stage::TessellationEval) { |
| @@ -1356,22 +1436,29 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1356 | } | 1436 | } |
| 1357 | size_t previous_unused_location = 0; | 1437 | size_t previous_unused_location = 0; |
| 1358 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | 1438 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { |
| 1359 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | 1439 | output_front_color = |
| 1360 | previous_unused_location = location; | 1440 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1361 | used_locations.set(location); | 1441 | } |
| 1362 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1442 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { |
| 1363 | Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); | 1443 | output_front_secondary_color = |
| 1364 | output_front_color = id; | 1444 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1445 | } | ||
| 1446 | if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | ||
| 1447 | output_back_color = | ||
| 1448 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1449 | } | ||
| 1450 | if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | ||
| 1451 | output_back_secondary_color = | ||
| 1452 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1453 | } | ||
| 1454 | if (info.stores.AnyComponent(IR::Attribute::FogCoordinate)) { | ||
| 1455 | output_fog_frag_coord = | ||
| 1456 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1365 | } | 1457 | } |
| 1366 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | 1458 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { |
| 1367 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | 1459 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { |
| 1368 | const size_t location = | 1460 | output_fixed_fnc_textures[index] = |
| 1369 | FindNextUnusedLocation(used_locations, previous_unused_location); | 1461 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1370 | previous_unused_location = location; | ||
| 1371 | used_locations.set(location); | ||
| 1372 | const Id id{DefineOutput(*this, F32[4], invocations)}; | ||
| 1373 | Decorate(id, spv::Decoration::Location, location); | ||
| 1374 | output_fixed_fnc_textures[index] = id; | ||
| 1375 | } | 1462 | } |
| 1376 | } | 1463 | } |
| 1377 | switch (stage) { | 1464 | switch (stage) { |