• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
2 
3 /*
4  * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice (including the next
14  * paragraph) shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * Authors:
26  *    Rob Clark <robclark@freedesktop.org>
27  */
28 
29 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
32 #include "util/u_prim.h"
33 
34 #include "freedreno_state.h"
35 #include "freedreno_resource.h"
36 
37 #include "fd4_draw.h"
38 #include "fd4_context.h"
39 #include "fd4_emit.h"
40 #include "fd4_program.h"
41 #include "fd4_format.h"
42 #include "fd4_zsa.h"
43 
44 
45 static void
draw_impl(struct fd_context * ctx,struct fd_ringbuffer * ring,struct fd4_emit * emit)46 draw_impl(struct fd_context *ctx, struct fd_ringbuffer *ring,
47 		struct fd4_emit *emit)
48 {
49 	const struct pipe_draw_info *info = emit->info;
50 	enum pc_di_primtype primtype = ctx->primtypes[info->mode];
51 
52 	fd4_emit_state(ctx, ring, emit);
53 
54 	if (emit->dirty & (FD_DIRTY_VTXBUF | FD_DIRTY_VTXSTATE))
55 		fd4_emit_vertex_bufs(ring, emit);
56 
57 	OUT_PKT0(ring, REG_A4XX_VFD_INDEX_OFFSET, 2);
58 	OUT_RING(ring, info->indexed ? info->index_bias : info->start); /* VFD_INDEX_OFFSET */
59 	OUT_RING(ring, info->start_instance);   /* ??? UNKNOWN_2209 */
60 
61 	OUT_PKT0(ring, REG_A4XX_PC_RESTART_INDEX, 1);
62 	OUT_RING(ring, info->primitive_restart ? /* PC_RESTART_INDEX */
63 			info->restart_index : 0xffffffff);
64 
65 	/* points + psize -> spritelist: */
66 	if (ctx->rasterizer->point_size_per_vertex &&
67 			fd4_emit_get_vp(emit)->writes_psize &&
68 			(info->mode == PIPE_PRIM_POINTS))
69 		primtype = DI_PT_POINTLIST_PSIZE;
70 
71 	fd4_draw_emit(ctx->batch, ring, primtype,
72 			emit->key.binning_pass ? IGNORE_VISIBILITY : USE_VISIBILITY,
73 			info);
74 }
75 
76 /* fixup dirty shader state in case some "unrelated" (from the state-
77  * tracker's perspective) state change causes us to switch to a
78  * different variant.
79  */
80 static void
fixup_shader_state(struct fd_context * ctx,struct ir3_shader_key * key)81 fixup_shader_state(struct fd_context *ctx, struct ir3_shader_key *key)
82 {
83 	struct fd4_context *fd4_ctx = fd4_context(ctx);
84 	struct ir3_shader_key *last_key = &fd4_ctx->last_key;
85 
86 	if (!ir3_shader_key_equal(last_key, key)) {
87 		if (last_key->has_per_samp || key->has_per_samp) {
88 			if ((last_key->vsaturate_s != key->vsaturate_s) ||
89 					(last_key->vsaturate_t != key->vsaturate_t) ||
90 					(last_key->vsaturate_r != key->vsaturate_r) ||
91 					(last_key->vastc_srgb != key->vastc_srgb))
92 				ctx->dirty |= FD_SHADER_DIRTY_VP;
93 
94 			if ((last_key->fsaturate_s != key->fsaturate_s) ||
95 					(last_key->fsaturate_t != key->fsaturate_t) ||
96 					(last_key->fsaturate_r != key->fsaturate_r) ||
97 					(last_key->fastc_srgb != key->fastc_srgb))
98 				ctx->dirty |= FD_SHADER_DIRTY_FP;
99 		}
100 
101 		if (last_key->vclamp_color != key->vclamp_color)
102 			ctx->dirty |= FD_SHADER_DIRTY_VP;
103 
104 		if (last_key->fclamp_color != key->fclamp_color)
105 			ctx->dirty |= FD_SHADER_DIRTY_FP;
106 
107 		if (last_key->color_two_side != key->color_two_side)
108 			ctx->dirty |= FD_SHADER_DIRTY_FP;
109 
110 		if (last_key->half_precision != key->half_precision)
111 			ctx->dirty |= FD_SHADER_DIRTY_FP;
112 
113 		if (last_key->rasterflat != key->rasterflat)
114 			ctx->dirty |= FD_SHADER_DIRTY_FP;
115 
116 		if (last_key->ucp_enables != key->ucp_enables)
117 			ctx->dirty |= FD_SHADER_DIRTY_FP | FD_SHADER_DIRTY_VP;
118 
119 		fd4_ctx->last_key = *key;
120 	}
121 }
122 
123 static bool
fd4_draw_vbo(struct fd_context * ctx,const struct pipe_draw_info * info)124 fd4_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info)
125 {
126 	struct fd4_context *fd4_ctx = fd4_context(ctx);
127 	struct fd4_emit emit = {
128 		.debug = &ctx->debug,
129 		.vtx  = &ctx->vtx,
130 		.prog = &ctx->prog,
131 		.info = info,
132 		.key = {
133 			.color_two_side = ctx->rasterizer->light_twoside,
134 			.vclamp_color = ctx->rasterizer->clamp_vertex_color,
135 			.fclamp_color = ctx->rasterizer->clamp_fragment_color,
136 			.rasterflat = ctx->rasterizer->flatshade,
137 			.half_precision = ctx->in_blit &&
138 					fd_half_precision(&ctx->batch->framebuffer),
139 			.ucp_enables = ctx->rasterizer->clip_plane_enable,
140 			.has_per_samp = (fd4_ctx->fsaturate || fd4_ctx->vsaturate ||
141 					fd4_ctx->fastc_srgb || fd4_ctx->vastc_srgb),
142 			.vsaturate_s = fd4_ctx->vsaturate_s,
143 			.vsaturate_t = fd4_ctx->vsaturate_t,
144 			.vsaturate_r = fd4_ctx->vsaturate_r,
145 			.fsaturate_s = fd4_ctx->fsaturate_s,
146 			.fsaturate_t = fd4_ctx->fsaturate_t,
147 			.fsaturate_r = fd4_ctx->fsaturate_r,
148 			.vastc_srgb = fd4_ctx->vastc_srgb,
149 			.fastc_srgb = fd4_ctx->fastc_srgb,
150 		},
151 		.rasterflat = ctx->rasterizer->flatshade,
152 		.sprite_coord_enable = ctx->rasterizer->sprite_coord_enable,
153 		.sprite_coord_mode = ctx->rasterizer->sprite_coord_mode,
154 	};
155 
156 	fixup_shader_state(ctx, &emit.key);
157 
158 	unsigned dirty = ctx->dirty;
159 
160 	/* do regular pass first, since that is more likely to fail compiling: */
161 
162 	if (!(fd4_emit_get_vp(&emit) && fd4_emit_get_fp(&emit)))
163 		return false;
164 
165 	emit.key.binning_pass = false;
166 	emit.dirty = dirty;
167 
168 	struct fd_ringbuffer *ring = ctx->batch->draw;
169 
170 	if (ctx->rasterizer->rasterizer_discard) {
171 		fd_wfi(ctx->batch, ring);
172 		OUT_PKT3(ring, CP_REG_RMW, 3);
173 		OUT_RING(ring, REG_A4XX_RB_RENDER_CONTROL);
174 		OUT_RING(ring, ~A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE);
175 		OUT_RING(ring, A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE);
176 	}
177 
178 	draw_impl(ctx, ctx->batch->draw, &emit);
179 
180 	if (ctx->rasterizer->rasterizer_discard) {
181 		fd_wfi(ctx->batch, ring);
182 		OUT_PKT3(ring, CP_REG_RMW, 3);
183 		OUT_RING(ring, REG_A4XX_RB_RENDER_CONTROL);
184 		OUT_RING(ring, ~A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE);
185 		OUT_RING(ring, 0);
186 	}
187 
188 	/* and now binning pass: */
189 	emit.key.binning_pass = true;
190 	emit.dirty = dirty & ~(FD_DIRTY_BLEND);
191 	emit.vp = NULL;   /* we changed key so need to refetch vp */
192 	emit.fp = NULL;
193 	draw_impl(ctx, ctx->batch->binning, &emit);
194 
195 	return true;
196 }
197 
198 void
fd4_draw_init(struct pipe_context * pctx)199 fd4_draw_init(struct pipe_context *pctx)
200 {
201 	struct fd_context *ctx = fd_context(pctx);
202 	ctx->draw_vbo = fd4_draw_vbo;
203 }
204