Re-implement get unused location
This commit is contained in:
parent
9cdf2383e9
commit
e5ca733722
@ -6,7 +6,6 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <queue>
|
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#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;
|
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
|
} // Anonymous namespace
|
||||||
|
|
||||||
void VectorTypes::Define(Sirit::Module& sirit_ctx, Id base_type, std::string_view name) {
|
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]) {
|
loads[IR::Attribute::TessellationEvaluationPointV]) {
|
||||||
tess_coord = DefineInput(*this, F32[3], false, spv::BuiltIn::TessCoord);
|
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) {
|
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||||
const AttributeType input_type{runtime_info.generic_input_types[index]};
|
const AttributeType input_type{runtime_info.generic_input_types[index]};
|
||||||
if (!runtime_info.previous_stage_stores.Generic(index) || !loads.Generic(index) ||
|
if (!runtime_info.previous_stage_stores.Generic(index)) {
|
||||||
input_type == AttributeType::Disabled) {
|
|
||||||
ununsed_location.push(static_cast<u32>(index));
|
|
||||||
continue;
|
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 type{GetAttributeType(*this, input_type)};
|
||||||
const Id id{DefineInput(*this, type, true)};
|
const Id id{DefineInput(*this, type, true)};
|
||||||
Decorate(id, spv::Decoration::Location, static_cast<u32>(index));
|
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 (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
||||||
if (ununsed_location.empty()) {
|
size_t location = FindFistUnUsedLocation(used_location);
|
||||||
throw RuntimeError("Unable to get an unused location");
|
used_location.set(location);
|
||||||
}
|
|
||||||
u32 location = ununsed_location.front();
|
|
||||||
ununsed_location.pop();
|
|
||||||
const Id id{DefineInput(*this, F32[4], true)};
|
const Id id{DefineInput(*this, F32[4], true)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location, location);
|
||||||
input_front_color = id;
|
input_front_color = id;
|
||||||
}
|
}
|
||||||
for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
|
for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
|
||||||
if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
|
if (loads.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
|
||||||
if (ununsed_location.empty()) {
|
size_t location = FindFistUnUsedLocation(used_location);
|
||||||
throw RuntimeError("Unable to get an unused location");
|
used_location.set(location);
|
||||||
}
|
|
||||||
u32 location = ununsed_location.front();
|
|
||||||
ununsed_location.pop();
|
|
||||||
const Id id{DefineInput(*this, F32[4], true)};
|
const Id id{DefineInput(*this, F32[4], true)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location, location);
|
||||||
input_fixed_fnc_textures[index] = id;
|
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,
|
viewport_mask = DefineOutput(*this, TypeArray(U32[1], Const(1u)), std::nullopt,
|
||||||
spv::BuiltIn::ViewportMaskNV);
|
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) {
|
for (size_t index = 0; index < IR::NUM_GENERICS; ++index) {
|
||||||
if (info.stores.Generic(index)) {
|
if (info.stores.Generic(index)) {
|
||||||
DefineGenericOutput(*this, index, invocations);
|
DefineGenericOutput(*this, index, invocations);
|
||||||
} else {
|
used_location.set(index);
|
||||||
ununsed_location.push(static_cast<u32>(index));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
||||||
if (ununsed_location.empty()) {
|
size_t location = FindFistUnUsedLocation(used_location);
|
||||||
throw RuntimeError("Unable to get an unused location");
|
used_location.set(location);
|
||||||
}
|
|
||||||
u32 location = ununsed_location.front();
|
|
||||||
ununsed_location.pop();
|
|
||||||
const Id id{DefineOutput(*this, F32[4], invocations)};
|
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;
|
output_front_color = id;
|
||||||
}
|
}
|
||||||
for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
|
for (size_t index = 0; index < NUM_FIXEDFNCTEXTURE; ++index) {
|
||||||
if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
|
if (info.stores.AnyComponent(IR::Attribute::FixedFncTexture0S + index * 4)) {
|
||||||
if (ununsed_location.empty()) {
|
size_t location = FindFistUnUsedLocation(used_location);
|
||||||
throw RuntimeError("Unable to get an unused location");
|
used_location.set(location);
|
||||||
}
|
|
||||||
u32 location = ununsed_location.front();
|
|
||||||
ununsed_location.pop();
|
|
||||||
const Id id{DefineOutput(*this, F32[4], invocations)};
|
const Id id{DefineOutput(*this, F32[4], invocations)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location, location);
|
||||||
output_fixed_fnc_textures[index] = id;
|
output_fixed_fnc_textures[index] = id;
|
||||||
|
Loading…
Reference in New Issue
Block a user