|
@@ -15,6 +15,8 @@
|
|
|
|
|
|
|
|
namespace Shader::Backend::SPIRV {
|
|
namespace Shader::Backend::SPIRV {
|
|
|
namespace {
|
|
namespace {
|
|
|
|
|
+constexpr size_t NUM_FIXEDFNCTEXTURE = 10;
|
|
|
|
|
+
|
|
|
enum class Operation {
|
|
enum class Operation {
|
|
|
Increment,
|
|
Increment,
|
|
|
Decrement,
|
|
Decrement,
|
|
@@ -427,6 +429,16 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {
|
|
|
return pointer_type;
|
|
return pointer_type;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+size_t FindNextUnusedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations,
|
|
|
|
|
+ size_t start_offset) {
|
|
|
|
|
+ for (size_t location = start_offset; location < used_locations.size(); ++location) {
|
|
|
|
|
+ if (!used_locations.test(location)) {
|
|
|
|
|
+ return location;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ throw RuntimeError("Unable to get an unused location for legacy attribute");
|
|
|
|
|
+}
|
|
|
} // 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) {
|
|
@@ -1227,6 +1239,7 @@ 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::bitset<IR::NUM_GENERICS> used_locations{};
|
|
|
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)) {
|
|
if (!runtime_info.previous_stage_stores.Generic(index)) {
|
|
@@ -1238,6 +1251,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {
|
|
|
if (input_type == AttributeType::Disabled) {
|
|
if (input_type == AttributeType::Disabled) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
+ used_locations.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));
|
|
@@ -1263,6 +1277,26 @@ void EmitContext::DefineInputs(const IR::Program& program) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ size_t previous_unused_location = 0;
|
|
|
|
|
+ if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
|
|
|
|
+ const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location);
|
|
|
|
|
+ previous_unused_location = location;
|
|
|
|
|
+ used_locations.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)) {
|
|
|
|
|
+ const size_t location =
|
|
|
|
|
+ FindNextUnusedLocation(used_locations, previous_unused_location);
|
|
|
|
|
+ previous_unused_location = location;
|
|
|
|
|
+ used_locations.set(location);
|
|
|
|
|
+ const Id id{DefineInput(*this, F32[4], true)};
|
|
|
|
|
+ Decorate(id, spv::Decoration::Location, location);
|
|
|
|
|
+ input_fixed_fnc_textures[index] = id;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if (stage == Stage::TessellationEval) {
|
|
if (stage == Stage::TessellationEval) {
|
|
|
for (size_t index = 0; index < info.uses_patches.size(); ++index) {
|
|
for (size_t index = 0; index < info.uses_patches.size(); ++index) {
|
|
|
if (!info.uses_patches[index]) {
|
|
if (!info.uses_patches[index]) {
|
|
@@ -1313,9 +1347,31 @@ 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::bitset<IR::NUM_GENERICS> used_locations{};
|
|
|
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);
|
|
|
|
|
+ used_locations.set(index);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ size_t previous_unused_location = 0;
|
|
|
|
|
+ if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
|
|
|
|
+ const size_t location = FindNextUnusedLocation(used_locations, previous_unused_location);
|
|
|
|
|
+ previous_unused_location = location;
|
|
|
|
|
+ used_locations.set(location);
|
|
|
|
|
+ const Id id{DefineOutput(*this, F32[4], invocations)};
|
|
|
|
|
+ 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)) {
|
|
|
|
|
+ const size_t location =
|
|
|
|
|
+ FindNextUnusedLocation(used_locations, previous_unused_location);
|
|
|
|
|
+ previous_unused_location = location;
|
|
|
|
|
+ used_locations.set(location);
|
|
|
|
|
+ const Id id{DefineOutput(*this, F32[4], invocations)};
|
|
|
|
|
+ Decorate(id, spv::Decoration::Location, location);
|
|
|
|
|
+ output_fixed_fnc_textures[index] = id;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
switch (stage) {
|
|
switch (stage) {
|