3
0
Fork 0
forked from suyu/suyu

shader: Implement SR_LaneId

This commit is contained in:
FernandoS27 2021-04-02 23:05:47 +02:00 committed by ameerj
parent 595806fb1c
commit 45d547af11
7 changed files with 15 additions and 0 deletions

View file

@ -71,6 +71,7 @@ void EmitSetMXFlag(EmitContext& ctx);
Id EmitWorkgroupId(EmitContext& ctx); Id EmitWorkgroupId(EmitContext& ctx);
Id EmitLocalInvocationId(EmitContext& ctx); Id EmitLocalInvocationId(EmitContext& ctx);
Id EmitLoadLocal(EmitContext& ctx, Id word_offset); Id EmitLoadLocal(EmitContext& ctx, Id word_offset);
Id EmitLaneId(EmitContext& ctx);
void EmitWriteLocal(EmitContext& ctx, Id word_offset, Id value); void EmitWriteLocal(EmitContext& ctx, Id word_offset, Id value);
Id EmitUndefU1(EmitContext& ctx); Id EmitUndefU1(EmitContext& ctx);
Id EmitUndefU8(EmitContext& ctx); Id EmitUndefU8(EmitContext& ctx);

View file

@ -303,6 +303,10 @@ Id EmitLocalInvocationId(EmitContext& ctx) {
return ctx.OpLoad(ctx.U32[3], ctx.local_invocation_id); return ctx.OpLoad(ctx.U32[3], ctx.local_invocation_id);
} }
Id EmitLaneId(EmitContext& ctx) {
return ctx.OpLoad(ctx.U32[1], ctx.subgroup_local_invocation_id);
}
Id EmitLoadLocal(EmitContext& ctx, Id word_offset) { Id EmitLoadLocal(EmitContext& ctx, Id word_offset) {
const Id pointer{ctx.OpAccessChain(ctx.private_u32, ctx.local_memory, word_offset)}; const Id pointer{ctx.OpAccessChain(ctx.private_u32, ctx.local_memory, word_offset)};
return ctx.OpLoad(ctx.U32[1], pointer); return ctx.OpLoad(ctx.U32[1], pointer);

View file

@ -355,6 +355,10 @@ U32 IREmitter::LocalInvocationIdZ() {
return U32{CompositeExtract(Inst(Opcode::LocalInvocationId), 2)}; return U32{CompositeExtract(Inst(Opcode::LocalInvocationId), 2)};
} }
U32 IREmitter::LaneId() {
return Inst<U32>(Opcode::LaneId);
}
U32 IREmitter::LoadGlobalU8(const U64& address) { U32 IREmitter::LoadGlobalU8(const U64& address) {
return Inst<U32>(Opcode::LoadGlobalU8, address); return Inst<U32>(Opcode::LoadGlobalU8, address);
} }

View file

@ -97,6 +97,8 @@ public:
[[nodiscard]] U32 LocalInvocationIdY(); [[nodiscard]] U32 LocalInvocationIdY();
[[nodiscard]] U32 LocalInvocationIdZ(); [[nodiscard]] U32 LocalInvocationIdZ();
[[nodiscard]] U32 LaneId();
[[nodiscard]] U32 LoadGlobalU8(const U64& address); [[nodiscard]] U32 LoadGlobalU8(const U64& address);
[[nodiscard]] U32 LoadGlobalS8(const U64& address); [[nodiscard]] U32 LoadGlobalS8(const U64& address);
[[nodiscard]] U32 LoadGlobalU16(const U64& address); [[nodiscard]] U32 LoadGlobalU16(const U64& address);

View file

@ -63,6 +63,7 @@ OPCODE(SetTRFlag, Void, U1,
OPCODE(SetMXFlag, Void, U1, ) OPCODE(SetMXFlag, Void, U1, )
OPCODE(WorkgroupId, U32x3, ) OPCODE(WorkgroupId, U32x3, )
OPCODE(LocalInvocationId, U32x3, ) OPCODE(LocalInvocationId, U32x3, )
OPCODE(LaneId, U32, )
// Undefined // Undefined
OPCODE(UndefU1, U1, ) OPCODE(UndefU1, U1, )

View file

@ -99,6 +99,8 @@ enum class SpecialRegister : u64 {
return ir.Imm32(Common::BitCast<u32>(1.0f)); return ir.Imm32(Common::BitCast<u32>(1.0f));
case SpecialRegister::SR_WSCALEFACTOR_Z: case SpecialRegister::SR_WSCALEFACTOR_Z:
return ir.Imm32(Common::BitCast<u32>(1.0f)); return ir.Imm32(Common::BitCast<u32>(1.0f));
case SpecialRegister::SR_LANEID:
return ir.LaneId();
default: default:
throw NotImplementedException("S2R special register {}", special_register); throw NotImplementedException("S2R special register {}", special_register);
} }

View file

@ -340,6 +340,7 @@ void VisitUsages(Info& info, IR::Inst& inst) {
case IR::Opcode::ShuffleUp: case IR::Opcode::ShuffleUp:
case IR::Opcode::ShuffleDown: case IR::Opcode::ShuffleDown:
case IR::Opcode::ShuffleButterfly: case IR::Opcode::ShuffleButterfly:
case IR::Opcode::LaneId:
info.uses_subgroup_invocation_id = true; info.uses_subgroup_invocation_id = true;
break; break;
case IR::Opcode::GetCbufU8: case IR::Opcode::GetCbufU8: