nvc0: add support for GL_EXT_window_rectangles

Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
This commit is contained in:
Ilia Mirkin 2016-06-12 00:46:18 -04:00
parent d1bdc1238a
commit b21a00d129
8 changed files with 73 additions and 5 deletions

View File

@ -46,6 +46,7 @@ Note: some of the new features are only available with certain drivers.
<ul>
<li>GL_ARB_shader_group_vote on nvc0</li>
<li>GL_ARB_ES3_1_compatibility on i965</li>
<li>GL_EXT_window_rectangles on nvc0</li>
</ul>
<h2>Bug fixes</h2>

View File

@ -58,6 +58,7 @@
#define NVC0_NEW_3D_TESSFACTOR (1 << 25)
#define NVC0_NEW_3D_BUFFERS (1 << 26)
#define NVC0_NEW_3D_DRIVERCONST (1 << 27)
#define NVC0_NEW_3D_WINDOW_RECTS (1 << 28)
#define NVC0_NEW_CP_PROGRAM (1 << 0)
#define NVC0_NEW_CP_SURFACES (1 << 1)
@ -214,6 +215,7 @@ struct nvc0_context {
struct pipe_viewport_state viewports[NVC0_MAX_VIEWPORTS];
unsigned viewports_dirty;
struct pipe_clip_state clip;
struct nvc0_window_rect_stateobj window_rect;
unsigned sample_mask;
unsigned min_samples;

View File

@ -157,6 +157,8 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
return PIPE_ENDIAN_LITTLE;
case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
return 30;
case PIPE_CAP_MAX_WINDOW_RECTANGLES:
return NVC0_MAX_WINDOW_RECTANGLES;
/* supported caps */
case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
@ -261,7 +263,6 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
case PIPE_CAP_PCI_BUS:
case PIPE_CAP_PCI_DEVICE:
case PIPE_CAP_PCI_FUNCTION:
case PIPE_CAP_MAX_WINDOW_RECTANGLES:
return 0;
case PIPE_CAP_VENDOR_ID:

View File

@ -25,6 +25,8 @@
#define NVC0_MAX_IMAGES 8
#define NVC0_MAX_WINDOW_RECTANGLES 8
struct nvc0_context;
struct nvc0_blitter;

View File

@ -999,6 +999,22 @@ nvc0_set_viewport_states(struct pipe_context *pipe,
}
static void
nvc0_set_window_rectangles(struct pipe_context *pipe,
boolean include,
unsigned num_rectangles,
const struct pipe_scissor_state *rectangles)
{
struct nvc0_context *nvc0 = nvc0_context(pipe);
nvc0->window_rect.inclusive = include;
nvc0->window_rect.rects = MIN2(num_rectangles, NVC0_MAX_WINDOW_RECTANGLES);
memcpy(nvc0->window_rect.rect, rectangles,
sizeof(struct pipe_scissor_state) * nvc0->window_rect.rects);
nvc0->dirty_3d |= NVC0_NEW_3D_WINDOW_RECTS;
}
static void
nvc0_set_tess_state(struct pipe_context *pipe,
const float default_tess_outer[4],
@ -1490,6 +1506,7 @@ nvc0_init_state_functions(struct nvc0_context *nvc0)
pipe->set_polygon_stipple = nvc0_set_polygon_stipple;
pipe->set_scissor_states = nvc0_set_scissor_states;
pipe->set_viewport_states = nvc0_set_viewport_states;
pipe->set_window_rectangles = nvc0_set_window_rectangles;
pipe->set_tess_state = nvc0_set_tess_state;
pipe->create_vertex_elements_state = nvc0_vertex_state_create;

View File

@ -326,6 +326,30 @@ nvc0_validate_viewport(struct nvc0_context *nvc0)
nvc0->viewports_dirty = 0;
}
static void
nvc0_validate_window_rects(struct nvc0_context *nvc0)
{
struct nouveau_pushbuf *push = nvc0->base.pushbuf;
bool enable = nvc0->window_rect.rects > 0 || nvc0->window_rect.inclusive;
int i;
IMMED_NVC0(push, NVC0_3D(CLIP_RECTS_EN), enable);
if (!enable)
return;
IMMED_NVC0(push, NVC0_3D(CLIP_RECTS_MODE), !nvc0->window_rect.inclusive);
BEGIN_NVC0(push, NVC0_3D(CLIP_RECT_HORIZ(0)), NVC0_MAX_WINDOW_RECTANGLES * 2);
for (i = 0; i < nvc0->window_rect.rects; i++) {
struct pipe_scissor_state *s = &nvc0->window_rect.rect[i];
PUSH_DATA(push, (s->maxx << 16) | s->minx);
PUSH_DATA(push, (s->maxy << 16) | s->miny);
}
for (; i < NVC0_MAX_WINDOW_RECTANGLES; i++) {
PUSH_DATA(push, 0);
PUSH_DATA(push, 0);
}
}
static inline void
nvc0_upload_uclip_planes(struct nvc0_context *nvc0, unsigned s)
{
@ -716,6 +740,7 @@ validate_list_3d[] = {
{ nvc0_validate_stipple, NVC0_NEW_3D_STIPPLE },
{ nvc0_validate_scissor, NVC0_NEW_3D_SCISSOR | NVC0_NEW_3D_RASTERIZER },
{ nvc0_validate_viewport, NVC0_NEW_3D_VIEWPORT },
{ nvc0_validate_window_rects, NVC0_NEW_3D_WINDOW_RECTS },
{ nvc0_vertprog_validate, NVC0_NEW_3D_VERTPROG },
{ nvc0_tctlprog_validate, NVC0_NEW_3D_TCTLPROG },
{ nvc0_tevlprog_validate, NVC0_NEW_3D_TEVLPROG },

View File

@ -61,6 +61,12 @@ struct nvc0_vertex_stateobj {
struct nvc0_vertex_element element[0];
};
struct nvc0_window_rect_stateobj {
bool inclusive;
unsigned rects;
struct pipe_scissor_state rect[PIPE_MAX_WINDOW_RECTANGLES];
};
struct nvc0_so_target {
struct pipe_stream_output_target pipe;
struct pipe_query *pq;

View File

@ -782,6 +782,7 @@ struct nvc0_blitctx
enum pipe_texture_target target;
struct {
struct pipe_framebuffer_state fb;
struct nvc0_window_rect_stateobj window_rect;
struct nvc0_rasterizer_stateobj *rast;
struct nvc0_program *vp;
struct nvc0_program *tcp;
@ -1035,7 +1036,8 @@ nvc0_blitctx_prepare_state(struct nvc0_blitctx *blit)
}
static void
nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx,
const struct pipe_blit_info *info)
{
struct nvc0_context *nvc0 = ctx->nvc0;
struct nvc0_blitter *blitter = nvc0->screen->blitter;
@ -1058,6 +1060,7 @@ nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
ctx->saved.fp = nvc0->fragprog;
ctx->saved.min_samples = nvc0->min_samples;
ctx->saved.window_rect = nvc0->window_rect;
nvc0->rast = &ctx->rast;
@ -1067,6 +1070,13 @@ nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
nvc0->gmtyprog = NULL;
nvc0->fragprog = ctx->fp;
nvc0->window_rect.rects =
MIN2(info->num_window_rectangles, NVC0_MAX_WINDOW_RECTANGLES);
nvc0->window_rect.inclusive = info->window_rectangle_include;
if (nvc0->window_rect.rects)
memcpy(nvc0->window_rect.rect, info->window_rectangles,
sizeof(struct pipe_scissor_state) * nvc0->window_rect.rects);
for (s = 0; s <= 4; ++s) {
ctx->saved.num_textures[s] = nvc0->num_textures[s];
ctx->saved.num_samplers[s] = nvc0->num_samplers[s];
@ -1099,7 +1109,7 @@ nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
nvc0->dirty_3d = NVC0_NEW_3D_FRAMEBUFFER | NVC0_NEW_3D_MIN_SAMPLES |
NVC0_NEW_3D_VERTPROG | NVC0_NEW_3D_FRAGPROG |
NVC0_NEW_3D_TCTLPROG | NVC0_NEW_3D_TEVLPROG | NVC0_NEW_3D_GMTYPROG |
NVC0_NEW_3D_TEXTURES | NVC0_NEW_3D_SAMPLERS;
NVC0_NEW_3D_TEXTURES | NVC0_NEW_3D_SAMPLERS | NVC0_NEW_3D_WINDOW_RECTS;
}
static void
@ -1127,6 +1137,7 @@ nvc0_blitctx_post_blit(struct nvc0_blitctx *blit)
nvc0->fragprog = blit->saved.fp;
nvc0->min_samples = blit->saved.min_samples;
nvc0->window_rect = blit->saved.window_rect;
pipe_sampler_view_reference(&nvc0->textures[4][0], NULL);
pipe_sampler_view_reference(&nvc0->textures[4][1], NULL);
@ -1158,7 +1169,7 @@ nvc0_blitctx_post_blit(struct nvc0_blitctx *blit)
nvc0->dirty_3d = blit->saved.dirty_3d |
(NVC0_NEW_3D_FRAMEBUFFER | NVC0_NEW_3D_SCISSOR | NVC0_NEW_3D_SAMPLE_MASK |
NVC0_NEW_3D_RASTERIZER | NVC0_NEW_3D_ZSA | NVC0_NEW_3D_BLEND |
NVC0_NEW_3D_VIEWPORT |
NVC0_NEW_3D_VIEWPORT | NVC0_NEW_3D_WINDOW_RECTS |
NVC0_NEW_3D_TEXTURES | NVC0_NEW_3D_SAMPLERS |
NVC0_NEW_3D_VERTPROG | NVC0_NEW_3D_FRAGPROG |
NVC0_NEW_3D_TCTLPROG | NVC0_NEW_3D_TEVLPROG | NVC0_NEW_3D_GMTYPROG |
@ -1191,7 +1202,7 @@ nvc0_blit_3d(struct nvc0_context *nvc0, const struct pipe_blit_info *info)
blit->render_condition_enable = info->render_condition_enable;
nvc0_blit_select_fp(blit, info);
nvc0_blitctx_pre_blit(blit);
nvc0_blitctx_pre_blit(blit, info);
nvc0_blit_set_dst(blit, dst, info->dst.level, -1, info->dst.format);
nvc0_blit_set_src(blit, src, info->src.level, -1, info->src.format,
@ -1606,6 +1617,9 @@ nvc0_blit(struct pipe_context *pipe, const struct pipe_blit_info *info)
info->src.box.height != -info->dst.box.height))
eng3d = true;
if (info->num_window_rectangles > 0 || info->window_rectangle_include)
eng3d = true;
if (nvc0->screen->num_occlusion_queries_active)
IMMED_NVC0(push, NVC0_3D(SAMPLECNT_ENABLE), 0);