diff --git a/src/gallium/drivers/nouveau/nv50/nv50_context.c b/src/gallium/drivers/nouveau/nv50/nv50_context.c index f08e8c4b6b3..b22424281c2 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_context.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_context.c @@ -68,7 +68,7 @@ nv50_memory_barrier(struct pipe_context *pipe, unsigned flags) nv50->base.vbo_dirty = true; } - for (s = 0; s < 3 && !nv50->cb_dirty; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES && !nv50->cb_dirty; ++s) { uint32_t valid = nv50->constbuf_valid[s]; while (valid && !nv50->cb_dirty) { @@ -142,7 +142,7 @@ nv50_context_unreference_resources(struct nv50_context *nv50) for (i = 0; i < nv50->num_vtxbufs; ++i) pipe_vertex_buffer_unreference(&nv50->vtxbuf[i]); - for (s = 0; s < 3; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) { assert(nv50->num_textures[s] <= PIPE_MAX_SAMPLERS); for (i = 0; i < nv50->num_textures[s]; ++i) pipe_sampler_view_reference(&nv50->textures[s][i], NULL); @@ -232,7 +232,7 @@ nv50_invalidate_resource_storage(struct nouveau_context *ctx, } } - for (s = 0; s < 3; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) { assert(nv50->num_textures[s] <= PIPE_MAX_SAMPLERS); for (i = 0; i < nv50->num_textures[s]; ++i) { if (nv50->textures[s][i] && @@ -245,7 +245,7 @@ nv50_invalidate_resource_storage(struct nouveau_context *ctx, } } - for (s = 0; s < 3; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) { for (i = 0; i < NV50_MAX_PIPE_CONSTBUFS; ++i) { if (!(nv50->constbuf_valid[s] & (1 << i))) continue; diff --git a/src/gallium/drivers/nouveau/nv50/nv50_context.h b/src/gallium/drivers/nouveau/nv50/nv50_context.h index 0be11ba8c30..49ae7ca8dd5 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_context.h +++ b/src/gallium/drivers/nouveau/nv50/nv50_context.h @@ -26,6 +26,14 @@ #include "nv50/nv50_3d.xml.h" #include "nv50/nv50_2d.xml.h" +#define NV50_SHADER_STAGE_VERTEX 0 +#define NV50_SHADER_STAGE_FRAGMENT 1 +#define NV50_SHADER_STAGE_GEOMETRY 2 +#define NV50_SHADER_STAGE_COMPUTE 3 +#define NV50_MAX_SHADER_STAGES 4 + +#define NV50_MAX_3D_SHADER_STAGES 3 + #define NV50_NEW_3D_BLEND (1 << 0) #define NV50_NEW_3D_RASTERIZER (1 << 1) #define NV50_NEW_3D_ZSA (1 << 2) @@ -88,9 +96,9 @@ /* 8 user clip planes, at 4 32-bit floats each */ #define NV50_CB_AUX_UCP_OFFSET 0x0000 #define NV50_CB_AUX_UCP_SIZE (8 * 4 * 4) -/* 16 textures * 3 shaders, each with ms_x, ms_y u32 pairs */ +/* 16 textures * NV50_MAX_3D_SHADER_STAGES shaders, each with ms_x, ms_y u32 pairs */ #define NV50_CB_AUX_TEX_MS_OFFSET 0x0080 -#define NV50_CB_AUX_TEX_MS_SIZE (16 * 3 * 2 * 4) +#define NV50_CB_AUX_TEX_MS_SIZE (16 * NV50_MAX_3D_SHADER_STAGES * 2 * 4) /* For each MS level (4), 8 sets of 32-bit integer pairs sample offsets */ #define NV50_CB_AUX_MS_OFFSET 0x200 #define NV50_CB_AUX_MS_SIZE (4 * 8 * 4 * 2) @@ -135,10 +143,10 @@ struct nv50_context { struct nv50_program *fragprog; struct nv50_program *compprog; - struct nv50_constbuf constbuf[3][NV50_MAX_PIPE_CONSTBUFS]; - uint16_t constbuf_dirty[3]; - uint16_t constbuf_valid[3]; - uint16_t constbuf_coherent[3]; + struct nv50_constbuf constbuf[NV50_MAX_3D_SHADER_STAGES][NV50_MAX_PIPE_CONSTBUFS]; + uint16_t constbuf_dirty[NV50_MAX_3D_SHADER_STAGES]; + uint16_t constbuf_valid[NV50_MAX_3D_SHADER_STAGES]; + uint16_t constbuf_coherent[NV50_MAX_3D_SHADER_STAGES]; struct pipe_vertex_buffer vtxbuf[PIPE_MAX_ATTRIBS]; unsigned num_vtxbufs; @@ -151,11 +159,11 @@ struct nv50_context { uint32_t instance_off; /* base vertex for instanced arrays */ uint32_t instance_max; /* max instance for current draw call */ - struct pipe_sampler_view *textures[3][PIPE_MAX_SAMPLERS]; - unsigned num_textures[3]; - uint32_t textures_coherent[3]; - struct nv50_tsc_entry *samplers[3][PIPE_MAX_SAMPLERS]; - unsigned num_samplers[3]; + struct pipe_sampler_view *textures[NV50_MAX_3D_SHADER_STAGES][PIPE_MAX_SAMPLERS]; + unsigned num_textures[NV50_MAX_3D_SHADER_STAGES]; + uint32_t textures_coherent[NV50_MAX_3D_SHADER_STAGES]; + struct nv50_tsc_entry *samplers[NV50_MAX_3D_SHADER_STAGES][PIPE_MAX_SAMPLERS]; + unsigned num_samplers[NV50_MAX_3D_SHADER_STAGES]; bool seamless_cube_map; uint8_t num_so_targets; @@ -206,10 +214,10 @@ static inline unsigned nv50_context_shader_stage(unsigned pipe) { switch (pipe) { - case PIPE_SHADER_VERTEX: return 0; - case PIPE_SHADER_FRAGMENT: return 1; - case PIPE_SHADER_GEOMETRY: return 2; - case PIPE_SHADER_COMPUTE: return 3; + case PIPE_SHADER_VERTEX: return NV50_SHADER_STAGE_VERTEX; + case PIPE_SHADER_FRAGMENT: return NV50_SHADER_STAGE_FRAGMENT; + case PIPE_SHADER_GEOMETRY: return NV50_SHADER_STAGE_GEOMETRY; + case PIPE_SHADER_COMPUTE: return NV50_SHADER_STAGE_COMPUTE; default: assert(!"invalid/unhandled shader type"); return 0; diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c b/src/gallium/drivers/nouveau/nv50/nv50_screen.c index f56fcb567ef..54909914a61 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c @@ -793,7 +793,7 @@ nv50_screen_init_hwctx(struct nv50_screen *screen) nv50_upload_ms_info(push); /* max TIC (bits 4:8) & TSC bindings, per program type */ - for (i = 0; i < 3; ++i) { + for (i = 0; i < NV50_MAX_3D_SHADER_STAGES; ++i) { BEGIN_NV04(push, NV50_3D(TEX_LIMITS(i)), 1); PUSH_DATA (push, 0x54); } diff --git a/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c b/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c index 6a910d7f819..d1e970d60f8 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c @@ -37,7 +37,7 @@ nv50_constbufs_validate(struct nv50_context *nv50) struct nouveau_pushbuf *push = nv50->base.pushbuf; unsigned s; - for (s = 0; s < 3; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) { unsigned p; if (s == PIPE_SHADER_FRAGMENT) diff --git a/src/gallium/drivers/nouveau/nv50/nv50_state.c b/src/gallium/drivers/nouveau/nv50/nv50_state.c index 93bb3a724db..a9314a83844 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_state.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_state.c @@ -592,7 +592,7 @@ nv50_sampler_state_delete(struct pipe_context *pipe, void *hwcso) { unsigned s, i; - for (s = 0; s < 3; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) { assert(nv50_context(pipe)->num_samplers[s] <= PIPE_MAX_SAMPLERS); for (i = 0; i < nv50_context(pipe)->num_samplers[s]; ++i) if (nv50_context(pipe)->samplers[s][i] == hwcso) diff --git a/src/gallium/drivers/nouveau/nv50/nv50_surface.c b/src/gallium/drivers/nouveau/nv50/nv50_surface.c index b3259f26038..e742336b234 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_surface.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_surface.c @@ -856,8 +856,8 @@ struct nv50_blitctx struct nv50_program *vp; struct nv50_program *gp; struct nv50_program *fp; - unsigned num_textures[3]; - unsigned num_samplers[3]; + unsigned num_textures[NV50_MAX_3D_SHADER_STAGES]; + unsigned num_samplers[NV50_MAX_3D_SHADER_STAGES]; struct pipe_sampler_view *texture[2]; struct nv50_tsc_entry *sampler[2]; unsigned min_samples; @@ -1284,7 +1284,7 @@ nv50_blitctx_pre_blit(struct nv50_blitctx *ctx, memcpy(nv50->window_rect.rect, info->window_rectangles, sizeof(struct pipe_scissor_state) * nv50->window_rect.rects); - for (s = 0; s < 3; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) { ctx->saved.num_textures[s] = nv50->num_textures[s]; ctx->saved.num_samplers[s] = nv50->num_samplers[s]; } @@ -1338,7 +1338,7 @@ nv50_blitctx_post_blit(struct nv50_blitctx *blit) pipe_sampler_view_reference(&nv50->textures[2][0], NULL); pipe_sampler_view_reference(&nv50->textures[2][1], NULL); - for (s = 0; s < 3; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) { nv50->num_textures[s] = blit->saved.num_textures[s]; nv50->num_samplers[s] = blit->saved.num_samplers[s]; } diff --git a/src/gallium/drivers/nouveau/nv50/nv50_tex.c b/src/gallium/drivers/nouveau/nv50/nv50_tex.c index 55d3d8a420c..2bd49e77210 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_tex.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_tex.c @@ -331,11 +331,11 @@ nv50_validate_tic(struct nv50_context *nv50, int s) void nv50_validate_textures(struct nv50_context *nv50) { - bool need_flush; + unsigned s; + bool need_flush = false; - need_flush = nv50_validate_tic(nv50, 0); - need_flush |= nv50_validate_tic(nv50, 1); - need_flush |= nv50_validate_tic(nv50, 2); + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) + need_flush |= nv50_validate_tic(nv50, s); if (need_flush) { BEGIN_NV04(nv50->base.pushbuf, NV50_3D(TIC_FLUSH), 1); @@ -394,11 +394,11 @@ nv50_validate_tsc(struct nv50_context *nv50, int s) void nv50_validate_samplers(struct nv50_context *nv50) { - bool need_flush; + unsigned s; + bool need_flush = false; - need_flush = nv50_validate_tsc(nv50, 0); - need_flush |= nv50_validate_tsc(nv50, 1); - need_flush |= nv50_validate_tsc(nv50, 2); + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES; ++s) + need_flush |= nv50_validate_tsc(nv50, s); if (need_flush) { BEGIN_NV04(nv50->base.pushbuf, NV50_3D(TSC_FLUSH), 1); diff --git a/src/gallium/drivers/nouveau/nv50/nv50_transfer.c b/src/gallium/drivers/nouveau/nv50/nv50_transfer.c index fad21ba6a5c..68005547323 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_transfer.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_transfer.c @@ -536,7 +536,7 @@ nv50_cb_push(struct nouveau_context *nv, * find one which contains the region to be updated. */ /* XXX compute? */ - for (s = 0; s < 3 && !cb; s++) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES && !cb; s++) { uint16_t bindings = res->cb_bindings[s]; while (bindings) { int i = ffs(bindings) - 1; diff --git a/src/gallium/drivers/nouveau/nv50/nv50_vbo.c b/src/gallium/drivers/nouveau/nv50/nv50_vbo.c index e531b3f03af..cab3b3dc55b 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_vbo.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_vbo.c @@ -810,7 +810,7 @@ nv50_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info, push->kick_notify = nv50_draw_vbo_kick_notify; - for (s = 0; s < 3 && !nv50->cb_dirty; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES && !nv50->cb_dirty; ++s) { if (nv50->constbuf_coherent[s]) nv50->cb_dirty = true; } @@ -822,7 +822,7 @@ nv50_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info, nv50->cb_dirty = false; } - for (s = 0; s < 3 && !tex_dirty; ++s) { + for (s = 0; s < NV50_MAX_3D_SHADER_STAGES && !tex_dirty; ++s) { if (nv50->textures_coherent[s]) tex_dirty = true; }