mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 00:00:11 +01:00
brw/nir_lower_sample_index_in_coord: use helpers
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37753>
This commit is contained in:
parent
544a739abc
commit
ec8ed69131
1 changed files with 17 additions and 38 deletions
|
|
@ -4,63 +4,42 @@
|
|||
*/
|
||||
|
||||
#include "brw_nir.h"
|
||||
#include "nir.h"
|
||||
#include "compiler/nir/nir_builder.h"
|
||||
#include "util/macros.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)
|
||||
pass(nir_builder *b, nir_intrinsic_instr *intrin, UNUSED void *_)
|
||||
{
|
||||
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);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nir_intrinsic_image_dim(intrin) != GLSL_SAMPLER_DIM_MS)
|
||||
return false;
|
||||
|
||||
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 = nir_vector_insert_imm(b, coord, sample_index, 3);
|
||||
nir_src_rewrite(&intrin->src[1], new_coord);
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
return nir_shader_intrinsics_pass(shader, pass, nir_metadata_control_flow,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue