2 * Copyright (C) 2013 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"
31 #include "util/format/u_format.h"
33 #include "freedreno_state.h"
34 #include "freedreno_resource.h"
37 #include "fd3_context.h"
39 #include "fd3_program.h"
40 #include "fd3_format.h"
43 static inline uint32_t
44 add_sat(uint32_t a
, int32_t b
)
46 int64_t ret
= (uint64_t)a
+ (int64_t)b
;
55 draw_impl(struct fd_context
*ctx
, struct fd_ringbuffer
*ring
,
56 struct fd3_emit
*emit
, unsigned index_offset
)
58 const struct pipe_draw_info
*info
= emit
->info
;
59 enum pc_di_primtype primtype
= ctx
->primtypes
[info
->mode
];
61 fd3_emit_state(ctx
, ring
, emit
);
63 if (emit
->dirty
& (FD_DIRTY_VTXBUF
| FD_DIRTY_VTXSTATE
))
64 fd3_emit_vertex_bufs(ring
, emit
);
66 OUT_PKT0(ring
, REG_A3XX_PC_VERTEX_REUSE_BLOCK_CNTL
, 1);
67 OUT_RING(ring
, 0x0000000b); /* PC_VERTEX_REUSE_BLOCK_CNTL */
69 OUT_PKT0(ring
, REG_A3XX_VFD_INDEX_MIN
, 4);
70 OUT_RING(ring
, add_sat(info
->min_index
, info
->index_bias
)); /* VFD_INDEX_MIN */
71 OUT_RING(ring
, add_sat(info
->max_index
, info
->index_bias
)); /* VFD_INDEX_MAX */
72 OUT_RING(ring
, info
->start_instance
); /* VFD_INSTANCEID_OFFSET */
73 OUT_RING(ring
, info
->index_size
? info
->index_bias
: info
->start
); /* VFD_INDEX_OFFSET */
75 OUT_PKT0(ring
, REG_A3XX_PC_RESTART_INDEX
, 1);
76 OUT_RING(ring
, info
->primitive_restart
? /* PC_RESTART_INDEX */
77 info
->restart_index
: 0xffffffff);
79 /* points + psize -> spritelist: */
80 if (ctx
->rasterizer
->point_size_per_vertex
&&
81 fd3_emit_get_vp(emit
)->writes_psize
&&
82 (info
->mode
== PIPE_PRIM_POINTS
))
83 primtype
= DI_PT_POINTLIST_PSIZE
;
85 fd_draw_emit(ctx
->batch
, ring
, primtype
,
86 emit
->binning_pass
? IGNORE_VISIBILITY
: USE_VISIBILITY
,
90 /* fixup dirty shader state in case some "unrelated" (from the state-
91 * tracker's perspective) state change causes us to switch to a
95 fixup_shader_state(struct fd_context
*ctx
, struct ir3_shader_key
*key
)
97 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
98 struct ir3_shader_key
*last_key
= &fd3_ctx
->last_key
;
100 if (!ir3_shader_key_equal(last_key
, key
)) {
101 if (ir3_shader_key_changes_fs(last_key
, key
)) {
102 ctx
->dirty_shader
[PIPE_SHADER_FRAGMENT
] |= FD_DIRTY_SHADER_PROG
;
103 ctx
->dirty
|= FD_DIRTY_PROG
;
106 if (ir3_shader_key_changes_vs(last_key
, key
)) {
107 ctx
->dirty_shader
[PIPE_SHADER_VERTEX
] |= FD_DIRTY_SHADER_PROG
;
108 ctx
->dirty
|= FD_DIRTY_PROG
;
111 fd3_ctx
->last_key
= *key
;
116 fd3_draw_vbo(struct fd_context
*ctx
, const struct pipe_draw_info
*info
,
117 unsigned index_offset
)
119 struct fd3_context
*fd3_ctx
= fd3_context(ctx
);
120 struct fd3_emit emit
= {
121 .debug
= &ctx
->debug
,
126 .color_two_side
= ctx
->rasterizer
->light_twoside
,
127 .vclamp_color
= ctx
->rasterizer
->clamp_vertex_color
,
128 .fclamp_color
= ctx
->rasterizer
->clamp_fragment_color
,
129 .half_precision
= ctx
->in_blit
&&
130 fd_half_precision(&ctx
->batch
->framebuffer
),
131 .has_per_samp
= (fd3_ctx
->fsaturate
|| fd3_ctx
->vsaturate
),
132 .vsaturate_s
= fd3_ctx
->vsaturate_s
,
133 .vsaturate_t
= fd3_ctx
->vsaturate_t
,
134 .vsaturate_r
= fd3_ctx
->vsaturate_r
,
135 .fsaturate_s
= fd3_ctx
->fsaturate_s
,
136 .fsaturate_t
= fd3_ctx
->fsaturate_t
,
137 .fsaturate_r
= fd3_ctx
->fsaturate_r
,
139 .rasterflat
= ctx
->rasterizer
->flatshade
,
140 .sprite_coord_enable
= ctx
->rasterizer
->sprite_coord_enable
,
141 .sprite_coord_mode
= ctx
->rasterizer
->sprite_coord_mode
,
144 if (fd3_needs_manual_clipping(ctx
->prog
.vs
, ctx
->rasterizer
))
145 emit
.key
.ucp_enables
= ctx
->rasterizer
->clip_plane_enable
;
147 fixup_shader_state(ctx
, &emit
.key
);
149 unsigned dirty
= ctx
->dirty
;
150 const struct ir3_shader_variant
*vp
= fd3_emit_get_vp(&emit
);
151 const struct ir3_shader_variant
*fp
= fd3_emit_get_fp(&emit
);
153 /* do regular pass first, since that is more likely to fail compiling: */
158 ctx
->stats
.vs_regs
+= ir3_shader_halfregs(vp
);
159 ctx
->stats
.fs_regs
+= ir3_shader_halfregs(fp
);
161 emit
.binning_pass
= false;
163 draw_impl(ctx
, ctx
->batch
->draw
, &emit
, index_offset
);
165 /* and now binning pass: */
166 emit
.binning_pass
= true;
167 emit
.dirty
= dirty
& ~(FD_DIRTY_BLEND
);
168 emit
.vs
= NULL
; /* we changed key so need to refetch vs */
170 draw_impl(ctx
, ctx
->batch
->binning
, &emit
, index_offset
);
172 fd_context_all_clean(ctx
);
178 fd3_draw_init(struct pipe_context
*pctx
)
180 struct fd_context
*ctx
= fd_context(pctx
);
181 ctx
->draw_vbo
= fd3_draw_vbo
;