Support gl_FogFragCoord attribute
This commit is contained in:
parent
36c21ff6cb
commit
49f9a44235
@ -430,10 +430,12 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t FindNextUnusedLocation(const std::bitset<IR::NUM_GENERICS>& used_locations,
|
size_t FindAndSetNextUnusedLocation(std::bitset<IR::NUM_GENERICS>& used_locations,
|
||||||
size_t start_offset) {
|
size_t& start_offset) {
|
||||||
for (size_t location = start_offset; location < used_locations.size(); ++location) {
|
for (size_t location = start_offset; location < used_locations.size(); ++location) {
|
||||||
if (!used_locations.test(location)) {
|
if (!used_locations.test(location)) {
|
||||||
|
start_offset = location;
|
||||||
|
used_locations.set(location);
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1279,45 +1281,40 @@ void EmitContext::DefineInputs(const IR::Program& program) {
|
|||||||
}
|
}
|
||||||
size_t previous_unused_location = 0;
|
size_t previous_unused_location = 0;
|
||||||
if (loads.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
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)};
|
const Id id{DefineInput(*this, F32[4], true)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location,
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
|
||||||
input_front_color = id;
|
input_front_color = id;
|
||||||
}
|
}
|
||||||
if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) {
|
if (loads.AnyComponent(IR::Attribute::ColorFrontSpecularR)) {
|
||||||
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)};
|
const Id id{DefineInput(*this, F32[4], true)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location,
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
|
||||||
input_front_secondary_color = id;
|
input_front_secondary_color = id;
|
||||||
}
|
}
|
||||||
if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) {
|
if (loads.AnyComponent(IR::Attribute::ColorBackDiffuseR)) {
|
||||||
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)};
|
const Id id{DefineInput(*this, F32[4], true)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location,
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
|
||||||
input_back_color = id;
|
input_back_color = id;
|
||||||
}
|
}
|
||||||
if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) {
|
if (loads.AnyComponent(IR::Attribute::ColorBackSpecularR)) {
|
||||||
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)};
|
const Id id{DefineInput(*this, F32[4], true)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location,
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
|
||||||
input_back_secondary_color = id;
|
input_back_secondary_color = id;
|
||||||
}
|
}
|
||||||
|
if (loads.AnyComponent(IR::Attribute::FogCoordinate)) {
|
||||||
|
const Id id{DefineInput(*this, F32[4], true)};
|
||||||
|
Decorate(id, spv::Decoration::Location,
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
|
||||||
|
input_fog_frag_coord = 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)) {
|
||||||
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)};
|
const Id id{DefineInput(*this, F32[4], true)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location,
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
|
||||||
input_fixed_fnc_textures[index] = id;
|
input_fixed_fnc_textures[index] = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1380,45 +1377,45 @@ void EmitContext::DefineOutputs(const IR::Program& program) {
|
|||||||
}
|
}
|
||||||
size_t previous_unused_location = 0;
|
size_t previous_unused_location = 0;
|
||||||
if (info.stores.AnyComponent(IR::Attribute::ColorFrontDiffuseR)) {
|
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)};
|
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>(
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location)));
|
||||||
output_front_color = id;
|
output_front_color = id;
|
||||||
}
|
}
|
||||||
if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) {
|
if (info.stores.AnyComponent(IR::Attribute::ColorFrontSpecularR)) {
|
||||||
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)};
|
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>(
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location)));
|
||||||
output_front_secondary_color = id;
|
output_front_secondary_color = id;
|
||||||
}
|
}
|
||||||
if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) {
|
if (info.stores.AnyComponent(IR::Attribute::ColorBackDiffuseR)) {
|
||||||
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)};
|
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>(
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location)));
|
||||||
output_back_color = id;
|
output_back_color = id;
|
||||||
}
|
}
|
||||||
if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) {
|
if (info.stores.AnyComponent(IR::Attribute::ColorBackSpecularR)) {
|
||||||
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)};
|
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>(
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location)));
|
||||||
output_back_secondary_color = id;
|
output_back_secondary_color = id;
|
||||||
}
|
}
|
||||||
|
if (info.stores.AnyComponent(IR::Attribute::FogCoordinate)) {
|
||||||
|
const Id id{DefineOutput(*this, F32[4], invocations)};
|
||||||
|
Decorate(id, spv::Decoration::Location,
|
||||||
|
static_cast<u32>(
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location)));
|
||||||
|
output_fog_frag_coord = 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)) {
|
||||||
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)};
|
const Id id{DefineOutput(*this, F32[4], invocations)};
|
||||||
Decorate(id, spv::Decoration::Location, location);
|
Decorate(id, spv::Decoration::Location,
|
||||||
|
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
|
||||||
output_fixed_fnc_textures[index] = id;
|
output_fixed_fnc_textures[index] = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -272,6 +272,7 @@ public:
|
|||||||
Id input_front_secondary_color{};
|
Id input_front_secondary_color{};
|
||||||
Id input_back_color{};
|
Id input_back_color{};
|
||||||
Id input_back_secondary_color{};
|
Id input_back_secondary_color{};
|
||||||
|
Id input_fog_frag_coord{};
|
||||||
std::array<Id, 10> input_fixed_fnc_textures{};
|
std::array<Id, 10> input_fixed_fnc_textures{};
|
||||||
std::array<Id, 32> input_generics{};
|
std::array<Id, 32> input_generics{};
|
||||||
|
|
||||||
@ -281,6 +282,7 @@ public:
|
|||||||
Id output_front_secondary_color{};
|
Id output_front_secondary_color{};
|
||||||
Id output_back_color{};
|
Id output_back_color{};
|
||||||
Id output_back_secondary_color{};
|
Id output_back_secondary_color{};
|
||||||
|
Id output_fog_frag_coord{};
|
||||||
std::array<Id, 10> output_fixed_fnc_textures{};
|
std::array<Id, 10> output_fixed_fnc_textures{};
|
||||||
std::array<std::array<GenericElementInfo, 4>, 32> output_generics{};
|
std::array<std::array<GenericElementInfo, 4>, 32> output_generics{};
|
||||||
|
|
||||||
|
@ -143,6 +143,11 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) {
|
|||||||
const Id element_id{ctx.Const(element)};
|
const Id element_id{ctx.Const(element)};
|
||||||
return OutputAccessChain(ctx, ctx.output_f32, ctx.output_back_secondary_color, element_id);
|
return OutputAccessChain(ctx, ctx.output_f32, ctx.output_back_secondary_color, element_id);
|
||||||
}
|
}
|
||||||
|
case IR::Attribute::FogCoordinate: {
|
||||||
|
const u32 element{static_cast<u32>(attr) % 4};
|
||||||
|
const Id element_id{ctx.Const(element)};
|
||||||
|
return OutputAccessChain(ctx, ctx.output_f32, ctx.output_fog_frag_coord, element_id);
|
||||||
|
}
|
||||||
case IR::Attribute::ClipDistance0:
|
case IR::Attribute::ClipDistance0:
|
||||||
case IR::Attribute::ClipDistance1:
|
case IR::Attribute::ClipDistance1:
|
||||||
case IR::Attribute::ClipDistance2:
|
case IR::Attribute::ClipDistance2:
|
||||||
@ -391,8 +396,9 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
|
|||||||
case IR::Attribute::ColorFrontSpecularG:
|
case IR::Attribute::ColorFrontSpecularG:
|
||||||
case IR::Attribute::ColorFrontSpecularB:
|
case IR::Attribute::ColorFrontSpecularB:
|
||||||
case IR::Attribute::ColorFrontSpecularA: {
|
case IR::Attribute::ColorFrontSpecularA: {
|
||||||
return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_secondary_color,
|
return ctx.OpLoad(ctx.F32[1],
|
||||||
ctx.Const(element)));
|
AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_secondary_color,
|
||||||
|
ctx.Const(element)));
|
||||||
}
|
}
|
||||||
case IR::Attribute::ColorBackDiffuseR:
|
case IR::Attribute::ColorBackDiffuseR:
|
||||||
case IR::Attribute::ColorBackDiffuseG:
|
case IR::Attribute::ColorBackDiffuseG:
|
||||||
@ -405,8 +411,13 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
|
|||||||
case IR::Attribute::ColorBackSpecularG:
|
case IR::Attribute::ColorBackSpecularG:
|
||||||
case IR::Attribute::ColorBackSpecularB:
|
case IR::Attribute::ColorBackSpecularB:
|
||||||
case IR::Attribute::ColorBackSpecularA: {
|
case IR::Attribute::ColorBackSpecularA: {
|
||||||
return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_back_secondary_color,
|
return ctx.OpLoad(ctx.F32[1],
|
||||||
ctx.Const(element)));
|
AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_back_secondary_color,
|
||||||
|
ctx.Const(element)));
|
||||||
|
}
|
||||||
|
case IR::Attribute::FogCoordinate: {
|
||||||
|
return ctx.OpLoad(ctx.F32[1], AttrPointer(ctx, ctx.input_f32, vertex,
|
||||||
|
ctx.input_fog_frag_coord, ctx.Const(element)));
|
||||||
}
|
}
|
||||||
case IR::Attribute::InstanceId:
|
case IR::Attribute::InstanceId:
|
||||||
if (ctx.profile.support_vertex_instance_id) {
|
if (ctx.profile.support_vertex_instance_id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user