diff options
| author | 2021-10-31 22:02:05 +0800 | |
|---|---|---|
| committer | 2021-10-31 23:34:17 +0800 | |
| commit | 49f9a442356d582d31832e79098fd6db22f0f4c3 (patch) | |
| tree | b8e3a308f16f0e213b11af97d82275014c16ab98 /src/shader_recompiler/backend/spirv/emit_context.cpp | |
| parent | Support gl_BackSecondaryColor attribute (diff) | |
| download | yuzu-49f9a442356d582d31832e79098fd6db22f0f4c3.tar.gz yuzu-49f9a442356d582d31832e79098fd6db22f0f4c3.tar.xz yuzu-49f9a442356d582d31832e79098fd6db22f0f4c3.zip | |
Support gl_FogFragCoord attribute
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/spirv/emit_context.cpp | 85 |
1 files changed, 41 insertions, 44 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp index d60ad139d..386c14ce5 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/emit_context.cpp | |||
| @@ -430,10 +430,12 @@ 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 | } |
| @@ -1279,45 +1281,40 @@ void EmitContext::DefineInputs(const IR::Program& program) { | |||
| 1279 | } | 1281 | } |
| 1280 | size_t previous_unused_location = 0; | 1282 | size_t previous_unused_location = 0; |
| 1281 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | 1283 | if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { |
| 1282 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1283 | previous_unused_location = location; | ||
| 1284 | used_locations.set(location); | ||
| 1285 | const Id id{DefineInput(*this, F32[4], true)}; | 1284 | const Id id{DefineInput(*this, F32[4], true)}; |
| 1286 | Decorate(id, spv::Decoration::Location, location); | 1285 | Decorate(id, spv::Decoration::Location, |
| 1286 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1287 | input_front_color = id; | 1287 | input_front_color = id; |
| 1288 | } | 1288 | } |
| 1289 | if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { | 1289 | if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { |
| 1290 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1291 | previous_unused_location = location; | ||
| 1292 | used_locations.set(location); | ||
| 1293 | const Id id{DefineInput(*this, F32[4], true)}; | 1290 | const Id id{DefineInput(*this, F32[4], true)}; |
| 1294 | Decorate(id, spv::Decoration::Location, location); | 1291 | Decorate(id, spv::Decoration::Location, |
| 1292 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1295 | input_front_secondary_color = id; | 1293 | input_front_secondary_color = id; |
| 1296 | } | 1294 | } |
| 1297 | if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | 1295 | if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { |
| 1298 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1299 | previous_unused_location = location; | ||
| 1300 | used_locations.set(location); | ||
| 1301 | const Id id{DefineInput(*this, F32[4], true)}; | 1296 | const Id id{DefineInput(*this, F32[4], true)}; |
| 1302 | Decorate(id, spv::Decoration::Location, location); | 1297 | Decorate(id, spv::Decoration::Location, |
| 1298 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1303 | input_back_color = id; | 1299 | input_back_color = id; |
| 1304 | } | 1300 | } |
| 1305 | if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | 1301 | if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) { |
| 1306 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1307 | previous_unused_location = location; | ||
| 1308 | used_locations.set(location); | ||
| 1309 | const Id id{DefineInput(*this, F32[4], true)}; | 1302 | const Id id{DefineInput(*this, F32[4], true)}; |
| 1310 | Decorate(id, spv::Decoration::Location, location); | 1303 | Decorate(id, spv::Decoration::Location, |
| 1304 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1311 | input_back_secondary_color = id; | 1305 | input_back_secondary_color = id; |
| 1312 | } | 1306 | } |
| 1307 | if (loads.AnyComponent(IR::Attribute::FogCoordinate)) { | ||
| 1308 | const Id id{DefineInput(*this, F32[4], true)}; | ||
| 1309 | Decorate(id, spv::Decoration::Location, | ||
| 1310 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1311 | input_fog_frag_coord = id; | ||
| 1312 | } | ||
| 1313 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | 1313 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { |
| 1314 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | 1314 | if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { |
| 1315 | const size_t location = | ||
| 1316 | FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1317 | previous_unused_location = location; | ||
| 1318 | used_locations.set(location); | ||
| 1319 | const Id id{DefineInput(*this, F32[4], true)}; | 1315 | const Id id{DefineInput(*this, F32[4], true)}; |
| 1320 | Decorate(id, spv::Decoration::Location, location); | 1316 | Decorate(id, spv::Decoration::Location, |
| 1317 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1321 | input_fixed_fnc_textures[index] = id; | 1318 | input_fixed_fnc_textures[index] = id; |
| 1322 | } | 1319 | } |
| 1323 | } | 1320 | } |
| @@ -1380,45 +1377,45 @@ void EmitContext::DefineOutputs(const IR::Program& program) { | |||
| 1380 | } | 1377 | } |
| 1381 | size_t previous_unused_location = 0; | 1378 | size_t previous_unused_location = 0; |
| 1382 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { | 1379 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { |
| 1383 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1384 | previous_unused_location = location; | ||
| 1385 | used_locations.set(location); | ||
| 1386 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1380 | const Id id{DefineOutput(*this, F32[4], invocations)}; |
| 1387 | Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); | 1381 | Decorate(id, spv::Decoration::Location, |
| 1382 | static_cast<u32>( | ||
| 1383 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1388 | output_front_color = id; | 1384 | output_front_color = id; |
| 1389 | } | 1385 | } |
| 1390 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { | 1386 | if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) { |
| 1391 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1392 | previous_unused_location = location; | ||
| 1393 | used_locations.set(location); | ||
| 1394 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1387 | const Id id{DefineOutput(*this, F32[4], invocations)}; |
| 1395 | Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); | 1388 | Decorate(id, spv::Decoration::Location, |
| 1389 | static_cast<u32>( | ||
| 1390 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1396 | output_front_secondary_color = id; | 1391 | output_front_secondary_color = id; |
| 1397 | } | 1392 | } |
| 1398 | if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { | 1393 | if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) { |
| 1399 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1400 | previous_unused_location = location; | ||
| 1401 | used_locations.set(location); | ||
| 1402 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1394 | const Id id{DefineOutput(*this, F32[4], invocations)}; |
| 1403 | Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); | 1395 | Decorate(id, spv::Decoration::Location, |
| 1396 | static_cast<u32>( | ||
| 1397 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1404 | output_back_color = id; | 1398 | output_back_color = id; |
| 1405 | } | 1399 | } |
| 1406 | if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) { | 1400 | if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) { |
| 1407 | const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1408 | previous_unused_location = location; | ||
| 1409 | used_locations.set(location); | ||
| 1410 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1401 | const Id id{DefineOutput(*this, F32[4], invocations)}; |
| 1411 | Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); | 1402 | Decorate(id, spv::Decoration::Location, |
| 1403 | static_cast<u32>( | ||
| 1404 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1412 | output_back_secondary_color = id; | 1405 | output_back_secondary_color = id; |
| 1413 | } | 1406 | } |
| 1407 | if (info.stores.AnyComponent(IR::Attribute::FogCoordinate)) { | ||
| 1408 | const Id id{DefineOutput(*this, F32[4], invocations)}; | ||
| 1409 | Decorate(id, spv::Decoration::Location, | ||
| 1410 | static_cast<u32>( | ||
| 1411 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location))); | ||
| 1412 | output_fog_frag_coord = id; | ||
| 1413 | } | ||
| 1414 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { | 1414 | for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { |
| 1415 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { | 1415 | if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { |
| 1416 | const size_t location = | ||
| 1417 | FindNextUnusedLocation(used_locations, previous_unused_location); | ||
| 1418 | previous_unused_location = location; | ||
| 1419 | used_locations.set(location); | ||
| 1420 | const Id id{DefineOutput(*this, F32[4], invocations)}; | 1416 | const Id id{DefineOutput(*this, F32[4], invocations)}; |
| 1421 | Decorate(id, spv::Decoration::Location, location); | 1417 | Decorate(id, spv::Decoration::Location, |
| 1418 | FindAndSetNextUnusedLocation(used_locations, previous_unused_location)); | ||
| 1422 | output_fixed_fnc_textures[index] = id; | 1419 | output_fixed_fnc_textures[index] = id; |
| 1423 | } | 1420 | } |
| 1424 | } | 1421 | } |