1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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:
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
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
26 * Rob Clark <robclark@freedesktop.org>
29 #include "pipe/p_state.h"
30 #include "util/u_string.h"
31 #include "util/u_memory.h"
32 #include "util/u_prim.h"
34 #include "freedreno_state.h"
35 #include "freedreno_resource.h"
38 #include "fd4_context.h"
40 #include "fd4_program.h"
41 #include "fd4_format.h"
46 draw_impl(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
47 struct fd4_emit
*emit
)
49 const struct pipe_draw_info
*info
= emit
->info
;
50 enum pc_di_primtype primtype
= ctx
->primtypes
[info
->mode
];
52 fd4_emit_state(ctx
, ring
, emit
);
54 if (emit
->dirty
& (FD_DIRTY_VTXBUF
| FD_DIRTY_VTXSTATE
))
55 fd4_emit_vertex_bufs(ring
, emit
);
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 */
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);
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
;
71 fd4_draw_emit(ctx
->batch
, ring
, primtype
,
72 emit
->key
.binning_pass
? IGNORE_VISIBILITY
: USE_VISIBILITY
,
76 /* fixup dirty shader state in case some "unrelated" (from the state-
77 * tracker's perspective) state change causes us to switch to a
81 fixup_shader_state(struct fd_context
*ctx
, struct ir3_shader_key
*key
)
83 struct fd4_context
*fd4_ctx
= fd4_context(ctx
);
84 struct ir3_shader_key
*last_key
= &fd4_ctx
->last_key
;
86 if (!ir3_shader_key_equal(last_key
, key
)) {
87 if (ir3_shader_key_changes_fs(last_key
, key
)) {
88 ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] |= FD_DIRTY_SHADER_PROG
;
89 ctx
->dirty
|= FD_DIRTY_PROG
;
92 if (ir3_shader_key_changes_vs(last_key
, key
)) {
93 ctx
->dirty_shader
[PIPE_SHADER_VERTEX
] |= FD_DIRTY_SHADER_PROG
;
94 ctx
->dirty
|= FD_DIRTY_PROG
;
97 fd4_ctx
->last_key
= *key
;
102 fd4_draw_vbo(struct fd_context
*ctx
, const struct pipe_draw_info
*info
)
104 struct fd4_context
*fd4_ctx
= fd4_context(ctx
);
105 struct fd4_emit emit
= {
106 .debug
= &ctx
->debug
,
111 .color_two_side
= ctx
->rasterizer
->light_twoside
,
112 .vclamp_color
= ctx
->rasterizer
->clamp_vertex_color
,
113 .fclamp_color
= ctx
->rasterizer
->clamp_fragment_color
,
114 .rasterflat
= ctx
->rasterizer
->flatshade
,
115 .half_precision
= ctx
->in_blit
&&
116 fd_half_precision(&ctx
->batch
->framebuffer
),
117 .ucp_enables
= ctx
->rasterizer
->clip_plane_enable
,
118 .has_per_samp
= (fd4_ctx
->fsaturate
|| fd4_ctx
->vsaturate
||
119 fd4_ctx
->fastc_srgb
|| fd4_ctx
->vastc_srgb
),
120 .vsaturate_s
= fd4_ctx
->vsaturate_s
,
121 .vsaturate_t
= fd4_ctx
->vsaturate_t
,
122 .vsaturate_r
= fd4_ctx
->vsaturate_r
,
123 .fsaturate_s
= fd4_ctx
->fsaturate_s
,
124 .fsaturate_t
= fd4_ctx
->fsaturate_t
,
125 .fsaturate_r
= fd4_ctx
->fsaturate_r
,
126 .vastc_srgb
= fd4_ctx
->vastc_srgb
,
127 .fastc_srgb
= fd4_ctx
->fastc_srgb
,
129 .rasterflat
= ctx
->rasterizer
->flatshade
,
130 .sprite_coord_enable
= ctx
->rasterizer
->sprite_coord_enable
,
131 .sprite_coord_mode
= ctx
->rasterizer
->sprite_coord_mode
,
134 fixup_shader_state(ctx
, &emit
.key
);
136 enum fd_dirty_3d_state dirty
= ctx
->dirty
;
138 /* do regular pass first, since that is more likely to fail compiling: */
140 if (!(fd4_emit_get_vp(&emit
) && fd4_emit_get_fp(&emit
)))
143 emit
.key
.binning_pass
= false;
146 struct fd_ringbuffer
*ring
= ctx
->batch
->draw
;
148 if (ctx
->rasterizer
->rasterizer_discard
) {
149 fd_wfi(ctx
->batch
, ring
);
150 OUT_PKT3(ring
, CP_REG_RMW
, 3);
151 OUT_RING(ring
, REG_A4XX_RB_RENDER_CONTROL
);
152 OUT_RING(ring
, ~A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
);
153 OUT_RING(ring
, A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
);
156 draw_impl(ctx
, ctx
->batch
->draw
, &emit
);
158 if (ctx
->rasterizer
->rasterizer_discard
) {
159 fd_wfi(ctx
->batch
, ring
);
160 OUT_PKT3(ring
, CP_REG_RMW
, 3);
161 OUT_RING(ring
, REG_A4XX_RB_RENDER_CONTROL
);
162 OUT_RING(ring
, ~A4XX_RB_RENDER_CONTROL_DISABLE_COLOR_PIPE
);
166 /* and now binning pass: */
167 emit
.key
.binning_pass
= true;
168 emit
.dirty
= dirty
& ~(FD_DIRTY_BLEND
);
169 emit
.vp
= NULL
; /* we changed key so need to refetch vp */
171 draw_impl(ctx
, ctx
->batch
->binning
, &emit
);
173 fd_context_all_clean(ctx
);
179 fd4_draw_init(struct pipe_context
*pctx
)
181 struct fd_context
*ctx
= fd_context(pctx
);
182 ctx
->draw_vbo
= fd4_draw_vbo
;