mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 22:38:05 +02:00
pco: basic arrayed image/sampler descriptor support
Signed-off-by: Simon Perretta <simon.perretta@imgtec.com> Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36412>
This commit is contained in:
parent
fd31165c38
commit
5088429170
6 changed files with 73 additions and 52 deletions
|
|
@ -2682,13 +2682,15 @@ intrinsic("enqueue_node_payloads", src_comp=[-1])
|
|||
# Returns true if it has been called for every payload.
|
||||
intrinsic("finalize_incoming_node_payload", src_comp=[-1], dest_comp=1)
|
||||
|
||||
# load_{tex,smp}_state_pco(array element)
|
||||
# Loads the texture/sampler state words for a given descriptor.
|
||||
intrinsic("load_tex_state_pco", dest_comp=0, indices=[DESC_SET, BINDING, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
|
||||
intrinsic("load_smp_state_pco", dest_comp=0, indices=[DESC_SET, BINDING, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
|
||||
intrinsic("load_tex_state_pco", src_comp=[1], dest_comp=0, indices=[DESC_SET, BINDING, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
|
||||
intrinsic("load_smp_state_pco", src_comp=[1], dest_comp=0, indices=[DESC_SET, BINDING, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
|
||||
|
||||
# load_{tex,smp}_meta_pco(array element)
|
||||
# Loads the texture/sampler metadata for a given descriptor.
|
||||
intrinsic("load_tex_meta_pco", dest_comp=0, indices=[DESC_SET, BINDING, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
|
||||
intrinsic("load_smp_meta_pco", dest_comp=0, indices=[DESC_SET, BINDING, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
|
||||
intrinsic("load_tex_meta_pco", src_comp=[1], dest_comp=0, indices=[DESC_SET, BINDING, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
|
||||
intrinsic("load_smp_meta_pco", src_comp=[1], dest_comp=0, indices=[DESC_SET, BINDING, COMPONENT], flags=[CAN_ELIMINATE, CAN_REORDER], bit_sizes=[32])
|
||||
|
||||
index("uint16_t", "smp_flags_pco")
|
||||
|
||||
|
|
|
|||
|
|
@ -1556,7 +1556,7 @@ bool pco_legalize(pco_shader *shader);
|
|||
bool pco_nir_compute_instance_check(nir_shader *shader);
|
||||
bool pco_nir_lower_algebraic(nir_shader *shader);
|
||||
bool pco_nir_lower_algebraic_late(nir_shader *shader);
|
||||
bool pco_nir_lower_tex(nir_shader *shader, pco_common_data *common);
|
||||
bool pco_nir_lower_tex(nir_shader *shader);
|
||||
bool pco_nir_lower_vk(nir_shader *shader, pco_common_data *common);
|
||||
bool pco_nir_pfo(nir_shader *shader, pco_fs_data *fs);
|
||||
bool pco_nir_point_size(nir_shader *shader);
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ void pco_lower_nir(pco_ctx *ctx, nir_shader *nir, pco_data *data)
|
|||
nir_var_shader_in | nir_var_shader_out);
|
||||
|
||||
NIR_PASS(_, nir, nir_lower_tex, &(nir_lower_tex_options){});
|
||||
NIR_PASS(_, nir, pco_nir_lower_tex, &data->common);
|
||||
NIR_PASS(_, nir, pco_nir_lower_tex);
|
||||
|
||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
NIR_PASS(_, nir, pco_nir_pfo, &data->fs);
|
||||
|
|
|
|||
|
|
@ -47,23 +47,12 @@ static inline nir_def *get_src_def(nir_tex_instr *tex,
|
|||
*
|
||||
* \param[in] b NIR builder.
|
||||
* \param[in] tex NIR texture instruction.
|
||||
* \param[in] tex_desc_set Texture descriptor set.
|
||||
* \param[in] tex_binding Texture binding.
|
||||
* \param[in] common Shader common data.
|
||||
* \param[in] tex_state Texture state words.
|
||||
* \return The replacement/lowered def.
|
||||
*/
|
||||
static nir_def *lower_tex_query_basic(nir_builder *b,
|
||||
nir_tex_instr *tex,
|
||||
unsigned tex_desc_set,
|
||||
unsigned tex_binding,
|
||||
pco_common_data *common)
|
||||
static nir_def *
|
||||
lower_tex_query_basic(nir_builder *b, nir_tex_instr *tex, nir_def *tex_state)
|
||||
{
|
||||
/* Load texture state words. */
|
||||
nir_def *tex_state = nir_load_tex_state_pco(b,
|
||||
ROGUE_NUM_TEXSTATE_DWORDS,
|
||||
.desc_set = tex_desc_set,
|
||||
.binding = tex_binding);
|
||||
|
||||
nir_def *tex_state_word[] = {
|
||||
[0] = nir_channel(b, tex_state, 0),
|
||||
[1] = nir_channel(b, tex_state, 1),
|
||||
|
|
@ -246,10 +235,10 @@ static inline void unpack_base_addr(nir_builder *b,
|
|||
* \param[in] cb_data User callback data.
|
||||
* \return The replacement/lowered def.
|
||||
*/
|
||||
static nir_def *lower_tex(nir_builder *b, nir_instr *instr, void *cb_data)
|
||||
static nir_def *
|
||||
lower_tex(nir_builder *b, nir_instr *instr, UNUSED void *cb_data)
|
||||
{
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
pco_common_data *common = cb_data;
|
||||
|
||||
unsigned tex_desc_set;
|
||||
unsigned tex_binding;
|
||||
|
|
@ -264,19 +253,6 @@ static nir_def *lower_tex(nir_builder *b, nir_instr *instr, void *cb_data)
|
|||
|
||||
b->cursor = nir_before_instr(instr);
|
||||
|
||||
if (nir_tex_instr_is_query(tex) && tex->op != nir_texop_lod)
|
||||
return lower_tex_query_basic(b, tex, tex_desc_set, tex_binding, common);
|
||||
|
||||
nir_def *tex_state = nir_load_tex_state_pco(b,
|
||||
ROGUE_NUM_TEXSTATE_DWORDS,
|
||||
.desc_set = tex_desc_set,
|
||||
.binding = tex_binding);
|
||||
|
||||
nir_def *smp_state = nir_load_smp_state_pco(b,
|
||||
ROGUE_NUM_TEXSTATE_DWORDS,
|
||||
.desc_set = smp_desc_set,
|
||||
.binding = smp_binding);
|
||||
|
||||
/* Process tex sources, build up the smp flags and data words. */
|
||||
BITSET_DECLARE(tex_src_set, nir_num_tex_src_types) = { 0 };
|
||||
nir_def *tex_srcs[nir_num_tex_src_types];
|
||||
|
|
@ -291,6 +267,33 @@ static nir_def *lower_tex(nir_builder *b, nir_instr *instr, void *cb_data)
|
|||
if ((tex_srcs[s] = get_src_def(tex, s)) != NULL)
|
||||
BITSET_SET(tex_src_set, s);
|
||||
|
||||
nir_def *tex_elem = nir_imm_int(b, 0);
|
||||
if (BITSET_TEST(tex_src_set, nir_tex_src_backend1)) {
|
||||
tex_elem = tex_srcs[nir_tex_src_backend1];
|
||||
BITSET_CLEAR(tex_src_set, nir_tex_src_backend1);
|
||||
}
|
||||
|
||||
nir_def *smp_elem = nir_imm_int(b, 0);
|
||||
if (BITSET_TEST(tex_src_set, nir_tex_src_backend2)) {
|
||||
smp_elem = tex_srcs[nir_tex_src_backend2];
|
||||
BITSET_CLEAR(tex_src_set, nir_tex_src_backend2);
|
||||
}
|
||||
|
||||
nir_def *tex_state = nir_load_tex_state_pco(b,
|
||||
ROGUE_NUM_TEXSTATE_DWORDS,
|
||||
tex_elem,
|
||||
.desc_set = tex_desc_set,
|
||||
.binding = tex_binding);
|
||||
|
||||
if (nir_tex_instr_is_query(tex) && tex->op != nir_texop_lod)
|
||||
return lower_tex_query_basic(b, tex, tex_state);
|
||||
|
||||
nir_def *smp_state = nir_load_smp_state_pco(b,
|
||||
ROGUE_NUM_TEXSTATE_DWORDS,
|
||||
smp_elem,
|
||||
.desc_set = smp_desc_set,
|
||||
.binding = smp_binding);
|
||||
|
||||
nir_def *float_coords;
|
||||
nir_def *int_coords;
|
||||
nir_def *float_array_index;
|
||||
|
|
@ -416,6 +419,7 @@ static nir_def *lower_tex(nir_builder *b, nir_instr *instr, void *cb_data)
|
|||
|
||||
nir_def *tex_meta = nir_load_tex_meta_pco(b,
|
||||
PCO_IMAGE_META_COUNT,
|
||||
tex_elem,
|
||||
.desc_set = tex_desc_set,
|
||||
.binding = tex_binding);
|
||||
|
||||
|
|
@ -533,6 +537,7 @@ static nir_def *lower_tex(nir_builder *b, nir_instr *instr, void *cb_data)
|
|||
nir_def *compare_op =
|
||||
nir_load_smp_meta_pco(b,
|
||||
1,
|
||||
smp_elem,
|
||||
.desc_set = smp_desc_set,
|
||||
.binding = smp_binding,
|
||||
.component = PCO_SAMPLER_META_COMPARE_OP);
|
||||
|
|
@ -559,10 +564,9 @@ static bool is_tex(const nir_instr *instr, UNUSED const void *cb_data)
|
|||
* \brief Texture lowering pass.
|
||||
*
|
||||
* \param[in,out] shader NIR shader.
|
||||
* \param[in] common Shader common data.
|
||||
* \return True if the pass made progress.
|
||||
*/
|
||||
bool pco_nir_lower_tex(nir_shader *shader, pco_common_data *common)
|
||||
bool pco_nir_lower_tex(nir_shader *shader)
|
||||
{
|
||||
return nir_shader_lower_instructions(shader, is_tex, lower_tex, common);
|
||||
return nir_shader_lower_instructions(shader, is_tex, lower_tex, NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ static nir_def *lower_load_vulkan_descriptor(nir_builder *b,
|
|||
return nir_imm_ivec3(b, desc_set_binding, elem, 0);
|
||||
}
|
||||
|
||||
static void lower_tex_deref_to_binding(nir_tex_instr *tex,
|
||||
static void lower_tex_deref_to_binding(nir_builder *b,
|
||||
nir_tex_instr *tex,
|
||||
unsigned deref_index,
|
||||
pco_common_data *common)
|
||||
{
|
||||
|
|
@ -70,9 +71,19 @@ static void lower_tex_deref_to_binding(nir_tex_instr *tex,
|
|||
nir_deref_instr *deref =
|
||||
nir_instr_as_deref(deref_src->src.ssa->parent_instr);
|
||||
|
||||
assert(deref->deref_type == nir_deref_type_var);
|
||||
b->cursor = nir_before_instr(&tex->instr);
|
||||
|
||||
/* TODO: array support */
|
||||
unsigned array_elem = 0;
|
||||
if (deref->deref_type != nir_deref_type_var) {
|
||||
assert(deref->deref_type == nir_deref_type_array);
|
||||
|
||||
array_elem = nir_src_as_uint(deref->arr.index);
|
||||
|
||||
deref = nir_deref_instr_parent(deref);
|
||||
}
|
||||
|
||||
nir_def *elem = nir_imm_int(b, array_elem);
|
||||
assert(deref->deref_type == nir_deref_type_var);
|
||||
|
||||
unsigned desc_set = deref->var->data.descriptor_set;
|
||||
unsigned binding = deref->var->data.binding;
|
||||
|
|
@ -80,25 +91,29 @@ static void lower_tex_deref_to_binding(nir_tex_instr *tex,
|
|||
set_resource_used(common, desc_set, binding);
|
||||
|
||||
uint32_t desc_set_binding = pco_pack_desc(desc_set, binding);
|
||||
if (deref_src->src_type == nir_tex_src_texture_deref)
|
||||
if (deref_src->src_type == nir_tex_src_texture_deref) {
|
||||
tex->texture_index = desc_set_binding;
|
||||
else
|
||||
deref_src->src_type = nir_tex_src_backend1;
|
||||
} else {
|
||||
tex->sampler_index = desc_set_binding;
|
||||
deref_src->src_type = nir_tex_src_backend2;
|
||||
}
|
||||
|
||||
nir_tex_instr_remove_src(tex, deref_index);
|
||||
nir_src_rewrite(&deref_src->src, elem);
|
||||
}
|
||||
|
||||
static inline void lower_tex_derefs(nir_tex_instr *tex, pco_common_data *common)
|
||||
static inline void
|
||||
lower_tex_derefs(nir_builder *b, nir_tex_instr *tex, pco_common_data *common)
|
||||
{
|
||||
int deref_index;
|
||||
|
||||
deref_index = nir_tex_instr_src_index(tex, nir_tex_src_texture_deref);
|
||||
if (deref_index >= 0)
|
||||
lower_tex_deref_to_binding(tex, deref_index, common);
|
||||
lower_tex_deref_to_binding(b, tex, deref_index, common);
|
||||
|
||||
deref_index = nir_tex_instr_src_index(tex, nir_tex_src_sampler_deref);
|
||||
if (deref_index >= 0)
|
||||
lower_tex_deref_to_binding(tex, deref_index, common);
|
||||
lower_tex_deref_to_binding(b, tex, deref_index, common);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -129,7 +144,7 @@ static nir_def *lower_vk(nir_builder *b, nir_instr *instr, void *cb_data)
|
|||
|
||||
case nir_instr_type_tex: {
|
||||
nir_tex_instr *tex = nir_instr_as_tex(instr);
|
||||
lower_tex_derefs(tex, common);
|
||||
lower_tex_derefs(b, tex, common);
|
||||
return NIR_LOWER_INSTR_PROGRESS;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -755,12 +755,12 @@ static pco_instr *lower_load_tex_smp_state(trans_ctx *tctx,
|
|||
unsigned start_comp = nir_intrinsic_component(intr);
|
||||
unsigned chans = pco_ref_get_chans(dest);
|
||||
assert(start_comp + chans <= ROGUE_NUM_TEXSTATE_DWORDS);
|
||||
unsigned elem = nir_src_as_uint(intr->src[0]);
|
||||
|
||||
/* TODO: array support. */
|
||||
const pco_common_data *common = &tctx->shader->data.common;
|
||||
bool is_img_smp;
|
||||
unsigned sh_index =
|
||||
fetch_resource_base_reg(common, desc_set, binding, 0, &is_img_smp);
|
||||
fetch_resource_base_reg(common, desc_set, binding, elem, &is_img_smp);
|
||||
pco_ref state_words =
|
||||
pco_ref_hwreg_vec(sh_index, PCO_REG_CLASS_SHARED, chans);
|
||||
|
||||
|
|
@ -786,12 +786,12 @@ static pco_instr *lower_load_tex_smp_meta(trans_ctx *tctx,
|
|||
unsigned binding = nir_intrinsic_binding(intr);
|
||||
unsigned start_comp = nir_intrinsic_component(intr);
|
||||
unsigned chans = pco_ref_get_chans(dest);
|
||||
unsigned elem = nir_src_as_uint(intr->src[0]);
|
||||
|
||||
/* TODO: array support. */
|
||||
const pco_common_data *common = &tctx->shader->data.common;
|
||||
bool is_img_smp;
|
||||
unsigned sh_index =
|
||||
fetch_resource_base_reg(common, desc_set, binding, 0, &is_img_smp);
|
||||
fetch_resource_base_reg(common, desc_set, binding, elem, &is_img_smp);
|
||||
pco_ref state_words =
|
||||
pco_ref_hwreg_vec(sh_index, PCO_REG_CLASS_SHARED, chans);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue