summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/spirv/emit_context.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp
index b9fa5098c..118a80165 100644
--- a/src/shader_recompiler/backend/spirv/emit_context.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_context.cpp
@@ -15,6 +15,8 @@
15 15
16namespace Shader::Backend::SPIRV { 16namespace Shader::Backend::SPIRV {
17namespace { 17namespace {
18constexpr size_t NUM_FIXEDFNCTEXTURE = 10;
19
18enum class Operation { 20enum class Operation {
19 Increment, 21 Increment,
20 Decrement, 22 Decrement,
@@ -428,15 +430,14 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {
428 } 430 }
429} 431}
430 432
431constexpr size_t NUM_FIXEDFNCTEXTURE = 10; 433size_t FindFistUnUsedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations,
432 434 size_t previous_unused_location) {
433size_t FindFistUnUsedLocation(const auto& used_location) { 435 size_t location = previous_unused_location + 1;
434 if (used_location.all()) { 436 while (location < used_locations.size() && used_locations.test(location))
435 throw RuntimeError("Unable to get an unused location");
436 }
437 size_t location = 0;
438 while (location < used_location.size() && used_location.test(location))
439 ++location; 437 ++location;
438 if (location == used_locations.size()) {
439 throw RuntimeError("Unable to get an unused location for legacy attribute");
440 }
440 return location; 441 return location;
441} 442}
442} // Anonymous namespace 443} // Anonymous namespace
@@ -1239,7 +1240,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {
1239 loads[IR::Attribute::TessellationEvaluationPointV]) { 1240 loads[IR::Attribute::TessellationEvaluationPointV]) {
1240 tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord); 1241 tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord);
1241 } 1242 }
1242 std::bitset<IR::NUM_GENERICS> used_location; 1243 std::bitset<IR::NUM_GENERICS> used_locations{};
1243 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { 1244 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
1244 const AttributeType input_type{runtime_info.generic_input_types[index]}; 1245 const AttributeType input_type{runtime_info.generic_input_types[index]};
1245 if (!runtime_info.previous_stage_stores.Generic(index)) { 1246 if (!runtime_info.previous_stage_stores.Generic(index)) {
@@ -1251,7 +1252,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {
1251 if (input_type == AttributeType::Disabled) { 1252 if (input_type == AttributeType::Disabled) {
1252 continue; 1253 continue;
1253 } 1254 }
1254 used_location.set(index); 1255 used_locations.set(index);
1255 const Id type{GetAttributeType(*this, input_type)}; 1256 const Id type{GetAttributeType(*this, input_type)};
1256 const Id id{DefineInput(*this, type, true)}; 1257 const Id id{DefineInput(*this, type, true)};
1257 Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); 1258 Decorate(id, spv::Decoration::Location, static_cast<u32>(index));
@@ -1277,17 +1278,20 @@ void EmitContext::DefineInputs(const IR::Program& program) {
1277 break; 1278 break;
1278 } 1279 }
1279 } 1280 }
1281 size_t previous_unused_location = 0;
1280 if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { 1282 if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
1281 size_t location = FindFistUnUsedLocation(used_location); 1283 size_t location = FindFistUnUsedLocation(used_locations, previous_unused_location);
1282 used_location.set(location); 1284 previous_unused_location = location;
1285 used_locations.set(location);
1283 const Id id{DefineInput(*this, F32[4], true)}; 1286 const Id id{DefineInput(*this, F32[4], true)};
1284 Decorate(id, spv::Decoration::Location, location); 1287 Decorate(id, spv::Decoration::Location, location);
1285 input_front_color = id; 1288 input_front_color = id;
1286 } 1289 }
1287 for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { 1290 for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
1288 if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { 1291 if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
1289 size_t location = FindFistUnUsedLocation(used_location); 1292 size_t location = FindFistUnUsedLocation(used_locations, previous_unused_location);
1290 used_location.set(location); 1293 previous_unused_location = location;
1294 used_locations.set(location);
1291 const Id id{DefineInput(*this, F32[4], true)}; 1295 const Id id{DefineInput(*this, F32[4], true)};
1292 Decorate(id, spv::Decoration::Location, location); 1296 Decorate(id, spv::Decoration::Location, location);
1293 input_fixed_fnc_textures[index] = id; 1297 input_fixed_fnc_textures[index] = id;
@@ -1343,24 +1347,27 @@ void EmitContext::DefineOutputs(const IR::Program& program) {
1343 viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt, 1347 viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt,
1344 spv::BuiltIn::ViewportMaskNV); 1348 spv::BuiltIn::ViewportMaskNV);
1345 } 1349 }
1346 std::bitset<IR::NUM_GENERICS> used_location; 1350 std::bitset<IR::NUM_GENERICS> used_locations{};
1347 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { 1351 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
1348 if (info.stores.Generic(index)) { 1352 if (info.stores.Generic(index)) {
1349 DefineGenericOutput(*this, index, invocations); 1353 DefineGenericOutput(*this, index, invocations);
1350 used_location.set(index); 1354 used_locations.set(index);
1351 } 1355 }
1352 } 1356 }
1357 size_t previous_unused_location = 0;
1353 if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) { 1358 if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
1354 size_t location = FindFistUnUsedLocation(used_location); 1359 size_t location = FindFistUnUsedLocation(used_locations, previous_unused_location);
1355 used_location.set(location); 1360 previous_unused_location = location;
1361 used_locations.set(location);
1356 const Id id{DefineOutput(*this, F32[4], invocations)}; 1362 const Id id{DefineOutput(*this, F32[4], invocations)};
1357 Decorate(id, spv::Decoration::Location, static_cast<u32>(location)); 1363 Decorate(id, spv::Decoration::Location, static_cast<u32>(location));
1358 output_front_color = id; 1364 output_front_color = id;
1359 } 1365 }
1360 for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) { 1366 for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
1361 if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) { 1367 if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
1362 size_t location = FindFistUnUsedLocation(used_location); 1368 size_t location = FindFistUnUsedLocation(used_locations, previous_unused_location);
1363 used_location.set(location); 1369 previous_unused_location = location;
1370 used_locations.set(location);
1364 const Id id{DefineOutput(*this, F32[4], invocations)}; 1371 const Id id{DefineOutput(*this, F32[4], invocations)};
1365 Decorate(id, spv::Decoration::Location, location); 1372 Decorate(id, spv::Decoration::Location, location);
1366 output_fixed_fnc_textures[index] = id; 1373 output_fixed_fnc_textures[index] = id;