From 8064926999b0cdd7633dab3a5423149ffb8b83dc Mon Sep 17 00:00:00 2001 From: gibbed Date: Sat, 19 May 2018 15:45:13 -0500 Subject: [PATCH] [Vulkan] Implement support for color_exp_bias. --- src/xenia/gpu/spirv_shader_translator.cc | 33 ++++++++++-------------- src/xenia/gpu/spirv_shader_translator.h | 4 +-- src/xenia/gpu/vulkan/pipeline_cache.cc | 19 ++++++++++++++ src/xenia/gpu/vulkan/pipeline_cache.h | 4 +++ 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/xenia/gpu/spirv_shader_translator.cc b/src/xenia/gpu/spirv_shader_translator.cc index 1361279b3..f4859c7b1 100644 --- a/src/xenia/gpu/spirv_shader_translator.cc +++ b/src/xenia/gpu/spirv_shader_translator.cc @@ -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(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(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(offsetof(SpirvPushConstants, color_exp_bias))); @@ -558,23 +558,16 @@ std::vector SpirvShaderTranslator::CompleteTranslation() { spv::StorageClass::StorageClassPushConstant, push_consts_, std::vector({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({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({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 diff --git a/src/xenia/gpu/spirv_shader_translator.h b/src/xenia/gpu/spirv_shader_translator.h index b1023f458..1147603a7 100644 --- a/src/xenia/gpu/spirv_shader_translator.h +++ b/src/xenia/gpu/spirv_shader_translator.h @@ -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, diff --git a/src/xenia/gpu/vulkan/pipeline_cache.cc b/src/xenia/gpu/vulkan/pipeline_cache.cc index e4ba55ba7..a82bb996d 100644 --- a/src/xenia/gpu/vulkan/pipeline_cache.cc +++ b/src/xenia/gpu/vulkan/pipeline_cache.cc @@ -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((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(1 << color_info[i].color_exp_bias); + } + // Alpha testing -- ALPHAREF, ALPHAFUNC, ALPHATESTENABLE // Emulated in shader. // if(ALPHATESTENABLE && frag_out.a [<=/ALPHAFUNC] ALPHAREF) discard; diff --git a/src/xenia/gpu/vulkan/pipeline_cache.h b/src/xenia/gpu/vulkan/pipeline_cache.h index efb49f97c..426d455b7 100644 --- a/src/xenia/gpu/vulkan/pipeline_cache.h +++ b/src/xenia/gpu/vulkan/pipeline_cache.h @@ -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;