shader: Implement miss attribute layer

This commit is contained in:
FengChen 2022-11-11 00:25:03 +08:00
parent ad9e5bc5b7
commit 60e0d4a177
5 changed files with 13 additions and 0 deletions

View file

@ -320,6 +320,7 @@ void SetupOptions(const IR::Program& program, const Profile& profile,
} }
if (stage == Stage::Fragment) { if (stage == Stage::Fragment) {
header += "OPTION ARB_draw_buffers;"; header += "OPTION ARB_draw_buffers;";
header += "OPTION ARB_fragment_layer_viewport;";
} }
} }

View file

@ -104,6 +104,9 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, Scal
case IR::Attribute::PrimitiveId: case IR::Attribute::PrimitiveId:
ctx.Add("MOV.F {}.x,primitive.id;", inst); ctx.Add("MOV.F {}.x,primitive.id;", inst);
break; break;
case IR::Attribute::Layer:
ctx.Add("MOV.F {}.x,fragment.layer;", inst);
break;
case IR::Attribute::PositionX: case IR::Attribute::PositionX:
case IR::Attribute::PositionY: case IR::Attribute::PositionY:
case IR::Attribute::PositionZ: case IR::Attribute::PositionZ:

View file

@ -205,6 +205,9 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
case IR::Attribute::PrimitiveId: case IR::Attribute::PrimitiveId:
ctx.AddF32("{}=itof(gl_PrimitiveID);", inst); ctx.AddF32("{}=itof(gl_PrimitiveID);", inst);
break; break;
case IR::Attribute::Layer:
ctx.AddF32("{}=itof(gl_Layer);", inst);
break;
case IR::Attribute::PositionX: case IR::Attribute::PositionX:
case IR::Attribute::PositionY: case IR::Attribute::PositionY:
case IR::Attribute::PositionZ: case IR::Attribute::PositionZ:

View file

@ -315,6 +315,8 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
switch (attr) { switch (attr) {
case IR::Attribute::PrimitiveId: case IR::Attribute::PrimitiveId:
return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.primitive_id)); return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.primitive_id));
case IR::Attribute::Layer:
return ctx.OpBitcast(ctx.F32[1], ctx.OpLoad(ctx.U32[1], ctx.layer));
case IR::Attribute::PositionX: case IR::Attribute::PositionX:
case IR::Attribute::PositionY: case IR::Attribute::PositionY:
case IR::Attribute::PositionZ: case IR::Attribute::PositionZ:

View file

@ -1355,6 +1355,10 @@ void EmitContext::DefineInputs(const IR::Program& program) {
if (loads[IR::Attribute::PrimitiveId]) { if (loads[IR::Attribute::PrimitiveId]) {
primitive_id = DefineInput(*this, U32[1], false, spv::BuiltIn::PrimitiveId); primitive_id = DefineInput(*this, U32[1], false, spv::BuiltIn::PrimitiveId);
} }
if (loads[IR::Attribute::Layer]) {
AddCapability(spv::Capability::Geometry);
layer = DefineInput(*this, U32[1], false, spv::BuiltIn::Layer);
}
if (loads.AnyComponent(IR::Attribute::PositionX)) { if (loads.AnyComponent(IR::Attribute::PositionX)) {
const bool is_fragment{stage != Stage::Fragment}; const bool is_fragment{stage != Stage::Fragment};
const spv::BuiltIn built_in{is_fragment ? spv::BuiltIn::Position : spv::BuiltIn::FragCoord}; const spv::BuiltIn built_in{is_fragment ? spv::BuiltIn::Position : spv::BuiltIn::FragCoord};