|
|
@@ -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;
|