v3d: Make an array for frag/vert texture state in the context.
authorEric Anholt <eric@anholt.net>
Tue, 4 Dec 2018 21:48:10 +0000 (13:48 -0800)
committerEric Anholt <eric@anholt.net>
Sat, 8 Dec 2018 00:48:23 +0000 (16:48 -0800)
This simplifies a bunch of our texture handling, while introducing the
slots necessary for adding new shader stages.

src/gallium/drivers/v3d/v3d_blit.c
src/gallium/drivers/v3d/v3d_context.h
src/gallium/drivers/v3d/v3d_program.c
src/gallium/drivers/v3d/v3d_uniforms.c
src/gallium/drivers/v3d/v3dx_draw.c
src/gallium/drivers/v3d/v3dx_emit.c
src/gallium/drivers/v3d/v3dx_state.c

index f2ded8bbf72db33b49bfa7776a293522ee3fb34a..25f4c61c62d108300e578825c44487bfac126468 100644 (file)
@@ -184,10 +184,11 @@ v3d_blitter_save(struct v3d_context *v3d)
         util_blitter_save_sample_mask(v3d->blitter, v3d->sample_mask);
         util_blitter_save_framebuffer(v3d->blitter, &v3d->framebuffer);
         util_blitter_save_fragment_sampler_states(v3d->blitter,
-                        v3d->fragtex.num_samplers,
-                        (void **)v3d->fragtex.samplers);
+                        v3d->tex[PIPE_SHADER_FRAGMENT].num_samplers,
+                        (void **)v3d->tex[PIPE_SHADER_FRAGMENT].samplers);
         util_blitter_save_fragment_sampler_views(v3d->blitter,
-                        v3d->fragtex.num_textures, v3d->fragtex.textures);
+                        v3d->tex[PIPE_SHADER_FRAGMENT].num_textures,
+                        v3d->tex[PIPE_SHADER_FRAGMENT].textures);
         util_blitter_save_so_targets(v3d->blitter, v3d->streamout.num_targets,
                                      v3d->streamout.targets);
 }
index 6ffe09a9c1a16411014db995b6a40ca4130bb1c0..d62dd229ef270379000570210e86e95a25b0f3ea 100644 (file)
@@ -386,8 +386,6 @@ struct v3d_context {
         struct v3d_rasterizer_state *rasterizer;
         struct v3d_depth_stencil_alpha_state *zsa;
 
-        struct v3d_texture_stateobj verttex, fragtex;
-
         struct v3d_program_stateobj prog;
 
         struct v3d_vertex_stateobj *vtx;
@@ -424,6 +422,7 @@ struct v3d_context {
         struct pipe_clip_state clip;
         struct pipe_viewport_state viewport;
         struct v3d_constbuf_stateobj constbuf[PIPE_SHADER_TYPES];
+        struct v3d_texture_stateobj tex[PIPE_SHADER_TYPES];
         struct v3d_vertexbuf_stateobj vertexbuf;
         struct v3d_streamout_stateobj streamout;
         struct v3d_bo *current_oq;
@@ -501,8 +500,7 @@ v3d_ioctl(int fd, unsigned long request, void *arg)
 void v3d_set_shader_uniform_dirty_flags(struct v3d_compiled_shader *shader);
 struct v3d_cl_reloc v3d_write_uniforms(struct v3d_context *v3d,
                                        struct v3d_compiled_shader *shader,
-                                       struct v3d_constbuf_stateobj *cb,
-                                       struct v3d_texture_stateobj *texstate);
+                                       enum pipe_shader_type stage);
 
 void v3d_flush(struct pipe_context *pctx);
 void v3d_job_init(struct v3d_context *v3d);
index 25b346fd11b1e678950b174335fd8c8fba8c6481..6c9d5c461ab84221090c9fca640b98d6a17e802f 100644 (file)
@@ -419,7 +419,7 @@ v3d_update_compiled_fs(struct v3d_context *v3d, uint8_t prim_mode)
         }
 
         memset(key, 0, sizeof(*key));
-        v3d_setup_shared_key(v3d, &key->base, &v3d->fragtex);
+        v3d_setup_shared_key(v3d, &key->base, &v3d->tex[PIPE_SHADER_FRAGMENT]);
         key->base.shader_state = v3d->prog.bind_fs;
         key->is_points = (prim_mode == PIPE_PRIM_POINTS);
         key->is_lines = (prim_mode >= PIPE_PRIM_LINES &&
@@ -530,7 +530,7 @@ v3d_update_compiled_vs(struct v3d_context *v3d, uint8_t prim_mode)
         }
 
         memset(key, 0, sizeof(*key));
