intel/compiler: Lower sample index into coord for MSRT messages

Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32690>
This commit is contained in:
Sagar Ghuge 2023-10-04 15:39:48 -07:00 committed by Marge Bot
parent bea9d79cb9
commit 1bfe2571f5
4 changed files with 72 additions and 0 deletions

View file

@ -1794,6 +1794,9 @@ brw_postprocess_nir(nir_shader *nir, const struct brw_compiler *compiler,
OPT(nir_lower_idiv, &options);
}
if (devinfo->ver >= 30)
NIR_PASS(_, nir, brw_nir_lower_sample_index_in_coord);
if (gl_shader_stage_can_set_fragment_shading_rate(nir->info.stage))
NIR_PASS(_, nir, intel_nir_lower_shading_rate_output);

View file

@ -201,6 +201,8 @@ bool brw_nir_lower_texel_address(nir_shader *shader,
const struct intel_device_info *devinfo,
enum isl_tiling tiling);
bool brw_nir_lower_sample_index_in_coord(nir_shader *nir);
bool brw_nir_lower_mem_access_bit_sizes(nir_shader *shader,
const struct
intel_device_info *devinfo);

View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2015-2025 Intel Corporation
* SPDX-License-Identifier: MIT
*/
#include "brw_nir.h"
#include "compiler/nir/nir_builder.h"
/* Put the sample index in the 4th component of coords since multisampled
* images don't support mipmapping.
*/
static bool
lower_image_sample_index_in_coord(nir_builder *b,
nir_intrinsic_instr *intrin)
{
b->cursor = nir_before_instr(&intrin->instr);
nir_def *coord = intrin->src[1].ssa;
nir_def *sample_index = intrin->src[2].ssa;
nir_def *new_coord;
if (nir_intrinsic_image_array(intrin)) {
new_coord = nir_vec4(b, nir_channel(b, coord, 0),
nir_channel(b, coord, 1), nir_channel(b, coord, 2),
sample_index);
} else {
new_coord = nir_vec4(b, nir_channel(b, coord, 0),
nir_channel(b, coord, 1), nir_imm_int(b, 0),
sample_index);
}
nir_src_rewrite(&intrin->src[1], new_coord);
return true;
}
static bool
lower_image_sample_index_in_coord_instr(nir_builder *b,
nir_instr *instr,
void *cb_data)
{
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
case nir_intrinsic_image_load:
case nir_intrinsic_bindless_image_load:
case nir_intrinsic_image_store:
case nir_intrinsic_bindless_image_store:
if (nir_intrinsic_image_dim(intrin) != GLSL_SAMPLER_DIM_MS)
return false;
return lower_image_sample_index_in_coord(b, intrin);
default:
return false;
}
}
bool
brw_nir_lower_sample_index_in_coord(nir_shader *shader)
{
return nir_shader_instructions_pass(shader,
lower_image_sample_index_in_coord_instr,
nir_metadata_none, NULL);
}

View file

@ -75,6 +75,7 @@ libintel_compiler_brw_files = files(
'brw_nir_lower_intersection_shader.c',
'brw_nir_lower_ray_queries.c',
'brw_nir_lower_rt_intrinsics.c',
'brw_nir_lower_sample_index_in_coord.c',
'brw_nir_lower_shader_calls.c',
'brw_nir_lower_storage_image.c',
'brw_nir_lower_texel_address.c',