diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index fd6c650613d..440dfdc5f2f 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -2132,39 +2132,6 @@ v3dv_CmdBindPipeline(VkCommandBuffer commandBuffer, } } -/* FIXME: C&P from radv. tu has similar code. Perhaps common place? */ -void -v3dv_viewport_compute_xform(const VkViewport *viewport, - float scale[3], - float translate[3]) -{ - float x = viewport->x; - float y = viewport->y; - float half_width = 0.5f * viewport->width; - float half_height = 0.5f * viewport->height; - double n = viewport->minDepth; - double f = viewport->maxDepth; - - scale[0] = half_width; - translate[0] = half_width + x; - scale[1] = half_height; - translate[1] = half_height + y; - - scale[2] = (f - n); - translate[2] = n; - - /* It seems that if the scale is small enough the hardware won't clip - * correctly so we work around this my choosing the smallest scale that - * seems to work. - * - * This case is exercised by CTS: - * dEQP-VK.draw.inverted_depth_ranges.nodepthclamp_deltazero - */ - const float min_abs_scale = 0.000009f; - if (fabs(scale[2]) < min_abs_scale) - scale[2] = scale[2] < 0 ? -min_abs_scale : min_abs_scale; -} - /* Considers the pipeline's negative_one_to_one state and applies it to the * current viewport transform if needed to produce the resulting Z translate * and scale parameters. @@ -2217,9 +2184,10 @@ v3dv_CmdSetViewport(VkCommandBuffer commandBuffer, viewportCount * sizeof(*pViewports)); for (uint32_t i = firstViewport; i < total_count; i++) { - v3dv_viewport_compute_xform(&state->dynamic.viewport.viewports[i], - state->dynamic.viewport.scale[i], - state->dynamic.viewport.translate[i]); + v3dv_X(cmd_buffer->device, viewport_compute_xform) + (&state->dynamic.viewport.viewports[i], + state->dynamic.viewport.scale[i], + state->dynamic.viewport.translate[i]); } cmd_buffer->state.dirty |= V3DV_CMD_DIRTY_VIEWPORT; diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index b379b1a2e34..d3e307cacb2 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -2686,9 +2686,10 @@ pipeline_init_dynamic_state( pViewportState->viewportCount); for (uint32_t i = 0; i < dynamic->viewport.count; i++) { - v3dv_viewport_compute_xform(&dynamic->viewport.viewports[i], - dynamic->viewport.scale[i], - dynamic->viewport.translate[i]); + v3dv_X(pipeline->device, viewport_compute_xform) + (&dynamic->viewport.viewports[i], + dynamic->viewport.scale[i], + dynamic->viewport.translate[i]); } } diff --git a/src/broadcom/vulkan/v3dvx_cmd_buffer.c b/src/broadcom/vulkan/v3dvx_cmd_buffer.c index 504cd2fee7a..638158b791e 100644 --- a/src/broadcom/vulkan/v3dvx_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dvx_cmd_buffer.c @@ -1285,6 +1285,43 @@ v3dX(cmd_buffer_emit_render_pass_rcl)(struct v3dv_cmd_buffer *cmd_buffer) cl_emit(rcl, END_OF_RENDERING, end); } +void +v3dX(viewport_compute_xform)(const VkViewport *viewport, + float scale[3], + float translate[3]) +{ + float x = viewport->x; + float y = viewport->y; + float half_width = 0.5f * viewport->width; + float half_height = 0.5f * viewport->height; + double n = viewport->minDepth; + double f = viewport->maxDepth; + + scale[0] = half_width; + translate[0] = half_width + x; + scale[1] = half_height; + translate[1] = half_height + y; + + scale[2] = (f - n); + translate[2] = n; + + /* It seems that if the scale is small enough the hardware won't clip + * correctly so we work around this my choosing the smallest scale that + * seems to work. + * + * This case is exercised by CTS: + * dEQP-VK.draw.renderpass.inverted_depth_ranges.nodepthclamp_deltazero + * + * V3D 7.x fixes this by using the new + * CLIPPER_Z_SCALE_AND_OFFSET_NO_GUARDBAND. + */ +#if V3D_VERSION <= 42 + const float min_abs_scale = 0.0005f; + if (fabs(scale[2]) < min_abs_scale) + scale[2] = scale[2] < 0 ? -min_abs_scale : min_abs_scale; +#endif +} + void v3dX(cmd_buffer_emit_viewport)(struct v3dv_cmd_buffer *cmd_buffer) { diff --git a/src/broadcom/vulkan/v3dvx_private.h b/src/broadcom/vulkan/v3dvx_private.h index 036ce11b455..81715520913 100644 --- a/src/broadcom/vulkan/v3dvx_private.h +++ b/src/broadcom/vulkan/v3dvx_private.h @@ -339,3 +339,8 @@ v3dX(clamp_for_format_and_type)(uint32_t rt_type, uint32_t v3dX(clamp_for_format_and_type)(uint32_t rt_type, VkFormat vk_format); + +void +v3dX(viewport_compute_xform)(const VkViewport *viewport, + float scale[3], + float translate[3]);