[Vulkan] Add support for user clip planes
This commit is contained in:
@@ -4064,6 +4064,34 @@ void VulkanCommandProcessor::UpdateSystemConstantValues(
|
||||
system_constants_.ndc_offset[i] = viewport_info.ndc_offset[i];
|
||||
}
|
||||
|
||||
// User clip planes (for vertex shaders)
|
||||
auto pa_cl_clip_cntl = regs.Get<reg::PA_CL_CLIP_CNTL>();
|
||||
if (!pa_cl_clip_cntl.clip_disable && pa_cl_clip_cntl.ucp_ena) {
|
||||
float* user_clip_plane_write_ptr =
|
||||
clip_plane_constants_.user_clip_planes[0];
|
||||
uint32_t user_clip_planes_remaining = pa_cl_clip_cntl.ucp_ena;
|
||||
uint32_t user_clip_plane_index;
|
||||
while (xe::bit_scan_forward(user_clip_planes_remaining,
|
||||
&user_clip_plane_index)) {
|
||||
user_clip_planes_remaining =
|
||||
xe::clear_lowest_bit(user_clip_planes_remaining);
|
||||
// Validate plane index is within bounds (0-5).
|
||||
assert(user_clip_plane_index < 6);
|
||||
if (user_clip_plane_index >= 6) {
|
||||
continue;
|
||||
}
|
||||
const void* user_clip_plane_regs =
|
||||
®s[XE_GPU_REG_PA_CL_UCP_0_X + user_clip_plane_index * 4];
|
||||
if (std::memcmp(user_clip_plane_write_ptr, user_clip_plane_regs,
|
||||
4 * sizeof(float))) {
|
||||
dirty = true;
|
||||
std::memcpy(user_clip_plane_write_ptr, user_clip_plane_regs,
|
||||
4 * sizeof(float));
|
||||
}
|
||||
user_clip_plane_write_ptr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
// Point size.
|
||||
if (vgt_draw_initiator.prim_type == xenos::PrimitiveType::kPointList) {
|
||||
auto pa_su_point_minmax = regs.Get<reg::PA_SU_POINT_MINMAX>();
|
||||
@@ -4446,6 +4474,29 @@ bool VulkanCommandProcessor::UpdateBindings(const VulkanShader* vertex_shader,
|
||||
current_constant_buffers_up_to_date_ |=
|
||||
UINT32_C(1) << SpirvShaderTranslator::kConstantBufferSystem;
|
||||
}
|
||||
// Clip plane constants.
|
||||
auto pa_cl_clip_cntl = regs.Get<reg::PA_CL_CLIP_CNTL>();
|
||||
bool clip_planes_enabled =
|
||||
!pa_cl_clip_cntl.clip_disable && pa_cl_clip_cntl.ucp_ena;
|
||||
if (clip_planes_enabled) {
|
||||
if (!(current_constant_buffers_up_to_date_ &
|
||||
(UINT32_C(1)
|
||||
<< SpirvShaderTranslator::kConstantBufferClipPlanes))) {
|
||||
VkDescriptorBufferInfo& buffer_info = current_constant_buffer_infos_
|
||||
[SpirvShaderTranslator::kConstantBufferClipPlanes];
|
||||
uint8_t* mapping = uniform_buffer_pool_->Request(
|
||||
frame_current_, sizeof(SpirvShaderTranslator::ClipPlaneConstants),
|
||||
uniform_buffer_alignment, buffer_info.buffer, buffer_info.offset);
|
||||
if (!mapping) {
|
||||
return false;
|
||||
}
|
||||
buffer_info.range = sizeof(SpirvShaderTranslator::ClipPlaneConstants);
|
||||
std::memcpy(mapping, &clip_plane_constants_,
|
||||
sizeof(SpirvShaderTranslator::ClipPlaneConstants));
|
||||
current_constant_buffers_up_to_date_ |=
|
||||
UINT32_C(1) << SpirvShaderTranslator::kConstantBufferClipPlanes;
|
||||
}
|
||||
}
|
||||
// Vertex shader float constants.
|
||||
if (!(current_constant_buffers_up_to_date_ &
|
||||
(UINT32_C(1) << SpirvShaderTranslator::kConstantBufferFloatVertex))) {
|
||||
|
||||
@@ -753,6 +753,9 @@ class VulkanCommandProcessor final : public CommandProcessor {
|
||||
// System shader constants.
|
||||
SpirvShaderTranslator::SystemConstants system_constants_;
|
||||
|
||||
// Clip plane constants.
|
||||
SpirvShaderTranslator::ClipPlaneConstants clip_plane_constants_;
|
||||
|
||||
// Temporary storage for memexport stream constants used in the draw.
|
||||
std::vector<draw_util::MemExportRange> memexport_ranges_;
|
||||
|
||||
|
||||
@@ -175,6 +175,14 @@ VulkanPipelineCache::GetCurrentVertexShaderModification(
|
||||
|
||||
modification.vertex.interpolator_mask = interpolator_mask;
|
||||
|
||||
// User clip planes.
|
||||
auto pa_cl_clip_cntl = regs.Get<reg::PA_CL_CLIP_CNTL>();
|
||||
uint32_t user_clip_planes =
|
||||
pa_cl_clip_cntl.clip_disable ? 0 : pa_cl_clip_cntl.ucp_ena;
|
||||
modification.vertex.user_clip_plane_count = xe::bit_count(user_clip_planes);
|
||||
modification.vertex.user_clip_plane_cull =
|
||||
uint32_t(user_clip_planes && pa_cl_clip_cntl.ucp_cull_only_ena);
|
||||
|
||||
if (host_vertex_shader_type ==
|
||||
Shader::HostVertexShaderType::kPointListAsTriangleStrip) {
|
||||
modification.vertex.output_point_parameters = uint32_t(ps_param_gen_used);
|
||||
@@ -805,15 +813,14 @@ bool VulkanPipelineCache::GetGeometryShaderKey(
|
||||
// real counts here.
|
||||
key.interpolator_count =
|
||||
xe::bit_count(vertex_shader_modification.vertex.interpolator_mask);
|
||||
key.user_clip_plane_count =
|
||||
/* vertex_shader_modification.vertex.user_clip_plane_count */ 0;
|
||||
key.user_clip_plane_cull =
|
||||
/* vertex_shader_modification.vertex.user_clip_plane_cull */ 0;
|
||||
key.has_vertex_kill_and =
|
||||
/* vertex_shader_modification.vertex.vertex_kill_and */ 0;
|
||||
key.has_point_size =
|
||||
vertex_shader_modification.vertex.output_point_parameters;
|
||||
key.has_point_coordinates = pixel_shader_modification.pixel.param_gen_point;
|
||||
// Single bit to indicate if clip planes are enabled.
|
||||
key.has_user_clip_planes =
|
||||
uint32_t(vertex_shader_modification.vertex.user_clip_plane_count > 0);
|
||||
key_out = key;
|
||||
return true;
|
||||
}
|
||||
@@ -858,10 +865,12 @@ VkShaderModule VulkanPipelineCache::GetGeometryShader(GeometryShaderKey key) {
|
||||
assert_unhandled_case(key.type);
|
||||
}
|
||||
|
||||
// When enabled, use max size to reduce variants from different counts.
|
||||
constexpr uint32_t kMaxUserClipPlanes = 6;
|
||||
uint32_t clip_distance_count =
|
||||
key.user_clip_plane_cull ? 0 : key.user_clip_plane_count;
|
||||
key.has_user_clip_planes ? kMaxUserClipPlanes : 0;
|
||||
uint32_t cull_distance_count =
|
||||
(key.user_clip_plane_cull ? key.user_clip_plane_count : 0) +
|
||||
(key.has_user_clip_planes ? kMaxUserClipPlanes : 0) +
|
||||
key.has_vertex_kill_and;
|
||||
|
||||
SpirvBuilder builder(spv::Spv_1_5,
|
||||
|
||||
@@ -224,8 +224,7 @@ class VulkanPipelineCache {
|
||||
struct {
|
||||
PipelineGeometryShader type : 2;
|
||||
uint32_t interpolator_count : 5;
|
||||
uint32_t user_clip_plane_count : 3;
|
||||
uint32_t user_clip_plane_cull : 1;
|
||||
uint32_t has_user_clip_planes : 1;
|
||||
uint32_t has_vertex_kill_and : 1;
|
||||
uint32_t has_point_size : 1;
|
||||
uint32_t has_point_coordinates : 1;
|
||||
|
||||
Reference in New Issue
Block a user