diff options
Diffstat (limited to 'src/shader_recompiler/backend')
3 files changed, 0 insertions, 189 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp index ad84966b5..14f470812 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp | |||
| @@ -44,14 +44,6 @@ Id AttrPointer(EmitContext& ctx, Id pointer_type, Id vertex, Id base, Args&&... | |||
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | bool IsLegacyAttribute(IR::Attribute attribute) { | ||
| 48 | return (attribute >= IR::Attribute::ColorFrontDiffuseR && | ||
| 49 | attribute <= IR::Attribute::ColorBackSpecularA) || | ||
| 50 | attribute == IR::Attribute::FogCoordinate || | ||
| 51 | (attribute >= IR::Attribute::FixedFncTexture0S && | ||
| 52 | attribute <= IR::Attribute::FixedFncTexture9Q); | ||
| 53 | } | ||
| 54 | |||
| 55 | template <typename... Args> | 47 | template <typename... Args> |
| 56 | Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) { | 48 | Id OutputAccessChain(EmitContext& ctx, Id result_type, Id base, Args&&... args) { |
| 57 | if (ctx.stage == Stage::TessellationControl) { | 49 | if (ctx.stage == Stage::TessellationControl) { |
| @@ -83,17 +75,6 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 83 | return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id); | 75 | return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id); |
| 84 | } | 76 | } |
| 85 | } | 77 | } |
| 86 | if (IsLegacyAttribute(attr)) { | ||
| 87 | if (attr == IR::Attribute::FogCoordinate) { | ||
| 88 | return OutputAccessChain(ctx, ctx.output_f32, ctx.OutputLegacyAttribute(attr), | ||
| 89 | ctx.Const(0u)); | ||
| 90 | } else { | ||
| 91 | const u32 element{static_cast<u32>(attr) % 4}; | ||
| 92 | const Id element_id{ctx.Const(element)}; | ||
| 93 | return OutputAccessChain(ctx, ctx.output_f32, ctx.OutputLegacyAttribute(attr), | ||
| 94 | element_id); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | switch (attr) { | 78 | switch (attr) { |
| 98 | case IR::Attribute::PointSize: | 79 | case IR::Attribute::PointSize: |
| 99 | return ctx.output_point_size; | 80 | return ctx.output_point_size; |
| @@ -327,18 +308,6 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 327 | const Id value{ctx.OpLoad(type->id, pointer)}; | 308 | const Id value{ctx.OpLoad(type->id, pointer)}; |
| 328 | return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; | 309 | return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; |
| 329 | } | 310 | } |
| 330 | if (IsLegacyAttribute(attr)) { | ||
| 331 | if (attr == IR::Attribute::FogCoordinate) { | ||
| 332 | const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, | ||
| 333 | ctx.InputLegacyAttribute(attr), ctx.Const(0u))}; | ||
| 334 | return ctx.OpLoad(ctx.F32[1], attr_ptr); | ||
| 335 | } else { | ||
| 336 | const Id element_id{ctx.Const(element)}; | ||
| 337 | const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, | ||
| 338 | ctx.InputLegacyAttribute(attr), element_id)}; | ||
| 339 | return ctx.OpLoad(ctx.F32[1], attr_ptr); | ||
| 340 | } | ||
| 341 | } | ||
| 342 | switch (attr) { | 311 | switch (attr) { |
| 343 | case IR::Attribute::PrimitiveId: | 312 | case IR::Attribute::PrimitiveId: |
| 344 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.primitive_id)); | 313 | return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.primitive_id)); |
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) { |
diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.h b/src/shader_recompiler/backend/spirv/spirv_emit_context.h index 63f8185d9..f87138f7e 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.h +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.h | |||
| @@ -113,9 +113,6 @@ public: | |||
| 113 | [[nodiscard]] Id BitOffset8(const IR::Value& offset); | 113 | [[nodiscard]] Id BitOffset8(const IR::Value& offset); |
| 114 | [[nodiscard]] Id BitOffset16(const IR::Value& offset); | 114 | [[nodiscard]] Id BitOffset16(const IR::Value& offset); |
| 115 | 115 | ||
| 116 | Id InputLegacyAttribute(IR::Attribute attribute); | ||
| 117 | Id OutputLegacyAttribute(IR::Attribute attribute); | ||
| 118 | |||
| 119 | Id Const(u32 value) { | 116 | Id Const(u32 value) { |
| 120 | return Constant(U32[1], value); | 117 | return Constant(U32[1], value); |
| 121 | } | 118 | } |
| @@ -281,22 +278,10 @@ public: | |||
| 281 | Id write_global_func_u32x4{}; | 278 | Id write_global_func_u32x4{}; |
| 282 | 279 | ||
| 283 | Id input_position{}; | 280 | Id input_position{}; |
| 284 | Id input_front_color{}; | ||
| 285 | Id input_front_secondary_color{}; | ||
| 286 | Id input_back_color{}; | ||
| 287 | Id input_back_secondary_color{}; | ||
| 288 | Id input_fog_frag_coord{}; | ||
| 289 | std::array<Id, 10> input_fixed_fnc_textures{}; | ||
| 290 | std::array<Id, 32> input_generics{}; | 281 | std::array<Id, 32> input_generics{}; |
| 291 | 282 | ||
| 292 | Id output_point_size{}; | 283 | Id output_point_size{}; |
| 293 | Id output_position{}; | 284 | Id output_position{}; |
| 294 | Id output_front_color{}; | ||
| 295 | Id output_front_secondary_color{}; | ||
| 296 | Id output_back_color{}; | ||
| 297 | Id output_back_secondary_color{}; | ||
| 298 | Id output_fog_frag_coord{}; | ||
| 299 | std::array<Id, 10> output_fixed_fnc_textures{}; | ||
| 300 | std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; | 285 | std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; |
| 301 | 286 | ||
| 302 | Id output_tess_level_outer{}; | 287 | Id output_tess_level_outer{}; |