summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp47
-rw-r--r--src/shader_recompiler/backend/spirv/emit_spirv_context_get_set.cpp16
2 files changed, 35 insertions, 28 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;
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 dd0d01b2a..67df46499 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
@@ -50,16 +50,16 @@ bool IsFixedFncTexture(IR::Attribute attribute) {
50 50
51u32 FixedFncTextureAttributeIndex(IR::Attribute attribute) { 51u32 FixedFncTextureAttributeIndex(IR::Attribute attribute) {
52 if (!IsFixedFncTexture(attribute)) { 52 if (!IsFixedFncTexture(attribute)) {
53 throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute); 53 throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute);
54 } 54 }
55 return (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4u; 55 return (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4u;
56} 56}
57 57
58u32 FixedFncTextureAttributeElement(IR::Attribute attribute) { 58u32 FixedFncTextureAttributeElement(IR::Attribute attribute) {
59 if (!IsFixedFncTexture(attribute)) { 59 if (!IsFixedFncTexture(attribute)) {
60 throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute); 60 throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute);
61 } 61 }
62 return static_cast<u32>(attribute) % 4; 62 return static_cast<u32>(attribute) % 4u;
63} 63}
64 64
65template <typename... Args> 65template <typename... Args>
@@ -93,7 +93,7 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) {
93 return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id); 93 return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id);
94 } 94 }
95 } 95 }
96 if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) { 96 if (IsFixedFncTexture(attr)) {
97 const u32 index{FixedFncTextureAttributeIndex(attr)}; 97 const u32 index{FixedFncTextureAttributeIndex(attr)};
98 const u32 element{FixedFncTextureAttributeElement(attr)}; 98 const u32 element{FixedFncTextureAttributeElement(attr)};
99 const Id element_id{ctx.Const(element)}; 99 const Id element_id{ctx.Const(element)};
@@ -341,11 +341,11 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
341 const Id value{ctx.OpLoad(type->id, pointer)}; 341 const Id value{ctx.OpLoad(type->id, pointer)};
342 return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; 342 return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value;
343 } 343 }
344 if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) { 344 if (IsFixedFncTexture(attr)) {
345 const u32 index{FixedFncTextureAttributeIndex(attr)}; 345 const u32 index{FixedFncTextureAttributeIndex(attr)};
346 return ctx.OpLoad(ctx.F32[1], 346 const Id attr_id{ctx.input_fixed_fnc_textures[index]};
347 AttrPointer(ctx, ctx.input_f32, vertex, 347 const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, attr_id, ctx.Const(element))};
348 ctx.input_fixed_fnc_textures[index], ctx.Const(element))); 348 return ctx.OpLoad(ctx.F32[1], attr_ptr);
349 } 349 }
350 switch (attr) { 350 switch (attr) {
351 case IR::Attribute::PrimitiveId: 351 case IR::Attribute::PrimitiveId: