From f13bec79342671c80afd00c18b7f3feb05c8afb4 Mon Sep 17 00:00:00 2001 From: squidbus Date: Wed, 22 Apr 2026 14:46:40 -0700 Subject: [PATCH] kk: Add support for VK_EXT_depth_clip_control. Uses dynamic lowering pass pulled from asahi. Reviewed-by: Aitor Camacho Part-of: --- docs/features.txt | 2 +- src/kosmickrisp/vulkan/kk_cmd_buffer.h | 1 + src/kosmickrisp/vulkan/kk_cmd_draw.c | 6 ++++++ src/kosmickrisp/vulkan/kk_nir_lower_descriptors.c | 3 +++ src/kosmickrisp/vulkan/kk_physical_device.c | 4 ++++ src/kosmickrisp/vulkan/kk_shader.c | 1 + 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/features.txt b/docs/features.txt index c96f3b0ca39..79b445e31f1 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -620,7 +620,7 @@ Khronos extensions that are not part of any Vulkan version: VK_EXT_depth_bias_control DONE (anv, hk, lvp, nvk, panvk, radv, vn) VK_EXT_depth_clamp_control DONE (anv, hasvk, nvk, panvk, radv, tu, vn) VK_EXT_depth_clamp_zero_one DONE (anv, nvk, panvk, pvr, radv, tu, v3dv/vc7+, vn) - VK_EXT_depth_clip_control DONE (anv, hasvk, hk, lvp, nvk, panvk, radv, tu, v3dv, vn) + VK_EXT_depth_clip_control DONE (anv, hasvk, hk, kk, lvp, nvk, panvk, radv, tu, v3dv, vn) VK_EXT_depth_clip_enable DONE (anv, hasvk, hk, lvp, nvk, panvk, pvr, radv, tu, v3dv/vc7+, vn) VK_EXT_depth_range_unrestricted DONE (anv/gen20+, nvk, radv, lvp, vn) VK_EXT_descriptor_buffer DONE (anv, lvp, nvk, radv, tu) diff --git a/src/kosmickrisp/vulkan/kk_cmd_buffer.h b/src/kosmickrisp/vulkan/kk_cmd_buffer.h index 0b23f166767..2ea44011651 100644 --- a/src/kosmickrisp/vulkan/kk_cmd_buffer.h +++ b/src/kosmickrisp/vulkan/kk_cmd_buffer.h @@ -37,6 +37,7 @@ struct kk_root_descriptor_table { uint64_t attrib_base[KK_MAX_ATTRIBS]; uint32_t attrib_clamps[KK_MAX_ATTRIBS]; float blend_constant[4]; + float clip_z_coeff; uint32_t draw_id; } draw; struct { diff --git a/src/kosmickrisp/vulkan/kk_cmd_draw.c b/src/kosmickrisp/vulkan/kk_cmd_draw.c index 4d3ad650b3e..c3d5725fd80 100644 --- a/src/kosmickrisp/vulkan/kk_cmd_draw.c +++ b/src/kosmickrisp/vulkan/kk_cmd_draw.c @@ -742,6 +742,12 @@ kk_flush_dynamic_state(struct kk_cmd_buffer *cmd) IS_DIRTY(VP_SCISSOR_COUNT) || IS_DIRTY(VP_SCISSORS))) kk_flush_vp_state(cmd); + if (IS_DIRTY(VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE)) { + desc->root.draw.clip_z_coeff = + dyn->vp.depth_clip_negative_one_to_one ? 0.5f : 0.0f; + desc->root_dirty = true; + } + if (IS_DIRTY(RS_FRONT_FACE)) { mtl_set_front_face_winding( enc, vk_front_face_to_mtl_winding( diff --git a/src/kosmickrisp/vulkan/kk_nir_lower_descriptors.c b/src/kosmickrisp/vulkan/kk_nir_lower_descriptors.c index e02cc060349..4959665a77a 100644 --- a/src/kosmickrisp/vulkan/kk_nir_lower_descriptors.c +++ b/src/kosmickrisp/vulkan/kk_nir_lower_descriptors.c @@ -407,6 +407,9 @@ try_lower_intrin(nir_builder *b, nir_intrinsic_instr *intrin, case nir_intrinsic_load_blend_const_color_rgba: return lower_sysval_to_root_table(b, intrin, draw.blend_constant); + case nir_intrinsic_load_clip_z_coeff: + return lower_sysval_to_root_table(b, intrin, draw.clip_z_coeff); + case nir_intrinsic_load_push_constant: return lower_load_push_constant(b, intrin, ctx); diff --git a/src/kosmickrisp/vulkan/kk_physical_device.c b/src/kosmickrisp/vulkan/kk_physical_device.c index 9f2ef0b54df..fe1ced261c7 100644 --- a/src/kosmickrisp/vulkan/kk_physical_device.c +++ b/src/kosmickrisp/vulkan/kk_physical_device.c @@ -135,6 +135,7 @@ kk_get_device_extensions(const struct kk_instance *instance, .KHR_workgroup_memory_explicit_layout = true, .EXT_calibrated_timestamps = true, + .EXT_depth_clip_control = true, .EXT_external_memory_metal = true, .EXT_image_2d_view_of_3d = true, .EXT_load_store_op_none = true, @@ -303,6 +304,9 @@ kk_get_device_features( .formatA4R4G4B4 = true, .formatA4B4G4R4 = true, + /* VK_EXT_depth_clip_control */ + .depthClipControl = true, + /* EXT_image_2d_view_of_3d */ .image2DViewOf3D = true, .sampler2DViewOf3D = true, diff --git a/src/kosmickrisp/vulkan/kk_shader.c b/src/kosmickrisp/vulkan/kk_shader.c index 66082528e51..7882edf1662 100644 --- a/src/kosmickrisp/vulkan/kk_shader.c +++ b/src/kosmickrisp/vulkan/kk_shader.c @@ -323,6 +323,7 @@ kk_lower_vs(nir_shader *nir, const struct vk_graphics_pipeline_state *state) nir_shader_intrinsics_pass(nir, msl_nir_vs_remove_point_size_write, nir_metadata_control_flow, NULL); + NIR_PASS(_, nir, nir_lower_clip_halfz_dynamic); NIR_PASS(_, nir, msl_nir_vs_io_types); }