zink: support GL_OVR_multiview

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31128>
This commit is contained in:
Mike Blumenkrantz 2024-09-11 20:29:34 -04:00 committed by Marge Bot
parent 5c5763f6a8
commit 1491ce46e4
4 changed files with 32 additions and 1 deletions

View file

@ -97,7 +97,7 @@ struct ntv_context {
workgroup_id_var, num_workgroups_var,
local_invocation_id_var, global_invocation_id_var,
local_invocation_index_var, helper_invocation_var,
local_group_size_var,
local_group_size_var, view_index_var,
base_vertex_var, base_instance_var, draw_id_var;
SpvId shared_mem_size;
@ -2614,6 +2614,24 @@ emit_load_front_face(struct ntv_context *ctx, nir_intrinsic_instr *intr)
store_def(ctx, intr->def.index, result, nir_type_bool);
}
static void
emit_load_view_index(struct ntv_context *ctx, nir_intrinsic_instr *intr)
{
SpvId var_type = spirv_builder_type_uint(&ctx->builder, 32);
spirv_builder_emit_extension(&ctx->builder, "SPV_KHR_multiview");
spirv_builder_emit_cap(&ctx->builder, SpvCapabilityMultiView);
if (!ctx->view_index_var)
ctx->view_index_var = create_builtin_var(ctx, var_type,
SpvStorageClassInput,
"gl_ViewIndex",
SpvBuiltInViewIndex);
SpvId result = spirv_builder_emit_load(&ctx->builder, var_type,
ctx->view_index_var);
assert(1 == intr->def.num_components);
store_def(ctx, intr->def.index, result, nir_type_uint);
}
static void
emit_load_uint_input(struct ntv_context *ctx, nir_intrinsic_instr *intr, SpvId *var_id, const char *var_name, SpvBuiltIn builtin)
{
@ -3278,6 +3296,10 @@ emit_intrinsic(struct ntv_context *ctx, nir_intrinsic_instr *intr)
emit_load_front_face(ctx, intr);
break;
case nir_intrinsic_load_view_index:
emit_load_view_index(ctx, intr);
break;
case nir_intrinsic_load_base_instance:
emit_load_uint_input(ctx, intr, &ctx->base_instance_var, "gl_BaseInstance", SpvBuiltInBaseInstance);
break;

View file

@ -2771,6 +2771,7 @@ zink_update_rendering_info(struct zink_context *ctx)
struct zink_surface *surf = zink_csurface(ctx->fb_state.cbufs[i]);
ctx->gfx_pipeline_state.rendering_formats[i] = surf ? surf->info.format[0] : VK_FORMAT_UNDEFINED;
}
ctx->gfx_pipeline_state.rendering_info.viewMask = ctx->fb_state.viewmask;
ctx->gfx_pipeline_state.rendering_info.depthAttachmentFormat = VK_FORMAT_UNDEFINED;
ctx->gfx_pipeline_state.rendering_info.stencilAttachmentFormat = VK_FORMAT_UNDEFINED;
if (ctx->fb_state.zsbuf && zink_is_zsbuf_used(ctx)) {
@ -3296,6 +3297,7 @@ hash_rendering_state(const void *key)
const VkPipelineRenderingCreateInfo *info = key;
uint32_t hash = 0;
/*
uint32_t viewMask;
uint32_t colorAttachmentCount;
const VkFormat* pColorAttachmentFormats;
VkFormat depthAttachmentFormat;
@ -3303,6 +3305,7 @@ hash_rendering_state(const void *key)
* this data is not optimally arranged, so it must be manually hashed
*/
hash = XXH32(&info->colorAttachmentCount, sizeof(uint32_t), hash);
hash = XXH32(&info->viewMask, sizeof(uint32_t), hash);
hash = XXH32(&info->depthAttachmentFormat, sizeof(uint32_t), hash);
hash = XXH32(&info->stencilAttachmentFormat, sizeof(VkFormat), hash);
return XXH32(info->pColorAttachmentFormats, sizeof(VkFormat) * info->colorAttachmentCount, hash);
@ -3315,6 +3318,7 @@ equals_rendering_state(const void *a, const void *b)
const VkPipelineRenderingCreateInfo *bi = b;
return ai->colorAttachmentCount == bi->colorAttachmentCount &&
ai->depthAttachmentFormat == bi->depthAttachmentFormat &&
ai->viewMask == bi->viewMask &&
ai->stencilAttachmentFormat == bi->stencilAttachmentFormat &&
!memcmp(ai->pColorAttachmentFormats, bi->pColorAttachmentFormats, sizeof(VkFormat) * ai->colorAttachmentCount);
}
@ -3800,6 +3804,8 @@ zink_set_framebuffer_state(struct pipe_context *pctx,
ctx->dynamic_fb.info.colorAttachmentCount = ctx->fb_state.nr_cbufs;
ctx->rp_changed |= ctx->dynamic_fb.info.layerCount != layers;
ctx->dynamic_fb.info.layerCount = layers;
ctx->rp_changed |= ctx->dynamic_fb.info.viewMask != state->viewmask;
ctx->dynamic_fb.info.viewMask = state->viewmask;
ctx->gfx_pipeline_state.rendering_info.colorAttachmentCount = ctx->fb_state.nr_cbufs;
ctx->void_clears = 0;

View file

@ -413,6 +413,7 @@ zink_can_use_pipeline_libs(const struct zink_context *ctx)
!zink_get_fs_base_key(ctx)->fbfetch_ms &&
!ctx->gfx_pipeline_state.force_persample_interp &&
!ctx->gfx_pipeline_state.min_samples &&
!ctx->fb_state.viewmask &&
!ctx->is_generated_gs_bound;
}

View file

@ -555,6 +555,8 @@ zink_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
switch (param) {
case PIPE_CAP_NULL_TEXTURES:
return screen->info.rb_image_feats.robustImageAccess;
case PIPE_CAP_MULTIVIEW:
return screen->info.have_vulkan13 ? screen->info.feats11.multiview : 0;
case PIPE_CAP_TEXRECT:
case PIPE_CAP_MULTI_DRAW_INDIRECT_PARTIAL_STRIDE:
return 0;