diff options
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/Makefile.sources | 4 | ||||
-rw-r--r-- | src/gallium/auxiliary/draw/draw_pipe_pstipple.c | 330 | ||||
-rw-r--r-- | src/gallium/auxiliary/nir/tgsi_to_nir.c | 12 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_scan.c | 757 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_transform.h | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_ureg.c | 6 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_debug.c | 468 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_debug.h | 39 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_debug_image.c | 348 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_debug_image.h | 74 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_debug_stack.c | 61 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_pstipple.c | 4 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_pstipple.h | 5 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_staging.c | 50 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_staging.h | 24 |
15 files changed, 1011 insertions, 1173 deletions
diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources index 6f50f714c3f..84da85c5b96 100644 --- a/src/gallium/auxiliary/Makefile.sources +++ b/src/gallium/auxiliary/Makefile.sources @@ -191,11 +191,13 @@ C_SOURCES := \ util/u_cpu_detect.c \ util/u_cpu_detect.h \ util/u_debug.c \ + util/u_debug.h \ util/u_debug_describe.c \ util/u_debug_describe.h \ util/u_debug_flush.c \ util/u_debug_flush.h \ - util/u_debug.h \ + util/u_debug_image.c \ + util/u_debug_image.h \ util/u_debug_memory.c \ util/u_debug_refcnt.c \ util/u_debug_refcnt.h \ diff --git a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c index cf52ca48b26..0298334a28f 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_pstipple.c +++ b/src/gallium/auxiliary/draw/draw_pipe_pstipple.c @@ -43,10 +43,10 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_pstipple.h" #include "util/u_sampler.h" #include "tgsi/tgsi_transform.h" -#include "tgsi/tgsi_dump.h" #include "draw_context.h" #include "draw_pipe.h" @@ -114,178 +114,6 @@ struct pstip_stage }; - -/** - * Subclass of tgsi_transform_context, used for transforming the - * user's fragment shader to add the extra texture sample and fragment kill - * instructions. - */ -struct pstip_transform_context { - struct tgsi_transform_context base; - uint tempsUsed; /**< bitmask */ - int wincoordInput; - int maxInput; - uint samplersUsed; /**< bitfield of samplers used */ - bool hasSview; - int freeSampler; /** an available sampler for the pstipple */ - int texTemp; /**< temp registers */ - int numImmed; -}; - - -/** - * TGSI declaration transform callback. - * Look for a free sampler, a free input attrib, and two free temp regs. - */ -static void -pstip_transform_decl(struct tgsi_transform_context *ctx, - struct tgsi_full_declaration *decl) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - - if (decl->Declaration.File == TGSI_FILE_SAMPLER) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->samplersUsed |= 1 << i; - } - } - else if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) { - pctx->hasSview = true; - } - else if (decl->Declaration.File == TGSI_FILE_INPUT) { - pctx->maxInput = MAX2(pctx->maxInput, (int) decl->Range.Last); - if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) - pctx->wincoordInput = (int) decl->Range.First; - } - else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) { - uint i; - for (i = decl->Range.First; - i <= decl->Range.Last; i++) { - pctx->tempsUsed |= (1 << i); - } - } - - ctx->emit_declaration(ctx, decl); -} - - -/** - * TGSI immediate declaration transform callback. - * We're just counting the number of immediates here. - */ -static void -pstip_transform_immed(struct tgsi_transform_context *ctx, - struct tgsi_full_immediate *immed) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - ctx->emit_immediate(ctx, immed); /* emit to output shader */ - pctx->numImmed++; -} - - -/** - * Find the lowest zero bit in the given word, or -1 if bitfield is all ones. - */ -static int -free_bit(uint bitfield) -{ - return ffs(~bitfield) - 1; -} - - -/** - * TGSI transform prolog callback. - */ -static void -pstip_transform_prolog(struct tgsi_transform_context *ctx) -{ - struct pstip_transform_context *pctx = (struct pstip_transform_context *) ctx; - uint i; - int wincoordInput; - - /* find free sampler */ - pctx->freeSampler = free_bit(pctx->samplersUsed); - if (pctx->freeSampler >= PIPE_MAX_SAMPLERS) - pctx->freeSampler = PIPE_MAX_SAMPLERS - 1; - - if (pctx->wincoordInput < 0) - wincoordInput = pctx->maxInput + 1; - else - wincoordInput = pctx->wincoordInput; - - /* find one free temp reg */ - for (i = 0; i < 32; i++) { - if ((pctx->tempsUsed & (1 << i)) == 0) { - /* found a free temp */ - if (pctx->texTemp < 0) - pctx->texTemp = i; - else - break; - } - } - assert(pctx->texTemp >= 0); - - if (pctx->wincoordInput < 0) { - /* declare new position input reg */ - tgsi_transform_input_decl(ctx, wincoordInput, - TGSI_SEMANTIC_POSITION, 1, - TGSI_INTERPOLATE_LINEAR); - } - - /* declare new sampler */ - tgsi_transform_sampler_decl(ctx, pctx->freeSampler); - - /* if the src shader has SVIEW decl's for each SAMP decl, we - * need to continue the trend and ensure there is a matching - * SVIEW for the new SAMP we just created - */ - if (pctx->hasSview) { - tgsi_transform_sampler_view_decl(ctx, - pctx->freeSampler, - TGSI_TEXTURE_2D, - TGSI_RETURN_TYPE_FLOAT); - } - - /* declare new temp regs */ - tgsi_transform_temp_decl(ctx, pctx->texTemp); - - /* emit immediate = {1/32, 1/32, 1, 1} - * The index/position of this immediate will be pctx->numImmed - */ - tgsi_transform_immediate_decl(ctx, 1.0/32.0, 1.0/32.0, 1.0, 1.0); - - /* - * Insert new MUL/TEX/KILL_IF instructions at start of program - * Take gl_FragCoord, divide by 32 (stipple size), sample the - * texture and kill fragment if needed. - * - * We'd like to use non-normalized texcoords to index into a RECT - * texture, but we can only use GL_REPEAT wrap mode with normalized - * texcoords. Darn. - */ - - /* MUL texTemp, INPUT[wincoord], 1/32; */ - tgsi_transform_op2_inst(ctx, TGSI_OPCODE_MUL, - TGSI_FILE_TEMPORARY, pctx->texTemp, - TGSI_WRITEMASK_XYZW, - TGSI_FILE_INPUT, wincoordInput, - TGSI_FILE_IMMEDIATE, pctx->numImmed); - - /* TEX texTemp, texTemp, sampler; */ - tgsi_transform_tex_2d_inst(ctx, - TGSI_FILE_TEMPORARY, pctx->texTemp, - TGSI_FILE_TEMPORARY, pctx->texTemp, - pctx->freeSampler); - - /* KILL_IF -texTemp.wwww; # if -texTemp < 0, KILL fragment */ - tgsi_transform_kill_inst(ctx, - TGSI_FILE_TEMPORARY, pctx->texTemp, - TGSI_SWIZZLE_W, TRUE); -} - - - /** * Generate the frag shader we'll use for doing polygon stipple. * This will be the user's shader prefixed with a TEX and KIL instruction. @@ -293,40 +121,27 @@ pstip_transform_prolog(struct tgsi_transform_context *ctx) static boolean generate_pstip_fs(struct pstip_stage *pstip) { + struct pipe_context *pipe = pstip->pipe; + struct pipe_screen *screen = pipe->screen; const struct pipe_shader_state *orig_fs = &pstip->fs->state; /*struct draw_context *draw = pstip->stage.draw;*/ struct pipe_shader_state pstip_fs; - struct pstip_transform_context transform; - const uint newLen = tgsi_num_tokens(orig_fs->tokens) + NUM_NEW_TOKENS; + enum tgsi_file_type wincoord_file; + + wincoord_file = screen->get_param(screen, PIPE_CAP_TGSI_FS_POSITION_IS_SYSVAL) ? + TGSI_FILE_SYSTEM_VALUE : TGSI_FILE_INPUT; pstip_fs = *orig_fs; /* copy to init */ - pstip_fs.tokens = tgsi_alloc_tokens(newLen); + pstip_fs.tokens = util_pstipple_create_fragment_shader(orig_fs->tokens, + &pstip->fs->sampler_unit, + 0, + wincoord_file); if (pstip_fs.tokens == NULL) return FALSE; - memset(&transform, 0, sizeof(transform)); - transform.wincoordInput = -1; - transform.maxInput = -1; - transform.texTemp = -1; - transform.base.prolog = pstip_transform_prolog; - transform.base.transform_declaration = pstip_transform_decl; - transform.base.transform_immediate = pstip_transform_immed; - - tgsi_transform_shader(orig_fs->tokens, - (struct tgsi_token *) pstip_fs.tokens, - newLen, &transform.base); - -#if 0 /* DEBUG */ - tgsi_dump(orig_fs->tokens, 0); - tgsi_dump(pstip_fs.tokens, 0); -#endif - - assert(pstip->fs); - - pstip->fs->sampler_unit = transform.freeSampler; assert(pstip->fs->sampler_unit < PIPE_MAX_SAMPLERS); - pstip->fs->pstip_fs = pstip->driver_create_fs_state(pstip->pipe, &pstip_fs); + pstip->fs->pstip_fs = pstip->driver_create_fs_state(pipe, &pstip_fs); FREE((void *)pstip_fs.tokens); @@ -338,113 +153,6 @@ generate_pstip_fs(struct pstip_stage *pstip) /** - * Load texture image with current stipple pattern. - */ -static void -pstip_update_texture(struct pstip_stage *pstip) -{ - static const uint bit31 = 1 << 31; - struct pipe_context *pipe = pstip->pipe; - struct pipe_transfer *transfer; - const uint *stipple = pstip->state.stipple->stipple; - uint i, j; - ubyte *data; - - data = pipe_transfer_map(pipe, pstip->texture, 0, 0, - PIPE_TRANSFER_WRITE, 0, 0, 32, 32, &transfer); - - /* - * Load alpha texture. - * Note: 0 means keep the fragment, 255 means kill it. - * We'll negate the texel value and use KILL_IF which kills if value - * is negative. - */ - for (i = 0; i < 32; i++) { - for (j = 0; j < 32; j++) { - if (stipple[i] & (bit31 >> j)) { - /* fragment "on" */ - data[i * transfer->stride + j] = 0; - } - else { - /* fragment "off" */ - data[i * transfer->stride + j] = 255; - } - } - } - - /* unmap */ - pipe_transfer_unmap(pipe, transfer); -} - - -/** - * Create the texture map we'll use for stippling. - */ -static boolean -pstip_create_texture(struct pstip_stage *pstip) -{ - struct pipe_context *pipe = pstip->pipe; - struct pipe_screen *screen = pipe->screen; - struct pipe_resource texTemp; - struct pipe_sampler_view viewTempl; - - memset(&texTemp, 0, sizeof(texTemp)); - texTemp.target = PIPE_TEXTURE_2D; - texTemp.format = PIPE_FORMAT_A8_UNORM; /* XXX verify supported by driver! */ - texTemp.last_level = 0; - texTemp.width0 = 32; - texTemp.height0 = 32; - texTemp.depth0 = 1; - texTemp.array_size = 1; - texTemp.bind = PIPE_BIND_SAMPLER_VIEW; - - pstip->texture = screen->resource_create(screen, &texTemp); - if (pstip->texture == NULL) - return FALSE; - - u_sampler_view_default_template(&viewTempl, - pstip->texture, - pstip->texture->format); - pstip->sampler_view = pipe->create_sampler_view(pipe, - pstip->texture, - &viewTempl); - if (!pstip->sampler_view) { - return FALSE; - } - - return TRUE; -} - - -/** - * Create the sampler CSO that'll be used for stippling. - */ -static boolean -pstip_create_sampler(struct pstip_stage *pstip) -{ - struct pipe_sampler_state sampler; - struct pipe_context *pipe = pstip->pipe; - - memset(&sampler, 0, sizeof(sampler)); - sampler.wrap_s = PIPE_TEX_WRAP_REPEAT; - sampler.wrap_t = PIPE_TEX_WRAP_REPEAT; - sampler.wrap_r = PIPE_TEX_WRAP_REPEAT; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; - sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; - sampler.normalized_coords = 1; - sampler.min_lod = 0.0f; - sampler.max_lod = 0.0f; - - pstip->sampler_cso = pipe->create_sampler_state(pipe, &sampler); - if (pstip->sampler_cso == NULL) - return FALSE; - - return TRUE; -} - - -/** * When we're about to draw our first stipple polygon in a batch, this function * is called to tell the driver to bind our modified fragment shader. */ @@ -722,7 +430,8 @@ pstip_set_polygon_stipple(struct pipe_context *pipe, /* pass-through */ pstip->driver_set_polygon_stipple(pstip->pipe, stipple); - pstip_update_texture(pstip); + util_pstipple_update_stipple_texture(pstip->pipe, pstip->texture, + pstip->state.stipple->stipple); } @@ -758,10 +467,17 @@ draw_install_pstipple_stage(struct draw_context *draw, pstip->driver_set_polygon_stipple = pipe->set_polygon_stipple; /* create special texture, sampler state */ - if (!pstip_create_texture(pstip)) + pstip->texture = util_pstipple_create_stipple_texture(pipe, NULL); + if (!pstip->texture) + goto fail; + + pstip->sampler_view = util_pstipple_create_sampler_view(pipe, + pstip->texture); + if (!pstip->sampler_view) goto fail; - if (!pstip_create_sampler(pstip)) + pstip->sampler_cso = util_pstipple_create_sampler(pipe); + if (!pstip->sampler_cso) goto fail; /* override the driver's functions */ diff --git a/src/gallium/auxiliary/nir/tgsi_to_nir.c b/src/gallium/auxiliary/nir/tgsi_to_nir.c index 3e7d69f73ed..61ff0a74379 100644 --- a/src/gallium/auxiliary/nir/tgsi_to_nir.c +++ b/src/gallium/auxiliary/nir/tgsi_to_nir.c @@ -614,8 +614,8 @@ ttn_src_for_file_and_index(struct ttn_compile *c, unsigned file, unsigned index, } nir_ssa_def *offset; - if (dim) { - /* UBO loads don't have a const_index[0] base offset. */ + if (op == nir_intrinsic_load_ubo) { + /* UBO loads don't have a base offset. */ offset = nir_imm_int(b, index); if (indirect) { offset = nir_iadd(b, offset, ttn_src_for_indirect(c, indirect)); @@ -623,7 +623,7 @@ ttn_src_for_file_and_index(struct ttn_compile *c, unsigned file, unsigned index, /* UBO offsets are in bytes, but TGSI gives them to us in vec4's */ offset = nir_ishl(b, offset, nir_imm_int(b, 4)); } else { - load->const_index[0] = index; + nir_intrinsic_set_base(load, index); if (indirect) { offset = ttn_src_for_indirect(c, indirect); } else { @@ -1875,7 +1875,7 @@ ttn_emit_instruction(struct ttn_compile *c) &tgsi_dst->Indirect : NULL; store->num_components = 4; - store->const_index[0] = dest.write_mask; + nir_intrinsic_set_write_mask(store, dest.write_mask); store->variables[0] = ttn_array_deref(c, store, var, offset, indirect); store->src[0] = nir_src_for_reg(dest.dest.reg.reg); @@ -1907,8 +1907,8 @@ ttn_add_output_stores(struct ttn_compile *c) store->num_components = 4; store->src[0].reg.reg = c->output_regs[loc].reg; store->src[0].reg.base_offset = c->output_regs[loc].offset; - store->const_index[0] = loc; - store->const_index[1] = 0xf; /* writemask */ + nir_intrinsic_set_base(store, loc); + nir_intrinsic_set_write_mask(store, 0xf); store->src[1] = nir_src_for_ssa(nir_imm_int(b, 0)); nir_builder_instr_insert(b, &store->instr); } diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.c b/src/gallium/auxiliary/tgsi/tgsi_scan.c index 687fb54830d..489423d7f12 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_scan.c +++ b/src/gallium/auxiliary/tgsi/tgsi_scan.c @@ -44,6 +44,387 @@ +static void +scan_instruction(struct tgsi_shader_info *info, + const struct tgsi_full_instruction *fullinst, + unsigned *current_depth) +{ + unsigned i; + + assert(fullinst->Instruction.Opcode < TGSI_OPCODE_LAST); + info->opcode_count[fullinst->Instruction.Opcode]++; + + switch (fullinst->Instruction.Opcode) { + case TGSI_OPCODE_IF: + case TGSI_OPCODE_UIF: + case TGSI_OPCODE_BGNLOOP: + (*current_depth)++; + info->max_depth = MAX2(info->max_depth, *current_depth); + break; + case TGSI_OPCODE_ENDIF: + case TGSI_OPCODE_ENDLOOP: + (*current_depth)--; + break; + default: + break; + } + + if (fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_CENTROID || + fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_OFFSET || + fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_SAMPLE) { + const struct tgsi_full_src_register *src0 = &fullinst->Src[0]; + unsigned input; + + if (src0->Register.Indirect && src0->Indirect.ArrayID) + input = info->input_array_first[src0->Indirect.ArrayID]; + else + input = src0->Register.Index; + + /* For the INTERP opcodes, the interpolation is always + * PERSPECTIVE unless LINEAR is specified. + */ + switch (info->input_interpolate[input]) { + case TGSI_INTERPOLATE_COLOR: + case TGSI_INTERPOLATE_CONSTANT: + case TGSI_INTERPOLATE_PERSPECTIVE: + switch (fullinst->Instruction.Opcode) { + case TGSI_OPCODE_INTERP_CENTROID: + info->uses_persp_opcode_interp_centroid = TRUE; + break; + case TGSI_OPCODE_INTERP_OFFSET: + info->uses_persp_opcode_interp_offset = TRUE; + break; + case TGSI_OPCODE_INTERP_SAMPLE: + info->uses_persp_opcode_interp_sample = TRUE; + break; + } + break; + + case TGSI_INTERPOLATE_LINEAR: + switch (fullinst->Instruction.Opcode) { + case TGSI_OPCODE_INTERP_CENTROID: + info->uses_linear_opcode_interp_centroid = TRUE; + break; + case TGSI_OPCODE_INTERP_OFFSET: + info->uses_linear_opcode_interp_offset = TRUE; + break; + case TGSI_OPCODE_INTERP_SAMPLE: + info->uses_linear_opcode_interp_sample = TRUE; + break; + } + break; + } + } + + if (fullinst->Instruction.Opcode >= TGSI_OPCODE_F2D && + fullinst->Instruction.Opcode <= TGSI_OPCODE_DSSG) + info->uses_doubles = TRUE; + + for (i = 0; i < fullinst->Instruction.NumSrcRegs; i++) { + const struct tgsi_full_src_register *src = &fullinst->Src[i]; + int ind = src->Register.Index; + + /* Mark which inputs are effectively used */ + if (src->Register.File == TGSI_FILE_INPUT) { + unsigned usage_mask; + usage_mask = tgsi_util_get_inst_usage_mask(fullinst, i); + if (src->Register.Indirect) { + for (ind = 0; ind < info->num_inputs; ++ind) { + info->input_usage_mask[ind] |= usage_mask; + } + } else { + assert(ind >= 0); + assert(ind < PIPE_MAX_SHADER_INPUTS); + info->input_usage_mask[ind] |= usage_mask; + } + + if (info->processor == TGSI_PROCESSOR_FRAGMENT && + !src->Register.Indirect) { + unsigned name = + info->input_semantic_name[src->Register.Index]; + unsigned index = + info->input_semantic_index[src->Register.Index]; + + if (name == TGSI_SEMANTIC_POSITION && + (src->Register.SwizzleX == TGSI_SWIZZLE_Z || + src->Register.SwizzleY == TGSI_SWIZZLE_Z || + src->Register.SwizzleZ == TGSI_SWIZZLE_Z || + src->Register.SwizzleW == TGSI_SWIZZLE_Z)) + info->reads_z = TRUE; + + if (name == TGSI_SEMANTIC_COLOR) { + unsigned mask = + (1 << src->Register.SwizzleX) | + (1 << src->Register.SwizzleY) | + (1 << src->Register.SwizzleZ) | + (1 << src->Register.SwizzleW); + + info->colors_read |= mask << (index * 4); + } + } + } + + /* check for indirect register reads */ + if (src->Register.Indirect) { + info->indirect_files |= (1 << src->Register.File); + info->indirect_files_read |= (1 << src->Register.File); + } + + /* MSAA samplers */ + if (src->Register.File == TGSI_FILE_SAMPLER) { + assert(fullinst->Instruction.Texture); + assert(src->Register.Index < Elements(info->is_msaa_sampler)); + + if (fullinst->Instruction.Texture && + (fullinst->Texture.Texture == TGSI_TEXTURE_2D_MSAA || + fullinst->Texture.Texture == TGSI_TEXTURE_2D_ARRAY_MSAA)) { + info->is_msaa_sampler[src->Register.Index] = TRUE; + } + } + } + + /* check for indirect register writes */ + for (i = 0; i < fullinst->Instruction.NumDstRegs; i++) { + const struct tgsi_full_dst_register *dst = &fullinst->Dst[i]; + if (dst->Register.Indirect) { + info->indirect_files |= (1 << dst->Register.File); + info->indirect_files_written |= (1 << dst->Register.File); + } + } + + info->num_instructions++; +} + + +static void +scan_declaration(struct tgsi_shader_info *info, + const struct tgsi_full_declaration *fulldecl) +{ + const uint file = fulldecl->Declaration.File; + const unsigned procType = info->processor; + uint reg; + + if (fulldecl->Declaration.Array) { + unsigned array_id = fulldecl->Array.ArrayID; + + switch (file) { + case TGSI_FILE_INPUT: + assert(array_id < ARRAY_SIZE(info->input_array_first)); + info->input_array_first[array_id] = fulldecl->Range.First; + info->input_array_last[array_id] = fulldecl->Range.Last; + break; + case TGSI_FILE_OUTPUT: + assert(array_id < ARRAY_SIZE(info->output_array_first)); + info->output_array_first[array_id] = fulldecl->Range.First; + info->output_array_last[array_id] = fulldecl->Range.Last; + break; + } + info->array_max[file] = MAX2(info->array_max[file], array_id); + } + + for (reg = fulldecl->Range.First; reg <= fulldecl->Range.Last; reg++) { + unsigned semName = fulldecl->Semantic.Name; + unsigned semIndex = fulldecl->Semantic.Index + + (reg - fulldecl->Range.First); + + /* only first 32 regs will appear in this bitfield */ + info->file_mask[file] |= (1 << reg); + info->file_count[file]++; + info->file_max[file] = MAX2(info->file_max[file], (int)reg); + + if (file == TGSI_FILE_CONSTANT) { + int buffer = 0; + + if (fulldecl->Declaration.Dimension) + buffer = fulldecl->Dim.Index2D; + + info->const_file_max[buffer] = + MAX2(info->const_file_max[buffer], (int)reg); + } + else if (file == TGSI_FILE_INPUT) { + info->input_semantic_name[reg] = (ubyte) semName; + info->input_semantic_index[reg] = (ubyte) semIndex; + info->input_interpolate[reg] = (ubyte)fulldecl->Interp.Interpolate; + info->input_interpolate_loc[reg] = (ubyte)fulldecl->Interp.Location; + info->input_cylindrical_wrap[reg] = (ubyte)fulldecl->Interp.CylindricalWrap; + info->num_inputs++; + + /* Only interpolated varyings. Don't include POSITION. + * Don't include integer varyings, because they are not + * interpolated. + */ + if (semName == TGSI_SEMANTIC_GENERIC || + semName == TGSI_SEMANTIC_TEXCOORD || + semName == TGSI_SEMANTIC_COLOR || + semName == TGSI_SEMANTIC_BCOLOR || + semName == TGSI_SEMANTIC_FOG || + semName == TGSI_SEMANTIC_CLIPDIST || + semName == TGSI_SEMANTIC_CULLDIST) { + switch (fulldecl->Interp.Interpolate) { + case TGSI_INTERPOLATE_COLOR: + case TGSI_INTERPOLATE_PERSPECTIVE: + switch (fulldecl->Interp.Location) { + case TGSI_INTERPOLATE_LOC_CENTER: + info->uses_persp_center = TRUE; + break; + case TGSI_INTERPOLATE_LOC_CENTROID: + info->uses_persp_centroid = TRUE; + break; + case TGSI_INTERPOLATE_LOC_SAMPLE: + info->uses_persp_sample = TRUE; + break; + } + break; + case TGSI_INTERPOLATE_LINEAR: + switch (fulldecl->Interp.Location) { + case TGSI_INTERPOLATE_LOC_CENTER: + info->uses_linear_center = TRUE; + break; + case TGSI_INTERPOLATE_LOC_CENTROID: + info->uses_linear_centroid = TRUE; + break; + case TGSI_INTERPOLATE_LOC_SAMPLE: + info->uses_linear_sample = TRUE; + break; + } + break; + /* TGSI_INTERPOLATE_CONSTANT doesn't do any interpolation. */ + } + } + + if (semName == TGSI_SEMANTIC_PRIMID) + info->uses_primid = TRUE; + else if (procType == TGSI_PROCESSOR_FRAGMENT) { + if (semName == TGSI_SEMANTIC_POSITION) + info->reads_position = TRUE; + else if (semName == TGSI_SEMANTIC_FACE) + info->uses_frontface = TRUE; + } + } + else if (file == TGSI_FILE_SYSTEM_VALUE) { + unsigned index = fulldecl->Range.First; + + info->system_value_semantic_name[index] = semName; + info->num_system_values = MAX2(info->num_system_values, index + 1); + + switch (semName) { + case TGSI_SEMANTIC_INSTANCEID: + info->uses_instanceid = TRUE; + break; + case TGSI_SEMANTIC_VERTEXID: + info->uses_vertexid = TRUE; + break; + case TGSI_SEMANTIC_VERTEXID_NOBASE: + info->uses_vertexid_nobase = TRUE; + break; + case TGSI_SEMANTIC_BASEVERTEX: + info->uses_basevertex = TRUE; + break; + case TGSI_SEMANTIC_PRIMID: + info->uses_primid = TRUE; + break; + case TGSI_SEMANTIC_INVOCATIONID: + info->uses_invocationid = TRUE; + break; + case TGSI_SEMANTIC_POSITION: + info->reads_position = TRUE; + break; + case TGSI_SEMANTIC_FACE: + info->uses_frontface = TRUE; + break; + case TGSI_SEMANTIC_SAMPLEMASK: + info->reads_samplemask = TRUE; + break; + } + } + else if (file == TGSI_FILE_OUTPUT) { + info->output_semantic_name[reg] = (ubyte) semName; + info->output_semantic_index[reg] = (ubyte) semIndex; + info->num_outputs++; + + if (semName == TGSI_SEMANTIC_COLOR) + info->colors_written |= 1 << semIndex; + + if (procType == TGSI_PROCESSOR_VERTEX || + procType == TGSI_PROCESSOR_GEOMETRY || + procType == TGSI_PROCESSOR_TESS_CTRL || + procType == TGSI_PROCESSOR_TESS_EVAL) { + switch (semName) { + case TGSI_SEMANTIC_VIEWPORT_INDEX: + info->writes_viewport_index = TRUE; + break; + case TGSI_SEMANTIC_LAYER: + info->writes_layer = TRUE; + break; + case TGSI_SEMANTIC_PSIZE: + info->writes_psize = TRUE; + break; + case TGSI_SEMANTIC_CLIPVERTEX: + info->writes_clipvertex = TRUE; + break; + } + } + + if (procType == TGSI_PROCESSOR_FRAGMENT) { + switch (semName) { + case TGSI_SEMANTIC_POSITION: + info->writes_z = TRUE; + break; + case TGSI_SEMANTIC_STENCIL: + info->writes_stencil = TRUE; + break; + case TGSI_SEMANTIC_SAMPLEMASK: + info->writes_samplemask = TRUE; + break; + } + } + + if (procType == TGSI_PROCESSOR_VERTEX) { + if (semName == TGSI_SEMANTIC_EDGEFLAG) { + info->writes_edgeflag = TRUE; + } + } + } else if (file == TGSI_FILE_SAMPLER) { + info->samplers_declared |= 1 << reg; + } + } +} + + +static void +scan_immediate(struct tgsi_shader_info *info) +{ + uint reg = info->immediate_count++; + uint file = TGSI_FILE_IMMEDIATE; + + info->file_mask[file] |= (1 << reg); + info->file_count[file]++; + info->file_max[file] = MAX2(info->file_max[file], (int)reg); +} + + +static void +scan_property(struct tgsi_shader_info *info, + const struct tgsi_full_property *fullprop) +{ + unsigned name = fullprop->Property.PropertyName; + unsigned value = fullprop->u[0].Data; + + assert(name < Elements(info->properties)); + info->properties[name] = value; + + switch (name) { + case TGSI_PROPERTY_NUM_CLIPDIST_ENABLED: + info->num_written_clipdistance = value; + info->clipdist_writemask |= (1 << value) - 1; + break; + case TGSI_PROPERTY_NUM_CULLDIST_ENABLED: + info->num_written_culldistance = value; + info->culldist_writemask |= (1 << value) - 1; + break; + } +} + /** * Scan the given TGSI shader to collect information such as number of @@ -81,390 +462,30 @@ tgsi_scan_shader(const struct tgsi_token *tokens, procType == TGSI_PROCESSOR_COMPUTE); info->processor = procType; - /** ** Loop over incoming program tokens/instructions */ - while( !tgsi_parse_end_of_tokens( &parse ) ) { - + while (!tgsi_parse_end_of_tokens(&parse)) { info->num_tokens++; tgsi_parse_token( &parse ); switch( parse.FullToken.Token.Type ) { case TGSI_TOKEN_TYPE_INSTRUCTION: - { - const struct tgsi_full_instruction *fullinst - = &parse.FullToken.FullInstruction; - uint i; - - assert(fullinst->Instruction.Opcode < TGSI_OPCODE_LAST); - info->opcode_count[fullinst->Instruction.Opcode]++; - - switch (fullinst->Instruction.Opcode) { - case TGSI_OPCODE_IF: - case TGSI_OPCODE_UIF: - case TGSI_OPCODE_BGNLOOP: - current_depth++; - info->max_depth = MAX2(info->max_depth, current_depth); - break; - case TGSI_OPCODE_ENDIF: - case TGSI_OPCODE_ENDLOOP: - current_depth--; - break; - default: - break; - } - - if (fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_CENTROID || - fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_OFFSET || - fullinst->Instruction.Opcode == TGSI_OPCODE_INTERP_SAMPLE) { - const struct tgsi_full_src_register *src0 = &fullinst->Src[0]; - unsigned input; - - if (src0->Register.Indirect && src0->Indirect.ArrayID) - input = info->input_array_first[src0->Indirect.ArrayID]; - else - input = src0->Register.Index; - - /* For the INTERP opcodes, the interpolation is always - * PERSPECTIVE unless LINEAR is specified. - */ - switch (info->input_interpolate[input]) { - case TGSI_INTERPOLATE_COLOR: - case TGSI_INTERPOLATE_CONSTANT: - case TGSI_INTERPOLATE_PERSPECTIVE: - switch (fullinst->Instruction.Opcode) { - case TGSI_OPCODE_INTERP_CENTROID: - info->uses_persp_opcode_interp_centroid = true; - break; - case TGSI_OPCODE_INTERP_OFFSET: - info->uses_persp_opcode_interp_offset = true; - break; - case TGSI_OPCODE_INTERP_SAMPLE: - info->uses_persp_opcode_interp_sample = true; - break; - } - break; - - case TGSI_INTERPOLATE_LINEAR: - switch (fullinst->Instruction.Opcode) { - case TGSI_OPCODE_INTERP_CENTROID: - info->uses_linear_opcode_interp_centroid = true; - break; - case TGSI_OPCODE_INTERP_OFFSET: - info->uses_linear_opcode_interp_offset = true; - break; - case TGSI_OPCODE_INTERP_SAMPLE: - info->uses_linear_opcode_interp_sample = true; - break; - } - break; - } - } - - if (fullinst->Instruction.Opcode >= TGSI_OPCODE_F2D && - fullinst->Instruction.Opcode <= TGSI_OPCODE_DSSG) - info->uses_doubles = true; - - for (i = 0; i < fullinst->Instruction.NumSrcRegs; i++) { - const struct tgsi_full_src_register *src = - &fullinst->Src[i]; - int ind = src->Register.Index; - - /* Mark which inputs are effectively used */ - if (src->Register.File == TGSI_FILE_INPUT) { - unsigned usage_mask; - usage_mask = tgsi_util_get_inst_usage_mask(fullinst, i); - if (src->Register.Indirect) { - for (ind = 0; ind < info->num_inputs; ++ind) { - info->input_usage_mask[ind] |= usage_mask; - } - } else { - assert(ind >= 0); - assert(ind < PIPE_MAX_SHADER_INPUTS); - info->input_usage_mask[ind] |= usage_mask; - } - - if (procType == TGSI_PROCESSOR_FRAGMENT && - !src->Register.Indirect) { - unsigned name = - info->input_semantic_name[src->Register.Index]; - unsigned index = - info->input_semantic_index[src->Register.Index]; - - if (name == TGSI_SEMANTIC_POSITION && - (src->Register.SwizzleX == TGSI_SWIZZLE_Z || - src->Register.SwizzleY == TGSI_SWIZZLE_Z || - src->Register.SwizzleZ == TGSI_SWIZZLE_Z || - src->Register.SwizzleW == TGSI_SWIZZLE_Z)) - info->reads_z = TRUE; - - if (name == TGSI_SEMANTIC_COLOR) { - unsigned mask = - (1 << src->Register.SwizzleX) | - (1 << src->Register.SwizzleY) | - (1 << src->Register.SwizzleZ) | - (1 << src->Register.SwizzleW); - - info->colors_read |= mask << (index * 4); - } - } - } - - /* check for indirect register reads */ - if (src->Register.Indirect) { - info->indirect_files |= (1 << src->Register.File); - info->indirect_files_read |= (1 << src->Register.File); - } - - /* MSAA samplers */ - if (src->Register.File == TGSI_FILE_SAMPLER) { - assert(fullinst->Instruction.Texture); - assert(src->Register.Index < Elements(info->is_msaa_sampler)); - - if (fullinst->Instruction.Texture && - (fullinst->Texture.Texture == TGSI_TEXTURE_2D_MSAA || - fullinst->Texture.Texture == TGSI_TEXTURE_2D_ARRAY_MSAA)) { - info->is_msaa_sampler[src->Register.Index] = TRUE; - } - } - } - - /* check for indirect register writes */ - for (i = 0; i < fullinst->Instruction.NumDstRegs; i++) { - const struct tgsi_full_dst_register *dst = &fullinst->Dst[i]; - if (dst->Register.Indirect) { - info->indirect_files |= (1 << dst->Register.File); - info->indirect_files_written |= (1 << dst->Register.File); - } - } - - info->num_instructions++; - } + scan_instruction(info, &parse.FullToken.FullInstruction, + ¤t_depth); break; - case TGSI_TOKEN_TYPE_DECLARATION: - { - const struct tgsi_full_declaration *fulldecl - = &parse.FullToken.FullDeclaration; - const uint file = fulldecl->Declaration.File; - uint reg; - - if (fulldecl->Declaration.Array) { - unsigned array_id = fulldecl->Array.ArrayID; - - switch (file) { - case TGSI_FILE_INPUT: - assert(array_id < ARRAY_SIZE(info->input_array_first)); - info->input_array_first[array_id] = fulldecl->Range.First; - info->input_array_last[array_id] = fulldecl->Range.Last; - break; - case TGSI_FILE_OUTPUT: - assert(array_id < ARRAY_SIZE(info->output_array_first)); - info->output_array_first[array_id] = fulldecl->Range.First; - info->output_array_last[array_id] = fulldecl->Range.Last; - break; - } - info->array_max[file] = MAX2(info->array_max[file], array_id); - } - - for (reg = fulldecl->Range.First; - reg <= fulldecl->Range.Last; - reg++) { - unsigned semName = fulldecl->Semantic.Name; - unsigned semIndex = - fulldecl->Semantic.Index + (reg - fulldecl->Range.First); - - /* only first 32 regs will appear in this bitfield */ - info->file_mask[file] |= (1 << reg); - info->file_count[file]++; - info->file_max[file] = MAX2(info->file_max[file], (int)reg); - - if (file == TGSI_FILE_CONSTANT) { - int buffer = 0; - - if (fulldecl->Declaration.Dimension) - buffer = fulldecl->Dim.Index2D; - - info->const_file_max[buffer] = - MAX2(info->const_file_max[buffer], (int)reg); - } - else if (file == TGSI_FILE_INPUT) { - info->input_semantic_name[reg] = (ubyte) semName; - info->input_semantic_index[reg] = (ubyte) semIndex; - info->input_interpolate[reg] = (ubyte)fulldecl->Interp.Interpolate; - info->input_interpolate_loc[reg] = (ubyte)fulldecl->Interp.Location; - info->input_cylindrical_wrap[reg] = (ubyte)fulldecl->Interp.CylindricalWrap; - info->num_inputs++; - - /* Only interpolated varyings. Don't include POSITION. - * Don't include integer varyings, because they are not - * interpolated. - */ - if (semName == TGSI_SEMANTIC_GENERIC || - semName == TGSI_SEMANTIC_TEXCOORD || - semName == TGSI_SEMANTIC_COLOR || - semName == TGSI_SEMANTIC_BCOLOR || - semName == TGSI_SEMANTIC_FOG || - semName == TGSI_SEMANTIC_CLIPDIST || - semName == TGSI_SEMANTIC_CULLDIST) { - switch (fulldecl->Interp.Interpolate) { - case TGSI_INTERPOLATE_COLOR: - case TGSI_INTERPOLATE_PERSPECTIVE: - switch (fulldecl->Interp.Location) { - case TGSI_INTERPOLATE_LOC_CENTER: - info->uses_persp_center = true; - break; - case TGSI_INTERPOLATE_LOC_CENTROID: - info->uses_persp_centroid = true; - break; - case TGSI_INTERPOLATE_LOC_SAMPLE: - info->uses_persp_sample = true; - break; - } - break; - case TGSI_INTERPOLATE_LINEAR: - switch (fulldecl->Interp.Location) { - case TGSI_INTERPOLATE_LOC_CENTER: - info->uses_linear_center = true; - break; - case TGSI_INTERPOLATE_LOC_CENTROID: - info->uses_linear_centroid = true; - break; - case TGSI_INTERPOLATE_LOC_SAMPLE: - info->uses_linear_sample = true; - break; - } - break; - /* TGSI_INTERPOLATE_CONSTANT doesn't do any interpolation. */ - } - } - - if (semName == TGSI_SEMANTIC_PRIMID) - info->uses_primid = TRUE; - else if (procType == TGSI_PROCESSOR_FRAGMENT) { - if (semName == TGSI_SEMANTIC_POSITION) - info->reads_position = TRUE; - else if (semName == TGSI_SEMANTIC_FACE) - info->uses_frontface = TRUE; - } - } - else if (file == TGSI_FILE_SYSTEM_VALUE) { - unsigned index = fulldecl->Range.First; - - info->system_value_semantic_name[index] = semName; - info->num_system_values = MAX2(info->num_system_values, - index + 1); - - if (semName == TGSI_SEMANTIC_INSTANCEID) { - info->uses_instanceid = TRUE; - } - else if (semName == TGSI_SEMANTIC_VERTEXID) { - info->uses_vertexid = TRUE; - } - else if (semName == TGSI_SEMANTIC_VERTEXID_NOBASE) { - info->uses_vertexid_nobase = TRUE; - } - else if (semName == TGSI_SEMANTIC_BASEVERTEX) { - info->uses_basevertex = TRUE; - } - else if (semName == TGSI_SEMANTIC_PRIMID) { - info->uses_primid = TRUE; - } else if (semName == TGSI_SEMANTIC_INVOCATIONID) { - info->uses_invocationid = TRUE; - } else if (semName == TGSI_SEMANTIC_POSITION) - info->reads_position = TRUE; - else if (semName == TGSI_SEMANTIC_FACE) - info->uses_frontface = TRUE; - else if (semName == TGSI_SEMANTIC_SAMPLEMASK) - info->reads_samplemask = TRUE; - } - else if (file == TGSI_FILE_OUTPUT) { - info->output_semantic_name[reg] = (ubyte) semName; - info->output_semantic_index[reg] = (ubyte) semIndex; - info->num_outputs++; - - if (semName == TGSI_SEMANTIC_COLOR) - info->colors_written |= 1 << semIndex; - - if (procType == TGSI_PROCESSOR_VERTEX || - procType == TGSI_PROCESSOR_GEOMETRY || - procType == TGSI_PROCESSOR_TESS_CTRL || - procType == TGSI_PROCESSOR_TESS_EVAL) { - if (semName == TGSI_SEMANTIC_VIEWPORT_INDEX) { - info->writes_viewport_index = TRUE; - } - else if (semName == TGSI_SEMANTIC_LAYER) { - info->writes_layer = TRUE; - } - else if (semName == TGSI_SEMANTIC_PSIZE) { - info->writes_psize = TRUE; - } - else if (semName == TGSI_SEMANTIC_CLIPVERTEX) { - info->writes_clipvertex = TRUE; - } - } - - if (procType == TGSI_PROCESSOR_FRAGMENT) { - if (semName == TGSI_SEMANTIC_POSITION) { - info->writes_z = TRUE; - } - else if (semName == TGSI_SEMANTIC_STENCIL) { - info->writes_stencil = TRUE; - } else if (semName == TGSI_SEMANTIC_SAMPLEMASK) { - info->writes_samplemask = TRUE; - } - } - - if (procType == TGSI_PROCESSOR_VERTEX) { - if (semName == TGSI_SEMANTIC_EDGEFLAG) { - info->writes_edgeflag = TRUE; - } - } - } else if (file == TGSI_FILE_SAMPLER) { - info->samplers_declared |= 1 << reg; - } - } - } + scan_declaration(info, &parse.FullToken.FullDeclaration); break; - case TGSI_TOKEN_TYPE_IMMEDIATE: - { - uint reg = info->immediate_count++; - uint file = TGSI_FILE_IMMEDIATE; - - info->file_mask[file] |= (1 << reg); - info->file_count[file]++; - info->file_max[file] = MAX2(info->file_max[file], (int)reg); - } + scan_immediate(info); break; - case TGSI_TOKEN_TYPE_PROPERTY: - { - const struct tgsi_full_property *fullprop - = &parse.FullToken.FullProperty; - unsigned name = fullprop->Property.PropertyName; - unsigned value = fullprop->u[0].Data; - - assert(name < Elements(info->properties)); - info->properties[name] = value; - - switch (name) { - case TGSI_PROPERTY_NUM_CLIPDIST_ENABLED: - info->num_written_clipdistance = value; - info->clipdist_writemask |= (1 << value) - 1; - break; - case TGSI_PROPERTY_NUM_CULLDIST_ENABLED: - info->num_written_culldistance = value; - info->culldist_writemask |= (1 << value) - 1; - break; - } - } + scan_property(info, &parse.FullToken.FullProperty); break; - default: - assert( 0 ); + assert(!"Unexpected TGSI token type"); } } @@ -487,7 +508,7 @@ tgsi_scan_shader(const struct tgsi_token *tokens, } } - tgsi_parse_free (&parse); + tgsi_parse_free(&parse); } diff --git a/src/gallium/auxiliary/tgsi/tgsi_transform.h b/src/gallium/auxiliary/tgsi/tgsi_transform.h index 3bd512b6f3e..27e6179c9ee 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_transform.h +++ b/src/gallium/auxiliary/tgsi/tgsi_transform.h @@ -192,7 +192,7 @@ tgsi_transform_sampler_view_decl(struct tgsi_transform_context *ctx, decl = tgsi_default_full_declaration(); decl.Declaration.File = TGSI_FILE_SAMPLER_VIEW; - decl.Declaration.UsageMask = 0xf; + decl.Declaration.UsageMask = TGSI_WRITEMASK_XYZW; decl.Range.First = decl.Range.Last = index; decl.SamplerView.Resource = target; diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c index d6811501d16..9654ac52bf2 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c @@ -1593,7 +1593,7 @@ emit_decl_sampler_view(struct ureg_program *ureg, out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 3; out[0].decl.File = TGSI_FILE_SAMPLER_VIEW; - out[0].decl.UsageMask = 0xf; + out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; out[1].value = 0; out[1].decl_range.First = index; @@ -1621,7 +1621,7 @@ emit_decl_image(struct ureg_program *ureg, out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 3; out[0].decl.File = TGSI_FILE_IMAGE; - out[0].decl.UsageMask = 0xf; + out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; out[1].value = 0; out[1].decl_range.First = index; @@ -1645,7 +1645,7 @@ emit_decl_buffer(struct ureg_program *ureg, out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION; out[0].decl.NrTokens = 2; out[0].decl.File = TGSI_FILE_BUFFER; - out[0].decl.UsageMask = 0xf; + out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW; out[0].decl.Atomic = atomic; out[1].value = 0; diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 2b605594a2e..db6635713e5 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -1,9 +1,9 @@ /************************************************************************** - * + * * Copyright 2008 VMware, Inc. * Copyright (c) 2008 VMware, Inc. * All Rights Reserved. - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -11,11 +11,11 @@ * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. @@ -23,24 +23,22 @@ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * + * **************************************************************************/ -#include "pipe/p_config.h" +#include "pipe/p_config.h" #include "pipe/p_compiler.h" -#include "util/u_debug.h" -#include "pipe/p_format.h" -#include "pipe/p_state.h" -#include "util/u_inlines.h" +#include "util/u_debug.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_inlines.h" #include "util/u_format.h" -#include "util/u_memory.h" -#include "util/u_string.h" -#include "util/u_math.h" -#include "util/u_tile.h" +#include "util/u_memory.h" +#include "util/u_string.h" +#include "util/u_math.h" #include "util/u_prim.h" -#include "util/u_surface.h" #include <inttypes.h> #include <stdio.h> @@ -53,14 +51,15 @@ #endif -void _debug_vprintf(const char *format, va_list ap) +void +_debug_vprintf(const char *format, va_list ap) { static char buf[4096] = {'\0'}; #if defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_EMBEDDED) /* We buffer until we find a newline. */ size_t len = strlen(buf); int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap); - if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) { + if (ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) { os_log_message(buf); buf[0] = '\0'; } @@ -70,12 +69,12 @@ void _debug_vprintf(const char *format, va_list ap) #endif } + void -_pipe_debug_message( - struct pipe_debug_callback *cb, - unsigned *id, - enum pipe_debug_type type, - const char *fmt, ...) +_pipe_debug_message(struct pipe_debug_callback *cb, + unsigned *id, + enum pipe_debug_type type, + const char *fmt, ...) { va_list args; va_start(args, fmt); @@ -112,9 +111,8 @@ debug_disable_error_message_boxes(void) #ifdef DEBUG -void debug_print_blob( const char *name, - const void *blob, - unsigned size ) +void +debug_print_blob(const char *name, const void *blob, unsigned size) { const unsigned *ublob = (const unsigned *)blob; unsigned i; @@ -147,6 +145,7 @@ debug_get_option_should_print(void) return value; } + const char * debug_get_option(const char *name, const char *dfault) { @@ -157,39 +156,42 @@ debug_get_option(const char *name, const char *dfault) result = dfault; if (debug_get_option_should_print()) - debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)"); - + debug_printf("%s: %s = %s\n", __FUNCTION__, name, + result ? result : "(null)"); + return result; } + boolean debug_get_bool_option(const char *name, boolean dfault) { const char *str = os_get_option(name); boolean result; - - if(str == NULL) + + if (str == NULL) result = dfault; - else if(!util_strcmp(str, "n")) + else if (!util_strcmp(str, "n")) result = FALSE; - else if(!util_strcmp(str, "no")) + else if (!util_strcmp(str, "no")) result = FALSE; - else if(!util_strcmp(str, "0")) + else if (!util_strcmp(str, "0")) result = FALSE; - else if(!util_strcmp(str, "f")) + else if (!util_strcmp(str, "f")) result = FALSE; - else if(!util_strcmp(str, "F")) + else if (!util_strcmp(str, "F")) result = FALSE; - else if(!util_strcmp(str, "false")) + else if (!util_strcmp(str, "false")) result = FALSE; - else if(!util_strcmp(str, "FALSE")) + else if (!util_strcmp(str, "FALSE")) result = FALSE; else result = TRUE; if (debug_get_option_should_print()) - debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE"); - + debug_printf("%s: %s = %s\n", __FUNCTION__, name, + result ? "TRUE" : "FALSE"); + return result; } @@ -199,23 +201,23 @@ debug_get_num_option(const char *name, long dfault) { long result; const char *str; - + str = os_get_option(name); - if(!str) + if (!str) result = dfault; else { long sign; char c; c = *str++; - if(c == '-') { + if (c == '-') { sign = -1; c = *str++; - } + } else { sign = 1; } result = 0; - while('0' <= c && c <= '9') { + while ('0' <= c && c <= '9') { result = result*10 + (c - '0'); c = *str++; } @@ -228,7 +230,9 @@ debug_get_num_option(const char *name, long dfault) return result; } -static boolean str_has_option(const char *str, const char *name) + +static boolean +str_has_option(const char *str, const char *name) { /* Empty string. */ if (!*str) { @@ -271,8 +275,9 @@ static boolean str_has_option(const char *str, const char *name) return FALSE; } + uint64_t -debug_get_flags_option(const char *name, +debug_get_flags_option(const char *name, const struct debug_named_value *flags, uint64_t dfault) { @@ -280,9 +285,9 @@ debug_get_flags_option(const char *name, const char *str; const struct debug_named_value *orig = flags; unsigned namealign = 0; - + str = os_get_option(name); - if(!str) + if (!str) result = dfault; else if (!util_strcmp(str, "help")) { result = dfault; @@ -296,7 +301,7 @@ debug_get_flags_option(const char *name, } else { result = 0; - while( flags->name ) { + while (flags->name) { if (str_has_option(str, flags->name)) result |= flags->value; ++flags; @@ -305,7 +310,8 @@ debug_get_flags_option(const char *name, if (debug_get_option_should_print()) { if (str) { - debug_printf("%s: %s = 0x%"PRIx64" (%s)\n", __FUNCTION__, name, result, str); + debug_printf("%s: %s = 0x%"PRIx64" (%s)\n", + __FUNCTION__, name, result, str); } else { debug_printf("%s: %s = 0x%"PRIx64"\n", __FUNCTION__, name, result); } @@ -315,24 +321,24 @@ debug_get_flags_option(const char *name, } -void _debug_assert_fail(const char *expr, - const char *file, - unsigned line, - const char *function) +void +_debug_assert_fail(const char *expr, const char *file, unsigned line, + const char *function) { - _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr); + _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", + file, line, function, expr); os_abort(); } const char * -debug_dump_enum(const struct debug_named_value *names, +debug_dump_enum(const struct debug_named_value *names, unsigned long value) { static char rest[64]; - - while(names->name) { - if(names->value == value) + + while (names->name) { + if (names->value == value) return names->name; ++names; } @@ -343,14 +349,14 @@ debug_dump_enum(const struct debug_named_value *names, const char * -debug_dump_enum_noprefix(const struct debug_named_value *names, +debug_dump_enum_noprefix(const struct debug_named_value *names, const char *prefix, unsigned long value) { static char rest[64]; - - while(names->name) { - if(names->value == value) { + + while (names->name) { + if (names->value == value) { const char *name = names->name; while (*name == *prefix) { name++; @@ -361,16 +367,13 @@ debug_dump_enum_noprefix(const struct debug_named_value *names, ++names; } - - util_snprintf(rest, sizeof(rest), "0x%08lx", value); return rest; } const char * -debug_dump_flags(const struct debug_named_value *names, - unsigned long value) +debug_dump_flags(const struct debug_named_value *names, unsigned long value) { static char output[4096]; static char rest[256]; @@ -378,8 +381,8 @@ debug_dump_flags(const struct debug_named_value *names, output[0] = '\0'; - while(names->name) { - if((names->value & value) == names->value) { + while (names->name) { + if ((names->value & value) == names->value) { if (!first) util_strncat(output, "|", sizeof(output) - strlen(output) - 1); else @@ -390,27 +393,28 @@ debug_dump_flags(const struct debug_named_value *names, } ++names; } - + if (value) { if (!first) util_strncat(output, "|", sizeof(output) - strlen(output) - 1); else first = 0; - + util_snprintf(rest, sizeof(rest), "0x%08lx", value); util_strncat(output, rest, sizeof(output) - strlen(output) - 1); output[sizeof(output) - 1] = '\0'; } - - if(first) + + if (first) return "0"; - + return output; } #ifdef DEBUG -void debug_print_format(const char *msg, unsigned fmt ) +void +debug_print_format(const char *msg, unsigned fmt ) { debug_printf("%s: %s\n", msg, util_format_name(fmt)); } @@ -447,7 +451,8 @@ u_prim_name(unsigned prim) int fl_indent = 0; const char* fl_function[1024]; -int debug_funclog_enter(const char* f, const int line, const char* file) +int +debug_funclog_enter(const char* f, const int line, const char* file) { int i; @@ -461,14 +466,16 @@ int debug_funclog_enter(const char* f, const int line, const char* file) return 0; } -void debug_funclog_exit(const char* f, const int line, const char* file) +void +debug_funclog_exit(const char* f, const int line, const char* file) { --fl_indent; assert(fl_indent >= 0); assert(fl_function[fl_indent] == f); } -void debug_funclog_enter_exit(const char* f, const int line, const char* file) +void +debug_funclog_enter_exit(const char* f, const int line, const char* file) { int i; for (i = 0; i < fl_indent; i++) @@ -481,313 +488,6 @@ void debug_funclog_enter_exit(const char* f, const int line, const char* file) #ifdef DEBUG /** - * Dump an image to .ppm file. - * \param format PIPE_FORMAT_x - * \param cpp bytes per pixel - * \param width width in pixels - * \param height height in pixels - * \param stride row stride in bytes - */ -void debug_dump_image(const char *prefix, - enum pipe_format format, unsigned cpp, - unsigned width, unsigned height, - unsigned stride, - const void *data) -{ - /* write a ppm file */ - char filename[256]; - unsigned char *rgb8; - FILE *f; - - util_snprintf(filename, sizeof(filename), "%s.ppm", prefix); - - rgb8 = MALLOC(height * width * 3); - if (!rgb8) { - return; - } - - util_format_translate( - PIPE_FORMAT_R8G8B8_UNORM, - rgb8, width * 3, - 0, 0, - format, - data, stride, - 0, 0, width, height); - - /* Must be opened in binary mode or DOS line ending causes data - * to be read with one byte offset. - */ - f = fopen(filename, "wb"); - if (f) { - fprintf(f, "P6\n"); - fprintf(f, "# ppm-file created by gallium\n"); - fprintf(f, "%i %i\n", width, height); - fprintf(f, "255\n"); - fwrite(rgb8, 1, height * width * 3, f); - fclose(f); - } - else { - fprintf(stderr, "Can't open %s for writing\n", filename); - } - - FREE(rgb8); -} - -/* FIXME: dump resources, not surfaces... */ -void debug_dump_surface(struct pipe_context *pipe, - const char *prefix, - struct pipe_surface *surface) -{ - struct pipe_resource *texture; - struct pipe_transfer *transfer; - void *data; - - if (!surface) - return; - - /* XXX: this doesn't necessarily work, as the driver may be using - * temporary storage for the surface which hasn't been propagated - * back into the texture. Need to nail down the semantics of views - * and transfers a bit better before we can say if extra work needs - * to be done here: - */ - texture = surface->texture; - - data = pipe_transfer_map(pipe, texture, surface->u.tex.level, - surface->u.tex.first_layer, - PIPE_TRANSFER_READ, - 0, 0, surface->width, surface->height, &transfer); - if (!data) - return; - - debug_dump_image(prefix, - texture->format, - util_format_get_blocksize(texture->format), - util_format_get_nblocksx(texture->format, surface->width), - util_format_get_nblocksy(texture->format, surface->height), - transfer->stride, - data); - - pipe->transfer_unmap(pipe, transfer); -} - - -void debug_dump_texture(struct pipe_context *pipe, - const char *prefix, - struct pipe_resource *texture) -{ - struct pipe_surface *surface, surf_tmpl; - - if (!texture) - return; - - /* XXX for now, just dump image for layer=0, level=0 */ - u_surface_default_template(&surf_tmpl, texture); - surface = pipe->create_surface(pipe, texture, &surf_tmpl); - if (surface) { - debug_dump_surface(pipe, prefix, surface); - pipe->surface_destroy(pipe, surface); - } -} - - -#pragma pack(push,2) -struct bmp_file_header { - uint16_t bfType; - uint32_t bfSize; - uint16_t bfReserved1; - uint16_t bfReserved2; - uint32_t bfOffBits; -}; -#pragma pack(pop) - -struct bmp_info_header { - uint32_t biSize; - int32_t biWidth; - int32_t biHeight; - uint16_t biPlanes; - uint16_t biBitCount; - uint32_t biCompression; - uint32_t biSizeImage; - int32_t biXPelsPerMeter; - int32_t biYPelsPerMeter; - uint32_t biClrUsed; - uint32_t biClrImportant; -}; - -struct bmp_rgb_quad { - uint8_t rgbBlue; - uint8_t rgbGreen; - uint8_t rgbRed; - uint8_t rgbAlpha; -}; - -void -debug_dump_surface_bmp(struct pipe_context *pipe, - const char *filename, - struct pipe_surface *surface) -{ - struct pipe_transfer *transfer; - struct pipe_resource *texture = surface->texture; - void *ptr; - - ptr = pipe_transfer_map(pipe, texture, surface->u.tex.level, - surface->u.tex.first_layer, PIPE_TRANSFER_READ, - 0, 0, surface->width, surface->height, &transfer); - - debug_dump_transfer_bmp(pipe, filename, transfer, ptr); - - pipe->transfer_unmap(pipe, transfer); -} - -void -debug_dump_transfer_bmp(struct pipe_context *pipe, - const char *filename, - struct pipe_transfer *transfer, void *ptr) -{ - float *rgba; - - if (!transfer) - goto error1; - - rgba = MALLOC(transfer->box.width * - transfer->box.height * - transfer->box.depth * - 4*sizeof(float)); - if (!rgba) - goto error1; - - pipe_get_tile_rgba(transfer, ptr, 0, 0, - transfer->box.width, transfer->box.height, - rgba); - - debug_dump_float_rgba_bmp(filename, - transfer->box.width, transfer->box.height, - rgba, transfer->box.width); - - FREE(rgba); -error1: - ; -} - -void -debug_dump_float_rgba_bmp(const char *filename, - unsigned width, unsigned height, - float *rgba, unsigned stride) -{ - FILE *stream; - struct bmp_file_header bmfh; - struct bmp_info_header bmih; - unsigned x, y; - - if (!rgba) - goto error1; - - bmfh.bfType = 0x4d42; - bmfh.bfSize = 14 + 40 + height*width*4; - bmfh.bfReserved1 = 0; - bmfh.bfReserved2 = 0; - bmfh.bfOffBits = 14 + 40; - - bmih.biSize = 40; - bmih.biWidth = width; - bmih.biHeight = height; - bmih.biPlanes = 1; - bmih.biBitCount = 32; - bmih.biCompression = 0; - bmih.biSizeImage = height*width*4; - bmih.biXPelsPerMeter = 0; - bmih.biYPelsPerMeter = 0; - bmih.biClrUsed = 0; - bmih.biClrImportant = 0; - - stream = fopen(filename, "wb"); - if (!stream) - goto error1; - - fwrite(&bmfh, 14, 1, stream); - fwrite(&bmih, 40, 1, stream); - - y = height; - while(y--) { - float *ptr = rgba + (stride * y * 4); - for(x = 0; x < width; ++x) - { - struct bmp_rgb_quad pixel; - pixel.rgbRed = float_to_ubyte(ptr[x*4 + 0]); - pixel.rgbGreen = float_to_ubyte(ptr[x*4 + 1]); - pixel.rgbBlue = float_to_ubyte(ptr[x*4 + 2]); - pixel.rgbAlpha = float_to_ubyte(ptr[x*4 + 3]); - fwrite(&pixel, 1, 4, stream); - } - } - - fclose(stream); -error1: - ; -} - -void -debug_dump_ubyte_rgba_bmp(const char *filename, - unsigned width, unsigned height, - const ubyte *rgba, unsigned stride) -{ - FILE *stream; - struct bmp_file_header bmfh; - struct bmp_info_header bmih; - unsigned x, y; - - assert(rgba); - if(!rgba) - goto error1; - - bmfh.bfType = 0x4d42; - bmfh.bfSize = 14 + 40 + height*width*4; - bmfh.bfReserved1 = 0; - bmfh.bfReserved2 = 0; - bmfh.bfOffBits = 14 + 40; - - bmih.biSize = 40; - bmih.biWidth = width; - bmih.biHeight = height; - bmih.biPlanes = 1; - bmih.biBitCount = 32; - bmih.biCompression = 0; - bmih.biSizeImage = height*width*4; - bmih.biXPelsPerMeter = 0; - bmih.biYPelsPerMeter = 0; - bmih.biClrUsed = 0; - bmih.biClrImportant = 0; - - stream = fopen(filename, "wb"); - assert(stream); - if(!stream) - goto error1; - - fwrite(&bmfh, 14, 1, stream); - fwrite(&bmih, 40, 1, stream); - - y = height; - while(y--) { - const ubyte *ptr = rgba + (stride * y * 4); - for(x = 0; x < width; ++x) - { - struct bmp_rgb_quad pixel; - pixel.rgbRed = ptr[x*4 + 0]; - pixel.rgbGreen = ptr[x*4 + 1]; - pixel.rgbBlue = ptr[x*4 + 2]; - pixel.rgbAlpha = ptr[x*4 + 3]; - fwrite(&pixel, 1, 4, stream); - } - } - - fclose(stream); -error1: - ; -} - - -/** * Print PIPE_TRANSFER_x flags with a message. */ void diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h index 671bd37a085..c2707b402cb 100644 --- a/src/gallium/auxiliary/util/u_debug.h +++ b/src/gallium/auxiliary/util/u_debug.h @@ -464,45 +464,6 @@ void debug_memory_end(unsigned long beginning); -#ifdef DEBUG -struct pipe_context; -struct pipe_surface; -struct pipe_transfer; -struct pipe_resource; - -void debug_dump_image(const char *prefix, - enum pipe_format format, unsigned cpp, - unsigned width, unsigned height, - unsigned stride, - const void *data); -void debug_dump_surface(struct pipe_context *pipe, - const char *prefix, - struct pipe_surface *surface); -void debug_dump_texture(struct pipe_context *pipe, - const char *prefix, - struct pipe_resource *texture); -void debug_dump_surface_bmp(struct pipe_context *pipe, - const char *filename, - struct pipe_surface *surface); -void debug_dump_transfer_bmp(struct pipe_context *pipe, - const char *filename, - struct pipe_transfer *transfer, void *ptr); -void debug_dump_float_rgba_bmp(const char *filename, - unsigned width, unsigned height, - float *rgba, unsigned stride); -void debug_dump_ubyte_rgba_bmp(const char *filename, - unsigned width, unsigned height, - const ubyte *rgba, unsigned stride); -#else -#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0) -#define debug_dump_surface(pipe, prefix, surface) ((void)0) -#define debug_dump_surface_bmp(pipe, filename, surface) ((void)0) -#define debug_dump_transfer_bmp(filename, transfer, ptr) ((void)0) -#define debug_dump_float_rgba_bmp(filename, width, height, rgba, stride) ((void)0) -#define debug_dump_ubyte_rgba_bmp(filename, width, height, rgba, stride) ((void)0) -#endif - - void debug_print_transfer_flags(const char *msg, unsigned usage); diff --git a/src/gallium/auxiliary/util/u_debug_image.c b/src/gallium/auxiliary/util/u_debug_image.c new file mode 100644 index 00000000000..98d73a63de2 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_image.c @@ -0,0 +1,348 @@ +/* + * Copyright (c) 2008-2016 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include "util/u_debug_image.h" +#include "util/u_format.h" +#include "util/u_inlines.h" +#include "util/u_memory.h" +#include "util/u_string.h" +#include "util/u_surface.h" +#include "util/u_tile.h" + +#include <stdio.h> + + +#ifdef DEBUG + +/** + * Dump an image to .ppm file. + * \param format PIPE_FORMAT_x + * \param cpp bytes per pixel + * \param width width in pixels + * \param height height in pixels + * \param stride row stride in bytes + */ +void +debug_dump_image(const char *prefix, + enum pipe_format format, unsigned cpp, + unsigned width, unsigned height, + unsigned stride, + const void *data) +{ + /* write a ppm file */ + char filename[256]; + unsigned char *rgb8; + FILE *f; + + util_snprintf(filename, sizeof(filename), "%s.ppm", prefix); + + rgb8 = MALLOC(height * width * 3); + if (!rgb8) { + return; + } + + util_format_translate( + PIPE_FORMAT_R8G8B8_UNORM, + rgb8, width * 3, + 0, 0, + format, + data, stride, + 0, 0, width, height); + + /* Must be opened in binary mode or DOS line ending causes data + * to be read with one byte offset. + */ + f = fopen(filename, "wb"); + if (f) { + fprintf(f, "P6\n"); + fprintf(f, "# ppm-file created by gallium\n"); + fprintf(f, "%i %i\n", width, height); + fprintf(f, "255\n"); + fwrite(rgb8, 1, height * width * 3, f); + fclose(f); + } + else { + fprintf(stderr, "Can't open %s for writing\n", filename); + } + + FREE(rgb8); +} + + +/* FIXME: dump resources, not surfaces... */ +void +debug_dump_surface(struct pipe_context *pipe, + const char *prefix, + struct pipe_surface *surface) +{ + struct pipe_resource *texture; + struct pipe_transfer *transfer; + void *data; + + if (!surface) + return; + + /* XXX: this doesn't necessarily work, as the driver may be using + * temporary storage for the surface which hasn't been propagated + * back into the texture. Need to nail down the semantics of views + * and transfers a bit better before we can say if extra work needs + * to be done here: + */ + texture = surface->texture; + + data = pipe_transfer_map(pipe, texture, surface->u.tex.level, + surface->u.tex.first_layer, + PIPE_TRANSFER_READ, + 0, 0, surface->width, surface->height, &transfer); + if (!data) + return; + + debug_dump_image(prefix, + texture->format, + util_format_get_blocksize(texture->format), + util_format_get_nblocksx(texture->format, surface->width), + util_format_get_nblocksy(texture->format, surface->height), + transfer->stride, + data); + + pipe->transfer_unmap(pipe, transfer); +} + + +void +debug_dump_texture(struct pipe_context *pipe, + const char *prefix, + struct pipe_resource *texture) +{ + struct pipe_surface *surface, surf_tmpl; + + if (!texture) + return; + + /* XXX for now, just dump image for layer=0, level=0 */ + u_surface_default_template(&surf_tmpl, texture); + surface = pipe->create_surface(pipe, texture, &surf_tmpl); + if (surface) { + debug_dump_surface(pipe, prefix, surface); + pipe->surface_destroy(pipe, surface); + } +} + + +#pragma pack(push,2) +struct bmp_file_header { + uint16_t bfType; + uint32_t bfSize; + uint16_t bfReserved1; + uint16_t bfReserved2; + uint32_t bfOffBits; +}; +#pragma pack(pop) + +struct bmp_info_header { + uint32_t biSize; + int32_t biWidth; + int32_t biHeight; + uint16_t biPlanes; + uint16_t biBitCount; + uint32_t biCompression; + uint32_t biSizeImage; + int32_t biXPelsPerMeter; + int32_t biYPelsPerMeter; + uint32_t biClrUsed; + uint32_t biClrImportant; +}; + +struct bmp_rgb_quad { + uint8_t rgbBlue; + uint8_t rgbGreen; + uint8_t rgbRed; + uint8_t rgbAlpha; +}; + +void +debug_dump_surface_bmp(struct pipe_context *pipe, + const char *filename, + struct pipe_surface *surface) +{ + struct pipe_transfer *transfer; + struct pipe_resource *texture = surface->texture; + void *ptr; + + ptr = pipe_transfer_map(pipe, texture, surface->u.tex.level, + surface->u.tex.first_layer, PIPE_TRANSFER_READ, + 0, 0, surface->width, surface->height, &transfer); + + debug_dump_transfer_bmp(pipe, filename, transfer, ptr); + + pipe->transfer_unmap(pipe, transfer); +} + +void +debug_dump_transfer_bmp(struct pipe_context *pipe, + const char *filename, + struct pipe_transfer *transfer, void *ptr) +{ + float *rgba; + + if (!transfer) + goto error1; + + rgba = MALLOC(transfer->box.width * + transfer->box.height * + transfer->box.depth * + 4*sizeof(float)); + if (!rgba) + goto error1; + + pipe_get_tile_rgba(transfer, ptr, 0, 0, + transfer->box.width, transfer->box.height, + rgba); + + debug_dump_float_rgba_bmp(filename, + transfer->box.width, transfer->box.height, + rgba, transfer->box.width); + + FREE(rgba); +error1: + ; +} + +void +debug_dump_float_rgba_bmp(const char *filename, + unsigned width, unsigned height, + float *rgba, unsigned stride) +{ + FILE *stream; + struct bmp_file_header bmfh; + struct bmp_info_header bmih; + unsigned x, y; + + if (!rgba) + goto error1; + + bmfh.bfType = 0x4d42; + bmfh.bfSize = 14 + 40 + height*width*4; + bmfh.bfReserved1 = 0; + bmfh.bfReserved2 = 0; + bmfh.bfOffBits = 14 + 40; + + bmih.biSize = 40; + bmih.biWidth = width; + bmih.biHeight = height; + bmih.biPlanes = 1; + bmih.biBitCount = 32; + bmih.biCompression = 0; + bmih.biSizeImage = height*width*4; + bmih.biXPelsPerMeter = 0; + bmih.biYPelsPerMeter = 0; + bmih.biClrUsed = 0; + bmih.biClrImportant = 0; + + stream = fopen(filename, "wb"); + if (!stream) + goto error1; + + fwrite(&bmfh, 14, 1, stream); + fwrite(&bmih, 40, 1, stream); + + y = height; + while (y--) { + float *ptr = rgba + (stride * y * 4); + for (x = 0; x < width; ++x) { + struct bmp_rgb_quad pixel; + pixel.rgbRed = float_to_ubyte(ptr[x*4 + 0]); + pixel.rgbGreen = float_to_ubyte(ptr[x*4 + 1]); + pixel.rgbBlue = float_to_ubyte(ptr[x*4 + 2]); + pixel.rgbAlpha = float_to_ubyte(ptr[x*4 + 3]); + fwrite(&pixel, 1, 4, stream); + } + } + + fclose(stream); +error1: + ; +} + +void +debug_dump_ubyte_rgba_bmp(const char *filename, + unsigned width, unsigned height, + const ubyte *rgba, unsigned stride) +{ + FILE *stream; + struct bmp_file_header bmfh; + struct bmp_info_header bmih; + unsigned x, y; + + assert(rgba); + if (!rgba) + goto error1; + + bmfh.bfType = 0x4d42; + bmfh.bfSize = 14 + 40 + height*width*4; + bmfh.bfReserved1 = 0; + bmfh.bfReserved2 = 0; + bmfh.bfOffBits = 14 + 40; + + bmih.biSize = 40; + bmih.biWidth = width; + bmih.biHeight = height; + bmih.biPlanes = 1; + bmih.biBitCount = 32; + bmih.biCompression = 0; + bmih.biSizeImage = height*width*4; + bmih.biXPelsPerMeter = 0; + bmih.biYPelsPerMeter = 0; + bmih.biClrUsed = 0; + bmih.biClrImportant = 0; + + stream = fopen(filename, "wb"); + assert(stream); + if (!stream) + goto error1; + + fwrite(&bmfh, 14, 1, stream); + fwrite(&bmih, 40, 1, stream); + + y = height; + while (y--) { + const ubyte *ptr = rgba + (stride * y * 4); + for (x = 0; x < width; ++x) { + struct bmp_rgb_quad pixel; + pixel.rgbRed = ptr[x*4 + 0]; + pixel.rgbGreen = ptr[x*4 + 1]; + pixel.rgbBlue = ptr[x*4 + 2]; + pixel.rgbAlpha = ptr[x*4 + 3]; + fwrite(&pixel, 1, 4, stream); + } + } + + fclose(stream); +error1: + ; +} + +#endif diff --git a/src/gallium/auxiliary/util/u_debug_image.h b/src/gallium/auxiliary/util/u_debug_image.h new file mode 100644 index 00000000000..f190eec5f52 --- /dev/null +++ b/src/gallium/auxiliary/util/u_debug_image.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008-2016 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#ifndef U_DEBUG_IMAGE_H +#define U_DEBUG_IMAGE_H + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + + +#ifdef DEBUG +struct pipe_context; +struct pipe_surface; +struct pipe_transfer; +struct pipe_resource; + +void debug_dump_image(const char *prefix, + enum pipe_format format, unsigned cpp, + unsigned width, unsigned height, + unsigned stride, + const void *data); +void debug_dump_surface(struct pipe_context *pipe, + const char *prefix, + struct pipe_surface *surface); +void debug_dump_texture(struct pipe_context *pipe, + const char *prefix, + struct pipe_resource *texture); +void debug_dump_surface_bmp(struct pipe_context *pipe, + const char *filename, + struct pipe_surface *surface); +void debug_dump_transfer_bmp(struct pipe_context *pipe, + const char *filename, + struct pipe_transfer *transfer, void *ptr); +void debug_dump_float_rgba_bmp(const char *filename, + unsigned width, unsigned height, + float *rgba, unsigned stride); +void debug_dump_ubyte_rgba_bmp(const char *filename, + unsigned width, unsigned height, + const ubyte *rgba, unsigned stride); +#else +#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0) +#define debug_dump_surface(pipe, prefix, surface) ((void)0) +#define debug_dump_surface_bmp(pipe, filename, surface) ((void)0) +#define debug_dump_transfer_bmp(filename, transfer, ptr) ((void)0) +#define debug_dump_float_rgba_bmp(filename, width, height, rgba, stride) ((void)0) +#define debug_dump_ubyte_rgba_bmp(filename, width, height, rgba, stride) ((void)0) +#endif + + +#endif diff --git a/src/gallium/auxiliary/util/u_debug_stack.c b/src/gallium/auxiliary/util/u_debug_stack.c index 68961d3510e..1faa1903a76 100644 --- a/src/gallium/auxiliary/util/u_debug_stack.c +++ b/src/gallium/auxiliary/util/u_debug_stack.c @@ -2,7 +2,7 @@ * * Copyright 2009 VMware, Inc. * All Rights Reserved. - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -10,11 +10,11 @@ * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. @@ -22,13 +22,13 @@ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * + * **************************************************************************/ /** * @file * Stack backtracing. - * + * * @author Jose Fonseca <[email protected]> */ @@ -44,12 +44,13 @@ /** * Capture stack backtrace. * - * NOTE: The implementation of this function is quite big, but it is important not to - * break it down in smaller functions to avoid adding new frames to the calling stack. + * NOTE: The implementation of this function is quite big, but it is important + * not to break it down in smaller functions to avoid adding new frames to the + * calling stack. */ void debug_backtrace_capture(struct debug_stack_frame *backtrace, - unsigned start_frame, + unsigned start_frame, unsigned nr_frames) { const void **frame_pointer = NULL; @@ -66,7 +67,8 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace, */ #if defined(PIPE_OS_WINDOWS) { - typedef USHORT (WINAPI *PFNCAPTURESTACKBACKTRACE)(ULONG, ULONG, PVOID *, PULONG); + typedef USHORT (WINAPI *PFNCAPTURESTACKBACKTRACE)(ULONG, ULONG, + PVOID *, PULONG); static PFNCAPTURESTACKBACKTRACE pfnCaptureStackBackTrace = NULL; if (!pfnCaptureStackBackTrace) { @@ -76,8 +78,9 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace, assert(hModule); } if (hModule) { - pfnCaptureStackBackTrace = (PFNCAPTURESTACKBACKTRACE)GetProcAddress(hModule, - "RtlCaptureStackBackTrace"); + pfnCaptureStackBackTrace = + (PFNCAPTURESTACKBACKTRACE)GetProcAddress(hModule, + "RtlCaptureStackBackTrace"); } } if (pfnCaptureStackBackTrace) { @@ -88,7 +91,8 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace, start_frame += 1; assert(start_frame + nr_frames < 63); - i = pfnCaptureStackBackTrace(start_frame, nr_frames, (PVOID *) &backtrace->function, NULL); + i = pfnCaptureStackBackTrace(start_frame, nr_frames, + (PVOID *) &backtrace->function, NULL); /* Pad remaing requested frames with NULL */ while (i < nr_frames) { @@ -110,50 +114,49 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace, #else frame_pointer = NULL; #endif - - + #ifdef PIPE_ARCH_X86 - while(nr_frames) { + while (nr_frames) { const void **next_frame_pointer; - if(!frame_pointer) + if (!frame_pointer) break; - - if(start_frame) + + if (start_frame) --start_frame; else { backtrace[i++].function = frame_pointer[1]; --nr_frames; } - + next_frame_pointer = (const void **)frame_pointer[0]; - + /* Limit the stack walk to avoid referencing undefined memory */ - if((uintptr_t)next_frame_pointer <= (uintptr_t)frame_pointer || - (uintptr_t)next_frame_pointer > (uintptr_t)frame_pointer + 64*1024) + if ((uintptr_t)next_frame_pointer <= (uintptr_t)frame_pointer || + (uintptr_t)next_frame_pointer > (uintptr_t)frame_pointer + 64*1024) break; - + frame_pointer = next_frame_pointer; } #else (void) frame_pointer; #endif - while(nr_frames) { + while (nr_frames) { backtrace[i++].function = NULL; --nr_frames; } } - + void -debug_backtrace_dump(const struct debug_stack_frame *backtrace, +debug_backtrace_dump(const struct debug_stack_frame *backtrace, unsigned nr_frames) { unsigned i; - - for(i = 0; i < nr_frames; ++i) { - if(!backtrace[i].function) + + for (i = 0; i < nr_frames; ++i) { + if (!backtrace[i].function) break; debug_symbol_print(backtrace[i].function); } diff --git a/src/gallium/auxiliary/util/u_pstipple.c b/src/gallium/auxiliary/util/u_pstipple.c index 3428172203b..74e6f99da67 100644 --- a/src/gallium/auxiliary/util/u_pstipple.c +++ b/src/gallium/auxiliary/util/u_pstipple.c @@ -58,7 +58,7 @@ #define NUM_NEW_TOKENS 53 -static void +void util_pstipple_update_stipple_texture(struct pipe_context *pipe, struct pipe_resource *tex, const uint32_t pattern[32]) @@ -118,7 +118,7 @@ util_pstipple_create_stipple_texture(struct pipe_context *pipe, tex = screen->resource_create(screen, &templat); - if (tex) + if (tex && pattern) util_pstipple_update_stipple_texture(pipe, tex, pattern); return tex; diff --git a/src/gallium/auxiliary/util/u_pstipple.h b/src/gallium/auxiliary/util/u_pstipple.h index ef8396f4318..d1662be2839 100644 --- a/src/gallium/auxiliary/util/u_pstipple.h +++ b/src/gallium/auxiliary/util/u_pstipple.h @@ -36,6 +36,11 @@ struct pipe_resource; struct pipe_shader_state; +extern void +util_pstipple_update_stipple_texture(struct pipe_context *pipe, + struct pipe_resource *tex, + const uint32_t pattern[32]); + extern struct pipe_resource * util_pstipple_create_stipple_texture(struct pipe_context *pipe, const uint32_t pattern[32]); diff --git a/src/gallium/auxiliary/util/u_staging.c b/src/gallium/auxiliary/util/u_staging.c index b569c8f9907..caef2a8245c 100644 --- a/src/gallium/auxiliary/util/u_staging.c +++ b/src/gallium/auxiliary/util/u_staging.c @@ -29,11 +29,14 @@ #include "util/u_memory.h" #include "util/u_inlines.h" + static void -util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigned height, unsigned depth, struct pipe_resource *template) +util_staging_resource_template(struct pipe_resource *pt, unsigned width, + unsigned height, unsigned depth, + struct pipe_resource *template) { memset(template, 0, sizeof(struct pipe_resource)); - if(pt->target != PIPE_BUFFER && depth <= 1) + if (pt->target != PIPE_BUFFER && depth <= 1) template->target = PIPE_TEXTURE_RECT; else template->target = pt->target; @@ -49,16 +52,15 @@ util_staging_resource_template(struct pipe_resource *pt, unsigned width, unsigne template->flags = 0; } + struct util_staging_transfer * util_staging_transfer_init(struct pipe_context *pipe, - struct pipe_resource *pt, - unsigned level, - unsigned usage, - const struct pipe_box *box, - boolean direct, struct util_staging_transfer *tx) + struct pipe_resource *pt, + unsigned level, unsigned usage, + const struct pipe_box *box, + boolean direct, struct util_staging_transfer *tx) { struct pipe_screen *pscreen = pipe->screen; - struct pipe_resource staging_resource_template; pipe_resource_reference(&tx->base.resource, pt); @@ -66,23 +68,22 @@ util_staging_transfer_init(struct pipe_context *pipe, tx->base.usage = usage; tx->base.box = *box; - if (direct) - { + if (direct) { tx->staging_resource = pt; return tx; } - util_staging_resource_template(pt, box->width, box->height, box->depth, &staging_resource_template); - tx->staging_resource = pscreen->resource_create(pscreen, &staging_resource_template); - if (!tx->staging_resource) - { + util_staging_resource_template(pt, box->width, box->height, + box->depth, &staging_resource_template); + tx->staging_resource = pscreen->resource_create(pscreen, + &staging_resource_template); + if (!tx->staging_resource) { pipe_resource_reference(&tx->base.resource, NULL); FREE(tx); return NULL; } - if (usage & PIPE_TRANSFER_READ) - { + if (usage & PIPE_TRANSFER_READ) { /* XXX this looks wrong dst is always the same but looping over src z? */ int zi; struct pipe_box sbox; @@ -92,7 +93,7 @@ util_staging_transfer_init(struct pipe_context *pipe, sbox.width = box->width; sbox.height = box->height; sbox.depth = 1; - for(zi = 0; zi < box->depth; ++zi) { + for (zi = 0; zi < box->depth; ++zi) { sbox.z = sbox.z + zi; pipe->resource_copy_region(pipe, tx->staging_resource, 0, 0, 0, 0, tx->base.resource, level, &sbox); @@ -102,14 +103,15 @@ util_staging_transfer_init(struct pipe_context *pipe, return tx; } + void -util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx) +util_staging_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *ptx) { struct util_staging_transfer *tx = (struct util_staging_transfer *)ptx; - if (tx->staging_resource != tx->base.resource) - { - if(tx->base.usage & PIPE_TRANSFER_WRITE) { + if (tx->staging_resource != tx->base.resource) { + if (tx->base.usage & PIPE_TRANSFER_WRITE) { /* XXX this looks wrong src is always the same but looping over dst z? */ int zi; struct pipe_box sbox; @@ -119,8 +121,10 @@ util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *p sbox.width = tx->base.box.width; sbox.height = tx->base.box.height; sbox.depth = 1; - for(zi = 0; zi < tx->base.box.depth; ++zi) - pipe->resource_copy_region(pipe, tx->base.resource, tx->base.level, tx->base.box.x, tx->base.box.y, tx->base.box.z + zi, + for (zi = 0; zi < tx->base.box.depth; ++zi) + pipe->resource_copy_region(pipe, tx->base.resource, tx->base.level, + tx->base.box.x, tx->base.box.y, + tx->base.box.z + zi, tx->staging_resource, 0, &sbox); } diff --git a/src/gallium/auxiliary/util/u_staging.h b/src/gallium/auxiliary/util/u_staging.h index ddbb33443e4..6c468aad161 100644 --- a/src/gallium/auxiliary/util/u_staging.h +++ b/src/gallium/auxiliary/util/u_staging.h @@ -42,22 +42,26 @@ struct util_staging_transfer { struct pipe_transfer base; - /* if direct, same as base.resource, otherwise the temporary staging resource */ + /* if direct, same as base.resource, otherwise the temporary staging + * resource + */ struct pipe_resource *staging_resource; }; -/* user must be stride, slice_stride and offset */ -/* pt->usage == PIPE_USAGE_DYNAMIC || pt->usage == PIPE_USAGE_STAGING should be a good value to pass for direct */ -/* staging resource is currently created with PIPE_USAGE_STAGING */ +/* user must be stride, slice_stride and offset. + * pt->usage == PIPE_USAGE_DYNAMIC || pt->usage == PIPE_USAGE_STAGING + * should be a good value to pass for direct staging resource is currently + * created with PIPE_USAGE_STAGING + */ struct util_staging_transfer * util_staging_transfer_init(struct pipe_context *pipe, - struct pipe_resource *pt, - unsigned level, - unsigned usage, - const struct pipe_box *box, - boolean direct, struct util_staging_transfer *tx); + struct pipe_resource *pt, + unsigned level, unsigned usage, + const struct pipe_box *box, + boolean direct, struct util_staging_transfer *tx); void -util_staging_transfer_destroy(struct pipe_context *pipe, struct pipe_transfer *ptx); +util_staging_transfer_destroy(struct pipe_context *pipe, + struct pipe_transfer *ptx); #endif |