vulkan,lavapipe: Use a tri-state enum for depth clip enable

This should make it a lot more clear how depth clip enables work.
Annoyingly, because of the way they originally worked in Vulkan 1.0,
it's dependent on the depth clamp if the state isn't set in the pipeline
and isn't declared dynamic.  The enum is explicitly set up so that
drivers don't need to be aware of this change unless they already
implement VK_EXT_extended_dynamic_state3.  If depth clamp/clamp are not
dynamic, depth clip will be either TRUE or FALSE which map to 1/0 so the
field can still be treated as a boolean.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18889>
This commit is contained in:
Jason Ekstrand 2022-09-29 11:55:03 -05:00 committed by Marge Bot
parent 0d3bc8c5b9
commit 650880105e
5 changed files with 45 additions and 17 deletions

View file

@ -741,11 +741,10 @@ static void handle_graphics_pipeline(struct vk_cmd_queue_entry *cmd,
if (BITSET_TEST(ps->dynamic, MESA_VK_DYNAMIC_RS_DEPTH_CLIP_ENABLE)) {
state->depth_clamp_sets_clip = false;
} else {
if (!ps->rs->depth_clip_present)
state->rs_state.depth_clip_near = state->rs_state.depth_clip_far = !state->rs_state.depth_clamp;
else
state->rs_state.depth_clip_near = state->rs_state.depth_clip_far = ps->rs->depth_clip_enable;
state->depth_clamp_sets_clip = !ps->rs->depth_clip_present;
state->rs_state.depth_clip_near = state->rs_state.depth_clip_far =
vk_rasterization_state_depth_clip_enable(ps->rs);
state->depth_clamp_sets_clip =
ps->rs->depth_clip_enable == VK_MESA_DEPTH_CLIP_ENABLE_NOT_CLAMP;
}
if (!BITSET_TEST(ps->dynamic, MESA_VK_DYNAMIC_RS_RASTERIZER_DISCARD_ENABLE))

View file

@ -2253,7 +2253,8 @@ anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline,
vk_dynamic_graphics_state_fill(&pipeline->dynamic_state, state);
pipeline->depth_clamp_enable = state->rs->depth_clamp_enable;
pipeline->depth_clip_enable = state->rs->depth_clip_enable;
pipeline->depth_clip_enable =
vk_rasterization_state_depth_clip_enable(state->rs);
pipeline->view_mask = state->rp->view_mask;
result = anv_graphics_pipeline_compile(pipeline, cache, pCreateInfo, state);

View file

@ -1892,7 +1892,8 @@ anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline,
vk_dynamic_graphics_state_fill(&pipeline->dynamic_state, state);
pipeline->depth_clamp_enable = state->rs->depth_clamp_enable;
pipeline->depth_clip_enable = state->rs->depth_clip_enable;
pipeline->depth_clip_enable =
vk_rasterization_state_depth_clip_enable(state->rs);
pipeline->view_mask = state->rp->view_mask;
result = anv_graphics_pipeline_compile(pipeline, cache, pCreateInfo, state);

View file

@ -507,8 +507,14 @@ vk_rasterization_state_init(struct vk_rasterization_state *rs,
* depth clipping is disabled when
* VkPipelineRasterizationStateCreateInfo::depthClampEnable is VK_TRUE.
*/
rs->depth_clamp_enable = rs_info->depthClampEnable;
rs->depth_clip_enable = !rs_info->depthClampEnable;
if (IS_DYNAMIC(RS_DEPTH_CLAMP_ENABLE)) {
rs->depth_clip_enable = VK_MESA_DEPTH_CLIP_ENABLE_NOT_CLAMP;
} else {
rs->depth_clamp_enable = rs_info->depthClampEnable;
rs->depth_clip_enable = rs_info->depthClampEnable ?
VK_MESA_DEPTH_CLIP_ENABLE_FALSE :
VK_MESA_DEPTH_CLIP_ENABLE_TRUE;
}
rs->polygon_mode = rs_info->polygonMode;
@ -535,8 +541,9 @@ vk_rasterization_state_init(struct vk_rasterization_state *rs,
case VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT: {
const VkPipelineRasterizationDepthClipStateCreateInfoEXT *rdc_info =
(const VkPipelineRasterizationDepthClipStateCreateInfoEXT *)ext;
rs->depth_clip_enable = rdc_info->depthClipEnable;
rs->depth_clip_present = true;
rs->depth_clip_enable = rdc_info->depthClipEnable ?
VK_MESA_DEPTH_CLIP_ENABLE_TRUE :
VK_MESA_DEPTH_CLIP_ENABLE_FALSE;
break;
}
@ -1988,8 +1995,9 @@ vk_common_CmdSetDepthClipEnableEXT(VkCommandBuffer commandBuffer,
VK_FROM_HANDLE(vk_command_buffer, cmd, commandBuffer);
struct vk_dynamic_graphics_state *dyn = &cmd->dynamic_graphics_state;
SET_DYN_BOOL(dyn, RS_DEPTH_CLIP_ENABLE,
rs.depth_clip_enable, depthClipEnable);
SET_DYN_VALUE(dyn, RS_DEPTH_CLIP_ENABLE, rs.depth_clip_enable,
depthClipEnable ? VK_MESA_DEPTH_CLIP_ENABLE_TRUE :
VK_MESA_DEPTH_CLIP_ENABLE_FALSE);
}
VKAPI_ATTR void VKAPI_CALL

View file

@ -215,6 +215,17 @@ struct vk_discard_rectangles_state {
VkRect2D rectangles[MESA_VK_MAX_DISCARD_RECTANGLES];
};
enum PACKED vk_mesa_depth_clip_enable {
/** Depth clipping should be disabled */
VK_MESA_DEPTH_CLIP_ENABLE_FALSE = 0,
/** Depth clipping should be enabled */
VK_MESA_DEPTH_CLIP_ENABLE_TRUE = 1,
/** Depth clipping should be enabled iff depth clamping is disabled */
VK_MESA_DEPTH_CLIP_ENABLE_NOT_CLAMP,
};
struct vk_rasterization_state {
/** VkPipelineRasterizationStateCreateInfo::rasterizerDiscardEnable
*
@ -234,10 +245,7 @@ struct vk_rasterization_state {
*
* MESA_VK_DYNAMIC_RS_DEPTH_CLIP_ENABLE
*/
bool depth_clip_enable;
/** denotes the presence of VkPipelineRasterizationDepthClipStateCreateInfoEXT */
bool depth_clip_present;
enum vk_mesa_depth_clip_enable depth_clip_enable;
/** VkPipelineRasterizationStateCreateInfo::polygonMode
*
@ -342,6 +350,17 @@ struct vk_rasterization_state {
} line;
};
static inline bool
vk_rasterization_state_depth_clip_enable(const struct vk_rasterization_state *rs)
{
switch (rs->depth_clip_enable) {
case VK_MESA_DEPTH_CLIP_ENABLE_FALSE: return false;
case VK_MESA_DEPTH_CLIP_ENABLE_TRUE: return true;
case VK_MESA_DEPTH_CLIP_ENABLE_NOT_CLAMP: return !rs->depth_clamp_enable;
}
unreachable("Invalid depth clip enable");
}
struct vk_fragment_shading_rate_state {
/** VkPipelineFragmentShadingRateStateCreateInfoKHR::fragmentSize
*