summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFeng Chen <vonchenplus@gmail.com>2021-09-07 07:21:17 +0200
committerFeng Chen <vonchenplus@gmail.com>2021-09-07 07:22:52 +0200
commite5ca733722865daa43eca8679f3c55826f0b88e6 (patch)
tree20fd8ddd84e99bb60c2025ae50708ce907d4645c
parentMove attribute related definitions to spirv anonymous namespace (diff)
downloadyuzu-e5ca733722865daa43eca8679f3c55826f0b88e6.tar
yuzu-e5ca733722865daa43eca8679f3c55826f0b88e6.tar.gz
yuzu-e5ca733722865daa43eca8679f3c55826f0b88e6.tar.bz2
yuzu-e5ca733722865daa43eca8679f3c55826f0b88e6.tar.lz
yuzu-e5ca733722865daa43eca8679f3c55826f0b88e6.tar.xz
yuzu-e5ca733722865daa43eca8679f3c55826f0b88e6.tar.zst
yuzu-e5ca733722865daa43eca8679f3c55826f0b88e6.zip
-rw-r--r--src/shader_recompiler/backend/spirv/emit_context.cpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/shader_recompiler/backend/spirv/emit_context.cpp b/src/shader_recompiler/backend/spirv/emit_context.cpp
index f048174cb..b9fa5098c 100644
--- a/src/shader_recompiler/backend/spirv/emit_context.cpp
+++ b/src/shader_recompiler/backend/spirv/emit_context.cpp
@@ -6,7 +6,6 @@
#include <array>
#include <climits>
#include <string_view>
-#include <queue>
#include <fmt/format.h>
@@ -430,6 +429,16 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {
}
constexpr size_t NUM_FIXEDFNCTEXTURE = 10;
+
+size_t FindFistUnUsedLocation(const auto& used_location) {
+ if (used_location.all()) {
+ throw RuntimeError("Unable to get an unused location");
+ }
+ size_t location = 0;
+ while (location < used_location.size() && used_location.test(location))
+ ++location;
+ return location;
+}
} // Anonymous namespace
void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) {
@@ -1230,15 +1239,19 @@ void EmitContext::DefineInputs(const IR::Program& program) {
loads[IR::Attribute::TessellationEvaluationPointV]) {
tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord);
}
- std::queue<u32> ununsed_location;
+ std::bitset<IR::NUM_GENERICS> used_location;
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
const AttributeType input_type{runtime_info.generic_input_types[index]};
- if (!runtime_info.previous_stage_stores.Generic(index) || !loads.Generic(index) ||
- input_type == AttributeType::Disabled) {
- ununsed_location.push(static_cast<u32>(index));
+ if (!runtime_info.previous_stage_stores.Generic(index)) {
continue;
}
-
+ if (!loads.Generic(index)) {
+ continue;
+ }
+ if (input_type == AttributeType::Disabled) {
+ continue;
+ }
+ used_location.set(index);
const Id type{GetAttributeType(*this, input_type)};
const Id id{DefineInput(*this, type, true)};
Decorate(id, spv::Decoration::Location, static_cast<u32>(index));
@@ -1265,22 +1278,16 @@ void EmitContext::DefineInputs(const IR::Program& program) {
}
}
if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
- if (ununsed_location.empty()) {
- throw RuntimeError("Unable to get an unused location");
- }
- u32 location = ununsed_location.front();
- ununsed_location.pop();
+ size_t location = FindFistUnUsedLocation(used_location);
+ used_location.set(location);
const Id id{DefineInput(*this, F32[4], true)};
Decorate(id, spv::Decoration::Location, location);
input_front_color = id;
}
for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
- if (ununsed_location.empty()) {
- throw RuntimeError("Unable to get an unused location");
- }
- u32 location = ununsed_location.front();
- ununsed_location.pop();
+ size_t location = FindFistUnUsedLocation(used_location);
+ used_location.set(location);
const Id id{DefineInput(*this, F32[4], true)};
Decorate(id, spv::Decoration::Location, location);
input_fixed_fnc_textures[index] = id;
@@ -1336,31 +1343,24 @@ void EmitContext::DefineOutputs(const IR::Program& program) {
viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt,
spv::BuiltIn::ViewportMaskNV);
}
- std::queue<u32> ununsed_location;
+ std::bitset<IR::NUM_GENERICS> used_location;
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
if (info.stores.Generic(index)) {
DefineGenericOutput(*this, index, invocations);
- } else {
- ununsed_location.push(static_cast<u32>(index));
+ used_location.set(index);
}
}
if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
- if (ununsed_location.empty()) {
- throw RuntimeError("Unable to get an unused location");
- }
- u32 location = ununsed_location.front();
- ununsed_location.pop();
+ size_t location = FindFistUnUsedLocation(used_location);
+ used_location.set(location);
const Id id{DefineOutput(*this, F32[4], invocations)};
- Decorate(id, spv::Decoration::Location, location);
+ Decorate(id, spv::Decoration::Location, static_cast<u32>(location));
output_front_color = id;
}
for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
- if (ununsed_location.empty()) {
- throw RuntimeError("Unable to get an unused location");
- }
- u32 location = ununsed_location.front();
- ununsed_location.pop();
+ size_t location = FindFistUnUsedLocation(used_location);
+ used_location.set(location);
const Id id{DefineOutput(*this, F32[4], invocations)};
Decorate(id, spv::Decoration::Location, location);
output_fixed_fnc_textures[index] = id;