mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-08-02 23:42:43 +00:00
vk_rasterizer: Add stencil dynamic states
This commit is contained in:
parent
a93b830f04
commit
3e8455f359
@ -1069,7 +1069,16 @@ ScePthread PThreadPool::Create(const char* name) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN64
|
||||
auto* ret = new PthreadInternal{};
|
||||
#else
|
||||
// TODO: Linux specific hack
|
||||
static u8* hint_address = reinterpret_cast<u8*>(0x7FFFFC000ULL);
|
||||
auto* ret = reinterpret_cast<PthreadInternal*>(
|
||||
mmap(hint_address, sizeof(PthreadInternal), PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0));
|
||||
hint_address += Common::AlignUp(sizeof(PthreadInternal), 4_KB);
|
||||
#endif
|
||||
ret->is_free = false;
|
||||
ret->is_detached = false;
|
||||
ret->is_almost_done = false;
|
||||
|
@ -95,9 +95,6 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
|
||||
? vk::FrontFace::eClockwise
|
||||
: vk::FrontFace::eCounterClockwise,
|
||||
.depthBiasEnable = bool(key.depth_bias_enable),
|
||||
.depthBiasConstantFactor = key.depth_bias_const_factor,
|
||||
.depthBiasClamp = key.depth_bias_clamp,
|
||||
.depthBiasSlopeFactor = key.depth_bias_slope_factor,
|
||||
.lineWidth = 1.0f,
|
||||
};
|
||||
|
||||
@ -134,9 +131,10 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
|
||||
};
|
||||
|
||||
boost::container::static_vector<vk::DynamicState, 14> dynamic_states = {
|
||||
vk::DynamicState::eViewport, vk::DynamicState::eScissor,
|
||||
vk::DynamicState::eBlendConstants, vk::DynamicState::eDepthBounds,
|
||||
vk::DynamicState::eDepthBias,
|
||||
vk::DynamicState::eViewport, vk::DynamicState::eScissor,
|
||||
vk::DynamicState::eBlendConstants, vk::DynamicState::eDepthBounds,
|
||||
vk::DynamicState::eDepthBias, vk::DynamicState::eStencilReference,
|
||||
vk::DynamicState::eStencilCompareMask, vk::DynamicState::eStencilWriteMask,
|
||||
};
|
||||
|
||||
if (instance.IsColorWriteEnableSupported()) {
|
||||
@ -163,9 +161,6 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
|
||||
.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),
|
||||
.compareMask = key.stencil_ref_front.stencil_mask,
|
||||
.writeMask = key.stencil_ref_front.stencil_write_mask,
|
||||
.reference = key.stencil_ref_front.stencil_test_val,
|
||||
},
|
||||
.back{
|
||||
.failOp = LiverpoolToVK::StencilOp(key.depth_stencil.backface_enable
|
||||
@ -180,12 +175,7 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul
|
||||
.compareOp = LiverpoolToVK::CompareOp(key.depth_stencil.backface_enable
|
||||
? key.depth_stencil.stencil_bf_func.Value()
|
||||
: key.depth_stencil.stencil_ref_func.Value()),
|
||||
.compareMask = key.stencil_ref_back.stencil_mask,
|
||||
.writeMask = key.stencil_ref_back.stencil_write_mask,
|
||||
.reference = key.stencil_ref_back.stencil_test_val,
|
||||
},
|
||||
.minDepthBounds = key.depth_bounds_min,
|
||||
.maxDepthBounds = key.depth_bounds_max,
|
||||
};
|
||||
|
||||
auto stage = u32(Shader::Stage::Vertex);
|
||||
|
@ -31,16 +31,9 @@ struct GraphicsPipelineKey {
|
||||
vk::Format stencil_format;
|
||||
|
||||
Liverpool::DepthControl depth_stencil;
|
||||
float depth_bounds_min;
|
||||
float depth_bounds_max;
|
||||
float depth_bias_const_factor;
|
||||
float depth_bias_slope_factor;
|
||||
float depth_bias_clamp;
|
||||
u32 depth_bias_enable;
|
||||
u32 num_samples;
|
||||
Liverpool::StencilControl stencil;
|
||||
Liverpool::StencilRefMask stencil_ref_front;
|
||||
Liverpool::StencilRefMask stencil_ref_back;
|
||||
Liverpool::PrimitiveType prim_type;
|
||||
u32 enable_primitive_restart;
|
||||
u32 primitive_restart_index;
|
||||
|
@ -202,44 +202,31 @@ bool PipelineCache::RefreshGraphicsKey() {
|
||||
auto& regs = liverpool->regs;
|
||||
auto& key = graphics_key;
|
||||
|
||||
key.depth_stencil = regs.depth_control;
|
||||
key.depth_stencil.depth_write_enable.Assign(regs.depth_control.depth_write_enable.Value() &&
|
||||
!regs.depth_render_control.depth_clear_enable);
|
||||
key.depth_bias_enable = regs.polygon_control.NeedsBias();
|
||||
|
||||
const auto& db = regs.depth_buffer;
|
||||
const bool depth_enable = db.Address() != 0 && regs.depth_control.depth_enable &&
|
||||
db.z_info.format != Liverpool::DepthBuffer::ZFormat::Invalid;
|
||||
if (depth_enable) {
|
||||
const bool depth_write = regs.depth_control.depth_write_enable.Value() &&
|
||||
!regs.depth_render_control.depth_clear_enable;
|
||||
key.depth_stencil.raw |= regs.depth_control.DepthState();
|
||||
key.depth_stencil.depth_write_enable.Assign(depth_write);
|
||||
key.depth_bias_enable = regs.polygon_control.NeedsBias();
|
||||
|
||||
const auto ds_format = LiverpoolToVK::DepthFormat(db.z_info.format, db.stencil_info.format);
|
||||
if (db.z_info.format != AmdGpu::Liverpool::DepthBuffer::ZFormat::Invalid) {
|
||||
key.depth_format = ds_format;
|
||||
} else {
|
||||
key.depth_format = vk::Format::eUndefined;
|
||||
}
|
||||
if (regs.depth_control.depth_enable) {
|
||||
key.depth_stencil.depth_enable.Assign(key.depth_format != vk::Format::eUndefined);
|
||||
}
|
||||
const auto ds_format = LiverpoolToVK::DepthFormat(db.z_info.format, db.stencil_info.format);
|
||||
if (db.z_info.format != AmdGpu::Liverpool::DepthBuffer::ZFormat::Invalid) {
|
||||
key.depth_format = ds_format;
|
||||
} else {
|
||||
key.depth_format = vk::Format::eUndefined;
|
||||
}
|
||||
const bool stencil_enable =
|
||||
regs.depth_control.stencil_enable &&
|
||||
db.stencil_info.format != Liverpool::DepthBuffer::StencilFormat::Invalid;
|
||||
if (stencil_enable) {
|
||||
key.depth_stencil.raw |= regs.depth_control.StencilState();
|
||||
key.stencil = regs.stencil_control;
|
||||
key.stencil.raw &= Liverpool::StencilControl::Mask();
|
||||
key.stencil_ref_front = regs.stencil_ref_front;
|
||||
key.stencil_ref_back = regs.stencil_ref_back;
|
||||
if (regs.depth_control.depth_enable) {
|
||||
key.depth_stencil.depth_enable.Assign(key.depth_format != vk::Format::eUndefined);
|
||||
}
|
||||
key.stencil = regs.stencil_control;
|
||||
key.stencil.raw &= Liverpool::StencilControl::Mask();
|
||||
|
||||
if (db.stencil_info.format != AmdGpu::Liverpool::DepthBuffer::StencilFormat::Invalid) {
|
||||
key.stencil_format = key.depth_format;
|
||||
} else {
|
||||
key.stencil_format = vk::Format::eUndefined;
|
||||
}
|
||||
if (regs.depth_control.stencil_enable) {
|
||||
key.depth_stencil.stencil_enable.Assign(key.stencil_format != vk::Format::eUndefined);
|
||||
}
|
||||
if (db.stencil_info.format != AmdGpu::Liverpool::DepthBuffer::StencilFormat::Invalid) {
|
||||
key.stencil_format = key.depth_format;
|
||||
} else {
|
||||
key.stencil_format = vk::Format::eUndefined;
|
||||
}
|
||||
if (key.depth_stencil.stencil_enable) {
|
||||
key.depth_stencil.stencil_enable.Assign(key.stencil_format != vk::Format::eUndefined);
|
||||
}
|
||||
key.prim_type = regs.primitive_type;
|
||||
key.enable_primitive_restart = regs.enable_primitive_restart & 1;
|
||||
|
@ -309,6 +309,31 @@ void Rasterizer::UpdateDynamicState(const GraphicsPipeline& pipeline) {
|
||||
regs.poly_offset.back_scale);
|
||||
}
|
||||
}
|
||||
if (regs.depth_control.stencil_enable) {
|
||||
const auto front = regs.stencil_ref_front;
|
||||
const auto back = regs.stencil_ref_back;
|
||||
if (front.stencil_test_val == back.stencil_test_val) {
|
||||
cmdbuf.setStencilReference(vk::StencilFaceFlagBits::eFrontAndBack,
|
||||
front.stencil_test_val);
|
||||
} else {
|
||||
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);
|
||||
} else {
|
||||
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);
|
||||
} else {
|
||||
cmdbuf.setStencilCompareMask(vk::StencilFaceFlagBits::eFront, front.stencil_mask);
|
||||
cmdbuf.setStencilCompareMask(vk::StencilFaceFlagBits::eBack, back.stencil_mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Rasterizer::UpdateViewportScissorState() {
|
||||
|
Loading…
Reference in New Issue
Block a user