1
0
Fork 0
forked from suyu/suyu

shader: Implement PrimitiveId

This commit is contained in:
ReinUsesLisp 2021-04-16 01:55:06 -03:00 committed by ameerj
parent 183855e396
commit b0f1255c8c
5 changed files with 10 additions and 0 deletions

View file

@ -1021,6 +1021,9 @@ void EmitContext::DefineInputs(const Info& info) {
fswzadd_lut_b = fswzadd_lut_b =
ConstantComposite(F32[4], f32_minus_one, f32_minus_one, f32_one, f32_minus_one); ConstantComposite(F32[4], f32_minus_one, f32_minus_one, f32_one, f32_minus_one);
} }
if (info.loads_primitive_id) {
primitive_id = DefineInput(*this, U32[1], false, spv::BuiltIn::PrimitiveId);
}
if (info.loads_position) { if (info.loads_position) {
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};

View file

@ -167,6 +167,7 @@ public:
Id clip_distances{}; Id clip_distances{};
Id layer{}; Id layer{};
Id viewport_index{}; Id viewport_index{};
Id primitive_id{};
Id fswzadd_lut_a{}; Id fswzadd_lut_a{};
Id fswzadd_lut_b{}; Id fswzadd_lut_b{};

View file

@ -210,6 +210,8 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, Id vertex) {
return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value; return type->needs_cast ? ctx.OpBitcast(ctx.F32[1], value) : value;
} }
switch (attr) { switch (attr) {
case IR::Attribute::PrimitiveId:
return ctx.OpLoad(ctx.U32[1], ctx.primitive_id);
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

@ -34,6 +34,9 @@ void GetAttribute(Info& info, IR::Attribute attribute) {
return; return;
} }
switch (attribute) { switch (attribute) {
case IR::Attribute::PrimitiveId:
info.loads_primitive_id = true;
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

@ -107,6 +107,7 @@ struct Info {
std::array<bool, 30> uses_patches{}; std::array<bool, 30> uses_patches{};
std::array<InputVarying, 32> input_generics{}; std::array<InputVarying, 32> input_generics{};
bool loads_primitive_id{};
bool loads_position{}; bool loads_position{};
bool loads_instance_id{}; bool loads_instance_id{};
bool loads_vertex_id{}; bool loads_vertex_id{};