Detail adjustment
This commit is contained in:
parent
e5ca733722
commit
bbc1800c1b
|
@ -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,
|
||||||
|
@ -428,15 +430,14 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_t NUM_FIXEDFNCTEXTURE = 10;
|
size_t FindFistUnUsedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations,
|
||||||
|
size_t previous_unused_location) {
|
||||||
size_t FindFistUnUsedLocation(const auto& used_location) {
|
size_t location = previous_unused_location + 1;
|
||||||
if (used_location.all()) {
|
while (location < used_locations.size() && used_locations.test(location))
|
||||||
throw RuntimeError("Unable to get an unused location");
|
|
||||||
}
|
|
||||||
size_t location = 0;
|
|
||||||
while (location < used_location.size() && used_location.test(location))
|
|
||||||
++location;
|
++location;
|
||||||
|
if (location == used_locations.size()) {
|
||||||
|
throw RuntimeError("Unable to get an unused location for legacy attribute");
|
||||||
|
}
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
@ -1239,7 +1240,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_location;
|
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)) {
|
||||||
|
@ -1251,7 +1252,7 @@ void EmitContext::DefineInputs(const IR::Program& program) {
|
||||||
if (input_type == AttributeType::Disabled) {
|
if (input_type == AttributeType::Disabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
used_location.set(index);
|
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));
|
||||||
|
@ -1277,17 +1278,20 @@ void EmitContext::DefineInputs(const IR::Program& program) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
size_t previous_unused_location = 0;
|
||||||
if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
||||||
size_t location = FindFistUnUsedLocation(used_location);
|
size_t location = FindFistUnUsedLocation(used_locations, previous_unused_location);
|
||||||
used_location.set(location);
|
previous_unused_location = location;
|
||||||
|
used_locations.set(location);
|
||||||
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)) {
|
||||||
size_t location = FindFistUnUsedLocation(used_location);
|
size_t location = FindFistUnUsedLocation(used_locations, previous_unused_location);
|
||||||
used_location.set(location);
|
previous_unused_location = location;
|
||||||
|
used_locations.set(location);
|
||||||
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;
|
||||||
|
@ -1343,24 +1347,27 @@ 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_location;
|
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_location.set(index);
|
used_locations.set(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
size_t previous_unused_location = 0;
|
||||||
if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
||||||
size_t location = FindFistUnUsedLocation(used_location);
|
size_t location = FindFistUnUsedLocation(used_locations, previous_unused_location);
|
||||||
used_location.set(location);
|
previous_unused_location = location;
|
||||||
|
used_locations.set(location);
|
||||||
const Id id{DefineOutput(*this, F32[4], invocations)};
|
const Id id{DefineOutput(*this, F32[4], invocations)};
|
||||||
Decorate(id, spv::Decoration::Location, static_cast<u32>(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)) {
|
||||||
size_t location = FindFistUnUsedLocation(used_location);
|
size_t location = FindFistUnUsedLocation(used_locations, previous_unused_location);
|
||||||
used_location.set(location);
|
previous_unused_location = location;
|
||||||
|
used_locations.set(location);
|
||||||
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;
|
||||||
|
|
|
@ -50,16 +50,16 @@ bool IsFixedFncTexture(IR::Attribute attribute) {
|
||||||
|
|
||||||
u32 FixedFncTextureAttributeIndex(IR::Attribute attribute) {
|
u32 FixedFncTextureAttributeIndex(IR::Attribute attribute) {
|
||||||
if (!IsFixedFncTexture(attribute)) {
|
if (!IsFixedFncTexture(attribute)) {
|
||||||
throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute);
|
throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute);
|
||||||
}
|
}
|
||||||
return (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4u;
|
return (static_cast<u32>(attribute) - static_cast<u32>(IR::Attribute::FixedFncTexture0S)) / 4u;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 FixedFncTextureAttributeElement(IR::Attribute attribute) {
|
u32 FixedFncTextureAttributeElement(IR::Attribute attribute) {
|
||||||
if (!IsFixedFncTexture(attribute)) {
|
if (!IsFixedFncTexture(attribute)) {
|
||||||
throw InvalidArgument("Attribute is not fixedfnctexture {}", attribute);
|
throw InvalidArgument("Attribute {} is not a FixedFncTexture", attribute);
|
||||||
}
|
}
|
||||||
return static_cast<u32>(attribute) % 4;
|
return static_cast<u32>(attribute) % 4u;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
|
@ -93,7 +93,7 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) {
|
||||||
return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id);
|
return OutputAccessChain(ctx, ctx.output_f32, info.id, index_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) {
|
if (IsFixedFncTexture(attr)) {
|
||||||
const u32 index{FixedFncTextureAttributeIndex(attr)};
|
const u32 index{FixedFncTextureAttributeIndex(attr)};
|
||||||
const u32 element{FixedFncTextureAttributeElement(attr)};
|
const u32 element{FixedFncTextureAttributeElement(attr)};
|
||||||
const Id element_id{ctx.Const(element)};
|
const Id element_id{ctx.Const(element)};
|
||||||
|
@ -341,11 +341,11 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
|
||||||
const Id value{ctx.OpLoad(type->id, pointer)};
|
const Id value{ctx.OpLoad(type->id, pointer)};
|
||||||
return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value;
|
return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value;
|
||||||
}
|
}
|
||||||
if (attr >= IR::Attribute::FixedFncTexture0S && attr <= IR::Attribute::FixedFncTexture9Q) {
|
if (IsFixedFncTexture(attr)) {
|
||||||
const u32 index{FixedFncTextureAttributeIndex(attr)};
|
const u32 index{FixedFncTextureAttributeIndex(attr)};
|
||||||
return ctx.OpLoad(ctx.F32[1],
|
const Id attr_id{ctx.input_fixed_fnc_textures[index]};
|
||||||
AttrPointer(ctx, ctx.input_f32, vertex,
|
const Id attr_ptr{AttrPointer(ctx, ctx.input_f32, vertex, attr_id, ctx.Const(element))};
|
||||||
ctx.input_fixed_fnc_textures[index], ctx.Const(element)));
|
return ctx.OpLoad(ctx.F32[1], attr_ptr);
|
||||||
}
|
}
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
case IR::Attribute::PrimitiveId:
|
case IR::Attribute::PrimitiveId:
|
||||||
|
|
Reference in New Issue