1 /**************************************************************************
3 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Copyright 2008 VMware, Inc.
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:
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
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.
26 **************************************************************************/
31 #include "pipe/p_context.h"
32 #include "pipe/p_state.h"
33 #include "pipe/p_screen.h"
35 #include "os/os_thread.h"
39 DD_DETECT_HANGS_PIPELINED
,
41 DD_DUMP_APITRACE_CALL
,
46 struct pipe_screen base
;
47 struct pipe_screen
*screen
;
53 unsigned apitrace_dump_call
;
60 CALL_RESOURCE_COPY_REGION
,
66 CALL_CLEAR_RENDER_TARGET
,
67 CALL_CLEAR_DEPTH_STENCIL
,
71 struct call_resource_copy_region
73 struct pipe_resource
*dst
;
75 unsigned dstx
, dsty
, dstz
;
76 struct pipe_resource
*src
;
78 struct pipe_box src_box
;
84 union pipe_color_union color
;
89 struct call_clear_buffer
91 struct pipe_resource
*res
;
94 const void *clear_value
;
98 struct call_generate_mipmap
{
99 struct pipe_resource
*res
;
100 enum pipe_format format
;
103 unsigned first_layer
;
107 struct call_draw_info
{
108 struct pipe_draw_info draw
;
109 struct pipe_draw_indirect_info indirect
;
117 struct call_draw_info draw_vbo
;
118 struct pipe_grid_info launch_grid
;
119 struct call_resource_copy_region resource_copy_region
;
120 struct pipe_blit_info blit
;
121 struct pipe_resource
*flush_resource
;
122 struct call_clear clear
;
123 struct call_clear_buffer clear_buffer
;
124 struct call_generate_mipmap generate_mipmap
;
131 struct pipe_query
*query
;
139 struct pipe_blend_state blend
;
140 struct pipe_depth_stencil_alpha_state dsa
;
141 struct pipe_rasterizer_state rs
;
142 struct pipe_sampler_state sampler
;
144 struct pipe_vertex_element velems
[PIPE_MAX_ATTRIBS
];
147 struct pipe_shader_state shader
;
154 struct dd_query
*query
;
159 struct pipe_vertex_buffer vertex_buffers
[PIPE_MAX_ATTRIBS
];
161 unsigned num_so_targets
;
162 struct pipe_stream_output_target
*so_targets
[PIPE_MAX_SO_BUFFERS
];
163 unsigned so_offsets
[PIPE_MAX_SO_BUFFERS
];
165 struct dd_state
*shaders
[PIPE_SHADER_TYPES
];
166 struct pipe_constant_buffer constant_buffers
[PIPE_SHADER_TYPES
][PIPE_MAX_CONSTANT_BUFFERS
];
167 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
168 struct dd_state
*sampler_states
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
169 struct pipe_image_view shader_images
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_IMAGES
];
170 struct pipe_shader_buffer shader_buffers
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_BUFFERS
];
172 struct dd_state
*velems
;
174 struct dd_state
*dsa
;
175 struct dd_state
*blend
;
177 struct pipe_blend_color blend_color
;
178 struct pipe_stencil_ref stencil_ref
;
179 unsigned sample_mask
;
180 unsigned min_samples
;
181 struct pipe_clip_state clip_state
;
182 struct pipe_framebuffer_state framebuffer_state
;
183 struct pipe_poly_stipple polygon_stipple
;
184 struct pipe_scissor_state scissors
[PIPE_MAX_VIEWPORTS
];
185 struct pipe_viewport_state viewports
[PIPE_MAX_VIEWPORTS
];
186 float tess_default_levels
[6];
188 unsigned apitrace_call_number
;
191 struct dd_draw_state_copy
193 struct dd_draw_state base
;
195 /* dd_draw_state_copy does not reference real CSOs. Instead, it points to
196 * these variables, which serve as storage.
198 struct dd_query render_cond
;
199 struct dd_state shaders
[PIPE_SHADER_TYPES
];
200 struct dd_state sampler_states
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
201 struct dd_state velems
;
204 struct dd_state blend
;
207 struct dd_draw_record
{
208 struct dd_draw_record
*next
;
211 uint32_t sequence_no
;
214 struct dd_draw_state_copy draw_state
;
215 char *driver_state_log
;
220 struct pipe_context base
;
221 struct pipe_context
*pipe
;
223 struct dd_draw_state draw_state
;
224 unsigned num_draw_calls
;
226 /* Pipelined hang detection.
228 * This is without unnecessary flushes and waits. There is a memory-based
229 * fence that is incremented by clear_buffer every draw call. Driver fences
232 * After each draw call, a new dd_draw_record is created that contains
233 * a copy of all states, the output of pipe_context::dump_debug_state,
234 * and it has a fence number assigned. That's done without knowing whether
235 * that draw call is problematic or not. The record is added into the list
238 * An independent, separate thread loops over the list of records and checks
239 * their fences. Records with signalled fences are freed. On fence timeout,
240 * the thread dumps the record of the oldest unsignalled fence.
245 struct pipe_resource
*fence
;
246 struct pipe_transfer
*fence_transfer
;
247 uint32_t *mapped_fence
;
248 uint32_t sequence_no
;
249 struct dd_draw_record
*records
;
250 int max_log_buffer_size
;
254 struct pipe_context
*
255 dd_context_create(struct dd_screen
*dscreen
, struct pipe_context
*pipe
);
258 dd_init_draw_functions(struct dd_context
*dctx
);
260 dd_thread_pipelined_hang_detect(void *input
);
263 static inline struct dd_context
*
264 dd_context(struct pipe_context
*pipe
)
266 return (struct dd_context
*)pipe
;
269 static inline struct dd_screen
*
270 dd_screen(struct pipe_screen
*screen
)
272 return (struct dd_screen
*)screen
;
276 #define CTX_INIT(_member) \
277 dctx->base._member = dctx->pipe->_member ? dd_context_##_member : NULL