recompiler: proper VS inputs initialization
This commit is contained in:
parent
a75851f7e2
commit
1b94f07a6a
|
@ -131,6 +131,13 @@ Id EmitReadConstBufferU32(EmitContext& ctx, u32 handle, Id index) {
|
||||||
return ctx.OpBitcast(ctx.U32[1], EmitReadConstBuffer(ctx, handle, index));
|
return ctx.OpBitcast(ctx.U32[1], EmitReadConstBuffer(ctx, handle, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Id EmitReadStepRate(EmitContext& ctx, int rate_idx) {
|
||||||
|
return ctx.OpLoad(
|
||||||
|
ctx.U32[1], ctx.OpAccessChain(ctx.TypePointer(spv::StorageClass::PushConstant, ctx.U32[1]),
|
||||||
|
ctx.instance_step_rates,
|
||||||
|
rate_idx == 0 ? ctx.u32_zero_value : ctx.u32_one_value));
|
||||||
|
}
|
||||||
|
|
||||||
Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, u32 comp) {
|
Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, u32 comp) {
|
||||||
if (IR::IsParam(attr)) {
|
if (IR::IsParam(attr)) {
|
||||||
const u32 index{u32(attr) - u32(IR::Attribute::Param0)};
|
const u32 index{u32(attr) - u32(IR::Attribute::Param0)};
|
||||||
|
@ -149,11 +156,7 @@ Id EmitGetAttribute(EmitContext& ctx, IR::Attribute attr, u32 comp) {
|
||||||
return ctx.OpLoad(param.component_type, param.id);
|
return ctx.OpLoad(param.component_type, param.id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const auto rate_idx = param.id.value == 0 ? ctx.u32_zero_value : ctx.u32_one_value;
|
const auto step_rate = EmitReadStepRate(ctx, param.id.value);
|
||||||
const auto step_rate = ctx.OpLoad(
|
|
||||||
ctx.U32[1],
|
|
||||||
ctx.OpAccessChain(ctx.TypePointer(spv::StorageClass::PushConstant, ctx.U32[1]),
|
|
||||||
ctx.instance_step_rates, rate_idx));
|
|
||||||
const auto offset = ctx.OpIAdd(
|
const auto offset = ctx.OpIAdd(
|
||||||
ctx.U32[1],
|
ctx.U32[1],
|
||||||
ctx.OpIMul(
|
ctx.OpIMul(
|
||||||
|
@ -182,6 +185,12 @@ Id EmitGetAttributeU32(EmitContext& ctx, IR::Attribute attr, u32 comp) {
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
case IR::Attribute::VertexId:
|
case IR::Attribute::VertexId:
|
||||||
return ctx.OpLoad(ctx.U32[1], ctx.vertex_index);
|
return ctx.OpLoad(ctx.U32[1], ctx.vertex_index);
|
||||||
|
case IR::Attribute::InstanceId:
|
||||||
|
return ctx.OpLoad(ctx.U32[1], ctx.instance_id);
|
||||||
|
case IR::Attribute::InstanceId0:
|
||||||
|
return EmitReadStepRate(ctx, 0);
|
||||||
|
case IR::Attribute::InstanceId1:
|
||||||
|
return EmitReadStepRate(ctx, 1);
|
||||||
case IR::Attribute::WorkgroupId:
|
case IR::Attribute::WorkgroupId:
|
||||||
return ctx.OpCompositeExtract(ctx.U32[1], ctx.OpLoad(ctx.U32[3], ctx.workgroup_id), comp);
|
return ctx.OpCompositeExtract(ctx.U32[1], ctx.OpLoad(ctx.U32[3], ctx.workgroup_id), comp);
|
||||||
case IR::Attribute::LocalInvocationId:
|
case IR::Attribute::LocalInvocationId:
|
||||||
|
|
|
@ -35,10 +35,20 @@ void Translator::EmitPrologue() {
|
||||||
IR::VectorReg dst_vreg = IR::VectorReg::V0;
|
IR::VectorReg dst_vreg = IR::VectorReg::V0;
|
||||||
switch (info.stage) {
|
switch (info.stage) {
|
||||||
case Stage::Vertex:
|
case Stage::Vertex:
|
||||||
// https://github.com/chaotic-cx/mesa-mirror/blob/72326e15/src/amd/vulkan/radv_shader_args.c#L146C1-L146C23
|
// v0: vertex ID, always present
|
||||||
ir.SetVectorReg(dst_vreg++, ir.GetAttributeU32(IR::Attribute::VertexId));
|
ir.SetVectorReg(dst_vreg++, ir.GetAttributeU32(IR::Attribute::VertexId));
|
||||||
ir.SetVectorReg(dst_vreg++, ir.GetAttributeU32(IR::Attribute::InstanceId));
|
// v1: instance ID, step rate 0
|
||||||
ir.SetVectorReg(dst_vreg++, ir.GetAttributeU32(IR::Attribute::PrimitiveId));
|
if (info.num_input_vgprs > 0) {
|
||||||
|
ir.SetVectorReg(dst_vreg++, ir.GetAttributeU32(IR::Attribute::InstanceId0));
|
||||||
|
}
|
||||||
|
// v2: instance ID, step rate 1
|
||||||
|
if (info.num_input_vgprs > 1) {
|
||||||
|
ir.SetVectorReg(dst_vreg++, ir.GetAttributeU32(IR::Attribute::InstanceId1));
|
||||||
|
}
|
||||||
|
// v3: instance ID, plain
|
||||||
|
if (info.num_input_vgprs > 2) {
|
||||||
|
ir.SetVectorReg(dst_vreg++, ir.GetAttributeU32(IR::Attribute::InstanceId));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Stage::Fragment:
|
case Stage::Fragment:
|
||||||
// https://github.com/chaotic-cx/mesa-mirror/blob/72326e15/src/amd/vulkan/radv_shader_args.c#L258
|
// https://github.com/chaotic-cx/mesa-mirror/blob/72326e15/src/amd/vulkan/radv_shader_args.c#L258
|
||||||
|
|
|
@ -72,6 +72,8 @@ enum class Attribute : u64 {
|
||||||
LocalInvocationId = 75,
|
LocalInvocationId = 75,
|
||||||
LocalInvocationIndex = 76,
|
LocalInvocationIndex = 76,
|
||||||
FragCoord = 77,
|
FragCoord = 77,
|
||||||
|
InstanceId0 = 78, // step rate 0
|
||||||
|
InstanceId1 = 79, // step rate 1
|
||||||
Max,
|
Max,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,7 @@ struct Info {
|
||||||
std::array<u32, 3> workgroup_size{};
|
std::array<u32, 3> workgroup_size{};
|
||||||
|
|
||||||
u32 num_user_data;
|
u32 num_user_data;
|
||||||
|
u32 num_input_vgprs;
|
||||||
std::span<const u32> user_data;
|
std::span<const u32> user_data;
|
||||||
Stage stage;
|
Stage stage;
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@ struct Liverpool {
|
||||||
union {
|
union {
|
||||||
BitField<0, 6, u64> num_vgprs;
|
BitField<0, 6, u64> num_vgprs;
|
||||||
BitField<6, 4, u64> num_sgprs;
|
BitField<6, 4, u64> num_sgprs;
|
||||||
|
BitField<24, 2, u64> vgpr_comp_cnt; // SPI provided per-thread inputs
|
||||||
BitField<33, 5, u64> num_user_regs;
|
BitField<33, 5, u64> num_user_regs;
|
||||||
} settings;
|
} settings;
|
||||||
UserData user_data;
|
UserData user_data;
|
||||||
|
|
|
@ -72,6 +72,7 @@ Shader::Info MakeShaderInfo(Shader::Stage stage, std::span<const u32, 16> user_d
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
case Shader::Stage::Vertex: {
|
case Shader::Stage::Vertex: {
|
||||||
info.num_user_data = regs.vs_program.settings.num_user_regs;
|
info.num_user_data = regs.vs_program.settings.num_user_regs;
|
||||||
|
info.num_input_vgprs = regs.vs_program.settings.vgpr_comp_cnt;
|
||||||
BuildVsOutputs(info, regs.vs_output_control);
|
BuildVsOutputs(info, regs.vs_output_control);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue