2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Rob Clark <robclark@freedesktop.org>
27 #include "pipe/p_state.h"
28 #include "util/u_string.h"
29 #include "util/u_memory.h"
30 #include "util/u_prim.h"
32 #include "freedreno_state.h"
33 #include "freedreno_resource.h"
36 #include "fd4_context.h"
38 #include "fd4_program.h"
39 #include "fd4_format.h"
44 draw_impl(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
45 struct fd4_emit
*emit
, unsigned index_offset
)
47 const struct pipe_draw_info
*info
= emit
->info
;
48 enum pc_di_primtype primtype
= ctx
->primtypes
[info
->mode
];
50 fd4_emit_state(ctx
, ring
, emit
);
52 if (emit
->dirty
& (FD_DIRTY_VTXBUF
| FD_DIRTY_VTXSTATE
))
53 fd4_emit_vertex_bufs(ring
, emit
);
55 OUT_PKT0(ring
, REG_A4XX_VFD_INDEX_OFFSET
, 2);
56 OUT_RING(ring
, info
->index_size
? info
->index_bias
: info
->start
); /* VFD_INDEX_OFFSET */
57 OUT_RING(ring
, info
->start_instance
); /* ??? UNKNOWN_2209 */
59 OUT_PKT0(ring
, REG_A4XX_PC_RESTART_INDEX
, 1);
60 OUT_RING(ring
, info
->primitive_restart
? /* PC_RESTART_INDEX */
61 info
->restart_index
: 0xffffffff);
63 /* points + psize -> spritelist: */
64 if (ctx
->rasterizer
->point_size_per_vertex
&&
65 fd4_emit_get_vp(emit
)->writes_psize
&&
66 (info
->mode
== PIPE_PRIM_POINTS
))
67 primtype
= DI_PT_POINTLIST_PSIZE
;
69 fd4_draw_emit(ctx
->batch
, ring
, primtype
,
70 emit
->binning_pass
? IGNORE_VISIBILITY
: USE_VISIBILITY
,
74 /* fixup dirty shader state in case some "unrelated" (from the state-
75 * tracker's perspective) state change causes us to switch to a
79 fixup_shader_state(struct fd_context
*ctx
, struct ir3_shader_key
*key
)
81 struct fd4_context
*fd4_ctx
= fd4_context(ctx
);
82 struct ir3_shader_key
*last_key
= &fd4_ctx
->last_key
;
84 if (!ir3_shader_key_equal(last_key
, key
)) {
85 if (ir3_shader_key_changes_fs(last_key
, key
)) {
86 ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] |= FD_DIRTY_SHADER_PROG
;
87 ctx
->dirty
|= FD_DIRTY_PROG
;
90 if (ir3_shader_key_changes_vs(last_key
, key
)) {
91 ctx
->dirty_shader
[PIPE_SHADER_VERTEX
] |= FD_DIRTY_SHADER_PROG
;
92 ctx
->dirty
|= FD_DIRTY_PROG
;
95 fd4_ctx
->last_key
= *key
;
100 fd4_draw_vbo(struct fd_context
*ctx
, const struct pipe_draw_info
*info
,
101 unsigned index_offset
)
103 struct fd4_context
*fd4_ctx
= fd4_context(ctx
);
104 struct fd4_emit emit
= {
105 .debug
= &ctx
->debug
,
110 .color_two_side
= ctx
->rasterizer
->light_twoside
,
111 .vclamp_color
= ctx
->rasterizer
->clamp_vertex_color
,
112 .fclamp_color
= ctx
->rasterizer
->clamp_fragment_color
,
113 .rasterflat
= ctx
->rasterizer
->flatshade
,
114 .ucp_enables
= ctx
->rasterizer
->clip_plane_enable
,
115 .has_per_samp
= (fd4_ctx
->fsaturate
|| fd4_ctx
->vsaturate
||
116 fd4_ctx
->fastc_srgb
|| fd4_ctx
->vastc_srgb
),
117 .vsaturate_s
= fd4_ctx
->vsaturate_s
,
118 .vsaturate_t
= fd4_ctx
->vsaturate_t
,
119 .vsaturate_r
= fd4_ctx
->vsaturate_r
,
120 .fsaturate_s
= fd4_ctx
->fsaturate_s
,
121 .fsaturate_t
= fd4_ctx
->fsaturate_t
,
122 .fsaturate_r
= fd4_ctx
->fsaturate_r
,
123 .vastc_srgb
= fd4_ctx
->vastc_srgb
,
124 .fastc_srgb
= fd4_ctx
->fastc_srgb
,
126 .rasterflat
= ctx
->rasterizer
->flatshade
,
127 .sprite_coord_enable
= ctx
->rasterizer
->sprite_coord_enable
,
128 .sprite_coord_mode
= ctx
->rasterizer
->sprite_coord_mode
,
131 fixup_shader_state(ctx
, &emit
.key
);
133 enum fd_dirty_3d_state dirty
= ctx
->dirty
;
134 const struct ir3_shader_variant
*vp
= fd4_emit_get_vp(&emit
);
135 const struct ir3_shader_variant
*fp
= fd4_emit_get_fp(&emit
);
137 /* do regular pass first, since that is more likely to fail compiling: */
142 ctx
->stats
.vs_regs
+= ir3_shader_halfregs(vp
);
143 ctx
->stats
.fs_regs
+= ir3_shader_halfregs(fp
);
145 emit
.binning_pass
= false;
148 struct fd_ringbuffer
*ring
= ctx
->batch
->draw
;
150 if (ctx
->rasterizer
->rasterizer_discard
) {
151 fd_wfi(ctx
->batch
, ring
);
152 OUT_PKT3(ring
, CP_REG_RMW
, 3);
153 OUT_RING(ring
, REG_A4XX_RB_RENDER_CONTROL
);
154 OUT_RING(ring
, ~A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
);
155 OUT_RING(ring
, A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
);
158 draw_impl(ctx
, ctx
->batch
->draw
, &emit
, index_offset
);
160 if (ctx
->rasterizer
->rasterizer_discard
) {
161 fd_wfi(ctx
->batch
, ring
);
162 OUT_PKT3(ring
, CP_REG_RMW
, 3);
163 OUT_RING(ring
, REG_A4XX_RB_RENDER_CONTROL
);
164 OUT_RING(ring
, ~A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
);
168 /* and now binning pass: */
169 emit
.binning_pass
= true;
170 emit
.dirty
= dirty
& ~(FD_DIRTY_BLEND
);
171 emit
.vs
= NULL
; /* we changed key so need to refetch vs */
173 draw_impl(ctx
, ctx
->batch
->binning
, &emit
, index_offset
);
175 fd_context_all_clean(ctx
);
181 fd4_draw_init(struct pipe_context
*pctx
)
183 struct fd_context
*ctx
= fd_context(pctx
);
184 ctx
->draw_vbo
= fd4_draw_vbo
;