5ba1b7a6d75a0ff3d204174e6736ff886eb5976b
[mesa.git] / src / gallium / drivers / ddebug / dd_pipe.h
1 /**************************************************************************
2 *
3 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Copyright 2008 VMware, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * on the rights to use, copy, modify, merge, publish, distribute, sub
11 * license, and/or sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
16 * Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef DD_H_
29 #define DD_H_
30
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
33 #include "pipe/p_screen.h"
34 #include "dd_util.h"
35
36 enum dd_mode {
37 DD_DETECT_HANGS,
38 DD_DUMP_ALL_CALLS,
39 DD_DUMP_APITRACE_CALL,
40 };
41
42 struct dd_screen
43 {
44 struct pipe_screen base;
45 struct pipe_screen *screen;
46 unsigned timeout_ms;
47 enum dd_mode mode;
48 bool no_flush;
49 bool verbose;
50 unsigned skip_count;
51 unsigned apitrace_dump_call;
52 };
53
54 enum call_type
55 {
56 CALL_DRAW_VBO,
57 CALL_LAUNCH_GRID,
58 CALL_RESOURCE_COPY_REGION,
59 CALL_BLIT,
60 CALL_FLUSH_RESOURCE,
61 CALL_CLEAR,
62 CALL_CLEAR_BUFFER,
63 CALL_CLEAR_RENDER_TARGET,
64 CALL_CLEAR_DEPTH_STENCIL,
65 CALL_GENERATE_MIPMAP,
66 };
67
68 struct call_resource_copy_region
69 {
70 struct pipe_resource *dst;
71 unsigned dst_level;
72 unsigned dstx, dsty, dstz;
73 struct pipe_resource *src;
74 unsigned src_level;
75 struct pipe_box src_box;
76 };
77
78 struct call_clear
79 {
80 unsigned buffers;
81 union pipe_color_union color;
82 double depth;
83 unsigned stencil;
84 };
85
86 struct call_clear_buffer
87 {
88 struct pipe_resource *res;
89 unsigned offset;
90 unsigned size;
91 const void *clear_value;
92 int clear_value_size;
93 };
94
95 struct call_generate_mipmap {
96 struct pipe_resource *res;
97 enum pipe_format format;
98 unsigned base_level;
99 unsigned last_level;
100 unsigned first_layer;
101 unsigned last_layer;
102 };
103
104 struct dd_call
105 {
106 enum call_type type;
107
108 union {
109 struct pipe_draw_info draw_vbo;
110 struct pipe_grid_info launch_grid;
111 struct call_resource_copy_region resource_copy_region;
112 struct pipe_blit_info blit;
113 struct pipe_resource *flush_resource;
114 struct call_clear clear;
115 struct call_clear_buffer clear_buffer;
116 struct call_generate_mipmap generate_mipmap;
117 } info;
118 };
119
120 struct dd_query
121 {
122 unsigned type;
123 struct pipe_query *query;
124 };
125
126 struct dd_state
127 {
128 void *cso;
129
130 union {
131 struct pipe_blend_state blend;
132 struct pipe_depth_stencil_alpha_state dsa;
133 struct pipe_rasterizer_state rs;
134 struct pipe_sampler_state sampler;
135 struct {
136 struct pipe_vertex_element velems[PIPE_MAX_ATTRIBS];
137 unsigned count;
138 } velems;
139 struct pipe_shader_state shader;
140 } state;
141 };
142
143 struct dd_draw_state
144 {
145 struct {
146 struct dd_query *query;
147 bool condition;
148 unsigned mode;
149 } render_cond;
150
151 struct pipe_index_buffer index_buffer;
152 struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
153
154 unsigned num_so_targets;
155 struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_BUFFERS];
156 unsigned so_offsets[PIPE_MAX_SO_BUFFERS];
157
158 struct dd_state *shaders[PIPE_SHADER_TYPES];
159 struct pipe_constant_buffer constant_buffers[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
160 struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
161 struct dd_state *sampler_states[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
162 struct pipe_image_view shader_images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
163 struct pipe_shader_buffer shader_buffers[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_BUFFERS];
164
165 struct dd_state *velems;
166 struct dd_state *rs;
167 struct dd_state *dsa;
168 struct dd_state *blend;
169
170 struct pipe_blend_color blend_color;
171 struct pipe_stencil_ref stencil_ref;
172 unsigned sample_mask;
173 unsigned min_samples;
174 struct pipe_clip_state clip_state;
175 struct pipe_framebuffer_state framebuffer_state;
176 struct pipe_poly_stipple polygon_stipple;
177 struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
178 struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
179 float tess_default_levels[6];
180
181 unsigned apitrace_call_number;
182 };
183
184 struct dd_context
185 {
186 struct pipe_context base;
187 struct pipe_context *pipe;
188
189 struct dd_draw_state draw_state;
190 unsigned num_draw_calls;
191 };
192
193
194 struct pipe_context *
195 dd_context_create(struct dd_screen *dscreen, struct pipe_context *pipe);
196
197 void
198 dd_init_draw_functions(struct dd_context *dctx);
199
200
201 static inline struct dd_context *
202 dd_context(struct pipe_context *pipe)
203 {
204 return (struct dd_context *)pipe;
205 }
206
207 static inline struct dd_screen *
208 dd_screen(struct pipe_screen *screen)
209 {
210 return (struct dd_screen*)screen;
211 }
212
213
214 #define CTX_INIT(_member) \
215 dctx->base._member = dctx->pipe->_member ? dd_context_##_member : NULL
216
217 #endif /* DD_H_ */