From 19d5d82d6f92388ea54fd686c09dd1390ceef729 Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Sun, 19 Nov 2023 22:09:15 +0100 Subject: [PATCH] lavapipe: Implement VK_EXT_depth_bias_control Reviewed-by: Mike Blumenkrantz Part-of: --- docs/features.txt | 2 +- src/gallium/frontends/lavapipe/lvp_device.c | 7 ++++ src/gallium/frontends/lavapipe/lvp_execute.c | 35 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/features.txt b/docs/features.txt index 88c58e2464b..21b1509f173 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -595,7 +595,7 @@ Khronos extensions that are not part of any Vulkan version: VK_EXT_debug_marker DONE (radv) VK_EXT_debug_report DONE (anv, dzn, hk, lvp, nvk, panvk, pvr, radv, tu, v3dv, vn) VK_EXT_debug_utils DONE (anv, dzn, hasvk, hk, lvp, nvk, panvk, pvr, radv, tu, v3dv, vn) - VK_EXT_depth_bias_control DONE (anv, hk, nvk, panvk, radv, vn) + VK_EXT_depth_bias_control DONE (anv, hk, lvp, nvk, panvk, radv, vn) VK_EXT_depth_clamp_control DONE (anv, hasvk, nvk, radv, vn) VK_EXT_depth_clip_control DONE (anv, hasvk, hk, lvp, nvk, panvk, radv, tu, v3dv, vn) VK_EXT_depth_clip_enable DONE (anv, hasvk, hk, lvp, nvk, panvk, radv, tu, v3dv/vc7+, vn) diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index bcb64a86e48..b35c0b2d6a4 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -203,6 +203,7 @@ static const struct vk_device_extension_table lvp_device_extensions_supported = .EXT_calibrated_timestamps = true, .EXT_color_write_enable = true, .EXT_conditional_rendering = true, + .EXT_depth_bias_control = true, .EXT_depth_clip_enable = true, .EXT_depth_clip_control = true, .EXT_depth_range_unrestricted = true, @@ -549,6 +550,12 @@ lvp_get_features(const struct lvp_physical_device *pdevice, /* VK_EXT_image_sliced_view_of_3d */ .imageSlicedViewOf3D = true, + /* VK_EXT_depth_bias_control */ + .depthBiasControl = true, + .leastRepresentableValueForceUnormRepresentation = true, + .floatRepresentation = true, + .depthBiasExact = true, + /* VK_EXT_depth_clip_control */ .depthClipControl = true, diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c b/src/gallium/frontends/lavapipe/lvp_execute.c index 86e86db1d5b..94dd5148bce 100644 --- a/src/gallium/frontends/lavapipe/lvp_execute.c +++ b/src/gallium/frontends/lavapipe/lvp_execute.c @@ -126,6 +126,7 @@ struct rendering_state { float offset_units; float offset_scale; float offset_clamp; + VkDepthBiasRepresentationEXT representation; bool enabled; } depth_bias; struct pipe_rasterizer_state rs_state; @@ -420,6 +421,16 @@ static void emit_state(struct rendering_state *state) state->rs_state.offset_tri = true; state->rs_state.offset_line = true; state->rs_state.offset_point = true; + + state->rs_state.offset_units_unscaled = + state->depth_bias.representation == VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT || + state->depth_bias.representation == VK_DEPTH_BIAS_REPRESENTATION_FLOAT_EXT; + + if (state->depth_bias.representation == VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORCE_UNORM_EXT) { + enum pipe_format depth_format = util_format_get_depth_only(state->depth_att.imgv->pformat); + const struct util_format_description *desc = util_format_description(depth_format); + state->rs_state.offset_units *= util_get_depth_format_mrd(desc); + } } else { state->rs_state.offset_units = 0.0f; state->rs_state.offset_scale = 0.0f; @@ -766,6 +777,7 @@ static void handle_graphics_pipeline(struct lvp_pipeline *pipeline, state->depth_bias.offset_units = ps->rs->depth_bias.constant_factor; state->depth_bias.offset_scale = ps->rs->depth_bias.slope_factor; state->depth_bias.offset_clamp = ps->rs->depth_bias.clamp; + state->depth_bias.representation = ps->rs->depth_bias.representation; } if (!BITSET_TEST(ps->dynamic, MESA_VK_DYNAMIC_RS_CULL_MODE)) @@ -1988,6 +2000,24 @@ static void handle_set_depth_bias(struct vk_cmd_queue_entry *cmd, state->rs_dirty = true; } +static void handle_set_depth_bias2(struct vk_cmd_queue_entry *cmd, + struct rendering_state *state) +{ + VkDepthBiasInfoEXT *info = cmd->u.set_depth_bias2_ext.depth_bias_info; + + state->depth_bias.offset_units = info->depthBiasConstantFactor; + state->depth_bias.offset_scale = info->depthBiasSlopeFactor; + state->depth_bias.offset_clamp = info->depthBiasClamp; + + const VkDepthBiasRepresentationInfoEXT *representation_info = + vk_find_struct_const(info->pNext, DEPTH_BIAS_REPRESENTATION_INFO_EXT); + state->depth_bias.representation = + representation_info ? representation_info->depthBiasRepresentation + : VK_DEPTH_BIAS_REPRESENTATION_LEAST_REPRESENTABLE_VALUE_FORMAT_EXT; + + state->rs_dirty = true; +} + static void handle_set_blend_constants(struct vk_cmd_queue_entry *cmd, struct rendering_state *state) { @@ -4911,6 +4941,8 @@ void lvp_add_enqueue_cmd_entrypoints(struct vk_device_dispatch_table *disp) ENQUEUE_CMD(CmdTraceRaysIndirectKHR) ENQUEUE_CMD(CmdTraceRaysKHR) + ENQUEUE_CMD(CmdSetDepthBias2EXT) + #undef ENQUEUE_CMD } @@ -5318,6 +5350,9 @@ static void lvp_execute_cmd_buffer(struct list_head *cmds, case VK_CMD_TRACE_RAYS_KHR: handle_trace_rays(cmd, state); break; + case VK_CMD_SET_DEPTH_BIAS2_EXT: + handle_set_depth_bias2(cmd, state); + break; default: fprintf(stderr, "Unsupported command %s\n", vk_cmd_queue_type_names[cmd->type]); unreachable("Unsupported command");