Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/asahi/vulkan/hk_cmd_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ struct hk_g17p_bind_tail_dyn_state {
uint32_t depth_bias_constant_raw;
uint32_t depth_bias_clamp_raw;
uint32_t depth_bias_slope_raw;
VkDepthClampRangeEXT depth_clamp_range;
VkDepthClampModeEXT depth_clamp_mode;
uint8_t depth_bias_representation;
uint8_t viewport_count;
uint8_t scissor_count;
Expand Down
53 changes: 42 additions & 11 deletions src/asahi/vulkan/hk_cmd_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -10859,6 +10859,28 @@ hk_effective_viewport_count(struct hk_cmd_buffer *cmd)
return MAX2(dyn->vp.viewport_count, 1);
}

/* Hardware depth clamp bounds for one viewport. The PPP depth clamp flag is
* the inverse of depth clip (see hk_flush_ppp_state), so with API depth clamp
* off the bounds stay [0, 1]. VK_EXT_depth_clamp_control replaces the viewport
* range with a user range; without depthRangeUnrestricted it lies in [0, 1].
*/
static inline void
hk_depth_clamp_bounds(const struct vk_dynamic_graphics_state *dyn,
const VkViewport *vp, float *min_z, float *max_z)
{
if (!dyn->rs.depth_clamp_enable) {
*min_z = 0.0f;
*max_z = 1.0f;
} else if (dyn->vp.depth_clamp_mode ==
VK_DEPTH_CLAMP_MODE_USER_DEFINED_RANGE_EXT) {
*min_z = dyn->vp.depth_clamp_range.minDepthClamp;
*max_z = dyn->vp.depth_clamp_range.maxDepthClamp;
} else {
*min_z = MIN2(vp->minDepth, vp->maxDepth);
*max_z = MAX2(vp->minDepth, vp->maxDepth);
}
}

