renderer_vulkan: Simplify depth pipeline state and move stencil to dynamic state. (#1854)

* renderer_vulkan: Simplify depth pipeline state and move stencil to dynamic state.

* Change graphics key depth-stencil flags to bitfields.
This commit is contained in:
squidbus 2024-12-24 03:45:11 -08:00 committed by GitHub
parent 092d42e981
commit 0a4453b912
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 54 additions and 35 deletions

View file

@ -123,7 +123,7 @@ GraphicsPipeline::GraphicsPipeline(
.frontFace = key.front_face == Liverpool::FrontFace::Clockwise
? vk::FrontFace::eClockwise
: vk::FrontFace::eCounterClockwise,
.depthBiasEnable = bool(key.depth_bias_enable),
.depthBiasEnable = key.depth_bias_enable,
.lineWidth = 1.0f,
};
@ -164,6 +164,7 @@ GraphicsPipeline::GraphicsPipeline(
vk::DynamicState::eBlendConstants, vk::DynamicState::eDepthBounds,
vk::DynamicState::eDepthBias, vk::DynamicState::eStencilReference,
vk::DynamicState::eStencilCompareMask, vk::DynamicState::eStencilWriteMask,
vk::DynamicState::eStencilOpEXT,
};
if (instance.IsColorWriteEnableSupported()) {
@ -182,31 +183,11 @@ GraphicsPipeline::GraphicsPipeline(
};
const vk::PipelineDepthStencilStateCreateInfo depth_info = {
.depthTestEnable = key.depth_stencil.depth_enable,
.depthWriteEnable = key.depth_stencil.depth_write_enable,
.depthCompareOp = LiverpoolToVK::CompareOp(key.depth_stencil.depth_func),
.depthBoundsTestEnable = key.depth_stencil.depth_bounds_enable,
.stencilTestEnable = key.depth_stencil.stencil_enable,
.front{
.failOp = LiverpoolToVK::StencilOp(key.stencil.stencil_fail_front),
.passOp = LiverpoolToVK::StencilOp(key.stencil.stencil_zpass_front),
.depthFailOp = LiverpoolToVK::StencilOp(key.stencil.stencil_zfail_front),
.compareOp = LiverpoolToVK::CompareOp(key.depth_stencil.stencil_ref_func),
},
.back{
.failOp = LiverpoolToVK::StencilOp(key.depth_stencil.backface_enable
? key.stencil.stencil_fail_back.Value()
: key.stencil.stencil_fail_front.Value()),
.passOp = LiverpoolToVK::StencilOp(key.depth_stencil.backface_enable
? key.stencil.stencil_zpass_back.Value()
: key.stencil.stencil_zpass_front.Value()),
.depthFailOp = LiverpoolToVK::StencilOp(key.depth_stencil.backface_enable
? key.stencil.stencil_zfail_back.Value()
: key.stencil.stencil_zfail_front.Value()),
.compareOp = LiverpoolToVK::CompareOp(key.depth_stencil.backface_enable
? key.depth_stencil.stencil_bf_func.Value()
: key.depth_stencil.stencil_ref_func.Value()),
},
.depthTestEnable = key.depth_test_enable,
.depthWriteEnable = key.depth_write_enable,
.depthCompareOp = key.depth_compare_op,
.depthBoundsTestEnable = key.depth_bounds_test_enable,
.stencilTestEnable = key.stencil_test_enable,
};
boost::container::static_vector<vk::PipelineShaderStageCreateInfo, MaxShaderStages>

View file

@ -36,11 +36,19 @@ struct GraphicsPipelineKey {
vk::Format depth_format;
vk::Format stencil_format;
Liverpool::DepthControl depth_stencil;
u32 depth_bias_enable;
struct {
bool depth_test_enable : 1;
bool depth_write_enable : 1;
bool depth_bounds_test_enable : 1;
bool depth_bias_enable : 1;
bool stencil_test_enable : 1;
// Must be named to be zero-initialized.
u8 _unused : 3;
};
vk::CompareOp depth_compare_op;
u32 num_samples;
u32 mrt_mask;
Liverpool::StencilControl stencil;
AmdGpu::PrimitiveType prim_type;
u32 enable_primitive_restart;
u32 primitive_restart_index;

View file

@ -258,11 +258,13 @@ bool PipelineCache::RefreshGraphicsKey() {
auto& regs = liverpool->regs;
auto& key = graphics_key;
key.depth_stencil = regs.depth_control;
key.stencil = regs.stencil_control;
key.depth_stencil.depth_write_enable.Assign(regs.depth_control.depth_write_enable.Value() &&
!regs.depth_render_control.depth_clear_enable);
key.depth_test_enable = regs.depth_control.depth_enable;
key.depth_write_enable =
regs.depth_control.depth_write_enable && !regs.depth_render_control.depth_clear_enable;
key.depth_bounds_test_enable = regs.depth_control.depth_bounds_enable;
key.depth_bias_enable = regs.polygon_control.NeedsBias();
key.depth_compare_op = LiverpoolToVK::CompareOp(regs.depth_control.depth_func);
key.stencil_test_enable = regs.depth_control.stencil_enable;
const auto depth_format = instance.GetSupportedFormat(
LiverpoolToVK::DepthFormat(regs.depth_buffer.z_info.format,
@ -272,13 +274,13 @@ bool PipelineCache::RefreshGraphicsKey() {
key.depth_format = depth_format;
} else {
key.depth_format = vk::Format::eUndefined;
key.depth_stencil.depth_enable.Assign(false);
key.depth_test_enable = false;
}
if (regs.depth_buffer.StencilValid()) {
key.stencil_format = depth_format;
} else {
key.stencil_format = vk::Format::eUndefined;
key.depth_stencil.stencil_enable.Assign(false);
key.stencil_test_enable = false;
}
key.prim_type = regs.primitive_type;

View file

@ -963,7 +963,33 @@ void Rasterizer::UpdateDynamicState(const GraphicsPipeline& pipeline) {
cmdbuf.setDepthBias(regs.poly_offset.back_offset, regs.poly_offset.depth_bias,
regs.poly_offset.back_scale / 16.f);
}
if (regs.depth_control.stencil_enable) {
const auto front_fail_op =
LiverpoolToVK::StencilOp(regs.stencil_control.stencil_fail_front);
const auto front_pass_op =
LiverpoolToVK::StencilOp(regs.stencil_control.stencil_zpass_front);
const auto front_depth_fail_op =
LiverpoolToVK::StencilOp(regs.stencil_control.stencil_zfail_front);
const auto front_compare_op = LiverpoolToVK::CompareOp(regs.depth_control.stencil_ref_func);
if (regs.depth_control.backface_enable) {
const auto back_fail_op =
LiverpoolToVK::StencilOp(regs.stencil_control.stencil_fail_back);
const auto back_pass_op =
LiverpoolToVK::StencilOp(regs.stencil_control.stencil_zpass_back);
const auto back_depth_fail_op =
LiverpoolToVK::StencilOp(regs.stencil_control.stencil_zfail_back);
const auto back_compare_op =
LiverpoolToVK::CompareOp(regs.depth_control.stencil_bf_func);
cmdbuf.setStencilOpEXT(vk::StencilFaceFlagBits::eFront, front_fail_op, front_pass_op,
front_depth_fail_op, front_compare_op);
cmdbuf.setStencilOpEXT(vk::StencilFaceFlagBits::eBack, back_fail_op, back_pass_op,
back_depth_fail_op, back_compare_op);
} else {
cmdbuf.setStencilOpEXT(vk::StencilFaceFlagBits::eFrontAndBack, front_fail_op,
front_pass_op, front_depth_fail_op, front_compare_op);
}
const auto front = regs.stencil_ref_front;
const auto back = regs.stencil_ref_back;
if (front.stencil_test_val == back.stencil_test_val) {
@ -973,6 +999,7 @@ void Rasterizer::UpdateDynamicState(const GraphicsPipeline& pipeline) {
cmdbuf.setStencilReference(vk::StencilFaceFlagBits::eFront, front.stencil_test_val);
cmdbuf.setStencilReference(vk::StencilFaceFlagBits::eBack, back.stencil_test_val);
}
if (front.stencil_write_mask == back.stencil_write_mask) {
cmdbuf.setStencilWriteMask(vk::StencilFaceFlagBits::eFrontAndBack,
front.stencil_write_mask);
@ -980,6 +1007,7 @@ void Rasterizer::UpdateDynamicState(const GraphicsPipeline& pipeline) {
cmdbuf.setStencilWriteMask(vk::StencilFaceFlagBits::eFront, front.stencil_write_mask);
cmdbuf.setStencilWriteMask(vk::StencilFaceFlagBits::eBack, back.stencil_write_mask);
}
if (front.stencil_mask == back.stencil_mask) {
cmdbuf.setStencilCompareMask(vk::StencilFaceFlagBits::eFrontAndBack,
front.stencil_mask);