Re: [Mesa-dev] [PATCH v2 1/3] nvc0: implement multiple viewports/scissors, enable ARB_viewport_array
I've made a few small fixes to this -- you forget to set the scissors/viewports dirty to ~0 on context switch, and also marking the first scissor dirty after a 3d blit (which I was forgetting to do on nv50 as well... oops). I'll push this out shortly with my modifications. Thanks for the contribution! -ilia On Sun, Jun 15, 2014 at 3:24 PM, Tobias Klausmann wrote: > Signed-off-by: Tobias Klausmann > --- > src/gallium/drivers/nouveau/nvc0/nvc0_context.h| 7 +- > src/gallium/drivers/nouveau/nvc0/nvc0_program.c| 2 +- > src/gallium/drivers/nouveau/nvc0/nvc0_screen.c | 20 ++-- > src/gallium/drivers/nouveau/nvc0/nvc0_screen.h | 3 + > src/gallium/drivers/nouveau/nvc0/nvc0_state.c | 27 +++-- > .../drivers/nouveau/nvc0/nvc0_state_validate.c | 116 > + > 6 files changed, 112 insertions(+), 63 deletions(-) > > diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h > b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h > index 76416a0..674dd3c 100644 > --- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h > +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h > @@ -178,8 +178,11 @@ struct nvc0_context { > struct pipe_blend_color blend_colour; > struct pipe_stencil_ref stencil_ref; > struct pipe_poly_stipple stipple; > - struct pipe_scissor_state scissor; > - struct pipe_viewport_state viewport; > + > + struct pipe_scissor_state scissors[NVC0_MAX_VIEWPORTS]; > + unsigned scissors_dirty; > + struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS]; > + unsigned viewports_dirty; > struct pipe_clip_state clip; > > unsigned sample_mask; > diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c > b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c > index 1c82a9a..667fbc8 100644 > --- a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c > +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c > @@ -64,7 +64,7 @@ nvc0_shader_output_address(unsigned sn, unsigned si, > unsigned ubase) > case NV50_SEMANTIC_TESSFACTOR:return 0x000 + si * 0x4; > case TGSI_SEMANTIC_PRIMID:return 0x060; > case TGSI_SEMANTIC_LAYER: return 0x064; > - case NV50_SEMANTIC_VIEWPORTINDEX: return 0x068; > + case TGSI_SEMANTIC_VIEWPORT_INDEX:return 0x068; > case TGSI_SEMANTIC_PSIZE: return 0x06c; > case TGSI_SEMANTIC_POSITION: return 0x070; > case TGSI_SEMANTIC_GENERIC: return ubase + si * 0x10; > diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c > b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c > index 3e6b011..3fdb6ae 100644 > --- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c > +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c > @@ -183,7 +183,7 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum > pipe_cap param) > case PIPE_CAP_FAKE_SW_MSAA: >return 0; > case PIPE_CAP_MAX_VIEWPORTS: > - return 1; > + return NVC0_MAX_VIEWPORTS; > case PIPE_CAP_TEXTURE_QUERY_LOD: > case PIPE_CAP_SAMPLE_SHADING: > case PIPE_CAP_TEXTURE_GATHER_OFFSETS: > @@ -933,19 +933,23 @@ nvc0_screen_create(struct nouveau_device *dev) > > BEGIN_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 1); > PUSH_DATA (push, 1); > - BEGIN_NVC0(push, NVC0_3D(DEPTH_RANGE_NEAR(0)), 2); > - PUSH_DATAf(push, 0.0f); > - PUSH_DATAf(push, 1.0f); > + for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) { > + BEGIN_NVC0(push, NVC0_3D(DEPTH_RANGE_NEAR(i)), 2); > + PUSH_DATAf(push, 0.0f); > + PUSH_DATAf(push, 1.0f); > + } > BEGIN_NVC0(push, NVC0_3D(VIEW_VOLUME_CLIP_CTRL), 1); > PUSH_DATA (push, NVC0_3D_VIEW_VOLUME_CLIP_CTRL_UNK1_UNK1); > > /* We use scissors instead of exact view volume clipping, > * so they're always enabled. > */ > - BEGIN_NVC0(push, NVC0_3D(SCISSOR_ENABLE(0)), 3); > - PUSH_DATA (push, 1); > - PUSH_DATA (push, 8192 << 16); > - PUSH_DATA (push, 8192 << 16); > + for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) { > + BEGIN_NVC0(push, NVC0_3D(SCISSOR_ENABLE(i)), 3); > + PUSH_DATA (push, 1); > + PUSH_DATA (push, 8192 << 16); > + PUSH_DATA (push, 8192 << 16); > + } > > #define MK_MACRO(m, n) i = nvc0_graph_set_macro(screen, m, i, sizeof(n), n); > > diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h > b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h > index c58add5..4802057 100644 > --- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h > +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h > @@ -20,6 +20,9 @@ > > #define NVC0_MAX_SURFACE_SLOTS 16 > > +#define NVC0_MAX_VIEWPORTS 16 > + > + > struct nvc0_context; > > struct nvc0_blitter; > diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c > b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c > index 27e5cd8..c92aaac 100644 > --- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c > +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c > @@ -909,10 +909,17 @@ nvc0_set_scissor_states(struct pipe_context *pipe, > unsigned nu
[Mesa-dev] [PATCH v2 1/3] nvc0: implement multiple viewports/scissors, enable ARB_viewport_array
Signed-off-by: Tobias Klausmann --- src/gallium/drivers/nouveau/nvc0/nvc0_context.h| 7 +- src/gallium/drivers/nouveau/nvc0/nvc0_program.c| 2 +- src/gallium/drivers/nouveau/nvc0/nvc0_screen.c | 20 ++-- src/gallium/drivers/nouveau/nvc0/nvc0_screen.h | 3 + src/gallium/drivers/nouveau/nvc0/nvc0_state.c | 27 +++-- .../drivers/nouveau/nvc0/nvc0_state_validate.c | 116 + 6 files changed, 112 insertions(+), 63 deletions(-) diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h index 76416a0..674dd3c 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h @@ -178,8 +178,11 @@ struct nvc0_context { struct pipe_blend_color blend_colour; struct pipe_stencil_ref stencil_ref; struct pipe_poly_stipple stipple; - struct pipe_scissor_state scissor; - struct pipe_viewport_state viewport; + + struct pipe_scissor_state scissors[NVC0_MAX_VIEWPORTS]; + unsigned scissors_dirty; + struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS]; + unsigned viewports_dirty; struct pipe_clip_state clip; unsigned sample_mask; diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c index 1c82a9a..667fbc8 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_program.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_program.c @@ -64,7 +64,7 @@ nvc0_shader_output_address(unsigned sn, unsigned si, unsigned ubase) case NV50_SEMANTIC_TESSFACTOR:return 0x000 + si * 0x4; case TGSI_SEMANTIC_PRIMID:return 0x060; case TGSI_SEMANTIC_LAYER: return 0x064; - case NV50_SEMANTIC_VIEWPORTINDEX: return 0x068; + case TGSI_SEMANTIC_VIEWPORT_INDEX:return 0x068; case TGSI_SEMANTIC_PSIZE: return 0x06c; case TGSI_SEMANTIC_POSITION: return 0x070; case TGSI_SEMANTIC_GENERIC: return ubase + si * 0x10; diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c index 3e6b011..3fdb6ae 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c @@ -183,7 +183,7 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) case PIPE_CAP_FAKE_SW_MSAA: return 0; case PIPE_CAP_MAX_VIEWPORTS: - return 1; + return NVC0_MAX_VIEWPORTS; case PIPE_CAP_TEXTURE_QUERY_LOD: case PIPE_CAP_SAMPLE_SHADING: case PIPE_CAP_TEXTURE_GATHER_OFFSETS: @@ -933,19 +933,23 @@ nvc0_screen_create(struct nouveau_device *dev) BEGIN_NVC0(push, NVC0_3D(VIEWPORT_TRANSFORM_EN), 1); PUSH_DATA (push, 1); - BEGIN_NVC0(push, NVC0_3D(DEPTH_RANGE_NEAR(0)), 2); - PUSH_DATAf(push, 0.0f); - PUSH_DATAf(push, 1.0f); + for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) { + BEGIN_NVC0(push, NVC0_3D(DEPTH_RANGE_NEAR(i)), 2); + PUSH_DATAf(push, 0.0f); + PUSH_DATAf(push, 1.0f); + } BEGIN_NVC0(push, NVC0_3D(VIEW_VOLUME_CLIP_CTRL), 1); PUSH_DATA (push, NVC0_3D_VIEW_VOLUME_CLIP_CTRL_UNK1_UNK1); /* We use scissors instead of exact view volume clipping, * so they're always enabled. */ - BEGIN_NVC0(push, NVC0_3D(SCISSOR_ENABLE(0)), 3); - PUSH_DATA (push, 1); - PUSH_DATA (push, 8192 << 16); - PUSH_DATA (push, 8192 << 16); + for (i = 0; i < NVC0_MAX_VIEWPORTS; i++) { + BEGIN_NVC0(push, NVC0_3D(SCISSOR_ENABLE(i)), 3); + PUSH_DATA (push, 1); + PUSH_DATA (push, 8192 << 16); + PUSH_DATA (push, 8192 << 16); + } #define MK_MACRO(m, n) i = nvc0_graph_set_macro(screen, m, i, sizeof(n), n); diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h index c58add5..4802057 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h @@ -20,6 +20,9 @@ #define NVC0_MAX_SURFACE_SLOTS 16 +#define NVC0_MAX_VIEWPORTS 16 + + struct nvc0_context; struct nvc0_blitter; diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c index 27e5cd8..c92aaac 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c @@ -909,10 +909,17 @@ nvc0_set_scissor_states(struct pipe_context *pipe, unsigned num_scissors, const struct pipe_scissor_state *scissor) { -struct nvc0_context *nvc0 = nvc0_context(pipe); + struct nvc0_context *nvc0 = nvc0_context(pipe); + int i; -nvc0->scissor = *scissor; -nvc0->dirty |= NVC0_NEW_SCISSOR; + assert(start_slot + num_scissors <= NVC0_MAX_VIEWPORTS); + for (i = 0; i < num_scissors; i++) { + if (!memcmp(&nvc0->scissors[start_slot + i], &scissor[i], sizeof(*scissor))) + continue; + nvc0->scissors[start_slot + i] = scissor[i]; + nvc0->scissors_dirty |= 1 << (start_slot + i);