diff options
Diffstat (limited to 'src/shader_recompiler/backend/spirv/spirv_emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/spirv_emit_context.cpp | 143 |
1 files changed, 0 insertions, 143 deletions
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index 4b6f792bf..d3ba66569 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp | |||
| @@ -18,8 +18,6 @@ | |||
| 18 | 18 | ||
| 19 | namespace Shader::Backend::SPIRV { | 19 | namespace Shader::Backend::SPIRV { |
| 20 | namespace { | 20 | namespace { |
| 21 | constexpr size_t NUM_FIXEDFNCTEXTURE = 10; | ||
| 22 | |||
| 23 | enum class Operation { | 21 | enum class Operation { |
| 24 | Increment, | 22 | Increment, |
| 25 | Decrement, | 23 | Decrement, |
| @@ -432,34 +430,6 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) { | |||
| 432 | return pointer_type; | 430 | return pointer_type; |
| 433 | } | 431 | } |
| 434 | } | 432 | } |
| 435 | |||
| 436 | size_t FindAndSetNextUnusedLocation(std::bitset<IR::NUM_GENERICS>& used_locations, | ||
| 437 | size_t& start_offset) { | ||
| 438 | for (size_t location = start_offset; location < used_locations.size(); ++location) { | ||
| 439 | if (!used_locations.test(location)) { | ||
| 440 | start_offset = location; | ||
| 441 | used_locations.set(location); | ||
| 442 | return location; | ||
| 443 | } | ||
| 444 | } | ||
| 445 | throw RuntimeError("Unable to get an unused location for legacy attribute"); | ||
| 446 | } | ||
| 447 | |||
| 448 | Id DefineLegacyInput(EmitContext& ctx, std::bitset<IR::NUM_GENERICS>& used_locations, | ||
| 449 | size_t& start_offset) { | ||
| 450 | const Id id{DefineInput(ctx, ctx.F32[4], true)}; | ||
| 451 | const size_t location = FindAndSetNextUnusedLocation(used_locations, start_offset); | ||
| 452 | ctx.Decorate(id, spv::Decoration::Location, location); | ||
| 453 | return id; | ||
| 454 | } | ||
| 455 | |||
| 456 | Id DefineLegacyOutput(EmitContext& ctx, std::bitset<IR::NUM_GENERICS>& used_locations, | ||
| 457 | size_t& start_offset, std::optional<u32> invocations) { | ||
| 458 | const Id id{DefineOutput(ctx, ctx.F32[4], invocations)}; | ||
| 459 | const size_t location = FindAndSetNextUnusedLocation(used_locations, start_offset); | ||
| 460 | ctx.Decorate(id, spv::Decoration::Location, location); | ||
| 461 | return id; | ||
| 462 | } | ||
| 463 | } // Anonymous namespace | 433 | } // Anonymous namespace |
| 464 | 434 | ||
| 465 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { | 435 | void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { |
| @@ -543,64 +513,6 @@ Id EmitContext::BitOffset16(const IR::Value& offset) { | |||
| 543 | return OpBitwiseAnd(U32[1], OpShiftLeftLogical(U32[1], Def(offset), Const(3u)), Const(16u)); | 513 | return OpBitwiseAnd(U32[1], OpShiftLeftLogical(U32[1], Def(offset), Const(3u)), Const(16u)); |
| 544 | } | 514 | } |
| 545 | 515 | ||
| 546 | Id EmitContext::InputLegacyAttribute(IR::Attribute attribute) { | ||
| 547 | if (attribute >= IR::Attribute::ColorFrontDiffuseR && | ||
| 548 | attribute <= IR::Attribute::ColorFrontDiffuseA) { | ||
| 549 | return input_front_color; | ||
| 550 | } | ||
| 551 | if (attribute >= IR::Attribute::ColorFrontSpecularR && | ||
| 552 | attribute <= IR::Attribute::ColorFrontSpecularA) { | ||
| 553 | return input_front_secondary_color; | ||
| 554 | } | ||
| 555 | if (attribute >= IR::Attribute::ColorBackDiffuseR && | ||
| 556 | attribute <= IR::Attribute::ColorBackDiffuseA) { | ||
| 557 | return input_back_color; | ||
| 558 | } | ||
| 559 | if (attribute >= IR::Attribute::ColorBackSpecularR && | ||
| 560 | attribute <= IR::Attribute::ColorBackSpecularA) { | ||
| 561 | return input_back_secondary_color; | ||
| 562 | } | ||
| 563 | if (attribute == IR::Attribute::FogCoordinate) { | ||
| 564 | return input_fog_frag_coord; | ||
| 565 | } | ||
| 566 | if (attribute >= IR::Attribute::FixedFncTexture0S && | ||
| 567 | attribute <= IR::Attribute::FixedFncTexture9Q) { | ||
| 568 | u32 index = | ||
| 569 | (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4; | ||
| 570 | return input_fixed_fnc_textures[index]; | ||
| 571 | } | ||
| 572 | throw InvalidArgument("Attribute is not legacy attribute {}", attribute); | ||
| 573 | } | ||
| 574 | |||
| 575 | Id EmitContext::OutputLegacyAttribute(IR::Attribute attribute) { | ||
| 576 | if (attribute >= IR::Attribute::ColorFrontDiffuseR && | ||
| 577 | attribute <= IR::Attribute::ColorFrontDiffuseA) { | ||
| 578 | return output_front_color; | ||
| 579 | } | ||
| 580 | if (attribute >= IR::Attribute::ColorFrontSpecularR && | ||
| 581 | attribute <= IR::Attribute::ColorFrontSpecularA) { | ||
| 582 | return output_front_secondary_color; | ||
| 583 | } | ||
| 584 | if (attribute >= IR::Attribute::ColorBackDiffuseR && | ||
| 585 | attribute <= IR::Attribute::ColorBackDiffuseA) { | ||
| 586 | return output_back_color; | ||
| 587 | } | ||
| 588 | if (attribute >= IR::Attribute::ColorBackSpecularR && | ||
| 589 | attribute <= IR::Attribute::ColorBackSpecularA) { | ||
| 590 | return output_back_secondary_color; | ||
| 591 | } | ||
| 592 | if (attribute == IR::Attribute::FogCoordinate) { | ||
| 593 | return output_fog_frag_coord; | ||
| 594 | } | ||
| 595 | if (attribute >= IR::Attribute::FixedFncTexture0S && | ||
| 596 | attribute <= IR::Attribute::FixedFncTexture9Q) { | ||
| 597 | u32 index = | ||
| 598 | (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4; | ||
| 599 | return output_fixed_fnc_textures[index]; | ||
| 600 | } | ||
| 601 | throw InvalidArgument("Attribute is not legacy attribute {}", attribute); | ||
| 602 | } | ||
| 603 | |||
| 604 | void EmitContext::DefineCommonTypes(const Info& info) { | 516 | void EmitContext::DefineCommonTypes(const Info& info) { |
| 605 | void_id = TypeVoid(); | 517 | void_id = TypeVoid(); |
| 606 | 518 | ||
| @@ -1389,7 +1301,6 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1389 | loads[IR::Attribute::TessellationEvaluationPointV]) { | 1301 | loads[IR::Attribute::TessellationEvaluationPointV]) { |
| 1390 | tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord); | 1302 | tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord); |
| 1391 | } | 1303 | } |
| 1392 | std::bitset<IR::NUM_GENERICS> used_locations{}; | ||
| 1393 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { | 1304 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { |
| 1394 | const AttributeType input_type{runtime_info.generic_input_types[index]}; | 1305 | const AttributeType input_type{runtime_info.generic_input_types[index]}; |
| 1395 | if (!runtime_info.previous_stage_stores.Generic(index)) { | 1306 | if (!runtime_info.previous_stage_stores.Generic(index)) { |
| @@ -1401,7 +1312,6 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1401 | if (input_type == AttributeType::Disabled) { | 1312 | if (input_type == AttributeType::Disabled) { |
| 1402 | continue; | 1313 | continue; |
| 1403 | } | 1314 | } |
| 1404 | used_locations.set(index); | ||
| 1405 | const Id type{GetAttributeType(*this, input_type)}; | 1315 | const Id type{GetAttributeType(*this, input_type)}; |
| 1406 | const Id id{DefineInput(*this, type, true)}; | 1316 | const Id id{DefineInput(*this, type, true)}; |
| 1407 | Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); | 1317 | Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); |
| @@ -1427,30 +1337,6 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1427 | break; | 1337 | break; |
| 1428 | } | 1338 | } |
| 1429 | } | 1339 | } |
| 1430 | size_t previous_unused_location = 0; | ||
| 1431 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | ||
| 1432 | input_front_color = DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1433 | } | ||
| 1434 | if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { | ||
| 1435 | input_front_secondary_color = | ||
| 1436 | DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1437 | } | ||
| 1438 | if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | ||
| 1439 | input_back_color = DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1440 | } | ||
| 1441 | if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | ||
| 1442 | input_back_secondary_color = | ||
| 1443 | DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1444 | } | ||
| 1445 | if (loads.AnyComponent(IR::Attribute::FogCoordinate)) { | ||
| 1446 | input_fog_frag_coord = DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1447 | } | ||
| 1448 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | ||
| 1449 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | ||
| 1450 | input_fixed_fnc_textures[index] = | ||
| 1451 | DefineLegacyInput(*this, used_locations, previous_unused_location); | ||
| 1452 | } | ||
| 1453 | } | ||
| 1454 | if (stage == Stage::TessellationEval) { | 1340 | if (stage == Stage::TessellationEval) { |
| 1455 | for (size_t index = 0; index < info.uses_patches.size(); ++index) { | 1341 | for (size_t index = 0; index < info.uses_patches.size(); ++index) { |
| 1456 | if (!info.uses_patches[index]) { | 1342 | if (!info.uses_patches[index]) { |
| @@ -1501,38 +1387,9 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1501 | viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt, | 1387 | viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt, |
| 1502 | spv::BuiltIn::ViewportMaskNV); | 1388 | spv::BuiltIn::ViewportMaskNV); |
| 1503 | } | 1389 | } |
| 1504 | std::bitset<IR::NUM_GENERICS> used_locations{}; | ||
| 1505 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { | 1390 | for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { |
| 1506 | if (info.stores.Generic(index)) { | 1391 | if (info.stores.Generic(index)) { |
| 1507 | DefineGenericOutput(*this, index, invocations); | 1392 | DefineGenericOutput(*this, index, invocations); |
| 1508 | used_locations.set(index); | ||
| 1509 | } | ||
| 1510 | } | ||
| 1511 | size_t previous_unused_location = 0; | ||
| 1512 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | ||
| 1513 | output_front_color = | ||
| 1514 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1515 | } | ||
| 1516 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { | ||
| 1517 | output_front_secondary_color = | ||
| 1518 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1519 | } | ||
| 1520 | if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | ||
| 1521 | output_back_color = | ||
| 1522 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1523 | } | ||
| 1524 | if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | ||
| 1525 | output_back_secondary_color = | ||
| 1526 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1527 | } | ||
| 1528 | if (info.stores.AnyComponent(IR::Attribute::FogCoordinate)) { | ||
| 1529 | output_fog_frag_coord = | ||
| 1530 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1531 | } | ||
| 1532 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | ||
| 1533 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | ||
| 1534 | output_fixed_fnc_textures[index] = | ||
| 1535 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); | ||
| 1536 | } | 1393 | } |
| 1537 | } | 1394 | } |
| 1538 | switch (stage) { | 1395 | switch (stage) { |