[Mesa-dev] [PATCH] r600, compute: setup compute sampler states and views
Marek Olšák
maraeo at gmail.com
Tue Aug 11 12:54:54 PDT 2015
On Mon, Aug 10, 2015 at 8:30 PM, Zoltan Gilian <zoltan.gilian at gmail.com> wrote:
> ---
> src/gallium/drivers/r600/evergreen_compute.c | 25 ++++++----------------
> src/gallium/drivers/r600/evergreen_state.c | 30 ++++++++++++++++++++------
> src/gallium/drivers/r600/evergreend.h | 5 +++++
> src/gallium/drivers/r600/r600_pipe.h | 7 +-----
> src/gallium/drivers/r600/r600_state_common.c | 32 ++++++++++++++++++++++------
> 5 files changed, 60 insertions(+), 39 deletions(-)
>
> diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c
> index d71eeb9..e886847 100644
> --- a/src/gallium/drivers/r600/evergreen_compute.c
> +++ b/src/gallium/drivers/r600/evergreen_compute.c
> @@ -504,6 +504,12 @@ static void compute_emit_cs(struct r600_context *ctx, const uint *block_layout,
> /* Emit constant buffer state */
> r600_emit_atom(ctx, &ctx->constbuf_state[PIPE_SHADER_COMPUTE].atom);
>
> + /* Emit sampler state */
> + r600_emit_atom(ctx, &ctx->samplers[PIPE_SHADER_COMPUTE].states.atom);
> +
> + /* Emit sampler view (texture resource) state */
> + r600_emit_atom(ctx, &ctx->samplers[PIPE_SHADER_COMPUTE].views.atom);
> +
> /* Emit compute shader state */
> r600_emit_atom(ctx, &ctx->cs_shader_state.atom);
>
> @@ -674,25 +680,6 @@ static void evergreen_set_compute_resources(struct pipe_context * ctx_,
> }
> }
>
> -void evergreen_set_cs_sampler_view(struct pipe_context *ctx_,
> - unsigned start_slot, unsigned count,
> - struct pipe_sampler_view **views)
> -{
> - struct r600_pipe_sampler_view **resource =
> - (struct r600_pipe_sampler_view **)views;
> -
> - for (unsigned i = 0; i < count; i++) {
> - if (resource[i]) {
> - assert(i+1 < 12);
> - /* XXX: Implement */
> - assert(!"Compute samplers not implemented.");
> - ///FETCH0 = VTX0 (param buffer),
> - //FETCH1 = VTX1 (global buffer pool), FETCH2... = TEX
> - }
> - }
> -}
> -
> -
> static void evergreen_set_global_binding(
> struct pipe_context *ctx_, unsigned first, unsigned n,
> struct pipe_resource **resources,
> diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c
> index 688a092..5f68e08 100644
> --- a/src/gallium/drivers/r600/evergreen_state.c
> +++ b/src/gallium/drivers/r600/evergreen_state.c
> @@ -2029,7 +2029,7 @@ static void evergreen_emit_cs_constant_buffers(struct r600_context *rctx, struct
>
> static void evergreen_emit_sampler_views(struct r600_context *rctx,
> struct r600_samplerview_state *state,
> - unsigned resource_id_base)
> + unsigned resource_id_base, unsigned pkt_flags)
> {
> struct radeon_winsys_cs *cs = rctx->b.rings.gfx.cs;
> uint32_t dirty_mask = state->dirty_mask;
> @@ -2042,7 +2042,7 @@ static void evergreen_emit_sampler_views(struct r600_context *rctx,
> rview = state->views[resource_index];
> assert(rview);
>
> - radeon_emit(cs, PKT3(PKT3_SET_RESOURCE, 8, 0));
> + radeon_emit(cs, PKT3(PKT3_SET_RESOURCE, 8, 0) | pkt_flags);
> radeon_emit(cs, (resource_id_base + resource_index) * 8);
> radeon_emit_array(cs, rview->tex_resource_words, 8);
>
> @@ -2051,11 +2051,11 @@ static void evergreen_emit_sampler_views(struct r600_context *rctx,
> rview->tex_resource->b.b.nr_samples > 1 ?
> RADEON_PRIO_SHADER_TEXTURE_MSAA :
> RADEON_PRIO_SHADER_TEXTURE_RO);
> - radeon_emit(cs, PKT3(PKT3_NOP, 0, 0));
> + radeon_emit(cs, PKT3(PKT3_NOP, 0, 0) | pkt_flags);
> radeon_emit(cs, reloc);
>
> if (!rview->skip_mip_address_reloc) {
> - radeon_emit(cs, PKT3(PKT3_NOP, 0, 0));
> + radeon_emit(cs, PKT3(PKT3_NOP, 0, 0) | pkt_flags);
> radeon_emit(cs, reloc);
> }
> }
> @@ -2064,17 +2064,26 @@ static void evergreen_emit_sampler_views(struct r600_context *rctx,
>
> static void evergreen_emit_vs_sampler_views(struct r600_context *rctx, struct r600_atom *atom)
> {
> - evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].views, 176 + R600_MAX_CONST_BUFFERS);
> + evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].views,
> + 176 + R600_MAX_CONST_BUFFERS, 0);
> }
>
> static void evergreen_emit_gs_sampler_views(struct r600_context *rctx, struct r600_atom *atom)
> {
> - evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_GEOMETRY].views, 336 + R600_MAX_CONST_BUFFERS);
> + evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_GEOMETRY].views,
> + 336 + R600_MAX_CONST_BUFFERS, 0);
> }
>
> static void evergreen_emit_ps_sampler_views(struct r600_context *rctx, struct r600_atom *atom)
> {
> - evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].views, R600_MAX_CONST_BUFFERS);
> + evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].views,
> + R600_MAX_CONST_BUFFERS, 0);
> +}
> +
> +static void evergreen_emit_cs_sampler_views(struct r600_context *rctx, struct r600_atom *atom)
> +{
> + evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_COMPUTE].views,
> + 816 + 2, RADEON_CP_PACKET3_COMPUTE_MODE);
> }
>
> static void evergreen_emit_sampler_states(struct r600_context *rctx,
> @@ -2120,6 +2129,11 @@ static void evergreen_emit_ps_sampler_states(struct r600_context *rctx, struct r
> evergreen_emit_sampler_states(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT], 0, R_00A400_TD_PS_SAMPLER0_BORDER_INDEX);
> }
>
> +static void evergreen_emit_cs_sampler_states(struct r600_context *rctx, struct r600_atom *atom)
> +{
> + evergreen_emit_sampler_states(rctx, &rctx->samplers[PIPE_SHADER_COMPUTE], 90, R_00A464_TD_CS_SAMPLER0_BORDER_INDEX);
> +}
Do compute sampler states need RADEON_CP_PACKET3_COMPUTE_MODE as well?
> +
> static void evergreen_emit_sample_mask(struct r600_context *rctx, struct r600_atom *a)
> {
> struct r600_sample_mask *s = (struct r600_sample_mask*)a;
> @@ -3480,12 +3494,14 @@ void evergreen_init_state_functions(struct r600_context *rctx)
> r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].states.atom, id++, evergreen_emit_vs_sampler_states, 0);
> r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_GEOMETRY].states.atom, id++, evergreen_emit_gs_sampler_states, 0);
> r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].states.atom, id++, evergreen_emit_ps_sampler_states, 0);
> + r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_COMPUTE].states.atom, id++, evergreen_emit_cs_sampler_states, 0);
> /* resources */
> r600_init_atom(rctx, &rctx->vertex_buffer_state.atom, id++, evergreen_fs_emit_vertex_buffers, 0);
> r600_init_atom(rctx, &rctx->cs_vertex_buffer_state.atom, id++, evergreen_cs_emit_vertex_buffers, 0);
> r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].views.atom, id++, evergreen_emit_vs_sampler_views, 0);
> r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_GEOMETRY].views.atom, id++, evergreen_emit_gs_sampler_views, 0);
> r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].views.atom, id++, evergreen_emit_ps_sampler_views, 0);
> + r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_COMPUTE].views.atom, id++, evergreen_emit_cs_sampler_views, 0);
>
> r600_init_atom(rctx, &rctx->vgt_state.atom, id++, r600_emit_vgt_state, 10);
>
> diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h
> index cd4ff46..ad6ad43 100644
> --- a/src/gallium/drivers/r600/evergreend.h
> +++ b/src/gallium/drivers/r600/evergreend.h
> @@ -1253,6 +1253,11 @@
> #define R_00A430_TD_GS_SAMPLER0_BORDER_GREEN 0x00A430
> #define R_00A434_TD_GS_SAMPLER0_BORDER_BLUE 0x00A434
> #define R_00A438_TD_GS_SAMPLER0_BORDER_ALPHA 0x00A438
> +#define R_00A464_TD_CS_SAMPLER0_BORDER_INDEX 0x00A464
> +#define R_00A468_TD_CS_SAMPLER0_BORDER_RED 0x00A468
> +#define R_00A46C_TD_CS_SAMPLER0_BORDER_GREEN 0x00A46C
> +#define R_00A470_TD_CS_SAMPLER0_BORDER_BLUE 0x00A470
> +#define R_00A474_TD_CS_SAMPLER0_BORDER_ALPHA 0x00A474
>
> #define R_03C000_SQ_TEX_SAMPLER_WORD0_0 0x03C000
> #define S_03C000_CLAMP_X(x) (((x) & 0x7) << 0)
> diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
> index 84c921a..1fc3242 100644
> --- a/src/gallium/drivers/r600/r600_pipe.h
> +++ b/src/gallium/drivers/r600/r600_pipe.h
> @@ -36,7 +36,7 @@
> #include "util/list.h"
> #include "util/u_transfer.h"
>
> -#define R600_NUM_ATOMS 73
> +#define R600_NUM_ATOMS 75
>
> #define R600_MAX_VIEWPORTS 16
>
> @@ -529,11 +529,6 @@ void compute_memory_pool_delete(struct compute_memory_pool* pool);
> struct compute_memory_pool* compute_memory_pool_new(
> struct r600_screen *rscreen);
>
> -/* evergreen_compute.c */
> -void evergreen_set_cs_sampler_view(struct pipe_context *ctx_,
> - unsigned start_slot, unsigned count,
> - struct pipe_sampler_view **views);
> -
> /* evergreen_state.c */
> struct pipe_sampler_view *
> evergreen_create_sampler_view_custom(struct pipe_context *ctx,
> diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
> index 455e59a..f0f1af6 100644
> --- a/src/gallium/drivers/r600/r600_state_common.c
> +++ b/src/gallium/drivers/r600/r600_state_common.c
> @@ -400,10 +400,16 @@ static void r600_bind_sampler_states(struct pipe_context *pipe,
> assert(start == 0); /* XXX fix below */
>
> if (shader != PIPE_SHADER_VERTEX &&
> - shader != PIPE_SHADER_FRAGMENT) {
> + shader != PIPE_SHADER_FRAGMENT &&
> + shader != PIPE_SHADER_COMPUTE) {
> return;
> }
Nice one. You've just helped me discover a geometry shader bug right
here. I'll send a separate patch removing this conditional completely.
>
> + if (shader == PIPE_SHADER_COMPUTE && !states) {
This can just be: if (!states) {
> + disable_mask = ~0u;
> + count = 0;
> + }
> +
> for (i = 0; i < count; i++) {
> struct r600_pipe_sampler_state *rstate = rstates[i];
>
> @@ -593,9 +599,9 @@ static void r600_set_sampler_views(struct pipe_context *pipe, unsigned shader,
>
> assert(start == 0); /* XXX fix below */
>
> - if (shader == PIPE_SHADER_COMPUTE) {
> - evergreen_set_cs_sampler_view(pipe, start, count, views);
> - return;
> + if (shader == PIPE_SHADER_COMPUTE && !views) {
Same as above: if (!views) {
> + disable_mask = ~0u;
> + count = 0;
> }
>
> remaining_mask = dst->views.enabled_mask & disable_mask;
> @@ -604,7 +610,11 @@ static void r600_set_sampler_views(struct pipe_context *pipe, unsigned shader,
All changes below should be dropped. All sampler views should be
referenced here (= increase their refcount). Is there any reason not
to reference them?
> i = u_bit_scan(&remaining_mask);
> assert(dst->views.views[i]);
>
> - pipe_sampler_view_reference((struct pipe_sampler_view **)&dst->views.views[i], NULL);
> + if (shader == PIPE_SHADER_COMPUTE) {
> + dst->views.views[i] = NULL;
> + } else {
> + pipe_sampler_view_reference((struct pipe_sampler_view **)&dst->views.views[i], NULL);
> + }
> }
>
> for (i = 0; i < count; i++) {
> @@ -639,11 +649,19 @@ static void r600_set_sampler_views(struct pipe_context *pipe, unsigned shader,
> dirty_sampler_states_mask |= 1 << i;
> }
>
> - pipe_sampler_view_reference((struct pipe_sampler_view **)&dst->views.views[i], views[i]);
> + if (shader == PIPE_SHADER_COMPUTE) {
> + dst->views.views[i] = rviews[i];
> + } else {
> + pipe_sampler_view_reference((struct pipe_sampler_view **)&dst->views.views[i], views[i]);
> + }
> new_mask |= 1 << i;
> r600_context_add_resource_size(pipe, views[i]->texture);
> } else {
> - pipe_sampler_view_reference((struct pipe_sampler_view **)&dst->views.views[i], NULL);
> + if (shader == PIPE_SHADER_COMPUTE) {
> + dst->views.views[i] = NULL;
> + } else {
> + pipe_sampler_view_reference((struct pipe_sampler_view **)&dst->views.views[i], NULL);
> + }
Marek
More information about the mesa-dev
mailing list