kk: Support robustBufferAccess2

Add missing vertex input robustness 2 behavior and advertise.

Reviewed-by: Aitor Camacho <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41313>
This commit is contained in:
squidbus 2026-04-30 21:27:53 -07:00 committed by Marge Bot
parent 23f7c87e3e
commit 0c9dfa90f9
3 changed files with 29 additions and 9 deletions

View file

@ -20,6 +20,7 @@ struct ctx {
bool requires_vertex_id;
bool requires_instance_id;
bool requires_base_instance;
bool requires_robustness2;
};
static bool
@ -201,6 +202,18 @@ pass(struct nir_builder *b, nir_intrinsic_instr *intr, void *data)
b, interchange_comps, interchange_register_size, base, stride_offset_el,
.format = interchange_format, .base = 0u);
if (ctx->requires_robustness2) {
uint64_t attrib_clamp_offset = offsetof(
struct kk_root_descriptor_table, draw.attrib_clamps[index]);
nir_def *bounds = nir_load_global_constant(
b, 1, 32, nir_iadd_imm(b, argbuf, attrib_clamp_offset));
nir_def *oob = nir_ult(b, bounds, el);
/* Produce zero for out-of-bounds access */
nir_def *zero = nir_imm_zero(b, memory->num_components, memory->bit_size);
memory = nir_bcsel(b, oob, zero, memory);
}
unsigned dest_size = intr->def.bit_size;
unsigned bits[] = {desc->channel[chan].size, desc->channel[chan].size,
desc->channel[chan].size, desc->channel[chan].size};
@ -261,11 +274,15 @@ pass(struct nir_builder *b, nir_intrinsic_instr *intr, void *data)
}
bool
kk_nir_lower_vbo(nir_shader *nir, struct kk_attribute *attribs)
kk_nir_lower_vbo(nir_shader *nir, struct kk_attribute *attribs,
bool robustness2)
{
assert(nir->info.stage == MESA_SHADER_VERTEX);
struct ctx ctx = {.attribs = attribs};
struct ctx ctx = {
.attribs = attribs,
.requires_robustness2 = robustness2,
};
bool progress =
nir_shader_intrinsics_pass(nir, pass, nir_metadata_control_flow, &ctx);

View file

@ -35,7 +35,8 @@ struct kk_attribute {
bool instanced : 1;
};
bool kk_nir_lower_vbo(nir_shader *shader, struct kk_attribute *attribs);
bool kk_nir_lower_vbo(nir_shader *shader, struct kk_attribute *attribs,
bool robustness2);
bool kk_vbo_supports_format(enum pipe_format format);

View file

@ -36,12 +36,11 @@ kk_get_nir_options(struct vk_physical_device *vk_pdev, mesa_shader_stage stage,
return &kk_nir_options;
}
/* TODO_KOSMICKRISP Once we support robustness2, update these values. */
static const struct vk_pipeline_robustness_state rs_all_supported = {
.uniform_buffers =
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS,
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_2,
.storage_buffers =
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS,
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_2,
.images = VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_ROBUST_IMAGE_ACCESS_2_EXT,
};
@ -287,7 +286,8 @@ kk_nir_swizzle_fragment_output(nir_builder *b, nir_intrinsic_instr *intrin,
}
static void
kk_lower_vs_vbo(nir_shader *nir, const struct vk_graphics_pipeline_state *state)
kk_lower_vs_vbo(nir_shader *nir, const struct vk_graphics_pipeline_state *state,
const struct vk_pipeline_robustness_state *rs)
{
assert(!(nir->info.inputs_read & BITFIELD64_MASK(VERT_ATTRIB_GENERIC0)) &&
"Fixed-function attributes not used in Vulkan");
@ -315,7 +315,9 @@ kk_lower_vs_vbo(nir_shader *nir, const struct vk_graphics_pipeline_state *state)
attributes[slot].instanced =
binding->input_rate == VK_VERTEX_INPUT_RATE_INSTANCE;
}
NIR_PASS(_, nir, kk_nir_lower_vbo, attributes);
bool robustness2 = rs->vertex_inputs ==
VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_2;
NIR_PASS(_, nir, kk_nir_lower_vbo, attributes, robustness2);
}
static void
@ -705,7 +707,7 @@ kk_compile_shader(struct kk_device *dev, struct vk_shader_compile_info *info,
/* VBO lowering needs to go here otherwise, the linking step removes all
* inputs since we read vertex attributes from UBOs. */
if (info->stage == MESA_SHADER_VERTEX) {
kk_lower_vs_vbo(nir, state);
kk_lower_vs_vbo(nir, state, info->robustness);
}
msl_lower_nir_late(nir);
msl_optimize_nir(nir);