-        v3d_setup_shared_key(v3d, &key->base, &v3d->verttex);
+        v3d_setup_shared_key(v3d, &key->base, &v3d->tex[PIPE_SHADER_VERTEX]);
         key->base.shader_state = v3d->prog.bind_vs;
         key->num_fs_inputs = v3d->prog.fs->prog_data.fs->base.num_inputs;
         STATIC_ASSERT(sizeof(key->fs_inputs) ==
index 6f0ef9155353a4adb095556b67c8a91bac47f6d3..d2e3e710237be6eb18480d6f93bba84220faec6c 100644 (file)
@@ -259,9 +259,10 @@ write_tmu_p1(struct v3d_job *job,
 
 struct v3d_cl_reloc
 v3d_write_uniforms(struct v3d_context *v3d, struct v3d_compiled_shader *shader,
-                   struct v3d_constbuf_stateobj *cb,
-                   struct v3d_texture_stateobj *texstate)
+                   enum pipe_shader_type stage)
 {
+        struct v3d_constbuf_stateobj *cb = &v3d->constbuf[stage];
+        struct v3d_texture_stateobj *texstate = &v3d->tex[stage];
         struct v3d_uniform_list *uinfo = &shader->prog_data.base->uniforms;
         struct v3d_job *job = v3d->job;
         const uint32_t *gallium_uniforms = cb->cb[0].user_buffer;
index 051907f1250261e976c5887ebc19e4aa3a22585d..519aa9157d5718fdc2a6648de604704790d69268 100644 (file)
@@ -146,16 +146,13 @@ v3d_emit_gl_shader_state(struct v3d_context *v3d,
         /* Upload the uniforms to the indirect CL first */
         struct v3d_cl_reloc fs_uniforms =
                 v3d_write_uniforms(v3d, v3d->prog.fs,
-                                   &v3d->constbuf[PIPE_SHADER_FRAGMENT],
-                                   &v3d->fragtex);
+                                   PIPE_SHADER_FRAGMENT);
         struct v3d_cl_reloc vs_uniforms =
                 v3d_write_uniforms(v3d, v3d->prog.vs,
-                                   &v3d->constbuf[PIPE_SHADER_VERTEX],
-                                   &v3d->verttex);
+                                   PIPE_SHADER_VERTEX);
         struct v3d_cl_reloc cs_uniforms =
                 v3d_write_uniforms(v3d, v3d->prog.cs,
-                                   &v3d->constbuf[PIPE_SHADER_VERTEX],
-                                   &v3d->verttex);
+                                   PIPE_SHADER_VERTEX);
 
         /* See GFXH-930 workaround below */
         uint32_t num_elements_to_emit = MAX2(vtx->num_elements, 1);
@@ -438,8 +435,8 @@ v3d_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
         /* Before setting up the draw, flush anything writing to the textures
          * that we read from.
          */
-        v3d_predraw_check_textures(pctx, &v3d->verttex);
-        v3d_predraw_check_textures(pctx, &v3d->fragtex);
+        for (int s = 0; s < PIPE_SHADER_TYPES; s++)
+                v3d_predraw_check_textures(pctx, &v3d->tex[s]);
 
         struct v3d_job *job = v3d_get_job_for_fbo(v3d);
 
@@ -451,7 +448,7 @@ v3d_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
          * on the last submitted render, rather than tracking the last
          * rendering to each texture's BO.
          */
-        if (v3d->verttex.num_textures) {
+        if (v3d->tex[PIPE_SHADER_VERTEX].num_textures) {
                 perf_debug("Blocking binner on last render "
                            "due to vertex texturing.\n");
                 job->submit.in_sync_bcl = v3d->out_sync;
index 0d14bcf4ddedd7e807e7e16a8ae53f780eb2c51b..adaf5f6c1394b3d1930a44cc9b85d8f816d71d5f 100644 (file)
@@ -653,10 +653,10 @@ v3dX(emit_state)(struct pipe_context *pctx)
          * the view, so we merge them together at draw time.
          */
         if (v3d->dirty & VC5_DIRTY_FRAGTEX)
-                emit_textures(v3d, &v3d->fragtex);
+                emit_textures(v3d, &v3d->tex[PIPE_SHADER_FRAGMENT]);
 
         if (v3d->dirty & VC5_DIRTY_VERTTEX)
-                emit_textures(v3d, &v3d->verttex);
+                emit_textures(v3d, &v3d->tex[PIPE_SHADER_VERTEX]);
 #endif
 
         if (v3d->dirty & VC5_DIRTY_FLAT_SHADE_FLAGS) {
index 75c81f099ddd87042b8a34e0718addbd5f866236..0d1a74091d5bcfd2376bf7080092e390d7917c7d 100644 (file)
@@ -502,24 +502,6 @@ v3d_set_framebuffer_state(struct pipe_context *pctx,
         v3d->dirty |= VC5_DIRTY_FRAMEBUFFER;
 }
 
-static struct v3d_texture_stateobj *
-v3d_get_stage_tex(struct v3d_context *v3d, enum pipe_shader_type shader)
-{
-        switch (shader) {
-        case PIPE_SHADER_FRAGMENT:
-                v3d->dirty |= VC5_DIRTY_FRAGTEX;
-                return &v3d->fragtex;
-                break;
-        case PIPE_SHADER_VERTEX:
-                v3d->dirty |= VC5_DIRTY_VERTTEX;
-                return &v3d->verttex;
-                break;
-        default:
-                fprintf(stderr, "Unknown shader target %d\n", shader);
-                abort();
-        }
-}
-
 static uint32_t translate_wrap(uint32_t pipe_wrap, bool using_nearest)
 {
         switch (pipe_wrap) {
@@ -644,7 +626,7 @@ v3d_sampler_states_bind(struct pipe_context *pctx,
                         unsigned nr, void **hwcso)
 {
         struct v3d_context *v3d = v3d_context(pctx);
-        struct v3d_texture_stateobj *stage_tex = v3d_get_stage_tex(v3d, shader);
+        struct v3d_texture_stateobj *stage_tex = &v3d->tex[shader];
 
         assert(start == 0);
         unsigned i;
@@ -876,7 +858,7 @@ v3d_set_sampler_views(struct pipe_context *pctx,
                       struct pipe_sampler_view **views)
 {
         struct v3d_context *v3d = v3d_context(pctx);
-        struct v3d_texture_stateobj *stage_tex = v3d_get_stage_tex(v3d, shader);
+        struct v3d_texture_stateobj *stage_tex = &v3d->tex[shader];
         unsigned i;
         unsigned new_nr = 0;