mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-17 07:00:20 +01:00
st/nine: Cache constant buffer size
The shader constant buffer size with the constant compaction code can vary depending on the shader variant compiled (for example if fog constants are required, etc). Thus instead of using fixed size for the shader, add in the variant cache the size required, pass it to the context, and use this value. Signed-off-by: Axel Davy <davyaxel0@gmail.com>
This commit is contained in:
parent
a3cdc466e7
commit
9942ba2ea3
7 changed files with 52 additions and 23 deletions
|
|
@ -119,16 +119,21 @@ struct nine_shader_variant
|
|||
struct nine_shader_variant *next;
|
||||
void *cso;
|
||||
unsigned *const_ranges;
|
||||
unsigned const_used_size;
|
||||
uint64_t key;
|
||||
};
|
||||
|
||||
static inline void *
|
||||
nine_shader_variant_get(struct nine_shader_variant *list, unsigned **const_ranges, uint64_t key)
|
||||
nine_shader_variant_get(struct nine_shader_variant *list,
|
||||
unsigned **const_ranges,
|
||||
unsigned *const_used_size,
|
||||
uint64_t key)
|
||||
{
|
||||
while (list->key != key && list->next)
|
||||
list = list->next;
|
||||
if (list->key == key) {
|
||||
*const_ranges = list->const_ranges;
|
||||
*const_used_size = list->const_used_size;
|
||||
return list->cso;
|
||||
}
|
||||
return NULL;
|
||||
|
|
@ -136,7 +141,9 @@ nine_shader_variant_get(struct nine_shader_variant *list, unsigned **const_range
|
|||
|
||||
static inline boolean
|
||||
nine_shader_variant_add(struct nine_shader_variant *list,
|
||||
uint64_t key, void *cso, unsigned *const_ranges)
|
||||
uint64_t key, void *cso,
|
||||
unsigned *const_ranges,
|
||||
unsigned const_used_size)
|
||||
{
|
||||
while (list->next) {
|
||||
assert(list->key != key);
|
||||
|
|
@ -149,6 +156,7 @@ nine_shader_variant_add(struct nine_shader_variant *list,
|
|||
list->next->key = key;
|
||||
list->next->cso = cso;
|
||||
list->next->const_ranges = const_ranges;
|
||||
list->next->const_used_size = const_used_size;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -437,7 +437,7 @@ prepare_vs_constants_userbuf(struct NineDevice9 *device)
|
|||
struct pipe_constant_buffer cb;
|
||||
cb.buffer = NULL;
|
||||
cb.buffer_offset = 0;
|
||||
cb.buffer_size = context->vs->const_used_size;
|
||||
cb.buffer_size = context->cso_shader.vs_const_used_size;
|
||||
cb.user_buffer = context->vs_const_f;
|
||||
|
||||
if (context->swvp) {
|
||||
|
|
@ -518,7 +518,7 @@ prepare_ps_constants_userbuf(struct NineDevice9 *device)
|
|||
struct pipe_constant_buffer cb;
|
||||
cb.buffer = NULL;
|
||||
cb.buffer_offset = 0;
|
||||
cb.buffer_size = context->ps->const_used_size;
|
||||
cb.buffer_size = context->cso_shader.ps_const_used_size;
|
||||
cb.user_buffer = context->ps_const_f;
|
||||
|
||||
if (context->changed.ps_const_i) {
|
||||
|
|
@ -535,7 +535,7 @@ prepare_ps_constants_userbuf(struct NineDevice9 *device)
|
|||
|
||||
/* Upload special constants needed to implement PS1.x instructions like TEXBEM,TEXBEML and BEM */
|
||||
if (context->ps->bumpenvmat_needed) {
|
||||
memcpy(context->ps_lconstf_temp, cb.user_buffer, cb.buffer_size);
|
||||
memcpy(context->ps_lconstf_temp, cb.user_buffer, 8 * sizeof(float[4]));
|
||||
memcpy(&context->ps_lconstf_temp[4 * 8], &device->context.bumpmap_vars, sizeof(device->context.bumpmap_vars));
|
||||
|
||||
cb.user_buffer = context->ps_lconstf_temp;
|
||||
|
|
@ -545,7 +545,7 @@ prepare_ps_constants_userbuf(struct NineDevice9 *device)
|
|||
context->rs[D3DRS_FOGENABLE]) {
|
||||
float *dst = &context->ps_lconstf_temp[4 * 32];
|
||||
if (cb.user_buffer != context->ps_lconstf_temp) {
|
||||
memcpy(context->ps_lconstf_temp, cb.user_buffer, cb.buffer_size);
|
||||
memcpy(context->ps_lconstf_temp, cb.user_buffer, 32 * sizeof(float[4]));
|
||||
cb.user_buffer = context->ps_lconstf_temp;
|
||||
}
|
||||
|
||||
|
|
@ -556,7 +556,6 @@ prepare_ps_constants_userbuf(struct NineDevice9 *device)
|
|||
} else if (context->rs[D3DRS_FOGTABLEMODE] != D3DFOG_NONE) {
|
||||
dst[4] = asfloat(context->rs[D3DRS_FOGDENSITY]);
|
||||
}
|
||||
cb.buffer_size = 4 * 4 * 34;
|
||||
}
|
||||
|
||||
if (!cb.buffer_size)
|
||||
|
|
@ -603,7 +602,9 @@ prepare_vs(struct NineDevice9 *device, uint8_t shader_changed)
|
|||
|
||||
/* likely because we dislike FF */
|
||||
if (likely(context->programmable_vs)) {
|
||||
context->cso_shader.vs = NineVertexShader9_GetVariant(vs, &context->cso_shader.vs_const_ranges);
|
||||
context->cso_shader.vs = NineVertexShader9_GetVariant(vs,
|
||||
&context->cso_shader.vs_const_ranges,
|
||||
&context->cso_shader.vs_const_used_size);
|
||||
} else {
|
||||
vs = device->ff.vs;
|
||||
context->cso_shader.vs = vs->ff_cso;
|
||||
|
|
@ -637,7 +638,9 @@ prepare_ps(struct NineDevice9 *device, uint8_t shader_changed)
|
|||
return 0;
|
||||
|
||||
if (likely(ps)) {
|
||||
context->cso_shader.ps = NinePixelShader9_GetVariant(ps, &context->cso_shader.ps_const_ranges);
|
||||
context->cso_shader.ps = NinePixelShader9_GetVariant(ps,
|
||||
&context->cso_shader.ps_const_ranges,
|
||||
&context->cso_shader.ps_const_used_size);
|
||||
} else {
|
||||
ps = device->ff.ps;
|
||||
context->cso_shader.ps = ps->ff_cso;
|
||||
|
|
|
|||
|
|
@ -240,8 +240,10 @@ struct nine_context {
|
|||
struct {
|
||||
void *vs;
|
||||
unsigned *vs_const_ranges;
|
||||
unsigned vs_const_used_size;
|
||||
void *ps;
|
||||
unsigned *ps_const_ranges;
|
||||
unsigned ps_const_used_size;
|
||||
} cso_shader;
|
||||
|
||||
struct pipe_context *pipe;
|
||||
|
|
|
|||
|
|
@ -80,13 +80,14 @@ NinePixelShader9_ctor( struct NinePixelShader9 *This,
|
|||
|
||||
This->variant.cso = info.cso;
|
||||
This->variant.const_ranges = info.const_ranges;
|
||||
This->variant.const_used_size = info.const_used_size;
|
||||
This->last_cso = info.cso;
|
||||
This->last_const_ranges = info.const_ranges;
|
||||
This->last_const_used_size = info.const_used_size;
|
||||
This->last_key = 0;
|
||||
|
||||
This->sampler_mask = info.sampler_mask;
|
||||
This->rt_mask = info.rt_mask;
|
||||
This->const_used_size = info.const_used_size;
|
||||
This->bumpenvmat_needed = info.bumpenvmat_needed;
|
||||
|
||||
memcpy(This->int_slots_used, info.int_slots_used, sizeof(This->int_slots_used));
|
||||
|
|
@ -159,7 +160,9 @@ NinePixelShader9_GetFunction( struct NinePixelShader9 *This,
|
|||
}
|
||||
|
||||
void *
|
||||
NinePixelShader9_GetVariant( struct NinePixelShader9 *This, unsigned **const_ranges )
|
||||
NinePixelShader9_GetVariant( struct NinePixelShader9 *This,
|
||||
unsigned **const_ranges,
|
||||
unsigned *const_used_size )
|
||||
{
|
||||
/* GetVariant is called from nine_context, thus we can
|
||||
* get pipe directly */
|
||||
|
|
@ -170,10 +173,11 @@ NinePixelShader9_GetVariant( struct NinePixelShader9 *This, unsigned **const_ran
|
|||
key = This->next_key;
|
||||
if (key == This->last_key) {
|
||||
*const_ranges = This->last_const_ranges;
|
||||
*const_used_size = This->last_const_used_size;
|
||||
return This->last_cso;
|
||||
}
|
||||
|
||||
cso = nine_shader_variant_get(&This->variant, const_ranges, key);
|
||||
cso = nine_shader_variant_get(&This->variant, const_ranges, const_used_size, key);
|
||||
if (!cso) {
|
||||
struct NineDevice9 *device = This->base.device;
|
||||
struct nine_shader_info info;
|
||||
|
|
@ -210,14 +214,17 @@ NinePixelShader9_GetVariant( struct NinePixelShader9 *This, unsigned **const_ran
|
|||
hr = nine_translate_shader(This->base.device, &info, pipe);
|
||||
if (FAILED(hr))
|
||||
return NULL;
|
||||
nine_shader_variant_add(&This->variant, key, info.cso, info.const_ranges);
|
||||
nine_shader_variant_add(&This->variant, key, info.cso,
|
||||
info.const_ranges, info.const_used_size);
|
||||
cso = info.cso;
|
||||
*const_ranges = info.const_ranges;
|
||||
*const_used_size = info.const_used_size;
|
||||
}
|
||||
|
||||
This->last_key = key;
|
||||
This->last_cso = cso;
|
||||
This->last_const_ranges = *const_ranges;
|
||||
This->last_const_used_size = *const_used_size;
|
||||
|
||||
return cso;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,8 +43,6 @@ struct NinePixelShader9
|
|||
uint8_t version; /* (major << 4) | minor */
|
||||
} byte_code;
|
||||
|
||||
unsigned const_used_size; /* in bytes */
|
||||
|
||||
uint8_t bumpenvmat_needed;
|
||||
uint16_t sampler_mask;
|
||||
uint8_t rt_mask;
|
||||
|
|
@ -63,6 +61,7 @@ struct NinePixelShader9
|
|||
uint64_t last_key;
|
||||
void *last_cso;
|
||||
unsigned *last_const_ranges;
|
||||
unsigned last_const_used_size; /* in bytes */
|
||||
|
||||
uint64_t next_key;
|
||||
};
|
||||
|
|
@ -132,7 +131,9 @@ NinePixelShader9_UpdateKey( struct NinePixelShader9 *ps,
|
|||
}
|
||||
|
||||
void *
|
||||
NinePixelShader9_GetVariant( struct NinePixelShader9 *ps, unsigned **const_ranges );
|
||||
NinePixelShader9_GetVariant( struct NinePixelShader9 *ps,
|
||||
unsigned **const_ranges,
|
||||
unsigned *const_used_size );
|
||||
|
||||
/*** public ***/
|
||||
|
||||
|
|
|
|||
|
|
@ -95,11 +95,12 @@ NineVertexShader9_ctor( struct NineVertexShader9 *This,
|
|||
|
||||
This->variant.cso = info.cso;
|
||||
This->variant.const_ranges = info.const_ranges;
|
||||
This->variant.const_used_size = info.const_used_size;
|
||||
This->last_cso = info.cso;
|
||||
This->last_const_ranges = info.const_ranges;
|
||||
This->last_const_used_size = info.const_used_size;
|
||||
This->last_key = (uint32_t) (info.swvp_on << 9);
|
||||
|
||||
This->const_used_size = info.const_used_size;
|
||||
This->lconstf = info.lconstf;
|
||||
This->sampler_mask = info.sampler_mask;
|
||||
This->position_t = info.position_t;
|
||||
|
|
@ -185,7 +186,9 @@ NineVertexShader9_GetFunction( struct NineVertexShader9 *This,
|
|||
}
|
||||
|
||||
void *
|
||||
NineVertexShader9_GetVariant( struct NineVertexShader9 *This, unsigned **const_ranges )
|
||||
NineVertexShader9_GetVariant( struct NineVertexShader9 *This,
|
||||
unsigned **const_ranges,
|
||||
unsigned *const_used_size )
|
||||
{
|
||||
/* GetVariant is called from nine_context, thus we can
|
||||
* get pipe directly */
|
||||
|
|
@ -196,10 +199,11 @@ NineVertexShader9_GetVariant( struct NineVertexShader9 *This, unsigned **const_r
|
|||
key = This->next_key;
|
||||
if (key == This->last_key) {
|
||||
*const_ranges = This->last_const_ranges;
|
||||
*const_used_size = This->last_const_used_size;
|
||||
return This->last_cso;
|
||||
}
|
||||
|
||||
cso = nine_shader_variant_get(&This->variant, const_ranges, key);
|
||||
cso = nine_shader_variant_get(&This->variant, const_ranges, const_used_size, key);
|
||||
if (!cso) {
|
||||
struct NineDevice9 *device = This->base.device;
|
||||
struct nine_shader_info info;
|
||||
|
|
@ -223,14 +227,17 @@ NineVertexShader9_GetVariant( struct NineVertexShader9 *This, unsigned **const_r
|
|||
hr = nine_translate_shader(This->base.device, &info, pipe);
|
||||
if (FAILED(hr))
|
||||
return NULL;
|
||||
nine_shader_variant_add(&This->variant, key, info.cso, info.const_ranges);
|
||||
nine_shader_variant_add(&This->variant, key, info.cso,
|
||||
info.const_ranges, info.const_used_size);
|
||||
cso = info.cso;
|
||||
*const_ranges = info.const_ranges;
|
||||
*const_used_size = info.const_used_size;
|
||||
}
|
||||
|
||||
This->last_key = key;
|
||||
This->last_cso = cso;
|
||||
This->last_const_ranges = *const_ranges;
|
||||
This->last_const_used_size = *const_used_size;
|
||||
|
||||
return cso;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,8 +55,6 @@ struct NineVertexShader9
|
|||
boolean point_size; /* if true, set rasterizer.point_size_per_vertex to 1 */
|
||||
boolean swvp_only;
|
||||
|
||||
unsigned const_used_size; /* in bytes */
|
||||
|
||||
struct nine_lconstf lconstf;
|
||||
|
||||
boolean int_slots_used[NINE_MAX_CONST_I];
|
||||
|
|
@ -73,6 +71,7 @@ struct NineVertexShader9
|
|||
uint64_t last_key;
|
||||
void *last_cso;
|
||||
unsigned *last_const_ranges;
|
||||
unsigned last_const_used_size; /* in bytes */
|
||||
|
||||
uint64_t next_key;
|
||||
|
||||
|
|
@ -124,7 +123,9 @@ NineVertexShader9_UpdateKey( struct NineVertexShader9 *vs,
|
|||
}
|
||||
|
||||
void *
|
||||
NineVertexShader9_GetVariant( struct NineVertexShader9 *vs, unsigned **const_ranges );
|
||||
NineVertexShader9_GetVariant( struct NineVertexShader9 *vs,
|
||||
unsigned **const_ranges,
|
||||
unsigned *const_used_size );
|
||||
|
||||
void *
|
||||
NineVertexShader9_GetVariantProcessVertices( struct NineVertexShader9 *vs,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue