nir: Add possibility to store image var offset in range_base

Add the intrinsic range_base value to the image intrinsics and add
the option to store the image array offset into range_base instead
of adding it to the image array index if the driver requests it.

v2: Always initialize range_base

v3: fix for bindless intrinsics

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19980>
This commit is contained in:
Gert Wollny
2022-11-24 13:23:06 +01:00
committed by Marge Bot
parent 2f4c7b5ccf
commit c4cde91c1b
3 changed files with 12 additions and 1 deletions

View File

@@ -98,14 +98,20 @@ lower_instr(nir_builder *b, nir_instr *instr, void *cb_data)
b->cursor = nir_before_instr(instr);
nir_ssa_def *src;
int range_base = 0;
if (bindless) {
src = nir_load_deref(b, deref);
} else if (b->shader->options->lower_image_offset_to_range_base) {
src = nir_build_deref_offset(b, deref, type_size_align_1);
range_base = var->data.driver_location;
} else {
src = nir_iadd_imm(b,
nir_build_deref_offset(b, deref, type_size_align_1),
var->data.driver_location);
}
nir_rewrite_image_intrinsic(intrinsic, src, bindless);
if (!bindless)
nir_intrinsic_set_range_base(intrinsic, range_base);
return true;
}

View File

@@ -3760,6 +3760,11 @@ typedef struct nir_shader_compiler_options {
* fragment task is far more than vertex one, so better left it disabled.
*/
bool lower_varying_from_uniform;
/** store the variable offset into the instrinsic range_base instead
* of adding it to the image index.
*/
bool lower_image_offset_to_range_base;
} nir_shader_compiler_options;
typedef struct nir_shader {

View File

@@ -633,7 +633,7 @@ def image(name, src_comp=[], extra_indices=[], **kwargs):
intrinsic("image_deref_" + name, src_comp=[-1] + src_comp,
indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
intrinsic("image_" + name, src_comp=[1] + src_comp,
indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)
indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS, RANGE_BASE] + extra_indices, **kwargs)
intrinsic("bindless_image_" + name, src_comp=[-1] + src_comp,
indices=[IMAGE_DIM, IMAGE_ARRAY, FORMAT, ACCESS] + extra_indices, **kwargs)