[Vulkan] Implement support for color_exp_bias.
This commit is contained in:
parent
9655b76f68
commit
8064926999
|
@ -161,7 +161,7 @@ void SpirvShaderTranslator::StartTranslation() {
|
|||
// Push constants, represented by SpirvPushConstants.
|
||||
Id push_constants_type =
|
||||
b.makeStructType({vec4_float_type_, vec4_float_type_, vec4_float_type_,
|
||||
vec3_float_type_, float_type_, uint_type_},
|
||||
vec4_float_type_, vec4_float_type_, uint_type_},
|
||||
"push_consts_type");
|
||||
b.addDecoration(push_constants_type, spv::Decoration::DecorationBlock);
|
||||
|
||||
|
@ -180,12 +180,12 @@ void SpirvShaderTranslator::StartTranslation() {
|
|||
push_constants_type, 2, spv::Decoration::DecorationOffset,
|
||||
static_cast<int>(offsetof(SpirvPushConstants, point_size)));
|
||||
b.addMemberName(push_constants_type, 2, "point_size");
|
||||
// float3 alpha_test;
|
||||
// float4 alpha_test;
|
||||
b.addMemberDecoration(
|
||||
push_constants_type, 3, spv::Decoration::DecorationOffset,
|
||||
static_cast<int>(offsetof(SpirvPushConstants, alpha_test)));
|
||||
b.addMemberName(push_constants_type, 3, "alpha_test");
|
||||
// float color_exp_bias;
|
||||
// float4 color_exp_bias;
|
||||
b.addMemberDecoration(
|
||||
push_constants_type, 4, spv::Decoration::DecorationOffset,
|
||||
static_cast<int>(offsetof(SpirvPushConstants, color_exp_bias)));
|
||||
|
@ -558,23 +558,16 @@ std::vector<uint8_t> SpirvShaderTranslator::CompleteTranslation() {
|
|||
spv::StorageClass::StorageClassPushConstant, push_consts_,
|
||||
std::vector<Id>({b.makeUintConstant(4)}));
|
||||
auto bias = b.createLoad(bias_ptr);
|
||||
|
||||
auto cond = b.createBinOp(spv::Op::OpFOrdNotEqual, bool_type_, bias,
|
||||
b.makeFloatConstant(0.f));
|
||||
spv::Builder::If bias_if(cond, 0, b);
|
||||
|
||||
auto bias_vector = b.createCompositeConstruct(vec4_float_type_,
|
||||
{bias, bias, bias, bias});
|
||||
|
||||
auto oC0_ptr = b.createAccessChain(
|
||||
spv::StorageClass::StorageClassOutput, frag_outputs_,
|
||||
std::vector<Id>({b.makeUintConstant(0)}));
|
||||
auto oC0_biased = b.createBinOp(spv::Op::OpFMul, vec4_float_type_,
|
||||
b.createLoad(oC0_ptr), bias_vector);
|
||||
|
||||
b.createStore(oC0_biased, oC0_ptr);
|
||||
|
||||
bias_if.makeEndIf();
|
||||
for (uint32_t i = 0; i < 4; i++) {
|
||||
auto bias_value = b.createOp(spv::Op::OpVectorShuffle, vec4_float_type_,
|
||||
{bias, bias, i, i, i, i});
|
||||
auto oC_ptr = b.createAccessChain(
|
||||
spv::StorageClass::StorageClassOutput, frag_outputs_,
|
||||
std::vector<Id>({b.makeUintConstant(i)}));
|
||||
auto oC_biased = b.createBinOp(spv::Op::OpFMul, vec4_float_type_,
|
||||
b.createLoad(oC_ptr), bias_value);
|
||||
b.createStore(oC_biased, oC_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
// Alpha test
|
||||
|
|
|
@ -36,8 +36,8 @@ struct SpirvPushConstants {
|
|||
float point_size[4]; // psx, psy, unused, unused
|
||||
|
||||
// Accessible to fragment shader only:
|
||||
float alpha_test[3]; // alpha test enable, func, ref
|
||||
float color_exp_bias;
|
||||
float alpha_test[4]; // alpha test enable, func, ref
|
||||
float color_exp_bias[4];
|
||||
uint32_t ps_param_gen;
|
||||
};
|
||||
static_assert(sizeof(SpirvPushConstants) <= 128,
|
||||
|
|
|
@ -741,6 +741,14 @@ bool PipelineCache::SetDynamicState(VkCommandBuffer command_buffer,
|
|||
SetShadowRegister(®s.sq_context_misc, XE_GPU_REG_SQ_CONTEXT_MISC);
|
||||
push_constants_dirty |=
|
||||
SetShadowRegister(®s.rb_colorcontrol, XE_GPU_REG_RB_COLORCONTROL);
|
||||
push_constants_dirty |=
|
||||
SetShadowRegister(®s.rb_color_info, XE_GPU_REG_RB_COLOR_INFO);
|
||||
push_constants_dirty |=
|
||||
SetShadowRegister(®s.rb_color1_info, XE_GPU_REG_RB_COLOR1_INFO);
|
||||
push_constants_dirty |=
|
||||
SetShadowRegister(®s.rb_color2_info, XE_GPU_REG_RB_COLOR2_INFO);
|
||||
push_constants_dirty |=
|
||||
SetShadowRegister(®s.rb_color3_info, XE_GPU_REG_RB_COLOR3_INFO);
|
||||
push_constants_dirty |=
|
||||
SetShadowRegister(®s.rb_alpha_ref, XE_GPU_REG_RB_ALPHA_REF);
|
||||
push_constants_dirty |=
|
||||
|
@ -803,6 +811,17 @@ bool PipelineCache::SetDynamicState(VkCommandBuffer command_buffer,
|
|||
push_constants.point_size[1] =
|
||||
static_cast<float>((regs.pa_su_point_size & 0x0000ffff)) / 8.0f;
|
||||
|
||||
reg::RB_COLOR_INFO color_info[4] = {
|
||||
regs.rb_color_info,
|
||||
regs.rb_color1_info,
|
||||
regs.rb_color2_info,
|
||||
regs.rb_color3_info,
|
||||
};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
push_constants.color_exp_bias[i] =
|
||||
static_cast<float>(1 << color_info[i].color_exp_bias);
|
||||
}
|
||||
|
||||
// Alpha testing -- ALPHAREF, ALPHAFUNC, ALPHATESTENABLE
|
||||
// Emulated in shader.
|
||||
// if(ALPHATESTENABLE && frag_out.a [<=/ALPHAFUNC] ALPHAREF) discard;
|
||||
|
|
|
@ -289,6 +289,10 @@ class PipelineCache {
|
|||
uint32_t sq_program_cntl;
|
||||
uint32_t sq_context_misc;
|
||||
uint32_t rb_colorcontrol;
|
||||
uint32_t rb_color_info;
|
||||
uint32_t rb_color1_info;
|
||||
uint32_t rb_color2_info;
|
||||
uint32_t rb_color3_info;
|
||||
float rb_alpha_ref;
|
||||
uint32_t pa_su_point_size;
|
||||
|
||||
|
|
Loading…
Reference in New Issue