kk: Attachmentless render passes start postponed to pipeline bind

Sample count is only known at pipeline bind not when the render pass is
started since there is no attachments to infer sample count.

Acked-by: Arcady Goldmints-Orlov <arcady@lunarg.com>
Signed-off-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38957>
This commit is contained in:
Aitor Camacho 2025-12-16 02:31:12 +09:00 committed by Marge Bot
parent 279679ce0c
commit 317a249205
5 changed files with 29 additions and 5 deletions

View file

@ -115,10 +115,12 @@ struct kk_graphics_state {
bool is_depth_stencil_dynamic;
bool is_cull_front_and_back;
bool restart_disabled;
bool need_to_start_render_pass;
enum mtl_primitive_type primitive_type;
enum mesa_prim prim;
enum kk_dirty dirty;
uint32_t sample_count;
struct {
enum mtl_visibility_result_mode mode;

View file

@ -229,8 +229,13 @@ kk_CmdBeginRendering(VkCommandBuffer commandBuffer,
mtl_new_render_pass_descriptor();
/* Framebufferless rendering, need to set pass_descriptors
* renderTargetWidth/Height to non-0 values and defaultRasterSampleCount */
if (framebuffer_extent.width == 0u && framebuffer_extent.height == 0u) {
* renderTargetWidth/Height to non-0 values and defaultRasterSampleCount.
* However, since the sample count will only be known at first pipeline bind,
* we need to delay the start of the pass until then since Metal will ignore
* bound pipeline's sample count. */
bool no_framebuffer =
framebuffer_extent.width == 0u && framebuffer_extent.height == 0u;
if (no_framebuffer) {
framebuffer_extent.width = render->area.extent.width;
framebuffer_extent.height = render->area.extent.height;
mtl_render_pass_descriptor_set_render_target_width(
@ -345,8 +350,9 @@ kk_CmdBeginRendering(VkCommandBuffer commandBuffer,
// TODO_KOSMICKRISP Fragment shading rate support goes here if Metal supports
// it
/* Start new encoder and encode sync commands from previous barriers (aka
* fences) */
/* Rendering with no attachments requires pushing the start of the render
* pass to first pipeline binding to know sample count. */
if (!no_framebuffer)
kk_encoder_start_render(cmd, pass_descriptor, render->view_mask);
/* Store descriptor in case we need to restart the pass at pipeline barrier,
@ -373,6 +379,7 @@ kk_CmdBeginRendering(VkCommandBuffer commandBuffer,
attachment_descriptor, MTL_LOAD_ACTION_LOAD);
}
cmd->state.gfx.render_pass_descriptor = pass_descriptor;
cmd->state.gfx.need_to_start_render_pass = no_framebuffer;
kk_cmd_buffer_dirty_all_gfx(cmd);

View file

@ -270,6 +270,15 @@ mtl_render_encoder *
kk_render_encoder(struct kk_cmd_buffer *cmd)
{
struct kk_encoder *encoder = cmd->encoder;
struct kk_graphics_state *gfx = &cmd->state.gfx;
if (gfx->need_to_start_render_pass) {
mtl_render_pass_descriptor_set_default_raster_sample_count(
cmd->state.gfx.render_pass_descriptor, gfx->sample_count);
gfx->need_to_start_render_pass = false;
kk_encoder_start_render(cmd, gfx->render_pass_descriptor,
gfx->render.view_mask);
}
/* Render encoders are created at vkBeginRendering only */
assert(encoder->main.last_used == KK_ENC_RENDER && encoder->main.encoder);
return (mtl_render_encoder *)encoder->main.encoder;

View file

@ -953,6 +953,7 @@ kk_compile_graphics_pipeline(struct kk_device *device,
pipeline_descriptor, max_amplification);
}
vertex_shader->pipeline.gfx.sample_count = 1u;
if (state->ms) {
mtl_render_pipeline_descriptor_set_raster_sample_count(
pipeline_descriptor, state->ms->rasterization_samples);
@ -960,6 +961,8 @@ kk_compile_graphics_pipeline(struct kk_device *device,
pipeline_descriptor, state->ms->alpha_to_coverage_enable);
mtl_render_pipeline_descriptor_set_alpha_to_one(
pipeline_descriptor, state->ms->alpha_to_one_enable);
vertex_shader->pipeline.gfx.sample_count =
state->ms->rasterization_samples;
}
vertex_shader->pipeline.gfx.handle =
@ -1216,6 +1219,8 @@ kk_cmd_bind_graphics_shader(struct kk_cmd_buffer *cmd,
cmd->state.gfx.is_depth_stencil_dynamic = requires_dynamic_depth_stencil;
cmd->state.gfx.dirty |= KK_DIRTY_PIPELINE;
cmd->state.gfx.dirty |= KK_DIRTY_VB;
cmd->state.gfx.sample_count = shader->pipeline.gfx.sample_count;
}
static void

View file

@ -42,6 +42,7 @@ struct kk_shader {
mtl_render_pipeline_state *handle;
mtl_depth_stencil_state *mtl_depth_stencil_state_handle;
enum mtl_primitive_type primitive_type;
uint32_t sample_count;
} gfx;
mtl_compute_pipeline_state *cs;
};