shader: Implement SR_THREAD_KILL

This commit is contained in:
ReinUsesLisp 2021-04-11 19:16:12 -03:00 committed by ameerj
parent c9337a4ae4
commit 5c61e860e4
10 changed files with 22 additions and 0 deletions

View File

@ -790,6 +790,9 @@ void EmitContext::DefineInputs(const Info& info) {
if (info.uses_local_invocation_id) { if (info.uses_local_invocation_id) {
local_invocation_id = DefineInput(*this, U32[3], spv::BuiltIn::LocalInvocationId); local_invocation_id = DefineInput(*this, U32[3], spv::BuiltIn::LocalInvocationId);
} }
if (info.uses_is_helper_invocation) {
is_helper_invocation = DefineInput(*this, U1, spv::BuiltIn::HelperInvocation);
}
if (info.uses_subgroup_mask) { if (info.uses_subgroup_mask) {
subgroup_mask_eq = DefineInput(*this, U32[4], spv::BuiltIn::SubgroupEqMaskKHR); subgroup_mask_eq = DefineInput(*this, U32[4], spv::BuiltIn::SubgroupEqMaskKHR);
subgroup_mask_lt = DefineInput(*this, U32[4], spv::BuiltIn::SubgroupLtMaskKHR); subgroup_mask_lt = DefineInput(*this, U32[4], spv::BuiltIn::SubgroupLtMaskKHR);

View File

@ -107,6 +107,7 @@ public:
Id workgroup_id{}; Id workgroup_id{};
Id local_invocation_id{}; Id local_invocation_id{};
Id is_helper_invocation{};
Id subgroup_local_invocation_id{}; Id subgroup_local_invocation_id{};
Id subgroup_mask_eq{}; Id subgroup_mask_eq{};
Id subgroup_mask_lt{}; Id subgroup_mask_lt{};

View File

@ -65,6 +65,7 @@ void EmitSetCFlag(EmitContext& ctx);
void EmitSetOFlag(EmitContext& ctx); void EmitSetOFlag(EmitContext& ctx);
Id EmitWorkgroupId(EmitContext& ctx); Id EmitWorkgroupId(EmitContext& ctx);
Id EmitLocalInvocationId(EmitContext& ctx); Id EmitLocalInvocationId(EmitContext& ctx);
Id EmitIsHelperInvocation(EmitContext& ctx);
Id EmitLoadLocal(EmitContext& ctx, Id word_offset); Id EmitLoadLocal(EmitContext& ctx, Id word_offset);
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);

View File

@ -274,6 +274,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 EmitIsHelperInvocation(EmitContext& ctx) {
return ctx.OpLoad(ctx.U1, ctx.is_helper_invocation);
}
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

@ -347,6 +347,10 @@ U32 IREmitter::LocalInvocationIdZ() {
return U32{CompositeExtract(Inst(Opcode::LocalInvocationId), 2)}; return U32{CompositeExtract(Inst(Opcode::LocalInvocationId), 2)};
} }
U1 IREmitter::IsHelperInvocation() {
return Inst<U1>(Opcode::IsHelperInvocation);
}
U32 IREmitter::LaneId() { U32 IREmitter::LaneId() {
return Inst<U32>(Opcode::LaneId); return Inst<U32>(Opcode::LaneId);
} }

View File

@ -90,6 +90,8 @@ public:
[[nodiscard]] U32 LocalInvocationIdY(); [[nodiscard]] U32 LocalInvocationIdY();
[[nodiscard]] U32 LocalInvocationIdZ(); [[nodiscard]] U32 LocalInvocationIdZ();
[[nodiscard]] U1 IsHelperInvocation();
[[nodiscard]] U32 LaneId(); [[nodiscard]] U32 LaneId();
[[nodiscard]] U32 LoadGlobalU8(const U64& address); [[nodiscard]] U32 LoadGlobalU8(const U64& address);

View File

@ -58,6 +58,7 @@ OPCODE(SetCFlag, Void, U1,
OPCODE(SetOFlag, Void, U1, ) OPCODE(SetOFlag, Void, U1, )
OPCODE(WorkgroupId, U32x3, ) OPCODE(WorkgroupId, U32x3, )
OPCODE(LocalInvocationId, U32x3, ) OPCODE(LocalInvocationId, U32x3, )
OPCODE(IsHelperInvocation, U1, )
// Undefined // Undefined
OPCODE(UndefU1, U1, ) OPCODE(UndefU1, U1, )

View File

@ -113,6 +113,8 @@ enum class SpecialRegister : u64 {
[[nodiscard]] IR::U32 Read(IR::IREmitter& ir, SpecialRegister special_register) { [[nodiscard]] IR::U32 Read(IR::IREmitter& ir, SpecialRegister special_register) {
switch (special_register) { switch (special_register) {
case SpecialRegister::SR_THREAD_KILL:
return IR::U32{ir.Select(ir.IsHelperInvocation(), ir.Imm32(-1), ir.Imm32(0))};
case SpecialRegister::SR_TID_X: case SpecialRegister::SR_TID_X:
return ir.LocalInvocationIdX(); return ir.LocalInvocationIdX();
case SpecialRegister::SR_TID_Y: case SpecialRegister::SR_TID_Y:

View File

@ -348,6 +348,9 @@ void VisitUsages(Info& info, IR::Inst& inst) {
case IR::Opcode::LocalInvocationId: case IR::Opcode::LocalInvocationId:
info.uses_local_invocation_id = true; info.uses_local_invocation_id = true;
break; break;
case IR::Opcode::IsHelperInvocation:
info.uses_is_helper_invocation = true;
break;
case IR::Opcode::LaneId: case IR::Opcode::LaneId:
case IR::Opcode::ShuffleIndex: case IR::Opcode::ShuffleIndex:
case IR::Opcode::ShuffleUp: case IR::Opcode::ShuffleUp:

View File

@ -92,6 +92,7 @@ struct Info {
bool uses_workgroup_id{}; bool uses_workgroup_id{};
bool uses_local_invocation_id{}; bool uses_local_invocation_id{};
bool uses_is_helper_invocation{};
bool uses_subgroup_invocation_id{}; bool uses_subgroup_invocation_id{};
std::array<InputVarying, 32> input_generics{}; std::array<InputVarying, 32> input_generics{};