nine: optimize texture binds a bit
this can just iterate over the mask of active textures instead of always iterating over and rebinding all textures Acked-by: Marek Olšák <marek.olsak@amd.com> Reviewed-by: <Axel Davy davyaxel0@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11865>
This commit is contained in:
parent
0165fde82c
commit
26d1886a7c
|
@ -995,30 +995,24 @@ update_textures_and_samplers(struct NineDevice9 *device)
|
||||||
struct nine_context *context = &device->context;
|
struct nine_context *context = &device->context;
|
||||||
struct pipe_context *pipe = context->pipe;
|
struct pipe_context *pipe = context->pipe;
|
||||||
struct pipe_sampler_view *view[NINE_MAX_SAMPLERS];
|
struct pipe_sampler_view *view[NINE_MAX_SAMPLERS];
|
||||||
unsigned num_textures;
|
unsigned num_textures = 0;
|
||||||
unsigned i;
|
|
||||||
boolean commit_samplers;
|
boolean commit_samplers;
|
||||||
uint16_t sampler_mask = context->ps ? context->ps->sampler_mask :
|
uint16_t sampler_mask = context->ps ? context->ps->sampler_mask :
|
||||||
device->ff.ps->sampler_mask;
|
device->ff.ps->sampler_mask;
|
||||||
|
|
||||||
/* TODO: Can we reduce iterations here ? */
|
|
||||||
|
|
||||||
commit_samplers = FALSE;
|
commit_samplers = FALSE;
|
||||||
|
uint16_t prev_mask = context->bound_samplers_mask_ps;
|
||||||
context->bound_samplers_mask_ps = 0;
|
context->bound_samplers_mask_ps = 0;
|
||||||
for (num_textures = 0, i = 0; i < NINE_MAX_SAMPLERS_PS; ++i) {
|
const uint16_t ps_mask = sampler_mask | context->enabled_samplers_mask_ps;
|
||||||
|
/* iterate over extant+enabled mask */
|
||||||
|
u_foreach_bit(i, ps_mask) {
|
||||||
const unsigned s = NINE_SAMPLER_PS(i);
|
const unsigned s = NINE_SAMPLER_PS(i);
|
||||||
int sRGB;
|
int sRGB;
|
||||||
|
|
||||||
if (!context->texture[s].enabled && !(sampler_mask & (1 << i))) {
|
if (context->enabled_samplers_mask_ps & BITFIELD_BIT(i)) {
|
||||||
view[i] = NULL;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context->texture[s].enabled) {
|
|
||||||
sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
|
sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
|
||||||
|
|
||||||
view[i] = context->texture[s].view[sRGB];
|
view[i] = context->texture[s].view[sRGB];
|
||||||
num_textures = i + 1;
|
|
||||||
|
|
||||||
if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
|
if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
|
||||||
context->changed.sampler[s] = 0;
|
context->changed.sampler[s] = 0;
|
||||||
|
@ -1033,7 +1027,6 @@ update_textures_and_samplers(struct NineDevice9 *device)
|
||||||
* anymore, but they're going to be removed as long as texture
|
* anymore, but they're going to be removed as long as texture
|
||||||
* or sampler states are changed. */
|
* or sampler states are changed. */
|
||||||
view[i] = device->dummy_sampler_view;
|
view[i] = device->dummy_sampler_view;
|
||||||
num_textures = i + 1;
|
|
||||||
|
|
||||||
cso_single_sampler(context->cso, PIPE_SHADER_FRAGMENT,
|
cso_single_sampler(context->cso, PIPE_SHADER_FRAGMENT,
|
||||||
s - NINE_SAMPLER_PS(0), &device->dummy_sampler_state);
|
s - NINE_SAMPLER_PS(0), &device->dummy_sampler_state);
|
||||||
|
@ -1041,32 +1034,34 @@ update_textures_and_samplers(struct NineDevice9 *device)
|
||||||
commit_samplers = TRUE;
|
commit_samplers = TRUE;
|
||||||
context->changed.sampler[s] = ~0;
|
context->changed.sampler[s] = ~0;
|
||||||
}
|
}
|
||||||
|
num_textures = i + 1;
|
||||||
|
|
||||||
context->bound_samplers_mask_ps |= (1 << s);
|
context->bound_samplers_mask_ps |= (1 << s);
|
||||||
}
|
}
|
||||||
|
/* fill in unused samplers */
|
||||||
|
u_foreach_bit(i, BITFIELD_MASK(num_textures) & ~ps_mask)
|
||||||
|
view[i] = NULL;
|
||||||
|
|
||||||
pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num_textures, 0, view);
|
pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, num_textures,
|
||||||
|
/* unbind trailing based on bitcount of shifted mask */
|
||||||
|
util_bitcount(prev_mask >> num_textures), view);
|
||||||
|
|
||||||
if (commit_samplers)
|
if (commit_samplers)
|
||||||
cso_single_sampler_done(context->cso, PIPE_SHADER_FRAGMENT);
|
cso_single_sampler_done(context->cso, PIPE_SHADER_FRAGMENT);
|
||||||
|
|
||||||
commit_samplers = FALSE;
|
commit_samplers = FALSE;
|
||||||
sampler_mask = context->programmable_vs ? context->vs->sampler_mask : 0;
|
sampler_mask = context->programmable_vs ? context->vs->sampler_mask : 0;
|
||||||
|
prev_mask = context->bound_samplers_mask_vs;
|
||||||
context->bound_samplers_mask_vs = 0;
|
context->bound_samplers_mask_vs = 0;
|
||||||
for (num_textures = 0, i = 0; i < NINE_MAX_SAMPLERS_VS; ++i) {
|
const uint16_t vs_mask = sampler_mask | context->enabled_samplers_mask_vs;
|
||||||
|
u_foreach_bit(i, vs_mask) {
|
||||||
const unsigned s = NINE_SAMPLER_VS(i);
|
const unsigned s = NINE_SAMPLER_VS(i);
|
||||||
int sRGB;
|
int sRGB;
|
||||||
|
|
||||||
if (!context->texture[s].enabled && !(sampler_mask & (1 << i))) {
|
|
||||||
view[i] = NULL;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context->texture[s].enabled) {
|
if (context->texture[s].enabled) {
|
||||||
sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
|
sRGB = context->samp[s][D3DSAMP_SRGBTEXTURE] ? 1 : 0;
|
||||||
|
|
||||||
view[i] = context->texture[s].view[sRGB];
|
view[i] = context->texture[s].view[sRGB];
|
||||||
num_textures = i + 1;
|
|
||||||
|
|
||||||
if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
|
if (update_sampler_derived(context, s) || (context->changed.sampler[s] & 0x05fe)) {
|
||||||
context->changed.sampler[s] = 0;
|
context->changed.sampler[s] = 0;
|
||||||
|
@ -1081,7 +1076,6 @@ update_textures_and_samplers(struct NineDevice9 *device)
|
||||||
* anymore, but they're going to be removed as long as texture
|
* anymore, but they're going to be removed as long as texture
|
||||||
* or sampler states are changed. */
|
* or sampler states are changed. */
|
||||||
view[i] = device->dummy_sampler_view;
|
view[i] = device->dummy_sampler_view;
|
||||||
num_textures = i + 1;
|
|
||||||
|
|
||||||
cso_single_sampler(context->cso, PIPE_SHADER_VERTEX,
|
cso_single_sampler(context->cso, PIPE_SHADER_VERTEX,
|
||||||
s - NINE_SAMPLER_VS(0), &device->dummy_sampler_state);
|
s - NINE_SAMPLER_VS(0), &device->dummy_sampler_state);
|
||||||
|
@ -1089,11 +1083,17 @@ update_textures_and_samplers(struct NineDevice9 *device)
|
||||||
commit_samplers = TRUE;
|
commit_samplers = TRUE;
|
||||||
context->changed.sampler[s] = ~0;
|
context->changed.sampler[s] = ~0;
|
||||||
}
|
}
|
||||||
|
num_textures = i + 1;
|
||||||
|
|
||||||
context->bound_samplers_mask_vs |= (1 << i);
|
context->bound_samplers_mask_vs |= (1 << i);
|
||||||
}
|
}
|
||||||
|
/* fill in unused samplers */
|
||||||
|
u_foreach_bit(i, BITFIELD_MASK(num_textures) & ~vs_mask)
|
||||||
|
view[i] = NULL;
|
||||||
|
|
||||||
pipe->set_sampler_views(pipe, PIPE_SHADER_VERTEX, 0, num_textures, 0, view);
|
pipe->set_sampler_views(pipe, PIPE_SHADER_VERTEX, 0, num_textures,
|
||||||
|
/* unbind trailing based on bitcount of shifted mask */
|
||||||
|
util_bitcount(prev_mask >> num_textures), view);
|
||||||
|
|
||||||
if (commit_samplers)
|
if (commit_samplers)
|
||||||
cso_single_sampler_done(context->cso, PIPE_SHADER_VERTEX);
|
cso_single_sampler_done(context->cso, PIPE_SHADER_VERTEX);
|
||||||
|
@ -1475,6 +1475,17 @@ CSMT_ITEM_NO_WAIT(nine_context_set_texture_apply,
|
||||||
uint fetch4_compatible = (fetch4_shadow_enabled >> 2) & 1;
|
uint fetch4_compatible = (fetch4_shadow_enabled >> 2) & 1;
|
||||||
|
|
||||||
context->texture[stage].enabled = enabled;
|
context->texture[stage].enabled = enabled;
|
||||||
|
if (enabled) {
|
||||||
|
if (stage < NINE_MAX_SAMPLERS_PS)
|
||||||
|
context->enabled_samplers_mask_ps |= BITFIELD_BIT(stage - NINE_SAMPLER_PS(0));
|
||||||
|
else if (stage >= NINE_SAMPLER_VS(0))
|
||||||
|
context->enabled_samplers_mask_vs |= BITFIELD_BIT(stage - NINE_SAMPLER_VS(0));
|
||||||
|
} else {
|
||||||
|
if (stage < NINE_MAX_SAMPLERS_PS)
|
||||||
|
context->enabled_samplers_mask_ps &= ~BITFIELD_BIT(stage - NINE_SAMPLER_PS(0));
|
||||||
|
else if (stage >= NINE_SAMPLER_VS(0))
|
||||||
|
context->enabled_samplers_mask_vs &= ~BITFIELD_BIT(stage - NINE_SAMPLER_VS(0));
|
||||||
|
}
|
||||||
context->samplers_shadow &= ~(1 << stage);
|
context->samplers_shadow &= ~(1 << stage);
|
||||||
context->samplers_shadow |= shadow << stage;
|
context->samplers_shadow |= shadow << stage;
|
||||||
context->samplers_fetch4 &= ~(1 << stage);
|
context->samplers_fetch4 &= ~(1 << stage);
|
||||||
|
|
|
@ -302,7 +302,9 @@ struct nine_context {
|
||||||
uint32_t samplers_fetch4;
|
uint32_t samplers_fetch4;
|
||||||
|
|
||||||
uint8_t bound_samplers_mask_vs;
|
uint8_t bound_samplers_mask_vs;
|
||||||
|
uint8_t enabled_samplers_mask_vs;
|
||||||
uint16_t bound_samplers_mask_ps;
|
uint16_t bound_samplers_mask_ps;
|
||||||
|
uint16_t enabled_samplers_mask_ps;
|
||||||
|
|
||||||
int dummy_vbo_bound_at; /* -1 = not bound , >= 0 = bound index */
|
int dummy_vbo_bound_at; /* -1 = not bound , >= 0 = bound index */
|
||||||
boolean vbo_bound_done;
|
boolean vbo_bound_done;
|
||||||
|
|
Loading…
Reference in New Issue