3
0
Fork 0
forked from suyu/suyu

glasm: Implement geometry shader attribute reads

This commit is contained in:
ReinUsesLisp 2021-05-20 19:21:38 -03:00 committed by ameerj
parent 83cef0426b
commit 79929be833
2 changed files with 18 additions and 4 deletions

View file

@ -74,6 +74,9 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
InterpDecorator(generic.interpolation), index, attr_stage, index, index); InterpDecorator(generic.interpolation), index, attr_stage, index, index);
} }
} }
if (stage == Stage::Geometry && info.loads_position) {
Add("ATTRIB vertex_position=vertex.position;");
}
for (size_t index = 0; index < program.info.stores_frag_color.size(); ++index) { for (size_t index = 0; index < program.info.stores_frag_color.size(); ++index) {
if (!program.info.stores_frag_color[index]) { if (!program.info.stores_frag_color[index]) {
continue; continue;

View file

@ -19,6 +19,14 @@ void GetCbuf(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU
const Register ret{ctx.reg_alloc.Define(inst)}; const Register ret{ctx.reg_alloc.Define(inst)};
ctx.Add("LDC.{} {},c{}[{}];", size, ret, binding.U32(), offset); ctx.Add("LDC.{} {},c{}[{}];", size, ret, binding.U32(), offset);
} }
std::string VertexIndex(EmitContext& ctx, ScalarU32 vertex) {
if (ctx.stage == Stage::Geometry) {
return fmt::format("[{}]", vertex);
} else {
return "";
}
}
} // Anonymous namespace } // Anonymous namespace
void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset) { void EmitGetCbufU8(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, ScalarU32 offset) {
@ -50,13 +58,12 @@ void EmitGetCbufU32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding
GetCbuf(ctx, inst, binding, offset, "U32X2"); GetCbuf(ctx, inst, binding, offset, "U32X2");
} }
void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr, ScalarU32 vertex) {
[[maybe_unused]] ScalarU32 vertex) {
const u32 element{static_cast<u32>(attr) % 4}; const u32 element{static_cast<u32>(attr) % 4};
const char swizzle{"xyzw"[element]}; const char swizzle{"xyzw"[element]};
if (IR::IsGeneric(attr)) { if (IR::IsGeneric(attr)) {
const u32 index{IR::GenericAttributeIndex(attr)}; const u32 index{IR::GenericAttributeIndex(attr)};
ctx.Add("MOV.F {}.x,in_attr{}[0].{};", inst, index, swizzle); ctx.Add("MOV.F {}.x,in_attr{}{}[0].{};", inst, index, VertexIndex(ctx, vertex), swizzle);
return; return;
} }
switch (attr) { switch (attr) {
@ -64,7 +71,11 @@ void EmitGetAttribute(EmitContext& ctx, IR::Inst& inst, IR::Attribute attr,
case IR::Attribute::PositionY: case IR::Attribute::PositionY:
case IR::Attribute::PositionZ: case IR::Attribute::PositionZ:
case IR::Attribute::PositionW: case IR::Attribute::PositionW:
if (ctx.stage == Stage::Geometry) {
ctx.Add("MOV.F {}.x,vertex_position{}.{};", inst, VertexIndex(ctx, vertex), swizzle);
} else {
ctx.Add("MOV.F {}.x,{}.position.{};", inst, ctx.attrib_name, swizzle); ctx.Add("MOV.F {}.x,{}.position.{};", inst, ctx.attrib_name, swizzle);
}
break; break;
case IR::Attribute::PointSpriteS: case IR::Attribute::PointSpriteS:
case IR::Attribute::PointSpriteT: case IR::Attribute::PointSpriteT: