1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2015 Advanced Micro Devices, Inc. 4bf215546Sopenharmony_ci * Copyright 2008 VMware, Inc. 5bf215546Sopenharmony_ci * All Rights Reserved. 6bf215546Sopenharmony_ci * 7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 9bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 10bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 11bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 12bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 15bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 16bf215546Sopenharmony_ci * Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 22bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "dd_pipe.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci#include "util/u_dump.h" 31bf215546Sopenharmony_ci#include "util/format/u_format.h" 32bf215546Sopenharmony_ci#include "util/u_framebuffer.h" 33bf215546Sopenharmony_ci#include "util/u_helpers.h" 34bf215546Sopenharmony_ci#include "util/u_inlines.h" 35bf215546Sopenharmony_ci#include "util/u_memory.h" 36bf215546Sopenharmony_ci#include "util/u_process.h" 37bf215546Sopenharmony_ci#include "tgsi/tgsi_parse.h" 38bf215546Sopenharmony_ci#include "tgsi/tgsi_scan.h" 39bf215546Sopenharmony_ci#include "util/os_time.h" 40bf215546Sopenharmony_ci#include <inttypes.h> 41bf215546Sopenharmony_ci#include "pipe/p_config.h" 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_civoid 44bf215546Sopenharmony_cidd_get_debug_filename_and_mkdir(char *buf, size_t buflen, bool verbose) 45bf215546Sopenharmony_ci{ 46bf215546Sopenharmony_ci static unsigned index; 47bf215546Sopenharmony_ci char proc_name[128], dir[256]; 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci if (!os_get_process_name(proc_name, sizeof(proc_name))) { 50bf215546Sopenharmony_ci fprintf(stderr, "dd: can't get the process name\n"); 51bf215546Sopenharmony_ci strcpy(proc_name, "unknown"); 52bf215546Sopenharmony_ci } 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci snprintf(dir, sizeof(dir), "%s/"DD_DIR, debug_get_option("HOME", ".")); 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci if (mkdir(dir, 0774) && errno != EEXIST) 57bf215546Sopenharmony_ci fprintf(stderr, "dd: can't create a directory (%i)\n", errno); 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci snprintf(buf, buflen, "%s/%s_%u_%08u", dir, proc_name, (unsigned int)getpid(), 60bf215546Sopenharmony_ci (unsigned int)p_atomic_inc_return(&index) - 1); 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci if (verbose) 63bf215546Sopenharmony_ci fprintf(stderr, "dd: dumping to file %s\n", buf); 64bf215546Sopenharmony_ci} 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ciFILE * 67bf215546Sopenharmony_cidd_get_debug_file(bool verbose) 68bf215546Sopenharmony_ci{ 69bf215546Sopenharmony_ci char name[512]; 70bf215546Sopenharmony_ci FILE *f; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_ci dd_get_debug_filename_and_mkdir(name, sizeof(name), verbose); 73bf215546Sopenharmony_ci f = fopen(name, "w"); 74bf215546Sopenharmony_ci if (!f) { 75bf215546Sopenharmony_ci fprintf(stderr, "dd: can't open file %s\n", name); 76bf215546Sopenharmony_ci return NULL; 77bf215546Sopenharmony_ci } 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_ci return f; 80bf215546Sopenharmony_ci} 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_civoid 83bf215546Sopenharmony_cidd_parse_apitrace_marker(const char *string, int len, unsigned *call_number) 84bf215546Sopenharmony_ci{ 85bf215546Sopenharmony_ci unsigned num; 86bf215546Sopenharmony_ci char *s; 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci if (len <= 0) 89bf215546Sopenharmony_ci return; 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_ci /* Make it zero-terminated. */ 92bf215546Sopenharmony_ci s = alloca(len + 1); 93bf215546Sopenharmony_ci memcpy(s, string, len); 94bf215546Sopenharmony_ci s[len] = 0; 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci /* Parse the number. */ 97bf215546Sopenharmony_ci errno = 0; 98bf215546Sopenharmony_ci num = strtol(s, NULL, 10); 99bf215546Sopenharmony_ci if (errno) 100bf215546Sopenharmony_ci return; 101bf215546Sopenharmony_ci 102bf215546Sopenharmony_ci *call_number = num; 103bf215546Sopenharmony_ci} 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_civoid 106bf215546Sopenharmony_cidd_write_header(FILE *f, struct pipe_screen *screen, unsigned apitrace_call_number) 107bf215546Sopenharmony_ci{ 108bf215546Sopenharmony_ci char cmd_line[4096]; 109bf215546Sopenharmony_ci if (os_get_command_line(cmd_line, sizeof(cmd_line))) 110bf215546Sopenharmony_ci fprintf(f, "Command: %s\n", cmd_line); 111bf215546Sopenharmony_ci fprintf(f, "Driver vendor: %s\n", screen->get_vendor(screen)); 112bf215546Sopenharmony_ci fprintf(f, "Device vendor: %s\n", screen->get_device_vendor(screen)); 113bf215546Sopenharmony_ci fprintf(f, "Device name: %s\n\n", screen->get_name(screen)); 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci if (apitrace_call_number) 116bf215546Sopenharmony_ci fprintf(f, "Last apitrace call: %u\n\n", apitrace_call_number); 117bf215546Sopenharmony_ci} 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ciFILE * 120bf215546Sopenharmony_cidd_get_file_stream(struct dd_screen *dscreen, unsigned apitrace_call_number) 121bf215546Sopenharmony_ci{ 122bf215546Sopenharmony_ci struct pipe_screen *screen = dscreen->screen; 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci FILE *f = dd_get_debug_file(dscreen->verbose); 125bf215546Sopenharmony_ci if (!f) 126bf215546Sopenharmony_ci return NULL; 127bf215546Sopenharmony_ci 128bf215546Sopenharmony_ci dd_write_header(f, screen, apitrace_call_number); 129bf215546Sopenharmony_ci return f; 130bf215546Sopenharmony_ci} 131bf215546Sopenharmony_ci 132bf215546Sopenharmony_cistatic void 133bf215546Sopenharmony_cidd_dump_dmesg(FILE *f) 134bf215546Sopenharmony_ci{ 135bf215546Sopenharmony_ci#ifdef PIPE_OS_LINUX 136bf215546Sopenharmony_ci char line[2000]; 137bf215546Sopenharmony_ci FILE *p = popen("dmesg | tail -n60", "r"); 138bf215546Sopenharmony_ci 139bf215546Sopenharmony_ci if (!p) 140bf215546Sopenharmony_ci return; 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_ci fprintf(f, "\nLast 60 lines of dmesg:\n\n"); 143bf215546Sopenharmony_ci while (fgets(line, sizeof(line), p)) 144bf215546Sopenharmony_ci fputs(line, f); 145bf215546Sopenharmony_ci 146bf215546Sopenharmony_ci pclose(p); 147bf215546Sopenharmony_ci#endif 148bf215546Sopenharmony_ci} 149bf215546Sopenharmony_ci 150bf215546Sopenharmony_cistatic unsigned 151bf215546Sopenharmony_cidd_num_active_viewports(struct dd_draw_state *dstate) 152bf215546Sopenharmony_ci{ 153bf215546Sopenharmony_ci struct tgsi_shader_info info; 154bf215546Sopenharmony_ci const struct tgsi_token *tokens; 155bf215546Sopenharmony_ci 156bf215546Sopenharmony_ci if (dstate->shaders[PIPE_SHADER_GEOMETRY]) 157bf215546Sopenharmony_ci tokens = dstate->shaders[PIPE_SHADER_GEOMETRY]->state.shader.tokens; 158bf215546Sopenharmony_ci else if (dstate->shaders[PIPE_SHADER_TESS_EVAL]) 159bf215546Sopenharmony_ci tokens = dstate->shaders[PIPE_SHADER_TESS_EVAL]->state.shader.tokens; 160bf215546Sopenharmony_ci else if (dstate->shaders[PIPE_SHADER_VERTEX]) 161bf215546Sopenharmony_ci tokens = dstate->shaders[PIPE_SHADER_VERTEX]->state.shader.tokens; 162bf215546Sopenharmony_ci else 163bf215546Sopenharmony_ci return 1; 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci if (tokens) { 166bf215546Sopenharmony_ci tgsi_scan_shader(tokens, &info); 167bf215546Sopenharmony_ci if (info.writes_viewport_index) 168bf215546Sopenharmony_ci return PIPE_MAX_VIEWPORTS; 169bf215546Sopenharmony_ci } 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci return 1; 172bf215546Sopenharmony_ci} 173bf215546Sopenharmony_ci 174bf215546Sopenharmony_ci#define COLOR_RESET "\033[0m" 175bf215546Sopenharmony_ci#define COLOR_SHADER "\033[1;32m" 176bf215546Sopenharmony_ci#define COLOR_STATE "\033[1;33m" 177bf215546Sopenharmony_ci 178bf215546Sopenharmony_ci#define DUMP(name, var) do { \ 179bf215546Sopenharmony_ci fprintf(f, COLOR_STATE #name ": " COLOR_RESET); \ 180bf215546Sopenharmony_ci util_dump_##name(f, var); \ 181bf215546Sopenharmony_ci fprintf(f, "\n"); \ 182bf215546Sopenharmony_ci} while(0) 183bf215546Sopenharmony_ci 184bf215546Sopenharmony_ci#define DUMP_I(name, var, i) do { \ 185bf215546Sopenharmony_ci fprintf(f, COLOR_STATE #name " %i: " COLOR_RESET, i); \ 186bf215546Sopenharmony_ci util_dump_##name(f, var); \ 187bf215546Sopenharmony_ci fprintf(f, "\n"); \ 188bf215546Sopenharmony_ci} while(0) 189bf215546Sopenharmony_ci 190bf215546Sopenharmony_ci#define DUMP_M(name, var, member) do { \ 191bf215546Sopenharmony_ci fprintf(f, " " #member ": "); \ 192bf215546Sopenharmony_ci util_dump_##name(f, (var)->member); \ 193bf215546Sopenharmony_ci fprintf(f, "\n"); \ 194bf215546Sopenharmony_ci} while(0) 195bf215546Sopenharmony_ci 196bf215546Sopenharmony_ci#define DUMP_M_ADDR(name, var, member) do { \ 197bf215546Sopenharmony_ci fprintf(f, " " #member ": "); \ 198bf215546Sopenharmony_ci util_dump_##name(f, &(var)->member); \ 199bf215546Sopenharmony_ci fprintf(f, "\n"); \ 200bf215546Sopenharmony_ci} while(0) 201bf215546Sopenharmony_ci 202bf215546Sopenharmony_ci#define PRINT_NAMED(type, name, value) \ 203bf215546Sopenharmony_cido { \ 204bf215546Sopenharmony_ci fprintf(f, COLOR_STATE "%s" COLOR_RESET " = ", name); \ 205bf215546Sopenharmony_ci util_dump_##type(f, value); \ 206bf215546Sopenharmony_ci fprintf(f, "\n"); \ 207bf215546Sopenharmony_ci} while (0) 208bf215546Sopenharmony_ci 209bf215546Sopenharmony_cistatic void 210bf215546Sopenharmony_ciutil_dump_uint(FILE *f, unsigned i) 211bf215546Sopenharmony_ci{ 212bf215546Sopenharmony_ci fprintf(f, "%u", i); 213bf215546Sopenharmony_ci} 214bf215546Sopenharmony_ci 215bf215546Sopenharmony_cistatic void 216bf215546Sopenharmony_ciutil_dump_int(FILE *f, int i) 217bf215546Sopenharmony_ci{ 218bf215546Sopenharmony_ci fprintf(f, "%d", i); 219bf215546Sopenharmony_ci} 220bf215546Sopenharmony_ci 221bf215546Sopenharmony_cistatic void 222bf215546Sopenharmony_ciutil_dump_hex(FILE *f, unsigned i) 223bf215546Sopenharmony_ci{ 224bf215546Sopenharmony_ci fprintf(f, "0x%x", i); 225bf215546Sopenharmony_ci} 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_cistatic void 228bf215546Sopenharmony_ciutil_dump_double(FILE *f, double d) 229bf215546Sopenharmony_ci{ 230bf215546Sopenharmony_ci fprintf(f, "%f", d); 231bf215546Sopenharmony_ci} 232bf215546Sopenharmony_ci 233bf215546Sopenharmony_cistatic void 234bf215546Sopenharmony_ciutil_dump_format(FILE *f, enum pipe_format format) 235bf215546Sopenharmony_ci{ 236bf215546Sopenharmony_ci fprintf(f, "%s", util_format_name(format)); 237bf215546Sopenharmony_ci} 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_cistatic void 240bf215546Sopenharmony_ciutil_dump_color_union(FILE *f, const union pipe_color_union *color) 241bf215546Sopenharmony_ci{ 242bf215546Sopenharmony_ci fprintf(f, "{f = {%f, %f, %f, %f}, ui = {%u, %u, %u, %u}", 243bf215546Sopenharmony_ci color->f[0], color->f[1], color->f[2], color->f[3], 244bf215546Sopenharmony_ci color->ui[0], color->ui[1], color->ui[2], color->ui[3]); 245bf215546Sopenharmony_ci} 246bf215546Sopenharmony_ci 247bf215546Sopenharmony_cistatic void 248bf215546Sopenharmony_cidd_dump_render_condition(struct dd_draw_state *dstate, FILE *f) 249bf215546Sopenharmony_ci{ 250bf215546Sopenharmony_ci if (dstate->render_cond.query) { 251bf215546Sopenharmony_ci fprintf(f, "render condition:\n"); 252bf215546Sopenharmony_ci DUMP_M(query_type, &dstate->render_cond, query->type); 253bf215546Sopenharmony_ci DUMP_M(uint, &dstate->render_cond, condition); 254bf215546Sopenharmony_ci DUMP_M(uint, &dstate->render_cond, mode); 255bf215546Sopenharmony_ci fprintf(f, "\n"); 256bf215546Sopenharmony_ci } 257bf215546Sopenharmony_ci} 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_cistatic void 260bf215546Sopenharmony_cidd_dump_shader(struct dd_draw_state *dstate, enum pipe_shader_type sh, FILE *f) 261bf215546Sopenharmony_ci{ 262bf215546Sopenharmony_ci int i; 263bf215546Sopenharmony_ci const char *shader_str[PIPE_SHADER_TYPES]; 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ci shader_str[PIPE_SHADER_VERTEX] = "VERTEX"; 266bf215546Sopenharmony_ci shader_str[PIPE_SHADER_TESS_CTRL] = "TESS_CTRL"; 267bf215546Sopenharmony_ci shader_str[PIPE_SHADER_TESS_EVAL] = "TESS_EVAL"; 268bf215546Sopenharmony_ci shader_str[PIPE_SHADER_GEOMETRY] = "GEOMETRY"; 269bf215546Sopenharmony_ci shader_str[PIPE_SHADER_FRAGMENT] = "FRAGMENT"; 270bf215546Sopenharmony_ci shader_str[PIPE_SHADER_COMPUTE] = "COMPUTE"; 271bf215546Sopenharmony_ci 272bf215546Sopenharmony_ci if (sh == PIPE_SHADER_TESS_CTRL && 273bf215546Sopenharmony_ci !dstate->shaders[PIPE_SHADER_TESS_CTRL] && 274bf215546Sopenharmony_ci dstate->shaders[PIPE_SHADER_TESS_EVAL]) 275bf215546Sopenharmony_ci fprintf(f, "tess_state: {default_outer_level = {%f, %f, %f, %f}, " 276bf215546Sopenharmony_ci "default_inner_level = {%f, %f}}\n", 277bf215546Sopenharmony_ci dstate->tess_default_levels[0], 278bf215546Sopenharmony_ci dstate->tess_default_levels[1], 279bf215546Sopenharmony_ci dstate->tess_default_levels[2], 280bf215546Sopenharmony_ci dstate->tess_default_levels[3], 281bf215546Sopenharmony_ci dstate->tess_default_levels[4], 282bf215546Sopenharmony_ci dstate->tess_default_levels[5]); 283bf215546Sopenharmony_ci 284bf215546Sopenharmony_ci if (sh == PIPE_SHADER_FRAGMENT) 285bf215546Sopenharmony_ci if (dstate->rs) { 286bf215546Sopenharmony_ci unsigned num_viewports = dd_num_active_viewports(dstate); 287bf215546Sopenharmony_ci 288bf215546Sopenharmony_ci if (dstate->rs->state.rs.clip_plane_enable) 289bf215546Sopenharmony_ci DUMP(clip_state, &dstate->clip_state); 290bf215546Sopenharmony_ci 291bf215546Sopenharmony_ci for (i = 0; i < num_viewports; i++) 292bf215546Sopenharmony_ci DUMP_I(viewport_state, &dstate->viewports[i], i); 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci if (dstate->rs->state.rs.scissor) 295bf215546Sopenharmony_ci for (i = 0; i < num_viewports; i++) 296bf215546Sopenharmony_ci DUMP_I(scissor_state, &dstate->scissors[i], i); 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ci DUMP(rasterizer_state, &dstate->rs->state.rs); 299bf215546Sopenharmony_ci 300bf215546Sopenharmony_ci if (dstate->rs->state.rs.poly_stipple_enable) 301bf215546Sopenharmony_ci DUMP(poly_stipple, &dstate->polygon_stipple); 302bf215546Sopenharmony_ci fprintf(f, "\n"); 303bf215546Sopenharmony_ci } 304bf215546Sopenharmony_ci 305bf215546Sopenharmony_ci if (!dstate->shaders[sh]) 306bf215546Sopenharmony_ci return; 307bf215546Sopenharmony_ci 308bf215546Sopenharmony_ci fprintf(f, COLOR_SHADER "begin shader: %s" COLOR_RESET "\n", shader_str[sh]); 309bf215546Sopenharmony_ci DUMP(shader_state, &dstate->shaders[sh]->state.shader); 310bf215546Sopenharmony_ci 311bf215546Sopenharmony_ci for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) 312bf215546Sopenharmony_ci if (dstate->constant_buffers[sh][i].buffer || 313bf215546Sopenharmony_ci dstate->constant_buffers[sh][i].user_buffer) { 314bf215546Sopenharmony_ci DUMP_I(constant_buffer, &dstate->constant_buffers[sh][i], i); 315bf215546Sopenharmony_ci if (dstate->constant_buffers[sh][i].buffer) 316bf215546Sopenharmony_ci DUMP_M(resource, &dstate->constant_buffers[sh][i], buffer); 317bf215546Sopenharmony_ci } 318bf215546Sopenharmony_ci 319bf215546Sopenharmony_ci for (i = 0; i < PIPE_MAX_SAMPLERS; i++) 320bf215546Sopenharmony_ci if (dstate->sampler_states[sh][i]) 321bf215546Sopenharmony_ci DUMP_I(sampler_state, &dstate->sampler_states[sh][i]->state.sampler, i); 322bf215546Sopenharmony_ci 323bf215546Sopenharmony_ci for (i = 0; i < PIPE_MAX_SAMPLERS; i++) 324bf215546Sopenharmony_ci if (dstate->sampler_views[sh][i]) { 325bf215546Sopenharmony_ci DUMP_I(sampler_view, dstate->sampler_views[sh][i], i); 326bf215546Sopenharmony_ci DUMP_M(resource, dstate->sampler_views[sh][i], texture); 327bf215546Sopenharmony_ci } 328bf215546Sopenharmony_ci 329bf215546Sopenharmony_ci for (i = 0; i < PIPE_MAX_SHADER_IMAGES; i++) 330bf215546Sopenharmony_ci if (dstate->shader_images[sh][i].resource) { 331bf215546Sopenharmony_ci DUMP_I(image_view, &dstate->shader_images[sh][i], i); 332bf215546Sopenharmony_ci if (dstate->shader_images[sh][i].resource) 333bf215546Sopenharmony_ci DUMP_M(resource, &dstate->shader_images[sh][i], resource); 334bf215546Sopenharmony_ci } 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci for (i = 0; i < PIPE_MAX_SHADER_BUFFERS; i++) 337bf215546Sopenharmony_ci if (dstate->shader_buffers[sh][i].buffer) { 338bf215546Sopenharmony_ci DUMP_I(shader_buffer, &dstate->shader_buffers[sh][i], i); 339bf215546Sopenharmony_ci if (dstate->shader_buffers[sh][i].buffer) 340bf215546Sopenharmony_ci DUMP_M(resource, &dstate->shader_buffers[sh][i], buffer); 341bf215546Sopenharmony_ci } 342bf215546Sopenharmony_ci 343bf215546Sopenharmony_ci fprintf(f, COLOR_SHADER "end shader: %s" COLOR_RESET "\n\n", shader_str[sh]); 344bf215546Sopenharmony_ci} 345bf215546Sopenharmony_ci 346bf215546Sopenharmony_cistatic void 347bf215546Sopenharmony_cidd_dump_flush(struct dd_draw_state *dstate, struct call_flush *info, FILE *f) 348bf215546Sopenharmony_ci{ 349bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 350bf215546Sopenharmony_ci DUMP_M(hex, info, flags); 351bf215546Sopenharmony_ci} 352bf215546Sopenharmony_ci 353bf215546Sopenharmony_cistatic void 354bf215546Sopenharmony_cidd_dump_draw_vbo(struct dd_draw_state *dstate, struct pipe_draw_info *info, 355bf215546Sopenharmony_ci unsigned drawid_offset, 356bf215546Sopenharmony_ci const struct pipe_draw_indirect_info *indirect, 357bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draw, FILE *f) 358bf215546Sopenharmony_ci{ 359bf215546Sopenharmony_ci int sh, i; 360bf215546Sopenharmony_ci 361bf215546Sopenharmony_ci DUMP(draw_info, info); 362bf215546Sopenharmony_ci PRINT_NAMED(int, "drawid offset", drawid_offset); 363bf215546Sopenharmony_ci DUMP(draw_start_count_bias, draw); 364bf215546Sopenharmony_ci if (indirect) { 365bf215546Sopenharmony_ci if (indirect->buffer) 366bf215546Sopenharmony_ci DUMP_M(resource, indirect, buffer); 367bf215546Sopenharmony_ci if (indirect->indirect_draw_count) 368bf215546Sopenharmony_ci DUMP_M(resource, indirect, indirect_draw_count); 369bf215546Sopenharmony_ci if (indirect->count_from_stream_output) 370bf215546Sopenharmony_ci DUMP_M(stream_output_target, indirect, count_from_stream_output); 371bf215546Sopenharmony_ci } 372bf215546Sopenharmony_ci 373bf215546Sopenharmony_ci fprintf(f, "\n"); 374bf215546Sopenharmony_ci 375bf215546Sopenharmony_ci /* TODO: dump active queries */ 376bf215546Sopenharmony_ci 377bf215546Sopenharmony_ci dd_dump_render_condition(dstate, f); 378bf215546Sopenharmony_ci 379bf215546Sopenharmony_ci for (i = 0; i < PIPE_MAX_ATTRIBS; i++) 380bf215546Sopenharmony_ci if (dstate->vertex_buffers[i].buffer.resource) { 381bf215546Sopenharmony_ci DUMP_I(vertex_buffer, &dstate->vertex_buffers[i], i); 382bf215546Sopenharmony_ci if (!dstate->vertex_buffers[i].is_user_buffer) 383bf215546Sopenharmony_ci DUMP_M(resource, &dstate->vertex_buffers[i], buffer.resource); 384bf215546Sopenharmony_ci } 385bf215546Sopenharmony_ci 386bf215546Sopenharmony_ci if (dstate->velems) { 387bf215546Sopenharmony_ci PRINT_NAMED(uint, "num vertex elements", 388bf215546Sopenharmony_ci dstate->velems->state.velems.count); 389bf215546Sopenharmony_ci for (i = 0; i < dstate->velems->state.velems.count; i++) { 390bf215546Sopenharmony_ci fprintf(f, " "); 391bf215546Sopenharmony_ci DUMP_I(vertex_element, &dstate->velems->state.velems.velems[i], i); 392bf215546Sopenharmony_ci } 393bf215546Sopenharmony_ci } 394bf215546Sopenharmony_ci 395bf215546Sopenharmony_ci PRINT_NAMED(uint, "num stream output targets", dstate->num_so_targets); 396bf215546Sopenharmony_ci for (i = 0; i < dstate->num_so_targets; i++) 397bf215546Sopenharmony_ci if (dstate->so_targets[i]) { 398bf215546Sopenharmony_ci DUMP_I(stream_output_target, dstate->so_targets[i], i); 399bf215546Sopenharmony_ci DUMP_M(resource, dstate->so_targets[i], buffer); 400bf215546Sopenharmony_ci fprintf(f, " offset = %i\n", dstate->so_offsets[i]); 401bf215546Sopenharmony_ci } 402bf215546Sopenharmony_ci 403bf215546Sopenharmony_ci fprintf(f, "\n"); 404bf215546Sopenharmony_ci for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) { 405bf215546Sopenharmony_ci if (sh == PIPE_SHADER_COMPUTE) 406bf215546Sopenharmony_ci continue; 407bf215546Sopenharmony_ci 408bf215546Sopenharmony_ci dd_dump_shader(dstate, sh, f); 409bf215546Sopenharmony_ci } 410bf215546Sopenharmony_ci 411bf215546Sopenharmony_ci if (dstate->dsa) 412bf215546Sopenharmony_ci DUMP(depth_stencil_alpha_state, &dstate->dsa->state.dsa); 413bf215546Sopenharmony_ci DUMP(stencil_ref, &dstate->stencil_ref); 414bf215546Sopenharmony_ci 415bf215546Sopenharmony_ci if (dstate->blend) 416bf215546Sopenharmony_ci DUMP(blend_state, &dstate->blend->state.blend); 417bf215546Sopenharmony_ci DUMP(blend_color, &dstate->blend_color); 418bf215546Sopenharmony_ci 419bf215546Sopenharmony_ci PRINT_NAMED(uint, "min_samples", dstate->min_samples); 420bf215546Sopenharmony_ci PRINT_NAMED(hex, "sample_mask", dstate->sample_mask); 421bf215546Sopenharmony_ci fprintf(f, "\n"); 422bf215546Sopenharmony_ci 423bf215546Sopenharmony_ci DUMP(framebuffer_state, &dstate->framebuffer_state); 424bf215546Sopenharmony_ci for (i = 0; i < dstate->framebuffer_state.nr_cbufs; i++) 425bf215546Sopenharmony_ci if (dstate->framebuffer_state.cbufs[i]) { 426bf215546Sopenharmony_ci fprintf(f, " " COLOR_STATE "cbufs[%i]:" COLOR_RESET "\n ", i); 427bf215546Sopenharmony_ci DUMP(surface, dstate->framebuffer_state.cbufs[i]); 428bf215546Sopenharmony_ci fprintf(f, " "); 429bf215546Sopenharmony_ci DUMP(resource, dstate->framebuffer_state.cbufs[i]->texture); 430bf215546Sopenharmony_ci } 431bf215546Sopenharmony_ci if (dstate->framebuffer_state.zsbuf) { 432bf215546Sopenharmony_ci fprintf(f, " " COLOR_STATE "zsbuf:" COLOR_RESET "\n "); 433bf215546Sopenharmony_ci DUMP(surface, dstate->framebuffer_state.zsbuf); 434bf215546Sopenharmony_ci fprintf(f, " "); 435bf215546Sopenharmony_ci DUMP(resource, dstate->framebuffer_state.zsbuf->texture); 436bf215546Sopenharmony_ci } 437bf215546Sopenharmony_ci fprintf(f, "\n"); 438bf215546Sopenharmony_ci} 439bf215546Sopenharmony_ci 440bf215546Sopenharmony_cistatic void 441bf215546Sopenharmony_cidd_dump_launch_grid(struct dd_draw_state *dstate, struct pipe_grid_info *info, FILE *f) 442bf215546Sopenharmony_ci{ 443bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 444bf215546Sopenharmony_ci DUMP(grid_info, info); 445bf215546Sopenharmony_ci fprintf(f, "\n"); 446bf215546Sopenharmony_ci 447bf215546Sopenharmony_ci dd_dump_shader(dstate, PIPE_SHADER_COMPUTE, f); 448bf215546Sopenharmony_ci fprintf(f, "\n"); 449bf215546Sopenharmony_ci} 450bf215546Sopenharmony_ci 451bf215546Sopenharmony_cistatic void 452bf215546Sopenharmony_cidd_dump_resource_copy_region(struct dd_draw_state *dstate, 453bf215546Sopenharmony_ci struct call_resource_copy_region *info, 454bf215546Sopenharmony_ci FILE *f) 455bf215546Sopenharmony_ci{ 456bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 457bf215546Sopenharmony_ci DUMP_M(resource, info, dst); 458bf215546Sopenharmony_ci DUMP_M(uint, info, dst_level); 459bf215546Sopenharmony_ci DUMP_M(uint, info, dstx); 460bf215546Sopenharmony_ci DUMP_M(uint, info, dsty); 461bf215546Sopenharmony_ci DUMP_M(uint, info, dstz); 462bf215546Sopenharmony_ci DUMP_M(resource, info, src); 463bf215546Sopenharmony_ci DUMP_M(uint, info, src_level); 464bf215546Sopenharmony_ci DUMP_M_ADDR(box, info, src_box); 465bf215546Sopenharmony_ci} 466bf215546Sopenharmony_ci 467bf215546Sopenharmony_cistatic void 468bf215546Sopenharmony_cidd_dump_blit(struct dd_draw_state *dstate, struct pipe_blit_info *info, FILE *f) 469bf215546Sopenharmony_ci{ 470bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 471bf215546Sopenharmony_ci DUMP_M(resource, info, dst.resource); 472bf215546Sopenharmony_ci DUMP_M(uint, info, dst.level); 473bf215546Sopenharmony_ci DUMP_M_ADDR(box, info, dst.box); 474bf215546Sopenharmony_ci DUMP_M(format, info, dst.format); 475bf215546Sopenharmony_ci 476bf215546Sopenharmony_ci DUMP_M(resource, info, src.resource); 477bf215546Sopenharmony_ci DUMP_M(uint, info, src.level); 478bf215546Sopenharmony_ci DUMP_M_ADDR(box, info, src.box); 479bf215546Sopenharmony_ci DUMP_M(format, info, src.format); 480bf215546Sopenharmony_ci 481bf215546Sopenharmony_ci DUMP_M(hex, info, mask); 482bf215546Sopenharmony_ci DUMP_M(uint, info, filter); 483bf215546Sopenharmony_ci DUMP_M(uint, info, scissor_enable); 484bf215546Sopenharmony_ci DUMP_M_ADDR(scissor_state, info, scissor); 485bf215546Sopenharmony_ci DUMP_M(uint, info, render_condition_enable); 486bf215546Sopenharmony_ci 487bf215546Sopenharmony_ci if (info->render_condition_enable) 488bf215546Sopenharmony_ci dd_dump_render_condition(dstate, f); 489bf215546Sopenharmony_ci} 490bf215546Sopenharmony_ci 491bf215546Sopenharmony_cistatic void 492bf215546Sopenharmony_cidd_dump_generate_mipmap(struct dd_draw_state *dstate, FILE *f) 493bf215546Sopenharmony_ci{ 494bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 495bf215546Sopenharmony_ci /* TODO */ 496bf215546Sopenharmony_ci} 497bf215546Sopenharmony_ci 498bf215546Sopenharmony_cistatic void 499bf215546Sopenharmony_cidd_dump_get_query_result_resource(struct call_get_query_result_resource *info, FILE *f) 500bf215546Sopenharmony_ci{ 501bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__ + 8); 502bf215546Sopenharmony_ci DUMP_M(query_type, info, query_type); 503bf215546Sopenharmony_ci DUMP_M(query_flags, info, flags); 504bf215546Sopenharmony_ci DUMP_M(query_value_type, info, result_type); 505bf215546Sopenharmony_ci DUMP_M(int, info, index); 506bf215546Sopenharmony_ci DUMP_M(resource, info, resource); 507bf215546Sopenharmony_ci DUMP_M(uint, info, offset); 508bf215546Sopenharmony_ci} 509bf215546Sopenharmony_ci 510bf215546Sopenharmony_cistatic void 511bf215546Sopenharmony_cidd_dump_flush_resource(struct dd_draw_state *dstate, struct pipe_resource *res, 512bf215546Sopenharmony_ci FILE *f) 513bf215546Sopenharmony_ci{ 514bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 515bf215546Sopenharmony_ci DUMP(resource, res); 516bf215546Sopenharmony_ci} 517bf215546Sopenharmony_ci 518bf215546Sopenharmony_cistatic void 519bf215546Sopenharmony_cidd_dump_clear(struct dd_draw_state *dstate, struct call_clear *info, FILE *f) 520bf215546Sopenharmony_ci{ 521bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 522bf215546Sopenharmony_ci DUMP_M(uint, info, buffers); 523bf215546Sopenharmony_ci fprintf(f, " scissor_state: %d,%d %d,%d\n", 524bf215546Sopenharmony_ci info->scissor_state.minx, info->scissor_state.miny, 525bf215546Sopenharmony_ci info->scissor_state.maxx, info->scissor_state.maxy); 526bf215546Sopenharmony_ci DUMP_M_ADDR(color_union, info, color); 527bf215546Sopenharmony_ci DUMP_M(double, info, depth); 528bf215546Sopenharmony_ci DUMP_M(hex, info, stencil); 529bf215546Sopenharmony_ci} 530bf215546Sopenharmony_ci 531bf215546Sopenharmony_cistatic void 532bf215546Sopenharmony_cidd_dump_clear_buffer(struct dd_draw_state *dstate, struct call_clear_buffer *info, 533bf215546Sopenharmony_ci FILE *f) 534bf215546Sopenharmony_ci{ 535bf215546Sopenharmony_ci int i; 536bf215546Sopenharmony_ci const char *value = (const char*)info->clear_value; 537bf215546Sopenharmony_ci 538bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 539bf215546Sopenharmony_ci DUMP_M(resource, info, res); 540bf215546Sopenharmony_ci DUMP_M(uint, info, offset); 541bf215546Sopenharmony_ci DUMP_M(uint, info, size); 542bf215546Sopenharmony_ci DUMP_M(uint, info, clear_value_size); 543bf215546Sopenharmony_ci 544bf215546Sopenharmony_ci fprintf(f, " clear_value:"); 545bf215546Sopenharmony_ci for (i = 0; i < info->clear_value_size; i++) 546bf215546Sopenharmony_ci fprintf(f, " %02x", value[i]); 547bf215546Sopenharmony_ci fprintf(f, "\n"); 548bf215546Sopenharmony_ci} 549bf215546Sopenharmony_ci 550bf215546Sopenharmony_cistatic void 551bf215546Sopenharmony_cidd_dump_transfer_map(struct call_transfer_map *info, FILE *f) 552bf215546Sopenharmony_ci{ 553bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 554bf215546Sopenharmony_ci DUMP_M_ADDR(transfer, info, transfer); 555bf215546Sopenharmony_ci DUMP_M(ptr, info, transfer_ptr); 556bf215546Sopenharmony_ci DUMP_M(ptr, info, ptr); 557bf215546Sopenharmony_ci} 558bf215546Sopenharmony_ci 559bf215546Sopenharmony_cistatic void 560bf215546Sopenharmony_cidd_dump_transfer_flush_region(struct call_transfer_flush_region *info, FILE *f) 561bf215546Sopenharmony_ci{ 562bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 563bf215546Sopenharmony_ci DUMP_M_ADDR(transfer, info, transfer); 564bf215546Sopenharmony_ci DUMP_M(ptr, info, transfer_ptr); 565bf215546Sopenharmony_ci DUMP_M_ADDR(box, info, box); 566bf215546Sopenharmony_ci} 567bf215546Sopenharmony_ci 568bf215546Sopenharmony_cistatic void 569bf215546Sopenharmony_cidd_dump_transfer_unmap(struct call_transfer_unmap *info, FILE *f) 570bf215546Sopenharmony_ci{ 571bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 572bf215546Sopenharmony_ci DUMP_M_ADDR(transfer, info, transfer); 573bf215546Sopenharmony_ci DUMP_M(ptr, info, transfer_ptr); 574bf215546Sopenharmony_ci} 575bf215546Sopenharmony_ci 576bf215546Sopenharmony_cistatic void 577bf215546Sopenharmony_cidd_dump_buffer_subdata(struct call_buffer_subdata *info, FILE *f) 578bf215546Sopenharmony_ci{ 579bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 580bf215546Sopenharmony_ci DUMP_M(resource, info, resource); 581bf215546Sopenharmony_ci DUMP_M(transfer_usage, info, usage); 582bf215546Sopenharmony_ci DUMP_M(uint, info, offset); 583bf215546Sopenharmony_ci DUMP_M(uint, info, size); 584bf215546Sopenharmony_ci DUMP_M(ptr, info, data); 585bf215546Sopenharmony_ci} 586bf215546Sopenharmony_ci 587bf215546Sopenharmony_cistatic void 588bf215546Sopenharmony_cidd_dump_texture_subdata(struct call_texture_subdata *info, FILE *f) 589bf215546Sopenharmony_ci{ 590bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 591bf215546Sopenharmony_ci DUMP_M(resource, info, resource); 592bf215546Sopenharmony_ci DUMP_M(uint, info, level); 593bf215546Sopenharmony_ci DUMP_M(transfer_usage, info, usage); 594bf215546Sopenharmony_ci DUMP_M_ADDR(box, info, box); 595bf215546Sopenharmony_ci DUMP_M(ptr, info, data); 596bf215546Sopenharmony_ci DUMP_M(uint, info, stride); 597bf215546Sopenharmony_ci DUMP_M(uint, info, layer_stride); 598bf215546Sopenharmony_ci} 599bf215546Sopenharmony_ci 600bf215546Sopenharmony_cistatic void 601bf215546Sopenharmony_cidd_dump_clear_texture(struct dd_draw_state *dstate, FILE *f) 602bf215546Sopenharmony_ci{ 603bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 604bf215546Sopenharmony_ci /* TODO */ 605bf215546Sopenharmony_ci} 606bf215546Sopenharmony_ci 607bf215546Sopenharmony_cistatic void 608bf215546Sopenharmony_cidd_dump_clear_render_target(struct dd_draw_state *dstate, FILE *f) 609bf215546Sopenharmony_ci{ 610bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 611bf215546Sopenharmony_ci /* TODO */ 612bf215546Sopenharmony_ci} 613bf215546Sopenharmony_ci 614bf215546Sopenharmony_cistatic void 615bf215546Sopenharmony_cidd_dump_clear_depth_stencil(struct dd_draw_state *dstate, FILE *f) 616bf215546Sopenharmony_ci{ 617bf215546Sopenharmony_ci fprintf(f, "%s:\n", __func__+8); 618bf215546Sopenharmony_ci /* TODO */ 619bf215546Sopenharmony_ci} 620bf215546Sopenharmony_ci 621bf215546Sopenharmony_cistatic void 622bf215546Sopenharmony_cidd_dump_driver_state(struct dd_context *dctx, FILE *f, unsigned flags) 623bf215546Sopenharmony_ci{ 624bf215546Sopenharmony_ci if (dctx->pipe->dump_debug_state) { 625bf215546Sopenharmony_ci fprintf(f,"\n\n**************************************************" 626bf215546Sopenharmony_ci "***************************\n"); 627bf215546Sopenharmony_ci fprintf(f, "Driver-specific state:\n\n"); 628bf215546Sopenharmony_ci dctx->pipe->dump_debug_state(dctx->pipe, f, flags); 629bf215546Sopenharmony_ci } 630bf215546Sopenharmony_ci} 631bf215546Sopenharmony_ci 632bf215546Sopenharmony_cistatic void 633bf215546Sopenharmony_cidd_dump_call(FILE *f, struct dd_draw_state *state, struct dd_call *call) 634bf215546Sopenharmony_ci{ 635bf215546Sopenharmony_ci switch (call->type) { 636bf215546Sopenharmony_ci case CALL_FLUSH: 637bf215546Sopenharmony_ci dd_dump_flush(state, &call->info.flush, f); 638bf215546Sopenharmony_ci break; 639bf215546Sopenharmony_ci case CALL_DRAW_VBO: 640bf215546Sopenharmony_ci dd_dump_draw_vbo(state, &call->info.draw_vbo.info, 641bf215546Sopenharmony_ci call->info.draw_vbo.drawid_offset, 642bf215546Sopenharmony_ci &call->info.draw_vbo.indirect, 643bf215546Sopenharmony_ci &call->info.draw_vbo.draw, f); 644bf215546Sopenharmony_ci break; 645bf215546Sopenharmony_ci case CALL_LAUNCH_GRID: 646bf215546Sopenharmony_ci dd_dump_launch_grid(state, &call->info.launch_grid, f); 647bf215546Sopenharmony_ci break; 648bf215546Sopenharmony_ci case CALL_RESOURCE_COPY_REGION: 649bf215546Sopenharmony_ci dd_dump_resource_copy_region(state, 650bf215546Sopenharmony_ci &call->info.resource_copy_region, f); 651bf215546Sopenharmony_ci break; 652bf215546Sopenharmony_ci case CALL_BLIT: 653bf215546Sopenharmony_ci dd_dump_blit(state, &call->info.blit, f); 654bf215546Sopenharmony_ci break; 655bf215546Sopenharmony_ci case CALL_FLUSH_RESOURCE: 656bf215546Sopenharmony_ci dd_dump_flush_resource(state, call->info.flush_resource, f); 657bf215546Sopenharmony_ci break; 658bf215546Sopenharmony_ci case CALL_CLEAR: 659bf215546Sopenharmony_ci dd_dump_clear(state, &call->info.clear, f); 660bf215546Sopenharmony_ci break; 661bf215546Sopenharmony_ci case CALL_CLEAR_BUFFER: 662bf215546Sopenharmony_ci dd_dump_clear_buffer(state, &call->info.clear_buffer, f); 663bf215546Sopenharmony_ci break; 664bf215546Sopenharmony_ci case CALL_CLEAR_TEXTURE: 665bf215546Sopenharmony_ci dd_dump_clear_texture(state, f); 666bf215546Sopenharmony_ci break; 667bf215546Sopenharmony_ci case CALL_CLEAR_RENDER_TARGET: 668bf215546Sopenharmony_ci dd_dump_clear_render_target(state, f); 669bf215546Sopenharmony_ci break; 670bf215546Sopenharmony_ci case CALL_CLEAR_DEPTH_STENCIL: 671bf215546Sopenharmony_ci dd_dump_clear_depth_stencil(state, f); 672bf215546Sopenharmony_ci break; 673bf215546Sopenharmony_ci case CALL_GENERATE_MIPMAP: 674bf215546Sopenharmony_ci dd_dump_generate_mipmap(state, f); 675bf215546Sopenharmony_ci break; 676bf215546Sopenharmony_ci case CALL_GET_QUERY_RESULT_RESOURCE: 677bf215546Sopenharmony_ci dd_dump_get_query_result_resource(&call->info.get_query_result_resource, f); 678bf215546Sopenharmony_ci break; 679bf215546Sopenharmony_ci case CALL_TRANSFER_MAP: 680bf215546Sopenharmony_ci dd_dump_transfer_map(&call->info.transfer_map, f); 681bf215546Sopenharmony_ci break; 682bf215546Sopenharmony_ci case CALL_TRANSFER_FLUSH_REGION: 683bf215546Sopenharmony_ci dd_dump_transfer_flush_region(&call->info.transfer_flush_region, f); 684bf215546Sopenharmony_ci break; 685bf215546Sopenharmony_ci case CALL_TRANSFER_UNMAP: 686bf215546Sopenharmony_ci dd_dump_transfer_unmap(&call->info.transfer_unmap, f); 687bf215546Sopenharmony_ci break; 688bf215546Sopenharmony_ci case CALL_BUFFER_SUBDATA: 689bf215546Sopenharmony_ci dd_dump_buffer_subdata(&call->info.buffer_subdata, f); 690bf215546Sopenharmony_ci break; 691bf215546Sopenharmony_ci case CALL_TEXTURE_SUBDATA: 692bf215546Sopenharmony_ci dd_dump_texture_subdata(&call->info.texture_subdata, f); 693bf215546Sopenharmony_ci break; 694bf215546Sopenharmony_ci } 695bf215546Sopenharmony_ci} 696bf215546Sopenharmony_ci 697bf215546Sopenharmony_cistatic void 698bf215546Sopenharmony_cidd_kill_process(void) 699bf215546Sopenharmony_ci{ 700bf215546Sopenharmony_ci#ifdef PIPE_OS_UNIX 701bf215546Sopenharmony_ci sync(); 702bf215546Sopenharmony_ci#endif 703bf215546Sopenharmony_ci fprintf(stderr, "dd: Aborting the process...\n"); 704bf215546Sopenharmony_ci fflush(stdout); 705bf215546Sopenharmony_ci fflush(stderr); 706bf215546Sopenharmony_ci exit(1); 707bf215546Sopenharmony_ci} 708bf215546Sopenharmony_ci 709bf215546Sopenharmony_cistatic void 710bf215546Sopenharmony_cidd_unreference_copy_of_call(struct dd_call *dst) 711bf215546Sopenharmony_ci{ 712bf215546Sopenharmony_ci switch (dst->type) { 713bf215546Sopenharmony_ci case CALL_FLUSH: 714bf215546Sopenharmony_ci break; 715bf215546Sopenharmony_ci case CALL_DRAW_VBO: 716bf215546Sopenharmony_ci pipe_so_target_reference(&dst->info.draw_vbo.indirect.count_from_stream_output, NULL); 717bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.draw_vbo.indirect.buffer, NULL); 718bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.draw_vbo.indirect.indirect_draw_count, NULL); 719bf215546Sopenharmony_ci if (dst->info.draw_vbo.info.index_size && 720bf215546Sopenharmony_ci !dst->info.draw_vbo.info.has_user_indices) 721bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.draw_vbo.info.index.resource, NULL); 722bf215546Sopenharmony_ci else 723bf215546Sopenharmony_ci dst->info.draw_vbo.info.index.user = NULL; 724bf215546Sopenharmony_ci break; 725bf215546Sopenharmony_ci case CALL_LAUNCH_GRID: 726bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.launch_grid.indirect, NULL); 727bf215546Sopenharmony_ci break; 728bf215546Sopenharmony_ci case CALL_RESOURCE_COPY_REGION: 729bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.resource_copy_region.dst, NULL); 730bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.resource_copy_region.src, NULL); 731bf215546Sopenharmony_ci break; 732bf215546Sopenharmony_ci case CALL_BLIT: 733bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.blit.dst.resource, NULL); 734bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.blit.src.resource, NULL); 735bf215546Sopenharmony_ci break; 736bf215546Sopenharmony_ci case CALL_FLUSH_RESOURCE: 737bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.flush_resource, NULL); 738bf215546Sopenharmony_ci break; 739bf215546Sopenharmony_ci case CALL_CLEAR: 740bf215546Sopenharmony_ci break; 741bf215546Sopenharmony_ci case CALL_CLEAR_BUFFER: 742bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.clear_buffer.res, NULL); 743bf215546Sopenharmony_ci break; 744bf215546Sopenharmony_ci case CALL_CLEAR_TEXTURE: 745bf215546Sopenharmony_ci break; 746bf215546Sopenharmony_ci case CALL_CLEAR_RENDER_TARGET: 747bf215546Sopenharmony_ci break; 748bf215546Sopenharmony_ci case CALL_CLEAR_DEPTH_STENCIL: 749bf215546Sopenharmony_ci break; 750bf215546Sopenharmony_ci case CALL_GENERATE_MIPMAP: 751bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.generate_mipmap.res, NULL); 752bf215546Sopenharmony_ci break; 753bf215546Sopenharmony_ci case CALL_GET_QUERY_RESULT_RESOURCE: 754bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.get_query_result_resource.resource, NULL); 755bf215546Sopenharmony_ci break; 756bf215546Sopenharmony_ci case CALL_TRANSFER_MAP: 757bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.transfer_map.transfer.resource, NULL); 758bf215546Sopenharmony_ci break; 759bf215546Sopenharmony_ci case CALL_TRANSFER_FLUSH_REGION: 760bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.transfer_flush_region.transfer.resource, NULL); 761bf215546Sopenharmony_ci break; 762bf215546Sopenharmony_ci case CALL_TRANSFER_UNMAP: 763bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.transfer_unmap.transfer.resource, NULL); 764bf215546Sopenharmony_ci break; 765bf215546Sopenharmony_ci case CALL_BUFFER_SUBDATA: 766bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.buffer_subdata.resource, NULL); 767bf215546Sopenharmony_ci break; 768bf215546Sopenharmony_ci case CALL_TEXTURE_SUBDATA: 769bf215546Sopenharmony_ci pipe_resource_reference(&dst->info.texture_subdata.resource, NULL); 770bf215546Sopenharmony_ci break; 771bf215546Sopenharmony_ci } 772bf215546Sopenharmony_ci} 773bf215546Sopenharmony_ci 774bf215546Sopenharmony_cistatic void 775bf215546Sopenharmony_cidd_init_copy_of_draw_state(struct dd_draw_state_copy *state) 776bf215546Sopenharmony_ci{ 777bf215546Sopenharmony_ci unsigned i,j; 778bf215546Sopenharmony_ci 779bf215546Sopenharmony_ci /* Just clear pointers to gallium objects. Don't clear the whole structure, 780bf215546Sopenharmony_ci * because it would kill performance with its size of 130 KB. 781bf215546Sopenharmony_ci */ 782bf215546Sopenharmony_ci memset(state->base.vertex_buffers, 0, 783bf215546Sopenharmony_ci sizeof(state->base.vertex_buffers)); 784bf215546Sopenharmony_ci memset(state->base.so_targets, 0, 785bf215546Sopenharmony_ci sizeof(state->base.so_targets)); 786bf215546Sopenharmony_ci memset(state->base.constant_buffers, 0, 787bf215546Sopenharmony_ci sizeof(state->base.constant_buffers)); 788bf215546Sopenharmony_ci memset(state->base.sampler_views, 0, 789bf215546Sopenharmony_ci sizeof(state->base.sampler_views)); 790bf215546Sopenharmony_ci memset(state->base.shader_images, 0, 791bf215546Sopenharmony_ci sizeof(state->base.shader_images)); 792bf215546Sopenharmony_ci memset(state->base.shader_buffers, 0, 793bf215546Sopenharmony_ci sizeof(state->base.shader_buffers)); 794bf215546Sopenharmony_ci memset(&state->base.framebuffer_state, 0, 795bf215546Sopenharmony_ci sizeof(state->base.framebuffer_state)); 796bf215546Sopenharmony_ci 797bf215546Sopenharmony_ci memset(state->shaders, 0, sizeof(state->shaders)); 798bf215546Sopenharmony_ci 799bf215546Sopenharmony_ci state->base.render_cond.query = &state->render_cond; 800bf215546Sopenharmony_ci 801bf215546Sopenharmony_ci for (i = 0; i < PIPE_SHADER_TYPES; i++) { 802bf215546Sopenharmony_ci state->base.shaders[i] = &state->shaders[i]; 803bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_SAMPLERS; j++) 804bf215546Sopenharmony_ci state->base.sampler_states[i][j] = &state->sampler_states[i][j]; 805bf215546Sopenharmony_ci } 806bf215546Sopenharmony_ci 807bf215546Sopenharmony_ci state->base.velems = &state->velems; 808bf215546Sopenharmony_ci state->base.rs = &state->rs; 809bf215546Sopenharmony_ci state->base.dsa = &state->dsa; 810bf215546Sopenharmony_ci state->base.blend = &state->blend; 811bf215546Sopenharmony_ci} 812bf215546Sopenharmony_ci 813bf215546Sopenharmony_cistatic void 814bf215546Sopenharmony_cidd_unreference_copy_of_draw_state(struct dd_draw_state_copy *state) 815bf215546Sopenharmony_ci{ 816bf215546Sopenharmony_ci struct dd_draw_state *dst = &state->base; 817bf215546Sopenharmony_ci unsigned i,j; 818bf215546Sopenharmony_ci 819bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dst->vertex_buffers); i++) 820bf215546Sopenharmony_ci pipe_vertex_buffer_unreference(&dst->vertex_buffers[i]); 821bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(dst->so_targets); i++) 822bf215546Sopenharmony_ci pipe_so_target_reference(&dst->so_targets[i], NULL); 823bf215546Sopenharmony_ci 824bf215546Sopenharmony_ci for (i = 0; i < PIPE_SHADER_TYPES; i++) { 825bf215546Sopenharmony_ci if (dst->shaders[i]) 826bf215546Sopenharmony_ci tgsi_free_tokens(dst->shaders[i]->state.shader.tokens); 827bf215546Sopenharmony_ci 828bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_CONSTANT_BUFFERS; j++) 829bf215546Sopenharmony_ci pipe_resource_reference(&dst->constant_buffers[i][j].buffer, NULL); 830bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_SAMPLERS; j++) 831bf215546Sopenharmony_ci pipe_sampler_view_reference(&dst->sampler_views[i][j], NULL); 832bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_SHADER_IMAGES; j++) 833bf215546Sopenharmony_ci pipe_resource_reference(&dst->shader_images[i][j].resource, NULL); 834bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_SHADER_BUFFERS; j++) 835bf215546Sopenharmony_ci pipe_resource_reference(&dst->shader_buffers[i][j].buffer, NULL); 836bf215546Sopenharmony_ci } 837bf215546Sopenharmony_ci 838bf215546Sopenharmony_ci util_unreference_framebuffer_state(&dst->framebuffer_state); 839bf215546Sopenharmony_ci} 840bf215546Sopenharmony_ci 841bf215546Sopenharmony_cistatic void 842bf215546Sopenharmony_cidd_copy_draw_state(struct dd_draw_state *dst, struct dd_draw_state *src) 843bf215546Sopenharmony_ci{ 844bf215546Sopenharmony_ci unsigned i,j; 845bf215546Sopenharmony_ci 846bf215546Sopenharmony_ci if (src->render_cond.query) { 847bf215546Sopenharmony_ci *dst->render_cond.query = *src->render_cond.query; 848bf215546Sopenharmony_ci dst->render_cond.condition = src->render_cond.condition; 849bf215546Sopenharmony_ci dst->render_cond.mode = src->render_cond.mode; 850bf215546Sopenharmony_ci } else { 851bf215546Sopenharmony_ci dst->render_cond.query = NULL; 852bf215546Sopenharmony_ci } 853bf215546Sopenharmony_ci 854bf215546Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(src->vertex_buffers); i++) { 855bf215546Sopenharmony_ci pipe_vertex_buffer_reference(&dst->vertex_buffers[i], 856bf215546Sopenharmony_ci &src->vertex_buffers[i]); 857bf215546Sopenharmony_ci } 858bf215546Sopenharmony_ci 859bf215546Sopenharmony_ci dst->num_so_targets = src->num_so_targets; 860bf215546Sopenharmony_ci for (i = 0; i < src->num_so_targets; i++) 861bf215546Sopenharmony_ci pipe_so_target_reference(&dst->so_targets[i], src->so_targets[i]); 862bf215546Sopenharmony_ci memcpy(dst->so_offsets, src->so_offsets, sizeof(src->so_offsets)); 863bf215546Sopenharmony_ci 864bf215546Sopenharmony_ci for (i = 0; i < PIPE_SHADER_TYPES; i++) { 865bf215546Sopenharmony_ci if (!src->shaders[i]) { 866bf215546Sopenharmony_ci dst->shaders[i] = NULL; 867bf215546Sopenharmony_ci continue; 868bf215546Sopenharmony_ci } 869bf215546Sopenharmony_ci 870bf215546Sopenharmony_ci if (src->shaders[i]) { 871bf215546Sopenharmony_ci dst->shaders[i]->state.shader = src->shaders[i]->state.shader; 872bf215546Sopenharmony_ci if (src->shaders[i]->state.shader.tokens) { 873bf215546Sopenharmony_ci dst->shaders[i]->state.shader.tokens = 874bf215546Sopenharmony_ci tgsi_dup_tokens(src->shaders[i]->state.shader.tokens); 875bf215546Sopenharmony_ci } else { 876bf215546Sopenharmony_ci dst->shaders[i]->state.shader.ir.nir = NULL; 877bf215546Sopenharmony_ci } 878bf215546Sopenharmony_ci } else { 879bf215546Sopenharmony_ci dst->shaders[i] = NULL; 880bf215546Sopenharmony_ci } 881bf215546Sopenharmony_ci 882bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_CONSTANT_BUFFERS; j++) { 883bf215546Sopenharmony_ci pipe_resource_reference(&dst->constant_buffers[i][j].buffer, 884bf215546Sopenharmony_ci src->constant_buffers[i][j].buffer); 885bf215546Sopenharmony_ci memcpy(&dst->constant_buffers[i][j], &src->constant_buffers[i][j], 886bf215546Sopenharmony_ci sizeof(src->constant_buffers[i][j])); 887bf215546Sopenharmony_ci } 888bf215546Sopenharmony_ci 889bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_SAMPLERS; j++) { 890bf215546Sopenharmony_ci pipe_sampler_view_reference(&dst->sampler_views[i][j], 891bf215546Sopenharmony_ci src->sampler_views[i][j]); 892bf215546Sopenharmony_ci if (src->sampler_states[i][j]) 893bf215546Sopenharmony_ci dst->sampler_states[i][j]->state.sampler = 894bf215546Sopenharmony_ci src->sampler_states[i][j]->state.sampler; 895bf215546Sopenharmony_ci else 896bf215546Sopenharmony_ci dst->sampler_states[i][j] = NULL; 897bf215546Sopenharmony_ci } 898bf215546Sopenharmony_ci 899bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_SHADER_IMAGES; j++) { 900bf215546Sopenharmony_ci pipe_resource_reference(&dst->shader_images[i][j].resource, 901bf215546Sopenharmony_ci src->shader_images[i][j].resource); 902bf215546Sopenharmony_ci memcpy(&dst->shader_images[i][j], &src->shader_images[i][j], 903bf215546Sopenharmony_ci sizeof(src->shader_images[i][j])); 904bf215546Sopenharmony_ci } 905bf215546Sopenharmony_ci 906bf215546Sopenharmony_ci for (j = 0; j < PIPE_MAX_SHADER_BUFFERS; j++) { 907bf215546Sopenharmony_ci pipe_resource_reference(&dst->shader_buffers[i][j].buffer, 908bf215546Sopenharmony_ci src->shader_buffers[i][j].buffer); 909bf215546Sopenharmony_ci memcpy(&dst->shader_buffers[i][j], &src->shader_buffers[i][j], 910bf215546Sopenharmony_ci sizeof(src->shader_buffers[i][j])); 911bf215546Sopenharmony_ci } 912bf215546Sopenharmony_ci } 913bf215546Sopenharmony_ci 914bf215546Sopenharmony_ci if (src->velems) 915bf215546Sopenharmony_ci dst->velems->state.velems = src->velems->state.velems; 916bf215546Sopenharmony_ci else 917bf215546Sopenharmony_ci dst->velems = NULL; 918bf215546Sopenharmony_ci 919bf215546Sopenharmony_ci if (src->rs) 920bf215546Sopenharmony_ci dst->rs->state.rs = src->rs->state.rs; 921bf215546Sopenharmony_ci else 922bf215546Sopenharmony_ci dst->rs = NULL; 923bf215546Sopenharmony_ci 924bf215546Sopenharmony_ci if (src->dsa) 925bf215546Sopenharmony_ci dst->dsa->state.dsa = src->dsa->state.dsa; 926bf215546Sopenharmony_ci else 927bf215546Sopenharmony_ci dst->dsa = NULL; 928bf215546Sopenharmony_ci 929bf215546Sopenharmony_ci if (src->blend) 930bf215546Sopenharmony_ci dst->blend->state.blend = src->blend->state.blend; 931bf215546Sopenharmony_ci else 932bf215546Sopenharmony_ci dst->blend = NULL; 933bf215546Sopenharmony_ci 934bf215546Sopenharmony_ci dst->blend_color = src->blend_color; 935bf215546Sopenharmony_ci dst->stencil_ref = src->stencil_ref; 936bf215546Sopenharmony_ci dst->sample_mask = src->sample_mask; 937bf215546Sopenharmony_ci dst->min_samples = src->min_samples; 938bf215546Sopenharmony_ci dst->clip_state = src->clip_state; 939bf215546Sopenharmony_ci util_copy_framebuffer_state(&dst->framebuffer_state, &src->framebuffer_state); 940bf215546Sopenharmony_ci memcpy(dst->scissors, src->scissors, sizeof(src->scissors)); 941bf215546Sopenharmony_ci memcpy(dst->viewports, src->viewports, sizeof(src->viewports)); 942bf215546Sopenharmony_ci memcpy(dst->tess_default_levels, src->tess_default_levels, 943bf215546Sopenharmony_ci sizeof(src->tess_default_levels)); 944bf215546Sopenharmony_ci dst->apitrace_call_number = src->apitrace_call_number; 945bf215546Sopenharmony_ci} 946bf215546Sopenharmony_ci 947bf215546Sopenharmony_cistatic void 948bf215546Sopenharmony_cidd_free_record(struct pipe_screen *screen, struct dd_draw_record *record) 949bf215546Sopenharmony_ci{ 950bf215546Sopenharmony_ci u_log_page_destroy(record->log_page); 951bf215546Sopenharmony_ci dd_unreference_copy_of_call(&record->call); 952bf215546Sopenharmony_ci dd_unreference_copy_of_draw_state(&record->draw_state); 953bf215546Sopenharmony_ci screen->fence_reference(screen, &record->prev_bottom_of_pipe, NULL); 954bf215546Sopenharmony_ci screen->fence_reference(screen, &record->top_of_pipe, NULL); 955bf215546Sopenharmony_ci screen->fence_reference(screen, &record->bottom_of_pipe, NULL); 956bf215546Sopenharmony_ci util_queue_fence_destroy(&record->driver_finished); 957bf215546Sopenharmony_ci FREE(record); 958bf215546Sopenharmony_ci} 959bf215546Sopenharmony_ci 960bf215546Sopenharmony_cistatic void 961bf215546Sopenharmony_cidd_write_record(FILE *f, struct dd_draw_record *record) 962bf215546Sopenharmony_ci{ 963bf215546Sopenharmony_ci PRINT_NAMED(ptr, "pipe", record->dctx->pipe); 964bf215546Sopenharmony_ci PRINT_NAMED(ns, "time before (API call)", record->time_before); 965bf215546Sopenharmony_ci PRINT_NAMED(ns, "time after (driver done)", record->time_after); 966bf215546Sopenharmony_ci fprintf(f, "\n"); 967bf215546Sopenharmony_ci 968bf215546Sopenharmony_ci dd_dump_call(f, &record->draw_state.base, &record->call); 969bf215546Sopenharmony_ci 970bf215546Sopenharmony_ci if (record->log_page) { 971bf215546Sopenharmony_ci fprintf(f,"\n\n**************************************************" 972bf215546Sopenharmony_ci "***************************\n"); 973bf215546Sopenharmony_ci fprintf(f, "Context Log:\n\n"); 974bf215546Sopenharmony_ci u_log_page_print(record->log_page, f); 975bf215546Sopenharmony_ci } 976bf215546Sopenharmony_ci} 977bf215546Sopenharmony_ci 978bf215546Sopenharmony_cistatic void 979bf215546Sopenharmony_cidd_maybe_dump_record(struct dd_screen *dscreen, struct dd_draw_record *record) 980bf215546Sopenharmony_ci{ 981bf215546Sopenharmony_ci if (dscreen->dump_mode == DD_DUMP_ONLY_HANGS || 982bf215546Sopenharmony_ci (dscreen->dump_mode == DD_DUMP_APITRACE_CALL && 983bf215546Sopenharmony_ci dscreen->apitrace_dump_call != record->draw_state.base.apitrace_call_number)) 984bf215546Sopenharmony_ci return; 985bf215546Sopenharmony_ci 986bf215546Sopenharmony_ci char name[512]; 987bf215546Sopenharmony_ci dd_get_debug_filename_and_mkdir(name, sizeof(name), dscreen->verbose); 988bf215546Sopenharmony_ci FILE *f = fopen(name, "w"); 989bf215546Sopenharmony_ci if (!f) { 990bf215546Sopenharmony_ci fprintf(stderr, "dd: failed to open %s\n", name); 991bf215546Sopenharmony_ci return; 992bf215546Sopenharmony_ci } 993bf215546Sopenharmony_ci 994bf215546Sopenharmony_ci dd_write_header(f, dscreen->screen, record->draw_state.base.apitrace_call_number); 995bf215546Sopenharmony_ci dd_write_record(f, record); 996bf215546Sopenharmony_ci 997bf215546Sopenharmony_ci fclose(f); 998bf215546Sopenharmony_ci} 999bf215546Sopenharmony_ci 1000bf215546Sopenharmony_cistatic const char * 1001bf215546Sopenharmony_cidd_fence_state(struct pipe_screen *screen, struct pipe_fence_handle *fence, 1002bf215546Sopenharmony_ci bool *not_reached) 1003bf215546Sopenharmony_ci{ 1004bf215546Sopenharmony_ci if (!fence) 1005bf215546Sopenharmony_ci return "---"; 1006bf215546Sopenharmony_ci 1007bf215546Sopenharmony_ci bool ok = screen->fence_finish(screen, NULL, fence, 0); 1008bf215546Sopenharmony_ci 1009bf215546Sopenharmony_ci if (not_reached && !ok) 1010bf215546Sopenharmony_ci *not_reached = true; 1011bf215546Sopenharmony_ci 1012bf215546Sopenharmony_ci return ok ? "YES" : "NO "; 1013bf215546Sopenharmony_ci} 1014bf215546Sopenharmony_ci 1015bf215546Sopenharmony_cistatic void 1016bf215546Sopenharmony_cidd_report_hang(struct dd_context *dctx) 1017bf215546Sopenharmony_ci{ 1018bf215546Sopenharmony_ci struct dd_screen *dscreen = dd_screen(dctx->base.screen); 1019bf215546Sopenharmony_ci struct pipe_screen *screen = dscreen->screen; 1020bf215546Sopenharmony_ci bool encountered_hang = false; 1021bf215546Sopenharmony_ci bool stop_output = false; 1022bf215546Sopenharmony_ci unsigned num_later = 0; 1023bf215546Sopenharmony_ci 1024bf215546Sopenharmony_ci fprintf(stderr, "GPU hang detected, collecting information...\n\n"); 1025bf215546Sopenharmony_ci 1026bf215546Sopenharmony_ci fprintf(stderr, "Draw # driver prev BOP TOP BOP dump file\n" 1027bf215546Sopenharmony_ci "-------------------------------------------------------------\n"); 1028bf215546Sopenharmony_ci 1029bf215546Sopenharmony_ci list_for_each_entry(struct dd_draw_record, record, &dctx->records, list) { 1030bf215546Sopenharmony_ci if (!encountered_hang && 1031bf215546Sopenharmony_ci screen->fence_finish(screen, NULL, record->bottom_of_pipe, 0)) { 1032bf215546Sopenharmony_ci dd_maybe_dump_record(dscreen, record); 1033bf215546Sopenharmony_ci continue; 1034bf215546Sopenharmony_ci } 1035bf215546Sopenharmony_ci 1036bf215546Sopenharmony_ci if (stop_output) { 1037bf215546Sopenharmony_ci dd_maybe_dump_record(dscreen, record); 1038bf215546Sopenharmony_ci num_later++; 1039bf215546Sopenharmony_ci continue; 1040bf215546Sopenharmony_ci } 1041bf215546Sopenharmony_ci 1042bf215546Sopenharmony_ci bool driver = util_queue_fence_is_signalled(&record->driver_finished); 1043bf215546Sopenharmony_ci bool top_not_reached = false; 1044bf215546Sopenharmony_ci const char *prev_bop = dd_fence_state(screen, record->prev_bottom_of_pipe, NULL); 1045bf215546Sopenharmony_ci const char *top = dd_fence_state(screen, record->top_of_pipe, &top_not_reached); 1046bf215546Sopenharmony_ci const char *bop = dd_fence_state(screen, record->bottom_of_pipe, NULL); 1047bf215546Sopenharmony_ci 1048bf215546Sopenharmony_ci fprintf(stderr, "%-9u %s %s %s %s ", 1049bf215546Sopenharmony_ci record->draw_call, driver ? "YES" : "NO ", prev_bop, top, bop); 1050bf215546Sopenharmony_ci 1051bf215546Sopenharmony_ci char name[512]; 1052bf215546Sopenharmony_ci dd_get_debug_filename_and_mkdir(name, sizeof(name), false); 1053bf215546Sopenharmony_ci 1054bf215546Sopenharmony_ci FILE *f = fopen(name, "w"); 1055bf215546Sopenharmony_ci if (!f) { 1056bf215546Sopenharmony_ci fprintf(stderr, "fopen failed\n"); 1057bf215546Sopenharmony_ci } else { 1058bf215546Sopenharmony_ci fprintf(stderr, "%s\n", name); 1059bf215546Sopenharmony_ci 1060bf215546Sopenharmony_ci dd_write_header(f, dscreen->screen, record->draw_state.base.apitrace_call_number); 1061bf215546Sopenharmony_ci dd_write_record(f, record); 1062bf215546Sopenharmony_ci 1063bf215546Sopenharmony_ci fclose(f); 1064bf215546Sopenharmony_ci } 1065bf215546Sopenharmony_ci 1066bf215546Sopenharmony_ci if (top_not_reached) 1067bf215546Sopenharmony_ci stop_output = true; 1068bf215546Sopenharmony_ci encountered_hang = true; 1069bf215546Sopenharmony_ci } 1070bf215546Sopenharmony_ci 1071bf215546Sopenharmony_ci if (num_later) 1072bf215546Sopenharmony_ci fprintf(stderr, "... and %u additional draws.\n", num_later); 1073bf215546Sopenharmony_ci 1074bf215546Sopenharmony_ci char name[512]; 1075bf215546Sopenharmony_ci dd_get_debug_filename_and_mkdir(name, sizeof(name), false); 1076bf215546Sopenharmony_ci FILE *f = fopen(name, "w"); 1077bf215546Sopenharmony_ci if (!f) { 1078bf215546Sopenharmony_ci fprintf(stderr, "fopen failed\n"); 1079bf215546Sopenharmony_ci } else { 1080bf215546Sopenharmony_ci dd_write_header(f, dscreen->screen, 0); 1081bf215546Sopenharmony_ci dd_dump_driver_state(dctx, f, PIPE_DUMP_DEVICE_STATUS_REGISTERS); 1082bf215546Sopenharmony_ci dd_dump_dmesg(f); 1083bf215546Sopenharmony_ci fclose(f); 1084bf215546Sopenharmony_ci } 1085bf215546Sopenharmony_ci 1086bf215546Sopenharmony_ci fprintf(stderr, "\nDone.\n"); 1087bf215546Sopenharmony_ci dd_kill_process(); 1088bf215546Sopenharmony_ci} 1089bf215546Sopenharmony_ci 1090bf215546Sopenharmony_ciint 1091bf215546Sopenharmony_cidd_thread_main(void *input) 1092bf215546Sopenharmony_ci{ 1093bf215546Sopenharmony_ci struct dd_context *dctx = (struct dd_context *)input; 1094bf215546Sopenharmony_ci struct dd_screen *dscreen = dd_screen(dctx->base.screen); 1095bf215546Sopenharmony_ci struct pipe_screen *screen = dscreen->screen; 1096bf215546Sopenharmony_ci 1097bf215546Sopenharmony_ci const char *process_name = util_get_process_name(); 1098bf215546Sopenharmony_ci if (process_name) { 1099bf215546Sopenharmony_ci char threadname[16]; 1100bf215546Sopenharmony_ci snprintf(threadname, sizeof(threadname), "%.*s:ddbg", 1101bf215546Sopenharmony_ci (int)MIN2(strlen(process_name), sizeof(threadname) - 6), 1102bf215546Sopenharmony_ci process_name); 1103bf215546Sopenharmony_ci u_thread_setname(threadname); 1104bf215546Sopenharmony_ci } 1105bf215546Sopenharmony_ci 1106bf215546Sopenharmony_ci mtx_lock(&dctx->mutex); 1107bf215546Sopenharmony_ci 1108bf215546Sopenharmony_ci for (;;) { 1109bf215546Sopenharmony_ci struct list_head records; 1110bf215546Sopenharmony_ci list_replace(&dctx->records, &records); 1111bf215546Sopenharmony_ci list_inithead(&dctx->records); 1112bf215546Sopenharmony_ci dctx->num_records = 0; 1113bf215546Sopenharmony_ci 1114bf215546Sopenharmony_ci if (dctx->api_stalled) 1115bf215546Sopenharmony_ci cnd_signal(&dctx->cond); 1116bf215546Sopenharmony_ci 1117bf215546Sopenharmony_ci if (list_is_empty(&records)) { 1118bf215546Sopenharmony_ci if (dctx->kill_thread) 1119bf215546Sopenharmony_ci break; 1120bf215546Sopenharmony_ci 1121bf215546Sopenharmony_ci cnd_wait(&dctx->cond, &dctx->mutex); 1122bf215546Sopenharmony_ci continue; 1123bf215546Sopenharmony_ci } 1124bf215546Sopenharmony_ci 1125bf215546Sopenharmony_ci mtx_unlock(&dctx->mutex); 1126bf215546Sopenharmony_ci 1127bf215546Sopenharmony_ci /* Wait for the youngest draw. This means hangs can take a bit longer 1128bf215546Sopenharmony_ci * to detect, but it's more efficient this way. */ 1129bf215546Sopenharmony_ci struct dd_draw_record *youngest = 1130bf215546Sopenharmony_ci list_last_entry(&records, struct dd_draw_record, list); 1131bf215546Sopenharmony_ci 1132bf215546Sopenharmony_ci if (dscreen->timeout_ms > 0) { 1133bf215546Sopenharmony_ci uint64_t abs_timeout = os_time_get_absolute_timeout( 1134bf215546Sopenharmony_ci (uint64_t)dscreen->timeout_ms * 1000*1000); 1135bf215546Sopenharmony_ci 1136bf215546Sopenharmony_ci if (!util_queue_fence_wait_timeout(&youngest->driver_finished, abs_timeout) || 1137bf215546Sopenharmony_ci !screen->fence_finish(screen, NULL, youngest->bottom_of_pipe, 1138bf215546Sopenharmony_ci (uint64_t)dscreen->timeout_ms * 1000*1000)) { 1139bf215546Sopenharmony_ci mtx_lock(&dctx->mutex); 1140bf215546Sopenharmony_ci list_splice(&records, &dctx->records); 1141bf215546Sopenharmony_ci dd_report_hang(dctx); 1142bf215546Sopenharmony_ci /* we won't actually get here */ 1143bf215546Sopenharmony_ci mtx_unlock(&dctx->mutex); 1144bf215546Sopenharmony_ci } 1145bf215546Sopenharmony_ci } else { 1146bf215546Sopenharmony_ci util_queue_fence_wait(&youngest->driver_finished); 1147bf215546Sopenharmony_ci } 1148bf215546Sopenharmony_ci 1149bf215546Sopenharmony_ci list_for_each_entry_safe(struct dd_draw_record, record, &records, list) { 1150bf215546Sopenharmony_ci dd_maybe_dump_record(dscreen, record); 1151bf215546Sopenharmony_ci list_del(&record->list); 1152bf215546Sopenharmony_ci dd_free_record(screen, record); 1153bf215546Sopenharmony_ci } 1154bf215546Sopenharmony_ci 1155bf215546Sopenharmony_ci mtx_lock(&dctx->mutex); 1156bf215546Sopenharmony_ci } 1157bf215546Sopenharmony_ci mtx_unlock(&dctx->mutex); 1158bf215546Sopenharmony_ci return 0; 1159bf215546Sopenharmony_ci} 1160bf215546Sopenharmony_ci 1161bf215546Sopenharmony_cistatic struct dd_draw_record * 1162bf215546Sopenharmony_cidd_create_record(struct dd_context *dctx) 1163bf215546Sopenharmony_ci{ 1164bf215546Sopenharmony_ci struct dd_draw_record *record; 1165bf215546Sopenharmony_ci 1166bf215546Sopenharmony_ci record = MALLOC_STRUCT(dd_draw_record); 1167bf215546Sopenharmony_ci if (!record) 1168bf215546Sopenharmony_ci return NULL; 1169bf215546Sopenharmony_ci 1170bf215546Sopenharmony_ci record->dctx = dctx; 1171bf215546Sopenharmony_ci record->draw_call = dctx->num_draw_calls; 1172bf215546Sopenharmony_ci 1173bf215546Sopenharmony_ci record->prev_bottom_of_pipe = NULL; 1174bf215546Sopenharmony_ci record->top_of_pipe = NULL; 1175bf215546Sopenharmony_ci record->bottom_of_pipe = NULL; 1176bf215546Sopenharmony_ci record->log_page = NULL; 1177bf215546Sopenharmony_ci util_queue_fence_init(&record->driver_finished); 1178bf215546Sopenharmony_ci util_queue_fence_reset(&record->driver_finished); 1179bf215546Sopenharmony_ci 1180bf215546Sopenharmony_ci dd_init_copy_of_draw_state(&record->draw_state); 1181bf215546Sopenharmony_ci dd_copy_draw_state(&record->draw_state.base, &dctx->draw_state); 1182bf215546Sopenharmony_ci 1183bf215546Sopenharmony_ci return record; 1184bf215546Sopenharmony_ci} 1185bf215546Sopenharmony_ci 1186bf215546Sopenharmony_cistatic void 1187bf215546Sopenharmony_cidd_add_record(struct dd_context *dctx, struct dd_draw_record *record) 1188bf215546Sopenharmony_ci{ 1189bf215546Sopenharmony_ci mtx_lock(&dctx->mutex); 1190bf215546Sopenharmony_ci if (unlikely(dctx->num_records > 10000)) { 1191bf215546Sopenharmony_ci dctx->api_stalled = true; 1192bf215546Sopenharmony_ci /* Since this is only a heuristic to prevent the API thread from getting 1193bf215546Sopenharmony_ci * too far ahead, we don't need a loop here. */ 1194bf215546Sopenharmony_ci cnd_wait(&dctx->cond, &dctx->mutex); 1195bf215546Sopenharmony_ci dctx->api_stalled = false; 1196bf215546Sopenharmony_ci } 1197bf215546Sopenharmony_ci 1198bf215546Sopenharmony_ci if (list_is_empty(&dctx->records)) 1199bf215546Sopenharmony_ci cnd_signal(&dctx->cond); 1200bf215546Sopenharmony_ci 1201bf215546Sopenharmony_ci list_addtail(&record->list, &dctx->records); 1202bf215546Sopenharmony_ci dctx->num_records++; 1203bf215546Sopenharmony_ci mtx_unlock(&dctx->mutex); 1204bf215546Sopenharmony_ci} 1205bf215546Sopenharmony_ci 1206bf215546Sopenharmony_cistatic void 1207bf215546Sopenharmony_cidd_before_draw(struct dd_context *dctx, struct dd_draw_record *record) 1208bf215546Sopenharmony_ci{ 1209bf215546Sopenharmony_ci struct dd_screen *dscreen = dd_screen(dctx->base.screen); 1210bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1211bf215546Sopenharmony_ci struct pipe_screen *screen = dscreen->screen; 1212bf215546Sopenharmony_ci 1213bf215546Sopenharmony_ci record->time_before = os_time_get_nano(); 1214bf215546Sopenharmony_ci 1215bf215546Sopenharmony_ci if (dscreen->timeout_ms > 0) { 1216bf215546Sopenharmony_ci if (dscreen->flush_always && dctx->num_draw_calls >= dscreen->skip_count) { 1217bf215546Sopenharmony_ci pipe->flush(pipe, &record->prev_bottom_of_pipe, 0); 1218bf215546Sopenharmony_ci screen->fence_reference(screen, &record->top_of_pipe, record->prev_bottom_of_pipe); 1219bf215546Sopenharmony_ci } else { 1220bf215546Sopenharmony_ci pipe->flush(pipe, &record->prev_bottom_of_pipe, 1221bf215546Sopenharmony_ci PIPE_FLUSH_DEFERRED | PIPE_FLUSH_BOTTOM_OF_PIPE); 1222bf215546Sopenharmony_ci pipe->flush(pipe, &record->top_of_pipe, 1223bf215546Sopenharmony_ci PIPE_FLUSH_DEFERRED | PIPE_FLUSH_TOP_OF_PIPE); 1224bf215546Sopenharmony_ci } 1225bf215546Sopenharmony_ci } else if (dscreen->flush_always && dctx->num_draw_calls >= dscreen->skip_count) { 1226bf215546Sopenharmony_ci pipe->flush(pipe, NULL, 0); 1227bf215546Sopenharmony_ci } 1228bf215546Sopenharmony_ci 1229bf215546Sopenharmony_ci dd_add_record(dctx, record); 1230bf215546Sopenharmony_ci} 1231bf215546Sopenharmony_ci 1232bf215546Sopenharmony_cistatic void 1233bf215546Sopenharmony_cidd_after_draw_async(void *data) 1234bf215546Sopenharmony_ci{ 1235bf215546Sopenharmony_ci struct dd_draw_record *record = (struct dd_draw_record *)data; 1236bf215546Sopenharmony_ci struct dd_context *dctx = record->dctx; 1237bf215546Sopenharmony_ci struct dd_screen *dscreen = dd_screen(dctx->base.screen); 1238bf215546Sopenharmony_ci 1239bf215546Sopenharmony_ci record->log_page = u_log_new_page(&dctx->log); 1240bf215546Sopenharmony_ci record->time_after = os_time_get_nano(); 1241bf215546Sopenharmony_ci 1242bf215546Sopenharmony_ci util_queue_fence_signal(&record->driver_finished); 1243bf215546Sopenharmony_ci 1244bf215546Sopenharmony_ci if (dscreen->dump_mode == DD_DUMP_APITRACE_CALL && 1245bf215546Sopenharmony_ci dscreen->apitrace_dump_call > dctx->draw_state.apitrace_call_number) { 1246bf215546Sopenharmony_ci dd_thread_join(dctx); 1247bf215546Sopenharmony_ci /* No need to continue. */ 1248bf215546Sopenharmony_ci exit(0); 1249bf215546Sopenharmony_ci } 1250bf215546Sopenharmony_ci} 1251bf215546Sopenharmony_ci 1252bf215546Sopenharmony_cistatic void 1253bf215546Sopenharmony_cidd_after_draw(struct dd_context *dctx, struct dd_draw_record *record) 1254bf215546Sopenharmony_ci{ 1255bf215546Sopenharmony_ci struct dd_screen *dscreen = dd_screen(dctx->base.screen); 1256bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1257bf215546Sopenharmony_ci 1258bf215546Sopenharmony_ci if (dscreen->timeout_ms > 0) { 1259bf215546Sopenharmony_ci unsigned flush_flags; 1260bf215546Sopenharmony_ci if (dscreen->flush_always && dctx->num_draw_calls >= dscreen->skip_count) 1261bf215546Sopenharmony_ci flush_flags = 0; 1262bf215546Sopenharmony_ci else 1263bf215546Sopenharmony_ci flush_flags = PIPE_FLUSH_DEFERRED | PIPE_FLUSH_BOTTOM_OF_PIPE; 1264bf215546Sopenharmony_ci pipe->flush(pipe, &record->bottom_of_pipe, flush_flags); 1265bf215546Sopenharmony_ci } 1266bf215546Sopenharmony_ci 1267bf215546Sopenharmony_ci if (pipe->callback) { 1268bf215546Sopenharmony_ci pipe->callback(pipe, dd_after_draw_async, record, true); 1269bf215546Sopenharmony_ci } else { 1270bf215546Sopenharmony_ci dd_after_draw_async(record); 1271bf215546Sopenharmony_ci } 1272bf215546Sopenharmony_ci 1273bf215546Sopenharmony_ci ++dctx->num_draw_calls; 1274bf215546Sopenharmony_ci if (dscreen->skip_count && dctx->num_draw_calls % 10000 == 0) 1275bf215546Sopenharmony_ci fprintf(stderr, "Gallium debugger reached %u draw calls.\n", 1276bf215546Sopenharmony_ci dctx->num_draw_calls); 1277bf215546Sopenharmony_ci} 1278bf215546Sopenharmony_ci 1279bf215546Sopenharmony_cistatic void 1280bf215546Sopenharmony_cidd_context_flush(struct pipe_context *_pipe, 1281bf215546Sopenharmony_ci struct pipe_fence_handle **fence, unsigned flags) 1282bf215546Sopenharmony_ci{ 1283bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1284bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1285bf215546Sopenharmony_ci struct pipe_screen *screen = pipe->screen; 1286bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1287bf215546Sopenharmony_ci 1288bf215546Sopenharmony_ci record->call.type = CALL_FLUSH; 1289bf215546Sopenharmony_ci record->call.info.flush.flags = flags; 1290bf215546Sopenharmony_ci 1291bf215546Sopenharmony_ci record->time_before = os_time_get_nano(); 1292bf215546Sopenharmony_ci 1293bf215546Sopenharmony_ci dd_add_record(dctx, record); 1294bf215546Sopenharmony_ci 1295bf215546Sopenharmony_ci pipe->flush(pipe, &record->bottom_of_pipe, flags); 1296bf215546Sopenharmony_ci if (fence) 1297bf215546Sopenharmony_ci screen->fence_reference(screen, fence, record->bottom_of_pipe); 1298bf215546Sopenharmony_ci 1299bf215546Sopenharmony_ci if (pipe->callback) { 1300bf215546Sopenharmony_ci pipe->callback(pipe, dd_after_draw_async, record, true); 1301bf215546Sopenharmony_ci } else { 1302bf215546Sopenharmony_ci dd_after_draw_async(record); 1303bf215546Sopenharmony_ci } 1304bf215546Sopenharmony_ci} 1305bf215546Sopenharmony_ci 1306bf215546Sopenharmony_cistatic void 1307bf215546Sopenharmony_cidd_context_draw_vbo(struct pipe_context *_pipe, 1308bf215546Sopenharmony_ci const struct pipe_draw_info *info, 1309bf215546Sopenharmony_ci unsigned drawid_offset, 1310bf215546Sopenharmony_ci const struct pipe_draw_indirect_info *indirect, 1311bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draws, 1312bf215546Sopenharmony_ci unsigned num_draws) 1313bf215546Sopenharmony_ci{ 1314bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1315bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1316bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1317bf215546Sopenharmony_ci 1318bf215546Sopenharmony_ci record->call.type = CALL_DRAW_VBO; 1319bf215546Sopenharmony_ci record->call.info.draw_vbo.info = *info; 1320bf215546Sopenharmony_ci record->call.info.draw_vbo.drawid_offset = drawid_offset; 1321bf215546Sopenharmony_ci record->call.info.draw_vbo.draw = draws[0]; 1322bf215546Sopenharmony_ci if (info->index_size && !info->has_user_indices) { 1323bf215546Sopenharmony_ci record->call.info.draw_vbo.info.index.resource = NULL; 1324bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.draw_vbo.info.index.resource, 1325bf215546Sopenharmony_ci info->index.resource); 1326bf215546Sopenharmony_ci } 1327bf215546Sopenharmony_ci 1328bf215546Sopenharmony_ci if (indirect) { 1329bf215546Sopenharmony_ci record->call.info.draw_vbo.indirect = *indirect; 1330bf215546Sopenharmony_ci record->call.info.draw_vbo.indirect.buffer = NULL; 1331bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.draw_vbo.indirect.buffer, 1332bf215546Sopenharmony_ci indirect->buffer); 1333bf215546Sopenharmony_ci record->call.info.draw_vbo.indirect.indirect_draw_count = NULL; 1334bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.draw_vbo.indirect.indirect_draw_count, 1335bf215546Sopenharmony_ci indirect->indirect_draw_count); 1336bf215546Sopenharmony_ci record->call.info.draw_vbo.indirect.count_from_stream_output = NULL; 1337bf215546Sopenharmony_ci pipe_so_target_reference(&record->call.info.draw_vbo.indirect.count_from_stream_output, 1338bf215546Sopenharmony_ci indirect->count_from_stream_output); 1339bf215546Sopenharmony_ci } else { 1340bf215546Sopenharmony_ci memset(&record->call.info.draw_vbo.indirect, 0, sizeof(*indirect)); 1341bf215546Sopenharmony_ci } 1342bf215546Sopenharmony_ci 1343bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1344bf215546Sopenharmony_ci pipe->draw_vbo(pipe, info, drawid_offset, indirect, draws, num_draws); 1345bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1346bf215546Sopenharmony_ci} 1347bf215546Sopenharmony_ci 1348bf215546Sopenharmony_cistatic void 1349bf215546Sopenharmony_cidd_context_draw_vertex_state(struct pipe_context *_pipe, 1350bf215546Sopenharmony_ci struct pipe_vertex_state *state, 1351bf215546Sopenharmony_ci uint32_t partial_velem_mask, 1352bf215546Sopenharmony_ci struct pipe_draw_vertex_state_info info, 1353bf215546Sopenharmony_ci const struct pipe_draw_start_count_bias *draws, 1354bf215546Sopenharmony_ci unsigned num_draws) 1355bf215546Sopenharmony_ci{ 1356bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1357bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1358bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1359bf215546Sopenharmony_ci 1360bf215546Sopenharmony_ci record->call.type = CALL_DRAW_VBO; 1361bf215546Sopenharmony_ci memset(&record->call.info.draw_vbo.info, 0, 1362bf215546Sopenharmony_ci sizeof(record->call.info.draw_vbo.info)); 1363bf215546Sopenharmony_ci record->call.info.draw_vbo.info.mode = info.mode; 1364bf215546Sopenharmony_ci record->call.info.draw_vbo.info.index_size = 4; 1365bf215546Sopenharmony_ci record->call.info.draw_vbo.info.instance_count = 1; 1366bf215546Sopenharmony_ci record->call.info.draw_vbo.drawid_offset = 0; 1367bf215546Sopenharmony_ci record->call.info.draw_vbo.draw = draws[0]; 1368bf215546Sopenharmony_ci record->call.info.draw_vbo.info.index.resource = NULL; 1369bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.draw_vbo.info.index.resource, 1370bf215546Sopenharmony_ci state->input.indexbuf); 1371bf215546Sopenharmony_ci memset(&record->call.info.draw_vbo.indirect, 0, 1372bf215546Sopenharmony_ci sizeof(record->call.info.draw_vbo.indirect)); 1373bf215546Sopenharmony_ci 1374bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1375bf215546Sopenharmony_ci pipe->draw_vertex_state(pipe, state, partial_velem_mask, info, draws, num_draws); 1376bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1377bf215546Sopenharmony_ci} 1378bf215546Sopenharmony_ci 1379bf215546Sopenharmony_cistatic void 1380bf215546Sopenharmony_cidd_context_launch_grid(struct pipe_context *_pipe, 1381bf215546Sopenharmony_ci const struct pipe_grid_info *info) 1382bf215546Sopenharmony_ci{ 1383bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1384bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1385bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1386bf215546Sopenharmony_ci 1387bf215546Sopenharmony_ci record->call.type = CALL_LAUNCH_GRID; 1388bf215546Sopenharmony_ci record->call.info.launch_grid = *info; 1389bf215546Sopenharmony_ci record->call.info.launch_grid.indirect = NULL; 1390bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.launch_grid.indirect, info->indirect); 1391bf215546Sopenharmony_ci 1392bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1393bf215546Sopenharmony_ci pipe->launch_grid(pipe, info); 1394bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1395bf215546Sopenharmony_ci} 1396bf215546Sopenharmony_ci 1397bf215546Sopenharmony_cistatic void 1398bf215546Sopenharmony_cidd_context_resource_copy_region(struct pipe_context *_pipe, 1399bf215546Sopenharmony_ci struct pipe_resource *dst, unsigned dst_level, 1400bf215546Sopenharmony_ci unsigned dstx, unsigned dsty, unsigned dstz, 1401bf215546Sopenharmony_ci struct pipe_resource *src, unsigned src_level, 1402bf215546Sopenharmony_ci const struct pipe_box *src_box) 1403bf215546Sopenharmony_ci{ 1404bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1405bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1406bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1407bf215546Sopenharmony_ci 1408bf215546Sopenharmony_ci record->call.type = CALL_RESOURCE_COPY_REGION; 1409bf215546Sopenharmony_ci record->call.info.resource_copy_region.dst = NULL; 1410bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.resource_copy_region.dst, dst); 1411bf215546Sopenharmony_ci record->call.info.resource_copy_region.dst_level = dst_level; 1412bf215546Sopenharmony_ci record->call.info.resource_copy_region.dstx = dstx; 1413bf215546Sopenharmony_ci record->call.info.resource_copy_region.dsty = dsty; 1414bf215546Sopenharmony_ci record->call.info.resource_copy_region.dstz = dstz; 1415bf215546Sopenharmony_ci record->call.info.resource_copy_region.src = NULL; 1416bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.resource_copy_region.src, src); 1417bf215546Sopenharmony_ci record->call.info.resource_copy_region.src_level = src_level; 1418bf215546Sopenharmony_ci record->call.info.resource_copy_region.src_box = *src_box; 1419bf215546Sopenharmony_ci 1420bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1421bf215546Sopenharmony_ci pipe->resource_copy_region(pipe, 1422bf215546Sopenharmony_ci dst, dst_level, dstx, dsty, dstz, 1423bf215546Sopenharmony_ci src, src_level, src_box); 1424bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1425bf215546Sopenharmony_ci} 1426bf215546Sopenharmony_ci 1427bf215546Sopenharmony_cistatic void 1428bf215546Sopenharmony_cidd_context_blit(struct pipe_context *_pipe, const struct pipe_blit_info *info) 1429bf215546Sopenharmony_ci{ 1430bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1431bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1432bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1433bf215546Sopenharmony_ci 1434bf215546Sopenharmony_ci record->call.type = CALL_BLIT; 1435bf215546Sopenharmony_ci record->call.info.blit = *info; 1436bf215546Sopenharmony_ci record->call.info.blit.dst.resource = NULL; 1437bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.blit.dst.resource, info->dst.resource); 1438bf215546Sopenharmony_ci record->call.info.blit.src.resource = NULL; 1439bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.blit.src.resource, info->src.resource); 1440bf215546Sopenharmony_ci 1441bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1442bf215546Sopenharmony_ci pipe->blit(pipe, info); 1443bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1444bf215546Sopenharmony_ci} 1445bf215546Sopenharmony_ci 1446bf215546Sopenharmony_cistatic bool 1447bf215546Sopenharmony_cidd_context_generate_mipmap(struct pipe_context *_pipe, 1448bf215546Sopenharmony_ci struct pipe_resource *res, 1449bf215546Sopenharmony_ci enum pipe_format format, 1450bf215546Sopenharmony_ci unsigned base_level, 1451bf215546Sopenharmony_ci unsigned last_level, 1452bf215546Sopenharmony_ci unsigned first_layer, 1453bf215546Sopenharmony_ci unsigned last_layer) 1454bf215546Sopenharmony_ci{ 1455bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1456bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1457bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1458bf215546Sopenharmony_ci bool result; 1459bf215546Sopenharmony_ci 1460bf215546Sopenharmony_ci record->call.type = CALL_GENERATE_MIPMAP; 1461bf215546Sopenharmony_ci record->call.info.generate_mipmap.res = NULL; 1462bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.generate_mipmap.res, res); 1463bf215546Sopenharmony_ci record->call.info.generate_mipmap.format = format; 1464bf215546Sopenharmony_ci record->call.info.generate_mipmap.base_level = base_level; 1465bf215546Sopenharmony_ci record->call.info.generate_mipmap.last_level = last_level; 1466bf215546Sopenharmony_ci record->call.info.generate_mipmap.first_layer = first_layer; 1467bf215546Sopenharmony_ci record->call.info.generate_mipmap.last_layer = last_layer; 1468bf215546Sopenharmony_ci 1469bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1470bf215546Sopenharmony_ci result = pipe->generate_mipmap(pipe, res, format, base_level, last_level, 1471bf215546Sopenharmony_ci first_layer, last_layer); 1472bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1473bf215546Sopenharmony_ci return result; 1474bf215546Sopenharmony_ci} 1475bf215546Sopenharmony_ci 1476bf215546Sopenharmony_cistatic void 1477bf215546Sopenharmony_cidd_context_get_query_result_resource(struct pipe_context *_pipe, 1478bf215546Sopenharmony_ci struct pipe_query *query, 1479bf215546Sopenharmony_ci enum pipe_query_flags flags, 1480bf215546Sopenharmony_ci enum pipe_query_value_type result_type, 1481bf215546Sopenharmony_ci int index, 1482bf215546Sopenharmony_ci struct pipe_resource *resource, 1483bf215546Sopenharmony_ci unsigned offset) 1484bf215546Sopenharmony_ci{ 1485bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1486bf215546Sopenharmony_ci struct dd_query *dquery = dd_query(query); 1487bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1488bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1489bf215546Sopenharmony_ci 1490bf215546Sopenharmony_ci record->call.type = CALL_GET_QUERY_RESULT_RESOURCE; 1491bf215546Sopenharmony_ci record->call.info.get_query_result_resource.query = query; 1492bf215546Sopenharmony_ci record->call.info.get_query_result_resource.flags = flags; 1493bf215546Sopenharmony_ci record->call.info.get_query_result_resource.result_type = result_type; 1494bf215546Sopenharmony_ci record->call.info.get_query_result_resource.index = index; 1495bf215546Sopenharmony_ci record->call.info.get_query_result_resource.resource = NULL; 1496bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.get_query_result_resource.resource, 1497bf215546Sopenharmony_ci resource); 1498bf215546Sopenharmony_ci record->call.info.get_query_result_resource.offset = offset; 1499bf215546Sopenharmony_ci 1500bf215546Sopenharmony_ci /* The query may be deleted by the time we need to print it. */ 1501bf215546Sopenharmony_ci record->call.info.get_query_result_resource.query_type = dquery->type; 1502bf215546Sopenharmony_ci 1503bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1504bf215546Sopenharmony_ci pipe->get_query_result_resource(pipe, dquery->query, flags, 1505bf215546Sopenharmony_ci result_type, index, resource, offset); 1506bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1507bf215546Sopenharmony_ci} 1508bf215546Sopenharmony_ci 1509bf215546Sopenharmony_cistatic void 1510bf215546Sopenharmony_cidd_context_flush_resource(struct pipe_context *_pipe, 1511bf215546Sopenharmony_ci struct pipe_resource *resource) 1512bf215546Sopenharmony_ci{ 1513bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1514bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1515bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1516bf215546Sopenharmony_ci 1517bf215546Sopenharmony_ci record->call.type = CALL_FLUSH_RESOURCE; 1518bf215546Sopenharmony_ci record->call.info.flush_resource = NULL; 1519bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.flush_resource, resource); 1520bf215546Sopenharmony_ci 1521bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1522bf215546Sopenharmony_ci pipe->flush_resource(pipe, resource); 1523bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1524bf215546Sopenharmony_ci} 1525bf215546Sopenharmony_ci 1526bf215546Sopenharmony_cistatic void 1527bf215546Sopenharmony_cidd_context_clear(struct pipe_context *_pipe, unsigned buffers, const struct pipe_scissor_state *scissor_state, 1528bf215546Sopenharmony_ci const union pipe_color_union *color, double depth, 1529bf215546Sopenharmony_ci unsigned stencil) 1530bf215546Sopenharmony_ci{ 1531bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1532bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1533bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1534bf215546Sopenharmony_ci 1535bf215546Sopenharmony_ci record->call.type = CALL_CLEAR; 1536bf215546Sopenharmony_ci record->call.info.clear.buffers = buffers; 1537bf215546Sopenharmony_ci if (scissor_state) 1538bf215546Sopenharmony_ci record->call.info.clear.scissor_state = *scissor_state; 1539bf215546Sopenharmony_ci record->call.info.clear.color = *color; 1540bf215546Sopenharmony_ci record->call.info.clear.depth = depth; 1541bf215546Sopenharmony_ci record->call.info.clear.stencil = stencil; 1542bf215546Sopenharmony_ci 1543bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1544bf215546Sopenharmony_ci pipe->clear(pipe, buffers, scissor_state, color, depth, stencil); 1545bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1546bf215546Sopenharmony_ci} 1547bf215546Sopenharmony_ci 1548bf215546Sopenharmony_cistatic void 1549bf215546Sopenharmony_cidd_context_clear_render_target(struct pipe_context *_pipe, 1550bf215546Sopenharmony_ci struct pipe_surface *dst, 1551bf215546Sopenharmony_ci const union pipe_color_union *color, 1552bf215546Sopenharmony_ci unsigned dstx, unsigned dsty, 1553bf215546Sopenharmony_ci unsigned width, unsigned height, 1554bf215546Sopenharmony_ci bool render_condition_enabled) 1555bf215546Sopenharmony_ci{ 1556bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1557bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1558bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1559bf215546Sopenharmony_ci 1560bf215546Sopenharmony_ci record->call.type = CALL_CLEAR_RENDER_TARGET; 1561bf215546Sopenharmony_ci 1562bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1563bf215546Sopenharmony_ci pipe->clear_render_target(pipe, dst, color, dstx, dsty, width, height, 1564bf215546Sopenharmony_ci render_condition_enabled); 1565bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1566bf215546Sopenharmony_ci} 1567bf215546Sopenharmony_ci 1568bf215546Sopenharmony_cistatic void 1569bf215546Sopenharmony_cidd_context_clear_depth_stencil(struct pipe_context *_pipe, 1570bf215546Sopenharmony_ci struct pipe_surface *dst, unsigned clear_flags, 1571bf215546Sopenharmony_ci double depth, unsigned stencil, unsigned dstx, 1572bf215546Sopenharmony_ci unsigned dsty, unsigned width, unsigned height, 1573bf215546Sopenharmony_ci bool render_condition_enabled) 1574bf215546Sopenharmony_ci{ 1575bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1576bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1577bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1578bf215546Sopenharmony_ci 1579bf215546Sopenharmony_ci record->call.type = CALL_CLEAR_DEPTH_STENCIL; 1580bf215546Sopenharmony_ci 1581bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1582bf215546Sopenharmony_ci pipe->clear_depth_stencil(pipe, dst, clear_flags, depth, stencil, 1583bf215546Sopenharmony_ci dstx, dsty, width, height, 1584bf215546Sopenharmony_ci render_condition_enabled); 1585bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1586bf215546Sopenharmony_ci} 1587bf215546Sopenharmony_ci 1588bf215546Sopenharmony_cistatic void 1589bf215546Sopenharmony_cidd_context_clear_buffer(struct pipe_context *_pipe, struct pipe_resource *res, 1590bf215546Sopenharmony_ci unsigned offset, unsigned size, 1591bf215546Sopenharmony_ci const void *clear_value, int clear_value_size) 1592bf215546Sopenharmony_ci{ 1593bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1594bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1595bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1596bf215546Sopenharmony_ci 1597bf215546Sopenharmony_ci record->call.type = CALL_CLEAR_BUFFER; 1598bf215546Sopenharmony_ci record->call.info.clear_buffer.res = NULL; 1599bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.clear_buffer.res, res); 1600bf215546Sopenharmony_ci record->call.info.clear_buffer.offset = offset; 1601bf215546Sopenharmony_ci record->call.info.clear_buffer.size = size; 1602bf215546Sopenharmony_ci record->call.info.clear_buffer.clear_value = clear_value; 1603bf215546Sopenharmony_ci record->call.info.clear_buffer.clear_value_size = clear_value_size; 1604bf215546Sopenharmony_ci 1605bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1606bf215546Sopenharmony_ci pipe->clear_buffer(pipe, res, offset, size, clear_value, clear_value_size); 1607bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1608bf215546Sopenharmony_ci} 1609bf215546Sopenharmony_ci 1610bf215546Sopenharmony_cistatic void 1611bf215546Sopenharmony_cidd_context_clear_texture(struct pipe_context *_pipe, 1612bf215546Sopenharmony_ci struct pipe_resource *res, 1613bf215546Sopenharmony_ci unsigned level, 1614bf215546Sopenharmony_ci const struct pipe_box *box, 1615bf215546Sopenharmony_ci const void *data) 1616bf215546Sopenharmony_ci{ 1617bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1618bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1619bf215546Sopenharmony_ci struct dd_draw_record *record = dd_create_record(dctx); 1620bf215546Sopenharmony_ci 1621bf215546Sopenharmony_ci record->call.type = CALL_CLEAR_TEXTURE; 1622bf215546Sopenharmony_ci 1623bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1624bf215546Sopenharmony_ci pipe->clear_texture(pipe, res, level, box, data); 1625bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1626bf215546Sopenharmony_ci} 1627bf215546Sopenharmony_ci 1628bf215546Sopenharmony_ci/******************************************************************** 1629bf215546Sopenharmony_ci * transfer 1630bf215546Sopenharmony_ci */ 1631bf215546Sopenharmony_ci 1632bf215546Sopenharmony_cistatic void * 1633bf215546Sopenharmony_cidd_context_buffer_map(struct pipe_context *_pipe, 1634bf215546Sopenharmony_ci struct pipe_resource *resource, unsigned level, 1635bf215546Sopenharmony_ci unsigned usage, const struct pipe_box *box, 1636bf215546Sopenharmony_ci struct pipe_transfer **transfer) 1637bf215546Sopenharmony_ci{ 1638bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1639bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1640bf215546Sopenharmony_ci struct dd_draw_record *record = 1641bf215546Sopenharmony_ci dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL; 1642bf215546Sopenharmony_ci 1643bf215546Sopenharmony_ci if (record) { 1644bf215546Sopenharmony_ci record->call.type = CALL_TRANSFER_MAP; 1645bf215546Sopenharmony_ci 1646bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1647bf215546Sopenharmony_ci } 1648bf215546Sopenharmony_ci void *ptr = pipe->buffer_map(pipe, resource, level, usage, box, transfer); 1649bf215546Sopenharmony_ci if (record) { 1650bf215546Sopenharmony_ci record->call.info.transfer_map.transfer_ptr = *transfer; 1651bf215546Sopenharmony_ci record->call.info.transfer_map.ptr = ptr; 1652bf215546Sopenharmony_ci if (*transfer) { 1653bf215546Sopenharmony_ci record->call.info.transfer_map.transfer = **transfer; 1654bf215546Sopenharmony_ci record->call.info.transfer_map.transfer.resource = NULL; 1655bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.transfer_map.transfer.resource, 1656bf215546Sopenharmony_ci (*transfer)->resource); 1657bf215546Sopenharmony_ci } else { 1658bf215546Sopenharmony_ci memset(&record->call.info.transfer_map.transfer, 0, sizeof(struct pipe_transfer)); 1659bf215546Sopenharmony_ci } 1660bf215546Sopenharmony_ci 1661bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1662bf215546Sopenharmony_ci } 1663bf215546Sopenharmony_ci return ptr; 1664bf215546Sopenharmony_ci} 1665bf215546Sopenharmony_ci 1666bf215546Sopenharmony_cistatic void * 1667bf215546Sopenharmony_cidd_context_texture_map(struct pipe_context *_pipe, 1668bf215546Sopenharmony_ci struct pipe_resource *resource, unsigned level, 1669bf215546Sopenharmony_ci unsigned usage, const struct pipe_box *box, 1670bf215546Sopenharmony_ci struct pipe_transfer **transfer) 1671bf215546Sopenharmony_ci{ 1672bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1673bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1674bf215546Sopenharmony_ci struct dd_draw_record *record = 1675bf215546Sopenharmony_ci dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL; 1676bf215546Sopenharmony_ci 1677bf215546Sopenharmony_ci if (record) { 1678bf215546Sopenharmony_ci record->call.type = CALL_TRANSFER_MAP; 1679bf215546Sopenharmony_ci 1680bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1681bf215546Sopenharmony_ci } 1682bf215546Sopenharmony_ci void *ptr = pipe->texture_map(pipe, resource, level, usage, box, transfer); 1683bf215546Sopenharmony_ci if (record) { 1684bf215546Sopenharmony_ci record->call.info.transfer_map.transfer_ptr = *transfer; 1685bf215546Sopenharmony_ci record->call.info.transfer_map.ptr = ptr; 1686bf215546Sopenharmony_ci if (*transfer) { 1687bf215546Sopenharmony_ci record->call.info.transfer_map.transfer = **transfer; 1688bf215546Sopenharmony_ci record->call.info.transfer_map.transfer.resource = NULL; 1689bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.transfer_map.transfer.resource, 1690bf215546Sopenharmony_ci (*transfer)->resource); 1691bf215546Sopenharmony_ci } else { 1692bf215546Sopenharmony_ci memset(&record->call.info.transfer_map.transfer, 0, sizeof(struct pipe_transfer)); 1693bf215546Sopenharmony_ci } 1694bf215546Sopenharmony_ci 1695bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1696bf215546Sopenharmony_ci } 1697bf215546Sopenharmony_ci return ptr; 1698bf215546Sopenharmony_ci} 1699bf215546Sopenharmony_ci 1700bf215546Sopenharmony_cistatic void 1701bf215546Sopenharmony_cidd_context_transfer_flush_region(struct pipe_context *_pipe, 1702bf215546Sopenharmony_ci struct pipe_transfer *transfer, 1703bf215546Sopenharmony_ci const struct pipe_box *box) 1704bf215546Sopenharmony_ci{ 1705bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1706bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1707bf215546Sopenharmony_ci struct dd_draw_record *record = 1708bf215546Sopenharmony_ci dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL; 1709bf215546Sopenharmony_ci 1710bf215546Sopenharmony_ci if (record) { 1711bf215546Sopenharmony_ci record->call.type = CALL_TRANSFER_FLUSH_REGION; 1712bf215546Sopenharmony_ci record->call.info.transfer_flush_region.transfer_ptr = transfer; 1713bf215546Sopenharmony_ci record->call.info.transfer_flush_region.box = *box; 1714bf215546Sopenharmony_ci record->call.info.transfer_flush_region.transfer = *transfer; 1715bf215546Sopenharmony_ci record->call.info.transfer_flush_region.transfer.resource = NULL; 1716bf215546Sopenharmony_ci pipe_resource_reference( 1717bf215546Sopenharmony_ci &record->call.info.transfer_flush_region.transfer.resource, 1718bf215546Sopenharmony_ci transfer->resource); 1719bf215546Sopenharmony_ci 1720bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1721bf215546Sopenharmony_ci } 1722bf215546Sopenharmony_ci pipe->transfer_flush_region(pipe, transfer, box); 1723bf215546Sopenharmony_ci if (record) 1724bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1725bf215546Sopenharmony_ci} 1726bf215546Sopenharmony_ci 1727bf215546Sopenharmony_cistatic void 1728bf215546Sopenharmony_cidd_context_buffer_unmap(struct pipe_context *_pipe, 1729bf215546Sopenharmony_ci struct pipe_transfer *transfer) 1730bf215546Sopenharmony_ci{ 1731bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1732bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1733bf215546Sopenharmony_ci struct dd_draw_record *record = 1734bf215546Sopenharmony_ci dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL; 1735bf215546Sopenharmony_ci 1736bf215546Sopenharmony_ci if (record) { 1737bf215546Sopenharmony_ci record->call.type = CALL_TRANSFER_UNMAP; 1738bf215546Sopenharmony_ci record->call.info.transfer_unmap.transfer_ptr = transfer; 1739bf215546Sopenharmony_ci record->call.info.transfer_unmap.transfer = *transfer; 1740bf215546Sopenharmony_ci record->call.info.transfer_unmap.transfer.resource = NULL; 1741bf215546Sopenharmony_ci pipe_resource_reference( 1742bf215546Sopenharmony_ci &record->call.info.transfer_unmap.transfer.resource, 1743bf215546Sopenharmony_ci transfer->resource); 1744bf215546Sopenharmony_ci 1745bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1746bf215546Sopenharmony_ci } 1747bf215546Sopenharmony_ci pipe->buffer_unmap(pipe, transfer); 1748bf215546Sopenharmony_ci if (record) 1749bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1750bf215546Sopenharmony_ci} 1751bf215546Sopenharmony_ci 1752bf215546Sopenharmony_cistatic void 1753bf215546Sopenharmony_cidd_context_texture_unmap(struct pipe_context *_pipe, 1754bf215546Sopenharmony_ci struct pipe_transfer *transfer) 1755bf215546Sopenharmony_ci{ 1756bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1757bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1758bf215546Sopenharmony_ci struct dd_draw_record *record = 1759bf215546Sopenharmony_ci dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL; 1760bf215546Sopenharmony_ci 1761bf215546Sopenharmony_ci if (record) { 1762bf215546Sopenharmony_ci record->call.type = CALL_TRANSFER_UNMAP; 1763bf215546Sopenharmony_ci record->call.info.transfer_unmap.transfer_ptr = transfer; 1764bf215546Sopenharmony_ci record->call.info.transfer_unmap.transfer = *transfer; 1765bf215546Sopenharmony_ci record->call.info.transfer_unmap.transfer.resource = NULL; 1766bf215546Sopenharmony_ci pipe_resource_reference( 1767bf215546Sopenharmony_ci &record->call.info.transfer_unmap.transfer.resource, 1768bf215546Sopenharmony_ci transfer->resource); 1769bf215546Sopenharmony_ci 1770bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1771bf215546Sopenharmony_ci } 1772bf215546Sopenharmony_ci pipe->texture_unmap(pipe, transfer); 1773bf215546Sopenharmony_ci if (record) 1774bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1775bf215546Sopenharmony_ci} 1776bf215546Sopenharmony_ci 1777bf215546Sopenharmony_cistatic void 1778bf215546Sopenharmony_cidd_context_buffer_subdata(struct pipe_context *_pipe, 1779bf215546Sopenharmony_ci struct pipe_resource *resource, 1780bf215546Sopenharmony_ci unsigned usage, unsigned offset, 1781bf215546Sopenharmony_ci unsigned size, const void *data) 1782bf215546Sopenharmony_ci{ 1783bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1784bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1785bf215546Sopenharmony_ci struct dd_draw_record *record = 1786bf215546Sopenharmony_ci dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL; 1787bf215546Sopenharmony_ci 1788bf215546Sopenharmony_ci if (record) { 1789bf215546Sopenharmony_ci record->call.type = CALL_BUFFER_SUBDATA; 1790bf215546Sopenharmony_ci record->call.info.buffer_subdata.resource = NULL; 1791bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.buffer_subdata.resource, resource); 1792bf215546Sopenharmony_ci record->call.info.buffer_subdata.usage = usage; 1793bf215546Sopenharmony_ci record->call.info.buffer_subdata.offset = offset; 1794bf215546Sopenharmony_ci record->call.info.buffer_subdata.size = size; 1795bf215546Sopenharmony_ci record->call.info.buffer_subdata.data = data; 1796bf215546Sopenharmony_ci 1797bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1798bf215546Sopenharmony_ci } 1799bf215546Sopenharmony_ci pipe->buffer_subdata(pipe, resource, usage, offset, size, data); 1800bf215546Sopenharmony_ci if (record) 1801bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1802bf215546Sopenharmony_ci} 1803bf215546Sopenharmony_ci 1804bf215546Sopenharmony_cistatic void 1805bf215546Sopenharmony_cidd_context_texture_subdata(struct pipe_context *_pipe, 1806bf215546Sopenharmony_ci struct pipe_resource *resource, 1807bf215546Sopenharmony_ci unsigned level, unsigned usage, 1808bf215546Sopenharmony_ci const struct pipe_box *box, 1809bf215546Sopenharmony_ci const void *data, unsigned stride, 1810bf215546Sopenharmony_ci unsigned layer_stride) 1811bf215546Sopenharmony_ci{ 1812bf215546Sopenharmony_ci struct dd_context *dctx = dd_context(_pipe); 1813bf215546Sopenharmony_ci struct pipe_context *pipe = dctx->pipe; 1814bf215546Sopenharmony_ci struct dd_draw_record *record = 1815bf215546Sopenharmony_ci dd_screen(dctx->base.screen)->transfers ? dd_create_record(dctx) : NULL; 1816bf215546Sopenharmony_ci 1817bf215546Sopenharmony_ci if (record) { 1818bf215546Sopenharmony_ci record->call.type = CALL_TEXTURE_SUBDATA; 1819bf215546Sopenharmony_ci record->call.info.texture_subdata.resource = NULL; 1820bf215546Sopenharmony_ci pipe_resource_reference(&record->call.info.texture_subdata.resource, resource); 1821bf215546Sopenharmony_ci record->call.info.texture_subdata.level = level; 1822bf215546Sopenharmony_ci record->call.info.texture_subdata.usage = usage; 1823bf215546Sopenharmony_ci record->call.info.texture_subdata.box = *box; 1824bf215546Sopenharmony_ci record->call.info.texture_subdata.data = data; 1825bf215546Sopenharmony_ci record->call.info.texture_subdata.stride = stride; 1826bf215546Sopenharmony_ci record->call.info.texture_subdata.layer_stride = layer_stride; 1827bf215546Sopenharmony_ci 1828bf215546Sopenharmony_ci dd_before_draw(dctx, record); 1829bf215546Sopenharmony_ci } 1830bf215546Sopenharmony_ci pipe->texture_subdata(pipe, resource, level, usage, box, data, 1831bf215546Sopenharmony_ci stride, layer_stride); 1832bf215546Sopenharmony_ci if (record) 1833bf215546Sopenharmony_ci dd_after_draw(dctx, record); 1834bf215546Sopenharmony_ci} 1835bf215546Sopenharmony_ci 1836bf215546Sopenharmony_civoid 1837bf215546Sopenharmony_cidd_init_draw_functions(struct dd_context *dctx) 1838bf215546Sopenharmony_ci{ 1839bf215546Sopenharmony_ci CTX_INIT(flush); 1840bf215546Sopenharmony_ci CTX_INIT(draw_vbo); 1841bf215546Sopenharmony_ci CTX_INIT(launch_grid); 1842bf215546Sopenharmony_ci CTX_INIT(resource_copy_region); 1843bf215546Sopenharmony_ci CTX_INIT(blit); 1844bf215546Sopenharmony_ci CTX_INIT(clear); 1845bf215546Sopenharmony_ci CTX_INIT(clear_render_target); 1846bf215546Sopenharmony_ci CTX_INIT(clear_depth_stencil); 1847bf215546Sopenharmony_ci CTX_INIT(clear_buffer); 1848bf215546Sopenharmony_ci CTX_INIT(clear_texture); 1849bf215546Sopenharmony_ci CTX_INIT(flush_resource); 1850bf215546Sopenharmony_ci CTX_INIT(generate_mipmap); 1851bf215546Sopenharmony_ci CTX_INIT(get_query_result_resource); 1852bf215546Sopenharmony_ci CTX_INIT(buffer_map); 1853bf215546Sopenharmony_ci CTX_INIT(texture_map); 1854bf215546Sopenharmony_ci CTX_INIT(transfer_flush_region); 1855bf215546Sopenharmony_ci CTX_INIT(buffer_unmap); 1856bf215546Sopenharmony_ci CTX_INIT(texture_unmap); 1857bf215546Sopenharmony_ci CTX_INIT(buffer_subdata); 1858bf215546Sopenharmony_ci CTX_INIT(texture_subdata); 1859bf215546Sopenharmony_ci CTX_INIT(draw_vertex_state); 1860bf215546Sopenharmony_ci} 1861