summaryrefslogtreecommitdiff
path: root/r600_lib.h
blob: 2a0ab3cb67cb57c3bf76fd9301c7f9dc8a62121d (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * r600_demo
 *
 * Copyright (C) 2008-2009  Matthias Hopf
 *
 * Based on r300_demo,
 * Copyright (C) various authors
 *
 * 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
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * 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 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 NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) 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.
 */

#ifndef __R600_LIB_H__
#define __R600_LIB_H__

/*
 * Helper routines, to be split up
 */

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>


#if __SIZEOF_LONG__ == 8
#  define PRINTF_INT64		"%ld"
#  define PRINTF_UINT64		"%lu"
#  define PRINTF_UINT64_HEX	"%010lx"		/* Yes, 64bit need 16 characters, but typically 10 are enough (mostly addresses) */
#else
#  define PRINTF_INT64		"%lld"
#  define PRINTF_UINT64		"%llu"
#  define PRINTF_UINT64_HEX	"%010llx"
#endif


#define CLEAR(x) memset (&x, 0, sizeof(x))


/* Options */
extern int verbose;
extern int use_ring_directly;
extern int vertex_format;
extern int vertex_load_as_int;
extern int vertex_unsigned;
extern int vertex_alu_scale_override;
extern int do_not_flush;


enum chipset_e {
    CHIPSET_NONE = 0,
    CHIPSET_R600,
    CHIPSET_RV610, CHIPSET_RV620,				// no VC
    CHIPSET_RS780, CHIPSET_M72, CHIPSET_M74, CHIPSET_M82,	// no VC
    CHIPSET_RV630, CHIPSET_RV635, CHIPSET_RV670,
    CHIPSET_RV770,
    CHIPSET_RV710,						// no VC
    CHIPSET_RV730
};

/* TODO: Should go to _hwapi.h, probably renamed context_t */
typedef struct {
    int chipID;
    enum chipset_e chipset;

    void    *framebuffer;
    uint64_t framebuffer_gpu;
    uint64_t framebuffer_size;

    void    *display;
    uint64_t display_gpu;
    uint32_t display_pitch;
    uint32_t display_width;
    uint32_t display_height;

    uint64_t color_gpu;
    uint32_t color_pitch;
    uint32_t color_height;
    
    void    *free_cpu;
    uint64_t free_gpu;
} adapter_t;

/* TODO: Should go to _hwapi.h, probably moved to adapter_t / context_t */
/* Buffers of at least 64000 bytes, for vertices and textures */
/* should be allocated in garttex, but due to bugs in DRM currently in buffer space */
/* pointers are CPU space, uint64 values GPU space */
extern uint32_t  *vtx, *tex;
extern uint64_t  vtx_gpu, tex_gpu;


void flush_gpu_source_cache (adapter_t *adapt, uint32_t type, uint64_t lower, uint64_t upper);
void flush_gpu_dest_cache   (adapter_t *adapt, uint32_t type, uint64_t lower, uint64_t upper);

#define FLUSH_GPU_INPUT_TYPE_ALL (TC_ACTION_ENA_bit | VC_ACTION_ENA_bit | \
				  CB_ACTION_ENA_bit | DB_ACTION_ENA_bit | \
				  SH_ACTION_ENA_bit | SMX_ACTION_ENA_bit)
#define FLUSH_GPU_ALL_SOURCE_CACHE(adapt) flush_gpu_source_cache (adapt, FLUSH_GPU_INPUT_TYPE_ALL, 0, 0xffffffff00ULL)

// Store shaders/buffers in GPU or GART (system) memory
// In the GPU case buffers are stored after front buffer
#define upload upload_gart

uint64_t upload_gart (adapter_t *adapt, void *input, int size, int offset);
uint64_t upload_gpu  (adapter_t *adapt, void *input, int size, int offset);

void dump_shader (adapter_t *adapt, uint32_t *shader, int size, char *what);

/* FIXME: naming: this waits on the CPU, while the others let the CP wait only */
void wait_reg (adapter_t *adapt, uint32_t reg, uint32_t v, const char *when);
float wait_reg_time (adapter_t *adapt, uint32_t reg, uint32_t v, const char *when, float maxtime);
float time_flush_cmds (adapter_t *adapt, float maxtime);

void wait_3d_idle_clean(void);
void wait_3d_idle(void);
void wait_3d_full_idle_clean (void);
void emit_wait_for_vsync (adapter_t *adapt, int line);

void simple_clear (adapter_t* adapt);

void soft_reset (adapter_t *adapt);
void show_state (adapter_t *adapt);

void dump_register (adapter_t *adapt, uint32_t reg);
void write_register (adapter_t *adapt, uint32_t reg, uint32_t val);

uint32_t *create_sample_texture (int width, int height, int pitch);


/* Demos functions */
/* r600_basic.c : */
void test_cp            (adapter_t *);
void test_packets       (adapter_t *);
/* r600_triangles.c : */
void tri_test_2d        (adapter_t *);
void tri_test_3d        (adapter_t *);
void pm4play_tri_test   (adapter_t *);
void pm4play_clear_test (adapter_t *);
void pm4play_blit_test  (adapter_t *);
/* r600_texture.c : */
void quad_test_tex_scaled(adapter_t *);
void tmp_test           (adapter_t *);
/* r600_exa.c : */
void test_solid(adapter_t *adapt);
void test_copy(adapter_t *adapt);
/* r600_perf.c : */
void test_perf (adapter_t *, int textype, int alutype);


#endif