summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/spirv/emit_context.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2021-09-08 14:04:44 -0700
committerGravatar GitHub2021-09-08 14:04:44 -0700
commit7e9163779dbdd549df039b2adb9fe8439a5e2c6e (patch)
tree3a89498f18ba98170f63e67c9ce7c7b082efcecc /src/shader_recompiler/backend/spirv/emit_context.cpp
parentMerge pull request #6980 from vonchenplus/fix_blend_equation_error (diff)
parentDetail adjustment (diff)
downloadyuzu-7e9163779dbdd549df039b2adb9fe8439a5e2c6e.tar.gz
yuzu-7e9163779dbdd549df039b2adb9fe8439a5e2c6e.tar.xz
yuzu-7e9163779dbdd549df039b2adb9fe8439a5e2c6e.zip
Merge pull request #6962 from vonchenplus/spirv_support_legacy_attribute
renderer_vulkan: Spirv support glsl legacy attribute
Diffstat (limited to 'src/shader_recompiler/backend/spirv/emit_context.cpp')
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp
index 2d29d8c14..2885e6799 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,
@@ -427,6 +429,16 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {
427 return pointer_type; 429 return pointer_type;
428 } 430 }
429} 431}
432
433size_t FindNextUnusedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations,
434 size_t start_offset) {
435 for (size_t location = start_offset; location < used_locations.size(); ++location) {
436 if (!used_locations.test(location)) {
437 return location;
438 }
439 }
440 throw RuntimeError("Unable to get an unused location for legacy attribute");
441}
430} // Anonymous namespace 442} // Anonymous namespace
431 443
432void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) { 444void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) {
@@ -1227,6 +1239,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {
1227 loads[IR::Attribute::TessellationEvaluationPointV]) { 1239 loads[IR::Attribute::TessellationEvaluationPointV]) {
1228 tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord); 1240 tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord);
1229 } 1241 }
1242 std::bitset<IR::NUM_GENERICS> used_locations{};
1230 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { 1243 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
1231 const AttributeType input_type{runtime_info.generic_input_types[index]}; 1244 const AttributeType input_type{runtime_info.generic_input_types[index]};
1232 if (!runtime_info.previous_stage_stores.Generic(index)) { 1245 if (!runtime_info.previous_stage_stores.Generic(index)) {
@@ -1238,6 +1251,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {
1238 if (input_type == AttributeType::Disabled) { 1251 if (input_type == AttributeType::Disabled) {
1239 continue; 1252 continue;
1240 } 1253 }
1254 used_locations.set(index);
1241 const Id type{GetAttributeType(*this, input_type)}; 1255 const Id type{GetAttributeType(*this, input_type)};
1242 const Id id{DefineInput(*this, type, true)}; 1256 const Id id{DefineInput(*this, type, true)};
1243 Decorate(id, spv::Decoration::Location, static_cast<u32>(index)); 1257 Decorate(id, spv::Decoration::Location, static_cast<u32>(index));
@@ -1263,6 +1277,26 @@ void EmitContext::DefineInputs(const IR::Program& program) {
1263 break; 1277 break;
1264 } 1278 }
1265 } 1279 }
1280 size_t previous_unused_location = 0;
1281 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)};
1286 Decorate(id, spv::Decoration::Location, location);
1287 input_front_color = id;
1288 }
1289 for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
1290 if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
1291 const size_t location =
1292 FindNextUnusedLocation(used_locations, previous_unused_location);
1293 previous_unused_location = location;
1294 used_locations.set(location);
1295 const Id id{DefineInput(*this, F32[4], true)};
1296 Decorate(id, spv::Decoration::Location, location);
1297 input_fixed_fnc_textures[index] = id;
1298 }
1299 }
1266 if (stage == Stage::TessellationEval) { 1300 if (stage == Stage::TessellationEval) {
1267 for (size_t index = 0; index < info.uses_patches.size(); ++index) { 1301 for (size_t index = 0; index < info.uses_patches.size(); ++index) {
1268 if (!info.uses_patches[index]) { 1302 if (!info.uses_patches[index]) {
@@ -1313,9 +1347,31 @@ void EmitContext::DefineOutputs(const IR::Program& program) {
1313 viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt, 1347 viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt,
1314 spv::BuiltIn::ViewportMaskNV); 1348 spv::BuiltIn::ViewportMaskNV);
1315 } 1349 }
1350 std::bitset<IR::NUM_GENERICS> used_locations{};
1316 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) { 1351 for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
1317 if (info.stores.Generic(index)) { 1352 if (info.stores.Generic(index)) {
1318 DefineGenericOutput(*this, index, invocations); 1353 DefineGenericOutput(*this, index, invocations);
1354 used_locations.set(index);
1355 }
1356 }
1357 size_t previous_unused_location = 0;
1358 if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
1359 const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location);
1360 previous_unused_location = location;
1361 used_locations.set(location);
1362 const Id id{DefineOutput(*this, F32[4], invocations)};
1363 Decorate(id, spv::Decoration::Location, static_cast<u32>(location));
1364 output_front_color = id;
1365 }
1366 for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
1367 if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
1368 const size_t location =
1369 FindNextUnusedLocation(used_locations, previous_unused_location);
1370 previous_unused_location = location;
1371 used_locations.set(location);
1372 const Id id{DefineOutput(*this, F32[4], invocations)};
1373 Decorate(id, spv::Decoration::Location, location);
1374 output_fixed_fnc_textures[index] = id;
1319 } 1375 }
1320 } 1376 }
1321 switch (stage) { 1377 switch (stage) {