diff options
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 148 |
1 files changed, 95 insertions, 53 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index 386c14ce5..3c84e6466 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -441,6 +441,22 @@ size_t FindAndSetNextUnusedLocation(std::bitset<IR::NUM_GENERICS>& used_location | |||
| 441 | } | 441 | } |
| 442 | throw RuntimeError("Unable to get an unused location for legacy attribute"); | 442 | throw RuntimeError("Unable to get an unused location for legacy attribute"); |
| 443 | } | 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 | } | ||
| 444 | } // Anonymous namespace | 460 | } // Anonymous namespace |
| 445 | 461 | ||
| 446 | 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) { |
| @@ -522,6 +538,64 @@ Id EmitContext::BitOffset16(const IR::Value& offset) { | |||
| 522 | 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)); |
| 523 | } | 539 | } |
| 524 | 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 | |||
| 525 | void EmitContext::DefineCommonTypes(const Info& info) { | 599 | void EmitContext::DefineCommonTypes(const Info& info) { |
| 526 | void_id = TypeVoid(); | 600 | void_id = TypeVoid(); |
| 527 | 601 | ||
| @@ -1281,41 +1355,26 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1281 | } | 1355 | } |
| 1282 | size_t previous_unused_location = 0; | 1356 | size_t previous_unused_location = 0; |
| 1283 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | 1357 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { |
| 1284 | const Id id{DefineInput(*this, F32[4], true)}; | 1358 | input_front_color = DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1285 | Decorate(id, spv::Decoration::Location, | ||
| 1286 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1287 | input_front_color = id; | ||
| 1288 | } | 1359 | } |
| 1289 | if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { | 1360 | if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { |
| 1290 | const Id id{DefineInput(*this, F32[4], true)}; | 1361 | input_front_secondary_color = |
| 1291 | Decorate(id, spv::Decoration::Location, | 1362 | DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1292 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1293 | input_front_secondary_color = id; | ||
| 1294 | } | 1363 | } |
| 1295 | if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | 1364 | if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { |
| 1296 | const Id id{DefineInput(*this, F32[4], true)}; | 1365 | input_back_color = DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1297 | Decorate(id, spv::Decoration::Location, | ||
| 1298 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1299 | input_back_color = id; | ||
| 1300 | } | 1366 | } |
| 1301 | if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | 1367 | if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) { |
| 1302 | const Id id{DefineInput(*this, F32[4], true)}; | 1368 | input_back_secondary_color = |
| 1303 | Decorate(id, spv::Decoration::Location, | 1369 | DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1304 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1305 | input_back_secondary_color = id; | ||
| 1306 | } | 1370 | } |
| 1307 | if (loads.AnyComponent(IR::Attribute::FogCoordinate)) { | 1371 | if (loads.AnyComponent(IR::Attribute::FogCoordinate)) { |
| 1308 | const Id id{DefineInput(*this, F32[4], true)}; | 1372 | input_fog_frag_coord = DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1309 | Decorate(id, spv::Decoration::Location, | ||
| 1310 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1311 | input_fog_frag_coord = id; | ||
| 1312 | } | 1373 | } |
| 1313 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | 1374 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { |
| 1314 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | 1375 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { |
| 1315 | const Id id{DefineInput(*this, F32[4], true)}; | 1376 | input_fixed_fnc_textures[index] = |
| 1316 | Decorate(id, spv::Decoration::Location, | 1377 | DefineLegacyInput(*this, used_locations, previous_unused_location); |
| 1317 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1318 | input_fixed_fnc_textures[index] = id; | ||
| 1319 | } | 1378 | } |
| 1320 | } | 1379 | } |
| 1321 | if (stage == Stage::TessellationEval) { | 1380 | if (stage == Stage::TessellationEval) { |
| @@ -1377,46 +1436,29 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1377 | } | 1436 | } |
| 1378 | size_t previous_unused_location = 0; | 1437 | size_t previous_unused_location = 0; |
| 1379 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | 1438 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { |
| 1380 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1439 | output_front_color = |
| 1381 | Decorate(id, spv::Decoration::Location, | 1440 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1382 | static_cast<u32>( | ||
| 1383 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1384 | output_front_color = id; | ||
| 1385 | } | 1441 | } |
| 1386 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { | 1442 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { |
| 1387 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1443 | output_front_secondary_color = |
| 1388 | Decorate(id, spv::Decoration::Location, | 1444 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1389 | static_cast<u32>( | ||
| 1390 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1391 | output_front_secondary_color = id; | ||
| 1392 | } | 1445 | } |
| 1393 | if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | 1446 | if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { |
| 1394 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1447 | output_back_color = |
| 1395 | Decorate(id, spv::Decoration::Location, | 1448 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1396 | static_cast<u32>( | ||
| 1397 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1398 | output_back_color = id; | ||
| 1399 | } | 1449 | } |
| 1400 | if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | 1450 | if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) { |
| 1401 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1451 | output_back_secondary_color = |
| 1402 | Decorate(id, spv::Decoration::Location, | 1452 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1403 | static_cast<u32>( | ||
| 1404 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1405 | output_back_secondary_color = id; | ||
| 1406 | } | 1453 | } |
| 1407 | if (info.stores.AnyComponent(IR::Attribute::FogCoordinate)) { | 1454 | if (info.stores.AnyComponent(IR::Attribute::FogCoordinate)) { |
| 1408 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1455 | output_fog_frag_coord = |
| 1409 | Decorate(id, spv::Decoration::Location, | 1456 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1410 | static_cast<u32>( | ||
| 1411 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1412 | output_fog_frag_coord = id; | ||
| 1413 | } | 1457 | } |
| 1414 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | 1458 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { |
| 1415 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | 1459 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { |
| 1416 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1460 | output_fixed_fnc_textures[index] = |
| 1417 | Decorate(id, spv::Decoration::Location, | 1461 | DefineLegacyOutput(*this, used_locations, previous_unused_location, invocations); |
| 1418 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1419 | output_fixed_fnc_textures[index] = id; | ||
| 1420 | } | 1462 | } |
| 1421 | } | 1463 | } |
| 1422 | switch (stage) { | 1464 | switch (stage) { |