static void
hk_compute_vp_scissor_rects(const struct vk_dynamic_graphics_state *dyn,
uint32_t fb_width, uint32_t fb_height,
Expand Down Expand Up @@ -10957,12 +10979,8 @@ hk_flush_vp_state(struct hk_cmd_buffer *cmd, struct hk_cs *cs, uint8_t **out)
*
* TODO: Reverse-engineer the finer interactions here.
*/
const float min_z = dyn->rs.depth_clamp_enable
? MIN2(vp->minDepth, vp->maxDepth)
: 0.0f;
const float max_z = dyn->rs.depth_clamp_enable
? MAX2(vp->minDepth, vp->maxDepth)
: 1.0f;
float min_z, max_z;
hk_depth_clamp_bounds(dyn, vp, &min_z, &max_z);
uint8_t *record = scissors + i * AGX_SCISSOR_LENGTH;

if (hal300) {
Expand Down Expand Up @@ -11283,6 +11301,8 @@ hk_g17p_bind_tail_dyn_capture(const struct vk_dynamic_graphics_state *dyn,
dyn->vp.depth_clip_negative_one_to_one;
out->rasterizer_discard_enable = dyn->rs.rasterizer_discard_enable;
out->depth_clamp_enable = dyn->rs.depth_clamp_enable;
out->depth_clamp_mode = dyn->vp.depth_clamp_mode;
out->depth_clamp_range = dyn->vp.depth_clamp_range;
out->depth_bias_enable = dyn->rs.depth_bias.enable;
out->depth_bias_exact = dyn->rs.depth_bias.exact;
out->depth_test_enable = dyn->ds.depth.test_enable;
Expand All @@ -11305,6 +11325,14 @@ hk_g17p_bind_tail_viewport_dyn_matches(
snap->depth_bias_enable != dyn->rs.depth_bias.enable)
return false;

if (dyn->rs.depth_clamp_enable &&
(snap->depth_clamp_mode != dyn->vp.depth_clamp_mode ||
(dyn->vp.depth_clamp_mode ==
VK_DEPTH_CLAMP_MODE_USER_DEFINED_RANGE_EXT &&
memcmp(&snap->depth_clamp_range, &dyn->vp.depth_clamp_range,
sizeof(snap->depth_clamp_range)) != 0)))
return false;

if (dyn->rs.depth_bias.enable &&
(snap->depth_bias_exact != dyn->rs.depth_bias.exact ||
snap->depth_bias_representation != dyn->rs.depth_bias.representation ||
Expand Down Expand Up @@ -11685,14 +11713,15 @@ hk_g17p_draw_state_viewports(struct hk_cmd_buffer *cmd,
maxy = MIN2(maxy, s->offset.y + s->extent.height);
}

const bool clamp = dyn->rs.depth_clamp_enable;
float min_z, max_z;
hk_depth_clamp_bounds(dyn, v, &min_z, &max_z);
state->viewports[i] = (struct agx_hal200_viewport){
.min_x = minx,
.min_y = miny,
.max_x = maxx,
.max_y = maxy,
.min_z_raw = fui(clamp ? MIN2(v->minDepth, v->maxDepth) : 0.0f),
.max_z_raw = fui(clamp ? MAX2(v->minDepth, v->maxDepth) : 1.0f),
.min_z_raw = fui(min_z),
.max_z_raw = fui(max_z),
.transform = {
.translate_x = fui(v->x + 0.5f * v->width),
.scale_x = fui(v->width * 0.5f),
Expand Down Expand Up @@ -15393,7 +15422,8 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs,
IS_DIRTY(VP_SCISSORS) || IS_DIRTY(VP_SCISSOR_COUNT) ||
IS_DIRTY(VP_VIEWPORTS) || IS_DIRTY(VP_VIEWPORT_COUNT) ||
IS_DIRTY(VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE) ||
IS_DIRTY(RS_DEPTH_CLIP_ENABLE) || IS_DIRTY(RS_DEPTH_CLAMP_ENABLE)) {
IS_DIRTY(RS_DEPTH_CLIP_ENABLE) || IS_DIRTY(RS_DEPTH_CLAMP_ENABLE) ||
IS_DIRTY(VP_DEPTH_CLAMP_RANGE)) {

/* TODO: Do less often? */
hk_reserve_scratch(cmd, cs, hw_vs);
Expand Down Expand Up @@ -15613,7 +15643,8 @@ hk_flush_dynamic_state_slow(struct hk_cmd_buffer *cmd, struct hk_cs *cs,
IS_DIRTY(VP_SCISSOR_COUNT) || IS_DIRTY(VP_VIEWPORTS) ||
IS_DIRTY(VP_VIEWPORT_COUNT) ||
IS_DIRTY(VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE) ||
IS_DIRTY(RS_DEPTH_CLIP_ENABLE) || IS_DIRTY(RS_DEPTH_CLAMP_ENABLE))) {
IS_DIRTY(RS_DEPTH_CLIP_ENABLE) || IS_DIRTY(RS_DEPTH_CLAMP_ENABLE) ||
IS_DIRTY(VP_DEPTH_CLAMP_RANGE))) {

hk_flush_vp_state(cmd, cs, &out);
if (vk_command_buffer_has_error(&cmd->vk)) {
Expand Down
4 changes: 4 additions & 0 deletions src/asahi/vulkan/hk_physical_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ hk_get_device_extensions(const struct agx_device *dev,
.EXT_custom_border_color = true,
.EXT_debug_marker = true,
.EXT_depth_bias_control = true,
.EXT_depth_clamp_control = true,
/* Lowered in NIR (agx_nir_lower_clip_m1_1) via the shared root table on
* AGX2, native AGX3, and AGX3C/HAL300 (M5: G17G/G17S/G17C); other HAL300
* encodings such as AGX3D (G18G) stay off until qualified. */
Expand Down Expand Up @@ -787,6 +788,9 @@ hk_get_device_features(
.floatRepresentation = false,
.depthBiasExact = true,

/* VK_EXT_depth_clamp_control */
.depthClampControl = true,

/* VK_EXT_depth_clip_control */
.depthClipControl = supported_extensions->EXT_depth_clip_control,

Expand Down