summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/r300/r300_cs.h
blob: 6726f100e1b9ae562123e78582d29b487d60f047 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE. */

/**
 * This file contains macros for immediate command submission.
 */

#ifndef R300_CS_H
#define R300_CS_H

#include "r300_reg.h"
#include "r300_context.h"
#include "r300_winsys.h"

/* Yes, I know macros are ugly. However, they are much prettier than the code
 * that they neatly hide away, and don't have the cost of function setup,so
 * we're going to use them. */

#ifdef DEBUG
#define CS_DEBUG(x) x
#else
#define CS_DEBUG(x)
#endif

/**
 * Command submission setup.
 */

#define CS_LOCALS(context) \
    struct r300_winsys_cs *cs_copy = (context)->cs; \
    struct r300_winsys_screen *cs_winsys = (context)->rws; \
    int cs_count = 0; (void) cs_count; (void) cs_winsys;

#define BEGIN_CS(size) do { \
    assert(size <= (R300_MAX_CMDBUF_DWORDS - cs_copy->cdw)); \
    CS_DEBUG(cs_count = size;) \
} while (0)

#ifdef DEBUG
#define END_CS do { \
    if (cs_count != 0) \
        debug_printf("r300: Warning: cs_count off by %d at (%s, %s:%i)\n", \
                     cs_count, __FUNCTION__, __FILE__, __LINE__); \
    cs_count = 0; \
} while (0)
#else
#define END_CS
#endif


/**
 * Writing pure DWORDs.
 */

#define OUT_CS(value) do { \
    cs_copy->buf[cs_copy->cdw++] = (value); \
    CS_DEBUG(cs_count--;) \
} while (0)

#define OUT_CS_32F(value) \
    OUT_CS(fui(value))

#define OUT_CS_REG(register, value) do { \
    OUT_CS(CP_PACKET0(register, 0)); \
    OUT_CS(value); \
} while (0)

/* Note: This expects count to be the number of registers,
 * not the actual packet0 count! */
#define OUT_CS_REG_SEQ(register, count) \
    OUT_CS(CP_PACKET0((register), ((count) - 1)))

#define OUT_CS_ONE_REG(register, count) \
    OUT_CS(CP_PACKET0((register), ((count) - 1)) | RADEON_ONE_REG_WR)

#define OUT_CS_PKT3(op, count) \
    OUT_CS(CP_PACKET3(op, count))

#define OUT_CS_TABLE(values, count) do { \
    memcpy(cs_copy->buf + cs_copy->cdw, values, count * 4); \
    cs_copy->cdw += count; \
    CS_DEBUG(cs_count -= count;) \
} while (0)


/**
 * Writing relocations.
 */

#define OUT_CS_RELOC(bo, offset) do { \
    assert(bo); \
    OUT_CS(offset); \
    cs_winsys->cs_write_reloc(cs_copy, bo); \
    CS_DEBUG(cs_count -= 2;) \
} while (0)

#define OUT_CS_BUF_RELOC(bo, offset) do { \
    assert(bo); \
    OUT_CS_RELOC(r300_buffer(bo)->cs_buf, offset); \
} while (0)

#define OUT_CS_TEX_RELOC(tex, offset) do { \
    assert(tex); \
    OUT_CS_RELOC(tex->cs_buffer, offset); \
} while (0)

#define OUT_CS_BUF_RELOC_NO_OFFSET(bo) do { \
    assert(bo); \
    cs_winsys->cs_write_reloc(cs_copy, r300_buffer(bo)->cs_buf); \
    CS_DEBUG(cs_count -= 2;) \
} while (0)


/**
 * Command buffer emission.
 */

#define WRITE_CS_TABLE(values, count) do { \
    CS_DEBUG(assert(cs_count == 0);) \
    memcpy(cs_copy->buf + cs_copy->cdw, (values), (count) * 4); \
    cs_copy->cdw += (count); \
} while (0)

#endif /* R300_CS_H */