diff options
Diffstat (limited to 'src')
3 files changed, 58 insertions, 48 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 | } |
diff --git a/src/shader_recompiler/backend/spirv/emit_context.h b/src/shader_recompiler/backend/spirv/emit_context.h index a08622099..e1af12a38 100644 --- a/src/shader_recompiler/backend/spirv/emit_context.h +++ b/src/shader_recompiler/backend/spirv/emit_context.h | |||
| @@ -272,6 +272,7 @@ public: | |||
| 272 | Id input_front_secondary_color{}; | 272 | Id input_front_secondary_color{}; |
| 273 | Id input_back_color{}; | 273 | Id input_back_color{}; |
| 274 | Id input_back_secondary_color{}; | 274 | Id input_back_secondary_color{}; |
| 275 | Id input_fog_frag_coord{}; | ||
| 275 | std::array<Id, 10> input_fixed_fnc_textures{}; | 276 | std::array<Id, 10> input_fixed_fnc_textures{}; |
| 276 | std::array<Id, 32> input_generics{}; | 277 | std::array<Id, 32> input_generics{}; |
| 277 | 278 | ||
| @@ -281,6 +282,7 @@ public: | |||
| 281 | Id output_front_secondary_color{}; | 282 | Id output_front_secondary_color{}; |
| 282 | Id output_back_color{}; | 283 | Id output_back_color{}; |
| 283 | Id output_back_secondary_color{}; | 284 | Id output_back_secondary_color{}; |
| 285 | Id output_fog_frag_coord{}; | ||
| 284 | std::array<Id, 10> output_fixed_fnc_textures{}; | 286 | std::array<Id, 10> output_fixed_fnc_textures{}; |
| 285 | std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; | 287 | std::array<std::array<GenericElementInfo, 4>, 32> output_generics{}; |
| 286 | 288 | ||
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 2d1545851..6fa99cc1a 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 | |||
| @@ -143,6 +143,11 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) { | |||
| 143 | const Id element_id{ctx.Const(element)}; | 143 | const Id element_id{ctx.Const(element)}; |
| 144 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_back_secondary_color, element_id); | 144 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_back_secondary_color, element_id); |
| 145 | } | 145 | } |
| 146 | case IR::Attribute::FogCoordinate: { | ||
| 147 | const u32 element{static_cast<u32>(attr) % 4}; | ||
| 148 | const Id element_id{ctx.Const(element)}; | ||
| 149 | return OutputAccessChain(ctx, ctx.output_f32, ctx.output_fog_frag_coord, element_id); | ||
| 150 | } | ||
| 146 | case IR::Attribute::ClipDistance0: | 151 | case IR::Attribute::ClipDistance0: |
| 147 | case IR::Attribute::ClipDistance1: | 152 | case IR::Attribute::ClipDistance1: |
| 148 | case IR::Attribute::ClipDistance2: | 153 | case IR::Attribute::ClipDistance2: |
| @@ -391,8 +396,9 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 391 | case IR::Attribute::ColorFrontSpecularG: | 396 | case IR::Attribute::ColorFrontSpecularG: |
| 392 | case IR::Attribute::ColorFrontSpecularB: | 397 | case IR::Attribute::ColorFrontSpecularB: |
| 393 | case IR::Attribute::ColorFrontSpecularA: { | 398 | case IR::Attribute::ColorFrontSpecularA: { |
| 394 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_secondary_color, | 399 | return ctx.OpLoad(ctx.F32[1], |
| 395 | ctx.Const(element))); | 400 | AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_secondary_color, |
| 401 | ctx.Const(element))); | ||
| 396 | } | 402 | } |
| 397 | case IR::Attribute::ColorBackDiffuseR: | 403 | case IR::Attribute::ColorBackDiffuseR: |
| 398 | case IR::Attribute::ColorBackDiffuseG: | 404 | case IR::Attribute::ColorBackDiffuseG: |
| @@ -405,8 +411,13 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) { | |||
| 405 | case IR::Attribute::ColorBackSpecularG: | 411 | case IR::Attribute::ColorBackSpecularG: |
| 406 | case IR::Attribute::ColorBackSpecularB: | 412 | case IR::Attribute::ColorBackSpecularB: |
| 407 | case IR::Attribute::ColorBackSpecularA: { | 413 | case IR::Attribute::ColorBackSpecularA: { |
| 408 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_back_secondary_color, | 414 | return ctx.OpLoad(ctx.F32[1], |
| 409 | ctx.Const(element))); | 415 | AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_back_secondary_color, |
| 416 | ctx.Const(element))); | ||
| 417 | } | ||
| 418 | case IR::Attribute::FogCoordinate: { | ||
| 419 | return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, | ||
| 420 | ctx.input_fog_frag_coord, ctx.Const(element))); | ||
| 410 | } | 421 | } |
| 411 | case IR::Attribute::InstanceId: | 422 | case IR::Attribute::InstanceId: |
| 412 | if (ctx.profile.support_vertex_instance_id) { | 423 | if (ctx.profile.support_vertex_instance_id) { |