Commit 8027a7ba authored by Dave Airlie's avatar Dave Airlie
Browse files

shader_info: convert textures_used to a bitset.



For now keep it a bitset of 1 32-bit dword.
Reviewed-by: Emma Anholt's avatarEric Anholt <eric@anholt.net>
Part-of: <!9456>
parent c55bd4b6
Pipeline #281538 waiting for manual action with stages
......@@ -230,14 +230,13 @@ record_textures_used(struct shader_info *info,
/* Structs have been lowered already, so get_aoa_size is sufficient. */
const unsigned size =
glsl_type_is_array(var->type) ? glsl_get_aoa_size(var->type) : 1;
unsigned mask = ((1ull << MAX2(size, 1)) - 1) << var->data.binding;
info->textures_used |= mask;
BITSET_SET_RANGE(info->textures_used, var->data.binding, var->data.binding + (MAX2(size, 1) - 1));
if (op == nir_texop_txf ||
op == nir_texop_txf_ms ||
op == nir_texop_txf_ms_mcs)
info->textures_used_by_txf |= mask;
BITSET_SET_RANGE(info->textures_used_by_txf, var->data.binding, var->data.binding + (MAX2(size, 1) - 1));
}
static bool
......
......@@ -165,10 +165,10 @@ typedef struct shader_info {
uint64_t patch_outputs_accessed_indirectly;
/** Bitfield of which textures are used */
uint32_t textures_used;
BITSET_DECLARE(textures_used, 32);
/** Bitfield of which textures are used by texelFetch() */
uint32_t textures_used_by_txf;
BITSET_DECLARE(textures_used_by_txf, 32);
/** Bitfield of which images are used */
uint32_t images_used;
......
......@@ -3405,7 +3405,7 @@ emit_instructions(struct ir3_context *ctx)
* it is write-only we don't have to count it, but after lowering derefs
* is too late to compact indices for that.
*/
ctx->so->num_samp = util_last_bit(ctx->s->info.textures_used) + ctx->s->info.num_images;
ctx->so->num_samp = BITSET_LAST_BIT(ctx->s->info.textures_used) + ctx->s->info.num_images;
/* Save off clip+cull information. Note that in OpenGL clip planes may
* be individually enabled/disabled, so we can't use the
......
......@@ -340,8 +340,7 @@ build_bindless(nir_builder *b, nir_deref_instr *deref, bool is_sampler,
const struct glsl_type *glsl_type = glsl_without_array(var->type);
uint32_t idx = var->data.index * 2;
b->shader->info.textures_used |=
((1ull << (bind_layout->array_size * 2)) - 1) << (idx * 2);
BITSET_SET_RANGE(b->shader->info.textures_used, idx * 2, ((idx * 2) + (bind_layout->array_size * 2)) - 1);
/* D24S8 workaround: stencil of D24S8 will be sampled as uint */
if (glsl_get_sampler_result_type(glsl_type) == GLSL_TYPE_UINT)
......
......@@ -134,7 +134,7 @@ nir_lower_pstipple_fs(struct nir_shader *shader,
tex_var->data.explicit_binding = true;
tex_var->data.how_declared = nir_var_hidden;
shader->info.textures_used |= (1 << binding);
BITSET_SET(shader->info.textures_used, binding);
state.stip_tex = tex_var;
nir_foreach_function(function, shader) {
......
......@@ -403,7 +403,7 @@ ntt_setup_uniforms(struct ntt_compile *c)
}
for (int i = 0; i < PIPE_MAX_SAMPLERS; i++) {
if (c->s->info.textures_used & (1 << i))
if (BITSET_TEST(c->s->info.textures_used, i))
ureg_DECL_sampler(c->ureg, i);
}
}
......
......@@ -801,9 +801,9 @@ void nir_tgsi_scan_shader(const struct nir_shader *nir,
info->samplers_declared = sampler_mask;
info->file_max[TGSI_FILE_SAMPLER] = util_last_bit(info->samplers_declared) - 1;
info->file_max[TGSI_FILE_SAMPLER_VIEW] = util_last_bit(nir->info.textures_used) - 1;
info->file_max[TGSI_FILE_SAMPLER_VIEW] = BITSET_LAST_BIT(nir->info.textures_used) - 1;
info->file_mask[TGSI_FILE_SAMPLER] = info->samplers_declared;
info->file_mask[TGSI_FILE_SAMPLER_VIEW] = nir->info.textures_used;
info->file_mask[TGSI_FILE_SAMPLER_VIEW] = nir->info.textures_used[0];
info->file_max[TGSI_FILE_IMAGE] = util_last_bit(info->images_declared) - 1;
info->file_mask[TGSI_FILE_IMAGE] = info->images_declared;
......
......@@ -1274,12 +1274,11 @@ get_sampler_var(struct ttn_compile *c, int binding,
c->num_samplers = MAX2(c->num_samplers, binding + 1);
/* Record textures used */
unsigned mask = 1 << binding;
c->build.shader->info.textures_used |= mask;
BITSET_SET(c->build.shader->info.textures_used, binding);
if (op == nir_texop_txf ||
op == nir_texop_txf_ms ||
op == nir_texop_txf_ms_mcs)
c->build.shader->info.textures_used_by_txf |= mask;
BITSET_SET(c->build.shader->info.textures_used_by_txf, binding);
}
return var;
......
......@@ -822,8 +822,8 @@ iris_setup_binding_table(const struct gen_device_info *devinfo,
bt->sizes[IRIS_SURFACE_GROUP_CS_WORK_GROUPS] = 1;
}
bt->sizes[IRIS_SURFACE_GROUP_TEXTURE] = util_last_bit(info->textures_used);
bt->used_mask[IRIS_SURFACE_GROUP_TEXTURE] = info->textures_used;
bt->sizes[IRIS_SURFACE_GROUP_TEXTURE] = BITSET_LAST_BIT(info->textures_used);
bt->used_mask[IRIS_SURFACE_GROUP_TEXTURE] = info->textures_used[0];
bt->sizes[IRIS_SURFACE_GROUP_IMAGE] = info->num_images;
......@@ -2570,8 +2570,8 @@ bind_shader_state(struct iris_context *ice,
const struct shader_info *old_info = iris_get_shader_info(ice, stage);
const struct shader_info *new_info = ish ? &ish->nir->info : NULL;
if ((old_info ? util_last_bit(old_info->textures_used) : 0) !=
(new_info ? util_last_bit(new_info->textures_used) : 0)) {
if ((old_info ? BITSET_LAST_BIT(old_info->textures_used) : 0) !=
(new_info ? BITSET_LAST_BIT(new_info->textures_used) : 0)) {
ice->state.stage_dirty |= IRIS_STAGE_DIRTY_SAMPLER_STATES_VS << stage;
}
......
......@@ -89,7 +89,7 @@ resolve_sampler_views(struct iris_context *ice,
bool *draw_aux_buffer_disabled,
bool consider_framebuffer)
{
uint32_t views = info ? (shs->bound_sampler_views & info->textures_used) : 0;
uint32_t views = info ? (shs->bound_sampler_views & info->textures_used[0]) : 0;
while (views) {
const int i = u_bit_scan(&views);
......
......@@ -2100,7 +2100,7 @@ iris_upload_sampler_states(struct iris_context *ice, gl_shader_stage stage)
/* We assume gallium frontends will call pipe->bind_sampler_states()
* if the program's number of textures changes.
*/
unsigned count = info ? util_last_bit(info->textures_used) : 0;
unsigned count = info ? BITSET_LAST_BIT(info->textures_used) : 0;
if (!count)
return;
......
......@@ -690,7 +690,7 @@ static void si_check_render_feedback(struct si_context *sctx)
si_check_render_feedback_images(sctx, &sctx->images[i],
u_bit_consecutive(0, info->base.num_images));
si_check_render_feedback_textures(sctx, &sctx->samplers[i],
info->base.textures_used);
info->base.textures_used[0]);
}
si_check_render_feedback_resident_images(sctx);
......
......@@ -837,7 +837,7 @@ static bool si_check_needs_implicit_sync(struct si_context *sctx)
*/
struct si_shader_info *info = &sctx->cs_shader_state.program->sel.info;
struct si_samplers *samplers = &sctx->samplers[PIPE_SHADER_COMPUTE];
unsigned mask = samplers->enabled_mask & info->base.textures_used;
unsigned mask = samplers->enabled_mask & info->base.textures_used[0];
while (mask) {
int i = u_bit_scan(&mask);
......
......@@ -791,7 +791,7 @@ static void si_dump_descriptors(struct si_context *sctx, gl_shader_stage stage,
if (info) {
enabled_constbuf = u_bit_consecutive(0, info->base.num_ubos);
enabled_shaderbuf = u_bit_consecutive(0, info->base.num_ssbos);
enabled_samplers = info->base.textures_used;
enabled_samplers = info->base.textures_used[0];
enabled_images = u_bit_consecutive(0, info->base.num_images);
} else {
enabled_constbuf =
......
......@@ -2663,7 +2663,7 @@ bool si_gfx_resources_check_encrypted(struct si_context *sctx)
si_buffer_resources_check_encrypted(sctx, &sctx->const_and_shader_buffers[i]);
use_encrypted_bo |=
si_sampler_views_check_encrypted(sctx, &sctx->samplers[i],
current_shader->cso->info.base.textures_used);
current_shader->cso->info.base.textures_used[0]);
use_encrypted_bo |= si_image_views_check_encrypted(sctx, &sctx->images[i],
u_bit_consecutive(0, current_shader->cso->info.base.num_images));
}
......@@ -2743,7 +2743,7 @@ bool si_compute_resources_check_encrypted(struct si_context *sctx)
* or all writable buffers are encrypted.
*/
return si_buffer_resources_check_encrypted(sctx, &sctx->const_and_shader_buffers[sh]) ||
si_sampler_views_check_encrypted(sctx, &sctx->samplers[sh], info->base.textures_used) ||
si_sampler_views_check_encrypted(sctx, &sctx->samplers[sh], info->base.textures_used[0]) ||
si_image_views_check_encrypted(sctx, &sctx->images[sh], u_bit_consecutive(0, info->base.num_images)) ||
si_buffer_resources_check_encrypted(sctx, &sctx->internal_bindings);
}
......
......@@ -820,7 +820,7 @@ bool si_llvm_translate_nir(struct si_shader_context *ctx, struct si_shader *shad
ctx->num_const_buffers = info->base.num_ubos;
ctx->num_shader_buffers = info->base.num_ssbos;
ctx->num_samplers = util_last_bit(info->base.textures_used);
ctx->num_samplers = BITSET_LAST_BIT(info->base.textures_used);
ctx->num_images = info->base.num_images;
si_llvm_init_resource_callbacks(ctx);
......
......@@ -1612,8 +1612,8 @@ static bool si_all_vs_resources_read_only(struct si_context *sctx, struct pipe_r
}
/* Samplers. */
if (vs->info.base.textures_used) {
unsigned num_samplers = util_last_bit(vs->info.base.textures_used);
if (vs->info.base.textures_used[0]) {
unsigned num_samplers = BITSET_LAST_BIT(vs->info.base.textures_used);
for (unsigned i = 0; i < num_samplers; i++) {
struct pipe_sampler_view *view = sctx->samplers[PIPE_SHADER_VERTEX].views[i];
......
......@@ -2621,7 +2621,7 @@ void si_get_active_slot_masks(const struct si_shader_info *info, uint64_t *const
/* two 8-byte images share one 16-byte slot */
num_images = align(info->base.num_images, 2);
num_msaa_images = align(util_last_bit(info->base.msaa_images), 2);
num_samplers = util_last_bit(info->base.textures_used);
num_samplers = BITSET_LAST_BIT(info->base.textures_used);
/* The layout is: sb[last] ... sb[0], cb[0] ... cb[last] */
start = si_get_shaderbuf_slot(num_shaderbufs - 1);
......
......@@ -111,7 +111,9 @@ clover_nir_lower_images(nir_shader *shader)
}
}
shader->info.num_textures = num_rd_images;
shader->info.textures_used = (1 << num_rd_images) - 1;
BITSET_ZERO(shader->info.textures_used);
if (num_rd_images)
BITSET_SET_RANGE(shader->info.textures_used, 0, num_rd_images - 1);
shader->info.num_images = num_wr_images;
nir_builder b;
......
......@@ -154,7 +154,7 @@ static void lower_vri_instr_tex(struct nir_builder *b,
lower_vri_instr_tex_deref(tex, nir_tex_src_sampler_deref, b->shader->info.stage, layout);
tex_value = lower_vri_instr_tex_deref(tex, nir_tex_src_texture_deref, b->shader->info.stage, layout);
if (tex_value >= 0)
b->shader->info.textures_used |= (1 << tex_value);
BITSET_SET(b->shader->info.textures_used, tex_value);
}
static nir_ssa_def *lower_vri_instr(struct nir_builder *b,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment