yuzu-emu
/
yuzu
Archived
1
0
Fork 0

Support gl_FogFragCoord attribute

This commit is contained in:
vonchenplus 2021-10-31 22:02:05 +08:00
parent 36c21ff6cb
commit 49f9a44235
3 changed files with 58 additions and 48 deletions

View File

@ -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 start_offset) {
size_t FindAndSetNextUnusedLocation(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)) {
start_offset = location;
used_locations.set(location);
return location;
}
}
@ -1279,45 +1281,40 @@ void EmitContext::DefineInputs(const IR::Program& program) {
}
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);
Decorate(id, spv::Decoration::Location,
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
input_front_color = id;
}
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)};
Decorate(id, spv::Decoration::Location, location);
Decorate(id, spv::Decoration::Location,
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
input_front_secondary_color = id;
}
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)};
Decorate(id, spv::Decoration::Location, location);
Decorate(id, spv::Decoration::Location,
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
input_back_color = id;
}
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)};
Decorate(id, spv::Decoration::Location, location);
Decorate(id, spv::Decoration::Location,
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
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) {
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);
Decorate(id, spv::Decoration::Location,
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
input_fixed_fnc_textures[index] = id;
}
}
@ -1380,45 +1377,45 @@ void EmitContext::DefineOutputs(const IR::Program& program) {
}
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));
Decorate(id, spv::Decoration::Location,
static_cast<u32>(
FindAndSetNextUnusedLocation(used_locations, previous_unused_location)));
output_front_color = id;
}
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)};
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;
}
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)};
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;
}
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)};
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;
}
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) {
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);
Decorate(id, spv::Decoration::Location,
FindAndSetNextUnusedLocation(used_locations, previous_unused_location));
output_fixed_fnc_textures[index] = id;
}
}

View File

@ -272,6 +272,7 @@ public:
Id input_front_secondary_color{};
Id input_back_color{};
Id input_back_secondary_color{};
Id input_fog_frag_coord{};
std::array<Id, 10> input_fixed_fnc_textures{};
std::array<Id, 32> input_generics{};
@ -281,6 +282,7 @@ public:
Id output_front_secondary_color{};
Id output_back_color{};
Id output_back_secondary_color{};
Id output_fog_frag_coord{};
std::array<Id, 10> output_fixed_fnc_textures{};
std::array<std::array<GenericElementInfo, 4>, 32> output_generics{};

View File

@ -143,6 +143,11 @@ std::optional<OutAttr> OutputAttrPointer(EmitContext& ctx, IR::Attribute attr) {
const Id element_id{ctx.Const(element)};
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::ClipDistance1:
case IR::Attribute::ClipDistance2:
@ -391,7 +396,8 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
case IR::Attribute::ColorFrontSpecularG:
case IR::Attribute::ColorFrontSpecularB:
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],
AttrPointer(ctx, ctx.input_f32, vertex, ctx.input_front_secondary_color,
ctx.Const(element)));
}
case IR::Attribute::ColorBackDiffuseR:
@ -405,9 +411,14 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
case IR::Attribute::ColorBackSpecularG:
case IR::Attribute::ColorBackSpecularB:
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],
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:
if (ctx.profile.support_vertex_instance_id) {
return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.instance_id));