1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22bf215546Sopenharmony_ci
23bf215546Sopenharmony_ci#ifndef R300_CONTEXT_H
24bf215546Sopenharmony_ci#define R300_CONTEXT_H
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#define R300_BUFFER_ALIGNMENT 64
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include "draw/draw_vertex.h"
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "util/u_blitter.h"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#include "pipe/p_context.h"
33bf215546Sopenharmony_ci#include "util/u_inlines.h"
34bf215546Sopenharmony_ci#include "util/u_transfer.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#include "r300_defines.h"
37bf215546Sopenharmony_ci#include "r300_screen.h"
38bf215546Sopenharmony_ci#include "compiler/radeon_regalloc.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistruct u_upload_mgr;
41bf215546Sopenharmony_cistruct r300_context;
42bf215546Sopenharmony_cistruct r300_fragment_shader;
43bf215546Sopenharmony_cistruct r300_vertex_shader;
44bf215546Sopenharmony_cistruct r300_stencilref_context;
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_cienum colormask_swizzle {
47bf215546Sopenharmony_ci    COLORMASK_BGRA,
48bf215546Sopenharmony_ci    COLORMASK_RGBA,
49bf215546Sopenharmony_ci    COLORMASK_RRRR,
50bf215546Sopenharmony_ci    COLORMASK_AAAA,
51bf215546Sopenharmony_ci    COLORMASK_GRRG,
52bf215546Sopenharmony_ci    COLORMASK_ARRA,
53bf215546Sopenharmony_ci    COLORMASK_BGRX,
54bf215546Sopenharmony_ci    COLORMASK_RGBX,
55bf215546Sopenharmony_ci    COLORMASK_NUM_SWIZZLES
56bf215546Sopenharmony_ci};
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_cistruct r300_atom {
59bf215546Sopenharmony_ci    /* Name, for debugging. */
60bf215546Sopenharmony_ci    const char* name;
61bf215546Sopenharmony_ci    /* Opaque state. */
62bf215546Sopenharmony_ci    void* state;
63bf215546Sopenharmony_ci    /* Emit the state to the context. */
64bf215546Sopenharmony_ci    void (*emit)(struct r300_context*, unsigned, void*);
65bf215546Sopenharmony_ci    /* Upper bound on number of dwords to emit. */
66bf215546Sopenharmony_ci    unsigned size;
67bf215546Sopenharmony_ci    /* Whether this atom should be emitted. */
68bf215546Sopenharmony_ci    boolean dirty;
69bf215546Sopenharmony_ci    /* Whether this atom may be emitted with state == NULL. */
70bf215546Sopenharmony_ci    boolean allow_null_state;
71bf215546Sopenharmony_ci};
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_cistruct r300_aa_state {
74bf215546Sopenharmony_ci    struct r300_surface *dest;
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci    uint32_t aa_config;
77bf215546Sopenharmony_ci};
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_cistruct r300_blend_state {
80bf215546Sopenharmony_ci    struct pipe_blend_state state;
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci    uint32_t cb_clamp[COLORMASK_NUM_SWIZZLES][8];
83bf215546Sopenharmony_ci    uint32_t cb_noclamp[8];
84bf215546Sopenharmony_ci    uint32_t cb_noclamp_noalpha[8];
85bf215546Sopenharmony_ci    uint32_t cb_no_readwrite[8];
86bf215546Sopenharmony_ci};
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_cistruct r300_blend_color_state {
89bf215546Sopenharmony_ci    struct pipe_blend_color state;
90bf215546Sopenharmony_ci    uint32_t cb[3];
91bf215546Sopenharmony_ci};
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_cistruct r300_clip_state {
94bf215546Sopenharmony_ci    uint32_t cb[29];
95bf215546Sopenharmony_ci};
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_cistruct r300_dsa_state {
98bf215546Sopenharmony_ci    struct pipe_depth_stencil_alpha_state dsa;
99bf215546Sopenharmony_ci
100bf215546Sopenharmony_ci    /* This is actually a command buffer with named dwords. */
101bf215546Sopenharmony_ci    uint32_t cb_begin;
102bf215546Sopenharmony_ci    uint32_t z_buffer_control;  /* R300_ZB_CNTL: 0x4f00 */
103bf215546Sopenharmony_ci    uint32_t z_stencil_control; /* R300_ZB_ZSTENCILCNTL: 0x4f04 */
104bf215546Sopenharmony_ci    uint32_t stencil_ref_mask;  /* R300_ZB_STENCILREFMASK: 0x4f08 */
105bf215546Sopenharmony_ci    uint32_t cb_reg;
106bf215546Sopenharmony_ci    uint32_t stencil_ref_bf;    /* R500_ZB_STENCILREFMASK_BF: 0x4fd4 */
107bf215546Sopenharmony_ci    uint32_t cb_reg1;
108bf215546Sopenharmony_ci    uint32_t alpha_value;       /* R500_FG_ALPHA_VALUE: 0x4be0 */
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci    /* Same, but without ZB reads and writes. */
111bf215546Sopenharmony_ci    uint32_t cb_zb_no_readwrite[8]; /* ZB not bound */
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci    /* Emitted separately: */
114bf215546Sopenharmony_ci    uint32_t alpha_function;
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci    /* Whether a two-sided stencil is enabled. */
117bf215546Sopenharmony_ci    boolean two_sided;
118bf215546Sopenharmony_ci    /* Whether a fallback should be used for a two-sided stencil ref value. */
119bf215546Sopenharmony_ci    boolean two_sided_stencil_ref;
120bf215546Sopenharmony_ci};
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_cistruct r300_hyperz_state {
123bf215546Sopenharmony_ci    int flush;
124bf215546Sopenharmony_ci    /* This is actually a command buffer with named dwords. */
125bf215546Sopenharmony_ci    uint32_t cb_flush_begin;
126bf215546Sopenharmony_ci    uint32_t zb_zcache_ctlstat;     /* R300_ZB_CACHE_CNTL */
127bf215546Sopenharmony_ci    uint32_t cb_begin;
128bf215546Sopenharmony_ci    uint32_t zb_bw_cntl;            /* R300_ZB_BW_CNTL */
129bf215546Sopenharmony_ci    uint32_t cb_reg1;
130bf215546Sopenharmony_ci    uint32_t zb_depthclearvalue;    /* R300_ZB_DEPTHCLEARVALUE */
131bf215546Sopenharmony_ci    uint32_t cb_reg2;
132bf215546Sopenharmony_ci    uint32_t sc_hyperz;             /* R300_SC_HYPERZ */
133bf215546Sopenharmony_ci    uint32_t cb_reg3;
134bf215546Sopenharmony_ci    uint32_t gb_z_peq_config;       /* R300_GB_Z_PEQ_CONFIG: 0x4028 */
135bf215546Sopenharmony_ci};
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_cistruct r300_gpu_flush {
138bf215546Sopenharmony_ci    uint32_t cb_flush_clean[6];
139bf215546Sopenharmony_ci};
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_ci#define RS_STATE_MAIN_SIZE 27
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_cistruct r300_rs_state {
144bf215546Sopenharmony_ci    /* Original rasterizer state. */
145bf215546Sopenharmony_ci    struct pipe_rasterizer_state rs;
146bf215546Sopenharmony_ci    /* Draw-specific rasterizer state. */
147bf215546Sopenharmony_ci    struct pipe_rasterizer_state rs_draw;
148bf215546Sopenharmony_ci
149bf215546Sopenharmony_ci    /* Command buffers. */
150bf215546Sopenharmony_ci    uint32_t cb_main[RS_STATE_MAIN_SIZE];
151bf215546Sopenharmony_ci    uint32_t cb_poly_offset_zb16[5];
152bf215546Sopenharmony_ci    uint32_t cb_poly_offset_zb24[5];
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci    /* The index to cb_main where the cull_mode register value resides. */
155bf215546Sopenharmony_ci    unsigned cull_mode_index;
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci    /* Whether polygon offset is enabled. */
158bf215546Sopenharmony_ci    boolean polygon_offset_enable;
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci    /* This is emitted in the draw function. */
161bf215546Sopenharmony_ci    uint32_t color_control;         /* R300_GA_COLOR_CONTROL: 0x4278 */
162bf215546Sopenharmony_ci};
163bf215546Sopenharmony_ci
164bf215546Sopenharmony_cistruct r300_rs_block {
165bf215546Sopenharmony_ci    uint32_t vap_vtx_state_cntl;  /* R300_VAP_VTX_STATE_CNTL: 0x2180 */
166bf215546Sopenharmony_ci    uint32_t vap_vsm_vtx_assm;    /* R300_VAP_VSM_VTX_ASSM: 0x2184 */
167bf215546Sopenharmony_ci    uint32_t vap_out_vtx_fmt[2];  /* R300_VAP_OUTPUT_VTX_FMT_[0-1]: 0x2090 */
168bf215546Sopenharmony_ci    uint32_t gb_enable;
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci    uint32_t ip[8]; /* R300_RS_IP_[0-7], R500_RS_IP_[0-7] */
171bf215546Sopenharmony_ci    uint32_t count; /* R300_RS_COUNT */
172bf215546Sopenharmony_ci    uint32_t inst_count; /* R300_RS_INST_COUNT */
173bf215546Sopenharmony_ci    uint32_t inst[8]; /* R300_RS_INST_[0-7] */
174bf215546Sopenharmony_ci};
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_cistruct r300_sampler_state {
177bf215546Sopenharmony_ci    struct pipe_sampler_state state;
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci    uint32_t filter0;      /* R300_TX_FILTER0: 0x4400 */
180bf215546Sopenharmony_ci    uint32_t filter1;      /* R300_TX_FILTER1: 0x4440 */
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_ci    /* Min/max LOD must be clamped to [0, last_level], thus
183bf215546Sopenharmony_ci     * it's dependent on a currently bound texture */
184bf215546Sopenharmony_ci    unsigned min_lod, max_lod;
185bf215546Sopenharmony_ci};
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_cistruct r300_texture_format_state {
188bf215546Sopenharmony_ci    uint32_t format0; /* R300_TX_FORMAT0: 0x4480 */
189bf215546Sopenharmony_ci    uint32_t format1; /* R300_TX_FORMAT1: 0x44c0 */
190bf215546Sopenharmony_ci    uint32_t format2; /* R300_TX_FORMAT2: 0x4500 */
191bf215546Sopenharmony_ci    uint32_t tile_config; /* R300_TX_OFFSET (subset thereof) */
192bf215546Sopenharmony_ci    uint32_t us_format0;   /* R500_US_FORMAT0_0: 0x4640 (through 15) */
193bf215546Sopenharmony_ci};
194bf215546Sopenharmony_ci
195bf215546Sopenharmony_cistruct r300_sampler_view {
196bf215546Sopenharmony_ci    struct pipe_sampler_view base;
197bf215546Sopenharmony_ci
198bf215546Sopenharmony_ci    /* For resource_copy_region. */
199bf215546Sopenharmony_ci    unsigned width0_override;
200bf215546Sopenharmony_ci    unsigned height0_override;
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_ci    /* Swizzles in the PIPE_SWIZZLE_* representation,
203bf215546Sopenharmony_ci     * derived from base. */
204bf215546Sopenharmony_ci    unsigned char swizzle[4];
205bf215546Sopenharmony_ci
206bf215546Sopenharmony_ci    /* Copy of r300_texture::texture_format_state with format-specific bits
207bf215546Sopenharmony_ci     * added. */
208bf215546Sopenharmony_ci    struct r300_texture_format_state format;
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci    /* The texture cache region for this texture. */
211bf215546Sopenharmony_ci    uint32_t texcache_region;
212bf215546Sopenharmony_ci};
213bf215546Sopenharmony_ci
214bf215546Sopenharmony_cistruct r300_texture_sampler_state {
215bf215546Sopenharmony_ci    struct r300_texture_format_state format;
216bf215546Sopenharmony_ci    uint32_t filter0;      /* R300_TX_FILTER0: 0x4400 */
217bf215546Sopenharmony_ci    uint32_t filter1;      /* R300_TX_FILTER1: 0x4440 */
218bf215546Sopenharmony_ci    uint32_t border_color; /* R300_TX_BORDER_COLOR: 0x45c0 */
219bf215546Sopenharmony_ci};
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_cistruct r300_textures_state {
222bf215546Sopenharmony_ci    /* Textures. */
223bf215546Sopenharmony_ci    struct r300_sampler_view *sampler_views[16];
224bf215546Sopenharmony_ci    int sampler_view_count;
225bf215546Sopenharmony_ci    /* Sampler states. */
226bf215546Sopenharmony_ci    struct r300_sampler_state *sampler_states[16];
227bf215546Sopenharmony_ci    int sampler_state_count;
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_ci    /* This is the merge of the texture and sampler states. */
230bf215546Sopenharmony_ci    unsigned count;
231bf215546Sopenharmony_ci    uint32_t tx_enable;         /* R300_TX_ENABLE: 0x4101 */
232bf215546Sopenharmony_ci    struct r300_texture_sampler_state regs[16];
233bf215546Sopenharmony_ci};
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_cistruct r300_vertex_stream_state {
236bf215546Sopenharmony_ci    /* R300_VAP_PROG_STREAK_CNTL_[0-7] */
237bf215546Sopenharmony_ci    uint32_t vap_prog_stream_cntl[8];
238bf215546Sopenharmony_ci    /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */
239bf215546Sopenharmony_ci    uint32_t vap_prog_stream_cntl_ext[8];
240bf215546Sopenharmony_ci
241bf215546Sopenharmony_ci    unsigned count;
242bf215546Sopenharmony_ci};
243bf215546Sopenharmony_ci
244bf215546Sopenharmony_cistruct r300_invariant_state {
245bf215546Sopenharmony_ci    uint32_t cb[24];
246bf215546Sopenharmony_ci};
247bf215546Sopenharmony_ci
248bf215546Sopenharmony_cistruct r300_vap_invariant_state {
249bf215546Sopenharmony_ci    uint32_t cb[11];
250bf215546Sopenharmony_ci};
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_cistruct r300_viewport_state {
253bf215546Sopenharmony_ci    float xscale;         /* R300_VAP_VPORT_XSCALE:  0x2098 */
254bf215546Sopenharmony_ci    float xoffset;        /* R300_VAP_VPORT_XOFFSET: 0x209c */
255bf215546Sopenharmony_ci    float yscale;         /* R300_VAP_VPORT_YSCALE:  0x20a0 */
256bf215546Sopenharmony_ci    float yoffset;        /* R300_VAP_VPORT_YOFFSET: 0x20a4 */
257bf215546Sopenharmony_ci    float zscale;         /* R300_VAP_VPORT_ZSCALE:  0x20a8 */
258bf215546Sopenharmony_ci    float zoffset;        /* R300_VAP_VPORT_ZOFFSET: 0x20ac */
259bf215546Sopenharmony_ci    uint32_t vte_control; /* R300_VAP_VTE_CNTL:      0x20b0 */
260bf215546Sopenharmony_ci};
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_cistruct r300_ztop_state {
263bf215546Sopenharmony_ci    uint32_t z_buffer_top;      /* R300_ZB_ZTOP: 0x4f14 */
264bf215546Sopenharmony_ci};
265bf215546Sopenharmony_ci
266bf215546Sopenharmony_ci/* The next several objects are not pure Radeon state; they inherit from
267bf215546Sopenharmony_ci * various Gallium classes. */
268bf215546Sopenharmony_ci
269bf215546Sopenharmony_cistruct r300_constant_buffer {
270bf215546Sopenharmony_ci    /* Buffer of constants */
271bf215546Sopenharmony_ci    uint32_t *ptr;
272bf215546Sopenharmony_ci    /* Remapping table. */
273bf215546Sopenharmony_ci    unsigned *remap_table;
274bf215546Sopenharmony_ci    /* const buffer base */
275bf215546Sopenharmony_ci    uint32_t buffer_base;
276bf215546Sopenharmony_ci};
277bf215546Sopenharmony_ci
278bf215546Sopenharmony_ci/* Query object.
279bf215546Sopenharmony_ci *
280bf215546Sopenharmony_ci * This is not a subclass of pipe_query because pipe_query is never
281bf215546Sopenharmony_ci * actually fully defined. So, rather than have it as a member, and do
282bf215546Sopenharmony_ci * subclass-style casting, we treat pipe_query as an opaque, and just
283bf215546Sopenharmony_ci * trust that our gallium frontend does not ever mess up query objects.
284bf215546Sopenharmony_ci */
285bf215546Sopenharmony_cistruct r300_query {
286bf215546Sopenharmony_ci    /* The kind of query. Currently only OQ is supported. */
287bf215546Sopenharmony_ci    unsigned type;
288bf215546Sopenharmony_ci    /* The number of pipes where query results are stored. */
289bf215546Sopenharmony_ci    unsigned num_pipes;
290bf215546Sopenharmony_ci    /* How many results have been written, in dwords. It's incremented
291bf215546Sopenharmony_ci     * after end_query and flush. */
292bf215546Sopenharmony_ci    unsigned num_results;
293bf215546Sopenharmony_ci    /* if begin has been emitted */
294bf215546Sopenharmony_ci    boolean begin_emitted;
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_ci    /* The buffer where query results are stored. */
297bf215546Sopenharmony_ci    struct pb_buffer *buf;
298bf215546Sopenharmony_ci};
299bf215546Sopenharmony_ci
300bf215546Sopenharmony_cistruct r300_surface {
301bf215546Sopenharmony_ci    struct pipe_surface base;
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci    /* Winsys buffer backing the texture. */
304bf215546Sopenharmony_ci    struct pb_buffer *buf;
305bf215546Sopenharmony_ci
306bf215546Sopenharmony_ci    enum radeon_bo_domain domain;
307bf215546Sopenharmony_ci
308bf215546Sopenharmony_ci    uint32_t offset;    /* COLOROFFSET or DEPTHOFFSET. */
309bf215546Sopenharmony_ci    uint32_t pitch;     /* COLORPITCH or DEPTHPITCH. */
310bf215546Sopenharmony_ci    uint32_t pitch_zmask; /* ZMASK_PITCH */
311bf215546Sopenharmony_ci    uint32_t pitch_hiz;   /* HIZ_PITCH */
312bf215546Sopenharmony_ci    uint32_t pitch_cmask; /* CMASK_PITCH */
313bf215546Sopenharmony_ci    uint32_t format;    /* US_OUT_FMT or ZB_FORMAT. */
314bf215546Sopenharmony_ci
315bf215546Sopenharmony_ci    /* Parameters dedicated to the CBZB clear. */
316bf215546Sopenharmony_ci    uint32_t cbzb_width;            /* Aligned width. */
317bf215546Sopenharmony_ci    uint32_t cbzb_height;           /* Half of the height. */
318bf215546Sopenharmony_ci    uint32_t cbzb_midpoint_offset;  /* DEPTHOFFSET. */
319bf215546Sopenharmony_ci    uint32_t cbzb_pitch;            /* DEPTHPITCH. */
320bf215546Sopenharmony_ci    uint32_t cbzb_format;           /* ZB_FORMAT. */
321bf215546Sopenharmony_ci
322bf215546Sopenharmony_ci    /* Whether the CBZB clear is allowed on the surface. */
323bf215546Sopenharmony_ci    boolean cbzb_allowed;
324bf215546Sopenharmony_ci
325bf215546Sopenharmony_ci    unsigned colormask_swizzle;
326bf215546Sopenharmony_ci};
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_cistruct r300_texture_desc {
329bf215546Sopenharmony_ci    /* Width, height, and depth.
330bf215546Sopenharmony_ci     * Most of the time, these are equal to pipe_texture::width0, height0,
331bf215546Sopenharmony_ci     * and depth0. However, NPOT 3D textures must have dimensions aligned
332bf215546Sopenharmony_ci     * to POT, and this is the only case when these variables differ from
333bf215546Sopenharmony_ci     * pipe_texture. */
334bf215546Sopenharmony_ci    unsigned width0, height0, depth0;
335bf215546Sopenharmony_ci
336bf215546Sopenharmony_ci    /* Buffer tiling.
337bf215546Sopenharmony_ci     * Macrotiling is specified per-level because small mipmaps cannot
338bf215546Sopenharmony_ci     * be macrotiled. */
339bf215546Sopenharmony_ci    enum radeon_bo_layout microtile;
340bf215546Sopenharmony_ci    enum radeon_bo_layout macrotile[R300_MAX_TEXTURE_LEVELS];
341bf215546Sopenharmony_ci
342bf215546Sopenharmony_ci    /* Offsets into the buffer. */
343bf215546Sopenharmony_ci    unsigned offset_in_bytes[R300_MAX_TEXTURE_LEVELS];
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_ci    /* Strides for each mip-level. */
346bf215546Sopenharmony_ci    unsigned stride_in_bytes[R300_MAX_TEXTURE_LEVELS];
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_ci    /* Size of one zslice or face or 2D image based on the texture target. */
349bf215546Sopenharmony_ci    unsigned layer_size_in_bytes[R300_MAX_TEXTURE_LEVELS];
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_ci    /* Total size of this texture, in bytes,
352bf215546Sopenharmony_ci     * derived from the texture properties. */
353bf215546Sopenharmony_ci    unsigned size_in_bytes;
354bf215546Sopenharmony_ci
355bf215546Sopenharmony_ci    /**
356bf215546Sopenharmony_ci     * If non-zero, override the natural texture layout with
357bf215546Sopenharmony_ci     * a custom stride (in bytes).
358bf215546Sopenharmony_ci     *
359bf215546Sopenharmony_ci     * \note Mipmapping fails for textures with a non-natural layout!
360bf215546Sopenharmony_ci     *
361bf215546Sopenharmony_ci     * \sa r300_texture_get_stride
362bf215546Sopenharmony_ci     */
363bf215546Sopenharmony_ci    unsigned stride_in_bytes_override;
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_ci    /* Whether this texture has non-power-of-two dimensions.
366bf215546Sopenharmony_ci     * It can be either a regular texture or a rectangle one. */
367bf215546Sopenharmony_ci    boolean is_npot;
368bf215546Sopenharmony_ci
369bf215546Sopenharmony_ci    /* This flag says that hardware must use the stride for addressing
370bf215546Sopenharmony_ci     * instead of the width. */
371bf215546Sopenharmony_ci    boolean uses_stride_addressing;
372bf215546Sopenharmony_ci
373bf215546Sopenharmony_ci    /* Whether CBZB fast color clear is allowed on the miplevel. */
374bf215546Sopenharmony_ci    boolean cbzb_allowed[R300_MAX_TEXTURE_LEVELS];
375bf215546Sopenharmony_ci
376bf215546Sopenharmony_ci    /* Zbuffer compression info for each miplevel. */
377bf215546Sopenharmony_ci    boolean zcomp8x8[R300_MAX_TEXTURE_LEVELS];
378bf215546Sopenharmony_ci    /* If zero, then disable Z compression/HiZ. */
379bf215546Sopenharmony_ci    unsigned zmask_dwords[R300_MAX_TEXTURE_LEVELS];
380bf215546Sopenharmony_ci    unsigned hiz_dwords[R300_MAX_TEXTURE_LEVELS];
381bf215546Sopenharmony_ci    /* Zmask/HiZ strides for each miplevel. */
382bf215546Sopenharmony_ci    unsigned zmask_stride_in_pixels[R300_MAX_TEXTURE_LEVELS];
383bf215546Sopenharmony_ci    unsigned hiz_stride_in_pixels[R300_MAX_TEXTURE_LEVELS];
384bf215546Sopenharmony_ci
385bf215546Sopenharmony_ci    /* CMASK info for AA buffers (no mipmapping). */
386bf215546Sopenharmony_ci    unsigned cmask_dwords;
387bf215546Sopenharmony_ci    unsigned cmask_stride_in_pixels;
388bf215546Sopenharmony_ci};
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_cistruct r300_resource
391bf215546Sopenharmony_ci{
392bf215546Sopenharmony_ci    struct pipe_resource b;
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ci    /* Winsys buffer backing this resource. */
395bf215546Sopenharmony_ci    struct pb_buffer *buf;
396bf215546Sopenharmony_ci    enum radeon_bo_domain domain;
397bf215546Sopenharmony_ci
398bf215546Sopenharmony_ci    /* Constant buffers and SWTCL vertex and index buffers are in user
399bf215546Sopenharmony_ci     * memory. */
400bf215546Sopenharmony_ci    uint8_t *malloced_buffer;
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ci    /* Texture description (addressing, layout, special features). */
403bf215546Sopenharmony_ci    struct r300_texture_desc tex;
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_ci    /* This is the level tiling flags were last time set for.
406bf215546Sopenharmony_ci     * It's used to prevent redundant tiling-flags changes from happening.*/
407bf215546Sopenharmony_ci    unsigned surface_level;
408bf215546Sopenharmony_ci};
409bf215546Sopenharmony_ci
410bf215546Sopenharmony_cistruct r300_vertex_element_state {
411bf215546Sopenharmony_ci    unsigned count;
412bf215546Sopenharmony_ci    struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
413bf215546Sopenharmony_ci    unsigned format_size[PIPE_MAX_ATTRIBS];
414bf215546Sopenharmony_ci
415bf215546Sopenharmony_ci    /* The size of the vertex, in dwords. */
416bf215546Sopenharmony_ci    unsigned vertex_size_dwords;
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_ci    struct r300_vertex_stream_state vertex_stream;
419bf215546Sopenharmony_ci};
420bf215546Sopenharmony_ci
421bf215546Sopenharmony_cienum r300_hiz_func {
422bf215546Sopenharmony_ci    HIZ_FUNC_NONE,
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_ci    /* The function, when determined, is set in stone
425bf215546Sopenharmony_ci     * until the next HiZ clear. */
426bf215546Sopenharmony_ci
427bf215546Sopenharmony_ci    /* MAX is written to the HiZ buffer.
428bf215546Sopenharmony_ci     * Used for LESS, LEQUAL. */
429bf215546Sopenharmony_ci    HIZ_FUNC_MAX,
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci    /* MIN is written to the HiZ buffer.
432bf215546Sopenharmony_ci     * Used for GREATER, GEQUAL. */
433bf215546Sopenharmony_ci    HIZ_FUNC_MIN,
434bf215546Sopenharmony_ci};
435bf215546Sopenharmony_ci
436bf215546Sopenharmony_ci/* For deferred fragment shader state validation. */
437bf215546Sopenharmony_cienum r300_fs_validity_status {
438bf215546Sopenharmony_ci    FRAGMENT_SHADER_VALID,      /* No need to change/validate the FS. */
439bf215546Sopenharmony_ci    FRAGMENT_SHADER_MAYBE_DIRTY,/* Validate the FS if external state was changed. */
440bf215546Sopenharmony_ci    FRAGMENT_SHADER_DIRTY       /* Always validate the FS (if the FS was changed) */
441bf215546Sopenharmony_ci};
442bf215546Sopenharmony_ci
443bf215546Sopenharmony_cistruct r300_context {
444bf215546Sopenharmony_ci    /* Parent class */
445bf215546Sopenharmony_ci    struct pipe_context context;
446bf215546Sopenharmony_ci
447bf215546Sopenharmony_ci    /* The interface to the windowing system, etc. */
448bf215546Sopenharmony_ci    struct radeon_winsys *rws;
449bf215546Sopenharmony_ci    /* The submission context. */
450bf215546Sopenharmony_ci    struct radeon_winsys_ctx *ctx;
451bf215546Sopenharmony_ci    /* The command stream. */
452bf215546Sopenharmony_ci    struct radeon_cmdbuf cs;
453bf215546Sopenharmony_ci    /* Screen. */
454bf215546Sopenharmony_ci    struct r300_screen *screen;
455bf215546Sopenharmony_ci
456bf215546Sopenharmony_ci    /* Draw module. Used mostly for SW TCL. */
457bf215546Sopenharmony_ci    struct draw_context* draw;
458bf215546Sopenharmony_ci    /* Vertex buffer for SW TCL. */
459bf215546Sopenharmony_ci    struct pb_buffer *vbo;
460bf215546Sopenharmony_ci    /* Offset and size into the SW TCL VBO. */
461bf215546Sopenharmony_ci    size_t draw_vbo_offset;
462bf215546Sopenharmony_ci
463bf215546Sopenharmony_ci    /* Accelerated blit support. */
464bf215546Sopenharmony_ci    struct blitter_context* blitter;
465bf215546Sopenharmony_ci    /* Stencil two-sided reference value fallback. */
466bf215546Sopenharmony_ci    struct r300_stencilref_context *stencilref_fallback;
467bf215546Sopenharmony_ci
468bf215546Sopenharmony_ci    /* The KIL opcode needs the first texture unit to be enabled
469bf215546Sopenharmony_ci     * on r3xx-r4xx. In order to calm down the CS checker, we bind this
470bf215546Sopenharmony_ci     * dummy texture there. */
471bf215546Sopenharmony_ci    struct r300_sampler_view *texkill_sampler;
472bf215546Sopenharmony_ci
473bf215546Sopenharmony_ci    /* When no vertex buffer is set, this one is used instead to prevent
474bf215546Sopenharmony_ci     * hardlocks. */
475bf215546Sopenharmony_ci    struct pipe_vertex_buffer dummy_vb;
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_ci    /* The currently active query. */
478bf215546Sopenharmony_ci    struct r300_query *query_current;
479bf215546Sopenharmony_ci    /* The saved query for blitter operations. */
480bf215546Sopenharmony_ci    struct r300_query *blitter_saved_query;
481bf215546Sopenharmony_ci    /* Query list. */
482bf215546Sopenharmony_ci    struct r300_query query_list;
483bf215546Sopenharmony_ci
484bf215546Sopenharmony_ci    /* Various CSO state objects. */
485bf215546Sopenharmony_ci
486bf215546Sopenharmony_ci    /* Each atom is emitted in the order it appears here, which can affect
487bf215546Sopenharmony_ci     * performance and stability if not handled with care. */
488bf215546Sopenharmony_ci    /* GPU flush. */
489bf215546Sopenharmony_ci    struct r300_atom gpu_flush;
490bf215546Sopenharmony_ci    /* Clears must be emitted immediately after the flush. */
491bf215546Sopenharmony_ci    /* HiZ clear */
492bf215546Sopenharmony_ci    struct r300_atom hiz_clear;
493bf215546Sopenharmony_ci    /* zmask clear */
494bf215546Sopenharmony_ci    struct r300_atom zmask_clear;
495bf215546Sopenharmony_ci    /* cmask clear */
496bf215546Sopenharmony_ci    struct r300_atom cmask_clear;
497bf215546Sopenharmony_ci    /* Anti-aliasing (MSAA) state. */
498bf215546Sopenharmony_ci    struct r300_atom aa_state;
499bf215546Sopenharmony_ci    /* Framebuffer state. */
500bf215546Sopenharmony_ci    struct r300_atom fb_state;
501bf215546Sopenharmony_ci    /* HyperZ state (various SC/ZB bits). */
502bf215546Sopenharmony_ci    struct r300_atom hyperz_state;
503bf215546Sopenharmony_ci    /* ZTOP state. */
504bf215546Sopenharmony_ci    struct r300_atom ztop_state;
505bf215546Sopenharmony_ci    /* Depth, stencil, and alpha state. */
506bf215546Sopenharmony_ci    struct r300_atom dsa_state;
507bf215546Sopenharmony_ci    /* Blend state. */
508bf215546Sopenharmony_ci    struct r300_atom blend_state;
509bf215546Sopenharmony_ci    /* Blend color state. */
510bf215546Sopenharmony_ci    struct r300_atom blend_color_state;
511bf215546Sopenharmony_ci    /* Scissor state. */
512bf215546Sopenharmony_ci    struct r300_atom scissor_state;
513bf215546Sopenharmony_ci    /* Sample mask. */
514bf215546Sopenharmony_ci    struct r300_atom sample_mask;
515bf215546Sopenharmony_ci    /* Invariant state. This must be emitted to get the engine started. */
516bf215546Sopenharmony_ci    struct r300_atom invariant_state;
517bf215546Sopenharmony_ci    /* Viewport state. */
518bf215546Sopenharmony_ci    struct r300_atom viewport_state;
519bf215546Sopenharmony_ci    /* PVS flush. */
520bf215546Sopenharmony_ci    struct r300_atom pvs_flush;
521bf215546Sopenharmony_ci    /* VAP invariant state. */
522bf215546Sopenharmony_ci    struct r300_atom vap_invariant_state;
523bf215546Sopenharmony_ci    /* Vertex stream formatting state. */
524bf215546Sopenharmony_ci    struct r300_atom vertex_stream_state;
525bf215546Sopenharmony_ci    /* Vertex shader. */
526bf215546Sopenharmony_ci    struct r300_atom vs_state;
527bf215546Sopenharmony_ci    /* User clip planes. */
528bf215546Sopenharmony_ci    struct r300_atom clip_state;
529bf215546Sopenharmony_ci    /* RS block state + VAP (vertex shader) output mapping state. */
530bf215546Sopenharmony_ci    struct r300_atom rs_block_state;
531bf215546Sopenharmony_ci    /* Rasterizer state. */
532bf215546Sopenharmony_ci    struct r300_atom rs_state;
533bf215546Sopenharmony_ci    /* Framebuffer state (pipelined regs). */
534bf215546Sopenharmony_ci    struct r300_atom fb_state_pipelined;
535bf215546Sopenharmony_ci    /* Fragment shader. */
536bf215546Sopenharmony_ci    struct r300_atom fs;
537bf215546Sopenharmony_ci    /* Fragment shader RC_CONSTANT_STATE variables. */
538bf215546Sopenharmony_ci    struct r300_atom fs_rc_constant_state;
539bf215546Sopenharmony_ci    /* Fragment shader constant buffer. */
540bf215546Sopenharmony_ci    struct r300_atom fs_constants;
541bf215546Sopenharmony_ci    /* Vertex shader constant buffer. */
542bf215546Sopenharmony_ci    struct r300_atom vs_constants;
543bf215546Sopenharmony_ci    /* Texture cache invalidate. */
544bf215546Sopenharmony_ci    struct r300_atom texture_cache_inval;
545bf215546Sopenharmony_ci    /* Textures state. */
546bf215546Sopenharmony_ci    struct r300_atom textures_state;
547bf215546Sopenharmony_ci    /* Occlusion query. */
548bf215546Sopenharmony_ci    struct r300_atom query_start;
549bf215546Sopenharmony_ci
550bf215546Sopenharmony_ci    struct util_debug_callback debug;
551bf215546Sopenharmony_ci
552bf215546Sopenharmony_ci    /* The pointers to the first and the last atom. */
553bf215546Sopenharmony_ci    struct r300_atom *first_dirty, *last_dirty;
554bf215546Sopenharmony_ci
555bf215546Sopenharmony_ci    /* Vertex elements for Gallium. */
556bf215546Sopenharmony_ci    struct r300_vertex_element_state *velems;
557bf215546Sopenharmony_ci
558bf215546Sopenharmony_ci    /* Vertex info for Draw. */
559bf215546Sopenharmony_ci    struct vertex_info vertex_info;
560bf215546Sopenharmony_ci
561bf215546Sopenharmony_ci    struct pipe_stencil_ref stencil_ref;
562bf215546Sopenharmony_ci    struct pipe_viewport_state viewport;
563bf215546Sopenharmony_ci
564bf215546Sopenharmony_ci    /* Stream locations for SWTCL. */
565bf215546Sopenharmony_ci    int stream_loc_notcl[16];
566bf215546Sopenharmony_ci
567bf215546Sopenharmony_ci    /* Flag indicating whether or not the HW is dirty. */
568bf215546Sopenharmony_ci    uint32_t dirty_hw;
569bf215546Sopenharmony_ci    /* Whether polygon offset is enabled. */
570bf215546Sopenharmony_ci    boolean polygon_offset_enabled;
571bf215546Sopenharmony_ci    /* Z buffer bit depth. */
572bf215546Sopenharmony_ci    uint32_t zbuffer_bpp;
573bf215546Sopenharmony_ci    /* Whether rendering is conditional and should be skipped. */
574bf215546Sopenharmony_ci    boolean skip_rendering;
575bf215546Sopenharmony_ci    /* The flag above saved by blitter. */
576bf215546Sopenharmony_ci    unsigned char blitter_saved_skip_rendering;
577bf215546Sopenharmony_ci    /* Point sprites texcoord index,  1 bit per texcoord */
578bf215546Sopenharmony_ci    int sprite_coord_enable;
579bf215546Sopenharmony_ci    /* Whether we are drawing points, to disable sprite coord if not */
580bf215546Sopenharmony_ci    boolean is_point;
581bf215546Sopenharmony_ci    /* Whether two-sided color selection is enabled (AKA light_twoside). */
582bf215546Sopenharmony_ci    boolean two_sided_color;
583bf215546Sopenharmony_ci    boolean flatshade;
584bf215546Sopenharmony_ci    boolean clip_halfz;
585bf215546Sopenharmony_ci    /* Whether fast color clear is enabled. */
586bf215546Sopenharmony_ci    boolean cbzb_clear;
587bf215546Sopenharmony_ci    /* Whether fragment shader needs to be validated. */
588bf215546Sopenharmony_ci    enum r300_fs_validity_status fs_status;
589bf215546Sopenharmony_ci    /* Framebuffer multi-write. */
590bf215546Sopenharmony_ci    boolean fb_multiwrite;
591bf215546Sopenharmony_ci    unsigned num_samples;
592bf215546Sopenharmony_ci    boolean msaa_enable;
593bf215546Sopenharmony_ci    boolean alpha_to_one;
594bf215546Sopenharmony_ci    boolean alpha_to_coverage;
595bf215546Sopenharmony_ci
596bf215546Sopenharmony_ci    void *dsa_decompress_zmask;
597bf215546Sopenharmony_ci
598bf215546Sopenharmony_ci    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
599bf215546Sopenharmony_ci    unsigned nr_vertex_buffers;
600bf215546Sopenharmony_ci    struct u_upload_mgr *uploader;
601bf215546Sopenharmony_ci
602bf215546Sopenharmony_ci    struct slab_child_pool pool_transfers;
603bf215546Sopenharmony_ci
604bf215546Sopenharmony_ci    /* Stat counter. */
605bf215546Sopenharmony_ci    uint64_t flush_counter;
606bf215546Sopenharmony_ci
607bf215546Sopenharmony_ci    /* const tracking for VS */
608bf215546Sopenharmony_ci    int vs_const_base;
609bf215546Sopenharmony_ci
610bf215546Sopenharmony_ci    /* Vertex array state info */
611bf215546Sopenharmony_ci    boolean vertex_arrays_dirty;
612bf215546Sopenharmony_ci    boolean vertex_arrays_indexed;
613bf215546Sopenharmony_ci    int vertex_arrays_offset;
614bf215546Sopenharmony_ci    int vertex_arrays_instance_id;
615bf215546Sopenharmony_ci    boolean instancing_enabled;
616bf215546Sopenharmony_ci
617bf215546Sopenharmony_ci    /* Hyper-Z stats. */
618bf215546Sopenharmony_ci    boolean hyperz_enabled;     /* Whether it owns Hyper-Z access. */
619bf215546Sopenharmony_ci    int64_t hyperz_time_of_last_flush; /* Time of the last flush with Z clear. */
620bf215546Sopenharmony_ci    unsigned num_z_clears;      /* Since the last flush. */
621bf215546Sopenharmony_ci
622bf215546Sopenharmony_ci    /* ZMask state. */
623bf215546Sopenharmony_ci    boolean zmask_in_use;       /* Whether ZMASK is enabled. */
624bf215546Sopenharmony_ci    boolean zmask_decompress;   /* Whether ZMASK is being decompressed. */
625bf215546Sopenharmony_ci    struct pipe_surface *locked_zbuffer; /* Unbound zbuffer which still has data in ZMASK. */
626bf215546Sopenharmony_ci
627bf215546Sopenharmony_ci    /* HiZ state. */
628bf215546Sopenharmony_ci    boolean hiz_in_use;         /* Whether HIZ is enabled. */
629bf215546Sopenharmony_ci    enum r300_hiz_func hiz_func; /* HiZ function. Can be either MIN or MAX. */
630bf215546Sopenharmony_ci    uint32_t hiz_clear_value;   /* HiZ clear value. */
631bf215546Sopenharmony_ci
632bf215546Sopenharmony_ci    /* CMASK state. */
633bf215546Sopenharmony_ci    boolean cmask_access;
634bf215546Sopenharmony_ci    boolean cmask_in_use;
635bf215546Sopenharmony_ci    uint32_t color_clear_value; /* RGBA8 or RGBA1010102 */
636bf215546Sopenharmony_ci    uint32_t color_clear_value_ar; /* RGBA16F */
637bf215546Sopenharmony_ci    uint32_t color_clear_value_gb; /* RGBA16F */
638bf215546Sopenharmony_ci
639bf215546Sopenharmony_ci    /* Compiler state. */
640bf215546Sopenharmony_ci    struct rc_regalloc_state fs_regalloc_state; /* Register allocator info for
641bf215546Sopenharmony_ci                                                 * fragment shaders. */
642bf215546Sopenharmony_ci};
643bf215546Sopenharmony_ci
644bf215546Sopenharmony_ci#define foreach_atom(r300, atom) \
645bf215546Sopenharmony_ci    for (atom = &r300->gpu_flush; atom != (&r300->query_start)+1; atom++)
646bf215546Sopenharmony_ci
647bf215546Sopenharmony_ci#define foreach_dirty_atom(r300, atom) \
648bf215546Sopenharmony_ci    for (atom = r300->first_dirty; atom != r300->last_dirty; atom++)
649bf215546Sopenharmony_ci
650bf215546Sopenharmony_ci/* Convenience cast wrappers. */
651bf215546Sopenharmony_cistatic inline struct r300_query* r300_query(struct pipe_query* q)
652bf215546Sopenharmony_ci{
653bf215546Sopenharmony_ci    return (struct r300_query*)q;
654bf215546Sopenharmony_ci}
655bf215546Sopenharmony_ci
656bf215546Sopenharmony_cistatic inline struct r300_surface* r300_surface(struct pipe_surface* surf)
657bf215546Sopenharmony_ci{
658bf215546Sopenharmony_ci    return (struct r300_surface*)surf;
659bf215546Sopenharmony_ci}
660bf215546Sopenharmony_ci
661bf215546Sopenharmony_cistatic inline struct r300_resource* r300_resource(struct pipe_resource* tex)
662bf215546Sopenharmony_ci{
663bf215546Sopenharmony_ci    return (struct r300_resource*)tex;
664bf215546Sopenharmony_ci}
665bf215546Sopenharmony_ci
666bf215546Sopenharmony_cistatic inline struct r300_context* r300_context(struct pipe_context* context)
667bf215546Sopenharmony_ci{
668bf215546Sopenharmony_ci    return (struct r300_context*)context;
669bf215546Sopenharmony_ci}
670bf215546Sopenharmony_ci
671bf215546Sopenharmony_cistatic inline struct r300_fragment_shader *r300_fs(struct r300_context *r300)
672bf215546Sopenharmony_ci{
673bf215546Sopenharmony_ci    return (struct r300_fragment_shader*)r300->fs.state;
674bf215546Sopenharmony_ci}
675bf215546Sopenharmony_ci
676bf215546Sopenharmony_cistatic inline struct r300_vertex_shader *r300_vs(struct r300_context *r300)
677bf215546Sopenharmony_ci{
678bf215546Sopenharmony_ci    return (struct r300_vertex_shader*)r300->vs_state.state;
679bf215546Sopenharmony_ci}
680bf215546Sopenharmony_ci
681bf215546Sopenharmony_cistatic inline void r300_mark_atom_dirty(struct r300_context *r300,
682bf215546Sopenharmony_ci                                        struct r300_atom *atom)
683bf215546Sopenharmony_ci{
684bf215546Sopenharmony_ci    atom->dirty = TRUE;
685bf215546Sopenharmony_ci
686bf215546Sopenharmony_ci    if (!r300->first_dirty) {
687bf215546Sopenharmony_ci        r300->first_dirty = atom;
688bf215546Sopenharmony_ci        r300->last_dirty = atom+1;
689bf215546Sopenharmony_ci    } else {
690bf215546Sopenharmony_ci        if (atom < r300->first_dirty)
691bf215546Sopenharmony_ci            r300->first_dirty = atom;
692bf215546Sopenharmony_ci        else if (atom+1 > r300->last_dirty)
693bf215546Sopenharmony_ci            r300->last_dirty = atom+1;
694bf215546Sopenharmony_ci    }
695bf215546Sopenharmony_ci}
696bf215546Sopenharmony_ci
697bf215546Sopenharmony_cistatic inline struct pipe_surface *
698bf215546Sopenharmony_cir300_get_nonnull_cb(struct pipe_framebuffer_state *fb, unsigned i)
699bf215546Sopenharmony_ci{
700bf215546Sopenharmony_ci    if (fb->cbufs[i])
701bf215546Sopenharmony_ci        return fb->cbufs[i];
702bf215546Sopenharmony_ci
703bf215546Sopenharmony_ci    /* The i-th framebuffer is NULL, return any non-NULL one. */
704bf215546Sopenharmony_ci    for (i = 0; i < fb->nr_cbufs; i++)
705bf215546Sopenharmony_ci        if (fb->cbufs[i])
706bf215546Sopenharmony_ci            return fb->cbufs[i];
707bf215546Sopenharmony_ci
708bf215546Sopenharmony_ci    return NULL;
709bf215546Sopenharmony_ci}
710bf215546Sopenharmony_ci
711bf215546Sopenharmony_cistruct pipe_context* r300_create_context(struct pipe_screen* screen,
712bf215546Sopenharmony_ci                                         void *priv, unsigned flags);
713bf215546Sopenharmony_ci
714bf215546Sopenharmony_ci/* Context initialization. */
715bf215546Sopenharmony_cistruct draw_stage* r300_draw_stage(struct r300_context* r300);
716bf215546Sopenharmony_civoid r300_init_blit_functions(struct r300_context *r300);
717bf215546Sopenharmony_civoid r300_init_flush_functions(struct r300_context* r300);
718bf215546Sopenharmony_civoid r300_init_query_functions(struct r300_context* r300);
719bf215546Sopenharmony_civoid r300_init_render_functions(struct r300_context *r300);
720bf215546Sopenharmony_civoid r300_init_state_functions(struct r300_context* r300);
721bf215546Sopenharmony_civoid r300_init_resource_functions(struct r300_context* r300);
722bf215546Sopenharmony_ci
723bf215546Sopenharmony_ci/* r300_blit.c */
724bf215546Sopenharmony_civoid r300_decompress_zmask(struct r300_context *r300);
725bf215546Sopenharmony_civoid r300_decompress_zmask_locked_unsafe(struct r300_context *r300);
726bf215546Sopenharmony_civoid r300_decompress_zmask_locked(struct r300_context *r300);
727bf215546Sopenharmony_cibool r300_is_blit_supported(enum pipe_format format);
728bf215546Sopenharmony_ci
729bf215546Sopenharmony_ci/* r300_flush.c */
730bf215546Sopenharmony_civoid r300_flush(struct pipe_context *pipe,
731bf215546Sopenharmony_ci                unsigned flags,
732bf215546Sopenharmony_ci                struct pipe_fence_handle **fence);
733bf215546Sopenharmony_ci
734bf215546Sopenharmony_ci/* r300_hyperz.c */
735bf215546Sopenharmony_civoid r300_update_hyperz_state(struct r300_context* r300);
736bf215546Sopenharmony_ci
737bf215546Sopenharmony_ci/* r300_query.c */
738bf215546Sopenharmony_civoid r300_resume_query(struct r300_context *r300,
739bf215546Sopenharmony_ci                       struct r300_query *query);
740bf215546Sopenharmony_civoid r300_stop_query(struct r300_context *r300);
741bf215546Sopenharmony_ci
742bf215546Sopenharmony_ci/* r300_render_translate.c */
743bf215546Sopenharmony_civoid r300_translate_index_buffer(struct r300_context *r300,
744bf215546Sopenharmony_ci                                 const struct pipe_draw_info *info,
745bf215546Sopenharmony_ci                                 struct pipe_resource **out_index_buffer,
746bf215546Sopenharmony_ci                                 unsigned *index_size, unsigned index_offset,
747bf215546Sopenharmony_ci                                 unsigned *start, unsigned count);
748bf215546Sopenharmony_ci
749bf215546Sopenharmony_ci/* r300_render_stencilref.c */
750bf215546Sopenharmony_civoid r300_plug_in_stencil_ref_fallback(struct r300_context *r300);
751bf215546Sopenharmony_ci
752bf215546Sopenharmony_ci/* r300_render.c */
753bf215546Sopenharmony_civoid r500_emit_index_bias(struct r300_context *r300, int index_bias);
754bf215546Sopenharmony_civoid r300_blitter_draw_rectangle(struct blitter_context *blitter,
755bf215546Sopenharmony_ci                                 void *vertex_elements_cso,
756bf215546Sopenharmony_ci                                 blitter_get_vs_func get_vs,
757bf215546Sopenharmony_ci                                 int x1, int y1, int x2, int y2,
758bf215546Sopenharmony_ci                                 float depth, unsigned num_instances,
759bf215546Sopenharmony_ci                                 enum blitter_attrib_type type,
760bf215546Sopenharmony_ci                                 const union blitter_attrib *attrib);
761bf215546Sopenharmony_ci
762bf215546Sopenharmony_ci/* r300_state.c */
763bf215546Sopenharmony_cienum r300_fb_state_change {
764bf215546Sopenharmony_ci    R300_CHANGED_FB_STATE = 0,
765bf215546Sopenharmony_ci    R300_CHANGED_HYPERZ_FLAG,
766bf215546Sopenharmony_ci    R300_CHANGED_MULTIWRITE,
767bf215546Sopenharmony_ci    R300_CHANGED_CMASK_ENABLE,
768bf215546Sopenharmony_ci};
769bf215546Sopenharmony_ci
770bf215546Sopenharmony_civoid r300_mark_fb_state_dirty(struct r300_context *r300,
771bf215546Sopenharmony_ci                              enum r300_fb_state_change change);
772bf215546Sopenharmony_civoid r300_mark_fs_code_dirty(struct r300_context *r300);
773bf215546Sopenharmony_ci
774bf215546Sopenharmony_cistruct pipe_sampler_view *
775bf215546Sopenharmony_cir300_create_sampler_view_custom(struct pipe_context *pipe,
776bf215546Sopenharmony_ci                         struct pipe_resource *texture,
777bf215546Sopenharmony_ci                         const struct pipe_sampler_view *templ,
778bf215546Sopenharmony_ci                         unsigned width0_override,
779bf215546Sopenharmony_ci                         unsigned height0_override);
780bf215546Sopenharmony_ci
781bf215546Sopenharmony_ci/* r300_state_derived.c */
782bf215546Sopenharmony_civoid r300_update_derived_state(struct r300_context* r300);
783bf215546Sopenharmony_ci
784bf215546Sopenharmony_ci/* r300_debug.c */
785bf215546Sopenharmony_civoid r500_dump_rs_block(struct r300_rs_block *rs);
786bf215546Sopenharmony_ci
787bf215546Sopenharmony_ci
788bf215546Sopenharmony_cistatic inline boolean CTX_DBG_ON(struct r300_context * ctx, unsigned flags)
789bf215546Sopenharmony_ci{
790bf215546Sopenharmony_ci    return SCREEN_DBG_ON(ctx->screen, flags);
791bf215546Sopenharmony_ci}
792bf215546Sopenharmony_ci
793bf215546Sopenharmony_cistatic inline void CTX_DBG(struct r300_context * ctx, unsigned flags,
794bf215546Sopenharmony_ci                       const char * fmt, ...)
795bf215546Sopenharmony_ci{
796bf215546Sopenharmony_ci    if (CTX_DBG_ON(ctx, flags)) {
797bf215546Sopenharmony_ci        va_list va;
798bf215546Sopenharmony_ci        va_start(va, fmt);
799bf215546Sopenharmony_ci        vfprintf(stderr, fmt, va);
800bf215546Sopenharmony_ci        va_end(va);
801bf215546Sopenharmony_ci    }
802bf215546Sopenharmony_ci}
803bf215546Sopenharmony_ci
804bf215546Sopenharmony_ci#define DBG_ON  CTX_DBG_ON
805bf215546Sopenharmony_ci#define DBG     CTX_DBG
806bf215546Sopenharmony_ci
807bf215546Sopenharmony_ci#endif /* R300_CONTEXT_H */
808