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"
36 #include "util/list.h"
37 #include "util/u_log.h"
38 #include "util/u_queue.h"
45 DD_DUMP_APITRACE_CALL
,
50 struct pipe_screen base
;
51 struct pipe_screen
*screen
;
53 enum dd_dump_mode dump_mode
;
58 unsigned apitrace_dump_call
;
66 CALL_RESOURCE_COPY_REGION
,
72 CALL_CLEAR_RENDER_TARGET
,
73 CALL_CLEAR_DEPTH_STENCIL
,
75 CALL_GET_QUERY_RESULT_RESOURCE
,
77 CALL_TRANSFER_FLUSH_REGION
,
83 struct call_resource_copy_region
85 struct pipe_resource
*dst
;
87 unsigned dstx
, dsty
, dstz
;
88 struct pipe_resource
*src
;
90 struct pipe_box src_box
;
96 union pipe_color_union color
;
101 struct call_clear_buffer
103 struct pipe_resource
*res
;
106 const void *clear_value
;
107 int clear_value_size
;
110 struct call_generate_mipmap
{
111 struct pipe_resource
*res
;
112 enum pipe_format format
;
115 unsigned first_layer
;
123 struct call_draw_info
{
124 struct pipe_draw_info draw
;
125 struct pipe_draw_indirect_info indirect
;
128 struct call_get_query_result_resource
{
129 struct pipe_query
*query
;
130 enum pipe_query_type query_type
;
132 enum pipe_query_value_type result_type
;
134 struct pipe_resource
*resource
;
138 struct call_transfer_map
{
139 struct pipe_transfer
*transfer_ptr
;
140 struct pipe_transfer transfer
;
144 struct call_transfer_flush_region
{
145 struct pipe_transfer
*transfer_ptr
;
146 struct pipe_transfer transfer
;
150 struct call_transfer_unmap
{
151 struct pipe_transfer
*transfer_ptr
;
152 struct pipe_transfer transfer
;
155 struct call_buffer_subdata
{
156 struct pipe_resource
*resource
;
163 struct call_texture_subdata
{
164 struct pipe_resource
*resource
;
170 unsigned layer_stride
;
178 struct call_flush flush
;
179 struct call_draw_info draw_vbo
;
180 struct pipe_grid_info launch_grid
;
181 struct call_resource_copy_region resource_copy_region
;
182 struct pipe_blit_info blit
;
183 struct pipe_resource
*flush_resource
;
184 struct call_clear clear
;
185 struct call_clear_buffer clear_buffer
;
186 struct call_generate_mipmap generate_mipmap
;
187 struct call_get_query_result_resource get_query_result_resource
;
188 struct call_transfer_map transfer_map
;
189 struct call_transfer_flush_region transfer_flush_region
;
190 struct call_transfer_unmap transfer_unmap
;
191 struct call_buffer_subdata buffer_subdata
;
192 struct call_texture_subdata texture_subdata
;
199 struct pipe_query
*query
;
207 struct pipe_blend_state blend
;
208 struct pipe_depth_stencil_alpha_state dsa
;
209 struct pipe_rasterizer_state rs
;
210 struct pipe_sampler_state sampler
;
212 struct pipe_vertex_element velems
[PIPE_MAX_ATTRIBS
];
215 struct pipe_shader_state shader
;
222 struct dd_query
*query
;
227 struct pipe_vertex_buffer vertex_buffers
[PIPE_MAX_ATTRIBS
];
229 unsigned num_so_targets
;
230 struct pipe_stream_output_target
*so_targets
[PIPE_MAX_SO_BUFFERS
];
231 unsigned so_offsets
[PIPE_MAX_SO_BUFFERS
];
233 struct dd_state
*shaders
[PIPE_SHADER_TYPES
];
234 struct pipe_constant_buffer constant_buffers
[PIPE_SHADER_TYPES
][PIPE_MAX_CONSTANT_BUFFERS
];
235 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
236 struct dd_state
*sampler_states
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
237 struct pipe_image_view shader_images
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_IMAGES
];
238 struct pipe_shader_buffer shader_buffers
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_BUFFERS
];
240 struct dd_state
*velems
;
242 struct dd_state
*dsa
;
243 struct dd_state
*blend
;
245 struct pipe_blend_color blend_color
;
246 struct pipe_stencil_ref stencil_ref
;
247 unsigned sample_mask
;
248 unsigned min_samples
;
249 struct pipe_clip_state clip_state
;
250 struct pipe_framebuffer_state framebuffer_state
;
251 struct pipe_poly_stipple polygon_stipple
;
252 struct pipe_scissor_state scissors
[PIPE_MAX_VIEWPORTS
];
253 struct pipe_viewport_state viewports
[PIPE_MAX_VIEWPORTS
];
254 float tess_default_levels
[6];
256 unsigned apitrace_call_number
;
259 struct dd_draw_state_copy
261 struct dd_draw_state base
;
263 /* dd_draw_state_copy does not reference real CSOs. Instead, it points to
264 * these variables, which serve as storage.
266 struct dd_query render_cond
;
267 struct dd_state shaders
[PIPE_SHADER_TYPES
];
268 struct dd_state sampler_states
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
269 struct dd_state velems
;
272 struct dd_state blend
;
275 struct dd_draw_record
{
276 struct list_head list
;
277 struct dd_context
*dctx
;
283 /* The fence pointers are guaranteed to be valid once driver_finished is signalled */
284 struct pipe_fence_handle
*prev_bottom_of_pipe
;
285 struct pipe_fence_handle
*top_of_pipe
;
286 struct pipe_fence_handle
*bottom_of_pipe
;
289 struct dd_draw_state_copy draw_state
;
291 struct util_queue_fence driver_finished
;
292 struct u_log_page
*log_page
;
297 struct pipe_context base
;
298 struct pipe_context
*pipe
;
300 struct dd_draw_state draw_state
;
301 unsigned num_draw_calls
;
303 struct u_log_context log
;
305 /* Pipelined hang detection.
307 * Before each draw call, a new dd_draw_record is created that contains
308 * a copy of all states. After each draw call, the driver's log is added
309 * to this record. Additionally, deferred fences are associated to each
310 * record both before and after the draw.
312 * The records are handed off to a separate thread which waits on the
313 * records' fences. Records with signalled fences are freed. When a timeout
314 * is detected, the thread dumps the records of in-flight draws.
319 struct list_head records
; /* oldest record first */
320 unsigned num_records
;
326 struct pipe_context
*
327 dd_context_create(struct dd_screen
*dscreen
, struct pipe_context
*pipe
);
330 dd_init_draw_functions(struct dd_context
*dctx
);
333 dd_thread_join(struct dd_context
*dctx
);
335 dd_thread_main(void *input
);
338 dd_get_file_stream(struct dd_screen
*dscreen
, unsigned apitrace_call_number
);
340 static inline struct dd_context
*
341 dd_context(struct pipe_context
*pipe
)
343 return (struct dd_context
*)pipe
;
346 static inline struct dd_screen
*
347 dd_screen(struct pipe_screen
*screen
)
349 return (struct dd_screen
*)screen
;
352 static inline struct dd_query
*
353 dd_query(struct pipe_query
*query
)
355 return (struct dd_query
*)query
;
358 static inline struct pipe_query
*
359 dd_query_unwrap(struct pipe_query
*query
)
362 return dd_query(query
)->query
;
369 #define CTX_INIT(_member) \
370 dctx->base._member = dctx->pipe->_member ? dd_context_##_member : NULL