[Mesa-dev] [PATCH 02/43] st/nine: Refactor how user constbufs sizes are calculated
Ilia Mirkin
imirkin at alum.mit.edu
Sat Jan 31 10:16:12 PST 2015
On Fri, Jan 30, 2015 at 3:34 PM, Axel Davy <axel.davy at ens.fr> wrote:
> Count explicitly the slots for float, int and bool constants,
> and deduce the constbuf size in nine_shader.
>
> Signed-off-by: Axel Davy <axel.davy at ens.fr>
> ---
> src/gallium/state_trackers/nine/nine_shader.c | 17 ++++++++++++++---
> src/gallium/state_trackers/nine/nine_shader.h | 22 ++++++++++------------
> src/gallium/state_trackers/nine/nine_state.h | 5 -----
> src/gallium/state_trackers/nine/pixelshader9.c | 1 -
> src/gallium/state_trackers/nine/vertexshader9.c | 2 --
> 5 files changed, 24 insertions(+), 23 deletions(-)
>
> diff --git a/src/gallium/state_trackers/nine/nine_shader.c b/src/gallium/state_trackers/nine/nine_shader.c
> index 944b646..1984087 100644
> --- a/src/gallium/state_trackers/nine/nine_shader.c
> +++ b/src/gallium/state_trackers/nine/nine_shader.c
> @@ -2995,7 +2995,9 @@ tx_ctor(struct shader_translator *tx, struct nine_shader_info *info)
> info->position_t = FALSE;
> info->point_size = FALSE;
>
> - tx->info->const_used_size = 0;
> + tx->info->num_float_consts_slots = 0;
> + tx->info->num_int_consts_slots = 0;
> + tx->info->num_bool_consts_slots = 0;
>
> info->sampler_mask = 0x0;
> info->rt_mask = 0x0;
> @@ -3065,6 +3067,7 @@ nine_translate_shader(struct NineDevice9 *device, struct nine_shader_info *info)
> struct shader_translator *tx;
> HRESULT hr = D3D_OK;
> const unsigned processor = tgsi_processor_from_type(info->type);
> + unsigned slot_max;
>
> user_assert(processor != ~0, D3DERR_INVALIDCALL);
>
> @@ -3196,8 +3199,16 @@ nine_translate_shader(struct NineDevice9 *device, struct nine_shader_info *info)
> hr = D3D_OK;
> }
>
> - if (tx->indirect_const_access)
> - info->const_used_size = ~0;
> + if (tx->indirect_const_access) /* vs only */
> + info->num_float_consts_slots = device->max_vs_const_f;
> +
> + slot_max = info->num_bool_consts_slots > 0 ?
> + device->max_vs_const_f + NINE_MAX_CONST_I
> + + info->num_bool_consts_slots :
> + info->num_int_consts_slots > 0 ?
> + device->max_vs_const_f + info->num_int_consts_slots :
> + info->num_float_consts_slots;
Please use an if ladder, no reason to make it so difficult to read.
> + info->const_used_size = sizeof(float[4]) * slot_max; /* slots start from 1 */
>
> info->cso = ureg_create_shader_and_destroy(tx->ureg, device->pipe);
> if (!info->cso) {
> diff --git a/src/gallium/state_trackers/nine/nine_shader.h b/src/gallium/state_trackers/nine/nine_shader.h
> index ddee372..027f765 100644
> --- a/src/gallium/state_trackers/nine/nine_shader.h
> +++ b/src/gallium/state_trackers/nine/nine_shader.h
> @@ -63,32 +63,30 @@ struct nine_shader_info
> unsigned const_b_base; /* in vec4 (16 byte) units */
> unsigned const_used_size;
>
> + unsigned num_float_consts_slots;
> + unsigned num_int_consts_slots;
> + unsigned num_bool_consts_slots;
You're more familiar with this code, but these names seem jarring
relative to the other stuff... why not
const_float_slots
const_int_slots
etc
Actually these are regarding the *used* slots right? So then it should be
const_float_used
const_int_used
etc?
> +
> struct nine_lconstf lconstf; /* out, NOTE: members to be free'd by user */
> };
>
> static INLINE void
> nine_info_mark_const_f_used(struct nine_shader_info *info, int idx)
> {
> - unsigned size = (idx + 1) * 16;
> -
> - if (info->const_used_size < size)
> - info->const_used_size = size;
> + if (info->num_float_consts_slots < (idx + 1))
> + info->num_float_consts_slots = idx + 1;
> }
> static INLINE void
> nine_info_mark_const_i_used(struct nine_shader_info *info, int idx)
> {
> - unsigned size = (info->const_i_base + (idx + 1)) * 16;
> -
> - if (info->const_used_size < size)
> - info->const_used_size = size;
> + if (info->num_int_consts_slots < (idx + 1))
> + info->num_int_consts_slots = idx + 1;
> }
> static INLINE void
> nine_info_mark_const_b_used(struct nine_shader_info *info, int idx)
> {
> - unsigned size = (info->const_b_base + ((idx + 4) / 4)) * 16;
> -
> - if (info->const_used_size < size)
> - info->const_used_size = size;
> + if (info->num_bool_consts_slots < (idx + 1))
> + info->num_bool_consts_slots = idx + 1;
> }
>
> HRESULT
> diff --git a/src/gallium/state_trackers/nine/nine_state.h b/src/gallium/state_trackers/nine/nine_state.h
> index 58ca8c9..927bfe1 100644
> --- a/src/gallium/state_trackers/nine/nine_state.h
> +++ b/src/gallium/state_trackers/nine/nine_state.h
> @@ -91,11 +91,6 @@
> ((nconstf) * 4 * sizeof(float) + \
> NINE_MAX_CONST_I * 4 * sizeof(int))
>
> -#define NINE_CONSTBUF_SIZE(nconstf) \
> - ((nconstf) * 4 * sizeof(float) + \
> - NINE_MAX_CONST_I * 4 * sizeof(int) + \
> - NINE_MAX_CONST_B * 1 * sizeof(float))
> -
>
> #define NINE_MAX_LIGHTS 65536
> #define NINE_MAX_LIGHTS_ACTIVE 8
> diff --git a/src/gallium/state_trackers/nine/pixelshader9.c b/src/gallium/state_trackers/nine/pixelshader9.c
> index dcd2346..3f176a3 100644
> --- a/src/gallium/state_trackers/nine/pixelshader9.c
> +++ b/src/gallium/state_trackers/nine/pixelshader9.c
> @@ -73,7 +73,6 @@ NinePixelShader9_ctor( struct NinePixelShader9 *This,
> This->rt_mask = info.rt_mask;
> This->const_used_size = info.const_used_size;
> /* no constant relative addressing for ps */
> - assert(info.const_used_size != ~0);
> assert(info.lconstf.data == NULL);
> assert(info.lconstf.ranges == NULL);
>
> diff --git a/src/gallium/state_trackers/nine/vertexshader9.c b/src/gallium/state_trackers/nine/vertexshader9.c
> index 3d40d60..bbd5ce9 100644
> --- a/src/gallium/state_trackers/nine/vertexshader9.c
> +++ b/src/gallium/state_trackers/nine/vertexshader9.c
> @@ -72,8 +72,6 @@ NineVertexShader9_ctor( struct NineVertexShader9 *This,
>
> This->variant.cso = info.cso;
> This->const_used_size = info.const_used_size;
> - if (info.const_used_size == ~0)
> - This->const_used_size = NINE_CONSTBUF_SIZE(device->max_vs_const_f);
> This->lconstf = info.lconstf;
> This->sampler_mask = info.sampler_mask;
> This->position_t = info.position_t;
> --
> 2.1.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list