diff options
Diffstat (limited to 'src/gallium')
277 files changed, 5252 insertions, 6894 deletions
diff --git a/src/gallium/SConscript b/src/gallium/SConscript index 31580556f03..428bc31f86b 100644 --- a/src/gallium/SConscript +++ b/src/gallium/SConscript @@ -53,7 +53,6 @@ if env['drm']: # Needed by some state trackers SConscript('winsys/sw/null/SConscript') -SConscript('state_trackers/python/SConscript') if env['platform'] != 'embedded': SConscript('state_trackers/vega/SConscript') SConscript('state_trackers/egl/SConscript') diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index aa1b255c0c9..428e097be09 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -107,6 +107,7 @@ C_SOURCES = \ util/u_caps.c \ util/u_cpu_detect.c \ util/u_dl.c \ + util/u_draw.c \ util/u_draw_quad.c \ util/u_format.c \ util/u_format_other.c \ diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index 84519cfd048..6176f0ae2a8 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -154,6 +154,7 @@ source = [ 'util/u_dump_defines.c', 'util/u_dump_state.c', 'util/u_dl.c', + 'util/u_draw.c', 'util/u_draw_quad.c', 'util/u_format.c', 'util/u_format_other.c', diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c index 95d96719873..d99f94edc43 100644 --- a/src/gallium/auxiliary/draw/draw_context.c +++ b/src/gallium/auxiliary/draw/draw_context.c @@ -751,7 +751,7 @@ void draw_set_mapped_texture(struct draw_context *draw, unsigned sampler_idx, uint32_t width, uint32_t height, uint32_t depth, - uint32_t last_level, + uint32_t first_level, uint32_t last_level, uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], const void *data[PIPE_MAX_TEXTURE_LEVELS]) @@ -760,7 +760,7 @@ draw_set_mapped_texture(struct draw_context *draw, if(draw->llvm) draw_llvm_set_mapped_texture(draw, sampler_idx, - width, height, depth, last_level, + width, height, depth, first_level, last_level, row_stride, img_stride, data); #endif } diff --git a/src/gallium/auxiliary/draw/draw_context.h b/src/gallium/auxiliary/draw/draw_context.h index a0b217e4d33..7db75b71b43 100644 --- a/src/gallium/auxiliary/draw/draw_context.h +++ b/src/gallium/auxiliary/draw/draw_context.h @@ -123,7 +123,7 @@ void draw_set_mapped_texture(struct draw_context *draw, unsigned sampler_idx, uint32_t width, uint32_t height, uint32_t depth, - uint32_t last_level, + uint32_t first_level, uint32_t last_level, uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], const void *data[PIPE_MAX_TEXTURE_LEVELS]); diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index a5217c1d4ec..a1b8fc38880 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -106,6 +106,7 @@ create_jit_texture_type(struct gallivm_state *gallivm) elem_types[DRAW_JIT_TEXTURE_WIDTH] = elem_types[DRAW_JIT_TEXTURE_HEIGHT] = elem_types[DRAW_JIT_TEXTURE_DEPTH] = + elem_types[DRAW_JIT_TEXTURE_FIRST_LEVEL] = elem_types[DRAW_JIT_TEXTURE_LAST_LEVEL] = int32_type; elem_types[DRAW_JIT_TEXTURE_ROW_STRIDE] = elem_types[DRAW_JIT_TEXTURE_IMG_STRIDE] = @@ -136,6 +137,9 @@ create_jit_texture_type(struct gallivm_state *gallivm) LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, depth, target, texture_type, DRAW_JIT_TEXTURE_DEPTH); + LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, first_level, + target, texture_type, + DRAW_JIT_TEXTURE_FIRST_LEVEL); LP_CHECK_MEMBER_OFFSET(struct draw_jit_texture, last_level, target, texture_type, DRAW_JIT_TEXTURE_LAST_LEVEL); @@ -438,7 +442,8 @@ generate_vs(struct draw_llvm *llvm, const LLVMValueRef (*inputs)[NUM_CHANNELS], LLVMValueRef system_values_array, LLVMValueRef context_ptr, - struct lp_build_sampler_soa *draw_sampler) + struct lp_build_sampler_soa *draw_sampler, + boolean clamp_vertex_color) { const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens; struct lp_type vs_type; @@ -474,6 +479,30 @@ generate_vs(struct draw_llvm *llvm, outputs, sampler, &llvm->draw->vs.vertex_shader->info); + + if(clamp_vertex_color) + { + LLVMValueRef out; + unsigned chan, attrib; + struct lp_build_context bld; + struct tgsi_shader_info* info = &llvm->draw->vs.vertex_shader->info; + lp_build_context_init(&bld, llvm->gallivm, vs_type); + + for (attrib = 0; attrib < info->num_outputs; ++attrib) { + for(chan = 0; chan < NUM_CHANNELS; ++chan) { + if(outputs[attrib][chan]) { + switch (info->output_semantic_name[attrib]) { + case TGSI_SEMANTIC_COLOR: + case TGSI_SEMANTIC_BCOLOR: + out = LLVMBuildLoad(builder, outputs[attrib][chan], ""); + out = lp_build_clamp(&bld, out, bld.zero, bld.one); + LLVMBuildStore(builder, out, outputs[attrib][chan]); + break; + } + } + } + } + } } #if DEBUG_STORE @@ -1235,7 +1264,8 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) ptr_aos, system_values_array, context_ptr, - sampler); + sampler, + variant->key.clamp_vertex_color); /* store original positions in clip before further manipulation */ store_clip(gallivm, io, outputs); @@ -1446,7 +1476,8 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian ptr_aos, system_values_array, context_ptr, - sampler); + sampler, + variant->key.clamp_vertex_color); /* store original positions in clip before further manipulation */ store_clip(gallivm, io, outputs); @@ -1524,6 +1555,8 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store) key = (struct draw_llvm_variant_key *)store; + key->clamp_vertex_color = llvm->draw->rasterizer->clamp_vertex_color; /**/ + /* Presumably all variants of the shader should have the same * number of vertex elements - ie the number of shader inputs. */ @@ -1566,7 +1599,7 @@ void draw_llvm_set_mapped_texture(struct draw_context *draw, unsigned sampler_idx, uint32_t width, uint32_t height, uint32_t depth, - uint32_t last_level, + uint32_t first_level, uint32_t last_level, uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], const void *data[PIPE_MAX_TEXTURE_LEVELS]) @@ -1582,9 +1615,10 @@ draw_llvm_set_mapped_texture(struct draw_context *draw, jit_tex->width = width; jit_tex->height = height; jit_tex->depth = depth; + jit_tex->first_level = first_level; jit_tex->last_level = last_level; - for (j = 0; j <= last_level; j++) { + for (j = first_level; j <= last_level; j++) { jit_tex->data[j] = data[j]; jit_tex->row_stride[j] = row_stride[j]; jit_tex->img_stride[j] = img_stride[j]; diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h index e8623e7bcdc..375b7b8b571 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.h +++ b/src/gallium/auxiliary/draw/draw_llvm.h @@ -50,6 +50,7 @@ struct draw_jit_texture uint32_t width; uint32_t height; uint32_t depth; + uint32_t first_level; uint32_t last_level; uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS]; uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS]; @@ -64,6 +65,7 @@ enum { DRAW_JIT_TEXTURE_WIDTH = 0, DRAW_JIT_TEXTURE_HEIGHT, DRAW_JIT_TEXTURE_DEPTH, + DRAW_JIT_TEXTURE_FIRST_LEVEL, DRAW_JIT_TEXTURE_LAST_LEVEL, DRAW_JIT_TEXTURE_ROW_STRIDE, DRAW_JIT_TEXTURE_IMG_STRIDE, @@ -162,6 +164,7 @@ struct draw_llvm_variant_key { unsigned nr_vertex_elements:8; unsigned nr_samplers:8; + unsigned clamp_vertex_color:1; unsigned clip_xy:1; unsigned clip_z:1; unsigned clip_user:1; @@ -169,7 +172,7 @@ struct draw_llvm_variant_key unsigned bypass_viewport:1; unsigned need_edgeflags:1; unsigned nr_planes:4; - unsigned pad:6; + unsigned pad:5; /* Variable number of vertex elements: */ @@ -295,7 +298,7 @@ void draw_llvm_set_mapped_texture(struct draw_context *draw, unsigned sampler_idx, uint32_t width, uint32_t height, uint32_t depth, - uint32_t last_level, + uint32_t first_level, uint32_t last_level, uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], const void *data[PIPE_MAX_TEXTURE_LEVELS]); diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c b/src/gallium/auxiliary/draw/draw_llvm_sample.c index 574c7cc452f..8af34617353 100644 --- a/src/gallium/auxiliary/draw/draw_llvm_sample.c +++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c @@ -144,6 +144,7 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base, DRAW_LLVM_TEXTURE_MEMBER(width, DRAW_JIT_TEXTURE_WIDTH, TRUE) DRAW_LLVM_TEXTURE_MEMBER(height, DRAW_JIT_TEXTURE_HEIGHT, TRUE) DRAW_LLVM_TEXTURE_MEMBER(depth, DRAW_JIT_TEXTURE_DEPTH, TRUE) +DRAW_LLVM_TEXTURE_MEMBER(first_level,DRAW_JIT_TEXTURE_FIRST_LEVEL, TRUE) DRAW_LLVM_TEXTURE_MEMBER(last_level, DRAW_JIT_TEXTURE_LAST_LEVEL, TRUE) DRAW_LLVM_TEXTURE_MEMBER(row_stride, DRAW_JIT_TEXTURE_ROW_STRIDE, FALSE) DRAW_LLVM_TEXTURE_MEMBER(img_stride, DRAW_JIT_TEXTURE_IMG_STRIDE, FALSE) @@ -209,6 +210,7 @@ draw_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state, sampler->dynamic_state.base.width = draw_llvm_texture_width; sampler->dynamic_state.base.height = draw_llvm_texture_height; sampler->dynamic_state.base.depth = draw_llvm_texture_depth; + sampler->dynamic_state.base.first_level = draw_llvm_texture_first_level; sampler->dynamic_state.base.last_level = draw_llvm_texture_last_level; sampler->dynamic_state.base.row_stride = draw_llvm_texture_row_stride; sampler->dynamic_state.base.img_stride = draw_llvm_texture_img_stride; diff --git a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c index 58c5858734a..61ae4665539 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c +++ b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c @@ -341,6 +341,16 @@ vbuf_flush_vertices( struct vbuf_stage *vbuf ) vbuf->max_vertices = vbuf->nr_vertices = 0; vbuf->vertex_ptr = vbuf->vertices = NULL; } + + /* Reset point/line/tri function pointers. + * If (for example) we transition from points to tris and back to points + * again, we need to call the vbuf_first_point() function again to flush + * the triangles before drawing more points. This can happen when drawing + * with front polygon mode = filled and back polygon mode = line or point. + */ + vbuf->stage.point = vbuf_first_point; + vbuf->stage.line = vbuf_first_line; + vbuf->stage.tri = vbuf_first_tri; } @@ -378,10 +388,6 @@ vbuf_flush( struct draw_stage *stage, unsigned flags ) struct vbuf_stage *vbuf = vbuf_stage( stage ); vbuf_flush_vertices( vbuf ); - - stage->point = vbuf_first_point; - stage->line = vbuf_first_line; - stage->tri = vbuf_first_tri; } diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h index db2e3c5410d..b7d693f8584 100644 --- a/src/gallium/auxiliary/draw/draw_private.h +++ b/src/gallium/auxiliary/draw/draw_private.h @@ -146,6 +146,14 @@ struct draw_context struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; unsigned nr_vertex_buffers; + /* + * This is the largest legal index value for the current set of + * bound vertex buffers. Regardless of any other consideration, + * all vertex lookups need to be clamped to 0..max_index to + * prevent out-of-bound access. + */ + unsigned max_index; + struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; unsigned nr_vertex_elements; diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c index c3d7e871f7a..e0eda67c1a2 100644 --- a/src/gallium/auxiliary/draw/draw_pt.c +++ b/src/gallium/auxiliary/draw/draw_pt.c @@ -470,6 +470,17 @@ draw_vbo(struct draw_context *draw, if (0) draw_print_arrays(draw, info->mode, info->start, MIN2(info->count, 20)); + draw->pt.max_index = util_draw_max_index(draw->pt.vertex_buffer, + draw->pt.nr_vertex_buffers, + draw->pt.vertex_element, + draw->pt.nr_vertex_elements, + info); + + /* + * TODO: We could use draw->pt.max_index to further narrow + * the min_index/max_index hints given by the state tracker. + */ + for (instance = 0; instance < info->instance_count; instance++) { draw->instance_id = instance + info->start_instance; diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch.c b/src/gallium/auxiliary/draw/draw_pt_fetch.c index 4fa3b265e10..5589a8212e4 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch.c @@ -139,7 +139,7 @@ void draw_pt_fetch_run( struct pt_fetch *fetch, ((char *)draw->pt.user.vbuffer[i] + draw->pt.vertex_buffer[i].buffer_offset), draw->pt.vertex_buffer[i].stride, - draw->pt.user.max_index); + draw->pt.max_index); } translate->run_elts( translate, diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c index 51043102a61..0ab11d015c6 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c @@ -186,7 +186,7 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle, ((char *)draw->pt.user.vbuffer[i] + draw->pt.vertex_buffer[i].buffer_offset), draw->pt.vertex_buffer[i].stride, - draw->pt.user.max_index); + draw->pt.max_index); } *max_vertices = (draw->render->max_vertex_buffer_bytes / diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c index 1e926fb028e..0dbbfe2b73c 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c @@ -169,7 +169,7 @@ static void fse_prepare( struct draw_pt_middle_end *middle, ((const ubyte *) draw->pt.user.vbuffer[i] + draw->pt.vertex_buffer[i].buffer_offset), draw->pt.vertex_buffer[i].stride, - draw->pt.user.max_index ); + draw->pt.max_index ); } *max_vertices = (draw->render->max_vertex_buffer_bytes / diff --git a/src/gallium/auxiliary/draw/draw_pt_vsplit.c b/src/gallium/auxiliary/draw/draw_pt_vsplit.c index a6875253094..c19dcd9e1f7 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vsplit.c +++ b/src/gallium/auxiliary/draw/draw_pt_vsplit.c @@ -85,7 +85,12 @@ vsplit_flush_cache(struct vsplit_frontend *vsplit, unsigned flags) static INLINE void vsplit_add_cache(struct vsplit_frontend *vsplit, unsigned fetch) { - unsigned hash = fetch % MAP_SIZE; + struct draw_context *draw = vsplit->draw; + unsigned hash; + + fetch = MIN2(fetch, draw->pt.max_index); + + hash = fetch % MAP_SIZE; if (vsplit->cache.fetches[hash] != fetch) { /* update cache */ diff --git a/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h index 75dba8c39a5..bb3cbf80ad7 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h +++ b/src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h @@ -47,14 +47,18 @@ CONCAT(vsplit_primitive_, ELT_TYPE)(struct vsplit_frontend *vsplit, const ushort *draw_elts = NULL; unsigned i; + ib += istart; + /* use the ib directly */ if (min_index == 0 && sizeof(ib[0]) == sizeof(draw_elts[0])) { if (icount > vsplit->max_vertices) return FALSE; for (i = 0; i < icount; i++) { - ELT_TYPE idx = ib[istart + i]; - assert(idx >= min_index && idx <= max_index); + ELT_TYPE idx = ib[i]; + if (idx < min_index || idx > max_index) { + debug_printf("warning: index out of range\n"); + } } draw_elts = (const ushort *) ib; } @@ -83,17 +87,21 @@ CONCAT(vsplit_primitive_, ELT_TYPE)(struct vsplit_frontend *vsplit, if (!draw_elts) { if (min_index == 0) { for (i = 0; i < icount; i++) { - ELT_TYPE idx = ib[istart + i]; + ELT_TYPE idx = ib[i]; - assert(idx >= min_index && idx <= max_index); + if (idx < min_index || idx > max_index) { + debug_printf("warning: index out of range\n"); + } vsplit->draw_elts[i] = (ushort) idx; } } else { for (i = 0; i < icount; i++) { - ELT_TYPE idx = ib[istart + i]; + ELT_TYPE idx = ib[i]; - assert(idx >= min_index && idx <= max_index); + if (idx < min_index || idx > max_index) { + debug_printf("warning: index out of range\n"); + } vsplit->draw_elts[i] = (ushort) (idx - min_index); } } diff --git a/src/gallium/auxiliary/draw/draw_vs.c b/src/gallium/auxiliary/draw/draw_vs.c index 7caad6f0053..1763dbc199f 100644 --- a/src/gallium/auxiliary/draw/draw_vs.c +++ b/src/gallium/auxiliary/draw/draw_vs.c @@ -104,11 +104,18 @@ draw_create_vertex_shader(struct draw_context *draw, } if (!draw->pt.middle.llvm) { +#if 0 +/* these paths don't support vertex clamping + * TODO: either add it, or remove them completely + * use LLVM instead if you want performance + * use exec instead if you want debugging/more correctness + */ #if defined(PIPE_ARCH_X86) vs = draw_create_vs_sse( draw, shader ); #elif defined(PIPE_ARCH_PPC) vs = draw_create_vs_ppc( draw, shader ); #endif +#endif } #if HAVE_LLVM else { diff --git a/src/gallium/auxiliary/draw/draw_vs_exec.c b/src/gallium/auxiliary/draw/draw_vs_exec.c index c41d7c42a01..d9c4209a42b 100644 --- a/src/gallium/auxiliary/draw/draw_vs_exec.c +++ b/src/gallium/auxiliary/draw/draw_vs_exec.c @@ -95,6 +95,7 @@ vs_exec_run_linear( struct draw_vertex_shader *shader, struct tgsi_exec_machine *machine = evs->machine; unsigned int i, j; unsigned slot; + boolean clamp_vertex_color = shader->draw->rasterizer->clamp_vertex_color; tgsi_exec_set_constant_buffers(machine, PIPE_MAX_CONSTANT_BUFFERS, constants, const_size); @@ -151,11 +152,22 @@ vs_exec_run_linear( struct draw_vertex_shader *shader, */ for (j = 0; j < max_vertices; j++) { for (slot = 0; slot < shader->info.num_outputs; slot++) { - output[slot][0] = machine->Outputs[slot].xyzw[0].f[j]; - output[slot][1] = machine->Outputs[slot].xyzw[1].f[j]; - output[slot][2] = machine->Outputs[slot].xyzw[2].f[j]; - output[slot][3] = machine->Outputs[slot].xyzw[3].f[j]; - + unsigned name = shader->info.output_semantic_name[slot]; + if(clamp_vertex_color && + (name == TGSI_SEMANTIC_COLOR || name == TGSI_SEMANTIC_BCOLOR)) + { + output[slot][0] = CLAMP(machine->Outputs[slot].xyzw[0].f[j], 0.0f, 1.0f); + output[slot][1] = CLAMP(machine->Outputs[slot].xyzw[1].f[j], 0.0f, 1.0f); + output[slot][2] = CLAMP(machine->Outputs[slot].xyzw[2].f[j], 0.0f, 1.0f); + output[slot][3] = CLAMP(machine->Outputs[slot].xyzw[3].f[j], 0.0f, 1.0f); + } + else + { + output[slot][0] = machine->Outputs[slot].xyzw[0].f[j]; + output[slot][1] = machine->Outputs[slot].xyzw[1].f[j]; + output[slot][2] = machine->Outputs[slot].xyzw[2].f[j]; + output[slot][3] = machine->Outputs[slot].xyzw[3].f[j]; + } } #if 0 diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp index bb2c82fe0ed..0b724a34948 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp +++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.cpp @@ -32,7 +32,12 @@ #include <llvm/Target/TargetInstrInfo.h> #include <llvm/Support/raw_ostream.h> #include <llvm/Support/MemoryObject.h> + +#if HAVE_LLVM >= 0x0209 +#include <llvm/Support/Host.h> +#else #include <llvm/System/Host.h> +#endif #if HAVE_LLVM >= 0x0207 #include <llvm/MC/MCDisassembler.h> @@ -202,9 +207,17 @@ lp_disassemble(const void* func) } raw_debug_ostream Out; + TargetMachine *TM = T->createTargetMachine(Triple, ""); +#if HAVE_LLVM >= 0x0300 + unsigned int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); +#else int AsmPrinterVariant = AsmInfo->getAssemblerDialect(); -#if HAVE_LLVM >= 0x0208 +#endif +#if HAVE_LLVM >= 0x0300 + OwningPtr<MCInstPrinter> Printer( + T->createMCInstPrinter(*TM, AsmPrinterVariant, *AsmInfo)); +#elif HAVE_LLVM >= 0x0208 OwningPtr<MCInstPrinter> Printer( T->createMCInstPrinter(AsmPrinterVariant, *AsmInfo)); #else @@ -216,8 +229,6 @@ lp_disassemble(const void* func) return; } - TargetMachine *TM = T->createTargetMachine(Triple, ""); - const TargetInstrInfo *TII = TM->getInstrInfo(); /* diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c index 8ad34598a92..4636371a0f5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c @@ -51,6 +51,10 @@ */ #define BRILINEAR_FACTOR 2 +static LLVMValueRef +lp_build_minify(struct lp_build_context *bld, + LLVMValueRef base_size, + LLVMValueRef level); /** * Does the given texture wrap mode allow sampling the texture border color? @@ -184,9 +188,11 @@ lp_sampler_static_state(struct lp_sampler_static_state *state, */ static LLVMValueRef lp_build_rho(struct lp_build_sample_context *bld, + unsigned unit, const LLVMValueRef ddx[4], const LLVMValueRef ddy[4]) { + struct lp_build_context *int_size_bld = &bld->int_size_bld; struct lp_build_context *float_size_bld = &bld->float_size_bld; struct lp_build_context *float_bld = &bld->float_bld; const unsigned dims = bld->dims; @@ -198,8 +204,9 @@ lp_build_rho(struct lp_build_sample_context *bld, LLVMValueRef dsdx, dsdy, dtdx, dtdy, drdx, drdy; LLVMValueRef rho_x, rho_y; LLVMValueRef rho_vec; - LLVMValueRef float_size; + LLVMValueRef int_size, float_size; LLVMValueRef rho; + LLVMValueRef first_level, first_level_vec; dsdx = ddx[0]; dsdy = ddy[0]; @@ -235,7 +242,11 @@ lp_build_rho(struct lp_build_sample_context *bld, rho_vec = lp_build_max(float_size_bld, rho_x, rho_y); - float_size = lp_build_int_to_float(float_size_bld, bld->int_size); + first_level = bld->dynamic_state->first_level(bld->dynamic_state, + bld->gallivm, unit); + first_level_vec = lp_build_broadcast_scalar(&bld->int_size_bld, first_level); + int_size = lp_build_minify(int_size_bld, bld->int_size, first_level_vec); + float_size = lp_build_int_to_float(float_size_bld, int_size); rho_vec = lp_build_mul(float_size_bld, rho_vec, float_size); @@ -442,7 +453,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld, else { LLVMValueRef rho; - rho = lp_build_rho(bld, ddx, ddy); + rho = lp_build_rho(bld, unit, ddx, ddy); /* * Compute lod = log2(rho) @@ -542,18 +553,18 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld, LLVMValueRef *level_out) { struct lp_build_context *int_bld = &bld->int_bld; - LLVMValueRef last_level, level; - - LLVMValueRef zero = lp_build_const_int32(bld->gallivm, 0); + LLVMValueRef first_level, last_level, level; + first_level = bld->dynamic_state->first_level(bld->dynamic_state, + bld->gallivm, unit); last_level = bld->dynamic_state->last_level(bld->dynamic_state, bld->gallivm, unit); /* convert float lod to integer */ - level = lod_ipart; + level = lp_build_add(int_bld, lod_ipart, first_level); /* clamp level to legal range of levels */ - *level_out = lp_build_clamp(int_bld, level, zero, last_level); + *level_out = lp_build_clamp(int_bld, level, first_level, last_level); } @@ -573,39 +584,42 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld, LLVMBuilderRef builder = bld->gallivm->builder; struct lp_build_context *int_bld = &bld->int_bld; struct lp_build_context *float_bld = &bld->float_bld; - LLVMValueRef last_level; + LLVMValueRef first_level, last_level; LLVMValueRef clamp_min; LLVMValueRef clamp_max; - *level0_out = lod_ipart; - *level1_out = lp_build_add(int_bld, lod_ipart, int_bld->one); + first_level = bld->dynamic_state->first_level(bld->dynamic_state, + bld->gallivm, unit); + + *level0_out = lp_build_add(int_bld, lod_ipart, first_level); + *level1_out = lp_build_add(int_bld, *level0_out, int_bld->one); last_level = bld->dynamic_state->last_level(bld->dynamic_state, bld->gallivm, unit); /* - * Clamp both lod_ipart and lod_ipart + 1 to [0, last_level], with the - * minimum number of comparisons, and zeroing lod_fpart in the extreme + * Clamp both *level0_out and *level1_out to [first_level, last_level], with + * the minimum number of comparisons, and zeroing lod_fpart in the extreme * ends in the process. */ - /* lod_ipart < 0 */ + /* *level0_out < first_level */ clamp_min = LLVMBuildICmp(builder, LLVMIntSLT, - lod_ipart, int_bld->zero, - "clamp_lod_to_zero"); + *level0_out, first_level, + "clamp_lod_to_first"); *level0_out = LLVMBuildSelect(builder, clamp_min, - int_bld->zero, *level0_out, ""); + first_level, *level0_out, ""); *level1_out = LLVMBuildSelect(builder, clamp_min, - int_bld->zero, *level1_out, ""); + first_level, *level1_out, ""); *lod_fpart_inout = LLVMBuildSelect(builder, clamp_min, float_bld->zero, *lod_fpart_inout, ""); - /* lod_ipart >= last_level */ + /* *level0_out >= last_level */ clamp_max = LLVMBuildICmp(builder, LLVMIntSGE, - lod_ipart, last_level, + *level0_out, last_level, "clamp_lod_to_last"); *level0_out = LLVMBuildSelect(builder, clamp_max, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index 8c9d5df4e43..a71e656fe0e 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -120,6 +120,12 @@ struct lp_sampler_dynamic_state struct gallivm_state *gallivm, unsigned unit); + /** Obtain the first mipmap level (base level) (returns int32) */ + LLVMValueRef + (*first_level)( const struct lp_sampler_dynamic_state *state, + struct gallivm_state *gallivm, + unsigned unit); + /** Obtain the number of mipmap levels minus one (returns int32) */ LLVMValueRef (*last_level)( const struct lp_sampler_dynamic_state *state, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c index e61cf9541ea..4f160159968 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_aos.c @@ -939,6 +939,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld, LLVMValueRef unswizzled[4]; LLVMValueRef face_ddx[4], face_ddy[4]; struct lp_build_context h16_bld; + LLVMValueRef first_level; LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0); /* we only support the common/simple wrap modes at this time */ @@ -1008,7 +1009,9 @@ lp_build_sample_aos(struct lp_build_sample_context *bld, lp_build_nearest_mip_level(bld, unit, lod_ipart, &ilevel0); } else { - ilevel0 = i32t_zero; + first_level = bld->dynamic_state->first_level(bld->dynamic_state, + bld->gallivm, unit); + ilevel0 = first_level; } break; case PIPE_TEX_MIPFILTER_NEAREST: @@ -1065,7 +1068,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld, lp_build_sample_mipmap(bld, mag_filter, PIPE_TEX_MIPFILTER_NONE, s, t, r, - i32t_zero, NULL, NULL, + ilevel0, NULL, NULL, packed_lo, packed_hi); } lp_build_endif(&if_ctx); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index 9961ba08f3a..4ea7b4bd8a2 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -943,6 +943,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld, LLVMValueRef ilevel0, ilevel1 = NULL; LLVMValueRef face_ddx[4], face_ddy[4]; LLVMValueRef texels[4]; + LLVMValueRef first_level; LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0); unsigned chan; @@ -1009,7 +1010,9 @@ lp_build_sample_general(struct lp_build_sample_context *bld, lp_build_nearest_mip_level(bld, unit, lod_ipart, &ilevel0); } else { - ilevel0 = i32t_zero; + first_level = bld->dynamic_state->first_level(bld->dynamic_state, + bld->gallivm, unit); + ilevel0 = first_level; } break; case PIPE_TEX_MIPFILTER_NEAREST: @@ -1068,7 +1071,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld, lp_build_sample_mipmap(bld, unit, mag_filter, PIPE_TEX_MIPFILTER_NONE, s, t, r, - i32t_zero, NULL, NULL, + ilevel0, NULL, NULL, texels); } lp_build_endif(&if_ctx); diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c index b03dd3a0cf8..5231bb08374 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c @@ -726,6 +726,16 @@ void x86_movzx16(struct x86_function *p, struct x86_reg dst, struct x86_reg src emit_modrm(p, dst, src); } +void x86_cmovcc( struct x86_function *p, + struct x86_reg dst, + struct x86_reg src, + enum x86_cc cc) +{ + DUMP_RRI( dst, src, cc ); + emit_2ub( p, 0x0f, 0x40 + cc ); + emit_modrm( p, dst, src ); +} + void x86_xor( struct x86_function *p, struct x86_reg dst, struct x86_reg src ) diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h index 2b9678b1765..af0565bb59d 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.h +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.h @@ -309,6 +309,7 @@ void sse_movmskps( struct x86_function *p, struct x86_reg dst, struct x86_reg sr void x86_add( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); void x86_and( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); +void x86_cmovcc( struct x86_function *p, struct x86_reg dst, struct x86_reg src, enum x86_cc cc ); void x86_cmp( struct x86_function *p, struct x86_reg dst, struct x86_reg src ); void x86_dec( struct x86_function *p, struct x86_reg reg ); void x86_inc( struct x86_function *p, struct x86_reg reg ); diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c index ad809db720d..e4e1c868333 100644 --- a/src/gallium/auxiliary/translate/translate_generic.c +++ b/src/gallium/auxiliary/translate/translate_generic.c @@ -381,14 +381,17 @@ static ALWAYS_INLINE void PIPE_CDECL generic_run_one( struct translate_generic * if (tg->attrib[attr].instance_divisor) { index = instance_id / tg->attrib[attr].instance_divisor; + /* XXX we need to clamp the index here too, but to a + * per-array max value, not the draw->pt.max_index value + * that's being given to us via translate->set_buffer(). + */ } else { index = elt; + /* clamp to avoid going out of bounds */ + index = MIN2(index, tg->attrib[attr].max_index); } - /* clamp to void going out of bounds */ - index = MIN2(index, tg->attrib[attr].max_index); - src = tg->attrib[attr].input_ptr + tg->attrib[attr].input_stride * index; diff --git a/src/gallium/auxiliary/translate/translate_sse.c b/src/gallium/auxiliary/translate/translate_sse.c index ef7f4be4c3e..c3d15661f05 100644 --- a/src/gallium/auxiliary/translate/translate_sse.c +++ b/src/gallium/auxiliary/translate/translate_sse.c @@ -53,7 +53,7 @@ struct translate_buffer { unsigned max_index; }; -struct translate_buffer_varient { +struct translate_buffer_variant { unsigned buffer_index; unsigned instance_divisor; void *ptr; /* updated either per vertex or per instance */ @@ -103,12 +103,12 @@ struct translate_sse { struct translate_buffer buffer[PIPE_MAX_ATTRIBS]; unsigned nr_buffers; - /* Multiple buffer varients can map to a single buffer. */ - struct translate_buffer_varient buffer_varient[PIPE_MAX_ATTRIBS]; - unsigned nr_buffer_varients; + /* Multiple buffer variants can map to a single buffer. */ + struct translate_buffer_variant buffer_variant[PIPE_MAX_ATTRIBS]; + unsigned nr_buffer_variants; - /* Multiple elements can map to a single buffer varient. */ - unsigned element_to_buffer_varient[PIPE_MAX_ATTRIBS]; + /* Multiple elements can map to a single buffer variant. */ + unsigned element_to_buffer_variant[PIPE_MAX_ATTRIBS]; boolean use_instancing; unsigned instance_id; @@ -1062,15 +1062,17 @@ static boolean init_inputs( struct translate_sse *p, struct x86_reg instance_id = x86_make_disp(p->machine_EDI, get_offset(p, &p->instance_id)); - for (i = 0; i < p->nr_buffer_varients; i++) { - struct translate_buffer_varient *varient = &p->buffer_varient[i]; - struct translate_buffer *buffer = &p->buffer[varient->buffer_index]; + for (i = 0; i < p->nr_buffer_variants; i++) { + struct translate_buffer_variant *variant = &p->buffer_variant[i]; + struct translate_buffer *buffer = &p->buffer[variant->buffer_index]; - if (!index_size || varient->instance_divisor) { + if (!index_size || variant->instance_divisor) { + struct x86_reg buf_max_index = x86_make_disp(p->machine_EDI, + get_offset(p, &buffer->max_index)); struct x86_reg buf_stride = x86_make_disp(p->machine_EDI, get_offset(p, &buffer->stride)); struct x86_reg buf_ptr = x86_make_disp(p->machine_EDI, - get_offset(p, &varient->ptr)); + get_offset(p, &variant->ptr)); struct x86_reg buf_base_ptr = x86_make_disp(p->machine_EDI, get_offset(p, &buffer->base_ptr)); struct x86_reg elt = p->idx_ESI; @@ -1079,12 +1081,12 @@ static boolean init_inputs( struct translate_sse *p, /* Calculate pointer to first attrib: * base_ptr + stride * index, where index depends on instance divisor */ - if (varient->instance_divisor) { + if (variant->instance_divisor) { /* Our index is instance ID divided by instance divisor. */ x86_mov(p->func, tmp_EAX, instance_id); - if (varient->instance_divisor != 1) { + if (variant->instance_divisor != 1) { struct x86_reg tmp_EDX = p->tmp2_EDX; struct x86_reg tmp_ECX = p->src_ECX; @@ -1093,26 +1095,33 @@ static boolean init_inputs( struct translate_sse *p, */ x86_xor(p->func, tmp_EDX, tmp_EDX); - x86_mov_reg_imm(p->func, tmp_ECX, varient->instance_divisor); + x86_mov_reg_imm(p->func, tmp_ECX, variant->instance_divisor); x86_div(p->func, tmp_ECX); /* EAX = EDX:EAX / ECX */ } + + /* XXX we need to clamp the index here too, but to a + * per-array max value, not the draw->pt.max_index value + * that's being given to us via translate->set_buffer(). + */ } else { x86_mov(p->func, tmp_EAX, elt); - } - /* - * TODO: Respect translate_buffer::max_index. - */ + /* Clamp to max_index + */ + x86_cmp(p->func, tmp_EAX, buf_max_index); + x86_cmovcc(p->func, tmp_EAX, buf_max_index, cc_AE); + } x86_imul(p->func, tmp_EAX, buf_stride); x64_rexw(p->func); x86_add(p->func, tmp_EAX, buf_base_ptr); + x86_cmp(p->func, p->count_EBP, p->tmp_EAX); /* In the linear case, keep the buffer pointer instead of the * index number. */ - if (!index_size && p->nr_buffer_varients == 1) + if (!index_size && p->nr_buffer_variants == 1) { x64_rexw(p->func); x86_mov(p->func, elt, tmp_EAX); @@ -1138,14 +1147,14 @@ static struct x86_reg get_buffer_ptr( struct translate_sse *p, return x86_make_disp(p->machine_EDI, get_offset(p, &p->instance_id)); } - if (!index_size && p->nr_buffer_varients == 1) { + if (!index_size && p->nr_buffer_variants == 1) { return p->idx_ESI; } - else if (!index_size || p->buffer_varient[var_idx].instance_divisor) { + else if (!index_size || p->buffer_variant[var_idx].instance_divisor) { struct x86_reg ptr = p->src_ECX; struct x86_reg buf_ptr = x86_make_disp(p->machine_EDI, - get_offset(p, &p->buffer_varient[var_idx].ptr)); + get_offset(p, &p->buffer_variant[var_idx].ptr)); x64_rexw(p->func); x86_mov(p->func, ptr, buf_ptr); @@ -1153,15 +1162,19 @@ static struct x86_reg get_buffer_ptr( struct translate_sse *p, } else { struct x86_reg ptr = p->src_ECX; - const struct translate_buffer_varient *varient = &p->buffer_varient[var_idx]; + const struct translate_buffer_variant *variant = &p->buffer_variant[var_idx]; struct x86_reg buf_stride = x86_make_disp(p->machine_EDI, - get_offset(p, &p->buffer[varient->buffer_index].stride)); + get_offset(p, &p->buffer[variant->buffer_index].stride)); struct x86_reg buf_base_ptr = x86_make_disp(p->machine_EDI, - get_offset(p, &p->buffer[varient->buffer_index].base_ptr)); + get_offset(p, &p->buffer[variant->buffer_index].base_ptr)); + + struct x86_reg buf_max_index = + x86_make_disp(p->machine_EDI, + get_offset(p, &p->buffer[variant->buffer_index].max_index)); @@ -1179,6 +1192,12 @@ static struct x86_reg get_buffer_ptr( struct translate_sse *p, x86_mov(p->func, ptr, elt); break; } + + /* Clamp to max_index + */ + x86_cmp(p->func, ptr, buf_max_index); + x86_cmovcc(p->func, ptr, buf_max_index, cc_AE); + x86_imul(p->func, ptr, buf_stride); x64_rexw(p->func); x86_add(p->func, ptr, buf_base_ptr); @@ -1191,11 +1210,11 @@ static struct x86_reg get_buffer_ptr( struct translate_sse *p, static boolean incr_inputs( struct translate_sse *p, unsigned index_size ) { - if (!index_size && p->nr_buffer_varients == 1) { + if (!index_size && p->nr_buffer_variants == 1) { struct x86_reg stride = x86_make_disp(p->machine_EDI, get_offset(p, &p->buffer[0].stride)); - if (p->buffer_varient[0].instance_divisor == 0) { + if (p->buffer_variant[0].instance_divisor == 0) { x64_rexw(p->func); x86_add(p->func, p->idx_ESI, stride); sse_prefetchnta(p->func, x86_make_disp(p->idx_ESI, 192)); @@ -1206,14 +1225,14 @@ static boolean incr_inputs( struct translate_sse *p, /* Is this worthwhile?? */ - for (i = 0; i < p->nr_buffer_varients; i++) { - struct translate_buffer_varient *varient = &p->buffer_varient[i]; + for (i = 0; i < p->nr_buffer_variants; i++) { + struct translate_buffer_variant *variant = &p->buffer_variant[i]; struct x86_reg buf_ptr = x86_make_disp(p->machine_EDI, - get_offset(p, &varient->ptr)); + get_offset(p, &variant->ptr)); struct x86_reg buf_stride = x86_make_disp(p->machine_EDI, - get_offset(p, &p->buffer[varient->buffer_index].stride)); + get_offset(p, &p->buffer[variant->buffer_index].stride)); - if (varient->instance_divisor == 0) { + if (variant->instance_divisor == 0) { x86_mov(p->func, p->tmp_EAX, buf_stride); x64_rexw(p->func); x86_add(p->func, p->tmp_EAX, buf_ptr); @@ -1323,18 +1342,18 @@ static boolean build_vertex_emit( struct translate_sse *p, label = x86_get_label(p->func); { struct x86_reg elt = !index_size ? p->idx_ESI : x86_deref(p->idx_ESI); - int last_varient = -1; + int last_variant = -1; struct x86_reg vb; for (j = 0; j < p->translate.key.nr_elements; j++) { const struct translate_element *a = &p->translate.key.element[j]; - unsigned varient = p->element_to_buffer_varient[j]; + unsigned variant = p->element_to_buffer_variant[j]; /* Figure out source pointer address: */ - if (varient != last_varient) { - last_varient = varient; - vb = get_buffer_ptr(p, index_size, varient, elt); + if (variant != last_variant) { + last_variant = variant; + vb = get_buffer_ptr(p, index_size, variant, elt); } if (!translate_attr( p, a, @@ -1460,24 +1479,24 @@ struct translate *translate_sse2_create( const struct translate_key *key ) } /* - * Map vertex element to vertex buffer varient. + * Map vertex element to vertex buffer variant. */ - for (j = 0; j < p->nr_buffer_varients; j++) { - if (p->buffer_varient[j].buffer_index == key->element[i].input_buffer && - p->buffer_varient[j].instance_divisor == key->element[i].instance_divisor) { + for (j = 0; j < p->nr_buffer_variants; j++) { + if (p->buffer_variant[j].buffer_index == key->element[i].input_buffer && + p->buffer_variant[j].instance_divisor == key->element[i].instance_divisor) { break; } } - if (j == p->nr_buffer_varients) { - p->buffer_varient[j].buffer_index = key->element[i].input_buffer; - p->buffer_varient[j].instance_divisor = key->element[i].instance_divisor; - p->nr_buffer_varients++; + if (j == p->nr_buffer_variants) { + p->buffer_variant[j].buffer_index = key->element[i].input_buffer; + p->buffer_variant[j].instance_divisor = key->element[i].instance_divisor; + p->nr_buffer_variants++; } - p->element_to_buffer_varient[i] = j; + p->element_to_buffer_variant[i] = j; } else { assert(key->element[i].type == TRANSLATE_ELEMENT_INSTANCE_ID); - p->element_to_buffer_varient[i] = ELEMENT_BUFFER_INSTANCE_ID; + p->element_to_buffer_variant[i] = ELEMENT_BUFFER_INSTANCE_ID; } } diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c index 32519b148b6..e0c8f73c7d3 100644 --- a/src/gallium/auxiliary/util/u_cpu_detect.c +++ b/src/gallium/auxiliary/util/u_cpu_detect.c @@ -270,13 +270,15 @@ util_cpu_detect(void) util_cpu_caps.x86_cpu_type = 8 + ((regs2[0] >> 20) & 255); /* use extended family (P4, IA64) */ /* general feature flags */ - util_cpu_caps.has_tsc = (regs2[3] & (1 << 8 )) >> 8; /* 0x0000010 */ - util_cpu_caps.has_mmx = (regs2[3] & (1 << 23 )) >> 23; /* 0x0800000 */ - util_cpu_caps.has_sse = (regs2[3] & (1 << 25 )) >> 25; /* 0x2000000 */ - util_cpu_caps.has_sse2 = (regs2[3] & (1 << 26 )) >> 26; /* 0x4000000 */ - util_cpu_caps.has_sse3 = (regs2[2] & (1)); /* 0x0000001 */ - util_cpu_caps.has_ssse3 = (regs2[2] & (1 << 9 )) >> 9; /* 0x0000020 */ - util_cpu_caps.has_sse4_1 = (regs2[2] & (1 << 19)) >> 19; + util_cpu_caps.has_tsc = (regs2[3] >> 8) & 1; /* 0x0000010 */ + util_cpu_caps.has_mmx = (regs2[3] >> 23) & 1; /* 0x0800000 */ + util_cpu_caps.has_sse = (regs2[3] >> 25) & 1; /* 0x2000000 */ + util_cpu_caps.has_sse2 = (regs2[3] >> 26) & 1; /* 0x4000000 */ + util_cpu_caps.has_sse3 = (regs2[2] >> 0) & 1; /* 0x0000001 */ + util_cpu_caps.has_ssse3 = (regs2[2] >> 9) & 1; /* 0x0000020 */ + util_cpu_caps.has_sse4_1 = (regs2[2] >> 19) & 1; + util_cpu_caps.has_sse4_2 = (regs2[2] >> 20) & 1; + util_cpu_caps.has_avx = (regs2[2] >> 28) & 1; util_cpu_caps.has_mmx2 = util_cpu_caps.has_sse; /* SSE cpus supports mmxext too */ cacheline = ((regs2[1] >> 8) & 0xFF) * 8; @@ -290,10 +292,10 @@ util_cpu_detect(void) cpuid(0x80000001, regs2); - util_cpu_caps.has_mmx |= (regs2[3] & (1 << 23 )) >> 23; /* 0x0800000 */ - util_cpu_caps.has_mmx2 |= (regs2[3] & (1 << 22 )) >> 22; /* 0x400000 */ - util_cpu_caps.has_3dnow = (regs2[3] & (1 << 31 )) >> 31; /* 0x80000000 */ - util_cpu_caps.has_3dnow_ext = (regs2[3] & (1 << 30 )) >> 30; + util_cpu_caps.has_mmx |= (regs2[3] >> 23) & 1; + util_cpu_caps.has_mmx2 |= (regs2[3] >> 22) & 1; + util_cpu_caps.has_3dnow = (regs2[3] >> 31) & 1; + util_cpu_caps.has_3dnow_ext = (regs2[3] >> 30) & 1; } if (regs[0] >= 0x80000006) { @@ -329,6 +331,8 @@ util_cpu_detect(void) debug_printf("util_cpu_caps.has_sse3 = %u\n", util_cpu_caps.has_sse3); debug_printf("util_cpu_caps.has_ssse3 = %u\n", util_cpu_caps.has_ssse3); debug_printf("util_cpu_caps.has_sse4_1 = %u\n", util_cpu_caps.has_sse4_1); + debug_printf("util_cpu_caps.has_sse4_2 = %u\n", util_cpu_caps.has_sse4_2); + debug_printf("util_cpu_caps.has_avx = %u\n", util_cpu_caps.has_avx); debug_printf("util_cpu_caps.has_3dnow = %u\n", util_cpu_caps.has_3dnow); debug_printf("util_cpu_caps.has_3dnow_ext = %u\n", util_cpu_caps.has_3dnow_ext); debug_printf("util_cpu_caps.has_altivec = %u\n", util_cpu_caps.has_altivec); diff --git a/src/gallium/auxiliary/util/u_cpu_detect.h b/src/gallium/auxiliary/util/u_cpu_detect.h index f3bef0993c7..856e8d7a0ef 100644 --- a/src/gallium/auxiliary/util/u_cpu_detect.h +++ b/src/gallium/auxiliary/util/u_cpu_detect.h @@ -53,6 +53,8 @@ struct util_cpu_caps { unsigned has_sse3:1; unsigned has_ssse3:1; unsigned has_sse4_1:1; + unsigned has_sse4_2:1; + unsigned has_avx:1; unsigned has_3dnow:1; unsigned has_3dnow_ext:1; unsigned has_altivec:1; diff --git a/src/gallium/auxiliary/util/u_double_list.h b/src/gallium/auxiliary/util/u_double_list.h index 42adb1f0699..2384c36cb13 100644 --- a/src/gallium/auxiliary/util/u_double_list.h +++ b/src/gallium/auxiliary/util/u_double_list.h @@ -39,6 +39,7 @@ #include <stddef.h> +#include "pipe/p_compiler.h" struct list_head @@ -47,50 +48,56 @@ struct list_head struct list_head *next; }; +static INLINE void list_inithead(struct list_head *item) +{ + item->prev = item; + item->next = item; +} + +static INLINE void list_add(struct list_head *item, struct list_head *list) +{ + item->prev = list; + item->next = list->next; + list->next->prev = item; + list->next = item; +} + +static INLINE void list_addtail(struct list_head *item, struct list_head *list) +{ + item->next = list; + item->prev = list->prev; + list->prev->next = item; + list->prev = item; +} + +static INLINE void list_replace(struct list_head *from, struct list_head *to) +{ + to->prev = from->prev; + to->next = from->next; + from->next->prev = to; + from->prev->next = to; +} + +static INLINE void list_del(struct list_head *item) +{ + item->prev->next = item->next; + item->next->prev = item->prev; +} -#define LIST_INITHEAD(__item) \ - do { \ - (__item)->prev = (__item); \ - (__item)->next = (__item); \ - } while (0) - -#define LIST_ADD(__item, __list) \ - do { \ - (__item)->prev = (__list); \ - (__item)->next = (__list)->next; \ - (__list)->next->prev = (__item); \ - (__list)->next = (__item); \ - } while (0) - -#define LIST_ADDTAIL(__item, __list) \ - do { \ - (__item)->next = (__list); \ - (__item)->prev = (__list)->prev; \ - (__list)->prev->next = (__item); \ - (__list)->prev = (__item); \ - } while(0) - -#define LIST_REPLACE(__from, __to) \ - do { \ - (__to)->prev = (__from)->prev; \ - (__to)->next = (__from)->next; \ - (__from)->next->prev = (__to); \ - (__from)->prev->next = (__to); \ - } while (0) - -#define LIST_DEL(__item) \ - do { \ - (__item)->prev->next = (__item)->next; \ - (__item)->next->prev = (__item)->prev; \ - } while(0) - -#define LIST_DELINIT(__item) \ - do { \ - (__item)->prev->next = (__item)->next; \ - (__item)->next->prev = (__item)->prev; \ - (__item)->next = (__item); \ - (__item)->prev = (__item); \ - } while(0) +static INLINE void list_delinit(struct list_head *item) +{ + item->prev->next = item->next; + item->next->prev = item->prev; + item->next = item; + item->prev = item; +} + +#define LIST_INITHEAD(__item) list_inithead(__item) +#define LIST_ADD(__item, __list) list_add(__item, __list) +#define LIST_ADDTAIL(__item, __list) list_addtail(__item, __list) +#define LIST_REPLACE(__from, __to) list_replace(__from, __to) +#define LIST_DEL(__item) list_del(__item) +#define LIST_DELINIT(__item) list_delinit(__item) #define LIST_ENTRY(__type, __item, __field) \ ((__type *)(((char *)(__item)) - offsetof(__type, __field))) @@ -114,4 +121,21 @@ struct list_head storage = container_of(pos->member.next, pos, member); \ &pos->member != (head); \ pos = storage, storage = container_of(storage->member.next, storage, member)) + +#define LIST_FOR_EACH_ENTRY_SAFE_REV(pos, storage, head, member) \ + for (pos = container_of((head)->prev, pos, member), \ + storage = container_of(pos->member.prev, pos, member); \ + &pos->member != (head); \ + pos = storage, storage = container_of(storage->member.prev, storage, member)) + +#define LIST_FOR_EACH_ENTRY_FROM(pos, start, head, member) \ + for (pos = container_of((start), pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.next, pos, member)) + +#define LIST_FOR_EACH_ENTRY_FROM_REV(pos, start, head, member) \ + for (pos = container_of((start), pos, member); \ + &pos->member != (head); \ + pos = container_of(pos->member.prev, pos, member)) + #endif /*_U_DOUBLE_LIST_H_*/ diff --git a/src/gallium/auxiliary/util/u_draw.c b/src/gallium/auxiliary/util/u_draw.c new file mode 100644 index 00000000000..20837be5e59 --- /dev/null +++ b/src/gallium/auxiliary/util/u_draw.c @@ -0,0 +1,99 @@ +/************************************************************************** + * + * Copyright 2011 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.h" +#include "util/u_math.h" +#include "util/u_format.h" +#include "util/u_draw.h" + + +/** + * Returns the largest legal index value for the current set of bound vertex + * buffers. Regardless of any other consideration, all vertex lookups need to + * be clamped to 0..max_index to prevent an out-of-bound access. + */ +unsigned +util_draw_max_index( + const struct pipe_vertex_buffer *vertex_buffers, + unsigned nr_vertex_buffers, + const struct pipe_vertex_element *vertex_elements, + unsigned nr_vertex_elements, + const struct pipe_draw_info *info) +{ + unsigned max_index; + unsigned i; + + max_index = ~0; + for (i = 0; i < nr_vertex_elements; i++) { + const struct pipe_vertex_element *element = + &vertex_elements[i]; + const struct pipe_vertex_buffer *buffer = + &vertex_buffers[element->vertex_buffer_index]; + unsigned buffer_size; + const struct util_format_description *format_desc; + unsigned format_size; + + assert(buffer->buffer->height0 == 1); + assert(buffer->buffer->depth0 == 1); + buffer_size = buffer->buffer->width0; + + format_desc = util_format_description(element->src_format); + assert(format_desc->block.width == 1); + assert(format_desc->block.height == 1); + assert(format_desc->block.bits % 8 == 0); + format_size = format_desc->block.bits/8; + + assert(buffer_size - buffer->buffer_offset <= buffer_size); + buffer_size -= buffer->buffer_offset; + + assert(buffer_size - element->src_offset <= buffer_size); + buffer_size -= element->src_offset; + + assert(buffer_size - format_size <= buffer_size); + buffer_size -= format_size; + + if (buffer->stride != 0) { + unsigned buffer_max_index; + + buffer_max_index = buffer_size / buffer->stride; + + if (element->instance_divisor == 0) { + /* Per-vertex data */ + max_index = MIN2(max_index, buffer_max_index); + } + else { + /* Per-instance data. Simply make sure the state tracker didn't + * request more instances than those that fit in the buffer */ + assert((info->start_instance + info->instance_count)/element->instance_divisor + <= (buffer_max_index + 1)); + } + } + } + + return max_index; +} diff --git a/src/gallium/auxiliary/util/u_draw.h b/src/gallium/auxiliary/util/u_draw.h index f06d09ef91d..fdb683ca8a2 100644 --- a/src/gallium/auxiliary/util/u_draw.h +++ b/src/gallium/auxiliary/util/u_draw.h @@ -34,6 +34,11 @@ #include "pipe/p_state.h" +#ifdef __cplusplus +extern "C" { +#endif + + static INLINE void util_draw_init_info(struct pipe_draw_info *info) { @@ -136,4 +141,18 @@ util_draw_range_elements(struct pipe_context *pipe, pipe->draw_vbo(pipe, &info); } + +unsigned +util_draw_max_index( + const struct pipe_vertex_buffer *vertex_buffers, + unsigned nr_vertex_buffers, + const struct pipe_vertex_element *vertex_elements, + unsigned nr_vertex_elements, + const struct pipe_draw_info *info); + + +#ifdef __cplusplus +} #endif + +#endif /* !U_DRAW_H */ diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c index 4896faa12bf..9cbdd0a5b99 100644 --- a/src/gallium/auxiliary/util/u_format.c +++ b/src/gallium/auxiliary/util/u_format.c @@ -36,6 +36,55 @@ #include "u_memory.h" #include "u_rect.h" #include "u_format.h" +#include "u_format_s3tc.h" + +#include "pipe/p_defines.h" + + +boolean +util_format_is_float(enum pipe_format format) +{ + const struct util_format_description *desc = util_format_description(format); + unsigned i; + + assert(desc); + if (!desc) { + return FALSE; + } + + /* Find the first non-void channel. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + + if (i == 4) { + return FALSE; + } + + return desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT ? TRUE : FALSE; +} + + +boolean +util_format_is_supported(enum pipe_format format, unsigned bind) +{ + if (util_format_is_s3tc(format) && !util_format_s3tc_enabled) { + return FALSE; + } + +#ifndef TEXTURE_FLOAT_ENABLED + if ((bind & PIPE_BIND_RENDER_TARGET) && + format != PIPE_FORMAT_R9G9B9E5_FLOAT && + format != PIPE_FORMAT_R11G11B10_FLOAT && + util_format_is_float(format)) { + return FALSE; + } +#endif + + return TRUE; +} void diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv index 22c63ae162a..e4b3f5df6ee 100644 --- a/src/gallium/auxiliary/util/u_format.csv +++ b/src/gallium/auxiliary/util/u_format.csv @@ -88,6 +88,22 @@ PIPE_FORMAT_L16_UNORM , plain, 1, 1, un16, , , , xxx1, r PIPE_FORMAT_A16_UNORM , plain, 1, 1, un16, , , , 000x, rgb PIPE_FORMAT_I16_UNORM , plain, 1, 1, un16, , , , xxxx, rgb PIPE_FORMAT_L16A16_UNORM , plain, 1, 1, un16, un16, , , xxxy, rgb +PIPE_FORMAT_A8_SNORM , plain, 1, 1, sn8 , , , , 000x, rgb +PIPE_FORMAT_L8_SNORM , plain, 1, 1, sn8 , , , , xxx1, rgb +PIPE_FORMAT_L8A8_SNORM , plain, 1, 1, sn8 , sn8 , , , xxxy, rgb +PIPE_FORMAT_I8_SNORM , plain, 1, 1, sn8 , , , , xxxx, rgb +PIPE_FORMAT_A16_SNORM , plain, 1, 1, sn16, , , , 000x, rgb +PIPE_FORMAT_L16_SNORM , plain, 1, 1, sn16, , , , xxx1, rgb +PIPE_FORMAT_L16A16_SNORM , plain, 1, 1, sn16, sn16, , , xxxy, rgb +PIPE_FORMAT_I16_SNORM , plain, 1, 1, sn16, , , , xxxx, rgb +PIPE_FORMAT_A16_FLOAT , plain, 1, 1, f16 , , , , 000x, rgb +PIPE_FORMAT_L16_FLOAT , plain, 1, 1, f16 , , , , xxx1, rgb +PIPE_FORMAT_L16A16_FLOAT , plain, 1, 1, f16 , f16 , , , xxxy, rgb +PIPE_FORMAT_I16_FLOAT , plain, 1, 1, f16 , , , , xxxx, rgb +PIPE_FORMAT_A32_FLOAT , plain, 1, 1, f32 , , , , 000x, rgb +PIPE_FORMAT_L32_FLOAT , plain, 1, 1, f32 , , , , xxx1, rgb +PIPE_FORMAT_L32A32_FLOAT , plain, 1, 1, f32 , f32 , , , xxxy, rgb +PIPE_FORMAT_I32_FLOAT , plain, 1, 1, f32 , , , , xxxx, rgb # SRGB formats PIPE_FORMAT_L8_SRGB , plain, 1, 1, un8 , , , , xxx1, srgb diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 7659a802a41..bb3ed72e932 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -473,6 +473,10 @@ util_format_colormask(const struct util_format_description *desc) } +boolean +util_format_is_float(enum pipe_format format); + + /** * Whether the src format can be blitted to destation format with a simple * memcpy. @@ -481,6 +485,12 @@ boolean util_is_format_compatible(const struct util_format_description *src_desc, const struct util_format_description *dst_desc); +/** + * Whether the format is supported by Gallium for the given bindings. + * This covers S3TC textures and floating-point render targets. + */ +boolean +util_format_is_supported(enum pipe_format format, unsigned bind); /** * Whether this format is a rgab8 variant. diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index 9caf76c802b..4c5cc4da182 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -157,6 +157,9 @@ util_resource_copy_region(struct pipe_context *pipe, unsigned h = src_box->height; assert(src && dst); + assert((src->target == PIPE_BUFFER && dst->target == PIPE_BUFFER) || + (src->target != PIPE_BUFFER && dst->target != PIPE_BUFFER)); + if (!src || !dst) return; @@ -188,15 +191,19 @@ util_resource_copy_region(struct pipe_context *pipe, assert(dst_map); if (src_map && dst_map) { - util_copy_rect(dst_map, - dst_format, - dst_trans->stride, - 0, 0, - w, h, - src_map, - src_trans->stride, - 0, - 0); + if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { + memcpy(dst_map, src_map, w); + } else { + util_copy_rect(dst_map, + dst_format, + dst_trans->stride, + 0, 0, + w, h, + src_map, + src_trans->stride, + 0, + 0); + } } pipe->transfer_unmap(pipe, src_trans); diff --git a/src/gallium/auxiliary/util/u_vbuf_mgr.c b/src/gallium/auxiliary/util/u_vbuf_mgr.c index 521ac07747c..dea2928f950 100644 --- a/src/gallium/auxiliary/util/u_vbuf_mgr.c +++ b/src/gallium/auxiliary/util/u_vbuf_mgr.c @@ -499,7 +499,7 @@ void u_vbuf_mgr_set_vertex_buffers(struct u_vbuf_mgr *mgrb, /* Update the maximum index. */ mgr->b.max_index = MIN2(mgr->b.max_index, - (vb->buffer->width0 - vb->buffer_offset) / vb->stride); + (vb->buffer->width0 - vb->buffer_offset) / vb->stride - 1); } for (; i < mgr->b.nr_real_vertex_buffers; i++) { @@ -572,7 +572,11 @@ void u_vbuf_mgr_draw_begin(struct u_vbuf_mgr *mgrb, int min_index, max_index; min_index = info->min_index - info->index_bias; - max_index = info->max_index - info->index_bias; + if (info->max_index == ~0) { + max_index = mgr->b.max_index; + } else { + max_index = MIN2(info->max_index - info->index_bias, mgr->b.max_index); + } /* Translate vertices with non-native layouts or formats. */ if (mgr->incompatible_vb_layout || mgr->ve->incompatible_layout) { diff --git a/src/gallium/auxiliary/util/u_vbuf_mgr.h b/src/gallium/auxiliary/util/u_vbuf_mgr.h index 8b241854c83..9380dce4f72 100644 --- a/src/gallium/auxiliary/util/u_vbuf_mgr.h +++ b/src/gallium/auxiliary/util/u_vbuf_mgr.h @@ -53,7 +53,7 @@ struct u_vbuf_mgr { int nr_real_vertex_buffers; /* Precomputed max_index for hardware vertex buffers. */ - int max_index; + unsigned max_index; /* This uploader can optionally be used by the driver. * diff --git a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c index 16b204df676..5027db4314e 100644 --- a/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c +++ b/src/gallium/auxiliary/vl/vl_mpeg12_decoder.c @@ -655,7 +655,7 @@ init_zscan(struct vl_mpeg12_decoder *dec) static bool init_idct(struct vl_mpeg12_decoder *dec) { - struct pipe_sampler_view *matrix, *transpose; + struct pipe_sampler_view *matrix, *transpose = NULL; float matrix_scale, transpose_scale; dec->nr_of_idct_render_targets = dec->pipe->screen->get_param(dec->pipe->screen, PIPE_CAP_MAX_RENDER_TARGETS); diff --git a/src/gallium/docs/source/context.rst b/src/gallium/docs/source/context.rst index b0229c70f20..25a3245066c 100644 --- a/src/gallium/docs/source/context.rst +++ b/src/gallium/docs/source/context.rst @@ -179,16 +179,25 @@ the mode of the primitive and the vertices to be fetched, in the range between Every instance with instanceID in the range between ``start_instance`` and ``start_instance``+``instance_count``-1, inclusive, will be drawn. -All vertex indices must fall inside the range given by ``min_index`` and -``max_index``. In case non-indexed draw, ``min_index`` should be set to +If there is an index buffer bound, and ``indexed`` field is true, all vertex +indices will be looked up in the index buffer. + +In indexed draw, ``min_index`` and ``max_index`` respectively provide a lower +and upper bound of the indices contained in the index buffer inside the range +between ``start`` to ``start``+``count``-1. This allows the driver to +determine which subset of vertices will be referenced during te draw call +without having to scan the index buffer. Providing a over-estimation of the +the true bounds, for example, a ``min_index`` and ``max_index`` of 0 and +0xffffffff respectively, must give exactly the same rendering, albeit with less +performance due to unreferenced vertex buffers being unnecessarily DMA'ed or +processed. Providing a underestimation of the true bounds will result in +undefined behavior, but should not result in program or system failure. + +In case of non-indexed draw, ``min_index`` should be set to ``start`` and ``max_index`` should be set to ``start``+``count``-1. -``index_bias`` is a value added to every vertex index before fetching vertex -attributes. It does not affect ``min_index`` and ``max_index``. - -If there is an index buffer bound, and ``indexed`` field is true, all vertex -indices will be looked up in the index buffer. ``min_index``, ``max_index``, -and ``index_bias`` apply after index lookup. +``index_bias`` is a value added to every vertex index after lookup and before +fetching vertex attributes. When drawing indexed primitives, the primitive restart index can be used to draw disjoint primitive strips. For example, several separate diff --git a/src/gallium/docs/source/cso/rasterizer.rst b/src/gallium/docs/source/cso/rasterizer.rst index d547055096f..e10c16ed900 100644 --- a/src/gallium/docs/source/cso/rasterizer.rst +++ b/src/gallium/docs/source/cso/rasterizer.rst @@ -7,6 +7,30 @@ The rasterizer state controls the rendering of points, lines and triangles. Attributes include polygon culling state, line width, line stipple, multisample state, scissoring and flat/smooth shading. +Linkage + +clamp_vertex_color +^^^^^^^^^^^^^^^^^^ + +If set, TGSI_SEMANTIC_COLOR registers are clamped to the [0, 1] range after +the execution of the vertex shader, before being passed to the geometry +shader or fragment shader. + +OpenGL: glClampColor(GL_CLAMP_VERTEX_COLOR) in GL 3.0 or GL_ARB_color_buffer_float + +D3D11: seems always disabled + +clamp_fragment_color +^^^^^^^^^^^^^^^^^^^^ + +Controls whether TGSI_SEMANTIC_COLOR outputs of the fragment shader +are clamped to [0, 1]. + +OpenGL: glClampColor(GL_CLAMP_FRAGMENT_COLOR) in GL 3.0 or ARB_color_buffer_float + +D3D11: seems always disabled + + Shading ------- diff --git a/src/gallium/drivers/galahad/glhd_context.c b/src/gallium/drivers/galahad/glhd_context.c index 813a21e2ee3..f73d8a5d32e 100644 --- a/src/gallium/drivers/galahad/glhd_context.c +++ b/src/gallium/drivers/galahad/glhd_context.c @@ -685,6 +685,12 @@ galahad_resource_copy_region(struct pipe_context *_pipe, util_format_short_name(_dst->format)); } + if ((_src->target == PIPE_BUFFER && _dst->target != PIPE_BUFFER) || + (_src->target != PIPE_BUFFER && _dst->target == PIPE_BUFFER)) { + glhd_warn("Resource target mismatch: Source is %i, destination is %i", + _src->target, _dst->target); + } + pipe->resource_copy_region(pipe, dst, dst_level, diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c index e62b609eb5a..0f4327fdc81 100644 --- a/src/gallium/drivers/i915/i915_screen.c +++ b/src/gallium/drivers/i915/i915_screen.c @@ -27,6 +27,7 @@ #include "draw/draw_context.h" +#include "util/u_format.h" #include "util/u_inlines.h" #include "util/u_memory.h" #include "util/u_string.h" @@ -285,6 +286,9 @@ i915_is_format_supported(struct pipe_screen *screen, const enum pipe_format *list; uint i; + if (!util_format_is_supported(format, tex_usage)) + return FALSE; + if (sample_count > 1) return FALSE; diff --git a/src/gallium/drivers/i915/i915_surface.c b/src/gallium/drivers/i915/i915_surface.c index d02c420f6c2..ac6e94500c8 100644 --- a/src/gallium/drivers/i915/i915_surface.c +++ b/src/gallium/drivers/i915/i915_surface.c @@ -37,6 +37,7 @@ #include "util/u_format.h" #include "util/u_memory.h" #include "util/u_pack_color.h" +#include "util/u_surface.h" /* * surface functions using the render engine @@ -51,6 +52,13 @@ i915_surface_copy_render(struct pipe_context *pipe, { struct i915_context *i915 = i915_context(pipe); + /* Fallback for buffers. */ + if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { + util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + return; + } + util_blitter_save_blend(i915->blitter, (void *)i915->blend); util_blitter_save_depth_stencil_alpha(i915->blitter, (void *)i915->depth_stencil); util_blitter_save_stencil_ref(i915->blitter, &i915->stencil_ref); @@ -158,6 +166,13 @@ i915_surface_copy_blitter(struct pipe_context *pipe, struct pipe_resource *spt = &src_tex->b.b; unsigned dst_offset, src_offset; /* in bytes */ + /* Fallback for buffers. */ + if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { + util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + return; + } + /* XXX cannot copy 3d regions at this time */ assert(src_box->depth == 1); if (dst->target != PIPE_TEXTURE_CUBE && diff --git a/src/gallium/drivers/i965/brw_screen.c b/src/gallium/drivers/i965/brw_screen.c index 25204fd088d..9178dfa8f69 100644 --- a/src/gallium/drivers/i965/brw_screen.c +++ b/src/gallium/drivers/i965/brw_screen.c @@ -26,6 +26,7 @@ **************************************************************************/ +#include "util/u_format.h" #include "util/u_inlines.h" #include "util/u_memory.h" #include "util/u_string.h" @@ -333,6 +334,9 @@ brw_is_format_supported(struct pipe_screen *screen, const enum pipe_format *list; uint i; + if (!util_format_is_supported(format, tex_usage)) + return FALSE; + if (sample_count > 1) return FALSE; diff --git a/src/gallium/drivers/llvmpipe/README b/src/gallium/drivers/llvmpipe/README deleted file mode 100644 index 1fc7746a834..00000000000 --- a/src/gallium/drivers/llvmpipe/README +++ /dev/null @@ -1,134 +0,0 @@ -LLVMPIPE -- a fork of softpipe that employs LLVM for code generation. - - -Requirements -============ - - - A x86 or amd64 processor. 64bit mode is preferred. - - Support for sse2 is strongly encouraged. Support for ssse3, and sse4.1 will - yield the most efficient code. The less features the CPU has the more - likely is that you ran into underperforming, buggy, or incomplete code. - - See /proc/cpuinfo to know what your CPU supports. - - - LLVM. Version 2.8 recommended. 2.6 or later required. - - For Linux, on a recent Debian based distribution do: - - aptitude install llvm-dev - - For Windows download pre-built MSVC 9.0 or MinGW binaries from - http://people.freedesktop.org/~jrfonseca/llvm/ and set the LLVM environment - variable to the extracted path. - - For MSVC there are two set of binaries: llvm-x.x-msvc32mt.7z and - llvm-x.x-msvc32mtd.7z . - - You have to set the LLVM=/path/to/llvm-x.x-msvc32mtd env var when passing - debug=yes to scons, and LLVM=/path/to/llvm-x.x-msvc32mt when building with - debug=no. This is necessary as LLVM builds as static library so the chosen - MS CRT must match. - - - scons (optional) - - -Building -======== - -To build everything on Linux invoke scons as: - - scons build=debug libgl-xlib - -Alternatively, you can build it with GNU make, if you prefer, by invoking it as - - make linux-llvm - -but the rest of these instructions assume that scons is used. - -For windows is everything the except except the winsys: - - scons build=debug libgl-gdi - -Using -===== - -On Linux, building will create a drop-in alternative for libGL.so into - - build/foo/gallium/targets/libgl-xlib/libGL.so - -To use it set the LD_LIBRARY_PATH environment variable accordingly. - -For performance evaluation pass debug=no to scons, and use the corresponding -lib directory without the "-debug" suffix. - -On Windows, building will create a drop-in alternative for opengl32.dll. To use -it put it in the same directory as the application. It can also be used by -replacing the native ICD driver, but it's quite an advanced usage, so if you -need to ask, don't even try it. - - -Profiling -========= - -To profile llvmpipe you should pass the options - - scons build=profile <same-as-before> - -This will ensure that frame pointers are used both in C and JIT functions, and -that no tail call optimizations are done by gcc. - - -To better profile JIT code you'll need to build LLVM with oprofile integration. - - ./configure \ - --prefix=$install_dir \ - --enable-optimized \ - --disable-profiling \ - --enable-targets=host-only \ - --with-oprofile - - make -C "$build_dir" - make -C "$build_dir" install - - find "$install_dir/lib" -iname '*.a' -print0 | xargs -0 strip --strip-debug - -The you should define - - export LLVM=/path/to/llvm-2.6-profile - -and rebuild. - - -Unit testing -============ - -Building will also create several unit tests in -build/linux-???-debug/gallium/drivers/llvmpipe: - - - lp_test_blend: blending - - lp_test_conv: SIMD vector conversion - - lp_test_format: pixel unpacking/packing - -Some of this tests can output results and benchmarks to a tab-separated-file -for posterior analysis, e.g.: - - build/linux-x86_64-debug/gallium/drivers/llvmpipe/lp_test_blend -o blend.tsv - - -Development Notes -================= - -- When looking to this code by the first time start in lp_state_fs.c, and - then skim through the lp_bld_* functions called in there, and the comments - at the top of the lp_bld_*.c functions. - -- The driver-independent parts of the LLVM / Gallium code are found in - src/gallium/auxiliary/gallivm/. The filenames and function prefixes - need to be renamed from "lp_bld_" to something else though. - -- We use LLVM-C bindings for now. They are not documented, but follow the C++ - interfaces very closely, and appear to be complete enough for code - generation. See - http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html - for a stand-alone example. See the llvm-c/Core.h file for reference. diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index 482a902dd23..268f0fa034b 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -54,6 +54,7 @@ lp_jit_create_types(struct llvmpipe_context *lp) elem_types[LP_JIT_TEXTURE_WIDTH] = elem_types[LP_JIT_TEXTURE_HEIGHT] = elem_types[LP_JIT_TEXTURE_DEPTH] = + elem_types[LP_JIT_TEXTURE_FIRST_LEVEL] = elem_types[LP_JIT_TEXTURE_LAST_LEVEL] = LLVMInt32TypeInContext(lc); elem_types[LP_JIT_TEXTURE_ROW_STRIDE] = elem_types[LP_JIT_TEXTURE_IMG_STRIDE] = @@ -81,6 +82,9 @@ lp_jit_create_types(struct llvmpipe_context *lp) LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, depth, gallivm->target, texture_type, LP_JIT_TEXTURE_DEPTH); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, first_level, + gallivm->target, texture_type, + LP_JIT_TEXTURE_FIRST_LEVEL); LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, last_level, gallivm->target, texture_type, LP_JIT_TEXTURE_LAST_LEVEL); diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index a6763dce17a..04e8dd5267b 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -50,6 +50,7 @@ struct lp_jit_texture uint32_t width; uint32_t height; uint32_t depth; + uint32_t first_level; uint32_t last_level; uint32_t row_stride[LP_MAX_TEXTURE_LEVELS]; uint32_t img_stride[LP_MAX_TEXTURE_LEVELS]; @@ -66,6 +67,7 @@ enum { LP_JIT_TEXTURE_WIDTH = 0, LP_JIT_TEXTURE_HEIGHT, LP_JIT_TEXTURE_DEPTH, + LP_JIT_TEXTURE_FIRST_LEVEL, LP_JIT_TEXTURE_LAST_LEVEL, LP_JIT_TEXTURE_ROW_STRIDE, LP_JIT_TEXTURE_IMG_STRIDE, diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index 521a52ad3ae..036a6e0c379 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -166,6 +166,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum pipe_cap param) return 0; case PIPE_CAP_TGSI_INSTANCEID: case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: + case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: return 1; default: return 0; diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index 3813e0ed972..c82ab821c7e 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -653,6 +653,7 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, jit_tex->width = tex->width0; jit_tex->height = tex->height0; jit_tex->depth = tex->depth0; + jit_tex->first_level = view->u.tex.first_level; jit_tex->last_level = tex->last_level; /* We're referencing the texture's internal data, so save a @@ -663,7 +664,7 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, if (!lp_tex->dt) { /* regular texture - setup array of mipmap level pointers */ int j; - for (j = 0; j <= tex->last_level; j++) { + for (j = view->u.tex.first_level; j <= tex->last_level; j++) { jit_tex->data[j] = llvmpipe_get_texture_image_all(lp_tex, j, LP_TEX_USAGE_READ, LP_TEX_LAYOUT_LINEAR); @@ -677,6 +678,7 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup, jit_tex->width = TILE_SIZE/8; jit_tex->height = TILE_SIZE/8; jit_tex->depth = 1; + jit_tex->first_level = 0; jit_tex->last_level = 0; jit_tex->row_stride[j] = 0; jit_tex->img_stride[j] = 0; diff --git a/src/gallium/drivers/llvmpipe/lp_state_sampler.c b/src/gallium/drivers/llvmpipe/lp_state_sampler.c index 1dd866195d3..df9fb89cc8e 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_sampler.c +++ b/src/gallium/drivers/llvmpipe/lp_state_sampler.c @@ -269,7 +269,7 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp, if (!lp_tex->dt) { /* regular texture - setup array of mipmap level pointers */ int j; - for (j = 0; j <= tex->last_level; j++) { + for (j = view->u.tex.first_level; j <= tex->last_level; j++) { data[j] = llvmpipe_get_texture_image_all(lp_tex, j, LP_TEX_USAGE_READ, LP_TEX_LAYOUT_LINEAR); @@ -293,7 +293,7 @@ llvmpipe_prepare_vertex_sampling(struct llvmpipe_context *lp, draw_set_mapped_texture(lp->draw, i, tex->width0, tex->height0, tex->depth0, - tex->last_level, + view->u.tex.first_level, tex->last_level, row_stride, img_stride, data); } } diff --git a/src/gallium/drivers/llvmpipe/lp_surface.c b/src/gallium/drivers/llvmpipe/lp_surface.c index f49638acf08..1b5e9d055f5 100644 --- a/src/gallium/drivers/llvmpipe/lp_surface.c +++ b/src/gallium/drivers/llvmpipe/lp_surface.c @@ -67,6 +67,13 @@ lp_resource_copy(struct pipe_context *pipe, unsigned height = src_box->height; assert(src_box->depth == 1); + /* Fallback for buffers. */ + if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { + util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + return; + } + llvmpipe_flush_resource(pipe, dst, dst_level, dstz, FALSE, /* read_only */ diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample.c b/src/gallium/drivers/llvmpipe/lp_tex_sample.c index ed4282937f8..ccc139603ee 100644 --- a/src/gallium/drivers/llvmpipe/lp_tex_sample.c +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample.c @@ -149,6 +149,7 @@ lp_llvm_texture_member(const struct lp_sampler_dynamic_state *base, LP_LLVM_TEXTURE_MEMBER(width, LP_JIT_TEXTURE_WIDTH, TRUE) LP_LLVM_TEXTURE_MEMBER(height, LP_JIT_TEXTURE_HEIGHT, TRUE) LP_LLVM_TEXTURE_MEMBER(depth, LP_JIT_TEXTURE_DEPTH, TRUE) +LP_LLVM_TEXTURE_MEMBER(first_level, LP_JIT_TEXTURE_FIRST_LEVEL, TRUE) LP_LLVM_TEXTURE_MEMBER(last_level, LP_JIT_TEXTURE_LAST_LEVEL, TRUE) LP_LLVM_TEXTURE_MEMBER(row_stride, LP_JIT_TEXTURE_ROW_STRIDE, FALSE) LP_LLVM_TEXTURE_MEMBER(img_stride, LP_JIT_TEXTURE_IMG_STRIDE, FALSE) @@ -219,6 +220,7 @@ lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state, sampler->dynamic_state.base.width = lp_llvm_texture_width; sampler->dynamic_state.base.height = lp_llvm_texture_height; sampler->dynamic_state.base.depth = lp_llvm_texture_depth; + sampler->dynamic_state.base.first_level = lp_llvm_texture_first_level; sampler->dynamic_state.base.last_level = lp_llvm_texture_last_level; sampler->dynamic_state.base.row_stride = lp_llvm_texture_row_stride; sampler->dynamic_state.base.img_stride = lp_llvm_texture_img_stride; diff --git a/src/gallium/drivers/noop/noop_pipe.c b/src/gallium/drivers/noop/noop_pipe.c index 496b7f5ec6d..18308b796f3 100644 --- a/src/gallium/drivers/noop/noop_pipe.c +++ b/src/gallium/drivers/noop/noop_pipe.c @@ -337,6 +337,7 @@ static int noop_get_param(struct pipe_screen* pscreen, enum pipe_cap param) case PIPE_CAP_TEXTURE_SHADOW_MAP: case PIPE_CAP_TEXTURE_SWIZZLE: case PIPE_CAP_BLEND_EQUATION_SEPARATE: + case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: return 1; case PIPE_CAP_DUAL_SOURCE_BLEND: diff --git a/src/gallium/drivers/nv50/nv50_3d.xml.h b/src/gallium/drivers/nv50/nv50_3d.xml.h index 9bb3211728c..41a380ec2ec 100644 --- a/src/gallium/drivers/nv50/nv50_3d.xml.h +++ b/src/gallium/drivers/nv50/nv50_3d.xml.h @@ -558,7 +558,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NV50_3D_UNK0F8C 0x00000f8c -#define NV50_3D_UNK0F90 0x00000f90 +#define NV50_3D_COLOR_MASK_COMMON 0x00000f90 #define NV50_3D_UNK0F94 0x00000f94 @@ -1007,7 +1007,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NV50_3D_TEX_CACHE_CTL_UNK1__MASK 0x00000030 #define NV50_3D_TEX_CACHE_CTL_UNK1__SHIFT 4 -#define NV50_3D_UNK133C 0x0000133c +#define NV50_3D_BLEND_SEPARATE_ALPHA 0x0000133c #define NV50_3D_BLEND_EQUATION_RGB 0x00001340 #define NV50_3D_BLEND_EQUATION_RGB_FUNC_ADD 0x00008006 @@ -1033,7 +1033,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NV50_3D_BLEND_FUNC_DST_ALPHA 0x00001358 -#define NV50_3D_UNK135C 0x0000135c +#define NV50_3D_BLEND_ENABLE_COMMON 0x0000135c #define NV50_3D_BLEND_ENABLE(i0) (0x00001360 + 0x4*(i0)) #define NV50_3D_BLEND_ENABLE__ESIZE 0x00000004 @@ -1673,7 +1673,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NV50_3D_MAP_SEMANTIC_0_BFC0_ID__SHIFT 8 #define NV50_3D_MAP_SEMANTIC_0_COLR_NR__MASK 0x00ff0000 #define NV50_3D_MAP_SEMANTIC_0_COLR_NR__SHIFT 16 -#define NV50_3D_MAP_SEMANTIC_0_CLMP_EN 0xff000000 +#define NV50_3D_MAP_SEMANTIC_0_CLMP_EN 0x01000000 #define NV50_3D_MAP_SEMANTIC_1 0x00001908 #define NV50_3D_MAP_SEMANTIC_1_CLIP_START__MASK 0x000000ff @@ -1706,7 +1706,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NV50_3D_CULL_FACE_BACK 0x00000405 #define NV50_3D_CULL_FACE_FRONT_AND_BACK 0x00000408 -#define NV50_3D_UNK1924 0x00001924 +#define NV50_3D_LINE_LAST_PIXEL 0x00001924 #define NVA3_3D_FP_MULTISAMPLE 0x00001928 #define NVA3_3D_FP_MULTISAMPLE_EXPORT_SAMPLE_MASK 0x00000001 diff --git a/src/gallium/drivers/nv50/nv50_context.c b/src/gallium/drivers/nv50/nv50_context.c index 930cee7c1e7..632ca4daf74 100644 --- a/src/gallium/drivers/nv50/nv50_context.c +++ b/src/gallium/drivers/nv50/nv50_context.c @@ -46,6 +46,17 @@ nv50_flush(struct pipe_context *pipe, FIRE_RING(screen->channel); } +static void +nv50_texture_barrier(struct pipe_context *pipe) +{ + struct nouveau_channel *chan = nv50_context(pipe)->screen->base.channel; + + BEGIN_RING(chan, RING_3D(SERIALIZE), 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, RING_3D(TEX_CACHE_CTL), 1); + OUT_RING (chan, 0x20); +} + void nv50_default_flush_notify(struct nouveau_channel *chan) { @@ -125,6 +136,7 @@ nv50_create(struct pipe_screen *pscreen, void *priv) pipe->clear = nv50_clear; pipe->flush = nv50_flush; + pipe->texture_barrier = nv50_texture_barrier; if (!screen->cur_ctx) screen->cur_ctx = nv50; diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h index 46e6c2250af..3f031994f0a 100644 --- a/src/gallium/drivers/nv50/nv50_context.h +++ b/src/gallium/drivers/nv50/nv50_context.h @@ -1,7 +1,6 @@ #ifndef __NV50_CONTEXT_H__ #define __NV50_CONTEXT_H__ -#include <stdio.h> #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_state.h" @@ -13,6 +12,7 @@ #include "draw/draw_vertex.h" +#include "nv50_debug.h" #include "nv50_winsys.h" #include "nv50_stateobj.h" #include "nv50_screen.h" @@ -26,15 +26,6 @@ #include "nv50_3d.xml.h" #include "nv50_2d.xml.h" -#define NOUVEAU_ERR(fmt, args...) \ - fprintf(stderr, "%s:%d - "fmt, __FUNCTION__, __LINE__, ##args); - -#ifdef NOUVEAU_DEBUG -# define NOUVEAU_DBG(args...) printf(args); -#else -# define NOUVEAU_DBG(args...) -#endif - #define NV50_NEW_BLEND (1 << 0) #define NV50_NEW_RASTERIZER (1 << 1) #define NV50_NEW_ZSA (1 << 2) @@ -80,6 +71,8 @@ struct nv50_context { uint32_t instance_elts; /* bitmask of per-instance elements */ uint32_t instance_base; uint32_t interpolant_ctrl; + uint32_t semantic_color; + uint32_t semantic_psize; int32_t index_bias; boolean prim_restart; boolean point_sprite; @@ -183,7 +176,7 @@ void nv50_fragprog_validate(struct nv50_context *); void nv50_fp_linkage_validate(struct nv50_context *); void nv50_gp_linkage_validate(struct nv50_context *); void nv50_constbufs_validate(struct nv50_context *); -void nv50_sprite_coords_validate(struct nv50_context *); +void nv50_validate_derived_rs(struct nv50_context *); /* nv50_state.c */ extern void nv50_init_state_functions(struct nv50_context *); diff --git a/src/gallium/drivers/nv50/nv50_debug.h b/src/gallium/drivers/nv50/nv50_debug.h new file mode 100644 index 00000000000..f3dee621519 --- /dev/null +++ b/src/gallium/drivers/nv50/nv50_debug.h @@ -0,0 +1,25 @@ + +#ifndef __NV50_DEBUG_H__ +#define __NV50_DEBUG_H__ + +#include <stdio.h> + +#include "util/u_debug.h" + +#define NV50_DEBUG_MISC 0x0001 +#define NV50_DEBUG_SHADER 0x0100 +#define NV50_DEBUG_PROG_IR 0x0200 +#define NV50_DEBUG_PROG_RA 0x0400 +#define NV50_DEBUG_PROG_CFLOW 0x0800 +#define NV50_DEBUG_PROG_ALL 0x1f00 + +#define NV50_DEBUG 0 + +#define NOUVEAU_ERR(fmt, args...) \ + fprintf(stderr, "%s:%d - "fmt, __FUNCTION__, __LINE__, ##args) + +#define NV50_DBGMSG(ch, args...) \ + if ((NV50_DEBUG) & (NV50_DEBUG_##ch)) \ + debug_printf(args) + +#endif /* __NV50_DEBUG_H__ */ diff --git a/src/gallium/drivers/nv50/nv50_formats.c b/src/gallium/drivers/nv50/nv50_formats.c index 7946117cf30..c65189d0671 100644 --- a/src/gallium/drivers/nv50/nv50_formats.c +++ b/src/gallium/drivers/nv50/nv50_formats.c @@ -93,6 +93,10 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = B_(C2, C1, C0, C3, UNORM, UNORM, UNORM, UNORM, 4_4_4_4, 1), SAMPLER_VIEW }, + [PIPE_FORMAT_B4G4R4X4_UNORM] = { 0, + B_(C2, C1, C0, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, 4_4_4_4, 1), + SAMPLER_VIEW }, + [PIPE_FORMAT_R10G10B10A2_UNORM] = { NV50_SURFACE_FORMAT_A2B10G10R10_UNORM, A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 2_10_10_10, 0), SAMPLER_VIEW | RENDER_TARGET | VERTEX_BUFFER | SCANOUT }, @@ -138,14 +142,62 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = A_(C0, C0, C0, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, 8, 0), SAMPLER_VIEW | RENDER_TARGET }, - [PIPE_FORMAT_I8_UNORM] = { NV50_SURFACE_FORMAT_R8_UNORM, - A_(C0, C0, C0, C0, UNORM, UNORM, UNORM, UNORM, 8, 0), + [PIPE_FORMAT_L16_SNORM] = { NV50_SURFACE_FORMAT_R16_SNORM, + B_(C0, C0, C0, ONE_FLOAT, SNORM, SNORM, SNORM, SNORM, 16, 0), + SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_L16_FLOAT] = { NV50_SURFACE_FORMAT_R16_FLOAT, + B_(C0, C0, C0, ONE_FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, 16, 0), SAMPLER_VIEW | RENDER_TARGET }, + [PIPE_FORMAT_L32_FLOAT] = { NV50_SURFACE_FORMAT_R32_FLOAT, + B_(C0, C0, C0, ONE_FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, 32, 0), + SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_I8_UNORM] = { 0, + A_(C0, C0, C0, C0, UNORM, UNORM, UNORM, UNORM, 8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I16_UNORM] = { NV50_SURFACE_FORMAT_R16_UNORM, + A_(C0, C0, C0, C0, UNORM, UNORM, UNORM, UNORM, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I16_SNORM] = { NV50_SURFACE_FORMAT_R16_SNORM, + B_(C0, C0, C0, C0, SNORM, SNORM, SNORM, SNORM, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I16_FLOAT] = { NV50_SURFACE_FORMAT_R16_FLOAT, + B_(C0, C0, C0, C0, FLOAT, FLOAT, FLOAT, FLOAT, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I32_FLOAT] = { NV50_SURFACE_FORMAT_R32_FLOAT, + B_(C0, C0, C0, C0, FLOAT, FLOAT, FLOAT, FLOAT, 32, 0), + SAMPLER_VIEW }, + [PIPE_FORMAT_A8_UNORM] = { NV50_SURFACE_FORMAT_A8_UNORM, A_(ZERO, ZERO, ZERO, C0, UNORM, UNORM, UNORM, UNORM, 8, 0), SAMPLER_VIEW | RENDER_TARGET }, + [PIPE_FORMAT_A8_SNORM] = { 0, + A_(ZERO, ZERO, ZERO, C0, SNORM, SNORM, SNORM, SNORM, 8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_A16_UNORM] = { 0, + A_(ZERO, ZERO, ZERO, C0, UNORM, UNORM, UNORM, UNORM, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_A16_SNORM] = { 0, + A_(ZERO, ZERO, ZERO, C0, SNORM, SNORM, SNORM, SNORM, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_A16_FLOAT] = { 0, + B_(ZERO, ZERO, ZERO, C0, FLOAT, FLOAT, FLOAT, FLOAT, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_A32_FLOAT] = { 0, + B_(ZERO, ZERO, ZERO, C0, FLOAT, FLOAT, FLOAT, FLOAT, 32, 0), + SAMPLER_VIEW }, + [PIPE_FORMAT_L8A8_UNORM] = { 0, A_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 8_8, 0), SAMPLER_VIEW }, @@ -154,6 +206,26 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = A_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 8_8, 0), SAMPLER_VIEW }, + [PIPE_FORMAT_L16A16_UNORM] = { 0, + A_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 16_16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_L16A16_SNORM] = { 0, + A_(C0, C0, C0, C1, SNORM, SNORM, SNORM, SNORM, 16_16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_L16A16_FLOAT] = { 0, + B_(C0, C0, C0, C1, FLOAT, FLOAT, FLOAT, FLOAT, 16_16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_L32A32_FLOAT] = { 0, + B_(C0, C0, C0, C1, FLOAT, FLOAT, FLOAT, FLOAT, 32_32, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_L4A4_UNORM] = { 0, + B_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 4_4, 0), + SAMPLER_VIEW }, + /* DXT, RGTC */ [PIPE_FORMAT_DXT1_RGB] = { 0, @@ -172,6 +244,22 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = B_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, DXT5, 0), SAMPLER_VIEW }, + [PIPE_FORMAT_DXT1_SRGB] = { 0, + B_(C0, C1, C2, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, DXT1, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_DXT1_SRGBA] = { 0, + B_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, DXT1, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_DXT3_SRGBA] = { 0, + B_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, DXT3, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_DXT5_SRGBA] = { 0, + B_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, DXT5, 0), + SAMPLER_VIEW }, + [PIPE_FORMAT_RGTC1_UNORM] = { 0, B_(C0, ZERO, ZERO, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, RGTC1, 0), SAMPLER_VIEW }, @@ -237,7 +325,7 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = /* SNORM 32 */ [PIPE_FORMAT_R32G32B32A32_SNORM] = { 0, - A_(C0, C1, C2, C3, FLOAT, FLOAT, FLOAT, FLOAT, 32_32_32_32, 0), + A_(C0, C1, C2, C3, SNORM, SNORM, SNORM, SNORM, 32_32_32_32, 0), VERTEX_BUFFER | SAMPLER_VIEW }, [PIPE_FORMAT_R32G32B32_SNORM] = { 0, @@ -255,7 +343,7 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = /* UNORM 32 */ [PIPE_FORMAT_R32G32B32A32_UNORM] = { 0, - A_(C0, C1, C2, C3, FLOAT, FLOAT, FLOAT, FLOAT, 32_32_32_32, 0), + A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 32_32_32_32, 0), VERTEX_BUFFER | SAMPLER_VIEW }, [PIPE_FORMAT_R32G32B32_UNORM] = { 0, @@ -281,7 +369,7 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = VERTEX_BUFFER | SAMPLER_VIEW }, [PIPE_FORMAT_R16G16_SNORM] = { NV50_SURFACE_FORMAT_R16G16_SNORM, - A_(C0, C1, C2, C3, SNORM, SNORM, SNORM, SNORM, 16_16, 0), + A_(C0, C1, ZERO, ONE_FLOAT, SNORM, SNORM, SNORM, SNORM, 16_16, 0), VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, [PIPE_FORMAT_R16_SNORM] = { NV50_SURFACE_FORMAT_R16_SNORM, @@ -299,7 +387,7 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = VERTEX_BUFFER | SAMPLER_VIEW }, [PIPE_FORMAT_R16G16_UNORM] = { NV50_SURFACE_FORMAT_R16G16_UNORM, - A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 16_16, 0), + A_(C0, C1, ZERO, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, 16_16, 0), VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, [PIPE_FORMAT_R16_UNORM] = { NV50_SURFACE_FORMAT_R16_UNORM, @@ -457,4 +545,30 @@ const struct nv50_format nv50_format_table[PIPE_FORMAT_COUNT] = [PIPE_FORMAT_R8_USCALED] = { 0, A_(C0, ZERO, ZERO, ONE_FLOAT, USCALED, USCALED, USCALED, USCALED, 8, 0), VERTEX_BUFFER }, + + /* OTHER FORMATS */ + + [PIPE_FORMAT_R8G8_B8G8_UNORM] = { 0, + B_(C0, C1, C2, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, C1_C2_C1_C0, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_G8R8_G8B8_UNORM] = { 0, + B_(C0, C1, C2, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, C2_C1_C0_C1, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_R8SG8SB8UX8U_NORM] = { 0, + B_(C0, C1, C2, ONE_FLOAT, SNORM, SNORM, UNORM, UNORM, 8_8_8_8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_R5SG5SB6U_NORM] = { 0, + B_(C0, C1, C2, ONE_FLOAT, SNORM, SNORM, UNORM, UNORM, 6_5_5, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_R1_UNORM] = { 0, + B_(C0, ZERO, ZERO, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, BITMAP_8X8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_A8B8G8R8_UNORM] = { 0, + B_(C3, C2, C1, C0, UNORM, UNORM, UNORM, UNORM, 8_8_8_8, 0), + SAMPLER_VIEW }, }; diff --git a/src/gallium/drivers/nv50/nv50_pc.c b/src/gallium/drivers/nv50/nv50_pc.c index 82f1b846527..7900bf811df 100644 --- a/src/gallium/drivers/nv50/nv50_pc.c +++ b/src/gallium/drivers/nv50/nv50_pc.c @@ -20,8 +20,6 @@ * SOFTWARE. */ -/* #define NV50PC_DEBUG */ - #include "nv50_pc.h" #include "nv50_program.h" @@ -180,6 +178,7 @@ nv50_op_can_write_flags(uint opcode) switch (opcode) { /* obvious ones like KIL, CALL, etc. not included */ case NV_OP_PHI: case NV_OP_MOV: + case NV_OP_SELECT: case NV_OP_LINTERP: case NV_OP_PINTERP: case NV_OP_LDA: @@ -367,7 +366,7 @@ nv_print_program(struct nv_pc *pc) nv_print_function(pc->root[i]); } -#ifdef NV50PC_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_CFLOW static void nv_do_print_cfgraph(struct nv_pc *pc, FILE *f, struct nv_basic_block *b) { @@ -425,7 +424,7 @@ nv_print_cfgraph(struct nv_pc *pc, const char *filepath, int subr) fclose(f); } -#endif +#endif /* NV50_DEBUG_PROG_CFLOW */ static INLINE void nvcg_show_bincode(struct nv_pc *pc) @@ -446,7 +445,7 @@ nv50_emit_program(struct nv_pc *pc) uint32_t *code = pc->emit; int n; - NV50_DBGMSG("emitting program: size = %u\n", pc->bin_size); + NV50_DBGMSG(SHADER, "emitting program: size = %u\n", pc->bin_size); for (n = 0; n < pc->num_blocks; ++n) { struct nv_instruction *i; @@ -472,7 +471,7 @@ nv50_emit_program(struct nv_pc *pc) pc->emit = code; code[pc->bin_size / 4 - 1] |= 1; -#ifdef NV50PC_DEBUG +#if NV50_DEBUG & NV50_DEBUG_SHADER nvcg_show_bincode(pc); #endif @@ -500,7 +499,7 @@ nv50_generate_code(struct nv50_translation_info *ti) ret = nv50_tgsi_to_nc(pc, ti); if (ret) goto out; -#ifdef NV50PC_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_IR nv_print_program(pc); #endif @@ -510,7 +509,7 @@ nv50_generate_code(struct nv50_translation_info *ti) ret = nv_pc_exec_pass0(pc); if (ret) goto out; -#ifdef NV50PC_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_IR nv_print_program(pc); #endif @@ -518,7 +517,7 @@ nv50_generate_code(struct nv50_translation_info *ti) ret = nv_pc_exec_pass1(pc); if (ret) goto out; -#ifdef NV50PC_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_CFLOW nv_print_program(pc); nv_print_cfgraph(pc, "nv50_shader_cfgraph.dot", 0); #endif @@ -552,7 +551,7 @@ nv50_generate_code(struct nv50_translation_info *ti) ti->p->uses_lmem = ti->store_to_memory; - NV50_DBGMSG("SHADER TRANSLATION - %s\n", ret ? "failure" : "success"); + NV50_DBGMSG(SHADER, "SHADER TRANSLATION - %s\n", ret ? "failed" : "success"); out: nv_pc_free_refs(pc); @@ -624,6 +623,9 @@ nvbb_insert_tail(struct nv_basic_block *b, struct nv_instruction *i) i->bb = b; b->num_instructions++; + + if (i->prev && i->prev->is_terminator) + nv_nvi_permute(i->prev, i); } void @@ -669,7 +671,7 @@ nv_nvi_delete(struct nv_instruction *nvi) if (nvi == b->phi) { if (nvi->opcode != NV_OP_PHI) - NV50_DBGMSG("NOTE: b->phi points to non-PHI instruction\n"); + NV50_DBGMSG(PROG_IR, "NOTE: b->phi points to non-PHI instruction\n"); assert(!nvi->prev); if (!nvi->next || nvi->next->opcode != NV_OP_PHI) diff --git a/src/gallium/drivers/nv50/nv50_pc.h b/src/gallium/drivers/nv50/nv50_pc.h index e6f3815bafe..5bb0e1296bb 100644 --- a/src/gallium/drivers/nv50/nv50_pc.h +++ b/src/gallium/drivers/nv50/nv50_pc.h @@ -23,13 +23,7 @@ #ifndef __NV50_COMPILER_H__ #define __NV50_COMPILER_H__ -#define NV50PC_DEBUG - -#ifdef NV50PC_DEBUG -# define NV50_DBGMSG(args...) debug_printf(args) -#else -# define NV50_DBGMSG(args...) -#endif +#include "nv50_debug.h" #include "pipe/p_defines.h" #include "util/u_inlines.h" @@ -228,6 +222,8 @@ struct nv_ref { ubyte flags; /* not used yet */ }; +#define NV_REF_FLAG_REGALLOC_PRIV (1 << 0) + struct nv_basic_block; struct nv_instruction { @@ -263,6 +259,15 @@ struct nv_instruction { ubyte quadop; }; +static INLINE int +nvi_vector_size(struct nv_instruction *nvi) +{ + int i; + assert(nvi); + for (i = 0; i < 4 && nvi->def[i]; ++i); + return i; +} + #define CFG_EDGE_FORWARD 0 #define CFG_EDGE_BACK 1 #define CFG_EDGE_LOOP_ENTER 2 diff --git a/src/gallium/drivers/nv50/nv50_pc_optimize.c b/src/gallium/drivers/nv50/nv50_pc_optimize.c index 281ccf7ac61..d72b23c137a 100644 --- a/src/gallium/drivers/nv50/nv50_pc_optimize.c +++ b/src/gallium/drivers/nv50/nv50_pc_optimize.c @@ -20,8 +20,6 @@ * SOFTWARE. */ -/* #define NV50PC_DEBUG */ - #include "nv50_pc.h" #define DESCEND_ARBITRARY(j, f) \ @@ -116,7 +114,7 @@ nvi_isnop(struct nv_instruction *nvi) return FALSE; if (nvi->src[0]->value->join->reg.id < 0) { - NV50_DBGMSG("nvi_isnop: orphaned value detected\n"); + NV50_DBGMSG(PROG_IR, "nvi_isnop: orphaned value detected\n"); return TRUE; } @@ -201,7 +199,7 @@ nv_pc_pass_pre_emission(void *priv, struct nv_basic_block *b) } if (!b->entry) { - NV50_DBGMSG("block %p is now empty\n", b); + NV50_DBGMSG(PROG_IR, "block %p is now empty\n", b); } else if (!b->exit->is_long) { assert(n32); @@ -240,7 +238,7 @@ nv_pc_exec_pass2(struct nv_pc *pc) { int i, ret; - NV50_DBGMSG("preparing %u blocks for emission\n", pc->num_blocks); + NV50_DBGMSG(PROG_IR, "preparing %u blocks for emission\n", pc->num_blocks); pc->num_blocks = 0; /* will reorder bb_list */ @@ -966,7 +964,8 @@ nv_pass_flatten(struct nv_pass *ctx, struct nv_basic_block *b) if (bb_is_if_else_endif(b)) { - NV50_DBGMSG("pass_flatten: IF/ELSE/ENDIF construct at BB:%i\n", b->id); + NV50_DBGMSG(PROG_IR, + "pass_flatten: IF/ELSE/ENDIF construct at BB:%i\n", b->id); for (n0 = 0, nvi = b->out[0]->entry; nvi; nvi = nvi->next, ++n0) if (!nv50_nvi_can_predicate(nvi)) @@ -975,7 +974,7 @@ nv_pass_flatten(struct nv_pass *ctx, struct nv_basic_block *b) for (n1 = 0, nvi = b->out[1]->entry; nvi; nvi = nvi->next, ++n1) if (!nv50_nvi_can_predicate(nvi)) break; -#ifdef NV50PC_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_IR if (nvi) { debug_printf("cannot predicate: "); nv_print_instruction(nvi); } diff --git a/src/gallium/drivers/nv50/nv50_pc_regalloc.c b/src/gallium/drivers/nv50/nv50_pc_regalloc.c index 39ae36681c0..e79fd594cea 100644 --- a/src/gallium/drivers/nv50/nv50_pc_regalloc.c +++ b/src/gallium/drivers/nv50/nv50_pc_regalloc.c @@ -20,11 +20,11 @@ * SOFTWARE. */ -/* #define NV50PC_DEBUG */ - -/* #define NV50_RA_DEBUG_LIVEI */ -/* #define NV50_RA_DEBUG_LIVE_SETS */ -/* #define NV50_RA_DEBUG_JOIN */ +#if NV50_DEBUG & NV50_DEBUG_PROG_RA +# define NV50_RA_DEBUG_LIVEI +# define NV50_RA_DEBUG_LIVE_SETS +# define NV50_RA_DEBUG_JOIN +#endif #include "nv50_context.h" #include "nv50_pc.h" @@ -32,14 +32,39 @@ #include "util/u_simple_list.h" #define NUM_REGISTER_FILES 4 +#define MAX_REGISTER_COUNT 256 struct register_set { struct nv_pc *pc; uint32_t last[NUM_REGISTER_FILES]; - uint32_t bits[NUM_REGISTER_FILES][8]; + uint32_t bits[NUM_REGISTER_FILES][(MAX_REGISTER_COUNT + 31) / 32]; }; +/* using OR because a set bit means occupied/unavailable, aliasing is allowed */ +static void +intersect_register_sets(struct register_set *dst, + struct register_set *src1, struct register_set *src2) +{ + int i, j; + + for (i = 0; i < NUM_REGISTER_FILES; ++i) { + for (j = 0; j < (MAX_REGISTER_COUNT + 31) / 32; ++j) + dst->bits[i][j] = src1->bits[i][j] | src2->bits[i][j]; + } +} + +static void +mask_register_set(struct register_set *set, uint32_t mask, uint32_t umask) +{ + int i, j; + + for (i = 0; i < NUM_REGISTER_FILES; ++i) { + for (j = 0; j < (MAX_REGISTER_COUNT + 31) / 32; ++j) + set->bits[i][j] = (set->bits[i][j] | mask) & umask; + } +} + struct nv_pc_pass { struct nv_pc *pc; @@ -61,11 +86,15 @@ ranges_coalesce(struct nv_range *range) } } +/* @return: TRUE if @new_range can be freed (i.e. was not reused) */ static boolean add_range_ex(struct nv_value *val, int bgn, int end, struct nv_range *new_range) { struct nv_range *range, **nextp = &val->livei; + if (bgn == end) /* [a, a) is invalid / empty */ + return TRUE; + for (range = val->livei; range; range = range->next) { if (end < range->bgn) break; /* insert before */ @@ -251,6 +280,8 @@ reg_occupy(struct register_set *set, struct nv_value *val) id <<= s; m = (1 << (1 << s)) - 1; + assert(s >= 0); /* XXX: remove me */ + set->bits[f][id / 32] |= m << (id % 32); if (set->pc->max_reg[f] < id) @@ -286,15 +317,12 @@ join_allowed(struct nv_pc_pass *ctx, struct nv_value *a, struct nv_value *b) if (a->join->reg.id == b->join->reg.id) return TRUE; -#if 1 /* either a or b or both have been assigned */ if (a->join->reg.id >= 0 && b->join->reg.id >= 0) return FALSE; else if (b->join->reg.id >= 0) { - if (a->join->reg.id >= 0) - return FALSE; val = a; a = b; b = val; @@ -309,8 +337,6 @@ join_allowed(struct nv_pc_pass *ctx, struct nv_value *a, struct nv_value *b) return FALSE; } return TRUE; -#endif - return FALSE; } static INLINE void @@ -336,14 +362,14 @@ do_join_values(struct nv_pc_pass *ctx, struct nv_value *a, struct nv_value *b) assert(b->join == a->join); } -static INLINE void +static INLINE boolean try_join_values(struct nv_pc_pass *ctx, struct nv_value *a, struct nv_value *b) { if (!join_allowed(ctx, a, b)) { #ifdef NV50_RA_DEBUG_JOIN debug_printf("cannot join %i to %i: not allowed\n", b->n, a->n); #endif - return; + return FALSE; } if (livei_have_overlap(a->join, b->join)) { #ifdef NV50_RA_DEBUG_JOIN @@ -351,10 +377,27 @@ try_join_values(struct nv_pc_pass *ctx, struct nv_value *a, struct nv_value *b) livei_print(a); livei_print(b); #endif - return; + return FALSE; } do_join_values(ctx, a, b); + + return TRUE; +} + +static void +join_values_nofail(struct nv_pc_pass *ctx, + struct nv_value *a, struct nv_value *b, boolean type_only) +{ + if (type_only) { + assert(join_allowed(ctx, a, b)); + do_join_values(ctx, a, b); + } else { + boolean ok = try_join_values(ctx, a, b); + if (!ok) { + NOUVEAU_ERR("failed to coalesce values\n"); + } + } } static INLINE boolean @@ -369,20 +412,32 @@ need_new_else_block(struct nv_basic_block *b, struct nv_basic_block *p) return (b->num_in > 1) && (n == 2); } +/* Look for the @phi's operand whose definition reaches @b. */ static int phi_opnd_for_bb(struct nv_instruction *phi, struct nv_basic_block *b, struct nv_basic_block *tb) { + struct nv_ref *srci, *srcj; int i, j; - for (j = -1, i = 0; i < 4 && phi->src[i]; ++i) { - if (!nvbb_reachable_by(b, phi->src[i]->value->insn->bb, tb)) + for (j = -1, i = 0; i < 6 && phi->src[i]; ++i) { + srci = phi->src[i]; + /* if already replaced, check with original source first */ + if (srci->flags & NV_REF_FLAG_REGALLOC_PRIV) + srci = srci->value->insn->src[0]; + if (!nvbb_reachable_by(b, srci->value->insn->bb, NULL)) continue; /* NOTE: back-edges are ignored by the reachable-by check */ - if (j < 0 || !nvbb_reachable_by(phi->src[j]->value->insn->bb, - phi->src[i]->value->insn->bb, tb)) + if (j < 0 || !nvbb_reachable_by(srcj->value->insn->bb, + srci->value->insn->bb, NULL)) { j = i; + srcj = srci; + } } + if (j >= 0 && nvbb_reachable_by(b, phi->def[0]->insn->bb, NULL)) + if (!nvbb_reachable_by(srcj->value->insn->bb, + phi->def[0]->insn->bb, NULL)) + j = -1; return j; } @@ -429,16 +484,21 @@ pass_generate_phi_movs(struct nv_pc_pass *ctx, struct nv_basic_block *b) ctx->pc->current_block = pn; for (i = b->phi; i && i->opcode == NV_OP_PHI; i = i->next) { - if ((j = phi_opnd_for_bb(i, p, b)) < 0) - continue; - val = i->src[j]->value; - - if (i->src[j]->flags) { - val = val->insn->src[0]->value; - while (j < 4 && i->src[j]) - ++j; - assert(j < 4); + j = phi_opnd_for_bb(i, p, b); + + if (j < 0) { + val = i->def[0]; + } else { + val = i->src[j]->value; + if (i->src[j]->flags & NV_REF_FLAG_REGALLOC_PRIV) { + j = -1; + /* use original value, we already encountered & replaced it */ + val = val->insn->src[0]->value; + } } + if (j < 0) /* need an additional source ? */ + for (j = 0; j < 5 && i->src[j] && i->src[j]->value != val; ++j); + assert(j < 5); ni = new_instruction(ctx->pc, NV_OP_MOV); @@ -452,11 +512,13 @@ pass_generate_phi_movs(struct nv_pc_pass *ctx, struct nv_basic_block *b) nv_reference(ctx->pc, &i->src[j], ni->def[0]); - i->src[j]->flags = 1; + i->src[j]->flags |= NV_REF_FLAG_REGALLOC_PRIV; } if (pn != p && pn->exit) { - ctx->pc->current_block = b->in[n ? 0 : 1]; + assert(!b->in[!n]->exit || b->in[!n]->exit->is_terminator); + /* insert terminator (branch to ENDIF) in new else block */ + ctx->pc->current_block = pn; ni = new_instruction(ctx->pc, NV_OP_BRA); ni->target = b; ni->is_terminator = 1; @@ -470,45 +532,50 @@ pass_generate_phi_movs(struct nv_pc_pass *ctx, struct nv_basic_block *b) return 0; } +#define JOIN_MASK_PHI (1 << 0) +#define JOIN_MASK_SELECT (1 << 1) +#define JOIN_MASK_MOV (1 << 2) +#define JOIN_MASK_TEX (1 << 3) + static int -pass_join_values(struct nv_pc_pass *ctx, int iter) +pass_join_values(struct nv_pc_pass *ctx, unsigned mask) { int c, n; for (n = 0; n < ctx->num_insns; ++n) { - struct nv_instruction *i = ctx->insns[n]; + struct nv_instruction *nvi, *i = ctx->insns[n]; switch (i->opcode) { case NV_OP_PHI: - if (iter != 2) + if (!(mask & JOIN_MASK_PHI)) break; - for (c = 0; c < 4 && i->src[c]; ++c) - try_join_values(ctx, i->def[0], i->src[c]->value); + for (c = 0; c < 5 && i->src[c]; ++c) + join_values_nofail(ctx, i->def[0], i->src[c]->value, FALSE); break; case NV_OP_MOV: - if ((iter == 2) && i->src[0]->value->insn && - !nv_is_vector_op(i->src[0]->value->join->insn->opcode)) + if (!(mask & JOIN_MASK_MOV)) + break; + nvi = i->src[0]->value->join->insn; + if (nvi && !nv_is_vector_op(nvi->opcode)) try_join_values(ctx, i->def[0], i->src[0]->value); break; case NV_OP_SELECT: - if (iter != 1) + if (!(mask & JOIN_MASK_SELECT)) break; - for (c = 0; c < 4 && i->src[c]; ++c) { - assert(join_allowed(ctx, i->def[0], i->src[c]->value)); - do_join_values(ctx, i->def[0], i->src[c]->value); - } + for (c = 0; c < 5 && i->src[c]; ++c) + join_values_nofail(ctx, i->def[0], i->src[c]->value, TRUE); break; case NV_OP_TEX: case NV_OP_TXB: case NV_OP_TXL: case NV_OP_TXQ: - if (iter) + if (!(mask & JOIN_MASK_TEX)) break; - for (c = 0; c < 4; ++c) { - if (!i->src[c]) - break; - do_join_values(ctx, i->def[c], i->src[c]->value); - } + /* This should work without conflicts because we always generate + * extra MOVs for the sources of a TEX. + */ + for (c = 0; c < 4 && i->src[c]; ++c) + join_values_nofail(ctx, i->def[c], i->src[c]->value, TRUE); break; default: break; @@ -643,15 +710,15 @@ static void collect_live_values(struct nv_basic_block *b, const int n) { int i; - if (b->out[0]) { - if (b->out[1]) { /* what to do about back-edges ? */ + if (b->out[0] && b->out_kind[0] != CFG_EDGE_FAKE) { + if (b->out[1] && b->out_kind[1] != CFG_EDGE_FAKE) { for (i = 0; i < n; ++i) b->live_set[i] = b->out[0]->live_set[i] | b->out[1]->live_set[i]; } else { memcpy(b->live_set, b->out[0]->live_set, n * sizeof(uint32_t)); } } else - if (b->out[1]) { + if (b->out[1] && b->out_kind[1] != CFG_EDGE_FAKE) { memcpy(b->live_set, b->out[1]->live_set, n * sizeof(uint32_t)); } else { memset(b->live_set, 0, n * sizeof(uint32_t)); @@ -770,8 +837,8 @@ insert_ordered_tail(struct nv_value *list, struct nv_value *nval) struct nv_value *elem; for (elem = list->prev; - elem != list && elem->livei->bgn > nval->livei->bgn; - elem = elem->prev); + elem != list && elem->livei->bgn > nval->livei->bgn; + elem = elem->prev); /* now elem begins before or at the same time as val */ nval->prev = elem; @@ -780,44 +847,49 @@ insert_ordered_tail(struct nv_value *list, struct nv_value *nval) elem->next = nval; } -static int -pass_linear_scan(struct nv_pc_pass *ctx, int iter) +static void +collect_register_values(struct nv_pc_pass *ctx, struct nv_value *head, + boolean assigned_only) { - struct nv_instruction *i; - struct register_set f, free; + struct nv_value *val; int k, n; - struct nv_value *cur, *val, *tmp[2]; - struct nv_value active, inactive, handled, unhandled; - make_empty_list(&active); - make_empty_list(&inactive); - make_empty_list(&handled); - make_empty_list(&unhandled); + make_empty_list(head); - nv50_ctor_register_set(ctx->pc, &free); - - /* joined values should have range = NULL and thus not be added; - * also, fixed memory values won't be added because they're not - * def'd, just used - */ for (n = 0; n < ctx->num_insns; ++n) { - i = ctx->insns[n]; + struct nv_instruction *i = ctx->insns[n]; + /* for joined values, only the representative will have livei != NULL */ for (k = 0; k < 4; ++k) { if (i->def[k] && i->def[k]->livei) - insert_ordered_tail(&unhandled, i->def[k]); - else - if (0 && i->def[k]) - debug_printf("skipping def'd value %i: no livei\n", i->def[k]->n); + if (!assigned_only || i->def[k]->reg.id >= 0) + insert_ordered_tail(head, i->def[k]); } if (i->flags_def && i->flags_def->livei) - insert_ordered_tail(&unhandled, i->flags_def); + if (!assigned_only || i->flags_def->reg.id >= 0) + insert_ordered_tail(head, i->flags_def); } - for (val = unhandled.next; val != unhandled.prev; val = val->next) { + for (val = head->next; val != head->prev; val = val->next) { assert(val->join == val); assert(val->livei->bgn <= val->next->livei->bgn); } +} + +static int +pass_linear_scan(struct nv_pc_pass *ctx, int iter) +{ + struct register_set f, free; + struct nv_value *cur, *val, *tmp[2]; + struct nv_value active, inactive, handled, unhandled; + + make_empty_list(&active); + make_empty_list(&inactive); + make_empty_list(&handled); + + nv50_ctor_register_set(ctx->pc, &free); + + collect_register_values(ctx, &unhandled, FALSE); foreach_s(cur, tmp[0], &unhandled) { remove_from_list(cur); @@ -854,13 +926,7 @@ pass_linear_scan(struct nv_pc_pass *ctx, int iter) reg_occupy(&f, val); if (cur->reg.id < 0) { - boolean mem = FALSE; - - if (nv_is_vector_op(cur->insn->opcode)) - mem = !reg_assign(&f, &cur->insn->def[0], 4); - else - if (iter) - mem = !reg_assign(&f, &cur, 1); + boolean mem = !reg_assign(&f, &cur, 1); if (mem) { NOUVEAU_ERR("out of registers\n"); @@ -874,13 +940,80 @@ pass_linear_scan(struct nv_pc_pass *ctx, int iter) return 0; } +/* Allocate values defined by instructions such as TEX, which have to be + * assigned to consecutive registers. + * Linear scan doesn't really work here since the values can have different + * live intervals. + */ +static int +pass_allocate_constrained_values(struct nv_pc_pass *ctx) +{ + struct nv_value regvals, *val; + struct nv_instruction *i; + struct nv_value *defs[4]; + struct register_set regs[4]; + int n, vsize, c; + uint32_t mask; + boolean mem; + + collect_register_values(ctx, ®vals, TRUE); + + for (n = 0; n < ctx->num_insns; ++n) { + i = ctx->insns[n]; + vsize = nvi_vector_size(i); + if (!(vsize > 1)) + continue; + assert(vsize <= 4); + for (c = 0; c < vsize; ++c) + defs[c] = i->def[c]->join; + + if (defs[0]->reg.id >= 0) { + for (c = 1; c < vsize; ++c) + assert(defs[c]->reg.id >= 0); + continue; + } + + /* Compute registers available for this "vector" of consecutive registers. + * Each value (component) has its own independent live interval. + */ + for (c = 0; c < vsize; ++c) { + nv50_ctor_register_set(ctx->pc, ®s[c]); + + foreach(val, ®vals) { + if (val->reg.id >= 0 && livei_have_overlap(val, defs[c])) + reg_occupy(®s[c], val); + } + /* Only 32 bit GPRs will be allocated here, but register set + * granularity for GPRs is 16 bit. + */ + mask = 0x03030303; + if (vsize == 2) /* granularity is 2 and not 4 */ + mask |= 0x03030303 << 4; + mask_register_set(®s[c], 0, mask << (c * 2)); + + if (defs[c]->livei) + insert_ordered_tail(®vals, defs[c]); + } + for (c = 1; c < vsize; ++c) + intersect_register_sets(®s[0], ®s[0], ®s[c]); + + mem = !reg_assign(®s[0], &defs[0], vsize); + + if (mem) { + NOUVEAU_ERR("out of registers\n"); + abort(); + } + } + return 0; +} + static int nv_pc_pass1(struct nv_pc *pc, struct nv_basic_block *root) { struct nv_pc_pass *ctx; int i, ret; - NV50_DBGMSG("REGISTER ALLOCATION - entering\n"); + NV50_DBGMSG(PROG_RA, "REGISTER ALLOCATION - entering\n"); ctx = CALLOC_STRUCT(nv_pc_pass); if (!ctx) @@ -923,16 +1056,16 @@ nv_pc_pass1(struct nv_pc *pc, struct nv_basic_block *root) livei_print(&pc->values[i]); #endif - ret = pass_join_values(ctx, 0); + ret = pass_join_values(ctx, JOIN_MASK_PHI); if (ret) goto out; - ret = pass_linear_scan(ctx, 0); + ret = pass_join_values(ctx, JOIN_MASK_SELECT | JOIN_MASK_TEX); if (ret) goto out; - ret = pass_join_values(ctx, 1); + ret = pass_join_values(ctx, JOIN_MASK_MOV); if (ret) goto out; - ret = pass_join_values(ctx, 2); + ret = pass_allocate_constrained_values(ctx); if (ret) goto out; ret = pass_linear_scan(ctx, 1); @@ -942,7 +1075,7 @@ nv_pc_pass1(struct nv_pc *pc, struct nv_basic_block *root) for (i = 0; i < pc->num_values; ++i) livei_release(&pc->values[i]); - NV50_DBGMSG("REGISTER ALLOCATION - leaving\n"); + NV50_DBGMSG(PROG_RA, "REGISTER ALLOCATION - leaving\n"); out: FREE(ctx->insns); diff --git a/src/gallium/drivers/nv50/nv50_program.c b/src/gallium/drivers/nv50/nv50_program.c index a63f9d8a6d5..41d3e14dc0f 100644 --- a/src/gallium/drivers/nv50/nv50_program.c +++ b/src/gallium/drivers/nv50/nv50_program.c @@ -20,8 +20,6 @@ * SOFTWARE. */ -/* #define NV50_PROGRAM_DEBUG */ - #include "nv50_program.h" #include "nv50_pc.h" #include "nv50_context.h" @@ -486,7 +484,7 @@ nv50_fragprog_prepare(struct nv50_translation_info *ti) ++nintp; } - p->fp.colors = (1 << 24) | 4; /* CLAMP, FFC0_ID = 4 */ + p->fp.colors = 4 << NV50_3D_MAP_SEMANTIC_0_FFC0_ID__SHIFT; /* after HPOS */ for (i = 0; i < p->in_nr; ++i) { int j = p->in[i].id; @@ -564,7 +562,7 @@ nv50_prog_scan(struct nv50_translation_info *ti) tgsi_scan_shader(p->pipe.tokens, &ti->scan); -#ifdef NV50_PROGRAM_DEBUG +#if NV50_DEBUG & NV50_DEBUG_SHADER tgsi_dump(p->pipe.tokens, 0); #endif diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c index 7690c80eef0..641ad7e2780 100644 --- a/src/gallium/drivers/nv50/nv50_screen.c +++ b/src/gallium/drivers/nv50/nv50_screen.c @@ -20,6 +20,7 @@ * SOFTWARE. */ +#include "util/u_format.h" #include "util/u_format_s3tc.h" #include "pipe/p_screen.h" @@ -45,17 +46,8 @@ nv50_screen_is_format_supported(struct pipe_screen *pscreen, if (sample_count > 1) return FALSE; - if (!util_format_s3tc_enabled) { - switch (format) { - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - case PIPE_FORMAT_DXT3_RGBA: - case PIPE_FORMAT_DXT5_RGBA: - return FALSE; - default: - break; - } - } + if (!util_format_is_supported(format, bindings)) + return FALSE; switch (format) { case PIPE_FORMAT_Z16_UNORM: @@ -108,6 +100,8 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) return 1; case PIPE_CAP_MAX_RENDER_TARGETS: return 8; + case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL: + return 1; case PIPE_CAP_TIMER_QUERY: case PIPE_CAP_OCCLUSION_QUERY: return 1; @@ -129,6 +123,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) case PIPE_CAP_PRIMITIVE_RESTART: case PIPE_CAP_TGSI_INSTANCEID: case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: + case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: return 1; default: NOUVEAU_ERR("unknown PIPE_CAP %d\n", param); @@ -417,6 +412,10 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) OUT_RING (chan, NV50_3D_MULTISAMPLE_MODE_MS1); BEGIN_RING(chan, RING_3D(MULTISAMPLE_CTRL), 1); OUT_RING (chan, 0); + BEGIN_RING(chan, RING_3D(LINE_LAST_PIXEL), 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, RING_3D(BLEND_SEPARATE_ALPHA), 1); + OUT_RING (chan, 1); BEGIN_RING(chan, RING_3D(SCREEN_Y_CONTROL), 1); OUT_RING (chan, 0); diff --git a/src/gallium/drivers/nv50/nv50_shader_state.c b/src/gallium/drivers/nv50/nv50_shader_state.c index bea9c095bb3..82c346cb5ea 100644 --- a/src/gallium/drivers/nv50/nv50_shader_state.c +++ b/src/gallium/drivers/nv50/nv50_shader_state.c @@ -226,7 +226,7 @@ nv50_gmtyprog_validate(struct nv50_context *nv50) OUT_RING (chan, gp->code_base); } -void +static void nv50_sprite_coords_validate(struct nv50_context *nv50) { struct nouveau_channel *chan = nv50->screen->base.channel; @@ -282,6 +282,39 @@ nv50_sprite_coords_validate(struct nv50_context *nv50) OUT_RINGp (chan, pntc, 8); } +/* Validate state derived from shaders and the rasterizer cso. */ +void +nv50_validate_derived_rs(struct nv50_context *nv50) +{ + struct nouveau_channel *chan = nv50->screen->base.channel; + uint32_t color, psize; + + nv50_sprite_coords_validate(nv50); + + if (nv50->dirty & NV50_NEW_FRAGPROG) + return; + psize = nv50->state.semantic_psize & ~NV50_3D_MAP_SEMANTIC_3_PTSZ_EN__MASK; + color = nv50->state.semantic_color & ~NV50_3D_MAP_SEMANTIC_0_CLMP_EN; + + if (nv50->rast->pipe.clamp_vertex_color) + color |= NV50_3D_MAP_SEMANTIC_0_CLMP_EN; + + if (color != nv50->state.semantic_color) { + nv50->state.semantic_color = color; + BEGIN_RING(chan, RING_3D(MAP_SEMANTIC_0), 1); + OUT_RING (chan, color); + } + + if (nv50->rast->pipe.point_size_per_vertex) + psize |= NV50_3D_MAP_SEMANTIC_3_PTSZ_EN__MASK; + + if (psize != nv50->state.semantic_psize) { + nv50->state.semantic_psize = psize; + BEGIN_RING(chan, RING_3D(MAP_SEMANTIC_3), 1); + OUT_RING (chan, psize); + } +} + static int nv50_vec4_map(uint8_t *map, int mid, uint32_t lin[4], struct nv50_varying *in, struct nv50_varying *out) @@ -372,6 +405,9 @@ nv50_fp_linkage_validate(struct nv50_context *nv50) map[m++] = vp->vp.psiz; } + if (nv50->rast->pipe.clamp_vertex_color) + colors |= NV50_3D_MAP_SEMANTIC_0_CLMP_EN; + n = (m + 3) / 4; assert(m <= 64); @@ -404,6 +440,9 @@ nv50_fp_linkage_validate(struct nv50_context *nv50) nv50->state.interpolant_ctrl = interp; + nv50->state.semantic_color = colors; + nv50->state.semantic_psize = psiz; + BEGIN_RING(chan, RING_3D(NOPERSPECTIVE_BITMAP(0)), 4); OUT_RINGp (chan, lin, 4); diff --git a/src/gallium/drivers/nv50/nv50_state.c b/src/gallium/drivers/nv50/nv50_state.c index db257159698..799f49619d2 100644 --- a/src/gallium/drivers/nv50/nv50_state.c +++ b/src/gallium/drivers/nv50/nv50_state.c @@ -97,8 +97,14 @@ nv50_blend_state_create(struct pipe_context *pipe, so->pipe = *cso; - SB_BEGIN_3D(so, BLEND_ENABLE(0), 8); + SB_BEGIN_3D(so, COLOR_MASK_COMMON, 1); + SB_DATA (so, !cso->independent_blend_enable); + + SB_BEGIN_3D(so, BLEND_ENABLE_COMMON, 1); + SB_DATA (so, !cso->independent_blend_enable); + if (cso->independent_blend_enable) { + SB_BEGIN_3D(so, BLEND_ENABLE(0), 8); for (i = 0; i < 8; ++i) { SB_DATA(so, cso->rt[i].blend_enable); if (cso->rt[i].blend_enable) @@ -121,8 +127,8 @@ nv50_blend_state_create(struct pipe_context *pipe, } } } else { - for (i = 0; i < 8; ++i) - SB_DATA(so, cso->rt[0].blend_enable); + SB_BEGIN_3D(so, BLEND_ENABLE(0), 1); + SB_DATA (so, cso->rt[0].blend_enable); } if (emit_common_func) { @@ -145,17 +151,16 @@ nv50_blend_state_create(struct pipe_context *pipe, SB_DATA (so, 0); } - SB_BEGIN_3D(so, COLOR_MASK(0), 8); if (cso->independent_blend_enable) { + SB_BEGIN_3D(so, COLOR_MASK(0), 8); for (i = 0; i < 8; ++i) SB_DATA(so, nv50_colormask(cso->rt[i].colormask)); } else { - uint32_t cmask = nv50_colormask(cso->rt[0].colormask); - for (i = 0; i < 8; ++i) - SB_DATA(so, cmask); + SB_BEGIN_3D(so, COLOR_MASK(0), 1); + SB_DATA (so, nv50_colormask(cso->rt[0].colormask)); } - assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); + assert(so->size <= (sizeof(so->state) / sizeof(so->state[0]))); return so; } @@ -174,6 +179,7 @@ nv50_blend_state_delete(struct pipe_context *pipe, void *hwcso) FREE(hwcso); } +/* NOTE: ignoring line_last_pixel, using FALSE (set on screen init) */ static void * nv50_rasterizer_state_create(struct pipe_context *pipe, const struct pipe_rasterizer_state *cso) @@ -198,6 +204,9 @@ nv50_rasterizer_state_create(struct pipe_context *pipe, SB_BEGIN_3D(so, VERTEX_TWO_SIDE_ENABLE, 1); SB_DATA (so, cso->light_twoside); + SB_BEGIN_3D(so, FRAG_COLOR_CLAMP_EN, 1); + SB_DATA (so, cso->clamp_fragment_color ? 0x11111111 : 0x00000000); + SB_BEGIN_3D(so, LINE_WIDTH, 1); SB_DATA (so, fui(cso->line_width)); SB_BEGIN_3D(so, LINE_SMOOTH_ENABLE, 1); @@ -258,7 +267,7 @@ nv50_rasterizer_state_create(struct pipe_context *pipe, SB_DATA (so, fui(cso->offset_units * 2.0f)); } - assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); + assert(so->size <= (sizeof(so->state) / sizeof(so->state[0]))); return (void *)so; } @@ -337,7 +346,7 @@ nv50_zsa_state_create(struct pipe_context *pipe, SB_DATA (so, 0); } - assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); + assert(so->size <= (sizeof(so->state) / sizeof(so->state[0]))); return (void *)so; } diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c index f3d45eb95e0..cdf1a982fcc 100644 --- a/src/gallium/drivers/nv50/nv50_state_validate.c +++ b/src/gallium/drivers/nv50/nv50_state_validate.c @@ -309,7 +309,7 @@ static struct state_validate { { nv50_fp_linkage_validate, NV50_NEW_FRAGPROG | NV50_NEW_VERTPROG | NV50_NEW_GMTYPROG }, { nv50_gp_linkage_validate, NV50_NEW_GMTYPROG | NV50_NEW_VERTPROG }, - { nv50_sprite_coords_validate, NV50_NEW_FRAGPROG | NV50_NEW_RASTERIZER | + { nv50_validate_derived_rs, NV50_NEW_FRAGPROG | NV50_NEW_RASTERIZER | NV50_NEW_VERTPROG | NV50_NEW_GMTYPROG }, { nv50_constbufs_validate, NV50_NEW_CONSTBUF }, { nv50_validate_textures, NV50_NEW_TEXTURES }, diff --git a/src/gallium/drivers/nv50/nv50_stateobj.h b/src/gallium/drivers/nv50/nv50_stateobj.h index 515e3e78d42..4c98c7e46fc 100644 --- a/src/gallium/drivers/nv50/nv50_stateobj.h +++ b/src/gallium/drivers/nv50/nv50_stateobj.h @@ -21,13 +21,13 @@ struct nv50_blend_stateobj { struct pipe_blend_state pipe; int size; - uint32_t state[78]; + uint32_t state[82]; // TODO: allocate less if !independent_blend_enable }; struct nv50_rasterizer_stateobj { struct pipe_rasterizer_state pipe; int size; - uint32_t state[40]; + uint32_t state[42]; }; struct nv50_zsa_stateobj { diff --git a/src/gallium/drivers/nv50/nv50_surface.c b/src/gallium/drivers/nv50/nv50_surface.c index dc9e2880f0f..3d7e880ccce 100644 --- a/src/gallium/drivers/nv50/nv50_surface.c +++ b/src/gallium/drivers/nv50/nv50_surface.c @@ -27,6 +27,7 @@ #include "util/u_inlines.h" #include "util/u_pack_color.h" #include "util/u_format.h" +#include "util/u_surface.h" #include "nv50_context.h" #include "nv50_resource.h" @@ -198,6 +199,13 @@ nv50_resource_copy_region(struct pipe_context *pipe, int ret; unsigned dst_layer = dstz, src_layer = src_box->z; + /* Fallback for buffers. */ + if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { + util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + return; + } + assert((src->format == dst->format) || (nv50_2d_format_faithful(src->format) && nv50_2d_format_faithful(dst->format))); diff --git a/src/gallium/drivers/nv50/nv50_tgsi_to_nc.c b/src/gallium/drivers/nv50/nv50_tgsi_to_nc.c index 1449cb04c69..25dcaaea14f 100644 --- a/src/gallium/drivers/nv50/nv50_tgsi_to_nc.c +++ b/src/gallium/drivers/nv50/nv50_tgsi_to_nc.c @@ -20,8 +20,6 @@ * SOFTWARE. */ -/* #define NV50_TGSI2NC_DEBUG */ - #include <unistd.h> #include "nv50_context.h" @@ -213,7 +211,7 @@ static INLINE void bld_warn_uninitialized(struct bld_context *bld, int kind, struct bld_value_stack *stk, struct nv_basic_block *b) { -#ifdef NV50_TGSI2NC_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_IR long i = (stk - &bld->tvs[0][0]) / 4; long c = (stk - &bld->tvs[0][0]) & 3; @@ -273,6 +271,12 @@ fetch_by_bb(struct bld_value_stack *stack, fetch_by_bb(stack, vals, n, b->in[i]); } +static INLINE boolean +nvbb_is_terminated(struct nv_basic_block *bb) +{ + return bb->exit && bb->exit->is_terminator; +} + static INLINE struct nv_value * bld_load_imm_u32(struct bld_context *bld, uint32_t u); @@ -1556,7 +1560,7 @@ bld_instruction(struct bld_context *bld, int c; uint opcode = translate_opcode(insn->Instruction.Opcode); -#ifdef NV50_TGSI2NC_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_IR debug_printf("bld_instruction:"); tgsi_dump_instruction(insn, 1); #endif @@ -1727,8 +1731,7 @@ bld_instruction(struct bld_context *bld, { struct nv_basic_block *b = new_basic_block(bld->pc); - if (bld->pc->current_block->exit && - !bld->pc->current_block->exit->is_terminator) + if (!nvbb_is_terminated(bld->pc->current_block)) bld_flow(bld, NV_OP_BRA, NV_CC_TR, NULL, b, FALSE); --bld->cond_lvl; @@ -1800,7 +1803,8 @@ bld_instruction(struct bld_context *bld, { struct nv_basic_block *bb = bld->loop_bb[bld->loop_lvl - 1]; - bld_flow(bld, NV_OP_BRA, NV_CC_TR, NULL, bb, FALSE); + if (!nvbb_is_terminated(bld->pc->current_block)) + bld_flow(bld, NV_OP_BRA, NV_CC_TR, NULL, bb, FALSE); nvbb_attach_block(bld->pc->current_block, bb, CFG_EDGE_BACK); diff --git a/src/gallium/drivers/nvc0/nvc0_3d.xml.h b/src/gallium/drivers/nvc0/nvc0_3d.xml.h index 94fa081ad7e..2ca0bc23836 100644 --- a/src/gallium/drivers/nvc0/nvc0_3d.xml.h +++ b/src/gallium/drivers/nvc0/nvc0_3d.xml.h @@ -82,6 +82,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_SERIALIZE 0x00000110 +#define NVC0_3D_LINE_WIDTH_SEPARATE 0x0000020c + #define NVC0_3D_EARLY_FRAGMENT_TESTS 0x00000210 #define NVC0_3D_MEM_BARRIER 0x0000021c @@ -342,10 +344,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_VERTEX_RUNOUT_ADDRESS_LOW 0x00000f88 +#define NVC0_3D_COLOR_MASK_COMMON 0x00000f90 + #define NVC0_3D_DEPTH_BOUNDS(i0) (0x00000f9c + 0x4*(i0)) #define NVC0_3D_DEPTH_BOUNDS__ESIZE 0x00000004 #define NVC0_3D_DEPTH_BOUNDS__LEN 0x00000002 +#define NVC0_3D_RT_SEPARATE_FRAG_DATA 0x00000fac + #define NVC0_3D_MSAA_MASK(i0) (0x00000fbc + 0x4*(i0)) #define NVC0_3D_MSAA_MASK__ESIZE 0x00000004 #define NVC0_3D_MSAA_MASK__LEN 0x00000004 @@ -561,6 +567,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_TEX_CACHE_CTL_UNK1__MASK 0x00000030 #define NVC0_3D_TEX_CACHE_CTL_UNK1__SHIFT 4 +#define NVC0_3D_BLEND_SEPARATE_ALPHA 0x0000133c + #define NVC0_3D_BLEND_EQUATION_RGB 0x00001340 #define NVC0_3D_BLEND_EQUATION_RGB_FUNC_ADD 0x00008006 #define NVC0_3D_BLEND_EQUATION_RGB_MIN 0x00008007 @@ -583,6 +591,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_BLEND_FUNC_DST_ALPHA 0x00001358 +#define NVC0_3D_BLEND_ENABLE_COMMON 0x0000135c + #define NVC0_3D_BLEND_ENABLE(i0) (0x00001360 + 0x4*(i0)) #define NVC0_3D_BLEND_ENABLE__ESIZE 0x00000004 #define NVC0_3D_BLEND_ENABLE__LEN 0x00000008 @@ -651,7 +661,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_SCREEN_Y_CONTROL_Y_NEGATE 0x00000001 #define NVC0_3D_SCREEN_Y_CONTROL_TRIANGLE_RAST_FLIP 0x00000010 -#define NVC0_3D_LINE_WIDTH 0x000013b0 +#define NVC0_3D_LINE_WIDTH_SMOOTH 0x000013b0 + +#define NVC0_3D_LINE_WIDTH_ALIASED 0x000013b4 #define NVC0_3D_GP_VERTEX_OUTPUT_COUNT 0x00001420 #define NVC0_3D_GP_VERTEX_OUTPUT_COUNT__MIN 0x00000001 @@ -977,6 +989,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_CULL_FACE_BACK 0x00000405 #define NVC0_3D_CULL_FACE_FRONT_AND_BACK 0x00000408 +#define NVC0_3D_LINE_LAST_PIXEL 0x00001924 + #define NVC0_3D_VIEWPORT_TRANSFORM_EN 0x0000192c #define NVC0_3D_VIEW_VOLUME_CLIP_CTRL 0x0000193c @@ -1220,8 +1234,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define NVC0_3D_TFB_VARYING_LOCS__ESIZE 0x00000004 #define NVC0_3D_TFB_VARYING_LOCS__LEN 0x00000020 -#define NVC0_3D_COLOR_MASK_BROADCAST 0x00003808 - #define NVC0_3D_VERTEX_ARRAY_SELECT 0x00003820 #define NVC0_3D_BLEND_ENABLES 0x00003858 diff --git a/src/gallium/drivers/nvc0/nvc0_context.c b/src/gallium/drivers/nvc0/nvc0_context.c index 5d2168e600b..2f2a3da7c44 100644 --- a/src/gallium/drivers/nvc0/nvc0_context.c +++ b/src/gallium/drivers/nvc0/nvc0_context.c @@ -47,6 +47,15 @@ nvc0_flush(struct pipe_context *pipe, } static void +nvc0_texture_barrier(struct pipe_context *pipe) +{ + struct nouveau_channel *chan = nvc0_context(pipe)->screen->base.channel; + + IMMED_RING(chan, RING_3D(SERIALIZE), 0); + IMMED_RING(chan, RING_3D(TEX_CACHE_CTL), 0); +} + +static void nvc0_context_unreference_resources(struct nvc0_context *nvc0) { unsigned s, i; @@ -128,6 +137,7 @@ nvc0_create(struct pipe_screen *pscreen, void *priv) pipe->clear = nvc0_clear; pipe->flush = nvc0_flush; + pipe->texture_barrier = nvc0_texture_barrier; if (!screen->cur_ctx) screen->cur_ctx = nvc0; diff --git a/src/gallium/drivers/nvc0/nvc0_context.h b/src/gallium/drivers/nvc0/nvc0_context.h index 102997e4fcb..f97141dd46e 100644 --- a/src/gallium/drivers/nvc0/nvc0_context.h +++ b/src/gallium/drivers/nvc0/nvc0_context.h @@ -1,7 +1,6 @@ #ifndef __NVC0_CONTEXT_H__ #define __NVC0_CONTEXT_H__ -#include <stdio.h> #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_state.h" @@ -13,6 +12,7 @@ #include "draw/draw_vertex.h" +#include "nv50/nv50_debug.h" #include "nvc0_winsys.h" #include "nvc0_stateobj.h" #include "nvc0_screen.h" @@ -26,15 +26,6 @@ #include "nvc0_2d.xml.h" #include "nvc0_m2mf.xml.h" -#define NOUVEAU_ERR(fmt, args...) \ - fprintf(stderr, "%s:%d - "fmt, __FUNCTION__, __LINE__, ##args); - -#ifdef NOUVEAU_DEBUG -# define NOUVEAU_DBG(args...) printf(args); -#else -# define NOUVEAU_DBG(args...) -#endif - #define NVC0_NEW_BLEND (1 << 0) #define NVC0_NEW_RASTERIZER (1 << 1) #define NVC0_NEW_ZSA (1 << 2) diff --git a/src/gallium/drivers/nvc0/nvc0_formats.c b/src/gallium/drivers/nvc0/nvc0_formats.c index 454c7440631..678e9b563ee 100644 --- a/src/gallium/drivers/nvc0/nvc0_formats.c +++ b/src/gallium/drivers/nvc0/nvc0_formats.c @@ -145,24 +145,64 @@ const struct nvc0_format nvc0_format_table[PIPE_FORMAT_COUNT] = [PIPE_FORMAT_L8_SRGB] = { NV50_SURFACE_FORMAT_R8_UNORM, A_(C0, C0, C0, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, 8, 0), - SAMPLER_VIEW }, + SAMPLER_VIEW | RENDER_TARGET }, - [PIPE_FORMAT_I8_UNORM] = { NV50_SURFACE_FORMAT_R8_UNORM, - A_(C0, C0, C0, C0, UNORM, UNORM, UNORM, UNORM, 8, 0), + [PIPE_FORMAT_L16_SNORM] = { NV50_SURFACE_FORMAT_R16_SNORM, + B_(C0, C0, C0, ONE_FLOAT, SNORM, SNORM, SNORM, SNORM, 16, 0), SAMPLER_VIEW | RENDER_TARGET }, - [PIPE_FORMAT_I16_UNORM] = { NV50_SURFACE_FORMAT_R16_UNORM, - A_(C0, C0, C0, C0, UNORM, UNORM, UNORM, UNORM, 16, 0), + [PIPE_FORMAT_L16_FLOAT] = { NV50_SURFACE_FORMAT_R16_FLOAT, + B_(C0, C0, C0, ONE_FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, 16, 0), SAMPLER_VIEW | RENDER_TARGET }, + [PIPE_FORMAT_L32_FLOAT] = { NV50_SURFACE_FORMAT_R32_FLOAT, + B_(C0, C0, C0, ONE_FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, 32, 0), + SAMPLER_VIEW | RENDER_TARGET }, + + [PIPE_FORMAT_I8_UNORM] = { 0, + A_(C0, C0, C0, C0, UNORM, UNORM, UNORM, UNORM, 8, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I16_UNORM] = { 0, + A_(C0, C0, C0, C0, UNORM, UNORM, UNORM, UNORM, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I16_SNORM] = { 0, + B_(C0, C0, C0, C0, SNORM, SNORM, SNORM, SNORM, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I16_FLOAT] = { 0, + B_(C0, C0, C0, C0, FLOAT, FLOAT, FLOAT, FLOAT, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_I32_FLOAT] = { 0, + B_(C0, C0, C0, C0, FLOAT, FLOAT, FLOAT, FLOAT, 32, 0), + SAMPLER_VIEW }, + [PIPE_FORMAT_A8_UNORM] = { NV50_SURFACE_FORMAT_A8_UNORM, A_(ZERO, ZERO, ZERO, C0, UNORM, UNORM, UNORM, UNORM, 8, 0), SAMPLER_VIEW | RENDER_TARGET }, + [PIPE_FORMAT_A8_SNORM] = { 0, + A_(ZERO, ZERO, ZERO, C0, SNORM, SNORM, SNORM, SNORM, 8, 0), + SAMPLER_VIEW }, + [PIPE_FORMAT_A16_UNORM] = { 0, A_(ZERO, ZERO, ZERO, C0, UNORM, UNORM, UNORM, UNORM, 16, 0), SAMPLER_VIEW }, + [PIPE_FORMAT_A16_SNORM] = { 0, + A_(ZERO, ZERO, ZERO, C0, SNORM, SNORM, SNORM, SNORM, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_A16_FLOAT] = { 0, + B_(ZERO, ZERO, ZERO, C0, FLOAT, FLOAT, FLOAT, FLOAT, 16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_A32_FLOAT] = { 0, + B_(ZERO, ZERO, ZERO, C0, FLOAT, FLOAT, FLOAT, FLOAT, 32, 0), + SAMPLER_VIEW }, + [PIPE_FORMAT_L8A8_UNORM] = { 0, A_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 8_8, 0), SAMPLER_VIEW }, @@ -175,6 +215,18 @@ const struct nvc0_format nvc0_format_table[PIPE_FORMAT_COUNT] = A_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 16_16, 0), SAMPLER_VIEW }, + [PIPE_FORMAT_L16A16_SNORM] = { 0, + A_(C0, C0, C0, C1, SNORM, SNORM, SNORM, SNORM, 16_16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_L16A16_FLOAT] = { 0, + B_(C0, C0, C0, C1, FLOAT, FLOAT, FLOAT, FLOAT, 16_16, 0), + SAMPLER_VIEW }, + + [PIPE_FORMAT_L32A32_FLOAT] = { 0, + B_(C0, C0, C0, C1, FLOAT, FLOAT, FLOAT, FLOAT, 32_32, 0), + SAMPLER_VIEW }, + [PIPE_FORMAT_L4A4_UNORM] = { 0, B_(C0, C0, C0, C1, UNORM, UNORM, UNORM, UNORM, 4_4, 0), SAMPLER_VIEW }, @@ -322,7 +374,7 @@ const struct nvc0_format nvc0_format_table[PIPE_FORMAT_COUNT] = VERTEX_BUFFER | SAMPLER_VIEW }, [PIPE_FORMAT_R16G16_SNORM] = { NV50_SURFACE_FORMAT_R16G16_SNORM, - A_(C0, C1, C2, C3, SNORM, SNORM, SNORM, SNORM, 16_16, 0), + A_(C0, C1, ZERO, ONE_FLOAT, SNORM, SNORM, SNORM, SNORM, 16_16, 0), VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, [PIPE_FORMAT_R16_SNORM] = { NV50_SURFACE_FORMAT_R16_SNORM, @@ -340,7 +392,7 @@ const struct nvc0_format nvc0_format_table[PIPE_FORMAT_COUNT] = VERTEX_BUFFER | SAMPLER_VIEW }, [PIPE_FORMAT_R16G16_UNORM] = { NV50_SURFACE_FORMAT_R16G16_UNORM, - A_(C0, C1, C2, C3, UNORM, UNORM, UNORM, UNORM, 16_16, 0), + A_(C0, C1, ZERO, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, 16_16, 0), VERTEX_BUFFER | SAMPLER_VIEW | RENDER_TARGET }, [PIPE_FORMAT_R16_UNORM] = { NV50_SURFACE_FORMAT_R16_UNORM, @@ -520,4 +572,8 @@ const struct nvc0_format nvc0_format_table[PIPE_FORMAT_COUNT] = [PIPE_FORMAT_R1_UNORM] = { 0, B_(C0, ZERO, ZERO, ONE_FLOAT, UNORM, UNORM, UNORM, UNORM, BITMAP_8X8, 0), SAMPLER_VIEW }, + + [PIPE_FORMAT_A8B8G8R8_UNORM] = { 0, + B_(C3, C2, C1, C0, UNORM, UNORM, UNORM, UNORM, 8_8_8_8, 0), + SAMPLER_VIEW }, }; diff --git a/src/gallium/drivers/nvc0/nvc0_graph_macros.h b/src/gallium/drivers/nvc0/nvc0_graph_macros.h index b7d0d3eafa4..a0a875fe627 100644 --- a/src/gallium/drivers/nvc0/nvc0_graph_macros.h +++ b/src/gallium/drivers/nvc0/nvc0_graph_macros.h @@ -68,19 +68,6 @@ static const uint32_t nvc0_9097_vertex_array_select[] = 0x00001841, /* 0x0b: send $r3 */ }; -static const uint32_t nvc0_9097_color_mask_brdc[] = -{ - 0x05a00021, /* maddr [NVC0_3D_COLOR_MASK(0), increment = 4] */ - 0x00000841, /* send $r1 */ - 0x00000841, /* send $r1 */ - 0x00000841, /* send $r1 */ - 0x00000841, /* send $r1 */ - 0x00000841, /* send $r1 */ - 0x00000841, /* send $r1 */ - 0x000008c1, /* exit send $r1 */ - 0x00000841, /* send $r1 */ -}; - /* * [GL_POLYGON_MODE_FRONT] = arg; * diff --git a/src/gallium/drivers/nvc0/nvc0_pc.c b/src/gallium/drivers/nvc0/nvc0_pc.c index bd85a7f1ffd..2c3b8555f32 100644 --- a/src/gallium/drivers/nvc0/nvc0_pc.c +++ b/src/gallium/drivers/nvc0/nvc0_pc.c @@ -20,8 +20,6 @@ * SOFTWARE. */ -#define NOUVEAU_DEBUG 1 - #include "nvc0_pc.h" #include "nvc0_program.h" @@ -262,7 +260,7 @@ nvc0_print_program(struct nv_pc *pc) nvc0_print_function(pc->root[i]); } -#if NOUVEAU_DEBUG > 1 +#if NV50_DEBUG & NV50_DEBUG_PROG_CFLOW static void nv_do_print_cfgraph(struct nv_pc *pc, FILE *f, struct nv_basic_block *b) { @@ -327,7 +325,7 @@ nvc0_pc_print_binary(struct nv_pc *pc) { unsigned i; - NOUVEAU_DBG("nvc0_pc_print_binary(%u ops)\n", pc->emit_size / 8); + NV50_DBGMSG(SHADER, "nvc0_pc_print_binary(%u ops)\n", pc->emit_size / 8); for (i = 0; i < pc->emit_size / 4; i += 2) { debug_printf("0x%08x ", pc->emit[i + 0]); @@ -344,7 +342,7 @@ nvc0_emit_program(struct nv_pc *pc) uint32_t *code = pc->emit; int n; - NOUVEAU_DBG("emitting program: size = %u\n", pc->emit_size); + NV50_DBGMSG(SHADER, "emitting program: size = %u\n", pc->emit_size); pc->emit_pos = 0; for (n = 0; n < pc->num_blocks; ++n) { @@ -365,11 +363,10 @@ nvc0_emit_program(struct nv_pc *pc) pc->emit = code; -#ifdef NOUVEAU_DEBUG +#if NV50_DEBUG & NV50_DEBUG_SHADER nvc0_pc_print_binary(pc); -#else - debug_printf("not printing binary\n"); #endif + return 0; } @@ -396,7 +393,7 @@ nvc0_generate_code(struct nvc0_translation_info *ti) ret = nvc0_tgsi_to_nc(pc, ti); if (ret) goto out; -#if NOUVEAU_DEBUG > 1 +#if NV50_DEBUG & NV50_DEBUG_PROG_IR nvc0_print_program(pc); #endif @@ -406,7 +403,7 @@ nvc0_generate_code(struct nvc0_translation_info *ti) ret = nvc0_pc_exec_pass0(pc); if (ret) goto out; -#ifdef NOUVEAU_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_IR nvc0_print_program(pc); #endif @@ -414,7 +411,7 @@ nvc0_generate_code(struct nvc0_translation_info *ti) ret = nvc0_pc_exec_pass1(pc); if (ret) goto out; -#if NOUVEAU_DEBUG > 1 +#if NV50_DEBUG & NV50_DEBUG_PROG_CFLOW nvc0_print_program(pc); nv_print_cfgraph(pc, "nvc0_shader_cfgraph.dot", 0); #endif @@ -444,7 +441,7 @@ nvc0_generate_code(struct nvc0_translation_info *ti) ti->prog->relocs = pc->reloc_entries; ti->prog->num_relocs = pc->num_relocs; - NOUVEAU_DBG("SHADER TRANSLATION - %s\n", ret ? "failure" : "success"); + NV50_DBGMSG(SHADER, "SHADER TRANSLATION - %s\n", ret ? "failed" : "success"); out: nv_pc_free_refs(pc); @@ -573,7 +570,7 @@ nvc0_insn_delete(struct nv_instruction *nvi) if (nvi == b->phi) { if (nvi->opcode != NV_OP_PHI) - NOUVEAU_DBG("NOTE: b->phi points to non-PHI instruction\n"); + NV50_DBGMSG(PROG_IR, "NOTE: b->phi points to non-PHI instruction\n"); assert(!nvi->prev); if (!nvi->next || nvi->next->opcode != NV_OP_PHI) diff --git a/src/gallium/drivers/nvc0/nvc0_pc.h b/src/gallium/drivers/nvc0/nvc0_pc.h index 3a5612a5fac..441692d766c 100644 --- a/src/gallium/drivers/nvc0/nvc0_pc.h +++ b/src/gallium/drivers/nvc0/nvc0_pc.h @@ -23,20 +23,7 @@ #ifndef __NVC0_COMPILER_H__ #define __NVC0_COMPILER_H__ -#include <stdio.h> - -#ifndef NOUVEAU_DBG -#ifdef NOUVEAU_DEBUG -# define NOUVEAU_DBG(args...) debug_printf(args); -#else -# define NOUVEAU_DBG(args...) -#endif -#endif - -#ifndef NOUVEAU_ERR -#define NOUVEAU_ERR(fmt, args...) \ - fprintf(stderr, "%s:%d - "fmt, __FUNCTION__, __LINE__, ##args); -#endif +#include "nv50/nv50_debug.h" #include "pipe/p_defines.h" #include "util/u_inlines.h" diff --git a/src/gallium/drivers/nvc0/nvc0_pc_emit.c b/src/gallium/drivers/nvc0/nvc0_pc_emit.c index 76ad40dbcf8..e35653280a1 100644 --- a/src/gallium/drivers/nvc0/nvc0_pc_emit.c +++ b/src/gallium/drivers/nvc0/nvc0_pc_emit.c @@ -715,6 +715,10 @@ emit_interp(struct nv_pc *pc, struct nv_instruction *i) if (i->opcode == NV_OP_PINTERP) { pc->emit[0] |= 0x040; SID(pc, i->src[1], 26); + + if (i->src[0]->value->reg.address >= 0x280 && + i->src[0]->value->reg.address <= 0x29c) + pc->emit[0] |= 0x080; /* XXX: ? */ } else { SID(pc, NULL, 26); } @@ -875,7 +879,9 @@ emit_st(struct nv_pc *pc, struct nv_instruction *i) void nvc0_emit_instruction(struct nv_pc *pc, struct nv_instruction *i) { +#if NV50_DEBUG & NV50_DEBUG_SHADER debug_printf("EMIT: "); nvc0_print_instruction(i); +#endif switch (i->opcode) { case NV_OP_VFETCH: diff --git a/src/gallium/drivers/nvc0/nvc0_pc_optimize.c b/src/gallium/drivers/nvc0/nvc0_pc_optimize.c index f7bf1680d09..7f5fbaff690 100644 --- a/src/gallium/drivers/nvc0/nvc0_pc_optimize.c +++ b/src/gallium/drivers/nvc0/nvc0_pc_optimize.c @@ -115,7 +115,7 @@ inst_is_noop(struct nv_instruction *nvi) return FALSE; if (nvi->src[0]->value->join->reg.id < 0) { - NOUVEAU_DBG("inst_is_noop: orphaned value detected\n"); + NV50_DBGMSG(PROG_IR, "inst_is_noop: orphaned value detected\n"); return TRUE; } @@ -178,7 +178,7 @@ nv_pc_pass_pre_emission(void *priv, struct nv_basic_block *b) } pc->emit_size += b->emit_size; -#ifdef NOUVEAU_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_IR if (!b->entry) debug_printf("BB:%i is now empty\n", b->id); else @@ -206,7 +206,7 @@ nvc0_pc_exec_pass2(struct nv_pc *pc) { int i, ret; - NOUVEAU_DBG("preparing %u blocks for emission\n", pc->num_blocks); + NV50_DBGMSG(PROG_IR, "preparing %u blocks for emission\n", pc->num_blocks); pc->num_blocks = 0; /* will reorder bb_list */ diff --git a/src/gallium/drivers/nvc0/nvc0_pc_regalloc.c b/src/gallium/drivers/nvc0/nvc0_pc_regalloc.c index f4afe083e2d..15bebb2134a 100644 --- a/src/gallium/drivers/nvc0/nvc0_pc_regalloc.c +++ b/src/gallium/drivers/nvc0/nvc0_pc_regalloc.c @@ -20,11 +20,11 @@ * SOFTWARE. */ -#define NOUVEAU_DEBUG 1 - -/* #define NVC0_RA_DEBUG_LIVEI */ -/* #define NVC0_RA_DEBUG_LIVE_SETS */ -/* #define NVC0_RA_DEBUG_JOIN */ +#if NV50_DEBUG & NV50_DEBUG_PROG_RA +# define NVC0_RA_DEBUG_LIVEI +# define NVC0_RA_DEBUG_LIVE_SETS +# define NVC0_RA_DEBUG_JOIN +#endif #include "nvc0_pc.h" #include "util/u_simple_list.h" @@ -504,7 +504,9 @@ pass_generate_phi_movs(struct nv_pc_pass *ctx, struct nv_basic_block *b) } if (pn != p && pn->exit) { - ctx->pc->current_block = b->in[n ? 0 : 1]; + assert(!b->in[!n]->exit || b->in[!n]->exit->terminator); + /* insert terminator (branch to ENDIF) in new else block */ + ctx->pc->current_block = pn; ni = new_instruction(ctx->pc, NV_OP_BRA); ni->target = b; ni->terminator = 1; @@ -965,7 +967,7 @@ nv_pc_pass1(struct nv_pc *pc, struct nv_basic_block *root) struct nv_pc_pass *ctx; int i, ret; - NOUVEAU_DBG("REGISTER ALLOCATION - entering\n"); + NV50_DBGMSG(PROG_RA, "REGISTER ALLOCATION - entering\n"); ctx = CALLOC_STRUCT(nv_pc_pass); if (!ctx) @@ -1031,7 +1033,7 @@ nv_pc_pass1(struct nv_pc *pc, struct nv_basic_block *root) for (i = 0; i < pc->num_values; ++i) livei_release(&pc->values[i]); - NOUVEAU_DBG("REGISTER ALLOCATION - leaving\n"); + NV50_DBGMSG(PROG_RA, "REGISTER ALLOCATION - leaving\n"); out: FREE(ctx->insns); diff --git a/src/gallium/drivers/nvc0/nvc0_program.c b/src/gallium/drivers/nvc0/nvc0_program.c index 3c59213176e..bcee027917e 100644 --- a/src/gallium/drivers/nvc0/nvc0_program.c +++ b/src/gallium/drivers/nvc0/nvc0_program.c @@ -23,8 +23,6 @@ #include "pipe/p_shader_tokens.h" #include "pipe/p_defines.h" -#define NOUVEAU_DEBUG - #include "tgsi/tgsi_parse.h" #include "tgsi/tgsi_util.h" #include "tgsi/tgsi_dump.h" @@ -225,6 +223,9 @@ nvc0_interp_mode(const struct tgsi_full_declaration *decl) if (decl->Declaration.Interpolate == TGSI_INTERPOLATE_PERSPECTIVE) mode = NVC0_INTERP_PERSPECTIVE; else + if (decl->Declaration.Semantic && decl->Semantic.Name == TGSI_SEMANTIC_COLOR) + mode = NVC0_INTERP_PERSPECTIVE; + else mode = NVC0_INTERP_LINEAR; if (decl->Declaration.Centroid) @@ -574,7 +575,7 @@ nvc0_prog_scan(struct nvc0_translation_info *ti) int ret; unsigned i; -#ifdef NOUVEAU_DEBUG +#if NV50_DEBUG & NV50_DEBUG_SHADER tgsi_dump(prog->pipe.tokens, 0); #endif @@ -691,12 +692,12 @@ nvc0_program_translate(struct nvc0_program *prog) if (ret) NOUVEAU_ERR("shader translation failed\n"); - { - unsigned i; - for (i = 0; i < sizeof(prog->hdr) / sizeof(prog->hdr[0]); ++i) - debug_printf("HDR[%02lx] = 0x%08x\n", - i * sizeof(prog->hdr[0]), prog->hdr[i]); - } +#if NV50_DEBUG & NV50_DEBUG_SHADER + unsigned i; + for (i = 0; i < sizeof(prog->hdr) / sizeof(prog->hdr[0]); ++i) + debug_printf("HDR[%02lx] = 0x%08x\n", + i * sizeof(prog->hdr[0]), prog->hdr[i]); +#endif out: if (ti->immd32) diff --git a/src/gallium/drivers/nvc0/nvc0_screen.c b/src/gallium/drivers/nvc0/nvc0_screen.c index 1047ba3c337..ca0691d2aee 100644 --- a/src/gallium/drivers/nvc0/nvc0_screen.c +++ b/src/gallium/drivers/nvc0/nvc0_screen.c @@ -20,6 +20,7 @@ * SOFTWARE. */ +#include "util/u_format.h" #include "util/u_format_s3tc.h" #include "pipe/p_screen.h" @@ -39,17 +40,8 @@ nvc0_screen_is_format_supported(struct pipe_screen *pscreen, if (sample_count > 1) return FALSE; - if (!util_format_s3tc_enabled) { - switch (format) { - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - case PIPE_FORMAT_DXT3_RGBA: - case PIPE_FORMAT_DXT5_RGBA: - return FALSE; - default: - break; - } - } + if (!util_format_is_supported(format, bindings)) + return FALSE; /* transfers & shared are always supported */ bindings &= ~(PIPE_BIND_TRANSFER_READ | @@ -93,6 +85,8 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) return 1; case PIPE_CAP_MAX_RENDER_TARGETS: return 8; + case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL: + return 1; case PIPE_CAP_TIMER_QUERY: case PIPE_CAP_OCCLUSION_QUERY: return 1; @@ -113,6 +107,7 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) case PIPE_CAP_PRIMITIVE_RESTART: case PIPE_CAP_TGSI_INSTANCEID: case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: + case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: return 1; default: NOUVEAU_ERR("unknown PIPE_CAP %d\n", param); @@ -291,8 +286,6 @@ nvc0_magic_3d_init(struct nouveau_channel *chan) OUT_RING (chan, 1 << 12); BEGIN_RING(chan, RING_3D_(0x151c), 1); OUT_RING (chan, 1); - BEGIN_RING(chan, RING_3D_(0x020c), 1); - OUT_RING (chan, 1); BEGIN_RING(chan, RING_3D_(0x030c), 1); OUT_RING (chan, 0); BEGIN_RING(chan, RING_3D_(0x0300), 1); @@ -309,11 +302,6 @@ nvc0_magic_3d_init(struct nouveau_channel *chan) OUT_RING (chan, 1); BEGIN_RING(chan, RING_3D_(0x075c), 1); OUT_RING (chan, 3); - - BEGIN_RING(chan, RING_3D_(0x0fac), 1); - OUT_RING (chan, 0); - BEGIN_RING(chan, RING_3D_(0x0f90), 1); - OUT_RING (chan, 0); } static void @@ -445,6 +433,14 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) OUT_RING (chan, NVC0_3D_MULTISAMPLE_MODE_1X); BEGIN_RING(chan, RING_3D(MULTISAMPLE_CTRL), 1); OUT_RING (chan, 0); + BEGIN_RING(chan, RING_3D(LINE_WIDTH_SEPARATE), 1); + OUT_RING (chan, 1); + BEGIN_RING(chan, RING_3D(LINE_LAST_PIXEL), 1); + OUT_RING (chan, 0); + BEGIN_RING(chan, RING_3D(BLEND_SEPARATE_ALPHA), 1); + OUT_RING (chan, 1); + BEGIN_RING(chan, RING_3D(BLEND_ENABLE_COMMON), 1); + OUT_RING (chan, 0); nvc0_magic_3d_init(chan); @@ -452,7 +448,10 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) if (ret) goto fail; - nouveau_resource_init(&screen->text_heap, 0, 1 << 20); + /* XXX: getting a page fault at the end of the code buffer every few + * launches, don't use the last 256 bytes to work around them - prefetch ? + */ + nouveau_resource_init(&screen->text_heap, 0, (1 << 20) - 0x100); ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 1 << 12, 6 << 16, &screen->uniforms); @@ -557,17 +556,6 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) OUT_RING (chan, 8192 << 16); OUT_RING (chan, 8192 << 16); - BEGIN_RING(chan, RING_3D_(0x0fac), 1); - OUT_RING (chan, 0); - BEGIN_RING(chan, RING_3D_(0x3484), 1); - OUT_RING (chan, 0); - BEGIN_RING(chan, RING_3D_(0x0dbc), 1); - OUT_RING (chan, 0x00010000); - BEGIN_RING(chan, RING_3D_(0x0dd8), 1); - OUT_RING (chan, 0xff800006); - BEGIN_RING(chan, RING_3D_(0x3488), 1); - OUT_RING (chan, 0); - #define MK_MACRO(m, n) i = nvc0_graph_set_macro(screen, m, i, sizeof(n), n); i = 0; @@ -577,10 +565,11 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) MK_MACRO(NVC0_3D_GP_SELECT, nvc0_9097_gp_select); MK_MACRO(NVC0_3D_POLYGON_MODE_FRONT, nvc0_9097_poly_mode_front); MK_MACRO(NVC0_3D_POLYGON_MODE_BACK, nvc0_9097_poly_mode_back); - MK_MACRO(NVC0_3D_COLOR_MASK_BROADCAST, nvc0_9097_color_mask_brdc); BEGIN_RING(chan, RING_3D(RASTERIZE_ENABLE), 1); OUT_RING (chan, 1); + BEGIN_RING(chan, RING_3D(RT_SEPARATE_FRAG_DATA), 1); + OUT_RING (chan, 1); BEGIN_RING(chan, RING_3D(GP_SELECT), 1); OUT_RING (chan, 0x40); BEGIN_RING(chan, RING_3D(LAYER), 1); @@ -599,8 +588,6 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev) BEGIN_RING(chan, RING_3D(POINT_RASTER_RULES), 1); OUT_RING (chan, NVC0_3D_POINT_RASTER_RULES_OGL); - BEGIN_RING(chan, RING_3D(FRAG_COLOR_CLAMP_EN), 1); - OUT_RING (chan, 0x11111111); BEGIN_RING(chan, RING_3D(EDGEFLAG_ENABLE), 1); OUT_RING (chan, 1); diff --git a/src/gallium/drivers/nvc0/nvc0_shader_state.c b/src/gallium/drivers/nvc0/nvc0_shader_state.c index 7294eaa222e..287160e0b2a 100644 --- a/src/gallium/drivers/nvc0/nvc0_shader_state.c +++ b/src/gallium/drivers/nvc0/nvc0_shader_state.c @@ -97,8 +97,6 @@ nvc0_vertprog_validate(struct nvc0_context *nvc0) // BEGIN_RING(chan, RING_3D_(0x163c), 1); // OUT_RING (chan, 0); - BEGIN_RING(chan, RING_3D(VERT_COLOR_CLAMP_EN), 1); - OUT_RING (chan, 1); } void diff --git a/src/gallium/drivers/nvc0/nvc0_state.c b/src/gallium/drivers/nvc0/nvc0_state.c index ab68abcfb5a..b0b2065167e 100644 --- a/src/gallium/drivers/nvc0/nvc0_state.c +++ b/src/gallium/drivers/nvc0/nvc0_state.c @@ -93,9 +93,18 @@ nvc0_blend_state_create(struct pipe_context *pipe, SB_IMMED_3D(so, BLEND_INDEPENDENT, cso->independent_blend_enable); + if (!cso->logicop_enable) + SB_IMMED_3D(so, LOGIC_OP_ENABLE, 0); + + if (cso->logicop_enable) { + SB_BEGIN_3D(so, LOGIC_OP_ENABLE, 2); + SB_DATA (so, 1); + SB_DATA (so, nvgl_logicop_func(cso->logicop_func)); + + SB_IMMED_3D(so, BLEND_ENABLES, 0); + } else if (!cso->independent_blend_enable) { - SB_BEGIN_3D(so, BLEND_ENABLES, 1); - SB_DATA (so, cso->rt[0].blend_enable ? 0xff : 0); + SB_IMMED_3D(so, BLEND_ENABLES, cso->rt[0].blend_enable ? 0xff : 0); if (cso->rt[0].blend_enable) { SB_BEGIN_3D(so, BLEND_EQUATION_RGB, 5); @@ -108,7 +117,8 @@ nvc0_blend_state_create(struct pipe_context *pipe, SB_DATA (so, nvc0_blend_fac(cso->rt[0].alpha_dst_factor)); } - SB_BEGIN_3D(so, COLOR_MASK_BROADCAST, 1); + SB_IMMED_3D(so, COLOR_MASK_COMMON, 1); + SB_BEGIN_3D(so, COLOR_MASK(0), 1); SB_DATA (so, nvc0_colormask(cso->rt[0].colormask)); } else { uint8_t en = 0; @@ -126,23 +136,15 @@ nvc0_blend_state_create(struct pipe_context *pipe, SB_DATA (so, nvc0_blend_fac(cso->rt[i].alpha_src_factor)); SB_DATA (so, nvc0_blend_fac(cso->rt[i].alpha_dst_factor)); } - SB_BEGIN_3D(so, BLEND_ENABLES, 1); - SB_DATA (so, en); + SB_IMMED_3D(so, BLEND_ENABLES, en); + SB_IMMED_3D(so, COLOR_MASK_COMMON, 0); SB_BEGIN_3D(so, COLOR_MASK(0), 8); for (i = 0; i < 8; ++i) SB_DATA(so, nvc0_colormask(cso->rt[i].colormask)); } - if (cso->logicop_enable) { - SB_BEGIN_3D(so, LOGIC_OP_ENABLE, 2); - SB_DATA (so, 1); - SB_DATA (so, nvgl_logicop_func(cso->logicop_func)); - } else { - SB_IMMED_3D(so, LOGIC_OP_ENABLE, 0); - } - - assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); + assert(so->size <= (sizeof(so->state) / sizeof(so->state[0]))); return so; } @@ -161,6 +163,7 @@ nvc0_blend_state_delete(struct pipe_context *pipe, void *hwcso) FREE(hwcso); } +/* NOTE: ignoring line_last_pixel, using FALSE (set on screen init) */ static void * nvc0_rasterizer_state_create(struct pipe_context *pipe, const struct pipe_rasterizer_state *cso) @@ -183,19 +186,23 @@ nvc0_rasterizer_state_create(struct pipe_context *pipe, SB_IMMED_3D(so, PROVOKING_VERTEX_LAST, !cso->flatshade_first); SB_IMMED_3D(so, VERTEX_TWO_SIDE_ENABLE, cso->light_twoside); - SB_BEGIN_3D(so, LINE_WIDTH, 1); - SB_DATA (so, fui(cso->line_width)); + SB_IMMED_3D(so, VERT_COLOR_CLAMP_EN, cso->clamp_vertex_color); + SB_BEGIN_3D(so, FRAG_COLOR_CLAMP_EN, 1); + SB_DATA (so, cso->clamp_fragment_color ? 0x11111111 : 0x00000000); + SB_IMMED_3D(so, LINE_SMOOTH_ENABLE, cso->line_smooth); + if (cso->line_smooth) + SB_BEGIN_3D(so, LINE_WIDTH_SMOOTH, 1); + else + SB_BEGIN_3D(so, LINE_WIDTH_ALIASED, 1); + SB_DATA (so, fui(cso->line_width)); - SB_BEGIN_3D(so, LINE_STIPPLE_ENABLE, 1); + SB_IMMED_3D(so, LINE_STIPPLE_ENABLE, cso->line_stipple_enable); if (cso->line_stipple_enable) { - SB_DATA (so, 1); SB_BEGIN_3D(so, LINE_STIPPLE_PATTERN, 1); SB_DATA (so, (cso->line_stipple_pattern << 8) | cso->line_stipple_factor); - } else { - SB_DATA (so, 0); } SB_IMMED_3D(so, VP_POINT_SIZE_EN, cso->point_size_per_vertex); @@ -249,7 +256,7 @@ nvc0_rasterizer_state_create(struct pipe_context *pipe, SB_DATA (so, fui(cso->offset_units * 2.0f)); } - assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); + assert(so->size <= (sizeof(so->state) / sizeof(so->state[0]))); return (void *)so; } @@ -320,7 +327,7 @@ nvc0_zsa_state_create(struct pipe_context *pipe, SB_DATA (so, nvgl_comparison_op(cso->alpha.func)); } - assert(so->size < (sizeof(so->state) / sizeof(so->state[0]))); + assert(so->size <= (sizeof(so->state) / sizeof(so->state[0]))); return (void *)so; } diff --git a/src/gallium/drivers/nvc0/nvc0_state_validate.c b/src/gallium/drivers/nvc0/nvc0_state_validate.c index bb81480bab9..9b2a28150b1 100644 --- a/src/gallium/drivers/nvc0/nvc0_state_validate.c +++ b/src/gallium/drivers/nvc0/nvc0_state_validate.c @@ -1,6 +1,7 @@ +#include "util/u_math.h" + #include "nvc0_context.h" -#include "os/os_time.h" static void nvc0_validate_zcull(struct nvc0_context *nvc0) @@ -156,11 +157,10 @@ static void nvc0_validate_stencil_ref(struct nvc0_context *nvc0) { struct nouveau_channel *chan = nvc0->screen->base.channel; + const ubyte *ref = &nvc0->stencil_ref.ref_value[0]; - BEGIN_RING(chan, RING_3D(STENCIL_FRONT_FUNC_REF), 1); - OUT_RING (chan, nvc0->stencil_ref.ref_value[0]); - BEGIN_RING(chan, RING_3D(STENCIL_BACK_FUNC_REF), 1); - OUT_RING (chan, nvc0->stencil_ref.ref_value[1]); + IMMED_RING(chan, RING_3D(STENCIL_FRONT_FUNC_REF), ref[0]); + IMMED_RING(chan, RING_3D(STENCIL_BACK_FUNC_REF), ref[1]); } static void @@ -214,10 +214,11 @@ nvc0_validate_viewport(struct nvc0_context *nvc0) /* now set the viewport rectangle to viewport dimensions for clipping */ - x = (int)(vp->translate[0] - fabsf(vp->scale[0])); - y = (int)(vp->translate[1] - fabsf(vp->scale[1])); - w = (int)fabsf(2.0f * vp->scale[0]); - h = (int)fabsf(2.0f * vp->scale[1]); + x = util_iround(MAX2(0.0f, vp->translate[0] - fabsf(vp->scale[0]))); + y = util_iround(MAX2(0.0f, vp->translate[1] - fabsf(vp->scale[1]))); + w = util_iround(vp->translate[0] + fabsf(vp->scale[0])) - x; + h = util_iround(vp->translate[1] + fabsf(vp->scale[1])) - y; + zmin = vp->translate[2] - fabsf(vp->scale[2]); zmax = vp->translate[2] + fabsf(vp->scale[2]); diff --git a/src/gallium/drivers/nvc0/nvc0_stateobj.h b/src/gallium/drivers/nvc0/nvc0_stateobj.h index 8222f9375ee..e0fe9df25d7 100644 --- a/src/gallium/drivers/nvc0/nvc0_stateobj.h +++ b/src/gallium/drivers/nvc0/nvc0_stateobj.h @@ -19,19 +19,19 @@ struct nvc0_blend_stateobj { struct pipe_blend_state pipe; int size; - uint32_t state[72]; + uint32_t state[70]; }; struct nvc0_rasterizer_stateobj { struct pipe_rasterizer_state pipe; int size; - uint32_t state[36]; + uint32_t state[38]; }; struct nvc0_zsa_stateobj { struct pipe_depth_stencil_alpha_state pipe; int size; - uint32_t state[29]; + uint32_t state[26]; }; struct nvc0_vertex_element { diff --git a/src/gallium/drivers/nvc0/nvc0_surface.c b/src/gallium/drivers/nvc0/nvc0_surface.c index fc5f45ea25d..6be3702bddc 100644 --- a/src/gallium/drivers/nvc0/nvc0_surface.c +++ b/src/gallium/drivers/nvc0/nvc0_surface.c @@ -27,6 +27,7 @@ #include "util/u_inlines.h" #include "util/u_pack_color.h" #include "util/u_format.h" +#include "util/u_surface.h" #include "nvc0_context.h" #include "nvc0_resource.h" @@ -234,6 +235,13 @@ nvc0_resource_copy_region(struct pipe_context *pipe, int ret; unsigned dst_layer = dstz, src_layer = src_box->z; + /* Fallback for buffers. */ + if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { + util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + return; + } + nv04_resource(dst)->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING; if (src->format == dst->format) { diff --git a/src/gallium/drivers/nvc0/nvc0_tgsi_to_nc.c b/src/gallium/drivers/nvc0/nvc0_tgsi_to_nc.c index a44d330c731..d57be916696 100644 --- a/src/gallium/drivers/nvc0/nvc0_tgsi_to_nc.c +++ b/src/gallium/drivers/nvc0/nvc0_tgsi_to_nc.c @@ -22,8 +22,6 @@ #include <unistd.h> -#define NOUVEAU_DEBUG 1 - #include "pipe/p_shader_tokens.h" #include "tgsi/tgsi_parse.h" #include "tgsi/tgsi_util.h" @@ -200,7 +198,7 @@ static INLINE void bld_warn_uninitialized(struct bld_context *bld, int kind, struct bld_register *reg, struct nv_basic_block *b) { -#ifdef NOUVEAU_DEBUG +#if NV50_DEBUG & NV50_DEBUG_SHADER long i = (reg - &bld->tvs[0][0]) / 4; long c = (reg - &bld->tvs[0][0]) & 3; @@ -259,6 +257,12 @@ fetch_by_bb(struct bld_register *reg, fetch_by_bb(reg, vals, n, b->in[i]); } +static INLINE boolean +nvc0_bblock_is_terminated(struct nv_basic_block *bb) +{ + return bb->exit && bb->exit->terminator; +} + static INLINE struct nv_value * bld_load_imm_u32(struct bld_context *bld, uint32_t u); @@ -1465,7 +1469,7 @@ bld_instruction(struct bld_context *bld, uint opcode = translate_opcode(insn->Instruction.Opcode); uint8_t mask = insn->Dst[0].Register.WriteMask; -#ifdef NOUVEAU_DEBUG +#if NV50_DEBUG & NV50_DEBUG_PROG_IR debug_printf("bld_instruction:"); tgsi_dump_instruction(insn, 1); #endif @@ -1637,8 +1641,7 @@ bld_instruction(struct bld_context *bld, { struct nv_basic_block *b = new_basic_block(bld->pc); - if (bld->pc->current_block->exit && - !bld->pc->current_block->exit->terminator) + if (!nvc0_bblock_is_terminated(bld->pc->current_block)) bld_flow(bld, NV_OP_BRA, NULL, NV_CC_P, b, FALSE); --bld->cond_lvl; diff --git a/src/gallium/drivers/nvfx/nvfx_context.c b/src/gallium/drivers/nvfx/nvfx_context.c index 2bcb93d93e3..2b1510264a1 100644 --- a/src/gallium/drivers/nvfx/nvfx_context.c +++ b/src/gallium/drivers/nvfx/nvfx_context.c @@ -13,7 +13,7 @@ nvfx_flush(struct pipe_context *pipe, struct nvfx_context *nvfx = nvfx_context(pipe); struct nvfx_screen *screen = nvfx->screen; struct nouveau_channel *chan = screen->base.channel; - struct nouveau_grobj *eng3d = screen->eng3d; + /*struct nouveau_grobj *eng3d = screen->eng3d;*/ /* XXX: we need to actually be intelligent here */ /* XXX This flag wasn't set by the state tracker anyway. */ diff --git a/src/gallium/drivers/nvfx/nvfx_screen.c b/src/gallium/drivers/nvfx/nvfx_screen.c index 8742f60c163..4a97dfb9c25 100644 --- a/src/gallium/drivers/nvfx/nvfx_screen.c +++ b/src/gallium/drivers/nvfx/nvfx_screen.c @@ -1,5 +1,6 @@ #include "pipe/p_screen.h" #include "pipe/p_state.h" +#include "util/u_format.h" #include "util/u_format_s3tc.h" #include "util/u_simple_screen.h" @@ -82,6 +83,8 @@ nvfx_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param) return 0; // TODO: implement primitive restart case PIPE_CAP_SHADER_STENCIL_EXPORT: return 0; + case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: + return 0; default: NOUVEAU_ERR("Warning: unknown PIPE_CAP %d\n", param); return 0; @@ -207,6 +210,9 @@ nvfx_screen_is_format_supported(struct pipe_screen *pscreen, { struct nvfx_screen *screen = nvfx_screen(pscreen); + if (!util_format_is_supported(format, bind)) + return FALSE; + if (sample_count > 1) return FALSE; diff --git a/src/gallium/drivers/nvfx/nvfx_surface.c b/src/gallium/drivers/nvfx/nvfx_surface.c index be31853d717..ced26494e15 100644 --- a/src/gallium/drivers/nvfx/nvfx_surface.c +++ b/src/gallium/drivers/nvfx/nvfx_surface.c @@ -33,6 +33,7 @@ #include "util/u_memory.h" #include "util/u_pack_color.h" #include "util/u_blitter.h" +#include "util/u_surface.h" #include "nouveau/nouveau_winsys.h" #include "nouveau/nouveau_screen.h" @@ -252,6 +253,13 @@ nvfx_resource_copy_region(struct pipe_context *pipe, if(!w || !h) return; + /* Fallback for buffers. */ + if (dstr->target == PIPE_BUFFER && srcr->target == PIPE_BUFFER) { + util_resource_copy_region(pipe, dstr, dst_level, dstx, dsty, dstz, + srcr, src_level, src_box); + return; + } + if(copy_threshold < 0) copy_threshold = debug_get_num_option("NOUVEAU_COPY_THRESHOLD", 4); diff --git a/src/gallium/drivers/r300/Makefile b/src/gallium/drivers/r300/Makefile index 66d900ebb5f..c9401b99f1c 100644 --- a/src/gallium/drivers/r300/Makefile +++ b/src/gallium/drivers/r300/Makefile @@ -29,8 +29,7 @@ C_SOURCES = \ r300_transfer.c LIBRARY_INCLUDES = \ - -I$(TOP)/src/mesa/drivers/dri/r300/compiler \ - -I$(TOP)/src/gallium/winsys/drm/radeon/core + -I$(TOP)/src/mesa/drivers/dri/r300/compiler COMPILER_ARCHIVE = $(TOP)/src/mesa/drivers/dri/r300/compiler/libr300compiler.a diff --git a/src/gallium/drivers/r300/SConscript b/src/gallium/drivers/r300/SConscript index b49db937994..3af157a7956 100644 --- a/src/gallium/drivers/r300/SConscript +++ b/src/gallium/drivers/r300/SConscript @@ -6,7 +6,6 @@ env = env.Clone() # add the paths for r300compiler env.Append(CPPPATH = [ '#/src/mesa/drivers/dri/r300/compiler', - '#/src/gallium/winsys/drm/radeon/core', '#/include', '#/src/mesa', ]) diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c index 37b635fd120..1217488bac7 100644 --- a/src/gallium/drivers/r300/r300_blit.c +++ b/src/gallium/drivers/r300/r300_blit.c @@ -23,10 +23,10 @@ #include "r300_context.h" #include "r300_emit.h" #include "r300_texture.h" -#include "r300_winsys.h" #include "util/u_format.h" #include "util/u_pack_color.h" +#include "util/u_surface.h" enum r300_blitter_op /* bitmask */ { @@ -206,7 +206,7 @@ static void r300_clear(struct pipe_context* pipe, (struct r300_hyperz_state*)r300->hyperz_state.state; uint32_t width = fb->width; uint32_t height = fb->height; - boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + boolean can_hyperz = r300->rws->get_value(r300->rws, RADEON_VID_CAN_HYPERZ); uint32_t hyperz_dcv = hyperz->zb_depthclearvalue; /* Enable fast Z clear. @@ -253,17 +253,15 @@ static void r300_clear(struct pipe_context* pipe, } else if (r300->zmask_clear.dirty || r300->hiz_clear.dirty) { /* Just clear zmask and hiz now, this does not use the standard draw * procedure. */ - unsigned dwords; - /* Calculate zmask_clear and hiz_clear atom sizes. */ - r300_update_hyperz_state(r300); - dwords = (r300->zmask_clear.dirty ? r300->zmask_clear.size : 0) + - (r300->hiz_clear.dirty ? r300->hiz_clear.size : 0) + - r300_get_num_cs_end_dwords(r300); + unsigned dwords = + (r300->zmask_clear.dirty ? r300->zmask_clear.size : 0) + + (r300->hiz_clear.dirty ? r300->hiz_clear.size : 0) + + r300_get_num_cs_end_dwords(r300); /* Reserve CS space. */ - if (dwords > (R300_MAX_CMDBUF_DWORDS - r300->cs->cdw)) { - r300_flush(&r300->context, R300_FLUSH_ASYNC, NULL); + if (dwords > (RADEON_MAX_CMDBUF_DWORDS - r300->cs->cdw)) { + r300_flush(&r300->context, RADEON_FLUSH_ASYNC, NULL); } /* Emit clear packets. */ @@ -306,16 +304,10 @@ static void r300_clear_render_target(struct pipe_context *pipe, { struct r300_context *r300 = r300_context(pipe); - r300->hyperz_locked = TRUE; - r300_mark_atom_dirty(r300, &r300->hyperz_state); - r300_blitter_begin(r300, R300_CLEAR_SURFACE); util_blitter_clear_render_target(r300->blitter, dst, rgba, dstx, dsty, width, height); r300_blitter_end(r300); - - r300->hyperz_locked = FALSE; - r300_mark_atom_dirty(r300, &r300->hyperz_state); } /* Clear a region of a depth stencil surface. */ @@ -334,21 +326,14 @@ static void r300_clear_depth_stencil(struct pipe_context *pipe, if (r300->zmask_in_use && !r300->hyperz_locked) { if (fb->zsbuf->texture == dst->texture) { r300_decompress_zmask(r300); - } else { - r300->hyperz_locked = TRUE; - r300_mark_atom_dirty(r300, &r300->hyperz_state); } } + /* XXX Do not decompress ZMask of the currently-set zbuffer. */ r300_blitter_begin(r300, R300_CLEAR_SURFACE); util_blitter_clear_depth_stencil(r300->blitter, dst, clear_flags, depth, stencil, dstx, dsty, width, height); r300_blitter_end(r300); - - if (r300->hyperz_locked) { - r300->hyperz_locked = FALSE; - r300_mark_atom_dirty(r300, &r300->hyperz_state); - } } void r300_decompress_zmask(struct r300_context *r300) @@ -431,13 +416,17 @@ static void r300_resource_copy_region(struct pipe_context *pipe, util_format_description(dst->format); struct pipe_box box; + /* Fallback for buffers. */ + if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { + util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + return; + } + if (r300->zmask_in_use && !r300->hyperz_locked) { if (fb->zsbuf->texture == src || fb->zsbuf->texture == dst) { r300_decompress_zmask(r300); - } else { - r300->hyperz_locked = TRUE; - r300_mark_atom_dirty(r300, &r300->hyperz_state); } } @@ -513,11 +502,6 @@ static void r300_resource_copy_region(struct pipe_context *pipe, r300_resource_set_properties(pipe->screen, src, 0, &old_src); if (old_dst.format != new_dst.format) r300_resource_set_properties(pipe->screen, dst, 0, &old_dst); - - if (r300->hyperz_locked) { - r300->hyperz_locked = FALSE; - r300_mark_atom_dirty(r300, &r300->hyperz_state); - } } void r300_init_blit_functions(struct r300_context *r300) diff --git a/src/gallium/drivers/r300/r300_chipset.c b/src/gallium/drivers/r300/r300_chipset.c index 990acea9f44..4949703120d 100644 --- a/src/gallium/drivers/r300/r300_chipset.c +++ b/src/gallium/drivers/r300/r300_chipset.c @@ -419,4 +419,5 @@ void r300_parse_chipset(struct r300_capabilities* caps) caps->is_rv350 = caps->family >= CHIP_FAMILY_RV350; caps->z_compress = caps->is_rv350 ? R300_ZCOMP_8X8 : R300_ZCOMP_4X4; caps->dxtc_swizzle = caps->is_r400 || caps->is_r500; + caps->has_us_format = caps->family == CHIP_FAMILY_R520; } diff --git a/src/gallium/drivers/r300/r300_chipset.h b/src/gallium/drivers/r300/r300_chipset.h index 68943d561ba..d0050bed2e8 100644 --- a/src/gallium/drivers/r300/r300_chipset.h +++ b/src/gallium/drivers/r300/r300_chipset.h @@ -90,6 +90,8 @@ struct r300_capabilities { boolean high_second_pipe; /* DXTC texture swizzling. */ boolean dxtc_swizzle; + /* Whether R500_US_FORMAT0_0 exists (R520-only and depends on DRM). */ + boolean has_us_format; }; /* Enumerations for legibility and telling which card we're running on. */ diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index 720d666d98c..15d1278c3bb 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -32,7 +32,6 @@ #include "r300_emit.h" #include "r300_screen.h" #include "r300_screen_buffer.h" -#include "r300_winsys.h" static void r300_update_num_contexts(struct r300_screen *r300screen, int diff) @@ -167,8 +166,8 @@ static boolean r300_setup_atoms(struct r300_context* r300) boolean is_rv350 = r300->screen->caps.is_rv350; boolean is_r500 = r300->screen->caps.is_r500; boolean has_tcl = r300->screen->caps.has_tcl; - boolean drm_2_6_0 = r300->rws->get_value(r300->rws, R300_VID_DRM_2_6_0); - boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + boolean drm_2_6_0 = r300->rws->get_value(r300->rws, RADEON_VID_DRM_2_6_0); + boolean can_hyperz = r300->rws->get_value(r300->rws, RADEON_VID_CAN_HYPERZ); boolean has_hiz_ram = r300->screen->caps.hiz_ram > 0; /* Create the actual atom list. @@ -379,7 +378,7 @@ static void r300_init_states(struct pipe_context *pipe) if (r300->screen->caps.is_r500 || (r300->screen->caps.is_rv350 && - r300->rws->get_value(r300->rws, R300_VID_DRM_2_6_0))) { + r300->rws->get_value(r300->rws, RADEON_VID_DRM_2_6_0))) { OUT_CB_REG(R300_GB_Z_PEQ_CONFIG, 0); } END_CB; @@ -391,7 +390,7 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, { struct r300_context* r300 = CALLOC_STRUCT(r300_context); struct r300_screen* r300screen = r300_screen(screen); - struct r300_winsys_screen *rws = r300screen->rws; + struct radeon_winsys *rws = r300screen->rws; if (!r300) return NULL; @@ -514,19 +513,19 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, "r300: DRM version: %d.%d.%d, Name: %s, ID: 0x%04x, GB: %d, Z: %d\n" "r300: GART size: %d MB, VRAM size: %d MB\n" "r300: AA compression: %s, Z compression: %s, HiZ: %s\n", - rws->get_value(rws, R300_VID_DRM_MAJOR), - rws->get_value(rws, R300_VID_DRM_MINOR), - rws->get_value(rws, R300_VID_DRM_PATCHLEVEL), + rws->get_value(rws, RADEON_VID_DRM_MAJOR), + rws->get_value(rws, RADEON_VID_DRM_MINOR), + rws->get_value(rws, RADEON_VID_DRM_PATCHLEVEL), screen->get_name(screen), - rws->get_value(rws, R300_VID_PCI_ID), - rws->get_value(rws, R300_VID_GB_PIPES), - rws->get_value(rws, R300_VID_Z_PIPES), - rws->get_value(rws, R300_VID_GART_SIZE) >> 20, - rws->get_value(rws, R300_VID_VRAM_SIZE) >> 20, - rws->get_value(rws, R300_CAN_AACOMPRESS) ? "YES" : "NO", - rws->get_value(rws, R300_CAN_HYPERZ) && + rws->get_value(rws, RADEON_VID_PCI_ID), + rws->get_value(rws, RADEON_VID_R300_GB_PIPES), + rws->get_value(rws, RADEON_VID_R300_Z_PIPES), + rws->get_value(rws, RADEON_VID_GART_SIZE) >> 20, + rws->get_value(rws, RADEON_VID_VRAM_SIZE) >> 20, + rws->get_value(rws, RADEON_VID_CAN_AACOMPRESS) ? "YES" : "NO", + rws->get_value(rws, RADEON_VID_CAN_HYPERZ) && r300->screen->caps.zmask_ram ? "YES" : "NO", - rws->get_value(rws, R300_CAN_HYPERZ) && + rws->get_value(rws, RADEON_VID_CAN_HYPERZ) && r300->screen->caps.hiz_ram ? "YES" : "NO"); } diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index e395f41290e..8a0a54cf1e9 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -34,7 +34,7 @@ #include "r300_defines.h" #include "r300_screen.h" -#include "r300_winsys.h" +#include "../../winsys/radeon/drm/radeon_winsys.h" struct u_upload_mgr; struct r300_context; @@ -190,6 +190,7 @@ struct r300_texture_format_state { uint32_t format1; /* R300_TX_FORMAT1: 0x44c0 */ uint32_t format2; /* R300_TX_FORMAT2: 0x4500 */ uint32_t tile_config; /* R300_TX_OFFSET (subset thereof) */ + uint32_t us_format0; /* R500_US_FORMAT0_0: 0x4640 (through 15) */ }; struct r300_sampler_view { @@ -211,7 +212,7 @@ struct r300_texture_sampler_state { struct r300_texture_format_state format; uint32_t filter0; /* R300_TX_FILTER0: 0x4400 */ uint32_t filter1; /* R300_TX_FILTER1: 0x4440 */ - uint32_t border_color; /* R300_TX_BORDER_COLOR: 0x45c0 */ + uint32_t border_color; /* R300_TX_BORDER_COLOR: 0x45c0 */ }; struct r300_textures_state { @@ -290,12 +291,12 @@ struct r300_query { boolean begin_emitted; /* The buffer where query results are stored. */ - struct r300_winsys_bo *buf; - struct r300_winsys_cs_handle *cs_buf; + struct pb_buffer *buf; + struct radeon_winsys_cs_handle *cs_buf; /* The size of the buffer. */ unsigned buffer_size; /* The domain of the buffer. */ - enum r300_buffer_domain domain; + enum radeon_bo_domain domain; /* Linked list members. */ struct r300_query* prev; @@ -306,10 +307,10 @@ struct r300_surface { struct pipe_surface base; /* Winsys buffer backing the texture. */ - struct r300_winsys_bo *buf; - struct r300_winsys_cs_handle *cs_buf; + struct pb_buffer *buf; + struct radeon_winsys_cs_handle *cs_buf; - enum r300_buffer_domain domain; + enum radeon_bo_domain domain; uint32_t offset; /* COLOROFFSET or DEPTHOFFSET. */ uint32_t pitch; /* COLORPITCH or DEPTHPITCH. */ @@ -339,8 +340,8 @@ struct r300_texture_desc { /* Buffer tiling. * Macrotiling is specified per-level because small mipmaps cannot * be macrotiled. */ - enum r300_buffer_tiling microtile; - enum r300_buffer_tiling macrotile[R300_MAX_TEXTURE_LEVELS]; + enum radeon_bo_layout microtile; + enum radeon_bo_layout macrotile[R300_MAX_TEXTURE_LEVELS]; /* Offsets into the buffer. */ unsigned offset_in_bytes[R300_MAX_TEXTURE_LEVELS]; @@ -396,9 +397,9 @@ struct r300_resource struct u_vbuf_resource b; /* Winsys buffer backing this resource. */ - struct r300_winsys_bo *buf; - struct r300_winsys_cs_handle *cs_buf; - enum r300_buffer_domain domain; + struct pb_buffer *buf; + struct radeon_winsys_cs_handle *cs_buf; + enum radeon_bo_domain domain; unsigned buf_size; /* Constant buffers are in user memory. */ @@ -447,14 +448,21 @@ enum r300_hiz_func { HIZ_FUNC_MIN, }; +/* For deferred fragment shader state validation. */ +enum r300_fs_validity_status { + FRAGMENT_SHADER_VALID, /* No need to change/validate the FS. */ + FRAGMENT_SHADER_MAYBE_DIRTY,/* Validate the FS if external state was changed. */ + FRAGMENT_SHADER_DIRTY /* Always validate the FS (if the FS was changed) */ +}; + struct r300_context { /* Parent class */ struct pipe_context context; /* The interface to the windowing system, etc. */ - struct r300_winsys_screen *rws; + struct radeon_winsys *rws; /* The command stream. */ - struct r300_winsys_cs *cs; + struct radeon_winsys_cs *cs; /* Screen. */ struct r300_screen *screen; @@ -580,6 +588,8 @@ struct r300_context { int sprite_coord_enable; /* Whether two-sided color selection is enabled (AKA light_twoside). */ boolean two_sided_color; + /* Whether fragment color clamping is enabled. */ + boolean frag_clamp; /* Whether fast color clear is enabled. */ boolean cbzb_clear; /* Whether ZMASK is enabled. */ @@ -596,6 +606,10 @@ struct r300_context { enum r300_hiz_func hiz_func; /* HiZ clear value. */ uint32_t hiz_clear_value; + /* Whether fragment shader needs to be validated. */ + enum r300_fs_validity_status fs_status; + /* Framebuffer multi-write. */ + boolean fb_multiwrite; void *dsa_decompress_zmask; diff --git a/src/gallium/drivers/r300/r300_cs.h b/src/gallium/drivers/r300/r300_cs.h index 2e52dfa43c6..c208e672f42 100644 --- a/src/gallium/drivers/r300/r300_cs.h +++ b/src/gallium/drivers/r300/r300_cs.h @@ -29,7 +29,6 @@ #include "r300_reg.h" #include "r300_context.h" -#include "r300_winsys.h" /* Yes, I know macros are ugly. However, they are much prettier than the code * that they neatly hide away, and don't have the cost of function setup,so @@ -40,14 +39,14 @@ */ #define CS_LOCALS(context) \ - struct r300_winsys_cs *cs_copy = (context)->cs; \ - struct r300_winsys_screen *cs_winsys = (context)->rws; \ + struct radeon_winsys_cs *cs_copy = (context)->cs; \ + struct radeon_winsys *cs_winsys = (context)->rws; \ int cs_count = 0; (void) cs_count; (void) cs_winsys; #ifdef DEBUG #define BEGIN_CS(size) do { \ - assert(size <= (R300_MAX_CMDBUF_DWORDS - cs_copy->cdw)); \ + assert(size <= (RADEON_MAX_CMDBUF_DWORDS - cs_copy->cdw)); \ cs_count = size; \ } while (0) diff --git a/src/gallium/drivers/r300/r300_defines.h b/src/gallium/drivers/r300/r300_defines.h index 2d111f9158d..30e9befad21 100644 --- a/src/gallium/drivers/r300/r300_defines.h +++ b/src/gallium/drivers/r300/r300_defines.h @@ -32,19 +32,4 @@ #define R300_INVALID_FORMAT 0xffff -/* Tiling flags. */ -enum r300_buffer_tiling { - R300_BUFFER_LINEAR = 0, - R300_BUFFER_TILED, - R300_BUFFER_SQUARETILED, - - R300_BUFFER_UNKNOWN, - R300_BUFFER_SELECT_LAYOUT = R300_BUFFER_UNKNOWN -}; - -enum r300_buffer_domain { /* bitfield */ - R300_DOMAIN_GTT = 2, - R300_DOMAIN_VRAM = 4 -}; - #endif diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index e17a907e77e..62435c5e2e2 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -375,7 +375,7 @@ void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state) struct pipe_framebuffer_state* fb = (struct pipe_framebuffer_state*)state; struct r300_surface* surf; unsigned i; - boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + boolean can_hyperz = r300->rws->get_value(r300->rws, RADEON_VID_CAN_HYPERZ); uint32_t rb3d_cctl = 0; CS_LOCALS(r300); @@ -387,8 +387,7 @@ void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state) if (r300->screen->caps.is_r500) { rb3d_cctl = R300_RB3D_CCTL_INDEPENDENT_COLORFORMAT_ENABLE_ENABLE; } - if (fb->nr_cbufs && - r300_fragment_shader_writes_all(r300_fs(r300))) { + if (fb->nr_cbufs && r300->fb_multiwrite) { rb3d_cctl |= R300_RB3D_CCTL_NUM_MULTIWRITES(fb->nr_cbufs); } @@ -483,7 +482,7 @@ void r300_emit_fb_state_pipelined(struct r300_context *r300, /* If we use the multiwrite feature, the colorbuffers 2,3,4 must be * marked as UNUSED in the US block. */ - if (r300_fragment_shader_writes_all(r300_fs(r300))) { + if (r300->fb_multiwrite) { num_cbufs = MIN2(num_cbufs, 1); } @@ -495,6 +494,11 @@ void r300_emit_fb_state_pipelined(struct r300_context *r300, for (i = 0; i < num_cbufs; i++) { OUT_CS(r300_surface(fb->cbufs[i])->format); } + for (; i < 1; i++) { + OUT_CS(R300_US_OUT_FMT_C4_8 | + R300_C0_SEL_B | R300_C1_SEL_G | + R300_C2_SEL_R | R300_C3_SEL_A); + } for (; i < 4; i++) { OUT_CS(R300_US_OUT_FMT_UNUSED); } @@ -771,6 +775,7 @@ void r300_emit_textures_state(struct r300_context *r300, struct r300_texture_sampler_state *texstate; struct r300_resource *tex; unsigned i; + boolean has_us_format = r300->screen->caps.has_us_format; CS_LOCALS(r300); BEGIN_CS(size); @@ -792,6 +797,11 @@ void r300_emit_textures_state(struct r300_context *r300, OUT_CS_REG(R300_TX_OFFSET_0 + (i * 4), texstate->format.tile_config); OUT_CS_RELOC(tex); + + if (has_us_format) { + OUT_CS_REG(R500_US_FORMAT0_0 + (i * 4), + texstate->format.us_format0); + } } } END_CS; @@ -1221,7 +1231,7 @@ validate: if (flushed) return FALSE; - r300_flush(&r300->context, R300_FLUSH_ASYNC, NULL); + r300_flush(&r300->context, RADEON_FLUSH_ASYNC, NULL); flushed = TRUE; goto validate; } diff --git a/src/gallium/drivers/r300/r300_flush.c b/src/gallium/drivers/r300/r300_flush.c index b3d0d344ec4..de7d77d608b 100644 --- a/src/gallium/drivers/r300/r300_flush.c +++ b/src/gallium/drivers/r300/r300_flush.c @@ -38,7 +38,7 @@ void r300_flush(struct pipe_context *pipe, { struct r300_context *r300 = r300_context(pipe); struct r300_atom *atom; - struct r300_winsys_bo **rfence = (struct r300_winsys_bo**)fence; + struct pb_buffer **rfence = (struct pb_buffer**)fence; if (r300->draw && !r300->draw_vbo_locked) r300_draw_flush_vbuf(r300); @@ -48,11 +48,11 @@ void r300_flush(struct pipe_context *pipe, *rfence = r300->rws->buffer_create(r300->rws, 1, 1, PIPE_BIND_VERTEX_BUFFER, PIPE_USAGE_STATIC, - R300_DOMAIN_GTT); + RADEON_DOMAIN_GTT); /* Add the fence as a dummy relocation. */ r300->rws->cs_add_reloc(r300->cs, r300->rws->buffer_get_cs_handle(*rfence), - R300_DOMAIN_GTT, R300_DOMAIN_GTT); + RADEON_DOMAIN_GTT, RADEON_DOMAIN_GTT); } if (r300->dirty_hw) { diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c index 4c502fefb3f..e3a1bc4a0f4 100644 --- a/src/gallium/drivers/r300/r300_fs.c +++ b/src/gallium/drivers/r300/r300_fs.c @@ -22,6 +22,7 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" @@ -34,6 +35,7 @@ #include "r300_screen.h" #include "r300_fs.h" #include "r300_reg.h" +#include "r300_texture.h" #include "r300_tgsi_to_rc.h" #include "radeon_code.h" @@ -146,10 +148,10 @@ static void get_external_state( struct r300_fragment_program_external_state* state) { struct r300_textures_state *texstate = r300->textures_state.state; + struct r300_rs_state *rs = r300->rs_state.state; unsigned i; - unsigned char *swizzle; - state->frag_clamp = 0; + state->frag_clamp = rs ? rs->rs.clamp_fragment_color : 0; for (i = 0; i < texstate->sampler_state_count; i++) { struct r300_sampler_state *s = texstate->sampler_states[i]; @@ -160,27 +162,37 @@ static void get_external_state( continue; } - t = r300_resource(texstate->sampler_views[i]->base.texture); + t = r300_resource(v->base.texture); if (s->state.compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) { state->unit[i].compare_mode_enabled = 1; - /* Pass depth texture swizzling to the compiler. */ - if (texstate->sampler_views[i]) { - swizzle = texstate->sampler_views[i]->swizzle; - - state->unit[i].depth_texture_swizzle = - RC_MAKE_SWIZZLE(swizzle[0], swizzle[1], - swizzle[2], swizzle[3]); - } else { - state->unit[i].depth_texture_swizzle = RC_SWIZZLE_XYZW; - } - /* Fortunately, no need to translate this. */ state->unit[i].texture_compare_func = s->state.compare_func; } state->unit[i].non_normalized_coords = !s->state.normalized_coords; + state->unit[i].convert_unorm_to_snorm = + v->base.format == PIPE_FORMAT_RGTC1_SNORM || + v->base.format == PIPE_FORMAT_LATC1_SNORM; + + /* Pass texture swizzling to the compiler, some lowering passes need it. */ + if (v->base.format == PIPE_FORMAT_RGTC1_SNORM || + v->base.format == PIPE_FORMAT_LATC1_SNORM) { + unsigned char swizzle[4]; + + util_format_combine_swizzles(swizzle, + util_format_description(v->base.format)->swizzle, + v->swizzle); + + state->unit[i].texture_swizzle = + RC_MAKE_SWIZZLE(swizzle[0], swizzle[1], + swizzle[2], swizzle[3]); + } else if (state->unit[i].compare_mode_enabled) { + state->unit[i].texture_swizzle = + RC_MAKE_SWIZZLE(v->swizzle[0], v->swizzle[1], + v->swizzle[2], v->swizzle[3]); + } /* XXX this should probably take into account STR, not just S. */ if (t->tex.is_npot) { diff --git a/src/gallium/drivers/r300/r300_hyperz.c b/src/gallium/drivers/r300/r300_hyperz.c index ecaadf4af8e..ef330f34c9e 100644 --- a/src/gallium/drivers/r300/r300_hyperz.c +++ b/src/gallium/drivers/r300/r300_hyperz.c @@ -24,7 +24,6 @@ #include "r300_context.h" #include "r300_reg.h" #include "r300_fs.h" -#include "r300_winsys.h" #include "util/u_format.h" #include "util/u_mm.h" @@ -153,7 +152,7 @@ static void r300_update_hyperz(struct r300_context* r300) } if (!zstex || - !r300->rws->get_value(r300->rws, R300_CAN_HYPERZ)) + !r300->rws->get_value(r300->rws, RADEON_VID_CAN_HYPERZ)) return; /* Zbuffer compression. */ diff --git a/src/gallium/drivers/r300/r300_public.h b/src/gallium/drivers/r300/r300_public.h index 8e7a963c55d..b6059203ff1 100644 --- a/src/gallium/drivers/r300/r300_public.h +++ b/src/gallium/drivers/r300/r300_public.h @@ -2,8 +2,8 @@ #ifndef R300_PUBLIC_H #define R300_PUBLIC_H -struct r300_winsys_screen; +struct radeon_winsys; -struct pipe_screen* r300_screen_create(struct r300_winsys_screen *rws); +struct pipe_screen* r300_screen_create(struct radeon_winsys *rws); #endif diff --git a/src/gallium/drivers/r300/r300_query.c b/src/gallium/drivers/r300/r300_query.c index 717485f43cb..9752a519491 100644 --- a/src/gallium/drivers/r300/r300_query.c +++ b/src/gallium/drivers/r300/r300_query.c @@ -26,7 +26,6 @@ #include "r300_context.h" #include "r300_screen.h" #include "r300_emit.h" -#include "r300_winsys.h" #include <stdio.h> @@ -46,7 +45,7 @@ static struct pipe_query *r300_create_query(struct pipe_context *pipe, return NULL; q->type = query_type; - q->domain = R300_DOMAIN_GTT; + q->domain = RADEON_DOMAIN_GTT; q->buffer_size = 4096; if (r300screen->caps.family == CHIP_FAMILY_RV530) @@ -70,7 +69,7 @@ static void r300_destroy_query(struct pipe_context* pipe, { struct r300_query* q = r300_query(query); - r300_winsys_bo_reference(&q->buf, NULL); + pb_reference(&q->buf, NULL); remove_from_list(q); FREE(query); } diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 26594dabe42..429b85545f7 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -218,8 +218,8 @@ static boolean r300_reserve_cs_dwords(struct r300_context *r300, cs_dwords += r300_get_num_cs_end_dwords(r300); /* Reserve requested CS space. */ - if (cs_dwords > (R300_MAX_CMDBUF_DWORDS - r300->cs->cdw)) { - r300_flush(&r300->context, R300_FLUSH_ASYNC, NULL); + if (cs_dwords > (RADEON_MAX_CMDBUF_DWORDS - r300->cs->cdw)) { + r300_flush(&r300->context, RADEON_FLUSH_ASYNC, NULL); flushed = TRUE; } @@ -343,7 +343,7 @@ static boolean immd_is_good_idea(struct r300_context *r300, if (!checked[vbi]) { buf = r300->vbuf_mgr->real_vertex_buffer[vbi]; - if ((r300_resource(buf)->domain != R300_DOMAIN_GTT)) { + if ((r300_resource(buf)->domain != RADEON_DOMAIN_GTT)) { return FALSE; } @@ -1080,7 +1080,7 @@ static void r300_render_draw_elements(struct vbuf_render* render, end_cs_dwords = r300_get_num_cs_end_dwords(r300); while (count) { - free_dwords = R300_MAX_CMDBUF_DWORDS - r300->cs->cdw; + free_dwords = RADEON_MAX_CMDBUF_DWORDS - r300->cs->cdw; short_count = MIN2(count, (free_dwords - end_cs_dwords - 6) * 2); diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index 8a69628c53e..9ec16c6562f 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -30,7 +30,6 @@ #include "r300_texture.h" #include "r300_screen_buffer.h" #include "r300_state_inlines.h" -#include "r300_winsys.h" #include "r300_public.h" #include "draw/draw_context.h" @@ -114,9 +113,12 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param) case PIPE_CAP_TEXTURE_MIRROR_REPEAT: case PIPE_CAP_BLEND_EQUATION_SEPARATE: case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: - return 1; + case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL: + return is_r500 ? 1 : 0; case PIPE_CAP_TEXTURE_SWIZZLE: return util_format_s3tc_enabled ? r300screen->caps.dxtc_swizzle : 1; + case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: + return is_r500 ? 1 : 0; /* Unsupported features (boolean caps). */ case PIPE_CAP_TIMER_QUERY: @@ -127,12 +129,12 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param) case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: case PIPE_CAP_SHADER_STENCIL_EXPORT: case PIPE_CAP_ARRAY_TEXTURES: + case PIPE_CAP_TGSI_INSTANCEID: return 0; /* SWTCL-only features. */ case PIPE_CAP_STREAM_OUTPUT: case PIPE_CAP_PRIMITIVE_RESTART: - case PIPE_CAP_TGSI_INSTANCEID: return !r300screen->caps.has_tcl; /* Texturing. */ @@ -209,7 +211,7 @@ static int r300_get_shader_param(struct pipe_screen *pscreen, unsigned shader, e case PIPE_SHADER_CAP_MAX_PREDS: return is_r500 ? 1 : 0; case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: - return 1; + return 0; case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: @@ -247,7 +249,7 @@ static int r300_get_shader_param(struct pipe_screen *pscreen, unsigned shader, e case PIPE_SHADER_CAP_MAX_PREDS: return is_r500 ? 4 : 0; /* XXX guessed. */ case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED: - return 1; + return 0; case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR: case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR: case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR: @@ -308,9 +310,9 @@ static boolean r300_is_format_supported(struct pipe_screen* screen, unsigned sample_count, unsigned usage) { - struct r300_winsys_screen *rws = r300_screen(screen)->rws; + struct radeon_winsys *rws = r300_screen(screen)->rws; uint32_t retval = 0; - boolean drm_2_8_0 = rws->get_value(rws, R300_VID_DRM_2_8_0); + boolean drm_2_8_0 = rws->get_value(rws, RADEON_VID_DRM_2_8_0); boolean is_r500 = r300_screen(screen)->caps.is_r500; boolean is_r400 = r300_screen(screen)->caps.is_r400; boolean is_color2101010 = format == PIPE_FORMAT_R10G10B10A2_UNORM || @@ -325,11 +327,20 @@ static boolean r300_is_format_supported(struct pipe_screen* screen, format == PIPE_FORMAT_RGTC2_SNORM || format == PIPE_FORMAT_LATC2_UNORM || format == PIPE_FORMAT_LATC2_SNORM; + boolean is_x16f_xy16f = format == PIPE_FORMAT_R16_FLOAT || + format == PIPE_FORMAT_R16G16_FLOAT || + format == PIPE_FORMAT_A16_FLOAT || + format == PIPE_FORMAT_L16_FLOAT || + format == PIPE_FORMAT_L16A16_FLOAT || + format == PIPE_FORMAT_I16_FLOAT; boolean is_half_float = format == PIPE_FORMAT_R16_FLOAT || format == PIPE_FORMAT_R16G16_FLOAT || format == PIPE_FORMAT_R16G16B16_FLOAT || format == PIPE_FORMAT_R16G16B16A16_FLOAT; + if (!util_format_is_supported(format, usage)) + return FALSE; + /* Check multisampling support. */ switch (sample_count) { case 0: @@ -358,6 +369,8 @@ static boolean r300_is_format_supported(struct pipe_screen* screen, (is_r500 || !is_ati1n) && /* ATI2N is supported on r4xx-r5xx. */ (is_r400 || is_r500 || !is_ati2n) && + /* R16F and RG16F texture support was added in as late as DRM 2.8.0 */ + (drm_2_8_0 || !is_x16f_xy16f) && r300_is_sampler_format_supported(format)) { retval |= PIPE_BIND_SAMPLER_VIEW; } @@ -403,7 +416,7 @@ static boolean r300_is_format_supported(struct pipe_screen* screen, static void r300_destroy_screen(struct pipe_screen* pscreen) { struct r300_screen* r300screen = r300_screen(pscreen); - struct r300_winsys_screen *rws = r300_winsys_screen(pscreen); + struct radeon_winsys *rws = radeon_winsys(pscreen); util_slab_destroy(&r300screen->pool_buffers); pipe_mutex_destroy(r300screen->num_contexts_mutex); @@ -418,15 +431,15 @@ static void r300_fence_reference(struct pipe_screen *screen, struct pipe_fence_handle **ptr, struct pipe_fence_handle *fence) { - r300_winsys_bo_reference((struct r300_winsys_bo**)ptr, - (struct r300_winsys_bo*)fence); + pb_reference((struct pb_buffer**)ptr, + (struct pb_buffer*)fence); } static boolean r300_fence_signalled(struct pipe_screen *screen, struct pipe_fence_handle *fence) { - struct r300_winsys_screen *rws = r300_screen(screen)->rws; - struct r300_winsys_bo *rfence = (struct r300_winsys_bo*)fence; + struct radeon_winsys *rws = r300_screen(screen)->rws; + struct pb_buffer *rfence = (struct pb_buffer*)fence; return !rws->buffer_is_busy(rfence); } @@ -435,8 +448,8 @@ static boolean r300_fence_finish(struct pipe_screen *screen, struct pipe_fence_handle *fence, uint64_t timeout) { - struct r300_winsys_screen *rws = r300_screen(screen)->rws; - struct r300_winsys_bo *rfence = (struct r300_winsys_bo*)fence; + struct radeon_winsys *rws = r300_screen(screen)->rws; + struct pb_buffer *rfence = (struct pb_buffer*)fence; if (timeout != PIPE_TIMEOUT_INFINITE) { int64_t start_time = os_time_get(); @@ -458,7 +471,7 @@ static boolean r300_fence_finish(struct pipe_screen *screen, return TRUE; } -struct pipe_screen* r300_screen_create(struct r300_winsys_screen *rws) +struct pipe_screen* r300_screen_create(struct radeon_winsys *rws) { struct r300_screen *r300screen = CALLOC_STRUCT(r300_screen); @@ -467,9 +480,9 @@ struct pipe_screen* r300_screen_create(struct r300_winsys_screen *rws) return NULL; } - r300screen->caps.pci_id = rws->get_value(rws, R300_VID_PCI_ID); - r300screen->caps.num_frag_pipes = rws->get_value(rws, R300_VID_GB_PIPES); - r300screen->caps.num_z_pipes = rws->get_value(rws, R300_VID_Z_PIPES); + r300screen->caps.pci_id = rws->get_value(rws, RADEON_VID_PCI_ID); + r300screen->caps.num_frag_pipes = rws->get_value(rws, RADEON_VID_R300_GB_PIPES); + r300screen->caps.num_z_pipes = rws->get_value(rws, RADEON_VID_R300_Z_PIPES); r300_init_debug(r300screen); r300_parse_chipset(&r300screen->caps); @@ -479,6 +492,9 @@ struct pipe_screen* r300_screen_create(struct r300_winsys_screen *rws) if (SCREEN_DBG_ON(r300screen, DBG_NO_HIZ)) r300screen->caps.hiz_ram = 0; + if (!rws->get_value(rws, RADEON_VID_DRM_2_8_0)) + r300screen->caps.has_us_format = FALSE; + pipe_mutex_init(r300screen->num_contexts_mutex); util_slab_create(&r300screen->pool_buffers, diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h index 576f9c1f4a9..bca86edb1d7 100644 --- a/src/gallium/drivers/r300/r300_screen.h +++ b/src/gallium/drivers/r300/r300_screen.h @@ -32,13 +32,13 @@ #include <stdio.h> -struct r300_winsys_screen; +struct radeon_winsys; struct r300_screen { /* Parent class */ struct pipe_screen screen; - struct r300_winsys_screen *rws; + struct radeon_winsys *rws; /* Chipset capabilities */ struct r300_capabilities caps; @@ -61,8 +61,8 @@ static INLINE struct r300_screen* r300_screen(struct pipe_screen* screen) { return (struct r300_screen*)screen; } -static INLINE struct r300_winsys_screen * -r300_winsys_screen(struct pipe_screen *screen) { +static INLINE struct radeon_winsys * +radeon_winsys(struct pipe_screen *screen) { return r300_screen(screen)->rws; } diff --git a/src/gallium/drivers/r300/r300_screen_buffer.c b/src/gallium/drivers/r300/r300_screen_buffer.c index 986ae384fbf..4154c81512e 100644 --- a/src/gallium/drivers/r300/r300_screen_buffer.c +++ b/src/gallium/drivers/r300/r300_screen_buffer.c @@ -31,7 +31,6 @@ #include "util/u_math.h" #include "r300_screen_buffer.h" -#include "r300_winsys.h" void r300_upload_index_buffer(struct r300_context *r300, struct pipe_resource **index_buffer, @@ -62,7 +61,7 @@ static void r300_buffer_destroy(struct pipe_screen *screen, FREE(rbuf->constant_buffer); if (rbuf->buf) - r300_winsys_bo_reference(&rbuf->buf, NULL); + pb_reference(&rbuf->buf, NULL); util_slab_free(&r300screen->pool_buffers, rbuf); } @@ -105,7 +104,7 @@ r300_buffer_transfer_map( struct pipe_context *pipe, { struct r300_context *r300 = r300_context(pipe); struct r300_screen *r300screen = r300_screen(pipe->screen); - struct r300_winsys_screen *rws = r300screen->rws; + struct radeon_winsys *rws = r300screen->rws; struct r300_resource *rbuf = r300_resource(transfer->resource); uint8_t *map; @@ -126,7 +125,7 @@ static void r300_buffer_transfer_unmap( struct pipe_context *pipe, struct pipe_transfer *transfer ) { struct r300_screen *r300screen = r300_screen(pipe->screen); - struct r300_winsys_screen *rws = r300screen->rws; + struct radeon_winsys *rws = r300screen->rws; struct r300_resource *rbuf = r300_resource(transfer->resource); if (rbuf->buf) { @@ -144,7 +143,7 @@ static void r300_buffer_transfer_inline_write(struct pipe_context *pipe, unsigned layer_stride) { struct r300_context *r300 = r300_context(pipe); - struct r300_winsys_screen *rws = r300->screen->rws; + struct radeon_winsys *rws = r300->screen->rws; struct r300_resource *rbuf = r300_resource(resource); uint8_t *map = NULL; @@ -188,7 +187,7 @@ struct pipe_resource *r300_buffer_create(struct pipe_screen *screen, pipe_reference_init(&rbuf->b.b.b.reference, 1); rbuf->b.b.b.screen = screen; rbuf->b.user_ptr = NULL; - rbuf->domain = R300_DOMAIN_GTT; + rbuf->domain = RADEON_DOMAIN_GTT; rbuf->buf = NULL; rbuf->buf_size = templ->width0; rbuf->constant_buffer = NULL; @@ -237,7 +236,7 @@ struct pipe_resource *r300_user_buffer_create(struct pipe_screen *screen, rbuf->b.b.b.flags = 0; rbuf->b.b.vtbl = &r300_buffer_vtbl; rbuf->b.user_ptr = ptr; - rbuf->domain = R300_DOMAIN_GTT; + rbuf->domain = RADEON_DOMAIN_GTT; rbuf->buf = NULL; rbuf->buf_size = size; rbuf->constant_buffer = NULL; diff --git a/src/gallium/drivers/r300/r300_screen_buffer.h b/src/gallium/drivers/r300/r300_screen_buffer.h index cdbc4425fcb..360ec509cc5 100644 --- a/src/gallium/drivers/r300/r300_screen_buffer.h +++ b/src/gallium/drivers/r300/r300_screen_buffer.h @@ -32,7 +32,6 @@ #include "util/u_transfer.h" #include "r300_screen.h" -#include "r300_winsys.h" #include "r300_context.h" /* Functions. */ diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index ecb4fc691cc..24b41d5085d 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -45,7 +45,6 @@ #include "r300_fs.h" #include "r300_texture.h" #include "r300_vs.h" -#include "r300_winsys.h" /* r300_state: Functions used to intialize state context by translating * Gallium state objects into semi-native r300 state objects. */ @@ -398,10 +397,6 @@ static void r300_bind_blend_state(struct pipe_context* pipe, struct r300_context* r300 = r300_context(pipe); UPDATE_STATE(state, r300->blend_state); - - if (r300->fs.state && r300_pick_fragment_shader(r300)) { - r300_mark_fs_code_dirty(r300); - } } /* Free blend state. */ @@ -773,7 +768,7 @@ void r300_mark_fb_state_dirty(struct r300_context *r300, enum r300_fb_state_change change) { struct pipe_framebuffer_state *state = r300->fb_state.state; - boolean can_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ); + boolean can_hyperz = r300->rws->get_value(r300->rws, RADEON_VID_CAN_HYPERZ); r300_mark_atom_dirty(r300, &r300->gpu_flush); r300_mark_atom_dirty(r300, &r300->fb_state); @@ -860,6 +855,7 @@ r300_set_framebuffer_state(struct pipe_context* pipe, } } } + assert(state->zsbuf || r300->hyperz_locked || !r300->zmask_in_use); /* Need to reset clamping or colormask. */ r300_mark_atom_dirty(r300, &r300->blend_state); @@ -973,24 +969,14 @@ static void r300_bind_fs_state(struct pipe_context* pipe, void* shader) { struct r300_context* r300 = r300_context(pipe); struct r300_fragment_shader* fs = (struct r300_fragment_shader*)shader; - struct pipe_framebuffer_state *fb = r300->fb_state.state; - boolean last_multi_write; if (fs == NULL) { r300->fs.state = NULL; return; } - last_multi_write = r300_fragment_shader_writes_all(r300_fs(r300)); - r300->fs.state = fs; - r300_pick_fragment_shader(r300); - r300_mark_fs_code_dirty(r300); - - if (fb->nr_cbufs > 1 && - last_multi_write != r300_fragment_shader_writes_all(fs)) { - r300_mark_fb_state_dirty(r300, R300_CHANGED_MULTIWRITE); - } + r300->fs_status = FRAGMENT_SHADER_DIRTY; r300_mark_atom_dirty(r300, &r300->rs_block_state); /* Will be updated before the emission. */ } @@ -1047,7 +1033,7 @@ static void* r300_create_rs_state(struct pipe_context* pipe, float point_texcoord_bottom = 0;/* R300_GA_POINT_T0: 0x4204 */ float point_texcoord_right = 1; /* R300_GA_POINT_S1: 0x4208 */ float point_texcoord_top = 0; /* R300_GA_POINT_T1: 0x420c */ - boolean vclamp = TRUE; + boolean vclamp = state->clamp_vertex_color; CB_LOCALS; /* Copy rasterizer state. */ @@ -1233,6 +1219,7 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) struct r300_rs_state* rs = (struct r300_rs_state*)state; int last_sprite_coord_enable = r300->sprite_coord_enable; boolean last_two_sided_color = r300->two_sided_color; + boolean last_frag_clamp = r300->frag_clamp; if (r300->draw && rs) { draw_set_rasterizer_state(r300->draw, &rs->rs_draw, state); @@ -1242,10 +1229,12 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) r300->polygon_offset_enabled = rs->polygon_offset_enable; r300->sprite_coord_enable = rs->rs.sprite_coord_enable; r300->two_sided_color = rs->rs.light_twoside; + r300->frag_clamp = rs->rs.clamp_fragment_color; } else { r300->polygon_offset_enabled = FALSE; r300->sprite_coord_enable = 0; r300->two_sided_color = FALSE; + r300->frag_clamp = FALSE; } UPDATE_STATE(state, r300->rs_state); @@ -1255,6 +1244,11 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) last_two_sided_color != r300->two_sided_color) { r300_mark_atom_dirty(r300, &r300->rs_block_state); } + + if (last_frag_clamp != r300->frag_clamp && + r300->fs_status == FRAGMENT_SHADER_VALID) { + r300->fs_status = FRAGMENT_SHADER_MAYBE_DIRTY; + } } /* Free rasterizer state. */ @@ -1551,7 +1545,8 @@ static void r300_set_viewport_state(struct pipe_context* pipe, } r300_mark_atom_dirty(r300, &r300->viewport_state); - if (r300->fs.state && r300_fs(r300)->shader->inputs.wpos != ATTR_UNUSED) { + if (r300->fs.state && r300_fs(r300)->shader && + r300_fs(r300)->shader->inputs.wpos != ATTR_UNUSED) { r300_mark_atom_dirty(r300, &r300->fs_rc_constant_state); } } diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index ec00e2552ca..afc1451183d 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -592,6 +592,13 @@ static void r300_update_rs_block(struct r300_context *r300) } } +static void rgba_to_bgra(float color[4]) +{ + float x = color[0]; + color[0] = color[2]; + color[2] = x; +} + static uint32_t r300_get_border_color(enum pipe_format format, const float border[4], boolean is_r500) @@ -625,13 +632,13 @@ static uint32_t r300_get_border_color(enum pipe_format format, for (i = 0; i < 4; i++) { switch (desc->swizzle[i]) { case UTIL_FORMAT_SWIZZLE_X: - border_swizzled[2] = border[i]; + border_swizzled[0] = border[i]; break; case UTIL_FORMAT_SWIZZLE_Y: border_swizzled[1] = border[i]; break; case UTIL_FORMAT_SWIZZLE_Z: - border_swizzled[0] = border[i]; + border_swizzled[2] = border[i]; break; case UTIL_FORMAT_SWIZZLE_W: border_swizzled[3] = border[i]; @@ -643,39 +650,46 @@ static uint32_t r300_get_border_color(enum pipe_format format, if (util_format_is_compressed(format)) { switch (format) { case PIPE_FORMAT_RGTC1_SNORM: - case PIPE_FORMAT_RGTC1_UNORM: case PIPE_FORMAT_LATC1_SNORM: + border_swizzled[0] = border_swizzled[0] < 0 ? + border_swizzled[0]*0.5+1 : + border_swizzled[0]*0.5; + /* Pass through. */ + + case PIPE_FORMAT_RGTC1_UNORM: case PIPE_FORMAT_LATC1_UNORM: /* Add 1/32 to round the border color instead of truncating. */ /* The Y component is used for the border color. */ - border_swizzled[1] = border_swizzled[2] + 1.0f/32; + border_swizzled[1] = border_swizzled[0] + 1.0f/32; util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc); return uc.ui; case PIPE_FORMAT_RGTC2_SNORM: case PIPE_FORMAT_LATC2_SNORM: - border_swizzled[0] = border_swizzled[2]; util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_SNORM, &uc); return uc.ui; case PIPE_FORMAT_RGTC2_UNORM: case PIPE_FORMAT_LATC2_UNORM: - util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc); return uc.ui; default: - util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc); + util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); return uc.ui; } } switch (desc->channel[0].size) { case 2: + rgba_to_bgra(border_swizzled); util_pack_color(border_swizzled, PIPE_FORMAT_B2G3R3_UNORM, &uc); break; case 4: + rgba_to_bgra(border_swizzled); util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc); break; case 5: + rgba_to_bgra(border_swizzled); if (desc->channel[1].size == 5) { util_pack_color(border_swizzled, PIPE_FORMAT_B5G5R5A1_UNORM, &uc); } else if (desc->channel[1].size == 6) { @@ -687,32 +701,39 @@ static uint32_t r300_get_border_color(enum pipe_format format, default: case 8: - util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) + util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_SNORM, &uc); + else + util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc); break; case 10: - util_pack_color(border_swizzled, PIPE_FORMAT_B10G10R10A2_UNORM, &uc); + util_pack_color(border_swizzled, PIPE_FORMAT_R10G10B10A2_UNORM, &uc); break; case 16: if (desc->nr_channels <= 2) { - border_swizzled[0] = border_swizzled[2]; if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) { util_pack_color(border_swizzled, PIPE_FORMAT_R16G16_FLOAT, &uc); + } else if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) { + util_pack_color(border_swizzled, PIPE_FORMAT_R16G16_SNORM, &uc); } else { util_pack_color(border_swizzled, PIPE_FORMAT_R16G16_UNORM, &uc); } } else { - util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) { + util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_SNORM, &uc); + } else { + util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc); + } } break; case 32: if (desc->nr_channels == 1) { - border_swizzled[0] = border_swizzled[2]; util_pack_color(border_swizzled, PIPE_FORMAT_R32_FLOAT, &uc); } else { - util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); + util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc); } break; } @@ -720,25 +741,6 @@ static uint32_t r300_get_border_color(enum pipe_format format, return uc.ui; } -static boolean util_format_is_float(enum pipe_format format) -{ - const struct util_format_description *desc = util_format_description(format); - unsigned i; - - if (!format) - return FALSE; - - /* Find the first non-void channel. */ - for (i = 0; i < 4; i++) - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) - break; - - if (i == 4) - return FALSE; - - return desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT ? TRUE : FALSE; -} - static void r300_merge_textures_and_samplers(struct r300_context* r300) { struct r300_textures_state *state = @@ -747,9 +749,10 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) struct r300_sampler_state *sampler; struct r300_sampler_view *view; struct r300_resource *tex; - unsigned min_level, max_level, i, j, size; + unsigned base_level, min_level, level_count, i, j, size; unsigned count = MIN2(state->sampler_view_count, state->sampler_state_count); + boolean has_us_format = r300->screen->caps.has_us_format; /* The KIL opcode fix, see below. */ if (!count && !r300->screen->caps.is_r500) @@ -779,21 +782,27 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) r300->screen->caps.is_r500); /* determine min/max levels */ - max_level = MIN3(sampler->max_lod + view->base.u.tex.first_level, - tex->b.b.b.last_level, view->base.u.tex.last_level); - min_level = MIN2(sampler->min_lod + view->base.u.tex.first_level, - max_level); - - if (tex->tex.is_npot && min_level > 0) { - /* Even though we do not implement mipmapping for NPOT - * textures, we should at least honor the minimum level - * which is allowed to be displayed. We do this by setting up - * the i-th mipmap level as the zero level. */ - unsigned offset = tex->tex_offset + - tex->tex.offset_in_bytes[min_level]; + base_level = view->base.u.tex.first_level; + min_level = sampler->min_lod; + level_count = MIN3(sampler->max_lod, + tex->b.b.b.last_level - base_level, + view->base.u.tex.last_level - base_level); + + if (base_level + min_level) { + unsigned offset; + + if (tex->tex.is_npot) { + /* Even though we do not implement mipmapping for NPOT + * textures, we should at least honor the minimum level + * which is allowed to be displayed. We do this by setting up + * an i-th mipmap level as the zero level. */ + base_level += min_level; + } + offset = tex->tex_offset + + tex->tex.offset_in_bytes[base_level]; r300_texture_setup_format_state(r300->screen, tex, - min_level, + base_level, &texstate->format); texstate->format.tile_config |= offset & 0xffffffe0; assert((offset & 0x1f) == 0); @@ -870,7 +879,7 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) } } else { /* the MAX_MIP level is the largest (finest) one */ - texstate->format.format0 |= R300_TX_NUM_LEVELS(max_level); + texstate->format.format0 |= R300_TX_NUM_LEVELS(level_count); texstate->filter0 |= R300_TX_MAX_MIP_LEVEL(min_level); } @@ -902,7 +911,7 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) texstate->filter0 |= i << 28; - size += 16; + size += 16 + (has_us_format ? 2 : 0); state->count = i+1; } else { /* For the KIL opcode to work on r3xx-r4xx, the texture unit @@ -931,7 +940,7 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) texstate->border_color = 0; texstate->filter0 |= i << 28; - size += 16; + size += 16 + (has_us_format ? 2 : 0); state->count = i+1; } } @@ -940,11 +949,10 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) r300->textures_state.size = size; /* Pick a fragment shader based on either the texture compare state - * or the uses_pitch flag. */ - if (r300->fs.state && count) { - if (r300_pick_fragment_shader(r300)) { - r300_mark_fs_code_dirty(r300); - } + * or the uses_pitch flag or some other external state. */ + if (count && + r300->fs_status == FRAGMENT_SHADER_VALID) { + r300->fs_status = FRAGMENT_SHADER_MAYBE_DIRTY; } } @@ -973,6 +981,34 @@ static void r300_decompress_depth_textures(struct r300_context *r300) } } +static void r300_validate_fragment_shader(struct r300_context *r300) +{ + struct pipe_framebuffer_state *fb = r300->fb_state.state; + + if (r300->fs.state && r300->fs_status != FRAGMENT_SHADER_VALID) { + /* Pick the fragment shader based on external states. + * Then mark the state dirty if the fragment shader is either dirty + * or the function r300_pick_fragment_shader changed the shader. */ + if (r300_pick_fragment_shader(r300) || + r300->fs_status == FRAGMENT_SHADER_DIRTY) { + /* Mark the state atom as dirty. */ + r300_mark_fs_code_dirty(r300); + + /* Does Multiwrite need to be changed? */ + if (fb->nr_cbufs > 1) { + boolean new_multiwrite = + r300_fragment_shader_writes_all(r300_fs(r300)); + + if (r300->fb_multiwrite != new_multiwrite) { + r300->fb_multiwrite = new_multiwrite; + r300_mark_fb_state_dirty(r300, R300_CHANGED_MULTIWRITE); + } + } + } + r300->fs_status = FRAGMENT_SHADER_VALID; + } +} + void r300_update_derived_state(struct r300_context* r300) { if (r300->textures_state.dirty) { @@ -980,6 +1016,8 @@ void r300_update_derived_state(struct r300_context* r300) r300_merge_textures_and_samplers(r300); } + r300_validate_fragment_shader(r300); + if (r300->rs_block_state.dirty) { r300_update_rs_block(r300); diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index c650fb7ed37..38ca9a24e45 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -29,7 +29,6 @@ #include "r300_texture_desc.h" #include "r300_transfer.h" #include "r300_screen.h" -#include "r300_winsys.h" #include "util/u_format.h" #include "util/u_format_s3tc.h" @@ -39,6 +38,18 @@ #include "pipe/p_screen.h" +void util_format_combine_swizzles(unsigned char *dst, + const unsigned char *swz1, + const unsigned char *swz2) +{ + unsigned i; + + for (i = 0; i < 4; i++) { + dst[i] = swz2[i] <= UTIL_FORMAT_SWIZZLE_W ? + swz1[swz2[i]] : swz2[i]; + } +} + unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format, const unsigned char *swizzle_view, boolean dxtc_swizzle) @@ -61,10 +72,7 @@ unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format, if (swizzle_view) { /* Combine two sets of swizzles. */ - for (i = 0; i < 4; i++) { - swizzle[i] = swizzle_view[i] <= UTIL_FORMAT_SWIZZLE_W ? - swizzle_format[swizzle_view[i]] : swizzle_view[i]; - } + util_format_combine_swizzles(swizzle, swizzle_format, swizzle_view); } else { memcpy(swizzle, swizzle_format, 4); } @@ -116,10 +124,10 @@ uint32_t r300_translate_texformat(enum pipe_format format, unsigned i; boolean uniform = TRUE; const uint32_t sign_bit[4] = { - R300_TX_FORMAT_SIGNED_X, - R300_TX_FORMAT_SIGNED_Y, - R300_TX_FORMAT_SIGNED_Z, R300_TX_FORMAT_SIGNED_W, + R300_TX_FORMAT_SIGNED_Z, + R300_TX_FORMAT_SIGNED_Y, + R300_TX_FORMAT_SIGNED_X, }; desc = util_format_description(format); @@ -171,17 +179,22 @@ uint32_t r300_translate_texformat(enum pipe_format format, } } - if (util_format_is_compressed(format) && - dxtc_swizzle && - format != PIPE_FORMAT_RGTC2_UNORM && - format != PIPE_FORMAT_RGTC2_SNORM && - format != PIPE_FORMAT_LATC2_UNORM && - format != PIPE_FORMAT_LATC2_SNORM) { - result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, - TRUE); - } else { - result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, - FALSE); + /* Add swizzling. */ + /* The RGTC1_SNORM and LATC1_SNORM swizzle is done in the shader. */ + if (format != PIPE_FORMAT_RGTC1_SNORM && + format != PIPE_FORMAT_LATC1_SNORM) { + if (util_format_is_compressed(format) && + dxtc_swizzle && + format != PIPE_FORMAT_RGTC2_UNORM && + format != PIPE_FORMAT_RGTC2_SNORM && + format != PIPE_FORMAT_LATC2_UNORM && + format != PIPE_FORMAT_LATC2_SNORM) { + result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, + TRUE); + } else { + result |= r300_get_swizzle_combined(desc->swizzle, swizzle_view, + FALSE); + } } /* S3TC formats. */ @@ -212,14 +225,13 @@ uint32_t r300_translate_texformat(enum pipe_format format, switch (format) { case PIPE_FORMAT_RGTC1_SNORM: case PIPE_FORMAT_LATC1_SNORM: - result |= sign_bit[1]; case PIPE_FORMAT_LATC1_UNORM: case PIPE_FORMAT_RGTC1_UNORM: return R500_TX_FORMAT_ATI1N | result; case PIPE_FORMAT_RGTC2_SNORM: case PIPE_FORMAT_LATC2_SNORM: - result |= sign_bit[2] | sign_bit[3]; + result |= sign_bit[1] | sign_bit[0]; case PIPE_FORMAT_RGTC2_UNORM: case PIPE_FORMAT_LATC2_UNORM: return R400_TX_FORMAT_ATI2N | result; @@ -390,20 +402,33 @@ static uint32_t r300_translate_colorformat(enum pipe_format format) switch (format) { /* 8-bit buffers. */ case PIPE_FORMAT_A8_UNORM: - /*case PIPE_FORMAT_A8_SNORM:*/ + case PIPE_FORMAT_A8_SNORM: case PIPE_FORMAT_I8_UNORM: - /*case PIPE_FORMAT_I8_SNORM:*/ + case PIPE_FORMAT_I8_SNORM: case PIPE_FORMAT_L8_UNORM: - /*case PIPE_FORMAT_L8_SNORM:*/ + case PIPE_FORMAT_L8_SNORM: case PIPE_FORMAT_R8_UNORM: case PIPE_FORMAT_R8_SNORM: return R300_COLOR_FORMAT_I8; /* 16-bit buffers. */ case PIPE_FORMAT_L8A8_UNORM: - /*case PIPE_FORMAT_L8A8_SNORM:*/ + case PIPE_FORMAT_L8A8_SNORM: case PIPE_FORMAT_R8G8_UNORM: case PIPE_FORMAT_R8G8_SNORM: + /* These formats work fine with UV88 if US_OUT_FMT is set correctly. */ + case PIPE_FORMAT_A16_UNORM: + case PIPE_FORMAT_A16_SNORM: + case PIPE_FORMAT_A16_FLOAT: + case PIPE_FORMAT_L16_UNORM: + case PIPE_FORMAT_L16_SNORM: + case PIPE_FORMAT_L16_FLOAT: + case PIPE_FORMAT_I16_UNORM: + case PIPE_FORMAT_I16_SNORM: + case PIPE_FORMAT_I16_FLOAT: + case PIPE_FORMAT_R16_UNORM: + case PIPE_FORMAT_R16_SNORM: + case PIPE_FORMAT_R16_FLOAT: return R300_COLOR_FORMAT_UV88; case PIPE_FORMAT_B5G6R5_UNORM: @@ -434,19 +459,33 @@ static uint32_t r300_translate_colorformat(enum pipe_format format) /*case PIPE_FORMAT_X8B8G8R8_SNORM:*/ case PIPE_FORMAT_R8G8B8X8_UNORM: /*case PIPE_FORMAT_R8G8B8X8_SNORM:*/ - case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + /* These formats work fine with ARGB8888 if US_OUT_FMT is set + * correctly. */ + case PIPE_FORMAT_R16G16_UNORM: + case PIPE_FORMAT_R16G16_SNORM: + case PIPE_FORMAT_R16G16_FLOAT: + case PIPE_FORMAT_L16A16_UNORM: + case PIPE_FORMAT_L16A16_SNORM: + case PIPE_FORMAT_L16A16_FLOAT: + case PIPE_FORMAT_A32_FLOAT: + case PIPE_FORMAT_L32_FLOAT: + case PIPE_FORMAT_I32_FLOAT: + case PIPE_FORMAT_R32_FLOAT: return R300_COLOR_FORMAT_ARGB8888; case PIPE_FORMAT_R10G10B10A2_UNORM: case PIPE_FORMAT_R10G10B10X2_SNORM: case PIPE_FORMAT_B10G10R10A2_UNORM: - case PIPE_FORMAT_R10SG10SB10SA2U_NORM: return R500_COLOR_FORMAT_ARGB2101010; /* R5xx-only? */ /* 64-bit buffers. */ case PIPE_FORMAT_R16G16B16A16_UNORM: case PIPE_FORMAT_R16G16B16A16_SNORM: case PIPE_FORMAT_R16G16B16A16_FLOAT: + /* These formats work fine with ARGB16161616 if US_OUT_FMT is set + * correctly. */ + case PIPE_FORMAT_R32G32_FLOAT: + case PIPE_FORMAT_L32A32_FLOAT: return R300_COLOR_FORMAT_ARGB16161616; /* 128-bit buffers. */ @@ -489,12 +528,7 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) uint32_t modifier = 0; unsigned i; const struct util_format_description *desc; - static const uint32_t sign_bit[4] = { - R300_OUT_SIGN(0x1), - R300_OUT_SIGN(0x2), - R300_OUT_SIGN(0x4), - R300_OUT_SIGN(0x8), - }; + boolean uniform_sign; desc = util_format_description(format); @@ -509,54 +543,109 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) return ~0; /* Unsupported/unknown. */ /* Specifies how the shader output is written to the fog unit. */ - if (desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT) { - if (desc->channel[i].size == 32) { - modifier |= R300_US_OUT_FMT_C4_32_FP; - } else { - modifier |= R300_US_OUT_FMT_C4_16_FP; + switch (desc->channel[i].type) { + case UTIL_FORMAT_TYPE_FLOAT: + switch (desc->channel[i].size) { + case 32: + switch (desc->nr_channels) { + case 1: + modifier |= R300_US_OUT_FMT_C_32_FP; + break; + case 2: + modifier |= R300_US_OUT_FMT_C2_32_FP; + break; + case 4: + modifier |= R300_US_OUT_FMT_C4_32_FP; + break; + } + break; + + case 16: + switch (desc->nr_channels) { + case 1: + modifier |= R300_US_OUT_FMT_C_16_FP; + break; + case 2: + modifier |= R300_US_OUT_FMT_C2_16_FP; + break; + case 4: + modifier |= R300_US_OUT_FMT_C4_16_FP; + break; + } + break; } - } else { - if (desc->channel[i].size == 16) { - modifier |= R300_US_OUT_FMT_C4_16; - } else if (desc->channel[i].size == 10) { + break; + + default: + switch (desc->channel[i].size) { + case 16: + switch (desc->nr_channels) { + case 1: + modifier |= R300_US_OUT_FMT_C_16; + break; + case 2: + modifier |= R300_US_OUT_FMT_C2_16; + break; + case 4: + modifier |= R300_US_OUT_FMT_C4_16; + break; + } + break; + + case 10: modifier |= R300_US_OUT_FMT_C4_10; - } else { + break; + + default: /* C4_8 seems to be used for the formats whose pixel size * is <= 32 bits. */ modifier |= R300_US_OUT_FMT_C4_8; + break; } } /* Add sign. */ - for (i = 0; i < 4; i++) - if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { - modifier |= sign_bit[i]; - } + uniform_sign = TRUE; + for (i = 0; i < desc->nr_channels; i++) + if (desc->channel[i].type != UTIL_FORMAT_TYPE_SIGNED) + uniform_sign = FALSE; + + if (uniform_sign) + modifier |= R300_OUT_SIGN(0xf); /* Add swizzles and return. */ switch (format) { - /* 8-bit outputs, one channel. - * COLORFORMAT_I8 stores the C2 component. */ + /*** Special cases (non-standard channel mapping) ***/ + + /* X8 + * COLORFORMAT_I8 stores the Z component (C2). */ case PIPE_FORMAT_A8_UNORM: - /*case PIPE_FORMAT_A8_SNORM:*/ + case PIPE_FORMAT_A8_SNORM: return modifier | R300_C2_SEL_A; case PIPE_FORMAT_I8_UNORM: - /*case PIPE_FORMAT_I8_SNORM:*/ + case PIPE_FORMAT_I8_SNORM: case PIPE_FORMAT_L8_UNORM: - /*case PIPE_FORMAT_L8_SNORM:*/ + case PIPE_FORMAT_L8_SNORM: case PIPE_FORMAT_R8_UNORM: case PIPE_FORMAT_R8_SNORM: return modifier | R300_C2_SEL_R; - /* 16-bit outputs, two channels. - * COLORFORMAT_UV88 stores C2 and C0. */ + /* X8Y8 + * COLORFORMAT_UV88 stores ZX (C2 and C0). */ + case PIPE_FORMAT_L8A8_SNORM: case PIPE_FORMAT_L8A8_UNORM: - /*case PIPE_FORMAT_L8A8_SNORM:*/ return modifier | R300_C0_SEL_A | R300_C2_SEL_R; - case PIPE_FORMAT_R8G8_UNORM: case PIPE_FORMAT_R8G8_SNORM: + case PIPE_FORMAT_R8G8_UNORM: return modifier | R300_C0_SEL_G | R300_C2_SEL_R; + /* X32Y32 + * ARGB16161616 stores XZ for RG32F */ + case PIPE_FORMAT_R32G32_FLOAT: + return modifier | R300_C0_SEL_R | R300_C2_SEL_G; + + /*** Generic cases (standard channel mapping) ***/ + /* BGRA outputs. */ case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_B5G5R5A1_UNORM: @@ -577,6 +666,10 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) /*case PIPE_FORMAT_A8R8G8B8_SNORM:*/ case PIPE_FORMAT_X8R8G8B8_UNORM: /*case PIPE_FORMAT_X8R8G8B8_SNORM:*/ + case PIPE_FORMAT_A16_UNORM: + case PIPE_FORMAT_A16_SNORM: + case PIPE_FORMAT_A16_FLOAT: + case PIPE_FORMAT_A32_FLOAT: return modifier | R300_C0_SEL_A | R300_C1_SEL_R | R300_C2_SEL_G | R300_C3_SEL_B; @@ -595,18 +688,39 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format) /*case PIPE_FORMAT_R8G8B8X8_SNORM:*/ case PIPE_FORMAT_R8G8B8A8_UNORM: case PIPE_FORMAT_R8G8B8A8_SNORM: - case PIPE_FORMAT_R8SG8SB8UX8U_NORM: case PIPE_FORMAT_R10G10B10A2_UNORM: case PIPE_FORMAT_R10G10B10X2_SNORM: - case PIPE_FORMAT_R10SG10SB10SA2U_NORM: + case PIPE_FORMAT_R16_UNORM: + case PIPE_FORMAT_R16G16_UNORM: case PIPE_FORMAT_R16G16B16A16_UNORM: + case PIPE_FORMAT_R16_SNORM: + case PIPE_FORMAT_R16G16_SNORM: case PIPE_FORMAT_R16G16B16A16_SNORM: + case PIPE_FORMAT_R16_FLOAT: + case PIPE_FORMAT_R16G16_FLOAT: case PIPE_FORMAT_R16G16B16A16_FLOAT: + case PIPE_FORMAT_R32_FLOAT: case PIPE_FORMAT_R32G32B32A32_FLOAT: + case PIPE_FORMAT_L16_UNORM: + case PIPE_FORMAT_L16_SNORM: + case PIPE_FORMAT_L16_FLOAT: + case PIPE_FORMAT_L32_FLOAT: + case PIPE_FORMAT_I16_UNORM: + case PIPE_FORMAT_I16_SNORM: + case PIPE_FORMAT_I16_FLOAT: + case PIPE_FORMAT_I32_FLOAT: return modifier | R300_C0_SEL_R | R300_C1_SEL_G | R300_C2_SEL_B | R300_C3_SEL_A; + /* LA outputs. */ + case PIPE_FORMAT_L16A16_UNORM: + case PIPE_FORMAT_L16A16_SNORM: + case PIPE_FORMAT_L16A16_FLOAT: + case PIPE_FORMAT_L32A32_FLOAT: + return modifier | + R300_C0_SEL_R | R300_C1_SEL_A; + default: return ~0; /* Unsupported. */ } @@ -636,6 +750,16 @@ void r300_texture_setup_format_state(struct r300_screen *screen, struct pipe_resource *pt = &tex->b.b.b; struct r300_texture_desc *desc = &tex->tex; boolean is_r500 = screen->caps.is_r500; + unsigned width, height, depth; + unsigned txwidth, txheight, txdepth; + + width = u_minify(desc->width0, level); + height = u_minify(desc->height0, level); + depth = u_minify(desc->depth0, level); + + txwidth = (width - 1) & 0x7ff; + txheight = (height - 1) & 0x7ff; + txdepth = util_logbase2(depth) & 0xf; /* Mask out all the fields we change. */ out->format0 = 0; @@ -645,9 +769,9 @@ void r300_texture_setup_format_state(struct r300_screen *screen, /* Set sampler state. */ out->format0 = - R300_TX_WIDTH((u_minify(desc->width0, level) - 1) & 0x7ff) | - R300_TX_HEIGHT((u_minify(desc->height0, level) - 1) & 0x7ff) | - R300_TX_DEPTH(util_logbase2(u_minify(desc->depth0, level)) & 0xf); + R300_TX_WIDTH(txwidth) | + R300_TX_HEIGHT(txheight) | + R300_TX_DEPTH(txdepth); if (desc->uses_stride_addressing) { /* rectangles love this */ @@ -665,12 +789,32 @@ void r300_texture_setup_format_state(struct r300_screen *screen, /* large textures on r500 */ if (is_r500) { - if (desc->width0 > 2048) { + unsigned us_width = txwidth; + unsigned us_height = txheight; + unsigned us_depth = txdepth; + + if (width > 2048) { out->format2 |= R500_TXWIDTH_BIT11; } - if (desc->height0 > 2048) { + if (height > 2048) { out->format2 |= R500_TXHEIGHT_BIT11; } + + /* The US_FORMAT register fixes an R500 TX addressing bug. + * Don't ask why it must be set like this. I don't know it either. */ + if (width > 2048) { + us_width = (0x000007FF + us_width) >> 1; + us_depth |= 0x0000000D; + } + if (height > 2048) { + us_height = (0x000007FF + us_height) >> 1; + us_depth |= 0x0000000E; + } + + out->us_format0 = + R300_TX_WIDTH(us_width) | + R300_TX_HEIGHT(us_height) | + R300_TX_DEPTH(us_depth); } out->tile_config = R300_TXO_MACRO_TILE(desc->macrotile[level]) | @@ -729,7 +873,7 @@ static void r300_texture_destroy(struct pipe_screen *screen, { struct r300_resource* tex = (struct r300_resource*)texture; - r300_winsys_bo_reference(&tex->buf, NULL); + pb_reference(&tex->buf, NULL); FREE(tex); } @@ -737,7 +881,7 @@ boolean r300_resource_get_handle(struct pipe_screen* screen, struct pipe_resource *texture, struct winsys_handle *whandle) { - struct r300_winsys_screen *rws = (struct r300_winsys_screen *)screen->winsys; + struct radeon_winsys *rws = (struct radeon_winsys *)screen->winsys; struct r300_resource* tex = (struct r300_resource*)texture; if (!tex) { @@ -764,17 +908,17 @@ static const struct u_resource_vtbl r300_texture_vtbl = static struct r300_resource* r300_texture_create_object(struct r300_screen *rscreen, const struct pipe_resource *base, - enum r300_buffer_tiling microtile, - enum r300_buffer_tiling macrotile, + enum radeon_bo_layout microtile, + enum radeon_bo_layout macrotile, unsigned stride_in_bytes_override, unsigned max_buffer_size, - struct r300_winsys_bo *buffer) + struct pb_buffer *buffer) { - struct r300_winsys_screen *rws = rscreen->rws; + struct radeon_winsys *rws = rscreen->rws; struct r300_resource *tex = CALLOC_STRUCT(r300_resource); if (!tex) { if (buffer) - r300_winsys_bo_reference(&buffer, NULL); + pb_reference(&buffer, NULL); return NULL; } @@ -788,13 +932,13 @@ r300_texture_create_object(struct r300_screen *rscreen, tex->tex.macrotile[0] = macrotile; tex->tex.stride_in_bytes_override = stride_in_bytes_override; tex->domain = base->flags & R300_RESOURCE_FLAG_TRANSFER ? - R300_DOMAIN_GTT : - R300_DOMAIN_VRAM | R300_DOMAIN_GTT; + RADEON_DOMAIN_GTT : + RADEON_DOMAIN_VRAM | RADEON_DOMAIN_GTT; tex->buf_size = max_buffer_size; if (!r300_resource_set_properties(&rscreen->screen, &tex->b.b.b, 0, base)) { if (buffer) - r300_winsys_bo_reference(&buffer, NULL); + pb_reference(&buffer, NULL); FREE(tex); return NULL; } @@ -827,15 +971,16 @@ struct pipe_resource *r300_texture_create(struct pipe_screen *screen, const struct pipe_resource *base) { struct r300_screen *rscreen = r300_screen(screen); - enum r300_buffer_tiling microtile, macrotile; + enum radeon_bo_layout microtile, macrotile; if ((base->flags & R300_RESOURCE_FLAG_TRANSFER) || (base->bind & PIPE_BIND_SCANOUT)) { - microtile = R300_BUFFER_LINEAR; - macrotile = R300_BUFFER_LINEAR; + microtile = RADEON_LAYOUT_LINEAR; + macrotile = RADEON_LAYOUT_LINEAR; } else { - microtile = R300_BUFFER_SELECT_LAYOUT; - macrotile = R300_BUFFER_SELECT_LAYOUT; + /* This will make the texture_create_function select the layout. */ + microtile = RADEON_LAYOUT_UNKNOWN; + macrotile = RADEON_LAYOUT_UNKNOWN; } return (struct pipe_resource*) @@ -847,10 +992,10 @@ struct pipe_resource *r300_texture_from_handle(struct pipe_screen *screen, const struct pipe_resource *base, struct winsys_handle *whandle) { - struct r300_winsys_screen *rws = (struct r300_winsys_screen*)screen->winsys; + struct radeon_winsys *rws = (struct radeon_winsys*)screen->winsys; struct r300_screen *rscreen = r300_screen(screen); - struct r300_winsys_bo *buffer; - enum r300_buffer_tiling microtile, macrotile; + struct pb_buffer *buffer; + enum radeon_bo_layout microtile, macrotile; unsigned stride, size; /* Support only 2D textures without mipmaps */ @@ -869,14 +1014,14 @@ struct pipe_resource *r300_texture_from_handle(struct pipe_screen *screen, /* Enforce a microtiled zbuffer. */ if (util_format_is_depth_or_stencil(base->format) && - microtile == R300_BUFFER_LINEAR) { + microtile == RADEON_LAYOUT_LINEAR) { switch (util_format_get_blocksize(base->format)) { case 4: - microtile = R300_BUFFER_TILED; + microtile = RADEON_LAYOUT_TILED; break; case 2: - microtile = R300_BUFFER_SQUARETILED; + microtile = RADEON_LAYOUT_SQUARETILED; break; } } @@ -917,8 +1062,8 @@ struct pipe_surface* r300_create_surface(struct pipe_context * ctx, /* Prefer VRAM if there are multiple domains to choose from. */ surface->domain = tex->domain; - if (surface->domain & R300_DOMAIN_VRAM) - surface->domain &= ~R300_DOMAIN_GTT; + if (surface->domain & RADEON_DOMAIN_VRAM) + surface->domain &= ~RADEON_DOMAIN_GTT; surface->offset = r300_texture_get_offset(tex, level, surf_tmpl->u.tex.first_layer); diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h index 158a387478f..4586bb2e4dc 100644 --- a/src/gallium/drivers/r300/r300_texture.h +++ b/src/gallium/drivers/r300/r300_texture.h @@ -35,6 +35,10 @@ struct r300_texture_desc; struct r300_resource; struct r300_screen; +void util_format_combine_swizzles(unsigned char *dst, + const unsigned char *swz1, + const unsigned char *swz2); + unsigned r300_get_swizzle_combined(const unsigned char *swizzle_format, const unsigned char *swizzle_view, boolean dxtc_swizzle); diff --git a/src/gallium/drivers/r300/r300_texture_desc.c b/src/gallium/drivers/r300/r300_texture_desc.c index 2910666dd51..da5778be65e 100644 --- a/src/gallium/drivers/r300/r300_texture_desc.c +++ b/src/gallium/drivers/r300/r300_texture_desc.c @@ -22,9 +22,7 @@ * USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "r300_texture_desc.h" - #include "r300_context.h" -#include "r300_winsys.h" #include "util/u_format.h" @@ -32,8 +30,8 @@ * in the given dimension. */ unsigned r300_get_pixel_alignment(enum pipe_format format, unsigned num_samples, - enum r300_buffer_tiling microtile, - enum r300_buffer_tiling macrotile, + enum radeon_bo_layout microtile, + enum radeon_bo_layout macrotile, enum r300_dim dim, boolean is_rs690) { static const unsigned table[2][5][3][2] = @@ -62,8 +60,8 @@ unsigned r300_get_pixel_alignment(enum pipe_format format, unsigned tile = 0; unsigned pixsize = util_format_get_blocksize(format); - assert(macrotile <= R300_BUFFER_TILED); - assert(microtile <= R300_BUFFER_SQUARETILED); + assert(macrotile <= RADEON_LAYOUT_TILED); + assert(microtile <= RADEON_LAYOUT_SQUARETILED); assert(pixsize <= 16); assert(dim <= DIM_HEIGHT); @@ -98,7 +96,7 @@ static boolean r300_texture_macro_switch(struct r300_resource *tex, unsigned tile, texdim; tile = r300_get_pixel_alignment(tex->b.b.b.format, tex->b.b.b.nr_samples, - tex->tex.microtile, R300_BUFFER_TILED, dim, 0); + tex->tex.microtile, RADEON_LAYOUT_TILED, dim, 0); if (dim == DIM_WIDTH) { texdim = u_minify(tex->tex.width0, level); } else { @@ -233,10 +231,10 @@ static void r300_setup_miptree(struct r300_screen *screen, for (i = 0; i <= base->last_level; i++) { /* Let's see if this miplevel can be macrotiled. */ tex->tex.macrotile[i] = - (tex->tex.macrotile[0] == R300_BUFFER_TILED && + (tex->tex.macrotile[0] == RADEON_LAYOUT_TILED && r300_texture_macro_switch(tex, i, rv350_mode, DIM_WIDTH) && r300_texture_macro_switch(tex, i, rv350_mode, DIM_HEIGHT)) ? - R300_BUFFER_TILED : R300_BUFFER_LINEAR; + RADEON_LAYOUT_TILED : RADEON_LAYOUT_LINEAR; stride = r300_texture_get_stride(screen, tex, i); @@ -424,8 +422,8 @@ static void r300_setup_tiling(struct r300_screen *screen, boolean is_zb = util_format_is_depth_or_stencil(format); boolean dbg_no_tiling = SCREEN_DBG_ON(screen, DBG_NO_TILING); - tex->tex.microtile = R300_BUFFER_LINEAR; - tex->tex.macrotile[0] = R300_BUFFER_LINEAR; + tex->tex.microtile = RADEON_LAYOUT_LINEAR; + tex->tex.macrotile[0] = RADEON_LAYOUT_LINEAR; if (!util_format_is_plain(format)) { return; @@ -441,11 +439,11 @@ static void r300_setup_tiling(struct r300_screen *screen, case 1: case 4: case 8: - tex->tex.microtile = R300_BUFFER_TILED; + tex->tex.microtile = RADEON_LAYOUT_TILED; break; case 2: - tex->tex.microtile = R300_BUFFER_SQUARETILED; + tex->tex.microtile = RADEON_LAYOUT_SQUARETILED; break; } @@ -456,7 +454,7 @@ static void r300_setup_tiling(struct r300_screen *screen, /* Set macrotiling. */ if (r300_texture_macro_switch(tex, 0, rv350_mode, DIM_WIDTH) && r300_texture_macro_switch(tex, 0, rv350_mode, DIM_HEIGHT)) { - tex->tex.macrotile[0] = R300_BUFFER_TILED; + tex->tex.macrotile[0] = RADEON_LAYOUT_TILED; } } @@ -501,7 +499,7 @@ boolean r300_texture_desc_init(struct r300_screen *rscreen, } /* Setup tiling. */ - if (tex->tex.microtile == R300_BUFFER_SELECT_LAYOUT) { + if (tex->tex.microtile == RADEON_LAYOUT_UNKNOWN) { r300_setup_tiling(rscreen, tex); } diff --git a/src/gallium/drivers/r300/r300_texture_desc.h b/src/gallium/drivers/r300/r300_texture_desc.h index ce6e9643ec6..a84d6fae0ea 100644 --- a/src/gallium/drivers/r300/r300_texture_desc.h +++ b/src/gallium/drivers/r300/r300_texture_desc.h @@ -25,7 +25,7 @@ #define R300_TEXTURE_DESC_H #include "pipe/p_format.h" -#include "r300_defines.h" +#include "r300_context.h" struct pipe_resource; struct r300_screen; @@ -39,8 +39,8 @@ enum r300_dim { unsigned r300_get_pixel_alignment(enum pipe_format format, unsigned num_samples, - enum r300_buffer_tiling microtile, - enum r300_buffer_tiling macrotile, + enum radeon_bo_layout microtile, + enum radeon_bo_layout macrotile, enum r300_dim dim, boolean is_rs690); boolean r300_texture_desc_init(struct r300_screen *rscreen, diff --git a/src/gallium/drivers/r300/r300_tgsi_to_rc.c b/src/gallium/drivers/r300/r300_tgsi_to_rc.c index 97ec0a1a1f2..6a000cfe2c6 100644 --- a/src/gallium/drivers/r300/r300_tgsi_to_rc.c +++ b/src/gallium/drivers/r300/r300_tgsi_to_rc.c @@ -52,8 +52,7 @@ static unsigned translate_opcode(unsigned opcode) case TGSI_OPCODE_MAD: return RC_OPCODE_MAD; case TGSI_OPCODE_SUB: return RC_OPCODE_SUB; case TGSI_OPCODE_LRP: return RC_OPCODE_LRP; - /* case TGSI_OPCODE_CND: return RC_OPCODE_CND; */ - /* case TGSI_OPCODE_CND0: return RC_OPCODE_CND0; */ + case TGSI_OPCODE_CND: return RC_OPCODE_CND; /* case TGSI_OPCODE_DP2A: return RC_OPCODE_DP2A; */ /* gap */ case TGSI_OPCODE_FRC: return RC_OPCODE_FRC; diff --git a/src/gallium/drivers/r300/r300_transfer.c b/src/gallium/drivers/r300/r300_transfer.c index 65c5095be6a..e2ea4cbf6c5 100644 --- a/src/gallium/drivers/r300/r300_transfer.c +++ b/src/gallium/drivers/r300/r300_transfer.c @@ -226,7 +226,7 @@ void* r300_texture_transfer_map(struct pipe_context *ctx, struct pipe_transfer *transfer) { struct r300_context *r300 = r300_context(ctx); - struct r300_winsys_screen *rws = (struct r300_winsys_screen *)ctx->winsys; + struct radeon_winsys *rws = (struct radeon_winsys *)ctx->winsys; struct r300_transfer *r300transfer = r300_transfer(transfer); struct r300_resource *tex = r300_resource(transfer->resource); char *map; @@ -256,7 +256,7 @@ void* r300_texture_transfer_map(struct pipe_context *ctx, void r300_texture_transfer_unmap(struct pipe_context *ctx, struct pipe_transfer *transfer) { - struct r300_winsys_screen *rws = (struct r300_winsys_screen *)ctx->winsys; + struct radeon_winsys *rws = (struct radeon_winsys *)ctx->winsys; struct r300_transfer *r300transfer = r300_transfer(transfer); struct r300_resource *tex = r300_resource(transfer->resource); diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h deleted file mode 100644 index 3a6798a5423..00000000000 --- a/src/gallium/drivers/r300/r300_winsys.h +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright 2008 Corbin Simpson <[email protected]> - * Copyright 2010 Marek Olšák <[email protected]> - * - * 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 - * on 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 - * THE AUTHOR(S) AND/OR THEIR 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 R300_WINSYS_H -#define R300_WINSYS_H - -/* The public winsys interface header for the r300 pipe driver. - * Any winsys hosting this pipe needs to implement r300_winsys_screen and then - * call r300_screen_create to start things. */ - -#include "r300_defines.h" - -#include "pipebuffer/pb_bufmgr.h" -#include "pipe/p_defines.h" -#include "pipe/p_state.h" - -#define R300_MAX_CMDBUF_DWORDS (16 * 1024) -#define R300_FLUSH_ASYNC (1 << 0) - -struct winsys_handle; -struct r300_winsys_screen; - -#define r300_winsys_bo pb_buffer -#define r300_winsys_bo_reference(pdst, src) pb_reference(pdst, src) - -struct r300_winsys_cs_handle; /* for write_reloc etc. */ - -struct r300_winsys_cs { - unsigned cdw; /* Number of used dwords. */ - uint32_t *buf; /* The command buffer. */ -}; - -enum r300_value_id { - R300_VID_PCI_ID, - R300_VID_GB_PIPES, - R300_VID_Z_PIPES, - R300_VID_GART_SIZE, - R300_VID_VRAM_SIZE, - R300_VID_DRM_MAJOR, - R300_VID_DRM_MINOR, - R300_VID_DRM_PATCHLEVEL, - - /* These should probably go away: */ - R300_VID_DRM_2_6_0, /* Hyper-Z, GB_Z_PEQ_CONFIG on rv350->r4xx, R500 FG_ALPHA_VALUE */ - R300_VID_DRM_2_8_0, /* R500 US_FORMAT regs, R500 ARGB2101010 colorbuffer, CMask, R16F/RG16F */ - - R300_CAN_HYPERZ, /* ZMask + HiZ */ - R300_CAN_AACOMPRESS, /* CMask */ -}; - -struct r300_winsys_screen { - /** - * Destroy this winsys. - * - * \param ws The winsys this function is called from. - */ - void (*destroy)(struct r300_winsys_screen *ws); - - /** - * Query a system value from a winsys. - * - * \param ws The winsys this function is called from. - * \param vid One of the R300_VID_* enums. - */ - uint32_t (*get_value)(struct r300_winsys_screen *ws, - enum r300_value_id vid); - - /************************************************************************** - * Buffer management. Buffer attributes are mostly fixed over its lifetime. - * - * Remember that gallium gets to choose the interface it needs, and the - * window systems must then implement that interface (rather than the - * other way around...). - *************************************************************************/ - - /** - * Create a buffer object. - * - * \param ws The winsys this function is called from. - * \param size The size to allocate. - * \param alignment An alignment of the buffer in memory. - * \param bind A bitmask of the PIPE_BIND_* flags. - * \param usage A bitmask of the PIPE_USAGE_* flags. - * \param domain A bitmask of the R300_DOMAIN_* flags. - * \return The created buffer object. - */ - struct r300_winsys_bo *(*buffer_create)(struct r300_winsys_screen *ws, - unsigned size, - unsigned alignment, - unsigned bind, - unsigned usage, - enum r300_buffer_domain domain); - - struct r300_winsys_cs_handle *(*buffer_get_cs_handle)( - struct r300_winsys_bo *buf); - - /** - * Map the entire data store of a buffer object into the client's address - * space. - * - * \param buf A winsys buffer object to map. - * \param cs A command stream to flush if the buffer is referenced by it. - * \param usage A bitmask of the PIPE_TRANSFER_* flags. - * \return The pointer at the beginning of the buffer. - */ - void *(*buffer_map)(struct r300_winsys_bo *buf, - struct r300_winsys_cs *cs, - enum pipe_transfer_usage usage); - - /** - * Unmap a buffer object from the client's address space. - * - * \param buf A winsys buffer object to unmap. - */ - void (*buffer_unmap)(struct r300_winsys_bo *buf); - - /** - * Return TRUE if a buffer object is being used by the GPU. - * - * \param buf A winsys buffer object. - */ - boolean (*buffer_is_busy)(struct r300_winsys_bo *buf); - - /** - * Wait for a buffer object until it is not used by a GPU. This is - * equivalent to a fence placed after the last command using the buffer, - * and synchronizing to the fence. - * - * \param buf A winsys buffer object to wait for. - */ - void (*buffer_wait)(struct r300_winsys_bo *buf); - - /** - * Return tiling flags describing a memory layout of a buffer object. - * - * \param buf A winsys buffer object to get the flags from. - * \param macrotile A pointer to the return value of the microtile flag. - * \param microtile A pointer to the return value of the macrotile flag. - * - * \note microtile and macrotile are not bitmasks! - */ - void (*buffer_get_tiling)(struct r300_winsys_bo *buf, - enum r300_buffer_tiling *microtile, - enum r300_buffer_tiling *macrotile); - - /** - * Set tiling flags describing a memory layout of a buffer object. - * - * \param buf A winsys buffer object to set the flags for. - * \param cs A command stream to flush if the buffer is referenced by it. - * \param macrotile A macrotile flag. - * \param microtile A microtile flag. - * \param stride A stride of the buffer in bytes, for texturing. - * - * \note microtile and macrotile are not bitmasks! - */ - void (*buffer_set_tiling)(struct r300_winsys_bo *buf, - struct r300_winsys_cs *cs, - enum r300_buffer_tiling microtile, - enum r300_buffer_tiling macrotile, - unsigned stride); - - /** - * Get a winsys buffer from a winsys handle. The internal structure - * of the handle is platform-specific and only a winsys should access it. - * - * \param ws The winsys this function is called from. - * \param whandle A winsys handle pointer as was received from a state - * tracker. - * \param stride The returned buffer stride in bytes. - * \param size The returned buffer size. - */ - struct r300_winsys_bo *(*buffer_from_handle)(struct r300_winsys_screen *ws, - struct winsys_handle *whandle, - unsigned *stride, - unsigned *size); - - /** - * Get a winsys handle from a winsys buffer. The internal structure - * of the handle is platform-specific and only a winsys should access it. - * - * \param buf A winsys buffer object to get the handle from. - * \param whandle A winsys handle pointer. - * \param stride A stride of the buffer in bytes, for texturing. - * \return TRUE on success. - */ - boolean (*buffer_get_handle)(struct r300_winsys_bo *buf, - unsigned stride, - struct winsys_handle *whandle); - - /************************************************************************** - * Command submission. - * - * Each pipe context should create its own command stream and submit - * commands independently of other contexts. - *************************************************************************/ - - /** - * Create a command stream. - * - * \param ws The winsys this function is called from. - */ - struct r300_winsys_cs *(*cs_create)(struct r300_winsys_screen *ws); - - /** - * Destroy a command stream. - * - * \param cs A command stream to destroy. - */ - void (*cs_destroy)(struct r300_winsys_cs *cs); - - /** - * Add a new buffer relocation. Every relocation must first be added - * before it can be written. - * - * \param cs A command stream to add buffer for validation against. - * \param buf A winsys buffer to validate. - * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags. - * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags. - */ - void (*cs_add_reloc)(struct r300_winsys_cs *cs, - struct r300_winsys_cs_handle *buf, - enum r300_buffer_domain rd, - enum r300_buffer_domain wd); - - /** - * Return TRUE if there is enough memory in VRAM and GTT for the relocs - * added so far. - * - * \param cs A command stream to validate. - */ - boolean (*cs_validate)(struct r300_winsys_cs *cs); - - /** - * Write a relocated dword to a command buffer. - * - * \param cs A command stream the relocation is written to. - * \param buf A winsys buffer to write the relocation for. - * \param rd A read domain containing a bitmask of the R300_DOMAIN_* flags. - * \param wd A write domain containing a bitmask of the R300_DOMAIN_* flags. - */ - void (*cs_write_reloc)(struct r300_winsys_cs *cs, - struct r300_winsys_cs_handle *buf); - - /** - * Flush a command stream. - * - * \param cs A command stream to flush. - * \param flags, R300_FLUSH_ASYNC or 0. - */ - void (*cs_flush)(struct r300_winsys_cs *cs, unsigned flags); - - /** - * Set a flush callback which is called from winsys when flush is - * required. - * - * \param cs A command stream to set the callback for. - * \param flush A flush callback function associated with the command stream. - * \param user A user pointer that will be passed to the flush callback. - */ - void (*cs_set_flush)(struct r300_winsys_cs *cs, - void (*flush)(void *ctx, unsigned flags), - void *user); - - /** - * Return TRUE if a buffer is referenced by a command stream. - * - * \param cs A command stream. - * \param buf A winsys buffer. - */ - boolean (*cs_is_buffer_referenced)(struct r300_winsys_cs *cs, - struct r300_winsys_cs_handle *buf); -}; - -#endif /* R300_WINSYS_H */ diff --git a/src/gallium/drivers/r600/eg_state_inlines.h b/src/gallium/drivers/r600/eg_state_inlines.h index 487adddcb72..f20d45f48de 100644 --- a/src/gallium/drivers/r600/eg_state_inlines.h +++ b/src/gallium/drivers/r600/eg_state_inlines.h @@ -367,10 +367,13 @@ static inline uint32_t r600_translate_colorswap(enum pipe_format format) case PIPE_FORMAT_B10G10R10A2_UNORM: return V_028C70_SWAP_ALT; + case PIPE_FORMAT_R32_FLOAT: + case PIPE_FORMAT_R16G16_FLOAT: case PIPE_FORMAT_R16G16_UNORM: return V_028C70_SWAP_STD; /* 64-bit buffers. */ + case PIPE_FORMAT_R32G32_FLOAT: case PIPE_FORMAT_R16G16B16A16_UNORM: case PIPE_FORMAT_R16G16B16A16_SNORM: case PIPE_FORMAT_R16G16B16A16_SSCALED: @@ -504,6 +507,57 @@ static INLINE uint32_t r600_translate_colorformat(enum pipe_format format) } } +static INLINE uint32_t r600_colorformat_endian_swap(uint32_t colorformat) +{ +#ifdef PIPE_ARCH_BIG_ENDIAN + switch(colorformat) { + case V_0280A0_COLOR_4_4: + return(ENDIAN_NONE); + + /* 8-bit buffers. */ + case V_0280A0_COLOR_8: + return(ENDIAN_NONE); + + /* 16-bit buffers. */ + case V_0280A0_COLOR_5_6_5: + case V_0280A0_COLOR_1_5_5_5: + case V_0280A0_COLOR_4_4_4_4: + case V_0280A0_COLOR_16: + case V_0280A0_COLOR_8_8: + return(ENDIAN_8IN16); + + /* 32-bit buffers. */ + case V_0280A0_COLOR_8_8_8_8: + case V_0280A0_COLOR_2_10_10_10: + case V_0280A0_COLOR_8_24: + case V_0280A0_COLOR_24_8: + case V_0280A0_COLOR_32_FLOAT: + case V_0280A0_COLOR_16_16_FLOAT: + case V_0280A0_COLOR_16_16: + return(ENDIAN_8IN32); + + /* 64-bit buffers. */ + case V_0280A0_COLOR_16_16_16_16: + case V_0280A0_COLOR_16_16_16_16_FLOAT: + return(ENDIAN_8IN16); + + case V_0280A0_COLOR_32_32_FLOAT: + case V_0280A0_COLOR_32_32: + return(ENDIAN_8IN32); + + /* 128-bit buffers. */ + case V_0280A0_COLOR_32_32_32_FLOAT: + case V_0280A0_COLOR_32_32_32_32_FLOAT: + case V_0280A0_COLOR_32_32_32_32: + return(ENDIAN_8IN32); + default: + return ENDIAN_NONE; /* Unsupported. */ + } +#else + return ENDIAN_NONE; +#endif +} + static INLINE boolean r600_is_sampler_format_supported(struct pipe_screen *screen, enum pipe_format format) { return r600_translate_texformat(screen, format, NULL, NULL, NULL) != ~0; diff --git a/src/gallium/drivers/r600/evergreen_state.c b/src/gallium/drivers/r600/evergreen_state.c index 77432661b64..a972f82fb1d 100644 --- a/src/gallium/drivers/r600/evergreen_state.c +++ b/src/gallium/drivers/r600/evergreen_state.c @@ -107,15 +107,18 @@ static void *evergreen_create_blend_state(struct pipe_context *ctx, r600_pipe_state_add_reg(rstate, R_028C3C_PA_SC_AA_MASK, 0xFFFFFFFF, 0xFFFFFFFF, NULL); for (int i = 0; i < 8; i++) { - unsigned eqRGB = state->rt[i].rgb_func; - unsigned srcRGB = state->rt[i].rgb_src_factor; - unsigned dstRGB = state->rt[i].rgb_dst_factor; - unsigned eqA = state->rt[i].alpha_func; - unsigned srcA = state->rt[i].alpha_src_factor; - unsigned dstA = state->rt[i].alpha_dst_factor; + /* state->rt entries > 0 only written if independent blending */ + const int j = state->independent_blend_enable ? i : 0; + + unsigned eqRGB = state->rt[j].rgb_func; + unsigned srcRGB = state->rt[j].rgb_src_factor; + unsigned dstRGB = state->rt[j].rgb_dst_factor; + unsigned eqA = state->rt[j].alpha_func; + unsigned srcA = state->rt[j].alpha_src_factor; + unsigned dstA = state->rt[j].alpha_dst_factor; blend_cntl[i] = 0; - if (!state->rt[i].blend_enable) + if (!state->rt[j].blend_enable) continue; blend_cntl[i] |= S_028780_BLEND_CONTROL_ENABLE(1); @@ -354,7 +357,7 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte const struct util_format_description *desc; struct r600_resource_texture *tmp; struct r600_resource *rbuffer; - unsigned format; + unsigned format, endian; uint32_t word4 = 0, yuv_format = 0, pitch = 0; unsigned char swizzle[4], array_mode = 0, tile_type = 0; struct r600_bo *bo[2]; @@ -391,6 +394,8 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte tmp = tmp->flushed_depth_texture; } + endian = r600_colorformat_endian_swap(format); + if (tmp->force_int_type) { word4 &= C_030010_NUM_FORMAT_ALL; word4 |= S_030010_NUM_FORMAT_ALL(V_030010_SQ_NUM_FORMAT_INT); @@ -422,6 +427,7 @@ static struct pipe_sampler_view *evergreen_create_sampler_view(struct pipe_conte r600_pipe_state_add_reg(rstate, R_030010_RESOURCE0_WORD4, word4 | S_030010_SRF_MODE_ALL(V_030010_SRF_MODE_NO_ZERO) | + S_030010_ENDIAN_SWAP(endian) | S_030010_BASE_LEVEL(state->u.tex.first_level), 0xFFFFFFFF, NULL); r600_pipe_state_add_reg(rstate, R_030014_RESOURCE0_WORD5, S_030014_LAST_LEVEL(state->u.tex.last_level) | @@ -652,7 +658,7 @@ static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state unsigned level = state->cbufs[cb]->u.tex.level; unsigned pitch, slice; unsigned color_info; - unsigned format, swap, ntype; + unsigned format, swap, ntype, endian; unsigned offset; unsigned tile_type; const struct util_format_description *desc; @@ -677,35 +683,43 @@ static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state level, state->cbufs[cb]->u.tex.first_layer); pitch = rtex->pitch_in_blocks[level] / 8 - 1; slice = rtex->pitch_in_blocks[level] * surf->aligned_height / 64 - 1; - ntype = 0; desc = util_format_description(surf->base.format); + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + break; + } + } + ntype = V_028C70_NUMBER_UNORM; if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) ntype = V_028C70_NUMBER_SRGB; + else if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) + ntype = V_028C70_NUMBER_SNORM; format = r600_translate_colorformat(surf->base.format); swap = r600_translate_colorswap(surf->base.format); + if (rbuffer->b.b.b.usage == PIPE_USAGE_STAGING) { + endian = ENDIAN_NONE; + } else { + endian = r600_colorformat_endian_swap(format); + } /* disable when gallium grows int textures */ if ((format == FMT_32_32_32_32 || format == FMT_16_16_16_16) && rtex->force_int_type) - ntype = 4; + ntype = V_028C70_NUMBER_UINT; color_info = S_028C70_FORMAT(format) | S_028C70_COMP_SWAP(swap) | S_028C70_ARRAY_MODE(rtex->array_mode[level]) | S_028C70_BLEND_CLAMP(1) | - S_028C70_NUMBER_TYPE(ntype); + S_028C70_NUMBER_TYPE(ntype) | + S_028C70_ENDIAN(endian); - for (i = 0; i < 4; i++) { - if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { - break; - } - } /* we can only set the export size if any thing is snorm/unorm component is > 11 bits, if we aren't a float, sint or uint */ if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS && desc->channel[i].size < 12 && desc->channel[i].type != UTIL_FORMAT_TYPE_FLOAT && - ntype != 4 && ntype != 5) + ntype != V_028C70_NUMBER_UINT && ntype != V_028C70_NUMBER_SINT) color_info |= S_028C70_SOURCE_FORMAT(V_028C70_EXPORT_4C_16BPC); if (rtex->array_mode[level] > V_028C70_ARRAY_LINEAR_ALIGNED) { @@ -808,6 +822,9 @@ static void evergreen_set_framebuffer_state(struct pipe_context *ctx, if (rstate == NULL) return; + evergreen_context_flush_dest_caches(&rctx->ctx); + rctx->ctx.num_dest_buffers = state->nr_cbufs; + /* unreference old buffer and reference new one */ rstate->id = R600_PIPE_STATE_FRAMEBUFFER; @@ -819,6 +836,7 @@ static void evergreen_set_framebuffer_state(struct pipe_context *ctx, } if (state->zsbuf) { evergreen_db(rctx, rstate, state); + rctx->ctx.num_dest_buffers++; } target_mask = 0x00000000; @@ -880,6 +898,19 @@ static void evergreen_set_framebuffer_state(struct pipe_context *ctx, } } +static void evergreen_texture_barrier(struct pipe_context *ctx) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_context_flush_all(&rctx->ctx, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_CB_ACTION_ENA(1) | + S_0085F0_CB0_DEST_BASE_ENA(1) | S_0085F0_CB1_DEST_BASE_ENA(1) | + S_0085F0_CB2_DEST_BASE_ENA(1) | S_0085F0_CB3_DEST_BASE_ENA(1) | + S_0085F0_CB4_DEST_BASE_ENA(1) | S_0085F0_CB5_DEST_BASE_ENA(1) | + S_0085F0_CB6_DEST_BASE_ENA(1) | S_0085F0_CB7_DEST_BASE_ENA(1) | + S_0085F0_CB8_DEST_BASE_ENA(1) | S_0085F0_CB9_DEST_BASE_ENA(1) | + S_0085F0_CB10_DEST_BASE_ENA(1) | S_0085F0_CB11_DEST_BASE_ENA(1)); +} + void evergreen_init_state_functions(struct r600_pipe_context *rctx) { rctx->context.create_blend_state = evergreen_create_blend_state; @@ -920,6 +951,7 @@ void evergreen_init_state_functions(struct r600_pipe_context *rctx) rctx->context.set_viewport_state = evergreen_set_viewport_state; rctx->context.sampler_view_destroy = r600_sampler_view_destroy; rctx->context.redefine_user_buffer = u_default_redefine_user_buffer; + rctx->context.texture_barrier = evergreen_texture_barrier; } void evergreen_init_config(struct r600_pipe_context *rctx) @@ -1542,8 +1574,10 @@ void evergreen_pipe_set_buffer_resource(struct r600_pipe_context *rctx, r600_pipe_state_add_reg(rstate, R_030004_RESOURCE0_WORD1, rbuffer->bo_size - offset - 1, 0xFFFFFFFF, NULL); r600_pipe_state_add_reg(rstate, R_030008_RESOURCE0_WORD2, - S_030008_STRIDE(stride), - 0xFFFFFFFF, NULL); +#ifdef PIPE_ARCH_BIG_ENDIAN + S_030008_ENDIAN_SWAP(ENDIAN_8IN32) | +#endif + S_030008_STRIDE(stride), 0xFFFFFFFF, NULL); r600_pipe_state_add_reg(rstate, R_03000C_RESOURCE0_WORD3, S_03000C_DST_SEL_X(V_03000C_SQ_SEL_X) | S_03000C_DST_SEL_Y(V_03000C_SQ_SEL_Y) | diff --git a/src/gallium/drivers/r600/evergreend.h b/src/gallium/drivers/r600/evergreend.h index c51a163bd06..de445b879a1 100644 --- a/src/gallium/drivers/r600/evergreend.h +++ b/src/gallium/drivers/r600/evergreend.h @@ -43,6 +43,7 @@ #define EVERGREEN_CTL_CONST_OFFSET 0x0003CFF0 #define EVERGREEN_CTL_CONST_END 0x0003E200 +#define EVENT_TYPE_PS_PARTIAL_FLUSH 0x10 #define EVENT_TYPE_ZPASS_DONE 0x15 #define EVENT_TYPE_CACHE_FLUSH_AND_INV_EVENT 0x16 #define EVENT_TYPE(x) ((x) << 0) @@ -1885,4 +1886,10 @@ #define R_03CFF4_SQ_VTX_START_INST_LOC 0x03CFF4 #define R_03A200_SQ_LOOP_CONST_0 0x3A200 + +#define ENDIAN_NONE 0 +#define ENDIAN_8IN16 1 +#define ENDIAN_8IN32 2 +#define ENDIAN_8IN64 3 + #endif diff --git a/src/gallium/drivers/r600/r600.h b/src/gallium/drivers/r600/r600.h index 0b7d6f70968..0b0df9d019b 100644 --- a/src/gallium/drivers/r600/r600.h +++ b/src/gallium/drivers/r600/r600.h @@ -179,11 +179,13 @@ struct r600_block_reloc { struct r600_block { struct list_head list; unsigned status; + unsigned flags; unsigned start_offset; unsigned pm4_ndwords; unsigned pm4_flush_ndwords; unsigned nbo; - unsigned nreg; + u16 nreg; + u16 nreg_dirty; u32 *reg; u32 pm4[R600_BLOCK_MAX_REG]; unsigned pm4_bo_index[R600_BLOCK_MAX_REG]; @@ -231,6 +233,8 @@ struct r600_query { #define R600_QUERY_STATE_ENDED (1 << 1) #define R600_QUERY_STATE_SUSPENDED (1 << 2) +#define R600_CONTEXT_DRAW_PENDING (1 << 0) +#define R600_CONTEXT_DST_CACHES_DIRTY (1 << 1) struct r600_context { struct radeon *radeon; @@ -253,6 +257,8 @@ struct r600_context { unsigned num_query_running; struct list_head fenced_bo; unsigned max_db; /* for OQ */ + unsigned num_dest_buffers; + unsigned flags; boolean predicate_drawing; }; @@ -288,9 +294,14 @@ void r600_context_queries_suspend(struct r600_context *ctx); void r600_context_queries_resume(struct r600_context *ctx); void r600_query_predication(struct r600_context *ctx, struct r600_query *query, int operation, int flag_wait); +void r600_context_emit_fence(struct r600_context *ctx, struct r600_bo *fence, + unsigned offset, unsigned value); +void r600_context_flush_all(struct r600_context *ctx, unsigned flush_flags); +void r600_context_flush_dest_caches(struct r600_context *ctx); int evergreen_context_init(struct r600_context *ctx, struct radeon *radeon); void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *draw); +void evergreen_context_flush_dest_caches(struct r600_context *ctx); void evergreen_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); void evergreen_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); void evergreen_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid); diff --git a/src/gallium/drivers/r600/r600_asm.c b/src/gallium/drivers/r600/r600_asm.c index 240093f9b9d..7e854b1b81d 100644 --- a/src/gallium/drivers/r600/r600_asm.c +++ b/src/gallium/drivers/r600/r600_asm.c @@ -22,6 +22,7 @@ */ #include <stdio.h> #include <errno.h> +#include <byteswap.h> #include "util/u_format.h" #include "util/u_memory.h" #include "pipe/p_shader_tokens.h" @@ -32,6 +33,12 @@ #include "r600_formats.h" #include "r600d.h" +#ifdef PIPE_ARCH_BIG_ENDIAN +#define CPU_TO_LE32(x) bswap_32(x) +#else +#define CPU_TO_LE32(x) (x) +#endif + #define NUM_OF_CYCLES 3 #define NUM_OF_COMPONENTS 4 @@ -953,10 +960,17 @@ static int merge_inst_groups(struct r600_bc *bc, struct r600_bc_alu *slots[5], } else result[i] = slots[i]; - // let's check source gprs alu = slots[i]; num_once_inst += is_alu_once_inst(bc, alu); + // let's check dst gpr + if (alu->dst.rel) { + if (have_mova) + return 0; + have_rel = 1; + } + + // let's check source gprs num_src = r600_bc_get_num_operands(bc, alu); for (src = 0; src < num_src; ++src) { if (alu->src[src].rel) { @@ -1376,6 +1390,7 @@ static int r600_bc_vtx_build(struct r600_bc *bc, struct r600_bc_vtx *vtx, unsign S_SQ_VTX_WORD1_SRF_MODE_ALL(vtx->srf_mode_all) | S_SQ_VTX_WORD1_GPR_DST_GPR(vtx->dst_gpr); bc->bytecode[id++] = S_SQ_VTX_WORD2_OFFSET(vtx->offset) | + S_SQ_VTX_WORD2_ENDIAN_SWAP(vtx->endian) | S_SQ_VTX_WORD2_MEGA_FETCH(1); bc->bytecode[id++] = 0; return 0; @@ -1910,6 +1925,7 @@ void r600_bc_dump(struct r600_bc *bc) fprintf(stderr, "MODE:%d)\n", vtx->srf_mode_all); id++; fprintf(stderr, "%04d %08X ", id, bc->bytecode[id]); + fprintf(stderr, "ENDIAN:%d ", vtx->endian); fprintf(stderr, "OFFSET:%d\n", vtx->offset); //TODO id++; @@ -1922,7 +1938,7 @@ void r600_bc_dump(struct r600_bc *bc) } static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, - unsigned *num_format, unsigned *format_comp) + unsigned *num_format, unsigned *format_comp, unsigned *endian) { const struct util_format_description *desc; unsigned i; @@ -1930,6 +1946,7 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, *format = 0; *num_format = 0; *format_comp = 0; + *endian = ENDIAN_NONE; desc = util_format_description(pformat); if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { @@ -1960,6 +1977,9 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, *format = FMT_16_16_16_16_FLOAT; break; } +#ifdef PIPE_ARCH_BIG_ENDIAN + *endian = ENDIAN_8IN16; +#endif break; case 32: switch (desc->nr_channels) { @@ -1976,6 +1996,9 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, *format = FMT_32_32_32_32_FLOAT; break; } +#ifdef PIPE_ARCH_BIG_ENDIAN + *endian = ENDIAN_8IN32; +#endif break; default: goto out_unknown; @@ -2013,6 +2036,9 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, *format = FMT_16_16_16_16; break; } +#ifdef PIPE_ARCH_BIG_ENDIAN + *endian = ENDIAN_8IN16; +#endif break; case 32: switch (desc->nr_channels) { @@ -2029,6 +2055,9 @@ static void r600_vertex_data_type(enum pipe_format pformat, unsigned *format, *format = FMT_32_32_32_32; break; } +#ifdef PIPE_ARCH_BIG_ENDIAN + *endian = ENDIAN_8IN32; +#endif break; default: goto out_unknown; @@ -2060,7 +2089,7 @@ int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, stru struct pipe_vertex_element *elements = ve->elements; const struct util_format_description *desc; unsigned fetch_resource_start = rctx->family >= CHIP_CEDAR ? 0 : 160; - unsigned format, num_format, format_comp; + unsigned format, num_format, format_comp, endian; u32 *bytecode; int i, r; @@ -2107,7 +2136,7 @@ int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, stru for (i = 0; i < ve->count; i++) { unsigned vbuffer_index; - r600_vertex_data_type(ve->elements[i].src_format, &format, &num_format, &format_comp); + r600_vertex_data_type(ve->elements[i].src_format, &format, &num_format, &format_comp, &endian); desc = util_format_description(ve->elements[i].src_format); if (desc == NULL) { r600_bc_clear(&bc); @@ -2133,6 +2162,7 @@ int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, stru vtx.format_comp_all = format_comp; vtx.srf_mode_all = 1; vtx.offset = elements[i].src_offset; + vtx.endian = endian; if ((r = r600_bc_add_vtx(&bc, &vtx))) { r600_bc_clear(&bc); @@ -2172,7 +2202,9 @@ int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, stru return -ENOMEM; } - memcpy(bytecode, bc.bytecode, ve->fs_size); + for(i = 0; i < ve->fs_size / 4; i++) { + *(bytecode + i) = CPU_TO_LE32(*(bc.bytecode + i)); + } r600_bo_unmap(rctx->radeon, ve->fetch_shader); r600_bc_clear(&bc); diff --git a/src/gallium/drivers/r600/r600_asm.h b/src/gallium/drivers/r600/r600_asm.h index 27ea293ebe5..26d337fe125 100644 --- a/src/gallium/drivers/r600/r600_asm.h +++ b/src/gallium/drivers/r600/r600_asm.h @@ -104,6 +104,7 @@ struct r600_bc_vtx { unsigned format_comp_all; unsigned srf_mode_all; unsigned offset; + unsigned endian; }; struct r600_bc_output { diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c index 04408a5cc8e..151f48a8bf8 100644 --- a/src/gallium/drivers/r600/r600_blit.c +++ b/src/gallium/drivers/r600/r600_blit.c @@ -277,6 +277,13 @@ static void r600_resource_copy_region(struct pipe_context *ctx, struct texture_orig_info orig_info[2]; boolean restore_orig[2]; + /* Fallback for buffers. */ + if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { + util_resource_copy_region(ctx, dst, dst_level, dstx, dsty, dstz, + src, src_level, src_box); + return; + } + if (rsrc->depth && !rsrc->is_flushing_texture) r600_texture_depth_flush(ctx, src, FALSE); diff --git a/src/gallium/drivers/r600/r600_buffer.c b/src/gallium/drivers/r600/r600_buffer.c index 6ced719c8f0..71b47e1b056 100644 --- a/src/gallium/drivers/r600/r600_buffer.c +++ b/src/gallium/drivers/r600/r600_buffer.c @@ -24,6 +24,8 @@ * Jerome Glisse * Corbin Simpson <[email protected]> */ +#include <byteswap.h> + #include <pipe/p_screen.h> #include <util/u_format.h> #include <util/u_math.h> @@ -266,11 +268,31 @@ void r600_upload_const_buffer(struct r600_pipe_context *rctx, struct r600_resour uint8_t *ptr = (*rbuffer)->r.b.user_ptr; unsigned size = (*rbuffer)->r.b.b.b.width0; boolean flushed; +#ifdef PIPE_ARCH_BIG_ENDIAN + int i; + uint32_t *tmpPtr; + + *rbuffer = NULL; + + tmpPtr = (uint32_t *)malloc(size); + /* big endian swap */ + if(tmpPtr == NULL) { + return; + } + for(i = 0; i < size / 4; i++) { + tmpPtr[i] = bswap_32(*((uint32_t *)ptr + i)); + } + + u_upload_data(rctx->vbuf_mgr->uploader, 0, size, tmpPtr, const_offset, + (struct pipe_resource**)rbuffer, &flushed); + free(tmpPtr); +#else *rbuffer = NULL; u_upload_data(rctx->vbuf_mgr->uploader, 0, size, ptr, const_offset, (struct pipe_resource**)rbuffer, &flushed); +#endif } else { *const_offset = 0; } diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c index 4a30eddb621..89b46f5ad7e 100644 --- a/src/gallium/drivers/r600/r600_pipe.c +++ b/src/gallium/drivers/r600/r600_pipe.c @@ -30,6 +30,7 @@ #include <tgsi/tgsi_util.h> #include <util/u_blitter.h> #include <util/u_double_list.h> +#include "util/u_format.h" #include <util/u_format_s3tc.h> #include <util/u_transfer.h> #include <util/u_surface.h> @@ -37,6 +38,7 @@ #include <util/u_memory.h> #include <util/u_inlines.h> #include "util/u_upload_mgr.h" +#include "os/os_time.h" #include <pipebuffer/pb_buffer.h> #include "r600.h" #include "r600d.h" @@ -49,15 +51,82 @@ /* * pipe_context */ +static struct r600_fence *r600_create_fence(struct r600_pipe_context *ctx) +{ + struct r600_fence *fence = NULL; + + if (!ctx->fences.bo) { + /* Create the shared buffer object */ + ctx->fences.bo = r600_bo(ctx->radeon, 4096, 0, 0, 0); + if (!ctx->fences.bo) { + R600_ERR("r600: failed to create bo for fence objects\n"); + return NULL; + } + ctx->fences.data = r600_bo_map(ctx->radeon, ctx->fences.bo, PB_USAGE_UNSYNCHRONIZED, NULL); + } + + if (!LIST_IS_EMPTY(&ctx->fences.pool)) { + struct r600_fence *entry; + + /* Try to find a freed fence that has been signalled */ + LIST_FOR_EACH_ENTRY(entry, &ctx->fences.pool, head) { + if (ctx->fences.data[entry->index] != 0) { + LIST_DELINIT(&entry->head); + fence = entry; + break; + } + } + } + + if (!fence) { + /* Allocate a new fence */ + struct r600_fence_block *block; + unsigned index; + + if ((ctx->fences.next_index + 1) >= 1024) { + R600_ERR("r600: too many concurrent fences\n"); + return NULL; + } + + index = ctx->fences.next_index++; + + if (!(index % FENCE_BLOCK_SIZE)) { + /* Allocate a new block */ + block = CALLOC_STRUCT(r600_fence_block); + if (block == NULL) + return NULL; + + LIST_ADD(&block->head, &ctx->fences.blocks); + } else { + block = LIST_ENTRY(struct r600_fence_block, ctx->fences.blocks.next, head); + } + + fence = &block->fences[index % FENCE_BLOCK_SIZE]; + fence->ctx = ctx; + fence->index = index; + } + + pipe_reference_init(&fence->reference, 1); + + ctx->fences.data[fence->index] = 0; + r600_context_emit_fence(&ctx->ctx, ctx->fences.bo, fence->index, 1); + return fence; +} + static void r600_flush(struct pipe_context *ctx, struct pipe_fence_handle **fence) { struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + struct r600_fence **rfence = (struct r600_fence**)fence; + #if 0 static int dc = 0; char dname[256]; #endif + if (rfence) + *rfence = r600_create_fence(rctx); + if (!rctx->ctx.pm4_cdwords) return; @@ -101,6 +170,7 @@ static void r600_destroy_context(struct pipe_context *context) struct r600_pipe_context *rctx = (struct r600_pipe_context *)context; rctx->context.delete_depth_stencil_alpha_state(&rctx->context, rctx->custom_dsa_flush); + util_unreference_framebuffer_state(&rctx->framebuffer); r600_context_fini(&rctx->ctx); @@ -113,6 +183,18 @@ static void r600_destroy_context(struct pipe_context *context) u_vbuf_mgr_destroy(rctx->vbuf_mgr); util_slab_destroy(&rctx->pool_transfers); + if (rctx->fences.bo) { + struct r600_fence_block *entry, *tmp; + + LIST_FOR_EACH_ENTRY_SAFE(entry, tmp, &rctx->fences.blocks, head) { + LIST_DEL(&entry->head); + FREE(entry); + } + + r600_bo_unmap(rctx->radeon, rctx->fences.bo); + r600_bo_reference(rctx->radeon, &rctx->fences.bo, NULL); + } + r600_update_num_contexts(rctx->screen, -1); FREE(rctx); @@ -140,6 +222,12 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen, void rctx->radeon = rscreen->radeon; rctx->family = r600_get_family(rctx->radeon); + rctx->fences.bo = NULL; + rctx->fences.data = NULL; + rctx->fences.next_index = 0; + LIST_INITHEAD(&rctx->fences.pool); + LIST_INITHEAD(&rctx->fences.blocks); + r600_init_blit_functions(rctx); r600_init_query_functions(rctx); r600_init_context_resource_functions(rctx); @@ -284,8 +372,8 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param) case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: case PIPE_CAP_DEPTH_CLAMP: case PIPE_CAP_SHADER_STENCIL_EXPORT: - case PIPE_CAP_TGSI_INSTANCEID: case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR: + case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: return 1; case PIPE_CAP_INDEP_BLEND_ENABLE: /* R600 doesn't support per-MRT blends */ @@ -294,10 +382,14 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param) else return 1; + case PIPE_CAP_TGSI_INSTANCEID: + return 0; + /* Unsupported features (boolean caps). */ case PIPE_CAP_STREAM_OUTPUT: case PIPE_CAP_PRIMITIVE_RESTART: case PIPE_CAP_INDEP_BLEND_FUNC: /* FIXME allow this */ + case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL: /* R600 doesn't support per-MRT blends */ if (family == CHIP_R600) return 0; @@ -435,6 +527,9 @@ static boolean r600_is_format_supported(struct pipe_screen* screen, return FALSE; } + if (!util_format_is_supported(format, usage)) + return FALSE; + /* Multisample */ if (sample_count > 1) return FALSE; @@ -492,6 +587,62 @@ static void r600_destroy_screen(struct pipe_screen* pscreen) FREE(rscreen); } +static void r600_fence_reference(struct pipe_screen *pscreen, + struct pipe_fence_handle **ptr, + struct pipe_fence_handle *fence) +{ + struct r600_fence **oldf = (struct r600_fence**)ptr; + struct r600_fence *newf = (struct r600_fence*)fence; + + if (pipe_reference(&(*oldf)->reference, &newf->reference)) { + struct r600_pipe_context *ctx = (*oldf)->ctx; + LIST_ADDTAIL(&(*oldf)->head, &ctx->fences.pool); + } + + *ptr = fence; +} + +static boolean r600_fence_signalled(struct pipe_screen *pscreen, + struct pipe_fence_handle *fence) +{ + struct r600_fence *rfence = (struct r600_fence*)fence; + struct r600_pipe_context *ctx = rfence->ctx; + + return ctx->fences.data[rfence->index]; +} + +static boolean r600_fence_finish(struct pipe_screen *pscreen, + struct pipe_fence_handle *fence, + uint64_t timeout) +{ + struct r600_fence *rfence = (struct r600_fence*)fence; + struct r600_pipe_context *ctx = rfence->ctx; + int64_t start_time = 0; + unsigned spins = 0; + + if (timeout != PIPE_TIMEOUT_INFINITE) { + start_time = os_time_get(); + + /* Convert to microseconds. */ + timeout /= 1000; + } + + while (ctx->fences.data[rfence->index] == 0) { + if (++spins % 256) + continue; +#ifdef PIPE_OS_UNIX + sched_yield(); +#else + os_time_sleep(10); +#endif + if (timeout != PIPE_TIMEOUT_INFINITE && + os_time_get() - start_time >= timeout) { + return FALSE; + } + } + + return TRUE; +} struct pipe_screen *r600_screen_create(struct radeon *radeon) { @@ -513,6 +664,9 @@ struct pipe_screen *r600_screen_create(struct radeon *radeon) rscreen->screen.is_format_supported = r600_is_format_supported; rscreen->screen.context_create = r600_create_context; rscreen->screen.video_context_create = r600_video_create; + rscreen->screen.fence_reference = r600_fence_reference; + rscreen->screen.fence_signalled = r600_fence_signalled; + rscreen->screen.fence_finish = r600_fence_finish; r600_init_screen_resource_functions(&rscreen->screen); rscreen->tiling_info = r600_get_tiling_info(radeon); diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h index 396801e4a41..88aff0e81bb 100644 --- a/src/gallium/drivers/r600/r600_pipe.h +++ b/src/gallium/drivers/r600/r600_pipe.h @@ -124,6 +124,30 @@ struct r600_textures_info { unsigned n_samplers; }; +struct r600_fence { + struct pipe_reference reference; + struct r600_pipe_context *ctx; + unsigned index; /* in the shared bo */ + struct list_head head; +}; + +#define FENCE_BLOCK_SIZE 16 + +struct r600_fence_block { + struct r600_fence fences[FENCE_BLOCK_SIZE]; + struct list_head head; +}; + +struct r600_pipe_fences { + struct r600_bo *bo; + unsigned *data; + unsigned next_index; + /* linked list of preallocated blocks */ + struct list_head blocks; + /* linked list of freed fences */ + struct list_head pool; +}; + #define R600_CONSTANT_ARRAY_SIZE 256 #define R600_RESOURCE_ARRAY_SIZE 160 @@ -158,9 +182,12 @@ struct r600_pipe_context { bool flatshade; struct r600_textures_info ps_samplers; + struct r600_pipe_fences fences; + struct u_vbuf_mgr *vbuf_mgr; struct util_slab_mempool pool_transfers; bool blit; + }; struct r600_drawl { diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index e7285d624e3..188cea0ff88 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -33,6 +33,13 @@ #include "r600d.h" #include <stdio.h> #include <errno.h> +#include <byteswap.h> + +#ifdef PIPE_ARCH_BIG_ENDIAN +#define CPU_TO_LE32(x) bswap_32(x) +#else +#define CPU_TO_LE32(x) (x) +#endif int r600_find_vs_semantic_index(struct r600_shader *vs, struct r600_shader *ps, int id) @@ -52,7 +59,8 @@ static int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *s { struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; struct r600_shader *rshader = &shader->shader; - void *ptr; + uint32_t *ptr; + int i; /* copy new shader */ if (shader->bo == NULL) { @@ -60,8 +68,10 @@ static int r600_pipe_shader(struct pipe_context *ctx, struct r600_pipe_shader *s if (shader->bo == NULL) { return -ENOMEM; } - ptr = r600_bo_map(rctx->radeon, shader->bo, 0, NULL); - memcpy(ptr, rshader->bc.bytecode, rshader->bc.ndw * 4); + ptr = (uint32_t*)r600_bo_map(rctx->radeon, shader->bo, 0, NULL); + for(i = 0; i < rshader->bc.ndw; i++) { + *(ptr + i) = CPU_TO_LE32(*(rshader->bc.bytecode + i)); + } r600_bo_unmap(rctx->radeon, shader->bo); } /* build state */ @@ -467,6 +477,11 @@ static int tgsi_fetch_rel_const(struct r600_shader_ctx *ctx, unsigned int offset vtx.num_format_all = 2; /* NUM_FORMAT_SCALED */ vtx.format_comp_all = 1; /* FORMAT_COMP_SIGNED */ vtx.srf_mode_all = 1; /* SRF_MODE_NO_ZERO */ +#ifdef PIPE_ARCH_BIG_ENDIAN + vtx.endian = ENDIAN_8IN32; +#else + vtx.endian = ENDIAN_NONE; +#endif if ((r = r600_bc_add_vtx(ctx->bc, &vtx))) return r; @@ -1526,9 +1541,13 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) unsigned src_gpr; int r, i; int opcode; - boolean src_not_temp = - inst->Src[0].Register.File != TGSI_FILE_TEMPORARY && - inst->Src[0].Register.File != TGSI_FILE_INPUT; + /* Texture fetch instructions can only use gprs as source. + * Also they cannot negate the source or take the absolute value */ + const boolean src_requires_loading = + (inst->Src[0].Register.File != TGSI_FILE_TEMPORARY && + inst->Src[0].Register.File != TGSI_FILE_INPUT) || + ctx->src[0].neg || ctx->src[0].abs; + boolean src_loaded = FALSE; src_gpr = ctx->file_offset[inst->Src[0].Register.File] + inst->Src[0].Register.Index; @@ -1570,7 +1589,7 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) r = r600_bc_add_alu(ctx->bc, &alu); if (r) return r; - src_not_temp = FALSE; + src_loaded = TRUE; src_gpr = ctx->temp_reg; } @@ -1655,11 +1674,11 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) if (r) return r; - src_not_temp = FALSE; + src_loaded = TRUE; src_gpr = ctx->temp_reg; } - if (src_not_temp) { + if (src_requires_loading && !src_loaded) { for (i = 0; i < 4; i++) { memset(&alu, 0, sizeof(struct r600_bc_alu)); alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MOV); @@ -1673,6 +1692,7 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) if (r) return r; } + src_loaded = TRUE; src_gpr = ctx->temp_reg; } @@ -1691,10 +1711,18 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) tex.dst_sel_y = (inst->Dst[0].Register.WriteMask & 2) ? 1 : 7; tex.dst_sel_z = (inst->Dst[0].Register.WriteMask & 4) ? 2 : 7; tex.dst_sel_w = (inst->Dst[0].Register.WriteMask & 8) ? 3 : 7; - tex.src_sel_x = 0; - tex.src_sel_y = 1; - tex.src_sel_z = 2; - tex.src_sel_w = 3; + if (src_loaded) { + tex.src_sel_x = 0; + tex.src_sel_y = 1; + tex.src_sel_z = 2; + tex.src_sel_w = 3; + } else { + tex.src_sel_x = ctx->src[0].swizzle[0]; + tex.src_sel_y = ctx->src[0].swizzle[1]; + tex.src_sel_z = ctx->src[0].swizzle[2]; + tex.src_sel_w = ctx->src[0].swizzle[3]; + tex.src_rel = ctx->src[0].rel; + } if (inst->Texture.Texture == TGSI_TEXTURE_CUBE) { tex.src_sel_x = 1; @@ -1712,12 +1740,12 @@ static int tgsi_tex(struct r600_shader_ctx *ctx) if (inst->Texture.Texture == TGSI_TEXTURE_1D_ARRAY) { tex.coord_type_z = 0; - tex.src_sel_z = 1; + tex.src_sel_z = tex.src_sel_y; } else if (inst->Texture.Texture == TGSI_TEXTURE_2D_ARRAY) tex.coord_type_z = 0; if (inst->Texture.Texture == TGSI_TEXTURE_SHADOW1D || inst->Texture.Texture == TGSI_TEXTURE_SHADOW2D) - tex.src_sel_w = 2; + tex.src_sel_w = tex.src_sel_z; r = r600_bc_add_tex(ctx->bc, &tex); if (r) diff --git a/src/gallium/drivers/r600/r600_state.c b/src/gallium/drivers/r600/r600_state.c index efb68cbd139..ac2e8986b97 100644 --- a/src/gallium/drivers/r600/r600_state.c +++ b/src/gallium/drivers/r600/r600_state.c @@ -161,16 +161,19 @@ static void *r600_create_blend_state(struct pipe_context *ctx, color_control, 0xFFFFFFFD, NULL); for (int i = 0; i < 8; i++) { - unsigned eqRGB = state->rt[i].rgb_func; - unsigned srcRGB = state->rt[i].rgb_src_factor; - unsigned dstRGB = state->rt[i].rgb_dst_factor; + /* state->rt entries > 0 only written if independent blending */ + const int j = state->independent_blend_enable ? i : 0; - unsigned eqA = state->rt[i].alpha_func; - unsigned srcA = state->rt[i].alpha_src_factor; - unsigned dstA = state->rt[i].alpha_dst_factor; + unsigned eqRGB = state->rt[j].rgb_func; + unsigned srcRGB = state->rt[j].rgb_src_factor; + unsigned dstRGB = state->rt[j].rgb_dst_factor; + + unsigned eqA = state->rt[j].alpha_func; + unsigned srcA = state->rt[j].alpha_src_factor; + unsigned dstA = state->rt[j].alpha_dst_factor; uint32_t bc = 0; - if (!state->rt[i].blend_enable) + if (!state->rt[j].blend_enable) continue; bc |= S_028804_COLOR_COMB_FCN(r600_translate_blend_function(eqRGB)); @@ -410,7 +413,7 @@ static struct pipe_sampler_view *r600_create_sampler_view(struct pipe_context *c const struct util_format_description *desc; struct r600_resource_texture *tmp; struct r600_resource *rbuffer; - unsigned format; + unsigned format, endian; uint32_t word4 = 0, yuv_format = 0, pitch = 0; unsigned char swizzle[4], array_mode = 0, tile_type = 0; struct r600_bo *bo[2]; @@ -447,6 +450,7 @@ static struct pipe_sampler_view *r600_create_sampler_view(struct pipe_context *c r600_texture_depth_flush(ctx, texture, TRUE); tmp = tmp->flushed_depth_texture; } + endian = r600_colorformat_endian_swap(format); if (tmp->force_int_type) { word4 &= C_038010_NUM_FORMAT_ALL; @@ -487,6 +491,7 @@ static struct pipe_sampler_view *r600_create_sampler_view(struct pipe_context *c word4 | S_038010_SRF_MODE_ALL(V_038010_SRF_MODE_NO_ZERO) | S_038010_REQUEST_SIZE(1) | + S_038010_ENDIAN_SWAP(endian) | S_038010_BASE_LEVEL(state->u.tex.first_level), 0xFFFFFFFF, NULL); r600_pipe_state_add_reg(rstate, R_038014_RESOURCE0_WORD5, S_038014_LAST_LEVEL(state->u.tex.last_level) | @@ -715,7 +720,7 @@ static void r600_cb(struct r600_pipe_context *rctx, struct r600_pipe_state *rsta unsigned level = state->cbufs[cb]->u.tex.level; unsigned pitch, slice; unsigned color_info; - unsigned format, swap, ntype; + unsigned format, swap, ntype, endian; unsigned offset; const struct util_format_description *desc; struct r600_bo *bo[3]; @@ -739,40 +744,37 @@ static void r600_cb(struct r600_pipe_context *rctx, struct r600_pipe_state *rsta level, state->cbufs[cb]->u.tex.first_layer); pitch = rtex->pitch_in_blocks[level] / 8 - 1; slice = rtex->pitch_in_blocks[level] * surf->aligned_height / 64 - 1; - ntype = 0; desc = util_format_description(surf->base.format); - if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) - ntype = V_0280A0_NUMBER_SRGB; - else if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN) { - switch(desc->channel[0].type) { - case UTIL_FORMAT_TYPE_UNSIGNED: - ntype = V_0280A0_NUMBER_UNORM; - break; - - case UTIL_FORMAT_TYPE_SIGNED: - ntype = V_0280A0_NUMBER_SNORM; - break; - } - } for (i = 0; i < 4; i++) { if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { break; } } + ntype = V_0280A0_NUMBER_UNORM; + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) + ntype = V_0280A0_NUMBER_SRGB; + else if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) + ntype = V_0280A0_NUMBER_SNORM; format = r600_translate_colorformat(surf->base.format); swap = r600_translate_colorswap(surf->base.format); + if(rbuffer->b.b.b.usage == PIPE_USAGE_STAGING) { + endian = ENDIAN_NONE; + } else { + endian = r600_colorformat_endian_swap(format); + } /* disable when gallium grows int textures */ if ((format == FMT_32_32_32_32 || format == FMT_16_16_16_16) && rtex->force_int_type) - ntype = 4; + ntype = V_0280A0_NUMBER_UINT; color_info = S_0280A0_FORMAT(format) | S_0280A0_COMP_SWAP(swap) | S_0280A0_ARRAY_MODE(rtex->array_mode[level]) | S_0280A0_BLEND_CLAMP(1) | - S_0280A0_NUMBER_TYPE(ntype); + S_0280A0_NUMBER_TYPE(ntype) | + S_0280A0_ENDIAN(endian); /* on R600 this can't be set if BLEND_CLAMP isn't set, if BLEND_FLOAT32 is set of > 11 bits in a UNORM or SNORM */ @@ -855,6 +857,9 @@ static void r600_set_framebuffer_state(struct pipe_context *ctx, if (rstate == NULL) return; + r600_context_flush_dest_caches(&rctx->ctx); + rctx->ctx.num_dest_buffers = state->nr_cbufs; + /* unreference old buffer and reference new one */ rstate->id = R600_PIPE_STATE_FRAMEBUFFER; @@ -866,6 +871,7 @@ static void r600_set_framebuffer_state(struct pipe_context *ctx, } if (state->zsbuf) { r600_db(rctx, rstate, state); + rctx->ctx.num_dest_buffers++; } target_mask = 0x00000000; @@ -945,6 +951,17 @@ static void r600_set_framebuffer_state(struct pipe_context *ctx, } } +static void r600_texture_barrier(struct pipe_context *ctx) +{ + struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; + + r600_context_flush_all(&rctx->ctx, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_CB_ACTION_ENA(1) | + S_0085F0_CB0_DEST_BASE_ENA(1) | S_0085F0_CB1_DEST_BASE_ENA(1) | + S_0085F0_CB2_DEST_BASE_ENA(1) | S_0085F0_CB3_DEST_BASE_ENA(1) | + S_0085F0_CB4_DEST_BASE_ENA(1) | S_0085F0_CB5_DEST_BASE_ENA(1) | + S_0085F0_CB6_DEST_BASE_ENA(1) | S_0085F0_CB7_DEST_BASE_ENA(1)); +} + void r600_init_state_functions(struct r600_pipe_context *rctx) { rctx->context.create_blend_state = r600_create_blend_state; @@ -985,6 +1002,7 @@ void r600_init_state_functions(struct r600_pipe_context *rctx) rctx->context.set_viewport_state = r600_set_viewport_state; rctx->context.sampler_view_destroy = r600_sampler_view_destroy; rctx->context.redefine_user_buffer = u_default_redefine_user_buffer; + rctx->context.texture_barrier = r600_texture_barrier; } void r600_init_config(struct r600_pipe_context *rctx) @@ -1443,8 +1461,10 @@ void r600_pipe_set_buffer_resource(struct r600_pipe_context *rctx, r600_pipe_state_add_reg(rstate, R_038004_RESOURCE0_WORD1, rbuffer->bo_size - offset - 1, 0xFFFFFFFF, NULL); r600_pipe_state_add_reg(rstate, R_038008_RESOURCE0_WORD2, - S_038008_STRIDE(stride), - 0xFFFFFFFF, NULL); +#ifdef PIPE_ARCH_BIG_ENDIAN + S_038008_ENDIAN_SWAP(ENDIAN_8IN32) | +#endif + S_038008_STRIDE(stride), 0xFFFFFFFF, NULL); r600_pipe_state_add_reg(rstate, R_03800C_RESOURCE0_WORD3, 0x00000000, 0xFFFFFFFF, NULL); r600_pipe_state_add_reg(rstate, R_038010_RESOURCE0_WORD4, diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c index 43dad0c8023..997c9a597ee 100644 --- a/src/gallium/drivers/r600/r600_state_common.c +++ b/src/gallium/drivers/r600/r600_state_common.c @@ -435,7 +435,7 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info) { struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx; struct r600_resource *rbuffer; - u32 vgt_dma_index_type, vgt_draw_initiator, mask; + u32 vgt_dma_index_type, vgt_dma_swap_mode, vgt_draw_initiator, mask; struct r600_draw rdraw; struct r600_pipe_state vgt; struct r600_drawl draw = {}; @@ -467,14 +467,21 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info) draw.info.index_bias = info->start; } + vgt_dma_swap_mode = 0; switch (draw.index_size) { case 2: vgt_draw_initiator = 0; vgt_dma_index_type = 0; +#ifdef PIPE_ARCH_BIG_ENDIAN + vgt_dma_swap_mode = ENDIAN_8IN16; +#endif break; case 4: vgt_draw_initiator = 0; vgt_dma_index_type = 1; +#ifdef PIPE_ARCH_BIG_ENDIAN + vgt_dma_swap_mode = ENDIAN_8IN32; +#endif break; case 0: vgt_draw_initiator = 2; @@ -521,7 +528,7 @@ void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info) rdraw.vgt_num_indices = draw.info.count; rdraw.vgt_num_instances = draw.info.instance_count; - rdraw.vgt_index_type = vgt_dma_index_type; + rdraw.vgt_index_type = vgt_dma_index_type | (vgt_dma_swap_mode << 2); rdraw.vgt_draw_initiator = vgt_draw_initiator; rdraw.indices = NULL; if (draw.index_buffer) { diff --git a/src/gallium/drivers/r600/r600_state_inlines.h b/src/gallium/drivers/r600/r600_state_inlines.h index 2a40f41bbf5..5eabfdc2bc6 100644 --- a/src/gallium/drivers/r600/r600_state_inlines.h +++ b/src/gallium/drivers/r600/r600_state_inlines.h @@ -363,9 +363,12 @@ static inline uint32_t r600_translate_colorswap(enum pipe_format format) return V_0280A0_SWAP_ALT; case PIPE_FORMAT_R16G16_UNORM: + case PIPE_FORMAT_R16G16_FLOAT: + case PIPE_FORMAT_R32_FLOAT: return V_0280A0_SWAP_STD; /* 64-bit buffers. */ + case PIPE_FORMAT_R32G32_FLOAT: case PIPE_FORMAT_R16G16B16A16_UNORM: case PIPE_FORMAT_R16G16B16A16_SNORM: case PIPE_FORMAT_R16G16B16A16_SSCALED: @@ -501,6 +504,57 @@ static INLINE uint32_t r600_translate_colorformat(enum pipe_format format) } } +static INLINE uint32_t r600_colorformat_endian_swap(uint32_t colorformat) +{ +#ifdef PIPE_ARCH_BIG_ENDIAN + switch(colorformat) { + case V_0280A0_COLOR_4_4: + return(ENDIAN_NONE); + + /* 8-bit buffers. */ + case V_0280A0_COLOR_8: + return(ENDIAN_NONE); + + /* 16-bit buffers. */ + case V_0280A0_COLOR_5_6_5: + case V_0280A0_COLOR_1_5_5_5: + case V_0280A0_COLOR_4_4_4_4: + case V_0280A0_COLOR_16: + case V_0280A0_COLOR_8_8: + return(ENDIAN_8IN16); + + /* 32-bit buffers. */ + case V_0280A0_COLOR_8_8_8_8: + case V_0280A0_COLOR_2_10_10_10: + case V_0280A0_COLOR_8_24: + case V_0280A0_COLOR_24_8: + case V_0280A0_COLOR_32_FLOAT: + case V_0280A0_COLOR_16_16_FLOAT: + case V_0280A0_COLOR_16_16: + return(ENDIAN_8IN32); + + /* 64-bit buffers. */ + case V_0280A0_COLOR_16_16_16_16: + case V_0280A0_COLOR_16_16_16_16_FLOAT: + return(ENDIAN_8IN16); + + case V_0280A0_COLOR_32_32_FLOAT: + case V_0280A0_COLOR_32_32: + return(ENDIAN_8IN32); + + /* 128-bit buffers. */ + case V_0280A0_COLOR_32_32_32_FLOAT: + case V_0280A0_COLOR_32_32_32_32_FLOAT: + case V_0280A0_COLOR_32_32_32_32: + return(ENDIAN_8IN32); + default: + return ENDIAN_NONE; /* Unsupported. */ + } +#else + return ENDIAN_NONE; +#endif +} + static INLINE boolean r600_is_sampler_format_supported(struct pipe_screen *screen, enum pipe_format format) { return r600_translate_texformat(screen, format, NULL, NULL, NULL) != ~0; diff --git a/src/gallium/drivers/r600/r600d.h b/src/gallium/drivers/r600/r600d.h index df70e2889e2..2bff52bec8c 100644 --- a/src/gallium/drivers/r600/r600d.h +++ b/src/gallium/drivers/r600/r600d.h @@ -3460,4 +3460,10 @@ #define SQ_TEX_INST_SAMPLE 0x10 #define SQ_TEX_INST_SAMPLE_L 0x11 #define SQ_TEX_INST_SAMPLE_C 0x18 + +#define ENDIAN_NONE 0 +#define ENDIAN_8IN16 1 +#define ENDIAN_8IN32 2 +#define ENDIAN_8IN64 3 + #endif diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c index c09ce19559c..02892c16bde 100644 --- a/src/gallium/drivers/softpipe/sp_tex_sample.c +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c @@ -566,7 +566,7 @@ compute_lambda_1d(const struct sp_sampler_variant *samp, const struct pipe_resource *texture = samp->view->texture; float dsdx = fabsf(s[QUAD_BOTTOM_RIGHT] - s[QUAD_BOTTOM_LEFT]); float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); - float rho = MAX2(dsdx, dsdy) * texture->width0; + float rho = MAX2(dsdx, dsdy) * u_minify(texture->width0, samp->view->u.tex.first_level); return util_fast_log2(rho); } @@ -583,8 +583,8 @@ compute_lambda_2d(const struct sp_sampler_variant *samp, float dsdy = fabsf(s[QUAD_TOP_LEFT] - s[QUAD_BOTTOM_LEFT]); float dtdx = fabsf(t[QUAD_BOTTOM_RIGHT] - t[QUAD_BOTTOM_LEFT]); float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); - float maxx = MAX2(dsdx, dsdy) * texture->width0; - float maxy = MAX2(dtdx, dtdy) * texture->height0; + float maxx = MAX2(dsdx, dsdy) * u_minify(texture->width0, samp->view->u.tex.first_level); + float maxy = MAX2(dtdx, dtdy) * u_minify(texture->height0, samp->view->u.tex.first_level); float rho = MAX2(maxx, maxy); return util_fast_log2(rho); @@ -604,9 +604,9 @@ compute_lambda_3d(const struct sp_sampler_variant *samp, float dtdy = fabsf(t[QUAD_TOP_LEFT] - t[QUAD_BOTTOM_LEFT]); float dpdx = fabsf(p[QUAD_BOTTOM_RIGHT] - p[QUAD_BOTTOM_LEFT]); float dpdy = fabsf(p[QUAD_TOP_LEFT] - p[QUAD_BOTTOM_LEFT]); - float maxx = MAX2(dsdx, dsdy) * texture->width0; - float maxy = MAX2(dtdx, dtdy) * texture->height0; - float maxz = MAX2(dpdx, dpdy) * texture->depth0; + float maxx = MAX2(dsdx, dsdy) * u_minify(texture->width0, samp->view->u.tex.first_level); + float maxy = MAX2(dtdx, dtdy) * u_minify(texture->height0, samp->view->u.tex.first_level); + float maxz = MAX2(dpdx, dpdy) * u_minify(texture->depth0, samp->view->u.tex.first_level); float rho; rho = MAX2(maxx, maxy); @@ -1590,10 +1590,10 @@ mip_filter_linear(struct tgsi_sampler *tgsi_sampler, /* XXX: Take into account all lod values. */ lambda = lod[0]; - level0 = (int)lambda; + level0 = samp->view->u.tex.first_level + (int)lambda; if (lambda < 0.0) { - samp->level = 0; + samp->level = samp->view->u.tex.first_level; samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); } else if (level0 >= texture->last_level) { @@ -1601,7 +1601,7 @@ mip_filter_linear(struct tgsi_sampler *tgsi_sampler, samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); } else { - float levelBlend = lambda - level0; + float levelBlend = frac(lambda); float rgba0[4][4]; float rgba1[4][4]; int c,j; @@ -1658,11 +1658,11 @@ mip_filter_nearest(struct tgsi_sampler *tgsi_sampler, lambda = lod[0]; if (lambda < 0.0) { - samp->level = 0; + samp->level = samp->view->u.tex.first_level; samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); } else { - samp->level = (int)(lambda + 0.5) ; + samp->level = samp->view->u.tex.first_level + (int)(lambda + 0.5) ; samp->level = MIN2(samp->level, (int)texture->last_level); samp->min_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); } @@ -1699,6 +1699,7 @@ mip_filter_none(struct tgsi_sampler *tgsi_sampler, */ lambda = lod[0]; + samp->level = samp->view->u.tex.first_level; if (lambda < 0.0) { samp->mag_img_filter(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); } @@ -1741,20 +1742,20 @@ mip_filter_linear_2d_linear_repeat_POT( /* XXX: Take into account all lod values. */ lambda = lod[0]; - level0 = (int)lambda; + level0 = samp->view->u.tex.first_level + (int)lambda; /* Catches both negative and large values of level0: */ if ((unsigned)level0 >= texture->last_level) { if (level0 < 0) - samp->level = 0; + samp->level = samp->view->u.tex.first_level; else samp->level = texture->last_level; img_filter_2d_linear_repeat_POT(tgsi_sampler, s, t, p, NULL, tgsi_sampler_lod_bias, rgba); } else { - float levelBlend = lambda - level0; + float levelBlend = frac(lambda); float rgba0[4][4]; float rgba1[4][4]; int c,j; @@ -2238,14 +2239,13 @@ sp_sampler_variant_bind_view( struct sp_sampler_variant *samp, struct softpipe_tex_tile_cache *tex_cache, const struct pipe_sampler_view *view ) { - const struct pipe_sampler_state *sampler = samp->sampler; const struct pipe_resource *texture = view->texture; samp->view = view; samp->cache = tex_cache; samp->xpot = util_unsigned_logbase2( texture->width0 ); samp->ypot = util_unsigned_logbase2( texture->height0 ); - samp->level = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level); + samp->level = view->u.tex.first_level; } diff --git a/src/gallium/drivers/svga/include/svga3d_reg.h b/src/gallium/drivers/svga/include/svga3d_reg.h index 77cb4533100..a527d7dcf20 100644 --- a/src/gallium/drivers/svga/include/svga3d_reg.h +++ b/src/gallium/drivers/svga/include/svga3d_reg.h @@ -968,12 +968,18 @@ typedef enum { } SVGA3dTransferType; /* - * The maximum number vertex arrays we're guaranteed to support in + * The maximum number of vertex arrays we're guaranteed to support in * SVGA_3D_CMD_DRAWPRIMITIVES. */ #define SVGA3D_MAX_VERTEX_ARRAYS 32 /* + * The maximum number of primitive ranges we're guaranteed to support + * in SVGA_3D_CMD_DRAWPRIMITIVES. + */ +#define SVGA3D_MAX_DRAW_PRIMITIVE_RANGES 32 + +/* * Identifiers for commands in the command FIFO. * * IDs between 1000 and 1039 (inclusive) were used by obsolete versions of @@ -1474,10 +1480,12 @@ struct { * SVGA3dCmdDrawPrimitives structure. In order, * they are: * - * 1. SVGA3dVertexDecl, quantity 'numVertexDecls' - * 2. SVGA3dPrimitiveRange, quantity 'numRanges' + * 1. SVGA3dVertexDecl, quantity 'numVertexDecls', but no more than + * SVGA3D_MAX_VERTEX_ARRAYS; + * 2. SVGA3dPrimitiveRange, quantity 'numRanges', but no more than + * SVGA3D_MAX_DRAW_PRIMITIVE_RANGES; * 3. Optionally, SVGA3dVertexDivisor, quantity 'numVertexDecls' (contains - * the frequency divisor for this the corresponding vertex decl) + * the frequency divisor for the corresponding vertex decl). */ } SVGA3dCmdDrawPrimitives; /* SVGA_3D_CMD_DRAWPRIMITIVES */ diff --git a/src/gallium/drivers/svga/svga_context.c b/src/gallium/drivers/svga/svga_context.c index 4782b4bf70e..dbbc249258d 100644 --- a/src/gallium/drivers/svga/svga_context.c +++ b/src/gallium/drivers/svga/svga_context.c @@ -204,7 +204,6 @@ void svga_context_flush( struct svga_context *svga, { struct svga_screen *svgascreen = svga_screen(svga->pipe.screen); struct pipe_fence_handle *fence = NULL; - enum pipe_error ret; svga->curr.nr_fbs = 0; @@ -219,25 +218,11 @@ void svga_context_flush( struct svga_context *svga, svga_screen_cache_flush(svgascreen, fence); - /* To force the reemission of rendertargets and texture bindings at - * the beginning of every command buffer. - */ - svga->dirty |= SVGA_NEW_COMMAND_BUFFER; - - /* - * We must reemit the surface bindings here, because svga_update_state - * will always flush the primitives before processing the - * SVGA_NEW_COMMAND_BUFFER state change. - * - * TODO: Refactor this. + /* To force the re-emission of rendertargets and texture sampler bindings on + * the next command buffer. */ - ret = svga_reemit_framebuffer_bindings(svga); - assert(ret == PIPE_OK); - - ret = svga_reemit_tss_bindings(svga); - assert(ret == PIPE_OK); - - svga->dirty &= ~SVGA_NEW_COMMAND_BUFFER; + svga->rebind.rendertargets = TRUE; + svga->rebind.texture_samplers = TRUE; if (SVGA_DEBUG & DEBUG_SYNC) { if (fence) diff --git a/src/gallium/drivers/svga/svga_context.h b/src/gallium/drivers/svga/svga_context.h index 7b36a3606e0..eca529d262e 100644 --- a/src/gallium/drivers/svga/svga_context.h +++ b/src/gallium/drivers/svga/svga_context.h @@ -358,6 +358,11 @@ struct svga_context struct svga_state curr; /* state from the state tracker */ unsigned dirty; /* statechanges since last update_state() */ + struct { + unsigned rendertargets:1; + unsigned texture_samplers:1; + } rebind; + struct u_upload_mgr *upload_ib; struct u_upload_mgr *upload_vb; struct svga_hwtnl *hwtnl; @@ -402,7 +407,6 @@ struct svga_context #define SVGA_NEW_ZERO_STRIDE 0x2000000 #define SVGA_NEW_TEXTURE_FLAGS 0x4000000 #define SVGA_NEW_STENCIL_REF 0x8000000 -#define SVGA_NEW_COMMAND_BUFFER 0x10000000 diff --git a/src/gallium/drivers/svga/svga_draw.c b/src/gallium/drivers/svga/svga_draw.c index 2c873a0f7ac..d8af615ede1 100644 --- a/src/gallium/drivers/svga/svga_draw.c +++ b/src/gallium/drivers/svga/svga_draw.c @@ -170,6 +170,20 @@ svga_hwtnl_flush( struct svga_hwtnl *hwtnl ) ib_handle[i] = handle; } + if (svga->rebind.rendertargets) { + ret = svga_reemit_framebuffer_bindings(svga); + if (ret != PIPE_OK) { + return ret; + } + } + + if (svga->rebind.texture_samplers) { + ret = svga_reemit_tss_bindings(svga); + if (ret != PIPE_OK) { + return ret; + } + } + SVGA_DBG(DEBUG_DMA, "draw to sid %p, %d prims\n", svga->curr.framebuffer.cbufs[0] ? svga_surface(svga->curr.framebuffer.cbufs[0])->handle : NULL, diff --git a/src/gallium/drivers/svga/svga_draw_private.h b/src/gallium/drivers/svga/svga_draw_private.h index 11afb59875b..ca658ac6745 100644 --- a/src/gallium/drivers/svga/svga_draw_private.h +++ b/src/gallium/drivers/svga/svga_draw_private.h @@ -93,7 +93,9 @@ struct index_cache { struct pipe_resource *buffer; }; -#define QSZ 32 + +/** Max number of primitives per draw call */ +#define QSZ SVGA3D_MAX_DRAW_PRIMITIVE_RANGES struct draw_cmd { struct svga_winsys_context *swc; diff --git a/src/gallium/drivers/svga/svga_pipe_blit.c b/src/gallium/drivers/svga/svga_pipe_blit.c index c87afb6946c..c4f122f4f78 100644 --- a/src/gallium/drivers/svga/svga_pipe_blit.c +++ b/src/gallium/drivers/svga/svga_pipe_blit.c @@ -29,6 +29,8 @@ #include "svga_cmd.h" #include "svga_surface.h" +#include "util/u_surface.h" + #define FILE_DEBUG_FLAG DEBUG_BLIT @@ -54,6 +56,13 @@ static void svga_surface_copy(struct pipe_context *pipe, */ svga_surfaces_flush( svga ); + /* Fallback for buffers. */ + if (dst_tex->target == PIPE_BUFFER && src_tex->target == PIPE_BUFFER) { + util_resource_copy_region(pipe, dst_tex, dst_level, dstx, dsty, dstz, + src_tex, src_level, src_box); + return; + } + #if 0 srcsurf = screen->get_tex_surface(screen, src_tex, src_level, src_box->z, src_box->z, diff --git a/src/gallium/drivers/svga/svga_pipe_clear.c b/src/gallium/drivers/svga/svga_pipe_clear.c index 41f239c1a85..b288c3eb2a6 100644 --- a/src/gallium/drivers/svga/svga_pipe_clear.c +++ b/src/gallium/drivers/svga/svga_pipe_clear.c @@ -52,6 +52,13 @@ try_clear(struct svga_context *svga, if (ret) return ret; + if (svga->rebind.rendertargets) { + ret = svga_reemit_framebuffer_bindings(svga); + if (ret != PIPE_OK) { + return ret; + } + } + if ((buffers & PIPE_CLEAR_COLOR) && fb->cbufs[0]) { flags |= SVGA3D_CLEAR_COLOR; util_pack_color(rgba, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); diff --git a/src/gallium/drivers/svga/svga_resource_buffer_upload.c b/src/gallium/drivers/svga/svga_resource_buffer_upload.c index e5fcec08d6e..923958674b4 100644 --- a/src/gallium/drivers/svga/svga_resource_buffer_upload.c +++ b/src/gallium/drivers/svga/svga_resource_buffer_upload.c @@ -40,9 +40,6 @@ #include "svga_debug.h" -#define MAX_DMA_SIZE (4 * 1024 * 1024) - - /** * Allocate a winsys_buffer (ie. DMA, aka GMR memory). * @@ -60,18 +57,10 @@ svga_winsys_buffer_create( struct svga_context *svga, struct svga_winsys_screen *sws = svgascreen->sws; struct svga_winsys_buffer *buf; - /* XXX this shouldn't be a hard-coded number; it should be queried - * somehow. - */ - if (size > MAX_DMA_SIZE) { - return NULL; - } - /* Just try */ buf = sws->buffer_create(sws, alignment, usage, size); - if(!buf) { - - SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "flushing screen to find %d bytes GMR\n", + if (!buf) { + SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "flushing context to find %d bytes GMR\n", size); /* Try flushing all pending DMAs */ diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c index b61f85955a2..f9eb4949b2c 100644 --- a/src/gallium/drivers/svga/svga_resource_texture.c +++ b/src/gallium/drivers/svga/svga_resource_texture.c @@ -231,18 +231,19 @@ svga_transfer_dma(struct svga_context *svga, sw = (uint8_t *)st->swbuf + offset; - if(transfer == SVGA3D_WRITE_HOST_VRAM) { + if (transfer == SVGA3D_WRITE_HOST_VRAM) { + unsigned usage = PIPE_TRANSFER_WRITE; + /* Wait for the previous DMAs to complete */ /* TODO: keep one DMA (at half the size) in the background */ - if(y) { - svga_context_flush(svga, &fence); - sws->fence_finish(sws, fence, 0); - sws->fence_reference(sws, &fence, NULL); + if (y) { + svga_context_flush(svga, NULL); + usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE; } - hw = sws->buffer_map(sws, st->hwbuf, PIPE_TRANSFER_WRITE); + hw = sws->buffer_map(sws, st->hwbuf, usage); assert(hw); - if(hw) { + if (hw) { memcpy(hw, sw, length); sws->buffer_unmap(sws, st->hwbuf); } diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c index 6c987abe056..b847cf331b3 100644 --- a/src/gallium/drivers/svga/svga_screen.c +++ b/src/gallium/drivers/svga/svga_screen.c @@ -181,6 +181,8 @@ svga_get_paramf(struct pipe_screen *screen, enum pipe_cap param) case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE: return 1; + case PIPE_CAP_MIXED_COLORBUFFER_FORMATS: + return 0; default: return 0; diff --git a/src/gallium/drivers/svga/svga_state_framebuffer.c b/src/gallium/drivers/svga/svga_state_framebuffer.c index cdadb20c178..cc4819431ad 100644 --- a/src/gallium/drivers/svga/svga_state_framebuffer.c +++ b/src/gallium/drivers/svga/svga_state_framebuffer.c @@ -43,7 +43,7 @@ static int emit_framebuffer( struct svga_context *svga, { const struct pipe_framebuffer_state *curr = &svga->curr.framebuffer; struct pipe_framebuffer_state *hw = &svga->state.hw_clear.framebuffer; - boolean reemit = !!(dirty & SVGA_NEW_COMMAND_BUFFER); + boolean reemit = svga->rebind.rendertargets; unsigned i; enum pipe_error ret; @@ -88,6 +88,7 @@ static int emit_framebuffer( struct svga_context *svga, pipe_surface_reference(&hw->zsbuf, curr->zsbuf); } + svga->rebind.rendertargets = FALSE; return 0; } @@ -108,6 +109,8 @@ svga_reemit_framebuffer_bindings(struct svga_context *svga) unsigned i; enum pipe_error ret; + assert(svga->rebind.rendertargets); + for (i = 0; i < MIN2(PIPE_MAX_COLOR_BUFS, 8); ++i) { if (hw->cbufs[i]) { ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_COLOR0 + i, hw->cbufs[i]); @@ -138,6 +141,8 @@ svga_reemit_framebuffer_bindings(struct svga_context *svga) } } + svga->rebind.rendertargets = FALSE; + return PIPE_OK; } @@ -145,8 +150,7 @@ svga_reemit_framebuffer_bindings(struct svga_context *svga) struct svga_tracked_state svga_hw_framebuffer = { "hw framebuffer state", - SVGA_NEW_FRAME_BUFFER | - SVGA_NEW_COMMAND_BUFFER, + SVGA_NEW_FRAME_BUFFER, emit_framebuffer }; @@ -296,7 +300,7 @@ static int emit_viewport( struct svga_context *svga, break; case PIPE_PRIM_POINTS: case PIPE_PRIM_TRIANGLES: - adjust_x = -0.375; + adjust_x = -0.5; adjust_y = -0.5; break; } diff --git a/src/gallium/drivers/svga/svga_state_tss.c b/src/gallium/drivers/svga/svga_state_tss.c index c502506b93b..8b11a2a425e 100644 --- a/src/gallium/drivers/svga/svga_state_tss.c +++ b/src/gallium/drivers/svga/svga_state_tss.c @@ -66,7 +66,7 @@ static int update_tss_binding(struct svga_context *svga, unsigned dirty ) { - boolean reemit = !!(dirty & SVGA_NEW_COMMAND_BUFFER); + boolean reemit = svga->rebind.texture_samplers; unsigned i; unsigned count = MAX2( svga->curr.num_sampler_views, svga->state.hw_draw.num_views ); @@ -159,6 +159,8 @@ update_tss_binding(struct svga_context *svga, SVGA_FIFOCommitAll( svga->swc ); } + svga->rebind.texture_samplers = FALSE; + return 0; fail: @@ -181,6 +183,8 @@ svga_reemit_tss_bindings(struct svga_context *svga) enum pipe_error ret; struct bind_queue queue; + assert(svga->rebind.texture_samplers); + queue.bind_count = 0; for (i = 0; i < svga->state.hw_draw.num_views; i++) { @@ -220,6 +224,8 @@ svga_reemit_tss_bindings(struct svga_context *svga) SVGA_FIFOCommitAll(svga->swc); } + svga->rebind.texture_samplers = FALSE; + return PIPE_OK; } @@ -227,8 +233,7 @@ svga_reemit_tss_bindings(struct svga_context *svga) struct svga_tracked_state svga_hw_tss_binding = { "texture binding emit", SVGA_NEW_TEXTURE_BINDING | - SVGA_NEW_SAMPLER | - SVGA_NEW_COMMAND_BUFFER, + SVGA_NEW_SAMPLER, update_tss_binding }; diff --git a/src/gallium/drivers/trace/README b/src/gallium/drivers/trace/README index c210cba032a..cacd2e17498 100644 --- a/src/gallium/drivers/trace/README +++ b/src/gallium/drivers/trace/README @@ -13,12 +13,17 @@ It can traces all incoming calls. For tracing then do - GALLIUM_TRACE=tri.trace progs/trivial/tri + GALLIUM_TRACE=tri.trace trivial/tri which should create a tri.trace file, which is an XML file. You can view copying trace.xsl to the same directory, and opening with a XSLT capable browser such as Firefox or Internet Explorer. +For long traces you can use the + + src/gallium/tools/trace/dump.py tri.trace | less -R + + == Remote debugging == For remote debugging see: diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c index 4db7619c424..4f0d6c4b97a 100644 --- a/src/gallium/drivers/trace/tr_context.c +++ b/src/gallium/drivers/trace/tr_context.c @@ -47,15 +47,15 @@ static INLINE struct pipe_resource * trace_resource_unwrap(struct trace_context *tr_ctx, struct pipe_resource *resource) { - struct trace_resource *tr_tex; + struct trace_resource *tr_res; if(!resource) return NULL; - tr_tex = trace_resource(resource); + tr_res = trace_resource(resource); - assert(tr_tex->resource); - return tr_tex->resource; + assert(tr_res->resource); + return tr_res->resource; } @@ -832,19 +832,22 @@ trace_create_sampler_view(struct pipe_context *_pipe, const struct pipe_sampler_view *templ) { struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_resource *tr_tex = trace_resource(_resource); + struct trace_resource *tr_res = trace_resource(_resource); struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_resource *texture = tr_tex->resource; + struct pipe_resource *resource = tr_res->resource; struct pipe_sampler_view *result; struct trace_sampler_view *tr_view; trace_dump_call_begin("pipe_context", "create_sampler_view"); trace_dump_arg(ptr, pipe); - trace_dump_arg(ptr, texture); - trace_dump_arg(sampler_view_template, templ); + trace_dump_arg(ptr, resource); + + trace_dump_arg_begin("templ"); + trace_dump_sampler_view_template(templ, resource->target); + trace_dump_arg_end(); - result = pipe->create_sampler_view(pipe, texture, templ); + result = pipe->create_sampler_view(pipe, resource, templ); trace_dump_ret(ptr, result); @@ -895,29 +898,32 @@ trace_sampler_view_destroy(struct pipe_context *_pipe, static struct pipe_surface * trace_create_surface(struct pipe_context *_pipe, - struct pipe_resource *_texture, + struct pipe_resource *_resource, const struct pipe_surface *surf_tmpl) { struct trace_context *tr_ctx = trace_context(_pipe); - struct trace_resource *tr_tex = trace_resource(_texture); + struct trace_resource *tr_res = trace_resource(_resource); struct pipe_context *pipe = tr_ctx->pipe; - struct pipe_resource *texture = tr_tex->resource; + struct pipe_resource *resource = tr_res->resource; struct pipe_surface *result = NULL; trace_dump_call_begin("pipe_context", "create_surface"); trace_dump_arg(ptr, pipe); - trace_dump_arg(ptr, texture); - /* hmm some values unitialized there */ - trace_dump_arg(surface, surf_tmpl); + trace_dump_arg(ptr, resource); + + trace_dump_arg_begin("surf_tmpl"); + trace_dump_surface_template(surf_tmpl, resource->target); + trace_dump_arg_end(); + - result = pipe->create_surface(pipe, texture, surf_tmpl); + result = pipe->create_surface(pipe, resource, surf_tmpl); trace_dump_ret(ptr, result); trace_dump_call_end(); - result = trace_surf_create(tr_tex, result); + result = trace_surf_create(tr_res, result); return result; } @@ -1231,9 +1237,9 @@ trace_context_get_transfer(struct pipe_context *_context, const struct pipe_box *box) { struct trace_context *tr_context = trace_context(_context); - struct trace_resource *tr_tex = trace_resource(_resource); + struct trace_resource *tr_res = trace_resource(_resource); struct pipe_context *context = tr_context->pipe; - struct pipe_resource *texture = tr_tex->resource; + struct pipe_resource *texture = tr_res->resource; struct pipe_transfer *result = NULL; assert(texture->screen == context->screen); @@ -1246,7 +1252,7 @@ trace_context_get_transfer(struct pipe_context *_context, result = context->get_transfer(context, texture, level, usage, box); if (result) - result = trace_transfer_create(tr_context, tr_tex, result); + result = trace_transfer_create(tr_context, tr_res, result); return result; } @@ -1360,9 +1366,9 @@ trace_context_transfer_inline_write(struct pipe_context *_context, unsigned layer_stride) { struct trace_context *tr_context = trace_context(_context); - struct trace_resource *tr_tex = trace_resource(_resource); + struct trace_resource *tr_res = trace_resource(_resource); struct pipe_context *context = tr_context->pipe; - struct pipe_resource *resource = tr_tex->resource; + struct pipe_resource *resource = tr_res->resource; assert(resource->screen == context->screen); @@ -1397,9 +1403,9 @@ static void trace_redefine_user_buffer(struct pipe_context *_context, unsigned offset, unsigned size) { struct trace_context *tr_context = trace_context(_context); - struct trace_resource *tr_tex = trace_resource(_resource); + struct trace_resource *tr_res = trace_resource(_resource); struct pipe_context *context = tr_context->pipe; - struct pipe_resource *resource = tr_tex->resource; + struct pipe_resource *resource = tr_res->resource; assert(resource->screen == context->screen); diff --git a/src/gallium/drivers/trace/tr_dump_state.c b/src/gallium/drivers/trace/tr_dump_state.c index 18805655bd7..291a6a29ca5 100644 --- a/src/gallium/drivers/trace/tr_dump_state.c +++ b/src/gallium/drivers/trace/tr_dump_state.c @@ -321,8 +321,29 @@ void trace_dump_depth_stencil_alpha_state(const struct pipe_depth_stencil_alpha_ trace_dump_struct_end(); } +static void trace_dump_rt_blend_state(const struct pipe_rt_blend_state *state) +{ + trace_dump_struct_begin("pipe_rt_blend_state"); + + trace_dump_member(uint, state, blend_enable); + + trace_dump_member(uint, state, rgb_func); + trace_dump_member(uint, state, rgb_src_factor); + trace_dump_member(uint, state, rgb_dst_factor); + + trace_dump_member(uint, state, alpha_func); + trace_dump_member(uint, state, alpha_src_factor); + trace_dump_member(uint, state, alpha_dst_factor); + + trace_dump_member(uint, state, colormask); + + trace_dump_struct_end(); +} + void trace_dump_blend_state(const struct pipe_blend_state *state) { + unsigned valid_entries = 1; + if (!trace_dumping_enabled_locked()) return; @@ -331,7 +352,22 @@ void trace_dump_blend_state(const struct pipe_blend_state *state) return; } - trace_dump_bytes(state, sizeof *state); + trace_dump_struct_begin("pipe_blend_state"); + + trace_dump_member(bool, state, dither); + + trace_dump_member(bool, state, logicop_enable); + trace_dump_member(uint, state, logicop_func); + + trace_dump_member(bool, state, independent_blend_enable); + + trace_dump_member_begin("rt"); + if (state->independent_blend_enable) + valid_entries = PIPE_MAX_COLOR_BUFS; + trace_dump_struct_array(rt_blend_state, state->rt, valid_entries); + trace_dump_member_end(); + + trace_dump_struct_end(); } @@ -417,7 +453,8 @@ void trace_dump_sampler_state(const struct pipe_sampler_state *state) } -void trace_dump_sampler_view_template(const struct pipe_sampler_view *state) +void trace_dump_sampler_view_template(const struct pipe_sampler_view *state, + enum pipe_texture_target target) { if (!trace_dumping_enabled_locked()) return; @@ -430,13 +467,29 @@ void trace_dump_sampler_view_template(const struct pipe_sampler_view *state) trace_dump_struct_begin("pipe_sampler_view"); trace_dump_member(format, state, format); - /* XXX */ - trace_dump_member(uint, state, u.tex.first_level); - trace_dump_member(uint, state, u.tex.last_level); - trace_dump_member(uint, state, u.tex.first_layer); - trace_dump_member(uint, state, u.tex.last_layer); - trace_dump_member(uint, state, u.buf.first_element); - trace_dump_member(uint, state, u.buf.last_element); + + trace_dump_member_begin("u"); + trace_dump_struct_begin(""); /* anonymous */ + if (target == PIPE_BUFFER) { + trace_dump_member_begin("buf"); + trace_dump_struct_begin(""); /* anonymous */ + trace_dump_member(uint, &state->u.buf, first_element); + trace_dump_member(uint, &state->u.buf, last_element); + trace_dump_struct_end(); /* anonymous */ + trace_dump_member_end(); /* buf */ + } else { + trace_dump_member_begin("tex"); + trace_dump_struct_begin(""); /* anonymous */ + trace_dump_member(uint, &state->u.tex, first_layer); + trace_dump_member(uint, &state->u.tex, last_layer); + trace_dump_member(uint, &state->u.tex, first_level); + trace_dump_member(uint, &state->u.tex, last_level); + trace_dump_struct_end(); /* anonymous */ + trace_dump_member_end(); /* tex */ + } + trace_dump_struct_end(); /* anonymous */ + trace_dump_member_end(); /* u */ + trace_dump_member(uint, state, swizzle_r); trace_dump_member(uint, state, swizzle_g); trace_dump_member(uint, state, swizzle_b); @@ -446,7 +499,8 @@ void trace_dump_sampler_view_template(const struct pipe_sampler_view *state) } -void trace_dump_surface(const struct pipe_surface *state) +void trace_dump_surface_template(const struct pipe_surface *state, + enum pipe_texture_target target) { if (!trace_dumping_enabled_locked()) return; @@ -464,12 +518,26 @@ void trace_dump_surface(const struct pipe_surface *state) trace_dump_member(uint, state, usage); - trace_dump_member(ptr, state, texture); - trace_dump_member(uint, state, u.tex.level); - trace_dump_member(uint, state, u.tex.first_layer); - trace_dump_member(uint, state, u.tex.last_layer); - trace_dump_member(uint, state, u.buf.first_element); - trace_dump_member(uint, state, u.buf.last_element); + trace_dump_member_begin("u"); + trace_dump_struct_begin(""); /* anonymous */ + if (target == PIPE_BUFFER) { + trace_dump_member_begin("buf"); + trace_dump_struct_begin(""); /* anonymous */ + trace_dump_member(uint, &state->u.buf, first_element); + trace_dump_member(uint, &state->u.buf, last_element); + trace_dump_struct_end(); /* anonymous */ + trace_dump_member_end(); /* buf */ + } else { + trace_dump_member_begin("tex"); + trace_dump_struct_begin(""); /* anonymous */ + trace_dump_member(uint, &state->u.tex, level); + trace_dump_member(uint, &state->u.tex, first_layer); + trace_dump_member(uint, &state->u.tex, last_layer); + trace_dump_struct_end(); /* anonymous */ + trace_dump_member_end(); /* tex */ + } + trace_dump_struct_end(); /* anonymous */ + trace_dump_member_end(); /* u */ trace_dump_struct_end(); } diff --git a/src/gallium/drivers/trace/tr_dump_state.h b/src/gallium/drivers/trace/tr_dump_state.h index fe8ece78d43..a6e7ccdb864 100644 --- a/src/gallium/drivers/trace/tr_dump_state.h +++ b/src/gallium/drivers/trace/tr_dump_state.h @@ -65,9 +65,11 @@ void trace_dump_framebuffer_state(const struct pipe_framebuffer_state *state); void trace_dump_sampler_state(const struct pipe_sampler_state *state); -void trace_dump_sampler_view_template(const struct pipe_sampler_view *view); +void trace_dump_sampler_view_template(const struct pipe_sampler_view *view, + enum pipe_texture_target target); -void trace_dump_surface(const struct pipe_surface *state); +void trace_dump_surface_template(const struct pipe_surface *state, + enum pipe_texture_target target); void trace_dump_transfer(const struct pipe_transfer *state); diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c index 42180c4f19e..a7d33661838 100644 --- a/src/gallium/drivers/trace/tr_screen.c +++ b/src/gallium/drivers/trace/tr_screen.c @@ -117,7 +117,7 @@ trace_screen_get_shader_param(struct pipe_screen *_screen, unsigned shader, trace_dump_call_begin("pipe_screen", "get_shader_param"); trace_dump_arg(ptr, screen); - trace_dump_arg(int, shader); + trace_dump_arg(uint, shader); trace_dump_arg(int, param); result = screen->get_shader_param(screen, shader, param); @@ -282,40 +282,40 @@ trace_screen_resource_from_handle(struct pipe_screen *_screen, static boolean trace_screen_resource_get_handle(struct pipe_screen *_screen, - struct pipe_resource *_texture, + struct pipe_resource *_resource, struct winsys_handle *handle) { struct trace_screen *tr_screen = trace_screen(_screen); - struct trace_resource *tr_texture = trace_resource(_texture); + struct trace_resource *tr_resource = trace_resource(_resource); struct pipe_screen *screen = tr_screen->screen; - struct pipe_resource *texture = tr_texture->resource; + struct pipe_resource *resource = tr_resource->resource; /* TODO trace call */ - return screen->resource_get_handle(screen, texture, handle); + return screen->resource_get_handle(screen, resource, handle); } static void trace_screen_resource_destroy(struct pipe_screen *_screen, - struct pipe_resource *_texture) + struct pipe_resource *_resource) { struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_resource *tr_tex = trace_resource(_texture); + struct trace_resource *tr_res = trace_resource(_resource); struct pipe_screen *screen = tr_scr->screen; - struct pipe_resource *texture = tr_tex->resource; + struct pipe_resource *resource = tr_res->resource; - assert(texture->screen == screen); + assert(resource->screen == screen); - trace_dump_call_begin("pipe_screen", "texture_destroy"); + trace_dump_call_begin("pipe_screen", "resource_destroy"); trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, texture); + trace_dump_arg(ptr, resource); trace_dump_call_end(); - trace_resource_destroy(tr_scr, tr_tex); + trace_resource_destroy(tr_scr, tr_res); } diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c index 27997346471..648b7a4f1cc 100644 --- a/src/gallium/drivers/trace/tr_texture.c +++ b/src/gallium/drivers/trace/tr_texture.c @@ -39,24 +39,24 @@ struct pipe_resource * trace_resource_create(struct trace_screen *tr_scr, struct pipe_resource *texture) { - struct trace_resource *tr_tex; + struct trace_resource *tr_res; if(!texture) goto error; assert(texture->screen == tr_scr->screen); - tr_tex = CALLOC_STRUCT(trace_resource); - if(!tr_tex) + tr_res = CALLOC_STRUCT(trace_resource); + if(!tr_res) goto error; - memcpy(&tr_tex->base, texture, sizeof(struct pipe_resource)); + memcpy(&tr_res->base, texture, sizeof(struct pipe_resource)); - pipe_reference_init(&tr_tex->base.reference, 1); - tr_tex->base.screen = &tr_scr->base; - tr_tex->resource = texture; + pipe_reference_init(&tr_res->base.reference, 1); + tr_res->base.screen = &tr_scr->base; + tr_res->resource = texture; - return &tr_tex->base; + return &tr_res->base; error: pipe_resource_reference(&texture, NULL); @@ -66,15 +66,15 @@ error: void trace_resource_destroy(struct trace_screen *tr_scr, - struct trace_resource *tr_tex) + struct trace_resource *tr_res) { - pipe_resource_reference(&tr_tex->resource, NULL); - FREE(tr_tex); + pipe_resource_reference(&tr_res->resource, NULL); + FREE(tr_res); } struct pipe_surface * -trace_surf_create(struct trace_resource *tr_tex, +trace_surf_create(struct trace_resource *tr_res, struct pipe_surface *surface) { struct trace_surface *tr_surf; @@ -82,7 +82,7 @@ trace_surf_create(struct trace_resource *tr_tex, if(!surface) goto error; - assert(surface->texture == tr_tex->resource); + assert(surface->texture == tr_res->resource); tr_surf = CALLOC_STRUCT(trace_surface); if(!tr_surf) @@ -92,7 +92,7 @@ trace_surf_create(struct trace_resource *tr_tex, pipe_reference_init(&tr_surf->base.reference, 1); tr_surf->base.texture = NULL; - pipe_resource_reference(&tr_surf->base.texture, &tr_tex->base); + pipe_resource_reference(&tr_surf->base.texture, &tr_res->base); tr_surf->surface = surface; return &tr_surf->base; @@ -114,7 +114,7 @@ trace_surf_destroy(struct trace_surface *tr_surf) struct pipe_transfer * trace_transfer_create(struct trace_context *tr_ctx, - struct trace_resource *tr_tex, + struct trace_resource *tr_res, struct pipe_transfer *transfer) { struct trace_transfer *tr_trans; @@ -122,7 +122,7 @@ trace_transfer_create(struct trace_context *tr_ctx, if(!transfer) goto error; - assert(transfer->resource == tr_tex->resource); + assert(transfer->resource == tr_res->resource); tr_trans = CALLOC_STRUCT(trace_transfer); if(!tr_trans) @@ -133,8 +133,8 @@ trace_transfer_create(struct trace_context *tr_ctx, tr_trans->base.resource = NULL; tr_trans->transfer = transfer; - pipe_resource_reference(&tr_trans->base.resource, &tr_tex->base); - assert(tr_trans->base.resource == &tr_tex->base); + pipe_resource_reference(&tr_trans->base.resource, &tr_res->base); + assert(tr_trans->base.resource == &tr_res->base); return &tr_trans->base; diff --git a/src/gallium/drivers/trace/tr_texture.h b/src/gallium/drivers/trace/tr_texture.h index 3352c96e59a..bf3c16e8cd2 100644 --- a/src/gallium/drivers/trace/tr_texture.h +++ b/src/gallium/drivers/trace/tr_texture.h @@ -122,10 +122,10 @@ trace_resource_create(struct trace_screen *tr_scr, void trace_resource_destroy(struct trace_screen *tr_scr, - struct trace_resource *tr_tex); + struct trace_resource *tr_res); struct pipe_surface * -trace_surf_create(struct trace_resource *tr_tex, +trace_surf_create(struct trace_resource *tr_res, struct pipe_surface *surface); void @@ -133,7 +133,7 @@ trace_surf_destroy(struct trace_surface *tr_surf); struct pipe_transfer * trace_transfer_create(struct trace_context *tr_ctx, - struct trace_resource *tr_tex, + struct trace_resource *tr_res, struct pipe_transfer *transfer); void diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h index 3441db685ce..8c788f4bb0e 100644 --- a/src/gallium/include/pipe/p_compiler.h +++ b/src/gallium/include/pipe/p_compiler.h @@ -292,12 +292,14 @@ void _ReadWriteBarrier(void); * Note that profile guided optimization can offer better results, but * needs an appropriate coverage suite and does not inform human readers. */ -#ifdef __GNUC__ -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) -#else -#define likely(x) !!(x) -#define unlikely(x) !!(x) +#ifndef likely +# if defined(__GNUC__) +# define likely(x) __builtin_expect(!!(x), 1) +# define unlikely(x) __builtin_expect(!!(x), 0) +# else +# define likely(x) (x) +# define unlikely(x) (x) +# endif #endif diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index e3cc28ba476..75df89f2acb 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -414,78 +414,80 @@ enum pipe_transfer_usage { * pipe_screen::get_param() and pipe_screen::get_paramf(). */ enum pipe_cap { - PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS, - PIPE_CAP_NPOT_TEXTURES, - PIPE_CAP_TWO_SIDED_STENCIL, - PIPE_CAP_GLSL, /* XXX need something better */ - PIPE_CAP_DUAL_SOURCE_BLEND, - PIPE_CAP_ANISOTROPIC_FILTER, - PIPE_CAP_POINT_SPRITE, - PIPE_CAP_MAX_RENDER_TARGETS, - PIPE_CAP_OCCLUSION_QUERY, - PIPE_CAP_TIMER_QUERY, - PIPE_CAP_TEXTURE_SHADOW_MAP, - PIPE_CAP_TEXTURE_SWIZZLE, - PIPE_CAP_MAX_TEXTURE_2D_LEVELS, - PIPE_CAP_MAX_TEXTURE_3D_LEVELS, - PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS, - PIPE_CAP_MAX_LINE_WIDTH, - PIPE_CAP_MAX_LINE_WIDTH_AA, - PIPE_CAP_MAX_POINT_WIDTH, - PIPE_CAP_MAX_POINT_WIDTH_AA, - PIPE_CAP_MAX_TEXTURE_ANISOTROPY, - PIPE_CAP_MAX_TEXTURE_LOD_BIAS, - PIPE_CAP_GUARD_BAND_LEFT, /*< float */ - PIPE_CAP_GUARD_BAND_TOP, /*< float */ - PIPE_CAP_GUARD_BAND_RIGHT, /*< float */ - PIPE_CAP_GUARD_BAND_BOTTOM, /*< float */ - PIPE_CAP_TEXTURE_MIRROR_CLAMP, - PIPE_CAP_TEXTURE_MIRROR_REPEAT, - PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS, - PIPE_CAP_BLEND_EQUATION_SEPARATE, - PIPE_CAP_SM3, /*< Shader Model, supported */ - PIPE_CAP_STREAM_OUTPUT, - PIPE_CAP_PRIMITIVE_RESTART, + PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS = 0, + PIPE_CAP_NPOT_TEXTURES = 1, + PIPE_CAP_TWO_SIDED_STENCIL = 2, + PIPE_CAP_GLSL = 3, /* XXX need something better */ + PIPE_CAP_DUAL_SOURCE_BLEND = 4, + PIPE_CAP_ANISOTROPIC_FILTER = 5, + PIPE_CAP_POINT_SPRITE = 6, + PIPE_CAP_MAX_RENDER_TARGETS = 7, + PIPE_CAP_OCCLUSION_QUERY = 8, + PIPE_CAP_TIMER_QUERY = 9, + PIPE_CAP_TEXTURE_SHADOW_MAP = 10, + PIPE_CAP_TEXTURE_SWIZZLE = 11, + PIPE_CAP_MAX_TEXTURE_2D_LEVELS = 12, + PIPE_CAP_MAX_TEXTURE_3D_LEVELS = 13, + PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS = 14, + PIPE_CAP_MAX_LINE_WIDTH = 15, + PIPE_CAP_MAX_LINE_WIDTH_AA = 16, + PIPE_CAP_MAX_POINT_WIDTH = 17, + PIPE_CAP_MAX_POINT_WIDTH_AA = 18, + PIPE_CAP_MAX_TEXTURE_ANISOTROPY = 19, + PIPE_CAP_MAX_TEXTURE_LOD_BIAS = 20, + PIPE_CAP_GUARD_BAND_LEFT = 21, /*< float */ + PIPE_CAP_GUARD_BAND_TOP = 22, /*< float */ + PIPE_CAP_GUARD_BAND_RIGHT = 23, /*< float */ + PIPE_CAP_GUARD_BAND_BOTTOM = 24, /*< float */ + PIPE_CAP_TEXTURE_MIRROR_CLAMP = 25, + PIPE_CAP_TEXTURE_MIRROR_REPEAT = 26, + PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS = 27, + PIPE_CAP_BLEND_EQUATION_SEPARATE = 28, + PIPE_CAP_SM3 = 29, /*< Shader Model, supported */ + PIPE_CAP_STREAM_OUTPUT = 30, + PIPE_CAP_PRIMITIVE_RESTART = 31, /** Maximum texture image units accessible from vertex and fragment shaders * combined */ - PIPE_CAP_MAX_COMBINED_SAMPLERS, + PIPE_CAP_MAX_COMBINED_SAMPLERS = 32, /** blend enables and write masks per rendertarget */ - PIPE_CAP_INDEP_BLEND_ENABLE, + PIPE_CAP_INDEP_BLEND_ENABLE = 33, /** different blend funcs per rendertarget */ - PIPE_CAP_INDEP_BLEND_FUNC, - PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE, - PIPE_CAP_ARRAY_TEXTURES, - PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT, - PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT, - PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER, - PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER, - PIPE_CAP_DEPTH_CLAMP, - PIPE_CAP_SHADER_STENCIL_EXPORT, - PIPE_CAP_TGSI_INSTANCEID, - PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR, + PIPE_CAP_INDEP_BLEND_FUNC = 34, + PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE = 35, + PIPE_CAP_ARRAY_TEXTURES = 36, + PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT = 37, + PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT = 38, + PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER = 39, + PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER = 40, + PIPE_CAP_DEPTH_CLAMP = 41, + PIPE_CAP_SHADER_STENCIL_EXPORT = 42, + PIPE_CAP_TGSI_INSTANCEID = 43, + PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR = 44, + PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL = 45, + PIPE_CAP_MIXED_COLORBUFFER_FORMATS = 46, }; /* Shader caps not specific to any single stage */ enum pipe_shader_cap { - PIPE_SHADER_CAP_MAX_INSTRUCTIONS, /* if 0, it means the stage is unsupported */ - PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS, - PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS, - PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS, - PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH, - PIPE_SHADER_CAP_MAX_INPUTS, - PIPE_SHADER_CAP_MAX_CONSTS, - PIPE_SHADER_CAP_MAX_CONST_BUFFERS, - PIPE_SHADER_CAP_MAX_TEMPS, - PIPE_SHADER_CAP_MAX_ADDRS, - PIPE_SHADER_CAP_MAX_PREDS, + PIPE_SHADER_CAP_MAX_INSTRUCTIONS = 0, /* if 0, it means the stage is unsupported */ + PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS = 1, + PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS = 2, + PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS = 3, + PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH = 4, + PIPE_SHADER_CAP_MAX_INPUTS = 5, + PIPE_SHADER_CAP_MAX_CONSTS = 6, + PIPE_SHADER_CAP_MAX_CONST_BUFFERS = 7, + PIPE_SHADER_CAP_MAX_TEMPS = 8, + PIPE_SHADER_CAP_MAX_ADDRS = 9, + PIPE_SHADER_CAP_MAX_PREDS = 10, /* boolean caps */ - PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED, - PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR, - PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR, - PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR, - PIPE_SHADER_CAP_INDIRECT_CONST_ADDR, - PIPE_SHADER_CAP_SUBROUTINES, /* BGNSUB, ENDSUB, CAL, RET */ + PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED = 11, + PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR = 12, + PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR = 13, + PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR = 14, + PIPE_SHADER_CAP_INDIRECT_CONST_ADDR = 15, + PIPE_SHADER_CAP_SUBROUTINES = 16, /* BGNSUB, ENDSUB, CAL, RET */ }; diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h index 542931ec1d8..c9f75c019ef 100644 --- a/src/gallium/include/pipe/p_format.h +++ b/src/gallium/include/pipe/p_format.h @@ -211,17 +211,35 @@ enum pipe_format { PIPE_FORMAT_LATC2_UNORM = 145, PIPE_FORMAT_LATC2_SNORM = 146, - PIPE_FORMAT_YV12 = 147, - PIPE_FORMAT_YV16 = 148, - PIPE_FORMAT_IYUV = 149, /**< aka I420 */ - PIPE_FORMAT_NV12 = 150, - PIPE_FORMAT_NV21 = 151, + PIPE_FORMAT_A8_SNORM = 147, + PIPE_FORMAT_L8_SNORM = 148, + PIPE_FORMAT_L8A8_SNORM = 149, + PIPE_FORMAT_I8_SNORM = 150, + PIPE_FORMAT_A16_SNORM = 151, + PIPE_FORMAT_L16_SNORM = 152, + PIPE_FORMAT_L16A16_SNORM = 153, + PIPE_FORMAT_I16_SNORM = 154, + + PIPE_FORMAT_A16_FLOAT = 155, + PIPE_FORMAT_L16_FLOAT = 156, + PIPE_FORMAT_L16A16_FLOAT = 157, + PIPE_FORMAT_I16_FLOAT = 158, + PIPE_FORMAT_A32_FLOAT = 159, + PIPE_FORMAT_L32_FLOAT = 160, + PIPE_FORMAT_L32A32_FLOAT = 161, + PIPE_FORMAT_I32_FLOAT = 162, + + PIPE_FORMAT_YV12 = 163, + PIPE_FORMAT_YV16 = 164, + PIPE_FORMAT_IYUV = 165, /**< aka I420 */ + PIPE_FORMAT_NV12 = 166, + PIPE_FORMAT_NV21 = 167, PIPE_FORMAT_AYUV = PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_VUYA = PIPE_FORMAT_B8G8R8A8_UNORM, PIPE_FORMAT_XYUV = PIPE_FORMAT_X8R8G8B8_UNORM, PIPE_FORMAT_VUYX = PIPE_FORMAT_B8G8R8X8_UNORM, - PIPE_FORMAT_IA44 = 152, - PIPE_FORMAT_AI44 = 153, + PIPE_FORMAT_IA44 = 168, + PIPE_FORMAT_AI44 = 169, PIPE_FORMAT_COUNT }; diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index cf6c5b50268..f6ad4560f16 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -81,6 +81,8 @@ struct pipe_rasterizer_state { unsigned flatshade:1; unsigned light_twoside:1; + unsigned clamp_vertex_color:1; + unsigned clamp_fragment_color:1; unsigned front_ccw:1; unsigned cull_face:2; /**< PIPE_FACE_x */ unsigned fill_front:2; /**< PIPE_POLYGON_MODE_x */ diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.c b/src/gallium/state_trackers/egl/wayland/native_wayland.c index 068c3cd7c8e..b9cf8c48f1e 100644 --- a/src/gallium/state_trackers/egl/wayland/native_wayland.c +++ b/src/gallium/state_trackers/egl/wayland/native_wayland.c @@ -33,6 +33,7 @@ #include "state_tracker/drm_driver.h" #include "egllog.h" +#include <errno.h> #include "native_wayland.h" @@ -45,6 +46,9 @@ #include "wayland-egl-priv.h" #include <xf86drm.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> static struct native_event_handler *wayland_event_handler; @@ -135,6 +139,12 @@ wayland_display_destroy(struct native_display *ndpy) { struct wayland_display *display = wayland_display(ndpy); + if (display->fd) + close(display->fd); + if (display->wl_drm) + wl_drm_destroy(display->wl_drm); + if (display->device_name) + FREE(display->device_name); if (display->config) FREE(display->config); @@ -161,7 +171,7 @@ wayland_create_buffer(struct wayland_surface *surface, pipe_resource_reference(&resource, NULL); - return wl_drm_create_buffer(display->dpy->drm, wsh.handle, + return wl_drm_create_buffer(display->wl_drm, wsh.handle, width, height, wsh.stride, surface->win->visual); } @@ -174,21 +184,24 @@ wayland_pixmap_destroy(struct wl_egl_pixmap *egl_pixmap) assert(resource); pipe_resource_reference(&resource, NULL); + if (egl_pixmap->buffer) { + wl_buffer_destroy(egl_pixmap->buffer); + egl_pixmap->buffer = NULL; + } egl_pixmap->driver_private = NULL; egl_pixmap->destroy = NULL; - egl_pixmap->name = 0; } static void -wayland_pixmap_surface_intialize(struct wayland_surface *surface) +wayland_pixmap_surface_initialize(struct wayland_surface *surface) { struct native_display *ndpy = &surface->display->base; struct pipe_resource *resource; struct winsys_handle wsh; const enum native_attachment front_natt = NATIVE_ATTACHMENT_FRONT_LEFT; - if (surface->pix->name > 0) + if (surface->pix->buffer != NULL) return; resource = resource_surface_get_single_resource(surface->rsurf, front_natt); @@ -196,8 +209,11 @@ wayland_pixmap_surface_intialize(struct wayland_surface *surface) wsh.type = DRM_API_HANDLE_TYPE_SHARED; ndpy->screen->resource_get_handle(ndpy->screen, resource, &wsh); - surface->pix->name = wsh.handle; - surface->pix->stride = wsh.stride; + surface->pix->buffer = + wl_drm_create_buffer(surface->display->wl_drm, wsh.handle, + surface->pix->width, surface->pix->height, + wsh.stride, surface->pix->visual); + surface->pix->destroy = wayland_pixmap_destroy; surface->pix->driver_private = resource; } @@ -228,12 +244,12 @@ wayland_window_surface_handle_resize(struct wayland_surface *surface) surface->win->width, surface->win->height)) { if (surface->pending_resource) - force_roundtrip(display->dpy->display); + force_roundtrip(display->dpy); if (front_resource) { surface->pending_resource = front_resource; front_resource = NULL; - wl_display_sync_callback(display->dpy->display, + wl_display_sync_callback(display->dpy, wayland_release_pending_resource, surface); } @@ -274,13 +290,13 @@ wayland_surface_validate(struct native_surface *nsurf, uint attachment_mask, resource_surface_get_size(surface->rsurf, (uint *) width, (uint *) height); if (surface->type == WL_PIXMAP_SURFACE) - wayland_pixmap_surface_intialize(surface); + wayland_pixmap_surface_initialize(surface); return TRUE; } static void -wayland_frame_callback(void *data, uint32_t time) +wayland_frame_callback(struct wl_surface *surf, void *data, uint32_t time) { struct wayland_surface *surface = data; @@ -304,11 +320,11 @@ wayland_surface_swap_buffers(struct native_surface *nsurf) struct wayland_display *display = surface->display; while (surface->block_swap_buffers) - wl_display_iterate(display->dpy->display, WL_DISPLAY_READABLE); + wl_display_iterate(display->dpy, WL_DISPLAY_READABLE); surface->block_swap_buffers = TRUE; - wl_display_frame_callback(display->dpy->display, wayland_frame_callback, - surface); + wl_display_frame_callback(display->dpy, surface->win->surface, + wayland_frame_callback, surface); if (surface->type == WL_WINDOW_SURFACE) { resource_surface_swap_buffers(surface->rsurf, @@ -364,6 +380,7 @@ wayland_surface_present(struct native_surface *nsurf, if (surface->type == WL_WINDOW_SURFACE) { resource_surface_get_size(surface->rsurf, &width, &height); + wl_buffer_damage(surface->buffer[WL_BUFFER_FRONT], 0, 0, width, height); wl_surface_damage(surface->win->surface, 0, 0, width, height); } @@ -397,7 +414,6 @@ wayland_create_pixmap_surface(struct native_display *ndpy, const struct native_config *nconf) { struct wayland_display *display = wayland_display(ndpy); - struct wayland_config *config = wayland_config(nconf); struct wayland_surface *surface; struct wl_egl_pixmap *egl_pixmap = (struct wl_egl_pixmap *) pix; enum native_attachment natt = NATIVE_ATTACHMENT_FRONT_LEFT; @@ -412,7 +428,7 @@ wayland_create_pixmap_surface(struct native_display *ndpy, surface->type = WL_PIXMAP_SURFACE; surface->pix = egl_pixmap; - if (surface->pix->visual == wl_display_get_rgb_visual(display->dpy->display)) + if (surface->pix->visual == wl_display_get_rgb_visual(display->dpy)) surface->color_format = PIPE_FORMAT_B8G8R8X8_UNORM; else surface->color_format = PIPE_FORMAT_B8G8R8A8_UNORM; @@ -433,7 +449,7 @@ wayland_create_pixmap_surface(struct native_display *ndpy, egl_pixmap->width, egl_pixmap->height); /* the pixmap is already allocated, so import it */ - if (surface->pix->name > 0) + if (surface->pix->buffer != NULL) resource_surface_import_resource(surface->rsurf, natt, surface->pix->driver_private); @@ -511,35 +527,80 @@ get_drm_screen_name(int fd, drmVersionPtr version) return name; } +static void +drm_handle_device(void *data, struct wl_drm *drm, const char *device) +{ + struct wayland_display *display = data; + drm_magic_t magic; + + display->device_name = strdup(device); + if (!display->device_name) + return; + + display->fd = open(display->device_name, O_RDWR); + if (display->fd == -1) { + _eglLog(_EGL_WARNING, "wayland-egl: could not open %s (%s)", + display->device_name, strerror(errno)); + return; + } + + drmGetMagic(display->fd, &magic); + wl_drm_authenticate(display->wl_drm, magic); +} + +static void +drm_handle_authenticated(void *data, struct wl_drm *drm) +{ + struct wayland_display *display = data; + + display->authenticated = true; +} + +static const struct wl_drm_listener drm_listener = { + drm_handle_device, + drm_handle_authenticated +}; + static boolean wayland_display_init_screen(struct native_display *ndpy) { struct wayland_display *display = wayland_display(ndpy); drmVersionPtr version; const char *driver_name; + uint32_t id; - if (display->dpy->fd == -1) - force_roundtrip(display->dpy->display); - if (display->dpy->fd == -1) - return FALSE; + id = wl_display_get_global(display->dpy, "wl_drm", 1); + if (id == 0) + wl_display_iterate(display->dpy, WL_DISPLAY_READABLE); + id = wl_display_get_global(display->dpy, "wl_drm", 1); + if (id == 0) + return FALSE; - if (!display->dpy->authenticated) - force_roundtrip(display->dpy->display); - if (!display->dpy->authenticated) + display->wl_drm = wl_drm_create(display->dpy, id, 1); + if (!display->wl_drm) return FALSE; - version = drmGetVersion(display->dpy->fd); + wl_drm_add_listener(display->wl_drm, &drm_listener, display); + force_roundtrip(display->dpy); + if (display->fd == -1) + return FALSE; + + force_roundtrip(display->dpy); + if (!display->authenticated) + return FALSE; + + version = drmGetVersion(display->fd); if (!version) { - _eglLog(_EGL_WARNING, "invalid fd %d", display->dpy->fd); + _eglLog(_EGL_WARNING, "invalid fd %d", display->fd); return FALSE; } /* FIXME: share this with native_drm or egl_dri2 */ - driver_name = get_drm_screen_name(display->dpy->fd, version); + driver_name = get_drm_screen_name(display->fd, version); display->base.screen = wayland_event_handler->new_drm_screen(&display->base, - driver_name, display->dpy->fd); + driver_name, display->fd); drmFreeVersion(version); if (!display->base.screen) { @@ -592,7 +653,7 @@ wayland_display_create(void *dpy, boolean use_sw, void *user_data) display->base.user_data = user_data; display->dpy = dpy; - if (!display->dpy->display) { + if (!display->dpy) { wayland_display_destroy(&display->base); return NULL; } diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.h b/src/gallium/state_trackers/egl/wayland/native_wayland.h index 271c10dc113..14fc9b0fbb2 100644 --- a/src/gallium/state_trackers/egl/wayland/native_wayland.h +++ b/src/gallium/state_trackers/egl/wayland/native_wayland.h @@ -33,12 +33,17 @@ #include "common/native_helper.h" #include "wayland-egl-priv.h" +#include "wayland-drm-client-protocol.h" struct wayland_display { struct native_display base; struct wayland_config *config; - struct wl_egl_display *dpy; + struct wl_display *dpy; + struct wl_drm *wl_drm; + int fd; + char *device_name; + boolean authenticated; }; enum wayland_buffer_type { diff --git a/src/gallium/state_trackers/python/README b/src/gallium/state_trackers/python/README deleted file mode 100644 index e24a262aba9..00000000000 --- a/src/gallium/state_trackers/python/README +++ /dev/null @@ -1,43 +0,0 @@ -This directory contains Python bindings to Gallium3D. It looks like a state -tracker from the pipe driver perspective, and it looks like a pipe driver from -the python script perspective. - - -To build you'll need: -* Python (with development packages) -* SCons -* SWIG, http://www.swig.org/download.html -* Python Imaging Library with TK support, http://www.pythonware.com/products/pil/, - for the samples - -On a debian-based distro you can simply do: - - aptitude install python-dev scons swig python-imaging python-imaging-tk - -On a Windows machine ensure the swig command is in your PATH. - -Invoke scons on the top dir as - - scons debug=yes statetrackers=python drivers=softpipe winsys=none - -To use it set PYTHONPATH appropriately, e.g, in Linux do: - - export PYTHONPATH=$PWD/build/linux-x86-debug/gallium/state_trackers/python - -or (in Windows) - - set PYTHONPATH=%CD%\build\windows-x86-debug\gallium\state_trackers\python - -and then try running - - python progs/gallium/python/samples/tri.py - -which should show a triangle. - - -This is still work in progress: -- errors are not handled properly and almost always result in crash -- state atoms with array members are awkward to set - --- -Jose Fonseca <[email protected]> diff --git a/src/gallium/state_trackers/python/SConscript b/src/gallium/state_trackers/python/SConscript deleted file mode 100644 index b8371865a61..00000000000 --- a/src/gallium/state_trackers/python/SConscript +++ /dev/null @@ -1,66 +0,0 @@ -import sys -import os.path - -Import('*') - -if env['toolchain'] == 'crossmingw': - # Cross-compilation not supported - Return() - -if not env.Detect(['swig']): - Return() - -env = env.Clone() - -env.Tool('python') - -env.Tool('swig') -env.Append(SWIGPATH = ['#src/gallium/include', '#src/gallium/include/pipe']) -env.Append(SWIGFLAGS = ['-python', '-keyword']) - -env.Append(CPPPATH = '.') - -if env['platform'] == 'windows': - env.Append(LIBS = [ - 'opengl32', - 'gdi32', - 'user32', - 'kernel32', - 'ws2_32', - ]) -else: - env.Append(CPPDEFINES = ['GCC_HASCLASSVISIBILITY']) - env.Append(LIBS = [ - 'GL', - 'X11', - ]) - -sources = [ - 'gallium.i', - 'st_device.c', - 'st_sample.c', - 'st_hardpipe_winsys.c', - 'st_softpipe_winsys.c', -] - -env.Prepend(LIBS = [ - ws_null, - trace, - gallium, -]) - -if env['llvm']: - env.Append(CPPDEFINES = ['HAVE_LLVMPIPE']) - env.Prepend(LIBS = [llvmpipe]) -if True: - env.Append(CPPDEFINES = ['HAVE_SOFTPIPE']) - env.Prepend(LIBS = [softpipe]) - -env['no_import_lib'] = 1 - -pyst = env.SharedLibrary( - target = '_gallium', - source = sources, -) - -env.Alias('python', pyst) diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i deleted file mode 100644 index c6084f78aee..00000000000 --- a/src/gallium/state_trackers/python/gallium.i +++ /dev/null @@ -1,105 +0,0 @@ - /************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/** - * @file - * SWIG interface definion for Gallium types. - * - * @author Jose Fonseca <[email protected]> - */ - -%module gallium; - -%{ - -#include <stdio.h> - -#include "pipe/p_screen.h" -#include "pipe/p_context.h" -#include "pipe/p_shader_tokens.h" -#include "os/os_stream.h" -#include "util/u_inlines.h" -#include "util/u_draw_quad.h" -#include "util/u_tile.h" -#include "util/u_math.h" -#include "util/u_format.h" -#include "util/u_dump.h" -#include "util/u_memory.h" -#include "util/u_sampler.h" -#include "cso_cache/cso_context.h" -#include "tgsi/tgsi_text.h" -#include "tgsi/tgsi_dump.h" - -#include "st_device.h" -#include "st_sample.h" - -%} - -%include "typemaps.i" -%include "exception.i" -%include "cstring.i" - -%include "carrays.i" -%array_class(unsigned char, ByteArray); -%array_class(int, IntArray); -%array_class(unsigned, UnsignedArray); -%array_class(float, FloatArray); - - -%rename(Device) st_device; -%rename(Context) st_context; -%rename(Resource) pipe_resource; -%rename(Surface) st_surface; - -%rename(BlendColor) pipe_blend_color; -%rename(Blend) pipe_blend_state; -%rename(Clip) pipe_clip_state; -%rename(Depth) pipe_depth_state; -%rename(Stencil) pipe_stencil_state; -%rename(Alpha) pipe_alpha_state; -%rename(DepthStencilAlpha) pipe_depth_stencil_alpha_state; -%rename(Framebuffer) pipe_framebuffer_state; -%rename(PolyStipple) pipe_poly_stipple; -%rename(Rasterizer) pipe_rasterizer_state; -%rename(Sampler) pipe_sampler_state; -%rename(Scissor) pipe_scissor_state; -%rename(Shader) pipe_shader_state; -%rename(VertexBuffer) pipe_vertex_buffer; -%rename(VertexElement) pipe_vertex_element; -%rename(Viewport) pipe_viewport_state; - - -%include "p_compiler.i" -%include "p_defines.h" -%include "p_format.h" - -%include "p_device.i" -%include "p_context.i" -%include "p_texture.i" -%include "p_state.i" - -%include "u_format.i" diff --git a/src/gallium/state_trackers/python/p_compiler.i b/src/gallium/state_trackers/python/p_compiler.i deleted file mode 100644 index 15f6ba5b9db..00000000000 --- a/src/gallium/state_trackers/python/p_compiler.i +++ /dev/null @@ -1,29 +0,0 @@ - /************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - - -typedef unsigned char ubyte; diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i deleted file mode 100644 index 17d25ad0aa6..00000000000 --- a/src/gallium/state_trackers/python/p_context.i +++ /dev/null @@ -1,756 +0,0 @@ - /************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/** - * @file - * SWIG interface definion for Gallium types. - * - * @author Jose Fonseca <[email protected]> - */ - -%nodefaultctor st_context; -%nodefaultdtor st_context; - -struct st_context { -}; - -%extend st_context { - - ~st_context() { - st_context_destroy($self); - } - - /* - * State functions (create/bind/destroy state objects) - */ - - void set_blend( const struct pipe_blend_state *state ) { - cso_set_blend($self->cso, state); - } - - void set_fragment_sampler( unsigned index, const struct pipe_sampler_state *state ) { - cso_single_sampler($self->cso, index, state); - cso_single_sampler_done($self->cso); - } - - void set_vertex_sampler( unsigned index, const struct pipe_sampler_state *state ) { - cso_single_vertex_sampler($self->cso, index, state); - cso_single_vertex_sampler_done($self->cso); - } - - void set_rasterizer( const struct pipe_rasterizer_state *state ) { - cso_set_rasterizer($self->cso, state); - } - - void set_depth_stencil_alpha(const struct pipe_depth_stencil_alpha_state *state) { - cso_set_depth_stencil_alpha($self->cso, state); - } - - void set_fragment_shader( const struct pipe_shader_state *state ) { - void *fs; - - if(!state) { - cso_set_fragment_shader_handle($self->cso, NULL); - return; - } - - fs = $self->pipe->create_fs_state($self->pipe, state); - if(!fs) - return; - - if(cso_set_fragment_shader_handle($self->cso, fs) != PIPE_OK) - return; - - cso_delete_fragment_shader($self->cso, $self->fs); - $self->fs = fs; - } - - void set_vertex_shader( const struct pipe_shader_state *state ) { - void *vs; - - if(!state) { - cso_set_vertex_shader_handle($self->cso, NULL); - return; - } - - vs = $self->pipe->create_vs_state($self->pipe, state); - if(!vs) - return; - - if(cso_set_vertex_shader_handle($self->cso, vs) != PIPE_OK) - return; - - cso_delete_vertex_shader($self->cso, $self->vs); - $self->vs = vs; - } - - void set_geometry_shader( const struct pipe_shader_state *state ) { - void *gs; - - if(!state) { - cso_set_geometry_shader_handle($self->cso, NULL); - return; - } - - gs = $self->pipe->create_gs_state($self->pipe, state); - if(!gs) - return; - - if(cso_set_geometry_shader_handle($self->cso, gs) != PIPE_OK) - return; - - cso_delete_geometry_shader($self->cso, $self->gs); - $self->gs = gs; - } - - struct pipe_sampler_view * - create_sampler_view(struct pipe_resource *texture, - enum pipe_format format = PIPE_FORMAT_NONE, - unsigned first_level = 0, - unsigned last_level = ~0, - unsigned first_layer = 0, - unsigned last_layer = ~0, - unsigned swizzle_r = 0, - unsigned swizzle_g = 1, - unsigned swizzle_b = 2, - unsigned swizzle_a = 3) - { - struct pipe_context *pipe = $self->pipe; - struct pipe_sampler_view templat; - - memset(&templat, 0, sizeof templat); - if (format == PIPE_FORMAT_NONE) { - templat.format = texture->format; - } else { - templat.format = format; - } - templat.u.tex.last_level = MIN2(last_level, texture->last_level); - templat.u.tex.first_level = first_level; - templat.u.tex.first_layer = first_layer; - templat.u.tex.last_layer = last_layer; - templat.swizzle_r = swizzle_r; - templat.swizzle_g = swizzle_g; - templat.swizzle_b = swizzle_b; - templat.swizzle_a = swizzle_a; - - return pipe->create_sampler_view(pipe, texture, &templat); - } - - void - sampler_view_destroy(struct pipe_context *ctx, - struct pipe_sampler_view *view) - { - struct pipe_context *pipe = $self->pipe; - - pipe->sampler_view_destroy(pipe, view); - } - - /* - * Parameter-like state (or properties) - */ - - void set_blend_color(const struct pipe_blend_color *state ) { - cso_set_blend_color($self->cso, state); - } - - void set_stencil_ref(const struct pipe_stencil_ref *state ) { - cso_set_stencil_ref($self->cso, state); - } - - void set_clip(const struct pipe_clip_state *state ) { - $self->pipe->set_clip_state($self->pipe, state); - } - - void set_constant_buffer(unsigned shader, unsigned index, - struct pipe_resource *buffer ) - { - $self->pipe->set_constant_buffer($self->pipe, shader, index, buffer); - } - - void set_framebuffer(const struct pipe_framebuffer_state *state ) - { - memcpy(&$self->framebuffer, state, sizeof *state); - cso_set_framebuffer($self->cso, state); - } - - void set_polygon_stipple(const struct pipe_poly_stipple *state ) { - $self->pipe->set_polygon_stipple($self->pipe, state); - } - - void set_scissor(const struct pipe_scissor_state *state ) { - $self->pipe->set_scissor_state($self->pipe, state); - } - - void set_viewport(const struct pipe_viewport_state *state) { - cso_set_viewport($self->cso, state); - } - - void set_fragment_sampler_view(unsigned index, - struct pipe_sampler_view *view) - { - pipe_sampler_view_reference(&$self->fragment_sampler_views[index], view); - - $self->pipe->set_fragment_sampler_views($self->pipe, - PIPE_MAX_SAMPLERS, - $self->fragment_sampler_views); - } - - void set_vertex_sampler_view(unsigned index, - struct pipe_sampler_view *view) - { - pipe_sampler_view_reference(&$self->vertex_sampler_views[index], view); - - $self->pipe->set_vertex_sampler_views($self->pipe, - PIPE_MAX_VERTEX_SAMPLERS, - $self->vertex_sampler_views); - } - - void set_fragment_sampler_texture(unsigned index, - struct pipe_resource *texture) { - struct pipe_sampler_view templ; - - if(!texture) - texture = $self->default_texture; - pipe_sampler_view_reference(&$self->fragment_sampler_views[index], NULL); - u_sampler_view_default_template(&templ, - texture, - texture->format); - $self->fragment_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe, - texture, - &templ); - $self->pipe->set_fragment_sampler_views($self->pipe, - PIPE_MAX_SAMPLERS, - $self->fragment_sampler_views); - } - - void set_vertex_sampler_texture(unsigned index, - struct pipe_resource *texture) { - struct pipe_sampler_view templ; - - if(!texture) - texture = $self->default_texture; - pipe_sampler_view_reference(&$self->vertex_sampler_views[index], NULL); - u_sampler_view_default_template(&templ, - texture, - texture->format); - $self->vertex_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe, - texture, - &templ); - - $self->pipe->set_vertex_sampler_views($self->pipe, - PIPE_MAX_VERTEX_SAMPLERS, - $self->vertex_sampler_views); - } - - void set_vertex_buffer(unsigned index, - unsigned stride, - unsigned buffer_offset, - struct pipe_resource *buffer) - { - unsigned i; - struct pipe_vertex_buffer state; - - memset(&state, 0, sizeof(state)); - state.stride = stride; - state.buffer_offset = buffer_offset; - state.buffer = buffer; - - memcpy(&$self->vertex_buffers[index], &state, sizeof(state)); - - for(i = 0; i < PIPE_MAX_ATTRIBS; ++i) - if(self->vertex_buffers[i].buffer) - $self->num_vertex_buffers = i + 1; - - $self->pipe->set_vertex_buffers($self->pipe, - $self->num_vertex_buffers, - $self->vertex_buffers); - } - - void set_index_buffer(unsigned index_size, - unsigned offset, - struct pipe_resource *buffer) - { - struct pipe_index_buffer ib; - - memset(&ib, 0, sizeof(ib)); - ib.index_size = index_size; - ib.offset = offset; - ib.buffer = buffer; - - $self->pipe->set_index_buffer($self->pipe, &ib); - } - - void set_vertex_element(unsigned index, - const struct pipe_vertex_element *element) - { - memcpy(&$self->vertex_elements[index], element, sizeof(*element)); - } - - void set_vertex_elements(unsigned num) - { - $self->num_vertex_elements = num; - cso_set_vertex_elements($self->cso, - $self->num_vertex_elements, - $self->vertex_elements); - } - - /* - * Draw functions - */ - - void draw_arrays(unsigned mode, unsigned start, unsigned count) { - util_draw_arrays($self->pipe, mode, start, count); - } - - void draw_vbo(const struct pipe_draw_info *info) - { - $self->pipe->draw_vbo($self->pipe, info); - } - - void draw_vertices(unsigned prim, - unsigned num_verts, - unsigned num_attribs, - const float *vertices) - { - struct pipe_context *pipe = $self->pipe; - struct pipe_screen *screen = pipe->screen; - struct pipe_resource *vbuf; - struct pipe_transfer *transfer; - struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS]; - struct pipe_vertex_buffer vbuffer; - float *map; - unsigned size; - unsigned i; - - size = num_verts * num_attribs * 4 * sizeof(float); - - vbuf = pipe_buffer_create(screen, - PIPE_BIND_VERTEX_BUFFER, - PIPE_USAGE_STATIC, - size); - if(!vbuf) - goto error1; - - map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer); - if (!map) - goto error2; - memcpy(map, vertices, size); - pipe_buffer_unmap(pipe, transfer); - - cso_save_vertex_elements($self->cso); - - /* tell pipe about the vertex attributes */ - for (i = 0; i < num_attribs; i++) { - velements[i].src_offset = i * 4 * sizeof(float); - velements[i].instance_divisor = 0; - velements[i].vertex_buffer_index = 0; - velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - } - cso_set_vertex_elements($self->cso, num_attribs, velements); - - /* tell pipe about the vertex buffer */ - memset(&vbuffer, 0, sizeof(vbuffer)); - vbuffer.buffer = vbuf; - vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */ - vbuffer.buffer_offset = 0; - pipe->set_vertex_buffers(pipe, 1, &vbuffer); - - /* draw */ - util_draw_arrays(pipe, prim, 0, num_verts); - - cso_restore_vertex_elements($self->cso); - -error2: - pipe_resource_reference(&vbuf, NULL); -error1: - ; - } - - void - clear(unsigned buffers, const float *rgba, double depth = 0.0f, - unsigned stencil = 0) - { - $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil); - } - - void - flush(unsigned flags = 0) { - struct pipe_fence_handle *fence = NULL; - $self->pipe->flush($self->pipe, &fence); - if(fence) { - /* TODO: allow asynchronous operation */ - $self->pipe->screen->fence_finish( $self->pipe->screen, fence, PIPE_TIMEOUT_INFINITE ); - $self->pipe->screen->fence_reference( $self->pipe->screen, &fence, NULL ); - } - } - - /* - * Surface functions - */ - - void resource_copy_region(struct pipe_resource *dst, - unsigned dst_level, - unsigned dstx, unsigned dsty, unsigned dstz, - struct pipe_resource *src, - unsigned src_level, - const struct pipe_box *src_box) - { - $self->pipe->resource_copy_region($self->pipe, - dst, dst_level, dstx, dsty, dstz, - src, src_level, src_box); - } - - - void clear_render_target(struct st_surface *dst, - float *rgba, - unsigned x, unsigned y, - unsigned width, unsigned height) - { - struct pipe_surface *_dst = NULL; - - _dst = st_pipe_surface($self->pipe, dst, PIPE_BIND_RENDER_TARGET); - if(!_dst) - SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing"); - - $self->pipe->clear_render_target($self->pipe, _dst, rgba, x, y, width, height); - - fail: - pipe_surface_reference(&_dst, NULL); - } - - void clear_depth_stencil(struct st_surface *dst, - unsigned clear_flags, - double depth, - unsigned stencil, - unsigned x, unsigned y, - unsigned width, unsigned height) - { - struct pipe_surface *_dst = NULL; - - _dst = st_pipe_surface($self->pipe, dst, PIPE_BIND_DEPTH_STENCIL); - if(!_dst) - SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing"); - - $self->pipe->clear_depth_stencil($self->pipe, _dst, clear_flags, depth, stencil, - x, y, width, height); - - fail: - pipe_surface_reference(&_dst, NULL); - } - - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void - surface_read_raw(struct st_surface *surface, - unsigned x, unsigned y, unsigned w, unsigned h, - char **STRING, int *LENGTH) - { - struct pipe_resource *texture = surface->texture; - struct pipe_context *pipe = $self->pipe; - struct pipe_transfer *transfer; - unsigned stride; - - stride = util_format_get_stride(texture->format, w); - *LENGTH = util_format_get_nblocksy(texture->format, h) * stride; - *STRING = (char *) malloc(*LENGTH); - if(!*STRING) - return; - - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride); - pipe->transfer_destroy(pipe, transfer); - } - } - - %cstring_input_binary(const char *STRING, unsigned LENGTH); - void - surface_write_raw(struct st_surface *surface, - unsigned x, unsigned y, unsigned w, unsigned h, - const char *STRING, unsigned LENGTH, unsigned stride = 0) - { - struct pipe_resource *texture = surface->texture; - struct pipe_context *pipe = $self->pipe; - struct pipe_transfer *transfer; - - if(stride == 0) - stride = util_format_get_stride(texture->format, w); - - if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride) - SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(!transfer) - SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer"); - - pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride); - pipe->transfer_destroy(pipe, transfer); - - fail: - return; - } - - void - surface_read_rgba(struct st_surface *surface, - unsigned x, unsigned y, unsigned w, unsigned h, - float *rgba) - { - struct pipe_context *pipe = $self->pipe; - struct pipe_transfer *transfer; - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->transfer_destroy(pipe, transfer); - } - } - - void - surface_write_rgba(struct st_surface *surface, - unsigned x, unsigned y, unsigned w, unsigned h, - const float *rgba) - { - struct pipe_context *pipe = $self->pipe; - struct pipe_transfer *transfer; - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(transfer) { - pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - pipe->transfer_destroy(pipe, transfer); - } - } - - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void - surface_read_rgba8(struct st_surface *surface, - unsigned x, unsigned y, unsigned w, unsigned h, - char **STRING, int *LENGTH) - { - struct pipe_context *pipe = $self->pipe; - struct pipe_transfer *transfer; - float *rgba; - unsigned char *rgba8; - unsigned i, j, k; - - *LENGTH = 0; - *STRING = NULL; - - if (!surface) - return; - - *LENGTH = h*w*4; - *STRING = (char *) malloc(*LENGTH); - if(!*STRING) - return; - - rgba = malloc(h*w*4*sizeof(float)); - if(!rgba) - return; - - rgba8 = (unsigned char *) *STRING; - - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba); - for(j = 0; j < h; ++j) { - for(i = 0; i < w; ++i) - for(k = 0; k <4; ++k) - rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]); - } - pipe->transfer_destroy(pipe, transfer); - } - - free(rgba); - } - - void - surface_read_z(struct st_surface *surface, - unsigned x, unsigned y, unsigned w, unsigned h, - unsigned *z) - { - struct pipe_context *pipe = $self->pipe; - struct pipe_transfer *transfer; - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_READ, - x, y, w, h); - if(transfer) { - pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->transfer_destroy(pipe, transfer); - } - } - - void - surface_write_z(struct st_surface *surface, - unsigned x, unsigned y, unsigned w, unsigned h, - const unsigned *z) - { - struct pipe_context *pipe = $self->pipe; - struct pipe_transfer *transfer; - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_WRITE, - x, y, w, h); - if(transfer) { - pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z); - pipe->transfer_destroy(pipe, transfer); - } - } - - void - surface_sample_rgba(struct st_surface *surface, - float *rgba, - int norm = 0) - { - st_sample_surface($self->pipe, surface, rgba, norm != 0); - } - - unsigned - surface_compare_rgba(struct st_surface *surface, - unsigned x, unsigned y, unsigned w, unsigned h, - const float *rgba, float tol = 0.0) - { - struct pipe_context *pipe = $self->pipe; - struct pipe_transfer *transfer; - float *rgba2; - const float *p1; - const float *p2; - unsigned i, j, n; - - rgba2 = MALLOC(h*w*4*sizeof(float)); - if(!rgba2) - return ~0; - - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_READ, - x, y, w, h); - if(!transfer) { - FREE(rgba2); - return ~0; - } - - pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2); - pipe->transfer_destroy(pipe, transfer); - - p1 = rgba; - p2 = rgba2; - n = 0; - for(i = h*w; i; --i) { - unsigned differs = 0; - for(j = 4; j; --j) { - float delta = *p2++ - *p1++; - if (delta < -tol || delta > tol) - differs = 1; - } - n += differs; - } - - FREE(rgba2); - - return n; - } - - %cstring_input_binary(const char *STRING, unsigned LENGTH); - void - transfer_inline_write(struct pipe_resource *resource, - unsigned level, - unsigned usage, - const struct pipe_box *box, - const char *STRING, unsigned LENGTH, - unsigned stride, - unsigned layer_stride) - { - struct pipe_context *pipe = $self->pipe; - - pipe->transfer_inline_write(pipe, resource, level, usage, box, STRING, stride, layer_stride); - } - - %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1)); - void buffer_read(struct pipe_resource *buffer, - char **STRING, int *LENGTH) - { - struct pipe_context *pipe = $self->pipe; - - assert(buffer->target == PIPE_BUFFER); - - *LENGTH = buffer->width0; - *STRING = (char *) malloc(buffer->width0); - if(!*STRING) - return; - - pipe_buffer_read(pipe, buffer, 0, buffer->width0, *STRING); - } - - void buffer_write(struct pipe_resource *buffer, - const char *STRING, unsigned LENGTH, unsigned offset = 0) - { - struct pipe_context *pipe = $self->pipe; - - assert(buffer->target == PIPE_BUFFER); - - if(offset > buffer->width0) - SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size"); - - if(offset + LENGTH > buffer->width0) - SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer"); - - pipe_buffer_write(pipe, buffer, offset, LENGTH, STRING); - -fail: - return; - } - -}; diff --git a/src/gallium/state_trackers/python/p_device.i b/src/gallium/state_trackers/python/p_device.i deleted file mode 100644 index 61f6b3bb739..00000000000 --- a/src/gallium/state_trackers/python/p_device.i +++ /dev/null @@ -1,138 +0,0 @@ - /************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/** - * @file - * SWIG interface definion for Gallium types. - * - * @author Jose Fonseca <[email protected]> - */ - - -%nodefaultctor st_device; -%nodefaultdtor st_device; - - -struct st_device { -}; - -%newobject st_device::texture_create; -%newobject st_device::context_create; -%newobject st_device::buffer_create; - -%extend st_device { - - st_device(int hardware = 1) { - return st_device_create(hardware ? TRUE : FALSE); - } - - ~st_device() { - st_device_destroy($self); - } - - const char * get_name( void ) { - return $self->screen->get_name($self->screen); - } - - const char * get_vendor( void ) { - return $self->screen->get_vendor($self->screen); - } - - /** - * Query an integer-valued capability/parameter/limit - * \param param one of PIPE_CAP_x - */ - int get_param( int param ) { - return $self->screen->get_param($self->screen, param); - } - - /** - * Query a float-valued capability/parameter/limit - * \param param one of PIPE_CAP_x - */ - float get_paramf( int param ) { - return $self->screen->get_paramf($self->screen, param); - } - - /** - * Check if the given pipe_format is supported as a texture or - * drawing surface. - * \param bind bitmask of PIPE_BIND flags - */ - int is_format_supported( enum pipe_format format, - enum pipe_texture_target target, - unsigned sample_count, - unsigned bind ) { - /* We can't really display surfaces with the python statetracker so mask - * out that usage */ - bind &= ~PIPE_BIND_DISPLAY_TARGET; - - return $self->screen->is_format_supported( $self->screen, - format, - target, - sample_count, - bind ); - } - - struct st_context * - context_create(void) { - return st_context_create($self); - } - - struct pipe_resource * - resource_create( - enum pipe_format format, - unsigned width, - unsigned height, - unsigned depth = 1, - unsigned last_level = 0, - enum pipe_texture_target target = PIPE_TEXTURE_2D, - unsigned bind = 0 - ) { - struct pipe_resource templat; - - /* We can't really display surfaces with the python statetracker so mask - * out that usage */ - bind &= ~PIPE_BIND_DISPLAY_TARGET; - - memset(&templat, 0, sizeof(templat)); - templat.format = format; - templat.width0 = width; - templat.height0 = height; - templat.depth0 = depth; - templat.last_level = last_level; - templat.target = target; - templat.bind = bind; - - return $self->screen->resource_create($self->screen, &templat); - } - - struct pipe_resource * - buffer_create(unsigned size, unsigned usage, unsigned bind = 0) { - return pipe_buffer_create($self->screen, bind, usage, size); - } -}; diff --git a/src/gallium/state_trackers/python/p_state.i b/src/gallium/state_trackers/python/p_state.i deleted file mode 100644 index 0537557661d..00000000000 --- a/src/gallium/state_trackers/python/p_state.i +++ /dev/null @@ -1,186 +0,0 @@ - /************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/** - * @file - * SWIG interface definion for Gallium types. - * - * @author Jose Fonseca <[email protected]> - */ - -%module gallium; - -%ignore winsys; -%ignore pipe_vertex_buffer::buffer; - -%include "pipe/p_compiler.h"; -%include "pipe/p_state.h"; - - -%array_class(struct pipe_stencil_state, StencilArray); - - -%extend pipe_rt_blend_state -{ - struct pipe_rt_blend_state * - __getitem__(int index) - { - if(index < 0 || index >= PIPE_MAX_COLOR_BUFS) - SWIG_exception(SWIG_ValueError, "index out of bounds"); - return $self + index; - fail: - return NULL; - }; -}; - - -%extend pipe_blend_state -{ - pipe_blend_state(void) - { - return CALLOC_STRUCT(pipe_blend_state); - } - - %cstring_input_binary(const char *STRING, unsigned LENGTH); - pipe_blend_state(const char *STRING, unsigned LENGTH) - { - struct pipe_blend_state *state; - state = CALLOC_STRUCT(pipe_blend_state); - if (state) { - LENGTH = MIN2(sizeof *state, LENGTH); - memcpy(state, STRING, LENGTH); - } - return state; - } - - %cstring_output_allocate_size(char **STRING, int *LENGTH, os_free(*$1)); - void __str__(char **STRING, int *LENGTH) - { - struct os_stream *stream; - - stream = os_str_stream_create(1); - util_dump_blend_state(stream, $self); - - *STRING = os_str_stream_get_and_close(stream); - *LENGTH = strlen(*STRING); - } -}; - - -%extend pipe_framebuffer_state { - - pipe_framebuffer_state(void) { - return CALLOC_STRUCT(pipe_framebuffer_state); - } - - ~pipe_framebuffer_state() { - unsigned index; - for(index = 0; index < PIPE_MAX_COLOR_BUFS; ++index) - pipe_surface_reference(&$self->cbufs[index], NULL); - pipe_surface_reference(&$self->zsbuf, NULL); - FREE($self); - } - - void - set_cbuf(unsigned index, struct st_surface *surface) - { - struct pipe_surface *_surface = NULL; - - if(index >= PIPE_MAX_COLOR_BUFS) - SWIG_exception(SWIG_ValueError, "index out of bounds"); - - if(surface) { - /* XXX need a context here */ - _surface = st_pipe_surface(NULL, surface, PIPE_BIND_RENDER_TARGET); - if(!_surface) - SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing"); - } - - pipe_surface_reference(&$self->cbufs[index], _surface); - - fail: - return; - } - - void - set_zsbuf(struct st_surface *surface) - { - struct pipe_surface *_surface = NULL; - - if(surface) { - /* XXX need a context here */ - _surface = st_pipe_surface(NULL, surface, PIPE_BIND_DEPTH_STENCIL); - if(!_surface) - SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing"); - } - - pipe_surface_reference(&$self->zsbuf, _surface); - - fail: - return; - } - -}; - - -%extend pipe_shader_state { - - pipe_shader_state(const char *text, unsigned num_tokens = 1024) { - struct tgsi_token *tokens; - struct pipe_shader_state *shader; - - tokens = MALLOC(num_tokens * sizeof(struct tgsi_token)); - if(!tokens) - goto error1; - - if(tgsi_text_translate(text, tokens, num_tokens ) != TRUE) - goto error2; - - shader = CALLOC_STRUCT(pipe_shader_state); - if(!shader) - goto error3; - - shader->tokens = tokens; - - return shader; - -error3: -error2: - FREE(tokens); -error1: - return NULL; - } - - ~pipe_shader_state() { - FREE((void*)$self->tokens); - FREE($self); - } - - void dump(unsigned flags = 0) { - tgsi_dump($self->tokens, flags); - } -} diff --git a/src/gallium/state_trackers/python/p_texture.i b/src/gallium/state_trackers/python/p_texture.i deleted file mode 100644 index 1f4b4fd596b..00000000000 --- a/src/gallium/state_trackers/python/p_texture.i +++ /dev/null @@ -1,152 +0,0 @@ - /************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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. - * - **************************************************************************/ - -/** - * @file - * SWIG interface definion for Gallium types. - * - * @author Jose Fonseca <[email protected]> - */ - - -%nodefaultctor pipe_resource; -%nodefaultctor st_surface; - -%nodefaultdtor pipe_resource; -%nodefaultdtor st_surface; - -%ignore pipe_resource::screen; - -%immutable st_surface::texture; -%immutable st_surface::level; -%immutable st_surface::layer; - -%newobject pipe_resource::get_surface; - -/* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */ -%rename(read) read_; -%rename(write) write_; - -%extend pipe_resource { - - ~pipe_resource() { - struct pipe_resource *ptr = $self; - pipe_resource_reference(&ptr, NULL); - } - - unsigned get_width(unsigned level=0) { - return u_minify($self->width0, level); - } - - unsigned get_height(unsigned level=0) { - return u_minify($self->height0, level); - } - - unsigned get_depth(unsigned level=0) { - return u_minify($self->depth0, level); - } - - /** Get a surface which is a "view" into a texture */ - struct st_surface * - get_surface(unsigned level=0, unsigned layer=0) - { - struct st_surface *surface; - - if(level > $self->last_level) - SWIG_exception(SWIG_ValueError, "level out of bounds"); - if(layer >= ($self->target == PIPE_TEXTURE_3D ? - u_minify($self->depth0, level) : $self->depth0)) - SWIG_exception(SWIG_ValueError, "layer out of bounds"); - - surface = CALLOC_STRUCT(st_surface); - if(!surface) - return NULL; - - pipe_resource_reference(&surface->texture, $self); - surface->level = level; - surface->layer = layer; - - return surface; - - fail: - return NULL; - } - - unsigned __len__(void) - { - assert($self->target == PIPE_BUFFER); - assert(p_atomic_read(&$self->reference.count) > 0); - return $self->width0; - } - -}; - -struct st_surface -{ - %immutable; - - struct pipe_resource *texture; - unsigned level; - unsigned layer; - -}; - -%extend st_surface { - - %immutable; - - unsigned format; - unsigned width; - unsigned height; - - ~st_surface() { - pipe_resource_reference(&$self->texture, NULL); - FREE($self); - } - - -}; - -%{ - static enum pipe_format - st_surface_format_get(struct st_surface *surface) - { - return surface->texture->format; - } - - static unsigned - st_surface_width_get(struct st_surface *surface) - { - return u_minify(surface->texture->width0, surface->level); - } - - static unsigned - st_surface_height_get(struct st_surface *surface) - { - return u_minify(surface->texture->height0, surface->level); - } -%} diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c deleted file mode 100644 index d0a4295c7a2..00000000000 --- a/src/gallium/state_trackers/python/st_device.c +++ /dev/null @@ -1,305 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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 "pipe/p_screen.h" -#include "pipe/p_context.h" -#include "pipe/p_shader_tokens.h" -#include "util/u_inlines.h" -#include "cso_cache/cso_context.h" -#include "util/u_math.h" -#include "util/u_memory.h" -#include "util/u_sampler.h" -#include "util/u_simple_shaders.h" -#include "trace/tr_public.h" - -#include "st_device.h" -#include "st_winsys.h" - - -static void -st_device_really_destroy(struct st_device *st_dev) -{ - if(st_dev->screen) { - /* FIXME: Don't really destroy until we keep track of every single - * reference or we end up causing a segmentation fault every time - * python exits. */ -#if 0 - st_dev->screen->destroy(st_dev->screen); -#endif - } - - FREE(st_dev); -} - - -static void -st_device_reference(struct st_device **ptr, struct st_device *st_dev) -{ - struct st_device *old_dev = *ptr; - - if (pipe_reference(&(*ptr)->reference, &st_dev->reference)) - st_device_really_destroy(old_dev); - *ptr = st_dev; -} - - -void -st_device_destroy(struct st_device *st_dev) -{ - st_device_reference(&st_dev, NULL); -} - - -struct st_device * -st_device_create(boolean hardware) -{ - struct pipe_screen *screen; - struct st_device *st_dev; - - if (hardware) - screen = st_hardware_screen_create(); - else - screen = st_software_screen_create("softpipe"); - - screen = trace_screen_create(screen); - if (!screen) - goto no_screen; - - st_dev = CALLOC_STRUCT(st_device); - if (!st_dev) - goto no_device; - - pipe_reference_init(&st_dev->reference, 1); - st_dev->screen = screen; - - return st_dev; - -no_device: - screen->destroy(screen); -no_screen: - return NULL; -} - - -void -st_context_destroy(struct st_context *st_ctx) -{ - unsigned i; - - if(st_ctx) { - struct st_device *st_dev = st_ctx->st_dev; - - if(st_ctx->cso) { - cso_delete_vertex_shader(st_ctx->cso, st_ctx->vs); - cso_delete_fragment_shader(st_ctx->cso, st_ctx->fs); - - cso_destroy_context(st_ctx->cso); - } - - if(st_ctx->pipe) - st_ctx->pipe->destroy(st_ctx->pipe); - - for(i = 0; i < PIPE_MAX_SAMPLERS; ++i) - pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], NULL); - for(i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; ++i) - pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], NULL); - pipe_resource_reference(&st_ctx->default_texture, NULL); - - FREE(st_ctx); - - st_device_reference(&st_dev, NULL); - } -} - - -struct st_context * -st_context_create(struct st_device *st_dev) -{ - struct st_context *st_ctx; - - st_ctx = CALLOC_STRUCT(st_context); - if(!st_ctx) - return NULL; - - st_device_reference(&st_ctx->st_dev, st_dev); - - st_ctx->pipe = st_dev->screen->context_create(st_dev->screen, NULL); - if(!st_ctx->pipe) { - st_context_destroy(st_ctx); - return NULL; - } - - st_ctx->cso = cso_create_context(st_ctx->pipe); - if(!st_ctx->cso) { - st_context_destroy(st_ctx); - return NULL; - } - - /* disabled blending/masking */ - { - struct pipe_blend_state blend; - memset(&blend, 0, sizeof(blend)); - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE; - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE; - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO; - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO; - blend.rt[0].colormask = PIPE_MASK_RGBA; - cso_set_blend(st_ctx->cso, &blend); - } - - /* no-op depth/stencil/alpha */ - { - struct pipe_depth_stencil_alpha_state depthstencil; - memset(&depthstencil, 0, sizeof(depthstencil)); - cso_set_depth_stencil_alpha(st_ctx->cso, &depthstencil); - } - - /* rasterizer */ - { - struct pipe_rasterizer_state rasterizer; - memset(&rasterizer, 0, sizeof(rasterizer)); - rasterizer.cull_face = PIPE_FACE_NONE; - cso_set_rasterizer(st_ctx->cso, &rasterizer); - } - - /* clip */ - { - struct pipe_clip_state clip; - memset(&clip, 0, sizeof(clip)); - st_ctx->pipe->set_clip_state(st_ctx->pipe, &clip); - } - - /* identity viewport */ - { - struct pipe_viewport_state viewport; - viewport.scale[0] = 1.0; - viewport.scale[1] = 1.0; - viewport.scale[2] = 1.0; - viewport.scale[3] = 1.0; - viewport.translate[0] = 0.0; - viewport.translate[1] = 0.0; - viewport.translate[2] = 0.0; - viewport.translate[3] = 0.0; - cso_set_viewport(st_ctx->cso, &viewport); - } - - /* samplers */ - { - struct pipe_sampler_state sampler; - unsigned i; - memset(&sampler, 0, sizeof(sampler)); - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST; - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; - sampler.normalized_coords = 1; - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) - cso_single_sampler(st_ctx->cso, i, &sampler); - cso_single_sampler_done(st_ctx->cso); - } - - /* default textures */ - { - struct pipe_context *pipe = st_ctx->pipe; - struct pipe_screen *screen = st_dev->screen; - struct pipe_resource templat; - struct pipe_sampler_view view_templ; - struct pipe_sampler_view *view; - unsigned i; - - memset( &templat, 0, sizeof( templat ) ); - templat.target = PIPE_TEXTURE_2D; - templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; - templat.width0 = 1; - templat.height0 = 1; - templat.depth0 = 1; - templat.array_size = 1; - templat.last_level = 0; - templat.bind = PIPE_BIND_SAMPLER_VIEW; - - st_ctx->default_texture = screen->resource_create( screen, &templat ); - if(st_ctx->default_texture) { - struct pipe_box box; - uint32_t zero = 0; - - u_box_origin_2d( 1, 1, &box ); - - pipe->transfer_inline_write(pipe, - st_ctx->default_texture, - 0, - PIPE_TRANSFER_WRITE, - &box, - &zero, - sizeof zero, - 0); - } - - u_sampler_view_default_template(&view_templ, - st_ctx->default_texture, - st_ctx->default_texture->format); - view = st_ctx->pipe->create_sampler_view(st_ctx->pipe, - st_ctx->default_texture, - &view_templ); - - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) - pipe_sampler_view_reference(&st_ctx->fragment_sampler_views[i], view); - for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) - pipe_sampler_view_reference(&st_ctx->vertex_sampler_views[i], view); - - st_ctx->pipe->set_fragment_sampler_views(st_ctx->pipe, - PIPE_MAX_SAMPLERS, - st_ctx->fragment_sampler_views); - st_ctx->pipe->set_vertex_sampler_views(st_ctx->pipe, - PIPE_MAX_VERTEX_SAMPLERS, - st_ctx->vertex_sampler_views); - - pipe_sampler_view_reference(&view, NULL); - } - - /* vertex shader */ - { - const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, - TGSI_SEMANTIC_GENERIC }; - const uint semantic_indexes[] = { 0, 0 }; - st_ctx->vs = util_make_vertex_passthrough_shader(st_ctx->pipe, - 2, - semantic_names, - semantic_indexes); - cso_set_vertex_shader_handle(st_ctx->cso, st_ctx->vs); - } - - /* fragment shader */ - { - st_ctx->fs = util_make_fragment_passthrough_shader(st_ctx->pipe); - cso_set_fragment_shader_handle(st_ctx->cso, st_ctx->fs); - } - - return st_ctx; -} diff --git a/src/gallium/state_trackers/python/st_device.h b/src/gallium/state_trackers/python/st_device.h deleted file mode 100644 index 53e2556cb0d..00000000000 --- a/src/gallium/state_trackers/python/st_device.h +++ /dev/null @@ -1,111 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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 ST_DEVICE_H_ -#define ST_DEVICE_H_ - - -#include "pipe/p_state.h" - -struct cso_context; -struct pipe_screen; -struct pipe_context; -struct st_winsys; - - -struct st_surface -{ - struct pipe_resource *texture; - unsigned level; - unsigned layer; -}; - - -struct st_context -{ - struct st_device *st_dev; - - struct pipe_context *pipe; - - struct cso_context *cso; - - void *vs; - void *fs; - void *gs; - - struct pipe_resource *default_texture; - struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS]; - struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS]; - - unsigned num_vertex_buffers; - struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; - - unsigned num_vertex_elements; - struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS]; - - struct pipe_framebuffer_state framebuffer; -}; - - -struct st_device -{ - /* FIXME: we also need to refcount for textures and surfaces... */ - struct pipe_reference reference; - - struct pipe_screen *screen; -}; - - -static INLINE struct pipe_surface * -st_pipe_surface(struct pipe_context *pipe, struct st_surface *surface, unsigned usage) -{ - struct pipe_resource *texture = surface->texture; - struct pipe_surface surf_tmpl; - memset(&surf_tmpl, 0, sizeof(surf_tmpl)); - surf_tmpl.format = texture->format; - surf_tmpl.usage = usage; - surf_tmpl.u.tex.level = surface->level; - surf_tmpl.u.tex.first_layer = surface->layer; - surf_tmpl.u.tex.last_layer = surface->layer; - return pipe->create_surface(pipe, texture, &surf_tmpl); -} - -struct st_context * -st_context_create(struct st_device *st_dev); - -void -st_context_destroy(struct st_context *st_ctx); - -struct st_device * -st_device_create(boolean hardware); - -void -st_device_destroy(struct st_device *st_dev); - - -#endif /* ST_DEVICE_H_ */ diff --git a/src/gallium/state_trackers/python/st_hardpipe_winsys.c b/src/gallium/state_trackers/python/st_hardpipe_winsys.c deleted file mode 100644 index c6743dbd9c4..00000000000 --- a/src/gallium/state_trackers/python/st_hardpipe_winsys.c +++ /dev/null @@ -1,212 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Bismarck, ND., USA - * 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 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -/** - * @file - * Get a hardware accelerated Gallium screen/context from the OpenGL driver. - */ - - -#include "pipe/p_compiler.h" - -#ifdef PIPE_OS_WINDOWS -#include <windows.h> -#include <GL/gl.h> -#else -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <GL/gl.h> -#include <GL/glx.h> -#endif - -#include "st_winsys.h" - - -typedef struct pipe_screen * (GLAPIENTRY *PFNGETGALLIUMSCREENMESAPROC) (void); -typedef struct pipe_context * (GLAPIENTRY* PFNCREATEGALLIUMCONTEXTMESAPROC) (void); - -static PFNGETGALLIUMSCREENMESAPROC pfnGetGalliumScreenMESA = NULL; -static PFNCREATEGALLIUMCONTEXTMESAPROC pfnCreateGalliumContextMESA = NULL; - - -#ifdef PIPE_OS_WINDOWS - -static INLINE boolean -st_hardpipe_load(void) -{ - WNDCLASS wc; - HWND hwnd; - HGLRC hglrc; - HDC hdc; - PIXELFORMATDESCRIPTOR pfd; - int iPixelFormat; - - if(pfnGetGalliumScreenMESA && pfnCreateGalliumContextMESA) - return TRUE; - - memset(&wc, 0, sizeof wc); - wc.lpfnWndProc = DefWindowProc; - wc.lpszClassName = "gallium"; - wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; - RegisterClass(&wc); - - hwnd = CreateWindow(wc.lpszClassName, "gallium", 0, 0, 0, 0, 0, NULL, 0, wc.hInstance, NULL); - if (!hwnd) - return FALSE; - - hdc = GetDC(hwnd); - if (!hdc) - return FALSE; - - pfd.cColorBits = 3; - pfd.cRedBits = 1; - pfd.cGreenBits = 1; - pfd.cBlueBits = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; - pfd.iLayerType = PFD_MAIN_PLANE; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - - iPixelFormat = ChoosePixelFormat(hdc, &pfd); - if (!iPixelFormat) { - pfd.dwFlags |= PFD_DOUBLEBUFFER; - iPixelFormat = ChoosePixelFormat(hdc, &pfd); - } - if (!iPixelFormat) - return FALSE; - - SetPixelFormat(hdc, iPixelFormat, &pfd); - hglrc = wglCreateContext(hdc); - if (!hglrc) - return FALSE; - - if (!wglMakeCurrent(hdc, hglrc)) - return FALSE; - - pfnGetGalliumScreenMESA = (PFNGETGALLIUMSCREENMESAPROC)wglGetProcAddress("wglGetGalliumScreenMESA"); - if(!pfnGetGalliumScreenMESA) - return FALSE; - - pfnCreateGalliumContextMESA = (PFNCREATEGALLIUMCONTEXTMESAPROC)wglGetProcAddress("wglCreateGalliumContextMESA"); - if(!pfnCreateGalliumContextMESA) - return FALSE; - - DestroyWindow(hwnd); - - return TRUE; -} - -#else - -static INLINE boolean -st_hardpipe_load(void) -{ - Display *dpy; - int scrnum; - Window root; - int attribSingle[] = { - GLX_RGBA, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, - None }; - int attribDouble[] = { - GLX_RGBA, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, - GLX_DOUBLEBUFFER, - None }; - XVisualInfo *visinfo; - GLXContext ctx = NULL; - XSetWindowAttributes attr; - unsigned long mask; - int width = 100, height = 100; - Window win; - - dpy = XOpenDisplay(NULL); - if (!dpy) - return FALSE; - - scrnum = 0; - - root = RootWindow(dpy, scrnum); - - visinfo = glXChooseVisual(dpy, scrnum, attribSingle); - if (!visinfo) - visinfo = glXChooseVisual(dpy, scrnum, attribDouble); - if (!visinfo) - return FALSE; - - ctx = glXCreateContext( dpy, visinfo, NULL, True ); - - if (!ctx) - return FALSE; - - attr.background_pixel = 0; - attr.border_pixel = 0; - attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | ExposureMask; - - mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; - - win = XCreateWindow(dpy, root, 0, 0, width, height, - 0, visinfo->depth, InputOutput, - visinfo->visual, mask, &attr); - - if (!glXMakeCurrent(dpy, win, ctx)) - return FALSE; - - pfnGetGalliumScreenMESA = (PFNGETGALLIUMSCREENMESAPROC)glXGetProcAddressARB((const GLubyte *)"glXGetGalliumScreenMESA"); - if(!pfnGetGalliumScreenMESA) - return FALSE; - - pfnCreateGalliumContextMESA = (PFNCREATEGALLIUMCONTEXTMESAPROC)glXGetProcAddressARB((const GLubyte *)"glXCreateGalliumContextMESA"); - if(!pfnCreateGalliumContextMESA) - return FALSE; - - glXDestroyContext(dpy, ctx); - XFree(visinfo); - XDestroyWindow(dpy, win); - XCloseDisplay(dpy); - - return TRUE; -} - -#endif - - -struct pipe_screen * -st_hardware_screen_create(void) -{ - if(st_hardpipe_load()) - return pfnGetGalliumScreenMESA(); - else - return st_software_screen_create(NULL); -} diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c deleted file mode 100644 index cac9a1a6204..00000000000 --- a/src/gallium/state_trackers/python/st_sample.c +++ /dev/null @@ -1,594 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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 "pipe/p_compiler.h" -#include "pipe/p_format.h" -#include "pipe/p_state.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_tile.h" -#include "util/u_math.h" -#include "util/u_memory.h" - -#include "st_device.h" -#include "st_sample.h" - - -/** - * Use our own pseudo random generator to ensure consistent runs among - * multiple runs and platforms. - * - * @sa http://en.wikipedia.org/wiki/Linear_congruential_generator - */ -static uint32_t st_random(void) { - static uint64_t seed = UINT64_C(0xbb9a063afb0a739d); - - seed = UINT64_C(134775813) * seed + UINT64_C(1); - - return (uint32_t)(seed >> 32); -} - - -/** - * We don't want to include the patent-encumbered DXT code here, so instead - * we store several uncompressed/compressed data pairs for hardware testing - * purposes. - */ -struct dxt_data -{ - uint8_t rgba[16*4]; - uint8_t raw[16]; -}; - - -static const struct dxt_data -dxt1_rgb_data[] = { - { - { - 0x99, 0xb0, 0x8e, 0xff, - 0x5d, 0x62, 0x89, 0xff, - 0x99, 0xb0, 0x8e, 0xff, - 0x99, 0xb0, 0x8e, 0xff, - 0xd6, 0xff, 0x94, 0xff, - 0x5d, 0x62, 0x89, 0xff, - 0x99, 0xb0, 0x8e, 0xff, - 0xd6, 0xff, 0x94, 0xff, - 0x5d, 0x62, 0x89, 0xff, - 0x5d, 0x62, 0x89, 0xff, - 0x99, 0xb0, 0x8e, 0xff, - 0x21, 0x14, 0x84, 0xff, - 0x5d, 0x62, 0x89, 0xff, - 0x21, 0x14, 0x84, 0xff, - 0x21, 0x14, 0x84, 0xff, - 0x99, 0xb0, 0x8e, 0xff - }, - {0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97} - }, - { - { - 0xb5, 0xcf, 0x9c, 0xff, - 0x83, 0x8c, 0x8b, 0xff, - 0x21, 0x08, 0x6b, 0xff, - 0x83, 0x8c, 0x8b, 0xff, - 0x52, 0x4a, 0x7b, 0xff, - 0x83, 0x8c, 0x8b, 0xff, - 0x83, 0x8c, 0x8b, 0xff, - 0xb5, 0xcf, 0x9c, 0xff, - 0x21, 0x08, 0x6b, 0xff, - 0xb5, 0xcf, 0x9c, 0xff, - 0x83, 0x8c, 0x8b, 0xff, - 0x52, 0x4a, 0x7b, 0xff, - 0xb5, 0xcf, 0x9c, 0xff, - 0x83, 0x8c, 0x8b, 0xff, - 0x52, 0x4a, 0x7b, 0xff, - 0x83, 0x8c, 0x8b, 0xff - }, - {0x73, 0xb6, 0x4d, 0x20, 0x98, 0x2b, 0xe1, 0xb8} - }, - { - { - 0x00, 0x2c, 0xff, 0xff, - 0x94, 0x8d, 0x7b, 0xff, - 0x4a, 0x5c, 0xbd, 0xff, - 0x4a, 0x5c, 0xbd, 0xff, - 0x4a, 0x5c, 0xbd, 0xff, - 0x94, 0x8d, 0x7b, 0xff, - 0x94, 0x8d, 0x7b, 0xff, - 0x94, 0x8d, 0x7b, 0xff, - 0xde, 0xbe, 0x39, 0xff, - 0x94, 0x8d, 0x7b, 0xff, - 0xde, 0xbe, 0x39, 0xff, - 0xde, 0xbe, 0x39, 0xff, - 0xde, 0xbe, 0x39, 0xff, - 0xde, 0xbe, 0x39, 0xff, - 0xde, 0xbe, 0x39, 0xff, - 0x94, 0x8d, 0x7b, 0xff - }, - {0xe7, 0xdd, 0x7f, 0x01, 0xf9, 0xab, 0x08, 0x80} - }, - { - { - 0x6b, 0x24, 0x21, 0xff, - 0x7b, 0x4f, 0x5d, 0xff, - 0x7b, 0x4f, 0x5d, 0xff, - 0x8b, 0x7a, 0x99, 0xff, - 0x7b, 0x4f, 0x5d, 0xff, - 0x7b, 0x4f, 0x5d, 0xff, - 0x6b, 0x24, 0x21, 0xff, - 0x8b, 0x7a, 0x99, 0xff, - 0x9c, 0xa6, 0xd6, 0xff, - 0x6b, 0x24, 0x21, 0xff, - 0x7b, 0x4f, 0x5d, 0xff, - 0x8b, 0x7a, 0x99, 0xff, - 0x6b, 0x24, 0x21, 0xff, - 0x8b, 0x7a, 0x99, 0xff, - 0x7b, 0x4f, 0x5d, 0xff, - 0x9c, 0xa6, 0xd6, 0xff - }, - {0x3a, 0x9d, 0x24, 0x69, 0xbd, 0x9f, 0xb4, 0x39} - } -}; - - -static const struct dxt_data -dxt1_rgba_data[] = { - { - { - 0x00, 0x00, 0x00, 0x00, - 0x4e, 0xaa, 0x90, 0xff, - 0x4e, 0xaa, 0x90, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x4e, 0xaa, 0x90, 0xff, - 0x29, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x4e, 0xaa, 0x90, 0xff, - 0x73, 0x55, 0x21, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4e, 0xaa, 0x90, 0xff, - 0x4e, 0xaa, 0x90, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4e, 0xaa, 0x90, 0xff - }, - {0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe} - }, - { - { - 0xb5, 0xe3, 0x63, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x6b, 0x24, 0x84, 0xff, - 0xb5, 0xe3, 0x63, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0xb5, 0xe3, 0x63, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x6b, 0x24, 0x84, 0xff, - 0x6b, 0x24, 0x84, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0xb5, 0xe3, 0x63, 0xff, - 0x90, 0x83, 0x73, 0xff, - 0xb5, 0xe3, 0x63, 0xff - }, - {0x30, 0x69, 0x0c, 0xb7, 0x4d, 0xf7, 0x0f, 0x67} - }, - { - { - 0x00, 0x00, 0x00, 0x00, - 0xc6, 0x86, 0x8c, 0xff, - 0xc6, 0x86, 0x8c, 0xff, - 0x21, 0x65, 0x42, 0xff, - 0x21, 0x65, 0x42, 0xff, - 0x21, 0x65, 0x42, 0xff, - 0x21, 0x65, 0x42, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x21, 0x65, 0x42, 0xff, - 0xc6, 0x86, 0x8c, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xc6, 0x86, 0x8c, 0xff - }, - {0x28, 0x23, 0x31, 0xc4, 0x17, 0xc0, 0xd3, 0x7f} - }, - { - { - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xc6, 0xe3, 0x9c, 0xff, - 0x7b, 0x1c, 0x52, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x7b, 0x1c, 0x52, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x7b, 0x1c, 0x52, 0xff, - 0xa0, 0x7f, 0x77, 0xff, - 0xc6, 0xe3, 0x9c, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0xa0, 0x7f, 0x77, 0xff - }, - {0xea, 0x78, 0x13, 0xc7, 0x7f, 0xfc, 0x33, 0xb6} - }, -}; - - -static const struct dxt_data -dxt3_rgba_data[] = { - { - { - 0x6d, 0xc6, 0x96, 0x77, - 0x6d, 0xc6, 0x96, 0xee, - 0x6d, 0xc6, 0x96, 0xaa, - 0x8c, 0xff, 0xb5, 0x44, - 0x6d, 0xc6, 0x96, 0xff, - 0x6d, 0xc6, 0x96, 0x88, - 0x31, 0x55, 0x5a, 0x66, - 0x6d, 0xc6, 0x96, 0x99, - 0x31, 0x55, 0x5a, 0xbb, - 0x31, 0x55, 0x5a, 0x55, - 0x31, 0x55, 0x5a, 0x11, - 0x6d, 0xc6, 0x96, 0xcc, - 0x6d, 0xc6, 0x96, 0xcc, - 0x6d, 0xc6, 0x96, 0x11, - 0x31, 0x55, 0x5a, 0x44, - 0x31, 0x55, 0x5a, 0x88 - }, - {0xe7, 0x4a, 0x8f, 0x96, 0x5b, 0xc1, 0x1c, 0x84, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a} - }, - { - { - 0xad, 0xeb, 0x73, 0x99, - 0x97, 0xaa, 0x86, 0x66, - 0x6b, 0x28, 0xad, 0x99, - 0xad, 0xeb, 0x73, 0x99, - 0x6b, 0x28, 0xad, 0x22, - 0xad, 0xeb, 0x73, 0xff, - 0x97, 0xaa, 0x86, 0x55, - 0x6b, 0x28, 0xad, 0x55, - 0x6b, 0x28, 0xad, 0x44, - 0xad, 0xeb, 0x73, 0x33, - 0x6b, 0x28, 0xad, 0xee, - 0x6b, 0x28, 0xad, 0x99, - 0x97, 0xaa, 0x86, 0x66, - 0xad, 0xeb, 0x73, 0xbb, - 0x97, 0xaa, 0x86, 0x99, - 0xad, 0xeb, 0x73, 0xbb - }, - {0x69, 0x99, 0xf2, 0x55, 0x34, 0x9e, 0xb6, 0xb9, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22} - }, - { - { - 0x63, 0xd7, 0xd6, 0x00, - 0x57, 0x62, 0x5d, 0xdd, - 0x57, 0x62, 0x5d, 0xcc, - 0x57, 0x62, 0x5d, 0xbb, - 0x52, 0x28, 0x21, 0xaa, - 0x57, 0x62, 0x5d, 0xcc, - 0x57, 0x62, 0x5d, 0xcc, - 0x57, 0x62, 0x5d, 0x66, - 0x57, 0x62, 0x5d, 0x22, - 0x57, 0x62, 0x5d, 0xdd, - 0x63, 0xd7, 0xd6, 0xee, - 0x57, 0x62, 0x5d, 0x33, - 0x63, 0xd7, 0xd6, 0x55, - 0x52, 0x28, 0x21, 0x55, - 0x57, 0x62, 0x5d, 0x11, - 0x5d, 0x9c, 0x99, 0xee - }, - {0xd0, 0xbc, 0xca, 0x6c, 0xd2, 0x3e, 0x55, 0xe1, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4} - }, - { - { - 0x94, 0x6f, 0x60, 0x22, - 0x94, 0x6f, 0x60, 0x22, - 0xc5, 0xab, 0x76, 0x11, - 0xc5, 0xab, 0x76, 0xee, - 0x63, 0x34, 0x4a, 0xdd, - 0x63, 0x34, 0x4a, 0x33, - 0x94, 0x6f, 0x60, 0x77, - 0xf7, 0xe7, 0x8c, 0x00, - 0x94, 0x6f, 0x60, 0x33, - 0x63, 0x34, 0x4a, 0xaa, - 0x94, 0x6f, 0x60, 0x77, - 0x63, 0x34, 0x4a, 0xcc, - 0x94, 0x6f, 0x60, 0xaa, - 0xf7, 0xe7, 0x8c, 0x99, - 0x63, 0x34, 0x4a, 0x44, - 0xc5, 0xab, 0x76, 0xaa - }, - {0x22, 0xe1, 0x3d, 0x07, 0xa3, 0xc7, 0x9a, 0xa4, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93} - }, -}; - - -static const struct dxt_data -dxt5_rgba_data[] = { - { - { - 0x6d, 0xc6, 0x96, 0x74, - 0x6d, 0xc6, 0x96, 0xf8, - 0x6d, 0xc6, 0x96, 0xb6, - 0x8c, 0xff, 0xb5, 0x53, - 0x6d, 0xc6, 0x96, 0xf8, - 0x6d, 0xc6, 0x96, 0x95, - 0x31, 0x55, 0x5a, 0x53, - 0x6d, 0xc6, 0x96, 0x95, - 0x31, 0x55, 0x5a, 0xb6, - 0x31, 0x55, 0x5a, 0x53, - 0x31, 0x55, 0x5a, 0x11, - 0x6d, 0xc6, 0x96, 0xd7, - 0x6d, 0xc6, 0x96, 0xb6, - 0x6d, 0xc6, 0x96, 0x11, - 0x31, 0x55, 0x5a, 0x32, - 0x31, 0x55, 0x5a, 0x95 - }, - {0xf8, 0x11, 0xc5, 0x0c, 0x9a, 0x73, 0xb4, 0x9c, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a} - }, - { - { - 0xad, 0xeb, 0x73, 0xa1, - 0x97, 0xaa, 0x86, 0x65, - 0x6b, 0x28, 0xad, 0xa1, - 0xad, 0xeb, 0x73, 0xa1, - 0x6b, 0x28, 0xad, 0x2a, - 0xad, 0xeb, 0x73, 0xfb, - 0x97, 0xaa, 0x86, 0x47, - 0x6b, 0x28, 0xad, 0x65, - 0x6b, 0x28, 0xad, 0x47, - 0xad, 0xeb, 0x73, 0x47, - 0x6b, 0x28, 0xad, 0xdd, - 0x6b, 0x28, 0xad, 0xa1, - 0x97, 0xaa, 0x86, 0x65, - 0xad, 0xeb, 0x73, 0xbf, - 0x97, 0xaa, 0x86, 0xa1, - 0xad, 0xeb, 0x73, 0xbf - }, - {0xfb, 0x2a, 0x34, 0x19, 0xdc, 0xbf, 0xe8, 0x71, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22} - }, - { - { - 0x63, 0xd7, 0xd6, 0x00, - 0x57, 0x62, 0x5d, 0xf5, - 0x57, 0x62, 0x5d, 0xd2, - 0x57, 0x62, 0x5d, 0xaf, - 0x52, 0x28, 0x21, 0xaf, - 0x57, 0x62, 0x5d, 0xd2, - 0x57, 0x62, 0x5d, 0xd2, - 0x57, 0x62, 0x5d, 0x69, - 0x57, 0x62, 0x5d, 0x23, - 0x57, 0x62, 0x5d, 0xd2, - 0x63, 0xd7, 0xd6, 0xf5, - 0x57, 0x62, 0x5d, 0x46, - 0x63, 0xd7, 0xd6, 0x46, - 0x52, 0x28, 0x21, 0x69, - 0x57, 0x62, 0x5d, 0x23, - 0x5d, 0x9c, 0x99, 0xf5 - }, - {0xf5, 0x00, 0x81, 0x36, 0xa9, 0x17, 0xec, 0x1e, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4} - }, - { - { - 0x94, 0x6f, 0x60, 0x25, - 0x94, 0x6f, 0x60, 0x25, - 0xc5, 0xab, 0x76, 0x05, - 0xc5, 0xab, 0x76, 0xe8, - 0x63, 0x34, 0x4a, 0xe8, - 0x63, 0x34, 0x4a, 0x25, - 0x94, 0x6f, 0x60, 0x86, - 0xf7, 0xe7, 0x8c, 0x05, - 0x94, 0x6f, 0x60, 0x25, - 0x63, 0x34, 0x4a, 0xa7, - 0x94, 0x6f, 0x60, 0x66, - 0x63, 0x34, 0x4a, 0xc7, - 0x94, 0x6f, 0x60, 0xa7, - 0xf7, 0xe7, 0x8c, 0xa7, - 0x63, 0x34, 0x4a, 0x45, - 0xc5, 0xab, 0x76, 0xa7 - }, - {0xe8, 0x05, 0x7f, 0x80, 0x33, 0x5f, 0xb5, 0x79, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93} - }, -}; - - -static INLINE void -st_sample_dxt_pixel_block(enum pipe_format format, - uint8_t *raw, - float *rgba, unsigned rgba_stride, - unsigned w, unsigned h) -{ - const struct dxt_data *data; - unsigned n; - unsigned i; - unsigned x, y, ch; - - switch(format) { - case PIPE_FORMAT_DXT1_RGB: - data = dxt1_rgb_data; - n = sizeof(dxt1_rgb_data)/sizeof(dxt1_rgb_data[0]); - break; - case PIPE_FORMAT_DXT1_RGBA: - data = dxt1_rgba_data; - n = sizeof(dxt1_rgba_data)/sizeof(dxt1_rgba_data[0]); - break; - case PIPE_FORMAT_DXT3_RGBA: - data = dxt3_rgba_data; - n = sizeof(dxt3_rgba_data)/sizeof(dxt3_rgba_data[0]); - break; - case PIPE_FORMAT_DXT5_RGBA: - data = dxt5_rgba_data; - n = sizeof(dxt5_rgba_data)/sizeof(dxt5_rgba_data[0]); - break; - default: - assert(0); - return; - } - - i = st_random() % n; - - for(y = 0; y < h; ++y) - for(x = 0; x < w; ++x) - for(ch = 0; ch < 4; ++ch) - rgba[y*rgba_stride + x*4 + ch] = (float)(data[i].rgba[y*4*4 + x*4 + ch])/255.0f; - - memcpy(raw, data[i].raw, util_format_get_blocksize(format)); -} - - -static INLINE void -st_sample_generic_pixel_block(enum pipe_format format, - uint8_t *raw, - float *rgba, unsigned rgba_stride, - unsigned w, unsigned h, - boolean norm) -{ - unsigned i; - unsigned x, y, ch; - int blocksize = util_format_get_blocksize(format); - - if (norm) { - for (y = 0; y < h; ++y) { - for (x = 0; x < w; ++x) { - for (ch = 0; ch < 4; ++ch) { - unsigned offset = y*rgba_stride + x*4 + ch; - rgba[offset] = (st_random() & 0xff) / (double)0xff; - } - } - } - - util_format_write_4f(format, - rgba, rgba_stride * sizeof(float), - raw, util_format_get_stride(format, w), - 0, 0, w, h); - - } else { - for (i = 0; i < blocksize; ++i) - raw[i] = (uint8_t)st_random(); - } - - util_format_read_4f(format, - rgba, rgba_stride * sizeof(float), - raw, util_format_get_stride(format, w), - 0, 0, w, h); - - if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) { - for (y = 0; y < h; ++y) { - for (x = 0; x < w; ++x) { - for (ch = 0; ch < 4; ++ch) { - unsigned offset = y*rgba_stride + x*4 + ch; - rgba[offset] = CLAMP(rgba[offset], 0.0f, 1.0f); - } - } - } - } -} - - -/** - * Randomly sample pixels. - */ -void -st_sample_pixel_block(enum pipe_format format, - void *raw, - float *rgba, unsigned rgba_stride, - unsigned w, unsigned h, - boolean norm) -{ - switch(format) { - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - case PIPE_FORMAT_DXT3_RGBA: - case PIPE_FORMAT_DXT5_RGBA: - st_sample_dxt_pixel_block(format, raw, rgba, rgba_stride, w, h); - break; - - default: - st_sample_generic_pixel_block(format, raw, rgba, rgba_stride, w, h, norm); - break; - } -} - - -void -st_sample_surface(struct pipe_context *pipe, - struct st_surface *surface, - float *rgba, - boolean norm) -{ - struct pipe_resource *texture = surface->texture; - unsigned width = u_minify(texture->width0, surface->level); - unsigned height = u_minify(texture->height0, surface->level); - uint rgba_stride = width * 4; - struct pipe_transfer *transfer; - void *raw; - - transfer = pipe_get_transfer(pipe, - surface->texture, - surface->level, - surface->layer, - PIPE_TRANSFER_WRITE, - 0, 0, - width, - height); - if (!transfer) - return; - - raw = pipe->transfer_map(pipe, transfer); - if (raw) { - enum pipe_format format = texture->format; - uint x, y; - int nblocksx = util_format_get_nblocksx(format, width); - int nblocksy = util_format_get_nblocksy(format, height); - int blockwidth = util_format_get_blockwidth(format); - int blockheight = util_format_get_blockheight(format); - int blocksize = util_format_get_blocksize(format); - - - for (y = 0; y < nblocksy; ++y) { - for (x = 0; x < nblocksx; ++x) { - st_sample_pixel_block(format, - (uint8_t *) raw + y * transfer->stride + x * blocksize, - rgba + y * blockheight * rgba_stride + x * blockwidth * 4, - rgba_stride, - MIN2(blockwidth, width - x*blockwidth), - MIN2(blockheight, height - y*blockheight), - norm); - } - } - - pipe->transfer_unmap(pipe, transfer); - } - - pipe->transfer_destroy(pipe, transfer); -} diff --git a/src/gallium/state_trackers/python/st_sample.h b/src/gallium/state_trackers/python/st_sample.h deleted file mode 100644 index 2fdbb391f36..00000000000 --- a/src/gallium/state_trackers/python/st_sample.h +++ /dev/null @@ -1,53 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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 ST_SAMPLE_H_ -#define ST_SAMPLE_H_ - - -#include "pipe/p_format.h" - -struct pipe_context; -struct st_surface; - - -void -st_sample_pixel_block(enum pipe_format format, - void *raw, - float *rgba, unsigned rgba_stride, - unsigned w, unsigned h, - boolean norm); - -void -st_sample_surface(struct pipe_context *pipe, - struct st_surface *surface, - float *rgba, - boolean norm); - - -#endif /* ST_SAMPLE_H_ */ diff --git a/src/gallium/state_trackers/python/st_softpipe_winsys.c b/src/gallium/state_trackers/python/st_softpipe_winsys.c deleted file mode 100644 index 8584bad4679..00000000000 --- a/src/gallium/state_trackers/python/st_softpipe_winsys.c +++ /dev/null @@ -1,78 +0,0 @@ -/************************************************************************** - * - * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA - * 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 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * - **************************************************************************/ - -#include "util/u_debug.h" -#include "softpipe/sp_public.h" -#include "llvmpipe/lp_public.h" -#include "state_tracker/sw_winsys.h" -#include "sw/null/null_sw_winsys.h" -#include "st_winsys.h" - - -struct pipe_screen * -st_software_screen_create(const char *driver) -{ - struct sw_winsys *ws; - struct pipe_screen *screen = NULL; - - if (!driver) { - const char *default_driver; - -#if defined(HAVE_LLVMPIPE) - default_driver = "llvmpipe"; -#elif defined(HAVE_SOFTPIPE) - default_driver = "softpipe"; -#else - default_driver = ""; -#endif - - driver = debug_get_option("GALLIUM_DRIVER", default_driver); - } - - ws = null_sw_create(); - if(!ws) - return NULL; - -#ifdef HAVE_LLVMPIPE - if (strcmp(driver, "llvmpipe") == 0) { - screen = llvmpipe_create_screen(ws); - } -#endif - -#ifdef HAVE_SOFTPIPE - if (strcmp(driver, "softpipe") == 0) { - screen = softpipe_create_screen(ws); - } -#endif - - if (!screen) { - ws->destroy(ws); - } - - return screen; -} diff --git a/src/gallium/state_trackers/python/st_winsys.h b/src/gallium/state_trackers/python/st_winsys.h deleted file mode 100644 index 7d4066d947b..00000000000 --- a/src/gallium/state_trackers/python/st_winsys.h +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************************************** - * - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * 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 TUNGSTEN GRAPHICS 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 ST_WINSYS_H_ -#define ST_WINSYS_H_ - - -struct pipe_screen; - - -struct pipe_screen * -st_hardware_screen_create(void); - -struct pipe_screen * -st_software_screen_create(const char *driver); - - -#endif /* ST_WINSYS_H_ */ diff --git a/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png b/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png Binary files differdeleted file mode 100644 index c947a7b8813..00000000000 --- a/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png +++ /dev/null diff --git a/src/gallium/state_trackers/python/u_format.i b/src/gallium/state_trackers/python/u_format.i deleted file mode 100644 index 2184b420843..00000000000 --- a/src/gallium/state_trackers/python/u_format.i +++ /dev/null @@ -1,88 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 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 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 - * THE COPYRIGHT HOLDERS, AUTHORS 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. - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - **************************************************************************/ - - -static INLINE const char * -util_format_name(enum pipe_format format); - -static INLINE boolean -util_format_is_s3tc(enum pipe_format format); - -static INLINE boolean -util_format_is_depth_or_stencil(enum pipe_format format); - -static INLINE boolean -util_format_is_depth_and_stencil(enum pipe_format format); - - -uint -util_format_get_blocksizebits(enum pipe_format format); - -uint -util_format_get_blocksize(enum pipe_format format); - -uint -util_format_get_blockwidth(enum pipe_format format); - -uint -util_format_get_blockheight(enum pipe_format format); - -unsigned -util_format_get_nblocksx(enum pipe_format format, - unsigned x); - -unsigned -util_format_get_nblocksy(enum pipe_format format, - unsigned y); - -unsigned -util_format_get_nblocks(enum pipe_format format, - unsigned width, - unsigned height); - -size_t -util_format_get_stride(enum pipe_format format, - unsigned width); - -size_t -util_format_get_2d_size(enum pipe_format format, - size_t stride, - unsigned height); - -uint -util_format_get_component_bits(enum pipe_format format, - enum util_format_colorspace colorspace, - uint component); - -boolean -util_format_has_alpha(enum pipe_format format); - - -unsigned -util_format_get_nr_components(enum pipe_format format); - - diff --git a/src/gallium/state_trackers/vega/shaders_cache.c b/src/gallium/state_trackers/vega/shaders_cache.c index 023996ce2d8..70d860ddc8e 100644 --- a/src/gallium/state_trackers/vega/shaders_cache.c +++ b/src/gallium/state_trackers/vega/shaders_cache.c @@ -229,7 +229,6 @@ combine_shaders(const struct shader_asm_info *shaders[SHADER_STAGES], int num_sh return NULL; p = pipe->create_fs_state(pipe, shader); - ureg_destroy(ureg); if (num_temps >= 1) { for (i = start_temp; i < end_temp; i++) { @@ -237,6 +236,8 @@ combine_shaders(const struct shader_asm_info *shaders[SHADER_STAGES], int num_sh } } + ureg_destroy(ureg); + if (temp) free(temp); if (constant) diff --git a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c index 32636c603dc..fb5d5e8b929 100644 --- a/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c +++ b/src/gallium/state_trackers/wgl/stw_ext_pbuffer.c @@ -52,6 +52,9 @@ wglCreatePbufferARB(HDC _hDC, int useLargest = 0; const struct stw_pixelformat_info *info; struct stw_framebuffer *fb; + DWORD dwExStyle; + DWORD dwStyle; + RECT rect; HWND hWnd; HDC hDC; @@ -113,15 +116,45 @@ wglCreatePbufferARB(HDC _hDC, first = FALSE; } - hWnd = CreateWindowEx(0, + dwExStyle = 0; + dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN; + + if (0) { + /* + * Don't hide the window -- useful for debugging what the application is + * drawing + */ + + dwStyle |= WS_VISIBLE | WS_OVERLAPPEDWINDOW; + } else { + dwStyle |= WS_POPUPWINDOW; + } + + rect.left = 0; + rect.top = 0; + rect.right = rect.left + iWidth; + rect.bottom = rect.top + iHeight; + + /* + * The CreateWindowEx parameters are the total (outside) dimensions of the + * window, which can vary with Windows version and user settings. Use + * AdjustWindowRect to get the required total area for the given client area. + * + * AdjustWindowRectEx does not accept WS_OVERLAPPED style (which is defined + * as 0), which means we need to use some other style instead, e.g., + * WS_OVERLAPPEDWINDOW or WS_POPUPWINDOW as above. + */ + + AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle); + + hWnd = CreateWindowEx(dwExStyle, "wglpbuffer", /* wc.lpszClassName */ - "wglpbuffer", -#if 0 /* Useful for debugging what the application is drawing */ - WS_VISIBLE | -#endif - WS_CLIPSIBLINGS | WS_CLIPCHILDREN, - CW_USEDEFAULT, CW_USEDEFAULT, /* x, y */ - iWidth, iHeight, + NULL, + dwStyle, + CW_USEDEFAULT, /* x */ + CW_USEDEFAULT, /* y */ + rect.right - rect.left, /* width */ + rect.bottom - rect.top, /* height */ NULL, NULL, NULL, @@ -130,6 +163,18 @@ wglCreatePbufferARB(HDC _hDC, return 0; } +#ifdef DEBUG + /* + * Verify the client area size matches the specified size. + */ + + GetClientRect(hWnd, &rect); + assert(rect.left == 0); + assert(rect.top == 0); + assert(rect.right - rect.left == iWidth); + assert(rect.bottom - rect.top == iHeight); +#endif + hDC = GetDC(hWnd); if (!hDC) { return 0; diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c index 733222aa21c..d8b1440a688 100644 --- a/src/gallium/state_trackers/wgl/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c @@ -112,7 +112,7 @@ stw_framebuffer_release( static INLINE void stw_framebuffer_get_size( struct stw_framebuffer *fb ) { - unsigned width, height; + LONG width, height; RECT client_rect; RECT window_rect; POINT client_pos; @@ -126,10 +126,17 @@ stw_framebuffer_get_size( struct stw_framebuffer *fb ) width = client_rect.right - client_rect.left; height = client_rect.bottom - client_rect.top; - if(width < 1) - width = 1; - if(height < 1) - height = 1; + if (width <= 0 || height <= 0) { + /* + * When the window is minimized GetClientRect will return zeros. Simply + * preserve the current window size, until the window is restored or + * maximized again. + */ + + assert(width == 0 && height == 0); + + return; + } if(width != fb->width || height != fb->height) { fb->must_resize = TRUE; @@ -150,13 +157,13 @@ stw_framebuffer_get_size( struct stw_framebuffer *fb ) #if 0 debug_printf("\n"); - debug_printf("%s: client_position = (%i, %i)\n", + debug_printf("%s: client_position = (%li, %li)\n", __FUNCTION__, client_pos.x, client_pos.y); - debug_printf("%s: window_rect = (%i, %i) - (%i, %i)\n", + debug_printf("%s: window_rect = (%li, %li) - (%li, %li)\n", __FUNCTION__, window_rect.left, window_rect.top, window_rect.right, window_rect.bottom); - debug_printf("%s: client_rect = (%i, %i) - (%i, %i)\n", + debug_printf("%s: client_rect = (%li, %li) - (%li, %li)\n", __FUNCTION__, fb->client_rect.left, fb->client_rect.top, fb->client_rect.right, fb->client_rect.bottom); diff --git a/src/gallium/targets/dri-r300/target.c b/src/gallium/targets/dri-r300/target.c index 2ecf3457a76..b48bcad3710 100644 --- a/src/gallium/targets/dri-r300/target.c +++ b/src/gallium/targets/dri-r300/target.c @@ -7,10 +7,10 @@ static struct pipe_screen * create_screen(int fd) { - struct r300_winsys_screen *sws; + struct radeon_winsys *sws; struct pipe_screen *screen; - sws = r300_drm_winsys_screen_create(fd); + sws = radeon_drm_winsys_create(fd); if (!sws) return NULL; diff --git a/src/gallium/targets/egl-static/egl_pipe.c b/src/gallium/targets/egl-static/egl_pipe.c index a33d419e0aa..658c532b404 100644 --- a/src/gallium/targets/egl-static/egl_pipe.c +++ b/src/gallium/targets/egl-static/egl_pipe.c @@ -118,10 +118,10 @@ static struct pipe_screen * pipe_r300_create_screen(int fd) { #if _EGL_PIPE_R300 - struct r300_winsys_screen *sws; + struct radeon_winsys *sws; struct pipe_screen *screen; - sws = r300_drm_winsys_screen_create(fd); + sws = radeon_drm_winsys_create(fd); if (!sws) return NULL; diff --git a/src/gallium/targets/egl/pipe_r300.c b/src/gallium/targets/egl/pipe_r300.c index d84bb92539a..09940f0a194 100644 --- a/src/gallium/targets/egl/pipe_r300.c +++ b/src/gallium/targets/egl/pipe_r300.c @@ -7,10 +7,10 @@ static struct pipe_screen * create_screen(int fd) { - struct r300_winsys_screen *sws; + struct radeon_winsys *sws; struct pipe_screen *screen; - sws = r300_drm_winsys_screen_create(fd); + sws = radeon_drm_winsys_create(fd); if (!sws) return NULL; diff --git a/src/gallium/targets/xorg-radeon/radeon_target.c b/src/gallium/targets/xorg-radeon/radeon_target.c index 5a0a8dc5738..b8410efbd89 100644 --- a/src/gallium/targets/xorg-radeon/radeon_target.c +++ b/src/gallium/targets/xorg-radeon/radeon_target.c @@ -7,10 +7,10 @@ static struct pipe_screen * create_screen(int fd) { - struct r300_winsys_screen *sws; + struct radeon_winsys *sws; struct pipe_screen *screen; - sws = r300_drm_winsys_screen_create(fd); + sws = radeon_drm_winsys_create(fd); if (!sws) return NULL; diff --git a/src/gallium/tests/graw/fragment-shader b/src/gallium/tests/graw/fragment-shader deleted file mode 120000 index c7dd0b7c6b2..00000000000 --- a/src/gallium/tests/graw/fragment-shader +++ /dev/null @@ -1 +0,0 @@ -../python/tests/regress/fragment-shader
\ No newline at end of file diff --git a/src/gallium/tests/graw/fragment-shader/frag-abs.sh b/src/gallium/tests/graw/fragment-shader/frag-abs.sh new file mode 100644 index 00000000000..103d7497f48 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-abs.sh @@ -0,0 +1,13 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { -0.5, -0.4, -0.6, 0.0 } + +ADD TEMP[0], IN[0], IMM[0] +ABS OUT[0], TEMP[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-add.sh b/src/gallium/tests/graw/fragment-shader/frag-add.sh new file mode 100644 index 00000000000..bcb94205963 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-add.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +ADD OUT[0], IN[0], IN[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-cb-1d.sh b/src/gallium/tests/graw/fragment-shader/frag-cb-1d.sh new file mode 100644 index 00000000000..85fb9ea4e7f --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-cb-1d.sh @@ -0,0 +1,13 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR +DCL CONST[1] +DCL CONST[3] +DCL TEMP[0..1] + +ADD TEMP[0], IN[0], CONST[1] +RCP TEMP[1], CONST[3].xxxx +MUL OUT[0], TEMP[0], TEMP[1] + +END diff --git a/src/gallium/tests/python/tests/regress/fragment-shader/frag-cb-2d.sh b/src/gallium/tests/graw/fragment-shader/frag-cb-2d.sh index bbc3a10f9b5..bbc3a10f9b5 100644 --- a/src/gallium/tests/python/tests/regress/fragment-shader/frag-cb-2d.sh +++ b/src/gallium/tests/graw/fragment-shader/frag-cb-2d.sh diff --git a/src/gallium/tests/graw/fragment-shader/frag-dp3.sh b/src/gallium/tests/graw/fragment-shader/frag-dp3.sh new file mode 100644 index 00000000000..b5281975d4a --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-dp3.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DP3 OUT[0], IN[0], IN[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-dp4.sh b/src/gallium/tests/graw/fragment-shader/frag-dp4.sh new file mode 100644 index 00000000000..d59df76e70b --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-dp4.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DP4 OUT[0], IN[0].xyzx, IN[0].xyzx + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-dst.sh b/src/gallium/tests/graw/fragment-shader/frag-dst.sh new file mode 100644 index 00000000000..fbb20fa9f62 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-dst.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DST OUT[0], IN[0], IN[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-ex2.sh b/src/gallium/tests/graw/fragment-shader/frag-ex2.sh new file mode 100644 index 00000000000..b511288f4b6 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-ex2.sh @@ -0,0 +1,11 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +EX2 TEMP[0], IN[0].xxxx +MUL OUT[0], TEMP[0], IN[0] + +END diff --git a/src/gallium/tests/python/tests/regress/fragment-shader/frag-face.sh b/src/gallium/tests/graw/fragment-shader/frag-face.sh index 5745b6a5aba..5745b6a5aba 100644 --- a/src/gallium/tests/python/tests/regress/fragment-shader/frag-face.sh +++ b/src/gallium/tests/graw/fragment-shader/frag-face.sh diff --git a/src/gallium/tests/graw/fragment-shader/frag-flr.sh b/src/gallium/tests/graw/fragment-shader/frag-flr.sh new file mode 100644 index 00000000000..99a2f96103a --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-flr.sh @@ -0,0 +1,15 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { 2.5, 4.0, 2.0, 1.0 } +IMM FLT32 { 0.4, 0.25, 0.5, 1.0 } + +MUL TEMP[0], IN[0], IMM[0] +FLR TEMP[0], TEMP[0] +MUL OUT[0], TEMP[0], IMM[1] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-frc.sh b/src/gallium/tests/graw/fragment-shader/frag-frc.sh new file mode 100644 index 00000000000..a54c2623b0a --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-frc.sh @@ -0,0 +1,13 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { 2.7, 3.1, 4.5, 1.0 } + +MUL TEMP[0], IN[0], IMM[0] +FRC OUT[0], TEMP[0] + +END diff --git a/src/gallium/tests/python/tests/regress/fragment-shader/frag-kil.sh b/src/gallium/tests/graw/fragment-shader/frag-kil.sh index 583b0ca4a4a..583b0ca4a4a 100644 --- a/src/gallium/tests/python/tests/regress/fragment-shader/frag-kil.sh +++ b/src/gallium/tests/graw/fragment-shader/frag-kil.sh diff --git a/src/gallium/tests/graw/fragment-shader/frag-lg2.sh b/src/gallium/tests/graw/fragment-shader/frag-lg2.sh new file mode 100644 index 00000000000..5f5b4be1092 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-lg2.sh @@ -0,0 +1,15 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } +IMM FLT32 { 0.5, 0.0, 0.0, 0.0 } + +ADD TEMP[0], IN[0], IMM[0] +LG2 TEMP[0].x, TEMP[0].xxxx +ADD OUT[0], TEMP[0], IMM[1] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-lit.sh b/src/gallium/tests/graw/fragment-shader/frag-lit.sh new file mode 100644 index 00000000000..6323c4712dc --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-lit.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +LIT OUT[0], IN[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-lrp.sh b/src/gallium/tests/graw/fragment-shader/frag-lrp.sh new file mode 100644 index 00000000000..740809d22e0 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-lrp.sh @@ -0,0 +1,11 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +ABS TEMP[0], IN[0] +LRP OUT[0], TEMP[0], IN[0].xxxx, IN[0].yyyy + +END diff --git a/src/gallium/tests/python/tests/regress/fragment-shader/frag-mad-immx.sh b/src/gallium/tests/graw/fragment-shader/frag-mad-immx.sh index 6b034915769..6b034915769 100644 --- a/src/gallium/tests/python/tests/regress/fragment-shader/frag-mad-immx.sh +++ b/src/gallium/tests/graw/fragment-shader/frag-mad-immx.sh diff --git a/src/gallium/tests/graw/fragment-shader/frag-mad.sh b/src/gallium/tests/graw/fragment-shader/frag-mad.sh new file mode 100644 index 00000000000..413b9dc3916 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-mad.sh @@ -0,0 +1,11 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +IMM FLT32 { 0.5, 0.4, 0.6, 1.0 } +IMM FLT32 { 0.5, 0.4, 0.6, 0.0 } + +MAD OUT[0], IN[0], IMM[0], IMM[1] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-max.sh b/src/gallium/tests/graw/fragment-shader/frag-max.sh new file mode 100644 index 00000000000..b69f2132612 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-max.sh @@ -0,0 +1,10 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +IMM FLT32 { 0.4, 0.4, 0.4, 0.0 } + +MAX OUT[0], IN[0], IMM[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-min.sh b/src/gallium/tests/graw/fragment-shader/frag-min.sh new file mode 100644 index 00000000000..df284f49e71 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-min.sh @@ -0,0 +1,10 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +IMM FLT32 { 0.6, 0.6, 0.6, 1.0 } + +MIN OUT[0], IN[0], IMM[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-mov.sh b/src/gallium/tests/graw/fragment-shader/frag-mov.sh new file mode 100644 index 00000000000..64af72f381b --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-mov.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +MOV OUT[0], IN[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-mul.sh b/src/gallium/tests/graw/fragment-shader/frag-mul.sh new file mode 100644 index 00000000000..bdd0b0026b9 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-mul.sh @@ -0,0 +1,10 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +IMM FLT32 { 0.5, 0.6, 0.7, 1.0 } + +MUL OUT[0], IN[0], IMM[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-rcp.sh b/src/gallium/tests/graw/fragment-shader/frag-rcp.sh new file mode 100644 index 00000000000..f4b611b26ab --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-rcp.sh @@ -0,0 +1,15 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } +IMM FLT32 { 1.5, 0.0, 0.0, 0.0 } + +ADD TEMP[0], IN[0], IMM[0] +RCP TEMP[0].x, TEMP[0].xxxx +SUB OUT[0], TEMP[0], IMM[1] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-rsq.sh b/src/gallium/tests/graw/fragment-shader/frag-rsq.sh new file mode 100644 index 00000000000..d1e9b0b53be --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-rsq.sh @@ -0,0 +1,15 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { 1.0, 0.0, 0.0, 0.0 } +IMM FLT32 { 1.5, 0.0, 0.0, 0.0 } + +ADD TEMP[0], IN[0], IMM[0] +RSQ TEMP[0].x, TEMP[0].xxxx +SUB OUT[0], TEMP[0], IMM[1] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-sge.sh b/src/gallium/tests/graw/fragment-shader/frag-sge.sh new file mode 100644 index 00000000000..1f33fac4727 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-sge.sh @@ -0,0 +1,13 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { 0.6, 0.6, 0.6, 0.0 } + +SGE TEMP[0], IN[0], IMM[0] +MUL OUT[0], IN[0], TEMP[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-slt.sh b/src/gallium/tests/graw/fragment-shader/frag-slt.sh new file mode 100644 index 00000000000..d58b7886a12 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-slt.sh @@ -0,0 +1,13 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { 0.6, 0.6, 0.6, 0.0 } + +SLT TEMP[0], IN[0], IMM[0] +MUL OUT[0], IN[0], TEMP[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-srcmod-abs.sh b/src/gallium/tests/graw/fragment-shader/frag-srcmod-abs.sh new file mode 100644 index 00000000000..ecd19248c64 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-srcmod-abs.sh @@ -0,0 +1,13 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { -0.3, -0.5, -0.4, 0.0 } + +ADD TEMP[0], IN[0], IMM[0] +MOV OUT[0], |TEMP[0]| + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-srcmod-absneg.sh b/src/gallium/tests/graw/fragment-shader/frag-srcmod-absneg.sh new file mode 100644 index 00000000000..c2d99ddd15b --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-srcmod-absneg.sh @@ -0,0 +1,15 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +IMM FLT32 { -0.2, -0.3, -0.4, 0.0 } +IMM FLT32 { -1.0, -1.0, -1.0, -1.0 } + +ADD TEMP[0], IN[0], IMM[0] +MOV TEMP[0], -|TEMP[0]| +MUL OUT[0], TEMP[0], IMM[1] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-srcmod-neg.sh b/src/gallium/tests/graw/fragment-shader/frag-srcmod-neg.sh new file mode 100644 index 00000000000..a08ab6d2dcb --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-srcmod-neg.sh @@ -0,0 +1,11 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +DCL TEMP[0] + +SUB TEMP[0], IN[0], IN[0].yzxw +MOV OUT[0], -TEMP[0] + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-srcmod-swz.sh b/src/gallium/tests/graw/fragment-shader/frag-srcmod-swz.sh new file mode 100644 index 00000000000..6110647d979 --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-srcmod-swz.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +MOV OUT[0], IN[0].yxzw + +END diff --git a/src/gallium/tests/graw/fragment-shader/frag-sub.sh b/src/gallium/tests/graw/fragment-shader/frag-sub.sh new file mode 100644 index 00000000000..673fca139aa --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-sub.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +SUB OUT[0], IN[0], IN[0].yzxw + +END diff --git a/src/gallium/tests/python/tests/regress/fragment-shader/frag-tempx.sh b/src/gallium/tests/graw/fragment-shader/frag-tempx.sh index 81bcad2d65c..81bcad2d65c 100644 --- a/src/gallium/tests/python/tests/regress/fragment-shader/frag-tempx.sh +++ b/src/gallium/tests/graw/fragment-shader/frag-tempx.sh diff --git a/src/gallium/tests/graw/fragment-shader/frag-xpd.sh b/src/gallium/tests/graw/fragment-shader/frag-xpd.sh new file mode 100644 index 00000000000..6ec8b1184cc --- /dev/null +++ b/src/gallium/tests/graw/fragment-shader/frag-xpd.sh @@ -0,0 +1,8 @@ +FRAG + +DCL IN[0], COLOR, LINEAR +DCL OUT[0], COLOR + +XPD OUT[0], IN[0], IN[0].yzxw + +END diff --git a/src/gallium/tests/graw/vertex-shader b/src/gallium/tests/graw/vertex-shader deleted file mode 120000 index 7b216e8ca08..00000000000 --- a/src/gallium/tests/graw/vertex-shader +++ /dev/null @@ -1 +0,0 @@ -../python/tests/regress/vertex-shader
\ No newline at end of file diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-abs.sh b/src/gallium/tests/graw/vertex-shader/vert-abs.sh index 062a48b531e..062a48b531e 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-abs.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-abs.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-add.sh b/src/gallium/tests/graw/vertex-shader/vert-add.sh index 188931ebc8d..188931ebc8d 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-add.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-add.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-arl.sh b/src/gallium/tests/graw/vertex-shader/vert-arl.sh index 0039597f6f0..0039597f6f0 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-arl.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-arl.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-arr.sh b/src/gallium/tests/graw/vertex-shader/vert-arr.sh index fdde4f9ad12..fdde4f9ad12 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-arr.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-arr.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-cb-1d.sh b/src/gallium/tests/graw/vertex-shader/vert-cb-1d.sh index e227917fd3b..e227917fd3b 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-cb-1d.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-cb-1d.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-cb-2d.sh b/src/gallium/tests/graw/vertex-shader/vert-cb-2d.sh index 39768d2dda9..39768d2dda9 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-cb-2d.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-cb-2d.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-dp3.sh b/src/gallium/tests/graw/vertex-shader/vert-dp3.sh index 357e224f696..357e224f696 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-dp3.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-dp3.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-dp4.sh b/src/gallium/tests/graw/vertex-shader/vert-dp4.sh index 14f61066014..14f61066014 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-dp4.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-dp4.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-dst.sh b/src/gallium/tests/graw/vertex-shader/vert-dst.sh index 2d59bd1a0c3..2d59bd1a0c3 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-dst.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-dst.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-ex2.sh b/src/gallium/tests/graw/vertex-shader/vert-ex2.sh index e2383a6b5bd..e2383a6b5bd 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-ex2.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-ex2.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-flr.sh b/src/gallium/tests/graw/vertex-shader/vert-flr.sh index fa24806663b..fa24806663b 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-flr.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-flr.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-frc.sh b/src/gallium/tests/graw/vertex-shader/vert-frc.sh index ff09bfafd0c..ff09bfafd0c 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-frc.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-frc.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-lg2.sh b/src/gallium/tests/graw/vertex-shader/vert-lg2.sh index 876b7ab6608..876b7ab6608 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-lg2.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-lg2.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-lit.sh b/src/gallium/tests/graw/vertex-shader/vert-lit.sh index a2235ff6119..a2235ff6119 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-lit.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-lit.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-lrp.sh b/src/gallium/tests/graw/vertex-shader/vert-lrp.sh index a26ca3b0ec0..a26ca3b0ec0 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-lrp.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-lrp.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-mad.sh b/src/gallium/tests/graw/vertex-shader/vert-mad.sh index caf83a91e48..caf83a91e48 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-mad.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-mad.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-max.sh b/src/gallium/tests/graw/vertex-shader/vert-max.sh index db84a499214..db84a499214 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-max.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-max.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-min.sh b/src/gallium/tests/graw/vertex-shader/vert-min.sh index 63a8c2cf3cd..63a8c2cf3cd 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-min.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-min.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-mov.sh b/src/gallium/tests/graw/vertex-shader/vert-mov.sh index 4c23e3eaadb..4c23e3eaadb 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-mov.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-mov.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-mul.sh b/src/gallium/tests/graw/vertex-shader/vert-mul.sh index a409cd4b21e..a409cd4b21e 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-mul.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-mul.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-rcp.sh b/src/gallium/tests/graw/vertex-shader/vert-rcp.sh index d440e35d9a3..d440e35d9a3 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-rcp.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-rcp.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-rsq.sh b/src/gallium/tests/graw/vertex-shader/vert-rsq.sh index 6fbd53ae0ac..6fbd53ae0ac 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-rsq.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-rsq.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-sge.sh b/src/gallium/tests/graw/vertex-shader/vert-sge.sh index e32a21b6109..e32a21b6109 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-sge.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-sge.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-slt.sh b/src/gallium/tests/graw/vertex-shader/vert-slt.sh index 2af61062922..2af61062922 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-slt.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-slt.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-srcmod-abs.sh b/src/gallium/tests/graw/vertex-shader/vert-srcmod-abs.sh index e768d95049d..e768d95049d 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-srcmod-abs.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-srcmod-abs.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-srcmod-absneg.sh b/src/gallium/tests/graw/vertex-shader/vert-srcmod-absneg.sh index 40ca5d60def..40ca5d60def 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-srcmod-absneg.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-srcmod-absneg.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-srcmod-neg.sh b/src/gallium/tests/graw/vertex-shader/vert-srcmod-neg.sh index 297bc1ee3ed..297bc1ee3ed 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-srcmod-neg.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-srcmod-neg.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-srcmod-swz.sh b/src/gallium/tests/graw/vertex-shader/vert-srcmod-swz.sh index 528f164b9ee..528f164b9ee 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-srcmod-swz.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-srcmod-swz.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-sub.sh b/src/gallium/tests/graw/vertex-shader/vert-sub.sh index 90249abdd38..90249abdd38 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-sub.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-sub.sh diff --git a/src/gallium/tests/python/tests/regress/vertex-shader/vert-xpd.sh b/src/gallium/tests/graw/vertex-shader/vert-xpd.sh index 72b048676fb..72b048676fb 100644 --- a/src/gallium/tests/python/tests/regress/vertex-shader/vert-xpd.sh +++ b/src/gallium/tests/graw/vertex-shader/vert-xpd.sh diff --git a/src/gallium/tests/python/retrace/interpreter.py b/src/gallium/tests/python/retrace/interpreter.py deleted file mode 100755 index 84371223f66..00000000000 --- a/src/gallium/tests/python/retrace/interpreter.py +++ /dev/null @@ -1,733 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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 TUNGSTEN GRAPHICS 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. -# -########################################################################## - - -import sys -import struct - -import gallium -import model -import parse as parser - - -try: - from struct import unpack_from -except ImportError: - def unpack_from(fmt, buf, offset=0): - size = struct.calcsize(fmt) - return struct.unpack(fmt, buf[offset:offset + size]) - - -def make_image(ctx, surface, x=None, y=None, w=None, h=None): - if x is None: - x = 0 - if y is None: - y = 0 - if w is None: - w = surface.width - x - if h is None: - h = surface.height - y - data = ctx.surface_read_rgba8(surface, x, y, surface.width, surface.height) - - import Image - outimage = Image.fromstring('RGBA', (w, h), data, "raw", 'RGBA', 0, 1) - return outimage - -def save_image(ctx, filename, surface, x=None, y=None, w=None, h=None): - outimage = make_image(ctx, surface, x, y, w, h) - outimage.save(filename, "PNG") - -def show_image(ctx, surface, title, x=None, y=None, w=None, h=None): - outimage = make_image(ctx, surface, x, y, w, h) - - import Tkinter as tk - from PIL import Image, ImageTk - root = tk.Tk() - - root.title(title) - - image1 = ImageTk.PhotoImage(outimage) - w = image1.width() - h = image1.height() - x = 100 - y = 100 - root.geometry("%dx%d+%d+%d" % (w, h, x, y)) - panel1 = tk.Label(root, image=image1) - panel1.pack(side='top', fill='both', expand='yes') - panel1.image = image1 - root.mainloop() - - -class Struct: - """C-like struct""" - - # A basic Python class can pass as a C-like structure - pass - - -struct_factories = { - "pipe_blend_color": gallium.BlendColor, - "pipe_blend_state": gallium.Blend, - #"pipe_clip_state": gallium.Clip, - #"pipe_buffer": gallium.Buffer, - "pipe_depth_state": gallium.Depth, - "pipe_stencil_state": gallium.Stencil, - "pipe_alpha_state": gallium.Alpha, - "pipe_depth_stencil_alpha_state": gallium.DepthStencilAlpha, - #"pipe_framebuffer_state": gallium.Framebuffer, - "pipe_poly_stipple": gallium.PolyStipple, - "pipe_rasterizer_state": gallium.Rasterizer, - "pipe_sampler_state": gallium.Sampler, - "pipe_scissor_state": gallium.Scissor, - #"pipe_shader_state": gallium.Shader, - #"pipe_vertex_buffer": gallium.VertexBuffer, - "pipe_vertex_element": gallium.VertexElement, - "pipe_viewport_state": gallium.Viewport, - #"pipe_texture": gallium.Texture, - 'pipe_subresource': gallium.pipe_subresource, - 'pipe_box': gallium.pipe_box, - 'pipe_draw_info': gallium.pipe_draw_info, -} - - -member_array_factories = { - #"pipe_rasterizer_state": {"sprite_coord_mode": gallium.ByteArray}, - "pipe_poly_stipple": {"stipple": gallium.UnsignedArray}, - "pipe_viewport_state": {"scale": gallium.FloatArray, "translate": gallium.FloatArray}, - #"pipe_clip_state": {"ucp": gallium.FloatArray}, - "pipe_depth_stencil_alpha_state": {"stencil": gallium.StencilArray}, - "pipe_blend_color": {"color": gallium.FloatArray}, - "pipe_sampler_state": {"border_color": gallium.FloatArray}, -} - - -class Translator(model.Visitor): - """Translate model arguments into regular Python objects""" - - def __init__(self, interpreter): - self.interpreter = interpreter - self.result = None - - def visit(self, node): - self.result = None - node.visit(self) - return self.result - - def visit_literal(self, node): - self.result = node.value - - def visit_named_constant(self, node): - # lookup the named constant in the gallium module - self.result = getattr(gallium, node.name) - - def visit_array(self, node): - array = [] - for element in node.elements: - array.append(self.visit(element)) - self.result = array - - def visit_struct(self, node): - struct_factory = struct_factories.get(node.name, Struct) - struct = struct_factory() - for member_name, member_node in node.members: - member_value = self.visit(member_node) - try: - array_factory = member_array_factories[node.name][member_name] - except KeyError: - pass - else: - assert isinstance(member_value, list) - array = array_factory(len(member_value)) - for i in range(len(member_value)): - array[i] = member_value[i] - member_value = array - #print node.name, member_name, member_value - assert isinstance(struct, Struct) or hasattr(struct, member_name) - setattr(struct, member_name, member_value) - self.result = struct - - def visit_pointer(self, node): - self.result = self.interpreter.lookup_object(node.address) - - -class Object: - - def __init__(self, interpreter, real): - self.interpreter = interpreter - self.real = real - - -class Global(Object): - - def __init__(self, interpreter, real): - self.interpreter = interpreter - self.real = real - - def pipe_screen_create(self): - real = gallium.Device() - return Screen(self.interpreter, real) - - def pipe_context_create(self, screen): - context = screen.real.context_create() - return Context(self.interpreter, context) - - -class Transfer: - - def __init__(self, resource, usage, subresource, box): - self.resource = resource - self.usage = usage - self.subresource = subresource - self.box = box - - -class Screen(Object): - - def __init__(self, interpreter, real): - Object.__init__(self, interpreter, real) - self.context = self.real.context_create() - - def destroy(self): - pass - - def get_name(self): - pass - - def get_vendor(self): - pass - - def get_param(self, param): - pass - - def get_paramf(self, param): - pass - - def context_create(self): - context = self.real.context_create() - return Context(self.interpreter, context) - - def is_format_supported(self, format, target, sample_count, bind, geom_flags): - return self.real.is_format_supported(format, target, sample_count, bind, geom_flags) - - def resource_create(self, templat): - return self.real.resource_create( - format = templat.format, - width = templat.width, - height = templat.height, - depth = templat.depth, - last_level = templat.last_level, - target = templat.target, - bind = templat.bind, - ) - - def texture_destroy(self, texture): - self.interpreter.unregister_object(texture) - - def texture_release(self, surface): - pass - - def tex_surface_release(self, surface): - pass - - def user_buffer_create(self, data, size, usage): - bind = usage - # We don't really care to distinguish between user and regular buffers - buffer = self.real.buffer_create(size, bind) - assert size == len(data) - self.context.buffer_write(buffer, data) - return buffer - - def buffer_create(self, alignment, usage, size): - return self.real.buffer_create(size, alignment, usage) - - def buffer_destroy(self, buffer): - pass - - def fence_finish(self, fence, flags): - pass - - def fence_reference(self, dst, src): - pass - - def flush_frontbuffer(self, resource): - pass - - -class Context(Object): - - def __init__(self, interpreter, real): - Object.__init__(self, interpreter, real) - self.cbufs = [] - self.zsbuf = None - self.vbufs = [] - self.velems = [] - self.dirty = False - - def destroy(self): - pass - - def create_blend_state(self, state): - if isinstance(state, str): - state = gallium.Blend(state) - sys.stdout.write('\t%s\n' % state) - return state - - def bind_blend_state(self, state): - if state is not None: - self.real.set_blend(state) - - def delete_blend_state(self, state): - pass - - def create_sampler_state(self, state): - return state - - def delete_sampler_state(self, state): - pass - - def bind_vertex_sampler_states(self, num_states, states): - for i in range(num_states): - self.real.set_vertex_sampler(i, states[i]) - - def bind_fragment_sampler_states(self, num_states, states): - for i in range(num_states): - self.real.set_fragment_sampler(i, states[i]) - - def create_rasterizer_state(self, state): - return state - - def bind_rasterizer_state(self, state): - if state is not None: - self.real.set_rasterizer(state) - - def delete_rasterizer_state(self, state): - pass - - def create_depth_stencil_alpha_state(self, state): - return state - - def bind_depth_stencil_alpha_state(self, state): - if state is not None: - self.real.set_depth_stencil_alpha(state) - - def delete_depth_stencil_alpha_state(self, state): - pass - - def create_fs_state(self, state): - tokens = str(state.tokens) - shader = gallium.Shader(tokens) - return shader - - create_vs_state = create_fs_state - - def bind_fs_state(self, state): - self.real.set_fragment_shader(state) - - def bind_vs_state(self, state): - self.real.set_vertex_shader(state) - - def delete_fs_state(self, state): - pass - - delete_vs_state = delete_fs_state - - def set_blend_color(self, state): - self.real.set_blend_color(state) - - def set_stencil_ref(self, state): - self.real.set_stencil_ref(state) - - def set_clip_state(self, state): - _state = gallium.Clip() - _state.nr = state.nr - if state.nr: - # FIXME - ucp = gallium.FloatArray(gallium.PIPE_MAX_CLIP_PLANES*4) - for i in range(len(state.ucp)): - for j in range(len(state.ucp[i])): - ucp[i*4 + j] = state.ucp[i][j] - _state.ucp = ucp - self.real.set_clip(_state) - - def dump_constant_buffer(self, buffer): - if not self.interpreter.verbosity(2): - return - - data = self.real.buffer_read(buffer) - format = '4f' - index = 0 - for offset in range(0, len(data), struct.calcsize(format)): - x, y, z, w = unpack_from(format, data, offset) - sys.stdout.write('\tCONST[%2u] = {%10.4f, %10.4f, %10.4f, %10.4f}\n' % (index, x, y, z, w)) - index += 1 - sys.stdout.flush() - - def set_constant_buffer(self, shader, index, buffer): - if buffer is not None: - self.real.set_constant_buffer(shader, index, buffer) - - self.dump_constant_buffer(buffer) - - def set_framebuffer_state(self, state): - _state = gallium.Framebuffer() - _state.width = state.width - _state.height = state.height - _state.nr_cbufs = state.nr_cbufs - for i in range(len(state.cbufs)): - _state.set_cbuf(i, state.cbufs[i]) - _state.set_zsbuf(state.zsbuf) - self.real.set_framebuffer(_state) - - self.cbufs = state.cbufs - self.zsbuf = state.zsbuf - - def set_polygon_stipple(self, state): - self.real.set_polygon_stipple(state) - - def set_scissor_state(self, state): - self.real.set_scissor(state) - - def set_viewport_state(self, state): - self.real.set_viewport(state) - - def create_sampler_view(self, texture, templ): - return self.real.create_sampler_view(texture, - format = templ.format, - first_level = templ.first_level, - last_level = templ.last_level, - swizzle_r = templ.swizzle_r, - swizzle_g = templ.swizzle_r, - swizzle_b = templ.swizzle_g, - swizzle_a = templ.swizzle_a) - - def sampler_view_destroy(self, view): - pass - - def set_fragment_sampler_views(self, num, views): - for i in range(num): - self.real.set_fragment_sampler_view(i, views[i]) - - def set_vertex_sampler_views(self, num, views): - for i in range(num): - self.real.set_vertex_sampler_view(i, views[i]) - - def set_vertex_buffers(self, num_buffers, buffers): - self.vbufs = buffers[0:num_buffers] - for i in range(num_buffers): - vbuf = buffers[i] - self.real.set_vertex_buffer( - i, - stride = vbuf.stride, - max_index = vbuf.max_index, - buffer_offset = vbuf.buffer_offset, - buffer = vbuf.buffer, - ) - - def create_vertex_elements_state(self, num_elements, elements): - return elements[0:num_elements] - - def bind_vertex_elements_state(self, state): - if state is None: - self.real.set_vertex_elements(0) - return - - elements = state - num_elements = len(elements) - self.velems = elements - for i in range(num_elements): - self.real.set_vertex_element(i, elements[i]) - self.real.set_vertex_elements(num_elements) - - def delete_vertex_elements_state(self, state): - pass - - def dump_vertices(self, start, count): - if not self.interpreter.verbosity(2): - return - - for index in range(start, start + count): - if index >= start + 16: - sys.stdout.write('\t...\n') - break - sys.stdout.write('\t{\n') - for velem in self.velems: - vbuf = self.vbufs[velem.vertex_buffer_index] - - offset = vbuf.buffer_offset + velem.src_offset + vbuf.stride*index - format = { - gallium.PIPE_FORMAT_R32_FLOAT: 'f', - gallium.PIPE_FORMAT_R32G32_FLOAT: '2f', - gallium.PIPE_FORMAT_R32G32B32_FLOAT: '3f', - gallium.PIPE_FORMAT_R32G32B32A32_FLOAT: '4f', - gallium.PIPE_FORMAT_A8R8G8B8_UNORM: '4B', - gallium.PIPE_FORMAT_R8G8B8A8_UNORM: '4B', - gallium.PIPE_FORMAT_B8G8R8A8_UNORM: '4B', - gallium.PIPE_FORMAT_R16G16B16_SNORM: '3h', - }[velem.src_format] - - data = self.real.buffer_read(vbuf.buffer) - values = unpack_from(format, data, offset) - sys.stdout.write('\t\t{' + ', '.join(map(str, values)) + '},\n') - sys.stdout.write('\t},\n') - sys.stdout.flush() - - def dump_indices(self, ibuf, isize, ibias, start, count): - if not self.interpreter.verbosity(2): - return - - format = { - 1: 'B', - 2: 'H', - 4: 'I', - }[isize] - - assert struct.calcsize(format) == isize - - data = self.real.buffer_read(ibuf) - maxindex, minindex = 0, 0xffffffff - - sys.stdout.write('\t{\n') - for i in range(start, start + count): - if i >= start + 16 and not self.interpreter.verbosity(3): - sys.stdout.write('\t...\n') - break - offset = i*isize - index, = unpack_from(format, data, offset) - sys.stdout.write('\t\t%u,\n' % index) - minindex = min(minindex, index) - maxindex = max(maxindex, index) - sys.stdout.write('\t},\n') - sys.stdout.flush() - - return minindex + ibias, maxindex + ibias - - def set_index_buffer(self, ib): - if ib: - self.real.set_index_buffer(ib.index_size, ib.offset, ib.buffer) - else: - self.real.set_index_buffer(0, 0, None) - - def draw_vbo(self, info): - if self.interpreter.verbosity(2): - if 0: - minindex, maxindex = self.dump_indices(indexBuffer, indexSize, indexBias, start, count) - - self.dump_vertices(info.minindex, info.maxindex + 1 - info.minindex) - - self.real.draw_vbo(info) - self._set_dirty() - - def resource_copy_region(self, dst, subdst, dstx, dsty, dstz, src, subsrc, srcx, srcy, srcz, width, height): - if dst is not None and src is not None: - if self.interpreter.options.all: - self.interpreter.present(self.real, src, 'resource_copy_src', srcx, srcy, width, height) - self.real.resource_copy_region(dst, subdst, dstx, dsty, dstx, src, subsrc, srcx, srcy, srcz, width, height) - flags = 0 - self.flush(flags) - if self.interpreter.options.all: - self.interpreter.present(self.real, dst, 'resource_copy_dst', dstx, dsty, width, height) - - def is_resource_referenced(self, texture, face, level): - #return self.real.is_resource_referenced(format, texture, face, level) - pass - - def buffer_write(self, buffer, data, size, offset=0): - assert size == len(data) - self.buffer_write(buffer, data) - - def surface_write(self, surface, data, stride, size): - if surface is None: - return -# assert surface.nblocksy * stride == size - surface.put_tile_raw(0, 0, surface.width, surface.height, data, stride) - - def get_transfer(self, texture, sr, usage, box): - if texture is None: - return None - transfer = Transfer(texture, sr, usage, box) - if transfer and usage & gallium.PIPE_TRANSFER_READ: - if self.interpreter.options.all: - surface = texture.get_surface(sr.face, sr.level, box.z) - self.interpreter.present(self.real, transfer.surface, 'transf_read', box.x, box.y, box.width, box.height) - return transfer - - def tex_transfer_destroy(self, transfer): - self.interpreter.unregister_object(transfer) - - def transfer_inline_write(self, resource, sr, usage, box, stride, slice_stride, data): - self.real.transfer_inline_write(resource, sr, usage, box, data, stride, slice_stride) - if self.interpreter.options.all: - for z in range(box.z, box.z + box.depth): - surface = resource.get_surface(sr.face, sr.level, box.z) - self.interpreter.present(self.real, surface, 'transf_inline_write%u' % z, box.x, box.y, box.width, box.height) - - def _set_dirty(self): - if self.interpreter.options.step: - self._present() - else: - self.dirty = True - - def flush(self, flags): - self.real.flush(flags) - if self.dirty: - if flags & gallium.PIPE_FLUSH_FRAME: - self._present() - self.dirty = False - return None - - def clear(self, buffers, rgba, depth, stencil): - _rgba = gallium.FloatArray(4) - for i in range(4): - _rgba[i] = rgba[i] - self.real.clear(buffers, _rgba, depth, stencil) - - def clear_render_target(self, dst, rgba, dstx, dsty, width, height): - _rgba = gallium.FloatArray(4) - for i in range(4): - _rgba[i] = rgba[i] - self.real.clear_render_target(dst, _rgba, dstx, dsty, width, height) - - def clear_depth_stencil(self, dst, clear_flags, depth, stencil, dstx, dsty, width, height): - self.real.clear_depth_stencil(dst, clear_flags, depth, stencil, dstx, dsty, width, height) - - def _present(self): - self.real.flush() - - if self.cbufs and self.cbufs[0]: - self.interpreter.present(self.real, self.cbufs[0], "cbuf") - if self.zsbuf: - if self.interpreter.options.all: - self.interpreter.present(self.real, self.zsbuf, "zsbuf") - def create_surface(self, texture, level, layer, usage): - if texture is None: - return None - return texture.get_surface(level, layer) - - def surface_destroy(self, surface): - self.interpreter.unregister_object(surface) - -class Interpreter(parser.TraceDumper): - - ignore_calls = set(( - ('pipe_screen', 'is_format_supported'), - ('pipe_screen', 'get_param'), - ('pipe_screen', 'get_paramf'), - )) - - def __init__(self, stream, options): - parser.TraceDumper.__init__(self, stream) - self.options = options - self.objects = {} - self.result = None - self.globl = Global(self, None) - self.call_no = None - - def register_object(self, address, object): - self.objects[address] = object - - def unregister_object(self, object): - # FIXME: - pass - - def lookup_object(self, address): - return self.objects[address] - - def interpret(self, trace): - for call in trace.calls: - self.interpret_call(call) - - def handle_call(self, call): - if self.options.stop and call.no > self.options.stop: - sys.exit(0) - - if (call.klass, call.method) in self.ignore_calls: - return - - self.call_no = call.no - - if self.verbosity(1): - parser.TraceDumper.handle_call(self, call) - sys.stdout.flush() - - args = [(str(name), self.interpret_arg(arg)) for name, arg in call.args] - - if call.klass: - name, obj = args[0] - args = args[1:] - else: - obj = self.globl - - method = getattr(obj, call.method) - ret = method(**dict(args)) - - if call.ret and isinstance(call.ret, model.Pointer): - if ret is None: - sys.stderr.write('warning: NULL returned\n') - self.register_object(call.ret.address, ret) - - self.call_no = None - - def interpret_arg(self, node): - translator = Translator(self) - return translator.visit(node) - - def verbosity(self, level): - return self.options.verbosity >= level - - def present(self, ctx, surface, description, x=None, y=None, w=None, h=None): - if self.call_no < self.options.start: - return - - if self.options.images: - filename = '%04u_%s.png' % (self.call_no, description) - save_image(ctx, filename, surface, x, y, w, h) - else: - title = '%u. %s' % (self.call_no, description) - show_image(ctx, surface, title, x, y, w, h) - - -class Main(parser.Main): - - def get_optparser(self): - optparser = parser.Main.get_optparser(self) - optparser.add_option("-q", "--quiet", action="store_const", const=0, dest="verbosity", help="no messages") - optparser.add_option("-v", "--verbose", action="count", dest="verbosity", default=1, help="increase verbosity level") - optparser.add_option("-i", "--images", action="store_true", dest="images", default=False, help="save images instead of showing them") - optparser.add_option("-a", "--all", action="store_true", dest="all", default=False, help="show depth, stencil, and transfers") - optparser.add_option("-s", "--step", action="store_true", dest="step", default=False, help="step trhough every draw") - optparser.add_option("-f", "--from", action="store", type="int", dest="start", default=0, help="from call no") - optparser.add_option("-t", "--to", action="store", type="int", dest="stop", default=0, help="until call no") - return optparser - - def process_arg(self, stream, options): - parser = Interpreter(stream, options) - parser.parse() - - -if __name__ == '__main__': - Main().main() diff --git a/src/gallium/tests/python/tests/surface_copy.py b/src/gallium/tests/python/tests/surface_copy.py deleted file mode 100755 index 7a6ede38044..00000000000 --- a/src/gallium/tests/python/tests/surface_copy.py +++ /dev/null @@ -1,201 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# 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 -# 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. -# -########################################################################## - - -import os -import random - -from gallium import * -from base import * - - -def lods(*dims): - size = max(dims) - lods = 0 - while size: - lods += 1 - size >>= 1 - return lods - - -class TextureTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - ctx = self.ctx - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - - bind = PIPE_BIND_SAMPLER_VIEW - geom_flags = 0 - sample_count = 0 - if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): - raise TestSkip - - if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): - raise TestSkip - - # textures - dst_texture = dev.resource_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - bind = bind, - ) - - dst_surface = dst_texture.get_surface(face = face, level = level, zslice = zslice) - - src_texture = dev.resource_create( - target = target, - format = format, - width = dst_surface.width, - height = dst_surface.height, - depth = 1, - last_level = 0, - bind = PIPE_BIND_SAMPLER_VIEW, - ) - - src_surface = src_texture.get_surface() - - w = dst_surface.width - h = dst_surface.height - - stride = util_format_get_stride(format, w) - size = util_format_get_nblocksy(format, h) * stride - src_raw = os.urandom(size) - - ctx.surface_write_raw(src_surface, 0, 0, w, h, src_raw, stride) - - ctx.surface_copy(dst_surface, 0, 0, - src_surface, 0, 0, w, h) - - dst_raw = ctx.surface_read_raw(dst_surface, 0, 0, w, h) - - if dst_raw != src_raw: - raise TestFailure - - -def main(): - dev = Device() - ctx = dev.context_create() - suite = TestSuite() - - targets = [ - PIPE_TEXTURE_2D, - PIPE_TEXTURE_CUBE, - PIPE_TEXTURE_3D, - ] - - sizes = [64, 32, 16, 8, 4, 2, 1] - #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] - #sizes = [64] - #sizes = [63] - - faces = [ - PIPE_TEX_FACE_POS_X, - PIPE_TEX_FACE_NEG_X, - PIPE_TEX_FACE_POS_Y, - PIPE_TEX_FACE_NEG_Y, - PIPE_TEX_FACE_POS_Z, - PIPE_TEX_FACE_NEG_Z, - ] - - try: - n = int(sys.argv[1]) - except: - n = 10000 - - for i in range(n): - format = random.choice(formats.keys()) - if not util_format_is_depth_or_stencil(format): - is_depth_or_stencil = util_format_is_depth_or_stencil(format) - - if is_depth_or_stencil: - target = PIPE_TEXTURE_2D - else: - target = random.choice(targets) - - size = random.choice(sizes) - - if target == PIPE_TEXTURE_3D: - depth = size - else: - depth = 1 - - if target == PIPE_TEXTURE_CUBE: - face = random.choice(faces) - else: - face = PIPE_TEX_FACE_POS_X - - levels = lods(size) - last_level = random.randint(0, levels - 1) - level = random.randint(0, last_level) - zslice = random.randint(0, max(depth >> level, 1) - 1) - - test = TextureTest( - dev = dev, - ctx = ctx, - target = target, - format = format, - width = size, - height = size, - depth = depth, - last_level = last_level, - face = face, - level = level, - zslice = zslice, - ) - suite.add_test(test) - suite.run() - - -if __name__ == '__main__': - main() diff --git a/src/gallium/tests/python/tests/texture_blit.py b/src/gallium/tests/python/tests/texture_blit.py deleted file mode 100755 index 089d05c6237..00000000000 --- a/src/gallium/tests/python/tests/texture_blit.py +++ /dev/null @@ -1,638 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2009 VMware, Inc. -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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. -# -########################################################################## - - -import random - -from gallium import * -from base import * - - -def lods(*dims): - size = max(dims) - lods = 0 - while size: - lods += 1 - size >>= 1 - return lods - - -def minify(dims, level = 1): - return [max(dim>>level, 1) for dim in dims] - - -def tex_coords(texture, face, level, zslice): - st = [ - [0.0, 0.0], - [1.0, 0.0], - [1.0, 1.0], - [0.0, 1.0], - ] - - if texture.target == PIPE_TEXTURE_2D or texture.target == PIPE_TEXTURE_RECT: - return [[s, t, 0.0] for s, t in st] - elif texture.target == PIPE_TEXTURE_3D: - depth = texture.get_depth(level) - if depth > 1: - r = float(zslice)/float(depth - 1) - else: - r = 0.0 - return [[s, t, r] for s, t in st] - elif texture.target == PIPE_TEXTURE_CUBE: - result = [] - for s, t in st: - # See http://developer.nvidia.com/object/cube_map_ogl_tutorial.html - sc = 2.0*s - 1.0 - tc = 2.0*t - 1.0 - if face == PIPE_TEX_FACE_POS_X: - rx = 1.0 - ry = -tc - rz = -sc - if face == PIPE_TEX_FACE_NEG_X: - rx = -1.0 - ry = -tc - rz = sc - if face == PIPE_TEX_FACE_POS_Y: - rx = sc - ry = 1.0 - rz = tc - if face == PIPE_TEX_FACE_NEG_Y: - rx = sc - ry = -1.0 - rz = -tc - if face == PIPE_TEX_FACE_POS_Z: - rx = sc - ry = -tc - rz = 1.0 - if face == PIPE_TEX_FACE_NEG_Z: - rx = -sc - ry = -tc - rz = -1.0 - result.append([rx, ry, rz]) - return result - -def is_pot(n): - return n & (n - 1) == 0 - - -class TextureColorSampleTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - ctx = self.ctx - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - minz = 0.0 - maxz = 1.0 - - bind = PIPE_BIND_SAMPLER_VIEW - geom_flags = 0 - sample_count = 0 - if width != height: - geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE - if not is_pot(width) or not is_pot(height) or not is_pot(depth): - geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO - - if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): - raise TestSkip - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # no-op depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - ctx.set_rasterizer(rasterizer) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - sampler.min_lod = 0 - sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 - ctx.set_fragment_sampler(0, sampler) - - # texture - texture = dev.resource_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - bind = bind, - ) - - expected_rgba = FloatArray(height*width*4) - surface = texture.get_surface( - face = face, - level = level, - zslice = zslice, - ) - - ctx.surface_sample_rgba(surface, expected_rgba, True) - - ctx.set_fragment_sampler_texture(0, texture) - - # viewport - viewport = Viewport() - scale = FloatArray(4) - scale[0] = width - scale[1] = height - scale[2] = (maxz - minz) / 2.0 - scale[3] = 1.0 - viewport.scale = scale - translate = FloatArray(4) - translate[0] = 0.0 - translate[1] = 0.0 - translate[2] = (maxz - minz) / 2.0 - translate[3] = 0.0 - viewport.translate = translate - ctx.set_viewport(viewport) - - # scissor - scissor = Scissor() - scissor.minx = 0 - scissor.miny = 0 - scissor.maxx = width - scissor.maxy = height - ctx.set_scissor(scissor) - - # clip - clip = Clip() - clip.nr = 0 - ctx.set_clip(clip) - - # framebuffer - cbuf_tex = dev.resource_create( - PIPE_FORMAT_B8G8R8A8_UNORM, - width, - height, - bind = PIPE_BIND_RENDER_TARGET, - ) - - cbuf = cbuf_tex.get_surface() - fb = Framebuffer() - fb.width = width - fb.height = height - fb.nr_cbufs = 1 - fb.set_cbuf(0, cbuf) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.5 - rgba[1] = 0.5 - rgba[2] = 0.5 - rgba[3] = 0.5 - ctx.clear(PIPE_CLEAR_COLOR, rgba, 0.0, 0) - del fb - - # vertex shader - vs = Shader(''' - VERT - DCL IN[0], POSITION, CONSTANT - DCL IN[1], GENERIC, CONSTANT - DCL OUT[0], POSITION, CONSTANT - DCL OUT[1], GENERIC, CONSTANT - 0:MOV OUT[0], IN[0] - 1:MOV OUT[1], IN[1] - 2:END - ''') - #vs.dump() - ctx.set_vertex_shader(vs) - - # fragment shader - op = { - PIPE_TEXTURE_1D: "1D", - PIPE_TEXTURE_2D: "2D", - PIPE_TEXTURE_3D: "3D", - PIPE_TEXTURE_CUBE: "CUBE", - }[target] - fs = Shader(''' - FRAG - DCL IN[0], GENERIC[0], LINEAR - DCL OUT[0], COLOR, CONSTANT - DCL SAMP[0], CONSTANT - 0:TEX OUT[0], IN[0], SAMP[0], %s - 1:END - ''' % op) - #fs.dump() - ctx.set_fragment_shader(fs) - - nverts = 4 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - x = 0 - y = 0 - w, h = minify((width, height), level) - - pos = [ - [x, y], - [x+w, y], - [x+w, y+h], - [x, y+h], - ] - - tex = tex_coords(texture, face, level, zslice) - - for i in range(0, 4): - j = 8*i - verts[j + 0] = pos[i][0]/float(width) # x - verts[j + 1] = pos[i][1]/float(height) # y - verts[j + 2] = 0.0 # z - verts[j + 3] = 1.0 # w - verts[j + 4] = tex[i][0] # s - verts[j + 5] = tex[i][1] # r - verts[j + 6] = tex[i][2] # q - verts[j + 7] = 1.0 - - ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, - nverts, - nattrs, - verts) - - ctx.flush() - - cbuf = cbuf_tex.get_surface() - - self.assert_rgba(ctx, cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85) - - -class TextureDepthSampleTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - ctx = self.ctx - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - minz = 0.0 - maxz = 1.0 - - bind = PIPE_BIND_SAMPLER_VIEW - geom_flags = 0 - sample_count = 0 - if width != height: - geom_flags |= PIPE_TEXTURE_GEOM_NON_SQUARE - if not is_pot(width) or not is_pot(height) or not is_pot(depth): - geom_flags |= PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO - - if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): - raise TestSkip - - # disabled blending/masking - blend = Blend() - blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE - blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO - blend.rt[0].colormask = PIPE_MASK_RGBA - ctx.set_blend(blend) - - # depth/stencil/alpha - depth_stencil_alpha = DepthStencilAlpha() - depth_stencil_alpha.depth.enabled = 1 - depth_stencil_alpha.depth.writemask = 1 - depth_stencil_alpha.depth.func = PIPE_FUNC_LESS - ctx.set_depth_stencil_alpha(depth_stencil_alpha) - - # rasterizer - rasterizer = Rasterizer() - rasterizer.front_winding = PIPE_WINDING_CW - rasterizer.cull_mode = PIPE_WINDING_NONE - ctx.set_rasterizer(rasterizer) - - # viewport - viewport = Viewport() - scale = FloatArray(4) - scale[0] = width - scale[1] = height - scale[2] = (maxz - minz) / 2.0 - scale[3] = 1.0 - viewport.scale = scale - translate = FloatArray(4) - translate[0] = 0.0 - translate[1] = 0.0 - translate[2] = (maxz - minz) / 2.0 - translate[3] = 0.0 - viewport.translate = translate - ctx.set_viewport(viewport) - - # samplers - sampler = Sampler() - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE - sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST - sampler.normalized_coords = 1 - sampler.min_lod = 0 - sampler.max_lod = PIPE_MAX_TEXTURE_LEVELS - 1 - ctx.set_fragment_sampler(0, sampler) - - # texture - texture = dev.resource_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - bind = bind, - ) - - expected_rgba = FloatArray(height*width*4) - surface = texture.get_surface( - face = face, - level = level, - zslice = zslice, - ) - - ctx.surface_sample_rgba(surface, expected_rgba, True) - - ctx.set_fragment_sampler_texture(0, texture) - - # scissor - scissor = Scissor() - scissor.minx = 0 - scissor.miny = 0 - scissor.maxx = width - scissor.maxy = height - ctx.set_scissor(scissor) - - # clip - clip = Clip() - clip.nr = 0 - ctx.set_clip(clip) - - # framebuffer - cbuf_tex = dev.resource_create( - PIPE_FORMAT_B8G8R8A8_UNORM, - width, - height, - bind = PIPE_BIND_RENDER_TARGET, - ) - - zsbuf_tex = dev.resource_create( - PIPE_FORMAT_X8Z24_UNORM, - width, - height, - bind = PIPE_BIND_RENDER_TARGET, - ) - - cbuf = cbuf_tex.get_surface() - zsbuf = zsbuf_tex.get_surface() - fb = Framebuffer() - fb.width = width - fb.height = height - fb.nr_cbufs = 1 - fb.set_cbuf(0, cbuf) - fb.set_zsbuf(zsbuf) - ctx.set_framebuffer(fb) - rgba = FloatArray(4); - rgba[0] = 0.5 - rgba[1] = 0.5 - rgba[2] = 0.5 - rgba[3] = 0.5 - ctx.clear(PIPE_CLEAR_DEPTHSTENCIL, rgba, 1.0, 0) - del fb - - # vertex shader - vs = Shader(''' - VERT - DCL IN[0], POSITION, CONSTANT - DCL IN[1], GENERIC, CONSTANT - DCL OUT[0], POSITION, CONSTANT - DCL OUT[1], GENERIC, CONSTANT - 0:MOV OUT[0], IN[0] - 1:MOV OUT[1], IN[1] - 2:END - ''') - #vs.dump() - ctx.set_vertex_shader(vs) - - # fragment shader - op = { - PIPE_TEXTURE_1D: "1D", - PIPE_TEXTURE_2D: "2D", - PIPE_TEXTURE_3D: "3D", - PIPE_TEXTURE_CUBE: "CUBE", - }[target] - fs = Shader(''' - FRAG - DCL IN[0], GENERIC[0], LINEAR - DCL SAMP[0], CONSTANT - DCL OUT[0].z, POSITION - 0:TEX OUT[0].z, IN[0], SAMP[0], %s - 1:END - ''' % op) - #fs.dump() - ctx.set_fragment_shader(fs) - - nverts = 4 - nattrs = 2 - verts = FloatArray(nverts * nattrs * 4) - - x = 0 - y = 0 - w, h = minify((width, height), level) - - pos = [ - [x, y], - [x+w, y], - [x+w, y+h], - [x, y+h], - ] - - tex = tex_coords(texture, face, level, zslice) - - for i in range(0, 4): - j = 8*i - verts[j + 0] = pos[i][0]/float(width) # x - verts[j + 1] = pos[i][1]/float(height) # y - verts[j + 2] = 0.0 # z - verts[j + 3] = 1.0 # w - verts[j + 4] = tex[i][0] # s - verts[j + 5] = tex[i][1] # r - verts[j + 6] = tex[i][2] # q - verts[j + 7] = 1.0 - - ctx.draw_vertices(PIPE_PRIM_TRIANGLE_FAN, - nverts, - nattrs, - verts) - - ctx.flush() - - zsbuf = zsbuf_tex.get_surface() - - self.assert_rgba(ctx, zsbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85) - - - - -def main(): - random.seed(0xdead3eef) - - dev = Device() - ctx = dev.context_create() - suite = TestSuite() - - targets = [ - PIPE_TEXTURE_2D, - PIPE_TEXTURE_CUBE, - PIPE_TEXTURE_3D, - ] - - #sizes = [64, 32, 16, 8, 4, 2, 1] - #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] - sizes = [64] - #sizes = [63] - - faces = [ - PIPE_TEX_FACE_POS_X, - PIPE_TEX_FACE_NEG_X, - PIPE_TEX_FACE_POS_Y, - PIPE_TEX_FACE_NEG_Y, - PIPE_TEX_FACE_POS_Z, - PIPE_TEX_FACE_NEG_Z, - ] - - try: - n = int(sys.argv[1]) - except: - n = 10000 - - for i in range(n): - format = random.choice(formats.keys()) - if not util_format_is_depth_or_stencil(format): - is_depth_or_stencil = util_format_is_depth_or_stencil(format) - - if is_depth_or_stencil: - target = PIPE_TEXTURE_2D - else: - target = random.choice(targets) - - size = random.choice(sizes) - - if target == PIPE_TEXTURE_3D: - depth = size - else: - depth = 1 - - if target == PIPE_TEXTURE_CUBE: - face = random.choice(faces) - else: - face = PIPE_TEX_FACE_POS_X - - levels = lods(size) - last_level = random.randint(0, levels - 1) - level = random.randint(0, last_level) - zslice = random.randint(0, max(depth >> level, 1) - 1) - - if is_depth_or_stencil: - klass = TextureDepthSampleTest - else: - klass = TextureColorSampleTest - - test = klass( - dev = dev, - ctx = ctx, - target = target, - format = format, - width = size, - height = size, - depth = depth, - last_level = last_level, - face = face, - level = level, - zslice = zslice, - ) - suite.add_test(test) - suite.run() - - -if __name__ == '__main__': - main() diff --git a/src/gallium/tests/python/tests/texture_transfer.py b/src/gallium/tests/python/tests/texture_transfer.py deleted file mode 100755 index 65c919bc64d..00000000000 --- a/src/gallium/tests/python/tests/texture_transfer.py +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/env python -########################################################################## -# -# Copyright 2009 VMware, Inc. -# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. -# 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. -# -########################################################################## - - -import os -import random - -from gallium import * -from base import * - - -def lods(*dims): - size = max(dims) - lods = 0 - while size: - lods += 1 - size >>= 1 - return lods - - -class TextureTest(TestCase): - - tags = ( - 'target', - 'format', - 'width', - 'height', - 'depth', - 'last_level', - 'face', - 'level', - 'zslice', - ) - - def test(self): - dev = self.dev - ctx = self.ctx - - target = self.target - format = self.format - width = self.width - height = self.height - depth = self.depth - last_level = self.last_level - face = self.face - level = self.level - zslice = self.zslice - - bind = PIPE_BIND_SAMPLER_VIEW - geom_flags = 0 - sample_count = 0 - if not dev.is_format_supported(format, target, sample_count, bind, geom_flags): - raise TestSkip - - # textures - texture = dev.resource_create( - target = target, - format = format, - width = width, - height = height, - depth = depth, - last_level = last_level, - bind = bind, - ) - - surface = texture.get_surface(face, level, zslice) - - stride = util_format_get_stride(format, surface.width) - size = util_format_get_nblocksy(format, surface.height) * stride - - in_raw = os.urandom(size) - - ctx.surface_write_raw(surface, 0, 0, surface.width, surface.height, in_raw, stride) - - out_raw = ctx.surface_read_raw(surface, 0, 0, surface.width, surface.height) - - if in_raw != out_raw: - raise TestFailure - - -def main(): - dev = Device() - ctx = dev.context_create() - suite = TestSuite() - - targets = [ - PIPE_TEXTURE_2D, - PIPE_TEXTURE_CUBE, - PIPE_TEXTURE_3D, - ] - - sizes = [64, 32, 16, 8, 4, 2, 1] - #sizes = [1020, 508, 252, 62, 30, 14, 6, 3] - #sizes = [64] - #sizes = [63] - - faces = [ - PIPE_TEX_FACE_POS_X, - PIPE_TEX_FACE_NEG_X, - PIPE_TEX_FACE_POS_Y, - PIPE_TEX_FACE_NEG_Y, - PIPE_TEX_FACE_POS_Z, - PIPE_TEX_FACE_NEG_Z, - ] - - try: - n = int(sys.argv[1]) - except: - n = 10000 - - for i in range(n): - format = random.choice(formats.keys()) - if not util_format_is_depth_or_stencil(format): - is_depth_or_stencil = util_format_is_depth_or_stencil(format) - - if is_depth_or_stencil: - target = PIPE_TEXTURE_2D - else: - target = random.choice(targets) - - size = random.choice(sizes) - - if target == PIPE_TEXTURE_3D: - depth = size - else: - depth = 1 - - if target == PIPE_TEXTURE_CUBE: - face = random.choice(faces) - else: - face = PIPE_TEX_FACE_POS_X - - levels = lods(size) - last_level = random.randint(0, levels - 1) - level = random.randint(0, last_level) - zslice = random.randint(0, max(depth >> level, 1) - 1) - - test = TextureTest( - dev = dev, - ctx = ctx, - target = target, - format = format, - width = size, - height = size, - depth = depth, - last_level = last_level, - face = face, - level = level, - zslice = zslice, - ) - suite.add_test(test) - suite.run() - - -if __name__ == '__main__': - main() diff --git a/src/gallium/tests/unit/SConscript b/src/gallium/tests/unit/SConscript index 49f28c03691..edc1e80a412 100644 --- a/src/gallium/tests/unit/SConscript +++ b/src/gallium/tests/unit/SConscript @@ -19,13 +19,13 @@ progs = [ 'translate_test' ] -for prog in progs: +for progname in progs: prog = env.Program( - target = prog, - source = prog + '.c', + target = progname, + source = progname + '.c', ) - env.InstallProgram(prog) + env.Alias(progname, env.InstallProgram(prog)) # http://www.scons.org/wiki/UnitTests test_alias = env.Alias('unit', [prog], prog[0].abspath) diff --git a/src/gallium/tests/unit/translate_test.c b/src/gallium/tests/unit/translate_test.c index d0946a91a26..2976fb79227 100644 --- a/src/gallium/tests/unit/translate_test.c +++ b/src/gallium/tests/unit/translate_test.c @@ -57,6 +57,7 @@ int main(int argc, char** argv) unsigned char* byte_buffer; float* float_buffer; double* double_buffer; + unsigned * elts; unsigned count = 4; unsigned i, j, k; unsigned passed = 0; @@ -137,6 +138,8 @@ int main(int argc, char** argv) float_buffer = align_malloc(buffer_size, 4096); double_buffer = align_malloc(buffer_size, 4096); + elts = align_malloc(count * sizeof *elts, 4096); + key.nr_elements = 1; key.element[0].input_buffer = 0; key.element[0].input_offset = 0; @@ -156,6 +159,9 @@ int main(int argc, char** argv) for (i = 0; i < buffer_size / sizeof(double); ++i) double_buffer[i] = rand_double(); + for (i = 0; i < count; ++i) + elts[i] = i; + for (output_format = 1; output_format < PIPE_FORMAT_COUNT; ++output_format) { const struct util_format_description* output_format_desc = util_format_description(output_format); @@ -245,14 +251,14 @@ int main(int argc, char** argv) else buffer[0] = byte_buffer; - translate[0]->set_buffer(translate[0], 0, buffer[0], input_format_size, ~0); - translate[0]->run(translate[0], 0, count, 0, buffer[1]); - translate[1]->set_buffer(translate[1], 0, buffer[1], output_format_size, ~0); - translate[1]->run(translate[1], 0, count, 0, buffer[2]); - translate[0]->set_buffer(translate[0], 0, buffer[2], input_format_size, ~0); - translate[0]->run(translate[0], 0, count, 0, buffer[3]); - translate[1]->set_buffer(translate[1], 0, buffer[3], output_format_size, ~0); - translate[1]->run(translate[1], 0, count, 0, buffer[4]); + translate[0]->set_buffer(translate[0], 0, buffer[0], input_format_size, count - 1); + translate[0]->run_elts(translate[0], elts, count, 0, buffer[1]); + translate[1]->set_buffer(translate[1], 0, buffer[1], output_format_size, count - 1); + translate[1]->run_elts(translate[1], elts, count, 0, buffer[2]); + translate[0]->set_buffer(translate[0], 0, buffer[2], input_format_size, count - 1); + translate[0]->run_elts(translate[0], elts, count, 0, buffer[3]); + translate[1]->set_buffer(translate[1], 0, buffer[3], output_format_size, count - 1); + translate[1]->run_elts(translate[1], elts, count, 0, buffer[4]); for (i = 0; i < count; ++i) { diff --git a/src/gallium/tools/trace/dump.py b/src/gallium/tools/trace/dump.py new file mode 100755 index 00000000000..bd47c9a6b06 --- /dev/null +++ b/src/gallium/tools/trace/dump.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. +# 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 TUNGSTEN GRAPHICS 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. +# +########################################################################## + + +from parse import * + + +if __name__ == '__main__': + Main().main() diff --git a/src/gallium/tools/trace/format.py b/src/gallium/tools/trace/format.py new file mode 100755 index 00000000000..a4285bfe075 --- /dev/null +++ b/src/gallium/tools/trace/format.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. +# 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 TUNGSTEN GRAPHICS 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. +# +########################################################################## + + +import sys + + +class Formatter: + '''Plain formatter''' + + def __init__(self, stream): + self.stream = stream + + def text(self, text): + self.stream.write(text) + + def newline(self): + self.text('\n') + + def function(self, name): + self.text(name) + + def variable(self, name): + self.text(name) + + def literal(self, value): + self.text(str(value)) + + def address(self, addr): + self.text(str(addr)) + + +class AnsiFormatter(Formatter): + '''Formatter for plain-text files which outputs ANSI escape codes. See + http://en.wikipedia.org/wiki/ANSI_escape_code for more information + concerning ANSI escape codes. + ''' + + _csi = '\33[' + + _normal = '0m' + _bold = '1m' + _italic = '3m' + _red = '31m' + _green = '32m' + _blue = '34m' + + def _escape(self, code): + self.text(self._csi + code) + + def function(self, name): + self._escape(self._bold) + Formatter.function(self, name) + self._escape(self._normal) + + def variable(self, name): + self._escape(self._italic) + Formatter.variable(self, name) + self._escape(self._normal) + + def literal(self, value): + self._escape(self._blue) + Formatter.literal(self, value) + self._escape(self._normal) + + def address(self, value): + self._escape(self._green) + Formatter.address(self, value) + self._escape(self._normal) + + +class WindowsConsoleFormatter(Formatter): + '''Formatter for the Windows Console. See + http://code.activestate.com/recipes/496901/ for more information. + ''' + + STD_INPUT_HANDLE = -10 + STD_OUTPUT_HANDLE = -11 + STD_ERROR_HANDLE = -12 + + FOREGROUND_BLUE = 0x01 + FOREGROUND_GREEN = 0x02 + FOREGROUND_RED = 0x04 + FOREGROUND_INTENSITY = 0x08 + BACKGROUND_BLUE = 0x10 + BACKGROUND_GREEN = 0x20 + BACKGROUND_RED = 0x40 + BACKGROUND_INTENSITY = 0x80 + + _normal = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED + _bold = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY + _italic = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED + _red = FOREGROUND_RED | FOREGROUND_INTENSITY + _green = FOREGROUND_GREEN | FOREGROUND_INTENSITY + _blue = FOREGROUND_BLUE | FOREGROUND_INTENSITY + + def __init__(self, stream): + Formatter.__init__(self, stream) + + if stream is sys.stdin: + nStdHandle = self.STD_INPUT_HANDLE + elif stream is sys.stdout: + nStdHandle = self.STD_OUTPUT_HANDLE + elif stream is sys.stderr: + nStdHandle = self.STD_ERROR_HANDLE + else: + nStdHandle = None + + if nStdHandle: + import ctypes + self.handle = ctypes.windll.kernel32.GetStdHandle(nStdHandle) + else: + self.handle = None + + def _attribute(self, attr): + if self.handle: + import ctypes + ctypes.windll.kernel32.SetConsoleTextAttribute(self.handle, attr) + + def function(self, name): + self._attribute(self._bold) + Formatter.function(self, name) + self._attribute(self._normal) + + def variable(self, name): + self._attribute(self._italic) + Formatter.variable(self, name) + self._attribute(self._normal) + + def literal(self, value): + self._attribute(self._blue) + Formatter.literal(self, value) + self._attribute(self._normal) + + def address(self, value): + self._attribute(self._green) + Formatter.address(self, value) + self._attribute(self._normal) + + +def DefaultFormatter(stream): + if sys.platform in ('linux2', 'cygwin'): + return AnsiFormatter(stream) + elif sys.platform in ('win32',): + return WindowsConsoleFormatter(stream) + else: + return Formatter(stream) + diff --git a/src/gallium/tools/trace/model.py b/src/gallium/tools/trace/model.py new file mode 100755 index 00000000000..e76aad7788b --- /dev/null +++ b/src/gallium/tools/trace/model.py @@ -0,0 +1,214 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. +# 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 TUNGSTEN GRAPHICS 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. +# +########################################################################## + + +'''Trace data model.''' + + +import sys +import string +import format + +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO + + +class Node: + + def visit(self, visitor): + raise NotImplementedError + + def __str__(self): + stream = StringIO() + formatter = format.DefaultFormatter(stream) + pretty_printer = PrettyPrinter(formatter) + self.visit(pretty_printer) + return stream.getvalue() + + +class Literal(Node): + + def __init__(self, value): + self.value = value + + def visit(self, visitor): + visitor.visit_literal(self) + + +class NamedConstant(Node): + + def __init__(self, name): + self.name = name + + def visit(self, visitor): + visitor.visit_named_constant(self) + + +class Array(Node): + + def __init__(self, elements): + self.elements = elements + + def visit(self, visitor): + visitor.visit_array(self) + + +class Struct(Node): + + def __init__(self, name, members): + self.name = name + self.members = members + + def visit(self, visitor): + visitor.visit_struct(self) + + +class Pointer(Node): + + def __init__(self, address): + self.address = address + + def visit(self, visitor): + visitor.visit_pointer(self) + + +class Call: + + def __init__(self, no, klass, method, args, ret): + self.no = no + self.klass = klass + self.method = method + self.args = args + self.ret = ret + + def visit(self, visitor): + visitor.visit_call(self) + + +class Trace: + + def __init__(self, calls): + self.calls = calls + + def visit(self, visitor): + visitor.visit_trace(self) + + +class Visitor: + + def visit_literal(self, node): + raise NotImplementedError + + def visit_named_constant(self, node): + raise NotImplementedError + + def visit_array(self, node): + raise NotImplementedError + + def visit_struct(self, node): + raise NotImplementedError + + def visit_pointer(self, node): + raise NotImplementedError + + def visit_call(self, node): + raise NotImplementedError + + def visit_trace(self, node): + raise NotImplementedError + + +class PrettyPrinter: + + def __init__(self, formatter): + self.formatter = formatter + + def visit_literal(self, node): + if isinstance(node.value, basestring): + if len(node.value) >= 4096 or node.value.strip(string.printable): + self.formatter.address('blob(%u)' % len(node.value)) + #self.formatter.text('...') + return + + self.formatter.literal('"' + node.value + '"') + return + + self.formatter.literal(repr(node.value)) + + def visit_named_constant(self, node): + self.formatter.literal(node.name) + + def visit_array(self, node): + self.formatter.text('{') + sep = '' + for value in node.elements: + self.formatter.text(sep) + value.visit(self) + sep = ', ' + self.formatter.text('}') + + def visit_struct(self, node): + self.formatter.text('{') + sep = '' + for name, value in node.members: + self.formatter.text(sep) + self.formatter.variable(name) + self.formatter.text(' = ') + value.visit(self) + sep = ', ' + self.formatter.text('}') + + def visit_pointer(self, node): + self.formatter.address(node.address) + + def visit_call(self, node): + self.formatter.text('%s ' % node.no) + if node.klass is not None: + self.formatter.function(node.klass + '::' + node.method) + else: + self.formatter.function(node.method) + self.formatter.text('(') + sep = '' + for name, value in node.args: + self.formatter.text(sep) + self.formatter.variable(name) + self.formatter.text(' = ') + value.visit(self) + sep = ', ' + self.formatter.text(')') + if node.ret is not None: + self.formatter.text(' = ') + node.ret.visit(self) + + def visit_trace(self, node): + for call in node.calls: + call.visit(self) + self.formatter.newline() + diff --git a/src/gallium/tools/trace/parse.py b/src/gallium/tools/trace/parse.py new file mode 100755 index 00000000000..b08d3686715 --- /dev/null +++ b/src/gallium/tools/trace/parse.py @@ -0,0 +1,392 @@ +#!/usr/bin/env python +########################################################################## +# +# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. +# 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 TUNGSTEN GRAPHICS 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. +# +########################################################################## + + +import sys +import xml.parsers.expat +import binascii +import optparse + +from model import * + + +ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF = range(4) + + +class XmlToken: + + def __init__(self, type, name_or_data, attrs = None, line = None, column = None): + assert type in (ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF) + self.type = type + self.name_or_data = name_or_data + self.attrs = attrs + self.line = line + self.column = column + + def __str__(self): + if self.type == ELEMENT_START: + return '<' + self.name_or_data + ' ...>' + if self.type == ELEMENT_END: + return '</' + self.name_or_data + '>' + if self.type == CHARACTER_DATA: + return self.name_or_data + if self.type == EOF: + return 'end of file' + assert 0 + + +class XmlTokenizer: + """Expat based XML tokenizer.""" + + def __init__(self, fp, skip_ws = True): + self.fp = fp + self.tokens = [] + self.index = 0 + self.final = False + self.skip_ws = skip_ws + + self.character_pos = 0, 0 + self.character_data = '' + + self.parser = xml.parsers.expat.ParserCreate() + self.parser.StartElementHandler = self.handle_element_start + self.parser.EndElementHandler = self.handle_element_end + self.parser.CharacterDataHandler = self.handle_character_data + + def handle_element_start(self, name, attributes): + self.finish_character_data() + line, column = self.pos() + token = XmlToken(ELEMENT_START, name, attributes, line, column) + self.tokens.append(token) + + def handle_element_end(self, name): + self.finish_character_data() + line, column = self.pos() + token = XmlToken(ELEMENT_END, name, None, line, column) + self.tokens.append(token) + + def handle_character_data(self, data): + if not self.character_data: + self.character_pos = self.pos() + self.character_data += data + + def finish_character_data(self): + if self.character_data: + if not self.skip_ws or not self.character_data.isspace(): + line, column = self.character_pos + token = XmlToken(CHARACTER_DATA, self.character_data, None, line, column) + self.tokens.append(token) + self.character_data = '' + + def next(self): + size = 16*1024 + while self.index >= len(self.tokens) and not self.final: + self.tokens = [] + self.index = 0 + data = self.fp.read(size) + self.final = len(data) < size + data = data.rstrip('\0') + try: + self.parser.Parse(data, self.final) + except xml.parsers.expat.ExpatError, e: + #if e.code == xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS: + if e.code == 3: + pass + else: + raise e + if self.index >= len(self.tokens): + line, column = self.pos() + token = XmlToken(EOF, None, None, line, column) + else: + token = self.tokens[self.index] + self.index += 1 + return token + + def pos(self): + return self.parser.CurrentLineNumber, self.parser.CurrentColumnNumber + + +class TokenMismatch(Exception): + + def __init__(self, expected, found): + self.expected = expected + self.found = found + + def __str__(self): + return '%u:%u: %s expected, %s found' % (self.found.line, self.found.column, str(self.expected), str(self.found)) + + + +class XmlParser: + """Base XML document parser.""" + + def __init__(self, fp): + self.tokenizer = XmlTokenizer(fp) + self.consume() + + def consume(self): + self.token = self.tokenizer.next() + + def match_element_start(self, name): + return self.token.type == ELEMENT_START and self.token.name_or_data == name + + def match_element_end(self, name): + return self.token.type == ELEMENT_END and self.token.name_or_data == name + + def element_start(self, name): + while self.token.type == CHARACTER_DATA: + self.consume() + if self.token.type != ELEMENT_START: + raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) + if self.token.name_or_data != name: + raise TokenMismatch(XmlToken(ELEMENT_START, name), self.token) + attrs = self.token.attrs + self.consume() + return attrs + + def element_end(self, name): + while self.token.type == CHARACTER_DATA: + self.consume() + if self.token.type != ELEMENT_END: + raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) + if self.token.name_or_data != name: + raise TokenMismatch(XmlToken(ELEMENT_END, name), self.token) + self.consume() + + def character_data(self, strip = True): + data = '' + while self.token.type == CHARACTER_DATA: + data += self.token.name_or_data + self.consume() + if strip: + data = data.strip() + return data + + +class TraceParser(XmlParser): + + def __init__(self, fp): + XmlParser.__init__(self, fp) + self.last_call_no = 0 + + def parse(self): + self.element_start('trace') + while self.token.type not in (ELEMENT_END, EOF): + call = self.parse_call() + self.handle_call(call) + if self.token.type != EOF: + self.element_end('trace') + + def parse_call(self): + attrs = self.element_start('call') + try: + no = int(attrs['no']) + except KeyError: + self.last_call_no += 1 + no = self.last_call_no + else: + self.last_call_no = no + klass = attrs['class'] + method = attrs['method'] + args = [] + ret = None + while self.token.type == ELEMENT_START: + if self.token.name_or_data == 'arg': + arg = self.parse_arg() + args.append(arg) + elif self.token.name_or_data == 'ret': + ret = self.parse_ret() + elif self.token.name_or_data == 'call': + # ignore nested function calls + self.parse_call() + else: + raise TokenMismatch("<arg ...> or <ret ...>", self.token) + self.element_end('call') + + return Call(no, klass, method, args, ret) + + def parse_arg(self): + attrs = self.element_start('arg') + name = attrs['name'] + value = self.parse_value() + self.element_end('arg') + + return name, value + + def parse_ret(self): + attrs = self.element_start('ret') + value = self.parse_value() + self.element_end('ret') + + return value + + def parse_value(self): + expected_tokens = ('null', 'bool', 'int', 'uint', 'float', 'string', 'enum', 'array', 'struct', 'ptr', 'bytes') + if self.token.type == ELEMENT_START: + if self.token.name_or_data in expected_tokens: + method = getattr(self, 'parse_' + self.token.name_or_data) + return method() + raise TokenMismatch(" or " .join(expected_tokens), self.token) + + def parse_null(self): + self.element_start('null') + self.element_end('null') + return Literal(None) + + def parse_bool(self): + self.element_start('bool') + value = int(self.character_data()) + self.element_end('bool') + return Literal(value) + + def parse_int(self): + self.element_start('int') + value = int(self.character_data()) + self.element_end('int') + return Literal(value) + + def parse_uint(self): + self.element_start('uint') + value = int(self.character_data()) + self.element_end('uint') + return Literal(value) + + def parse_float(self): + self.element_start('float') + value = float(self.character_data()) + self.element_end('float') + return Literal(value) + + def parse_enum(self): + self.element_start('enum') + name = self.character_data() + self.element_end('enum') + return NamedConstant(name) + + def parse_string(self): + self.element_start('string') + value = self.character_data() + self.element_end('string') + return Literal(value) + + def parse_bytes(self): + self.element_start('bytes') + value = binascii.a2b_hex(self.character_data()) + self.element_end('bytes') + return Literal(value) + + def parse_array(self): + self.element_start('array') + elems = [] + while self.token.type != ELEMENT_END: + elems.append(self.parse_elem()) + self.element_end('array') + return Array(elems) + + def parse_elem(self): + self.element_start('elem') + value = self.parse_value() + self.element_end('elem') + return value + + def parse_struct(self): + attrs = self.element_start('struct') + name = attrs['name'] + members = [] + while self.token.type != ELEMENT_END: + members.append(self.parse_member()) + self.element_end('struct') + return Struct(name, members) + + def parse_member(self): + attrs = self.element_start('member') + name = attrs['name'] + value = self.parse_value() + self.element_end('member') + + return name, value + + def parse_ptr(self): + self.element_start('ptr') + address = self.character_data() + self.element_end('ptr') + + return Pointer(address) + + def handle_call(self, call): + pass + + +class TraceDumper(TraceParser): + + def __init__(self, fp): + TraceParser.__init__(self, fp) + self.formatter = format.DefaultFormatter(sys.stdout) + self.pretty_printer = PrettyPrinter(self.formatter) + + def handle_call(self, call): + call.visit(self.pretty_printer) + self.formatter.newline() + + +class Main: + '''Common main class for all retrace command line utilities.''' + + def __init__(self): + pass + + def main(self): + optparser = self.get_optparser() + (options, args) = optparser.parse_args(sys.argv[1:]) + + if args: + for arg in args: + if arg.endswith('.gz'): + from gzip import GzipFile + stream = GzipFile(arg, 'rt') + elif arg.endswith('.bz2'): + from bz2 import BZ2File + stream = BZ2File(arg, 'rU') + else: + stream = open(arg, 'rt') + self.process_arg(stream, options) + else: + self.process_arg(stream, options) + + def get_optparser(self): + optparser = optparse.OptionParser( + usage="\n\t%prog [options] [traces] ...") + return optparser + + def process_arg(self, stream, options): + parser = TraceDumper(stream) + parser.parse() + + +if __name__ == '__main__': + Main().main() diff --git a/src/gallium/winsys/i915/drm/i915_drm_winsys.c b/src/gallium/winsys/i915/drm/i915_drm_winsys.c index 2c3b508d056..6c8a10d800f 100644 --- a/src/gallium/winsys/i915/drm/i915_drm_winsys.c +++ b/src/gallium/winsys/i915/drm/i915_drm_winsys.c @@ -1,4 +1,7 @@ #include <stdio.h> +#include <sys/ioctl.h> + +#include "i915_drm.h" #include "state_tracker/drm_driver.h" @@ -13,26 +16,16 @@ static void -i915_drm_get_device_id(unsigned int *device_id) +i915_drm_get_device_id(int fd, unsigned int *device_id) { - char path[512]; - FILE *file; - void *shutup_gcc; - - /* - * FIXME: Fix this up to use a drm ioctl or whatever. - */ - - snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device"); - file = fopen(path, "r"); - if (!file) { - return; - } - - shutup_gcc = fgets(path, sizeof(path), file); - (void) shutup_gcc; - sscanf(path, "%x", device_id); - fclose(file); + int ret; + struct drm_i915_getparam gp; + + gp.param = I915_PARAM_CHIPSET_ID; + gp.value = (int *)device_id; + + ret = ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)); + assert(ret == 0); } static void @@ -55,7 +48,7 @@ i915_drm_winsys_create(int drmFD) if (!idws) return NULL; - i915_drm_get_device_id(&deviceID); + i915_drm_get_device_id(drmFD, &deviceID); i915_drm_winsys_init_batchbuffer_functions(idws); i915_drm_winsys_init_buffer_functions(idws); diff --git a/src/gallium/winsys/r600/drm/evergreen_hw_context.c b/src/gallium/winsys/r600/drm/evergreen_hw_context.c index 66398afa698..0a5b1a09336 100644 --- a/src/gallium/winsys/r600/drm/evergreen_hw_context.c +++ b/src/gallium/winsys/r600/drm/evergreen_hw_context.c @@ -69,29 +69,29 @@ static const struct r600_reg evergreen_context_reg_list[] = { {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02800C_DB_RENDER_OVERRIDE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028010_DB_RENDER_OVERRIDE2, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028014_DB_HTILE_DATA_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028014_DB_HTILE_DATA_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028028_DB_STENCIL_CLEAR, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02802C_DB_DEPTH_CLEAR, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028030_PA_SC_SCREEN_SCISSOR_TL, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028034_PA_SC_SCREEN_SCISSOR_BR, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028040_DB_Z_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028040_DB_Z_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028044_DB_STENCIL_INFO, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028048_DB_Z_READ_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028048_DB_Z_READ_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02804C_DB_STENCIL_READ_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02804C_DB_STENCIL_READ_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028050_DB_Z_WRITE_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028050_DB_Z_WRITE_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028054_DB_STENCIL_WRITE_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028054_DB_STENCIL_WRITE_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028058_DB_DEPTH_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02805C_DB_DEPTH_SLICE, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028140_ALU_CONST_BUFFER_SIZE_PS_0, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028180_ALU_CONST_BUFFER_SIZE_VS_0, 0, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028140_ALU_CONST_BUFFER_SIZE_PS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028180_ALU_CONST_BUFFER_SIZE_VS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028200_PA_SC_WINDOW_OFFSET, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028204_PA_SC_WINDOW_SCISSOR_TL, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028208_PA_SC_WINDOW_SCISSOR_BR, 0, 0, 0}, @@ -258,14 +258,14 @@ static const struct r600_reg evergreen_context_reg_list[] = { {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02881C_PA_CL_VS_OUT_CNTL, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028820_PA_CL_NANINF_CNTL, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028838_SQ_DYN_GPR_RESOURCE_LIMIT_1, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028840_SQ_PGM_START_PS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028840_SQ_PGM_START_PS, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028844_SQ_PGM_RESOURCES_PS, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028848_SQ_PGM_RESOURCES_2_PS, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02884C_SQ_PGM_EXPORTS_PS, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02885C_SQ_PGM_START_VS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_02885C_SQ_PGM_START_VS, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028860_SQ_PGM_RESOURCES_VS, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028864_SQ_PGM_RESOURCES_2_VS, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0288A4_SQ_PGM_START_FS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0288A4_SQ_PGM_START_FS, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0288A8_SQ_PGM_RESOURCES_FS, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_0288EC_SQ_LDS_ALLOC_PS, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028900_SQ_ESGS_RING_ITEMSIZE, 0, 0, 0}, @@ -278,8 +278,8 @@ static const struct r600_reg evergreen_context_reg_list[] = { {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028920_SQ_GS_VERT_ITEMSIZE_1, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028924_SQ_GS_VERT_ITEMSIZE_2, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028928_SQ_GS_VERT_ITEMSIZE_3, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028940_ALU_CONST_CACHE_PS_0, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028980_ALU_CONST_CACHE_VS_0, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028940_ALU_CONST_CACHE_PS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028980_ALU_CONST_CACHE_VS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A00_PA_SU_POINT_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A04_PA_SU_POINT_MINMAX, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028A08_PA_SU_LINE_CNTL, 0, 0, 0}, @@ -324,100 +324,100 @@ static const struct r600_reg evergreen_context_reg_list[] = { {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C3C_PA_SC_AA_MASK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C60_CB_COLOR0_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C60_CB_COLOR0_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C64_CB_COLOR0_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C68_CB_COLOR0_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C6C_CB_COLOR0_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C70_CB_COLOR0_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C74_CB_COLOR0_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C70_CB_COLOR0_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C74_CB_COLOR0_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C78_CB_COLOR0_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C9C_CB_COLOR1_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028C9C_CB_COLOR1_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CA0_CB_COLOR1_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CA4_CB_COLOR1_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CA8_CB_COLOR1_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CAC_CB_COLOR1_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CB0_CB_COLOR1_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CAC_CB_COLOR1_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CB0_CB_COLOR1_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CB4_CB_COLOR1_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CD8_CB_COLOR2_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CD8_CB_COLOR2_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CDC_CB_COLOR2_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CE0_CB_COLOR2_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CE4_CB_COLOR2_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CE8_CB_COLOR2_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CEC_CB_COLOR2_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CE8_CB_COLOR2_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CEC_CB_COLOR2_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028CF0_CB_COLOR2_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D14_CB_COLOR3_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D14_CB_COLOR3_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D18_CB_COLOR3_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D1C_CB_COLOR3_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D20_CB_COLOR3_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D24_CB_COLOR3_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D28_CB_COLOR3_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D24_CB_COLOR3_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D28_CB_COLOR3_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D2C_CB_COLOR3_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D50_CB_COLOR4_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D50_CB_COLOR4_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D54_CB_COLOR4_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D58_CB_COLOR4_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D5C_CB_COLOR4_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D60_CB_COLOR4_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D64_CB_COLOR4_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D60_CB_COLOR4_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D64_CB_COLOR4_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D68_CB_COLOR4_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D8C_CB_COLOR5_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D8C_CB_COLOR5_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D90_CB_COLOR5_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D94_CB_COLOR5_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D98_CB_COLOR5_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D9C_CB_COLOR5_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DA0_CB_COLOR5_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028D9C_CB_COLOR5_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DA0_CB_COLOR5_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DA4_CB_COLOR5_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DC8_CB_COLOR6_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DC8_CB_COLOR6_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DCC_CB_COLOR6_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DD0_CB_COLOR6_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DD4_CB_COLOR6_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DD8_CB_COLOR6_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DDC_CB_COLOR6_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DD8_CB_COLOR6_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DDC_CB_COLOR6_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028DE0_CB_COLOR6_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E04_CB_COLOR7_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E04_CB_COLOR7_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E08_CB_COLOR7_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E0C_CB_COLOR7_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E10_CB_COLOR7_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E14_CB_COLOR7_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E18_CB_COLOR7_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E14_CB_COLOR7_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E18_CB_COLOR7_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E1C_CB_COLOR7_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E40_CB_COLOR8_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E40_CB_COLOR8_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E44_CB_COLOR8_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E48_CB_COLOR8_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E4C_CB_COLOR8_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E50_CB_COLOR8_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E54_CB_COLOR8_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E50_CB_COLOR8_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E54_CB_COLOR8_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E58_CB_COLOR8_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E5C_CB_COLOR9_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E5C_CB_COLOR9_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E60_CB_COLOR9_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E64_CB_COLOR9_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E68_CB_COLOR9_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E6C_CB_COLOR9_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E70_CB_COLOR9_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E6C_CB_COLOR9_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E70_CB_COLOR9_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E74_CB_COLOR9_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E78_CB_COLOR10_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E78_CB_COLOR10_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E7C_CB_COLOR10_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E80_CB_COLOR10_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E84_CB_COLOR10_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E88_CB_COLOR10_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E8C_CB_COLOR10_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E88_CB_COLOR10_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E8C_CB_COLOR10_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E90_CB_COLOR10_DIM, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E94_CB_COLOR11_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E94_CB_COLOR11_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E98_CB_COLOR11_PITCH, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028E9C_CB_COLOR11_SLICE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EA0_CB_COLOR11_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EA4_CB_COLOR11_INFO, 1, 0, 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EA8_CB_COLOR11_ATTRIB, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EA4_CB_COLOR11_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EA8_CB_COLOR11_ATTRIB, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, EVERGREEN_CONTEXT_REG_OFFSET, R_028EAC_CB_COLOR11_DIM, 0, 0, 0}, }; @@ -427,8 +427,8 @@ static int evergreen_state_resource_init(struct r600_context *ctx, u32 offset) struct r600_reg r600_shader_resource[] = { {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030000_RESOURCE0_WORD0, 0, 0, 0}, {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030004_RESOURCE0_WORD1, 0, 0, 0}, - {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030008_RESOURCE0_WORD2, 1, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, - {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_03000C_RESOURCE0_WORD3, 1, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030008_RESOURCE0_WORD2, REG_FLAG_NEED_BO, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_03000C_RESOURCE0_WORD3, REG_FLAG_NEED_BO, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030010_RESOURCE0_WORD4, 0, 0, 0}, {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030014_RESOURCE0_WORD5, 0, 0, 0}, {PKT3_SET_RESOURCE, EVERGREEN_RESOURCE_OFFSET, R_030018_RESOURCE0_WORD6, 0, 0, 0}, @@ -499,7 +499,7 @@ static int evergreen_loop_const_init(struct r600_context *ctx, u32 offset) r600_loop_consts[i].opcode = PKT3_SET_LOOP_CONST; r600_loop_consts[i].offset_base = EVERGREEN_LOOP_CONST_OFFSET; r600_loop_consts[i].offset = EVERGREEN_LOOP_CONST_OFFSET + ((offset + i) * 4); - r600_loop_consts[i].need_bo = 0; + r600_loop_consts[i].flags = REG_FLAG_DIRTY_ALWAYS; r600_loop_consts[i].flush_flags = 0; } return r600_context_add_block(ctx, r600_loop_consts, nreg); @@ -633,74 +633,33 @@ out_err: return r; } -static inline void evergreen_context_pipe_state_set_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) -{ - struct r600_range *range; - struct r600_block *block; - - range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; - block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; - if (state == NULL) { - block->status &= ~(R600_BLOCK_STATUS_ENABLED | R600_BLOCK_STATUS_DIRTY); - r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); - r600_bo_reference(ctx->radeon , &block->reloc[2].bo, NULL); - LIST_DELINIT(&block->list); - return; - } - block->reg[0] = state->regs[0].value; - block->reg[1] = state->regs[1].value; - block->reg[2] = state->regs[2].value; - block->reg[3] = state->regs[3].value; - block->reg[4] = state->regs[4].value; - block->reg[5] = state->regs[5].value; - block->reg[6] = state->regs[6].value; - block->reg[7] = state->regs[7].value; - r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); - r600_bo_reference(ctx->radeon , &block->reloc[2].bo, NULL); - if (state->regs[0].bo) { - /* VERTEX RESOURCE, we preted there is 2 bo to relocate so - * we have single case btw VERTEX & TEXTURE resource - */ - r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[0].bo); - r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[0].bo); - } else { - /* TEXTURE RESOURCE */ - r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[2].bo); - r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[3].bo); - } - if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { - block->status |= R600_BLOCK_STATUS_ENABLED; - block->status |= R600_BLOCK_STATUS_DIRTY; - ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; - LIST_ADDTAIL(&block->list,&ctx->dirty); - } -} - void evergreen_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) { unsigned offset = R_030000_SQ_TEX_RESOURCE_WORD0_0 + 0x20 * rid; - evergreen_context_pipe_state_set_resource(ctx, state, offset); + r600_context_pipe_state_set_resource(ctx, state, offset); } void evergreen_context_pipe_state_set_vs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) { unsigned offset = R_030000_SQ_TEX_RESOURCE_WORD0_0 + 0x1600 + 0x20 * rid; - evergreen_context_pipe_state_set_resource(ctx, state, offset); + r600_context_pipe_state_set_resource(ctx, state, offset); } void evergreen_context_pipe_state_set_fs_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) { unsigned offset = R_030000_SQ_TEX_RESOURCE_WORD0_0 + 0x7C00 + 0x20 * rid; - evergreen_context_pipe_state_set_resource(ctx, state, offset); + r600_context_pipe_state_set_resource(ctx, state, offset); } static inline void evergreen_context_pipe_state_set_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) { struct r600_range *range; struct r600_block *block; + int i; + int dirty; range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; @@ -709,15 +668,27 @@ static inline void evergreen_context_pipe_state_set_sampler(struct r600_context LIST_DELINIT(&block->list); return; } - block->reg[0] = state->regs[0].value; - block->reg[1] = state->regs[1].value; - block->reg[2] = state->regs[2].value; - if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { - block->status |= R600_BLOCK_STATUS_ENABLED; - block->status |= R600_BLOCK_STATUS_DIRTY; - ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; - LIST_ADDTAIL(&block->list,&ctx->dirty); + dirty = block->status & R600_BLOCK_STATUS_DIRTY; + + for (i = 0; i < 3; i++) { + if (block->reg[i] != state->regs[i].value) { + dirty |= R600_BLOCK_STATUS_DIRTY; + block->reg[i] = state->regs[i].value; + } } + + r600_context_dirty_block(ctx, block, dirty, 2); +} + +static inline void evergreen_context_ps_partial_flush(struct r600_context *ctx) +{ + if (!(ctx->flags & R600_CONTEXT_DRAW_PENDING)) + return; + + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0, 0); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_PS_PARTIAL_FLUSH) | EVENT_INDEX(4); + + ctx->flags &= ~R600_CONTEXT_DRAW_PENDING; } static inline void evergreen_context_pipe_state_set_sampler_border(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset, unsigned id) @@ -725,6 +696,8 @@ static inline void evergreen_context_pipe_state_set_sampler_border(struct r600_c unsigned fake_offset = (offset - R_00A400_TD_PS_SAMPLER0_BORDER_INDEX) * 0x100 + 0x40000 + id * 0x1C; struct r600_range *range; struct r600_block *block; + int i; + int dirty; range = &ctx->range[CTX_RANGE_ID(ctx, fake_offset)]; block = range->blocks[CTX_BLOCK_ID(ctx, fake_offset)]; @@ -736,17 +709,27 @@ static inline void evergreen_context_pipe_state_set_sampler_border(struct r600_c if (state->nregs <= 3) { return; } - block->reg[0] = id; - block->reg[1] = state->regs[3].value; - block->reg[2] = state->regs[4].value; - block->reg[3] = state->regs[5].value; - block->reg[4] = state->regs[6].value; - if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { - block->status |= R600_BLOCK_STATUS_ENABLED; - block->status |= R600_BLOCK_STATUS_DIRTY; - ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; - LIST_ADDTAIL(&block->list,&ctx->dirty); + + dirty = block->status & R600_BLOCK_STATUS_DIRTY; + if (block->reg[0] != id) { + block->reg[0] = id; + dirty |= R600_BLOCK_STATUS_DIRTY; } + + for (i = 1; i < 5; i++) { + if (block->reg[i] != state->regs[i + 2].value) { + block->reg[i] = state->regs[i + 2].value; + dirty |= R600_BLOCK_STATUS_DIRTY; + } + } + + /* We have to flush the shaders before we change the border color + * registers, or previous draw commands that haven't completed yet + * will end up using the new border color. */ + if (dirty & R600_BLOCK_STATUS_DIRTY) + evergreen_context_ps_partial_flush(ctx); + + r600_context_dirty_block(ctx, block, dirty, 4); } void evergreen_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id) @@ -770,42 +753,18 @@ void evergreen_context_pipe_state_set_vs_sampler(struct r600_context *ctx, struc void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *draw) { - struct r600_bo *cb[12]; - struct r600_bo *db; - unsigned ndwords = 9, flush; + unsigned ndwords = 7; struct r600_block *dirty_block = NULL; struct r600_block *next_block; if (draw->indices) { - ndwords = 13; + ndwords = 11; /* make sure there is enough relocation space before scheduling draw */ if (ctx->creloc >= (ctx->nreloc - 1)) { r600_context_flush(ctx); } } - /* find number of color buffer */ - db = r600_context_reg_bo(ctx, R_028048_DB_Z_READ_BASE); - cb[0] = r600_context_reg_bo(ctx, R_028C60_CB_COLOR0_BASE); - cb[1] = r600_context_reg_bo(ctx, R_028C9C_CB_COLOR1_BASE); - cb[2] = r600_context_reg_bo(ctx, R_028CD8_CB_COLOR2_BASE); - cb[3] = r600_context_reg_bo(ctx, R_028D14_CB_COLOR3_BASE); - cb[4] = r600_context_reg_bo(ctx, R_028D50_CB_COLOR4_BASE); - cb[5] = r600_context_reg_bo(ctx, R_028D8C_CB_COLOR5_BASE); - cb[6] = r600_context_reg_bo(ctx, R_028DC8_CB_COLOR6_BASE); - cb[7] = r600_context_reg_bo(ctx, R_028E04_CB_COLOR7_BASE); - cb[8] = r600_context_reg_bo(ctx, R_028E40_CB_COLOR8_BASE); - cb[9] = r600_context_reg_bo(ctx, R_028E5C_CB_COLOR9_BASE); - cb[10] = r600_context_reg_bo(ctx, R_028E78_CB_COLOR10_BASE); - cb[11] = r600_context_reg_bo(ctx, R_028E94_CB_COLOR11_BASE); - for (int i = 0; i < 12; i++) { - if (cb[i]) { - ndwords += 7; - } - } - if (db) - ndwords += 7; - /* queries need some special values */ if (ctx->num_query_running) { r600_context_reg(ctx, @@ -818,6 +777,10 @@ void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *dr S_02800C_NOOP_CULL_DISABLE(1)); } + /* update the max dword count to make sure we have enough space + * reserved for flushing the destination caches */ + ctx->pm4_ndwords = RADEON_CTX_MAX_PM4 - ctx->num_dest_buffers * 7 - 16; + if ((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) { /* need to flush */ r600_context_flush(ctx); @@ -852,12 +815,41 @@ void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *dr ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_num_indices; ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_draw_initiator; } - ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0, ctx->predicate_drawing); - ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0); + + ctx->flags |= (R600_CONTEXT_DRAW_PENDING | R600_CONTEXT_DST_CACHES_DIRTY); + + /* all dirty state have been scheduled in current cs */ + ctx->pm4_dirty_cdwords = 0; +} + +void evergreen_context_flush_dest_caches(struct r600_context *ctx) +{ + struct r600_bo *cb[12]; + struct r600_bo *db; + + if (!(ctx->flags & R600_CONTEXT_DST_CACHES_DIRTY)) + return; + + /* find number of color buffer */ + db = r600_context_reg_bo(ctx, R_028048_DB_Z_READ_BASE); + cb[0] = r600_context_reg_bo(ctx, R_028C60_CB_COLOR0_BASE); + cb[1] = r600_context_reg_bo(ctx, R_028C9C_CB_COLOR1_BASE); + cb[2] = r600_context_reg_bo(ctx, R_028CD8_CB_COLOR2_BASE); + cb[3] = r600_context_reg_bo(ctx, R_028D14_CB_COLOR3_BASE); + cb[4] = r600_context_reg_bo(ctx, R_028D50_CB_COLOR4_BASE); + cb[5] = r600_context_reg_bo(ctx, R_028D8C_CB_COLOR5_BASE); + cb[6] = r600_context_reg_bo(ctx, R_028DC8_CB_COLOR6_BASE); + cb[7] = r600_context_reg_bo(ctx, R_028E04_CB_COLOR7_BASE); + cb[8] = r600_context_reg_bo(ctx, R_028E40_CB_COLOR8_BASE); + cb[9] = r600_context_reg_bo(ctx, R_028E5C_CB_COLOR9_BASE); + cb[10] = r600_context_reg_bo(ctx, R_028E78_CB_COLOR10_BASE); + cb[11] = r600_context_reg_bo(ctx, R_028E94_CB_COLOR11_BASE); /* flush color buffer */ for (int i = 0; i < 12; i++) { if (cb[i]) { + unsigned flush; + if (i > 7) { flush = (S_0085F0_CB8_DEST_BASE_ENA(1) << (i - 8)) | S_0085F0_CB_ACTION_ENA(1); @@ -875,7 +867,6 @@ void evergreen_context_draw(struct r600_context *ctx, const struct r600_draw *dr 0, db); } - /* all dirty state have been scheduled in current cs */ - ctx->pm4_dirty_cdwords = 0; + ctx->flags &= ~R600_CONTEXT_DST_CACHES_DIRTY; } diff --git a/src/gallium/winsys/r600/drm/r600_drm.c b/src/gallium/winsys/r600/drm/r600_drm.c index c081abb4dcd..ddd8ee3d6dd 100644 --- a/src/gallium/winsys/r600/drm/r600_drm.c +++ b/src/gallium/winsys/r600/drm/r600_drm.c @@ -30,6 +30,7 @@ #include <sys/ioctl.h> #include "util/u_inlines.h" #include "util/u_debug.h" +#include "util/u_hash_table.h" #include <pipebuffer/pb_bufmgr.h> #include "r600.h" #include "r600_priv.h" @@ -242,6 +243,18 @@ static int radeon_init_fence(struct radeon *radeon) return 0; } +#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x))) + +static unsigned handle_hash(void *key) +{ + return PTR_TO_UINT(key); +} + +static int handle_compare(void *key1, void *key2) +{ + return PTR_TO_UINT(key1) != PTR_TO_UINT(key2); +} + static struct radeon *radeon_new(int fd, unsigned device) { struct radeon *radeon; @@ -340,6 +353,9 @@ static struct radeon *radeon_new(int fd, unsigned device) radeon_decref(radeon); return NULL; } + + radeon->bo_handles = util_hash_table_create(handle_hash, handle_compare); + pipe_mutex_init(radeon->bo_handles_mutex); return radeon; } @@ -356,6 +372,8 @@ struct radeon *radeon_decref(struct radeon *radeon) return NULL; } + util_hash_table_destroy(radeon->bo_handles); + pipe_mutex_destroy(radeon->bo_handles_mutex); if (radeon->fence_bo) { r600_bo_reference(radeon, &radeon->fence_bo, NULL); } diff --git a/src/gallium/winsys/r600/drm/r600_hw_context.c b/src/gallium/winsys/r600/drm/r600_hw_context.c index a7c21784e51..662455be28c 100644 --- a/src/gallium/winsys/r600/drm/r600_hw_context.c +++ b/src/gallium/winsys/r600/drm/r600_hw_context.c @@ -106,16 +106,22 @@ int r600_context_add_block(struct r600_context *ctx, const struct r600_reg *reg, } /* initialize block */ + block->status |= R600_BLOCK_STATUS_DIRTY; /* dirty all blocks at start */ block->start_offset = reg[i].offset; block->pm4[block->pm4_ndwords++] = PKT3(reg[i].opcode, n, 0); block->pm4[block->pm4_ndwords++] = (block->start_offset - reg[i].offset_base) >> 2; block->reg = &block->pm4[block->pm4_ndwords]; block->pm4_ndwords += n; block->nreg = n; + block->nreg_dirty = n; + block->flags = 0; LIST_INITHEAD(&block->list); for (j = 0; j < n; j++) { - if (reg[i+j].need_bo) { + if (reg[i+j].flags & REG_FLAG_DIRTY_ALWAYS) { + block->flags |= REG_FLAG_DIRTY_ALWAYS; + } + if (reg[i+j].flags & REG_FLAG_NEED_BO) { block->nbo++; assert(block->nbo < R600_BLOCK_MAX_BO); block->pm4_bo_index[j] = block->nbo; @@ -191,97 +197,97 @@ static const struct r600_reg r600_context_reg_list[] = { {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028028_DB_STENCIL_CLEAR, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02802C_DB_DEPTH_CLEAR, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028040_CB_COLOR0_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028040_CB_COLOR0_BASE, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A0_CB_COLOR0_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A0_CB_COLOR0_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028060_CB_COLOR0_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028080_CB_COLOR0_VIEW, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E0_CB_COLOR0_FRAG, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E0_CB_COLOR0_FRAG, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C0_CB_COLOR0_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C0_CB_COLOR0_TILE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028100_CB_COLOR0_MASK, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028044_CB_COLOR1_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028044_CB_COLOR1_BASE, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A4_CB_COLOR1_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A4_CB_COLOR1_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028064_CB_COLOR1_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028084_CB_COLOR1_VIEW, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E4_CB_COLOR1_FRAG, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E4_CB_COLOR1_FRAG, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C4_CB_COLOR1_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C4_CB_COLOR1_TILE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028104_CB_COLOR1_MASK, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028048_CB_COLOR2_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028048_CB_COLOR2_BASE, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A8_CB_COLOR2_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280A8_CB_COLOR2_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028068_CB_COLOR2_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028088_CB_COLOR2_VIEW, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E8_CB_COLOR2_FRAG, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280E8_CB_COLOR2_FRAG, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C8_CB_COLOR2_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280C8_CB_COLOR2_TILE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028108_CB_COLOR2_MASK, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02804C_CB_COLOR3_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02804C_CB_COLOR3_BASE, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280AC_CB_COLOR3_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280AC_CB_COLOR3_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02806C_CB_COLOR3_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02808C_CB_COLOR3_VIEW, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280EC_CB_COLOR3_FRAG, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280EC_CB_COLOR3_FRAG, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280CC_CB_COLOR3_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280CC_CB_COLOR3_TILE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02810C_CB_COLOR3_MASK, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028050_CB_COLOR4_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028050_CB_COLOR4_BASE, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B0_CB_COLOR4_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B0_CB_COLOR4_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028070_CB_COLOR4_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028090_CB_COLOR4_VIEW, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F0_CB_COLOR4_FRAG, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F0_CB_COLOR4_FRAG, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D0_CB_COLOR4_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D0_CB_COLOR4_TILE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028110_CB_COLOR4_MASK, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028054_CB_COLOR5_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028054_CB_COLOR5_BASE, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B4_CB_COLOR5_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B4_CB_COLOR5_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028074_CB_COLOR5_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028094_CB_COLOR5_VIEW, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F4_CB_COLOR5_FRAG, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F4_CB_COLOR5_FRAG, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D4_CB_COLOR5_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D4_CB_COLOR5_TILE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028114_CB_COLOR5_MASK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028058_CB_COLOR6_BASE, 1, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B8_CB_COLOR6_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028058_CB_COLOR6_BASE, REG_FLAG_NEED_BO, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280B8_CB_COLOR6_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028078_CB_COLOR6_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028098_CB_COLOR6_VIEW, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F8_CB_COLOR6_FRAG, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280F8_CB_COLOR6_FRAG, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D8_CB_COLOR6_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280D8_CB_COLOR6_TILE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028118_CB_COLOR6_MASK, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02805C_CB_COLOR7_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02805C_CB_COLOR7_BASE, REG_FLAG_NEED_BO, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280BC_CB_COLOR7_INFO, 1, 0, 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280BC_CB_COLOR7_INFO, REG_FLAG_NEED_BO, 0, 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02807C_CB_COLOR7_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02809C_CB_COLOR7_VIEW, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280FC_CB_COLOR7_FRAG, 1, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280DC_CB_COLOR7_TILE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280FC_CB_COLOR7_FRAG, REG_FLAG_NEED_BO, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0280DC_CB_COLOR7_TILE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02811C_CB_COLOR7_MASK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028120_CB_CLEAR_RED, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028124_CB_CLEAR_GREEN, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028128_CB_CLEAR_BLUE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02812C_CB_CLEAR_ALPHA, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028140_ALU_CONST_BUFFER_SIZE_PS_0, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028180_ALU_CONST_BUFFER_SIZE_VS_0, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028940_ALU_CONST_CACHE_PS_0, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028980_ALU_CONST_CACHE_VS_0, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028140_ALU_CONST_BUFFER_SIZE_PS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028180_ALU_CONST_BUFFER_SIZE_VS_0, REG_FLAG_DIRTY_ALWAYS, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028940_ALU_CONST_CACHE_PS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028980_ALU_CONST_CACHE_VS_0, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02823C_CB_SHADER_MASK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028238_CB_TARGET_MASK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028410_SX_ALPHA_TEST_CONTROL, 0, 0, 0}, @@ -321,11 +327,11 @@ static const struct r600_reg r600_context_reg_list[] = { {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028C48_PA_SC_AA_MASK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D2C_DB_SRESULTS_COMPARE_STATE1, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D44_DB_ALPHA_TO_MASK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02800C_DB_DEPTH_BASE, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_02800C_DB_DEPTH_BASE, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028000_DB_DEPTH_SIZE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028004_DB_DEPTH_VIEW, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028010_DB_DEPTH_INFO, 1, 0, 0}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028010_DB_DEPTH_INFO, REG_FLAG_NEED_BO, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D0C_DB_RENDER_CONTROL, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D10_DB_RENDER_OVERRIDE, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028D24_DB_HTILE_SURFACE, 0, 0, 0}, @@ -449,11 +455,11 @@ static const struct r600_reg r600_context_reg_list[] = { {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028638_SPI_VS_OUT_ID_9, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286C4_SPI_VS_OUT_CONFIG, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028858_SQ_PGM_START_VS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028858_SQ_PGM_START_VS, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028868_SQ_PGM_RESOURCES_VS, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028894_SQ_PGM_START_FS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028894_SQ_PGM_START_FS, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288A4_SQ_PGM_RESOURCES_FS, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0288D0_SQ_PGM_CF_OFFSET_VS, 0, 0, 0}, @@ -494,7 +500,7 @@ static const struct r600_reg r600_context_reg_list[] = { {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286D0_SPI_PS_IN_CONTROL_1, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_0286D8_SPI_INPUT_Z, 0, 0, 0}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, - {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028840_SQ_PGM_START_PS, 1, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028840_SQ_PGM_START_PS, REG_FLAG_NEED_BO, S_0085F0_SH_ACTION_ENA(1), 0xFFFFFFFF}, {0, 0, GROUP_FORCE_NEW_BLOCK, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028850_SQ_PGM_RESOURCES_PS, 0, 0, 0}, {PKT3_SET_CONTEXT_REG, R600_CONTEXT_REG_OFFSET, R_028854_SQ_PGM_EXPORTS_PS, 0, 0, 0}, @@ -515,8 +521,8 @@ static int r600_state_resource_init(struct r600_context *ctx, u32 offset) struct r600_reg r600_shader_resource[] = { {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038000_RESOURCE0_WORD0, 0, 0, 0}, {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038004_RESOURCE0_WORD1, 0, 0, 0}, - {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038008_RESOURCE0_WORD2, 1, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, - {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_03800C_RESOURCE0_WORD3, 1, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038008_RESOURCE0_WORD2, REG_FLAG_NEED_BO, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, + {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_03800C_RESOURCE0_WORD3, REG_FLAG_NEED_BO, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_VC_ACTION_ENA(1), 0xFFFFFFFF}, {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038010_RESOURCE0_WORD4, 0, 0, 0}, {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038014_RESOURCE0_WORD5, 0, 0, 0}, {PKT3_SET_RESOURCE, R600_RESOURCE_OFFSET, R_038018_RESOURCE0_WORD6, 0, 0, 0}, @@ -572,7 +578,7 @@ static int r600_loop_const_init(struct r600_context *ctx, u32 offset) r600_loop_consts[i].opcode = PKT3_SET_LOOP_CONST; r600_loop_consts[i].offset_base = R600_LOOP_CONST_OFFSET; r600_loop_consts[i].offset = R600_LOOP_CONST_OFFSET + ((offset + i) * 4); - r600_loop_consts[i].need_bo = 0; + r600_loop_consts[i].flags = REG_FLAG_DIRTY_ALWAYS; r600_loop_consts[i].flush_flags = 0; r600_loop_consts[i].flush_mask = 0; } @@ -771,14 +777,30 @@ static void rv6xx_context_surface_base_update(struct r600_context *ctx, } } +/* Flushes all surfaces */ +void r600_context_flush_all(struct r600_context *ctx, unsigned flush_flags) +{ + unsigned ndwords = 5; + + if ((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) { + /* need to flush */ + r600_context_flush(ctx); + } + + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_SURFACE_SYNC, 3, ctx->predicate_drawing); + ctx->pm4[ctx->pm4_cdwords++] = flush_flags; /* CP_COHER_CNTL */ + ctx->pm4[ctx->pm4_cdwords++] = 0xffffffff; /* CP_COHER_SIZE */ + ctx->pm4[ctx->pm4_cdwords++] = 0; /* CP_COHER_BASE */ + ctx->pm4[ctx->pm4_cdwords++] = 0x0000000A; /* POLL_INTERVAL */ +} + void r600_context_bo_flush(struct r600_context *ctx, unsigned flush_flags, unsigned flush_mask, struct r600_bo *rbo) { struct radeon_bo *bo; - bo = r600_bo_get_bo(rbo); - /* if bo has already been flush */ - if (!(bo->last_flush ^ flush_flags)) { + /* if bo has already been flushed */ + if (!(~bo->last_flush & flush_flags)) { bo->last_flush &= flush_mask; return; } @@ -815,38 +837,91 @@ void r600_context_bo_reloc(struct r600_context *ctx, u32 *pm4, struct r600_bo *r *pm4 = bo->reloc_id; } -void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state) +void r600_context_reg(struct r600_context *ctx, + unsigned offset, unsigned value, + unsigned mask) { struct r600_range *range; struct r600_block *block; + unsigned id; + unsigned new_val; + int dirty; + + range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; + block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; + id = (offset - block->start_offset) >> 2; + + dirty = block->status & R600_BLOCK_STATUS_DIRTY; + + new_val = block->reg[id]; + new_val &= ~mask; + new_val |= value; + if (new_val != block->reg[id]) { + dirty |= R600_BLOCK_STATUS_DIRTY; + block->reg[id] = new_val; + } + r600_context_dirty_block(ctx, block, dirty, id); +} +void r600_context_dirty_block(struct r600_context *ctx, struct r600_block *block, + int dirty, int index) +{ + if (dirty && (index + 1) > block->nreg_dirty) + block->nreg_dirty = index + 1; + + if ((dirty != (block->status & R600_BLOCK_STATUS_DIRTY)) || !(block->status & R600_BLOCK_STATUS_ENABLED)) { + + block->status |= R600_BLOCK_STATUS_ENABLED; + block->status |= R600_BLOCK_STATUS_DIRTY; + ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; + LIST_ADDTAIL(&block->list,&ctx->dirty); + } +} + +void r600_context_pipe_state_set(struct r600_context *ctx, struct r600_pipe_state *state) +{ + struct r600_range *range; + struct r600_block *block; + unsigned new_val; + int dirty; for (int i = 0; i < state->nregs; i++) { - unsigned id; + unsigned id, reloc_id; range = &ctx->range[CTX_RANGE_ID(ctx, state->regs[i].offset)]; block = range->blocks[CTX_BLOCK_ID(ctx, state->regs[i].offset)]; id = (state->regs[i].offset - block->start_offset) >> 2; - block->reg[id] &= ~state->regs[i].mask; - block->reg[id] |= state->regs[i].value; + + dirty = block->status & R600_BLOCK_STATUS_DIRTY; + + new_val = block->reg[id]; + new_val &= ~state->regs[i].mask; + new_val |= state->regs[i].value; + if (new_val != block->reg[id]) { + block->reg[id] = new_val; + dirty |= R600_BLOCK_STATUS_DIRTY; + } + if (block->flags & REG_FLAG_DIRTY_ALWAYS) + dirty |= R600_BLOCK_STATUS_DIRTY; if (block->pm4_bo_index[id]) { /* find relocation */ - id = block->pm4_bo_index[id]; - r600_bo_reference(ctx->radeon, &block->reloc[id].bo, state->regs[i].bo); + reloc_id = block->pm4_bo_index[id]; + r600_bo_reference(ctx->radeon, &block->reloc[reloc_id].bo, state->regs[i].bo); state->regs[i].bo->fence = ctx->radeon->fence; + /* always force dirty for relocs for now */ + dirty |= R600_BLOCK_STATUS_DIRTY; } - if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { - block->status |= R600_BLOCK_STATUS_ENABLED; - block->status |= R600_BLOCK_STATUS_DIRTY; - ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; - LIST_ADDTAIL(&block->list,&ctx->dirty); - } + + r600_context_dirty_block(ctx, block, dirty, id); } } -static inline void r600_context_pipe_state_set_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) +void r600_context_pipe_state_set_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) { struct r600_range *range; struct r600_block *block; + int i; + int dirty; + int num_regs = ctx->radeon->chip_class >= EVERGREEN ? 8 : 7; range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; @@ -857,35 +932,57 @@ static inline void r600_context_pipe_state_set_resource(struct r600_context *ctx LIST_DELINIT(&block->list); return; } - block->reg[0] = state->regs[0].value; - block->reg[1] = state->regs[1].value; - block->reg[2] = state->regs[2].value; - block->reg[3] = state->regs[3].value; - block->reg[4] = state->regs[4].value; - block->reg[5] = state->regs[5].value; - block->reg[6] = state->regs[6].value; - r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); - r600_bo_reference(ctx->radeon , &block->reloc[2].bo, NULL); - if (state->regs[0].bo) { - /* VERTEX RESOURCE, we preted there is 2 bo to relocate so - * we have single case btw VERTEX & TEXTURE resource - */ - r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[0].bo); - r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[0].bo); - state->regs[0].bo->fence = ctx->radeon->fence; - } else { - /* TEXTURE RESOURCE */ - r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[2].bo); - r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[3].bo); - state->regs[2].bo->fence = ctx->radeon->fence; - state->regs[3].bo->fence = ctx->radeon->fence; + + dirty = block->status & R600_BLOCK_STATUS_DIRTY; + + for (i = 0; i < num_regs; i++) { + if (block->reg[i] != state->regs[i].value) { + dirty |= R600_BLOCK_STATUS_DIRTY; + block->reg[i] = state->regs[i].value; + } } - if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { - block->status |= R600_BLOCK_STATUS_ENABLED; - block->status |= R600_BLOCK_STATUS_DIRTY; - ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; - LIST_ADDTAIL(&block->list,&ctx->dirty); + + /* if no BOs on block, force dirty */ + if (!block->reloc[1].bo || !block->reloc[2].bo) + dirty |= R600_BLOCK_STATUS_DIRTY; + + if (!dirty) { + if (state->regs[0].bo) { + if ((block->reloc[1].bo->bo->handle != state->regs[0].bo->bo->handle) || + (block->reloc[2].bo->bo->handle != state->regs[0].bo->bo->handle)) + dirty |= R600_BLOCK_STATUS_DIRTY; + } else { + if ((block->reloc[1].bo->bo->handle != state->regs[2].bo->bo->handle) || + (block->reloc[2].bo->bo->handle != state->regs[3].bo->bo->handle)) + dirty |= R600_BLOCK_STATUS_DIRTY; + } } + if (!dirty) { + if (state->regs[0].bo) + state->regs[0].bo->fence = ctx->radeon->fence; + else { + state->regs[2].bo->fence = ctx->radeon->fence; + state->regs[3].bo->fence = ctx->radeon->fence; + } + } else { + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, NULL); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, NULL); + if (state->regs[0].bo) { + /* VERTEX RESOURCE, we preted there is 2 bo to relocate so + * we have single case btw VERTEX & TEXTURE resource + */ + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[0].bo); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[0].bo); + state->regs[0].bo->fence = ctx->radeon->fence; + } else { + /* TEXTURE RESOURCE */ + r600_bo_reference(ctx->radeon, &block->reloc[1].bo, state->regs[2].bo); + r600_bo_reference(ctx->radeon, &block->reloc[2].bo, state->regs[3].bo); + state->regs[2].bo->fence = ctx->radeon->fence; + state->regs[3].bo->fence = ctx->radeon->fence; + } + } + r600_context_dirty_block(ctx, block, dirty, num_regs - 1); } void r600_context_pipe_state_set_ps_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned rid) @@ -913,6 +1010,8 @@ static inline void r600_context_pipe_state_set_sampler(struct r600_context *ctx, { struct r600_range *range; struct r600_block *block; + int i; + int dirty; range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; @@ -921,21 +1020,34 @@ static inline void r600_context_pipe_state_set_sampler(struct r600_context *ctx, LIST_DELINIT(&block->list); return; } - block->reg[0] = state->regs[0].value; - block->reg[1] = state->regs[1].value; - block->reg[2] = state->regs[2].value; - if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { - block->status |= R600_BLOCK_STATUS_ENABLED; - block->status |= R600_BLOCK_STATUS_DIRTY; - ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; - LIST_ADDTAIL(&block->list,&ctx->dirty); + dirty = block->status & R600_BLOCK_STATUS_DIRTY; + for (i = 0; i < 3; i++) { + if (block->reg[i] != state->regs[i].value) { + block->reg[i] = state->regs[i].value; + dirty |= R600_BLOCK_STATUS_DIRTY; + } } + + r600_context_dirty_block(ctx, block, dirty, 2); +} + +static inline void r600_context_ps_partial_flush(struct r600_context *ctx) +{ + if (!(ctx->flags & R600_CONTEXT_DRAW_PENDING)) + return; + + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0, 0); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_PS_PARTIAL_FLUSH) | EVENT_INDEX(4); + + ctx->flags &= ~R600_CONTEXT_DRAW_PENDING; } static inline void r600_context_pipe_state_set_sampler_border(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset) { struct r600_range *range; struct r600_block *block; + int i; + int dirty; range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; @@ -947,16 +1059,21 @@ static inline void r600_context_pipe_state_set_sampler_border(struct r600_contex if (state->nregs <= 3) { return; } - block->reg[0] = state->regs[3].value; - block->reg[1] = state->regs[4].value; - block->reg[2] = state->regs[5].value; - block->reg[3] = state->regs[6].value; - if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { - block->status |= R600_BLOCK_STATUS_ENABLED; - block->status |= R600_BLOCK_STATUS_DIRTY; - ctx->pm4_dirty_cdwords += block->pm4_ndwords + block->pm4_flush_ndwords; - LIST_ADDTAIL(&block->list,&ctx->dirty); + dirty = block->status & R600_BLOCK_STATUS_DIRTY; + for (i = 0; i < 4; i++) { + if (block->reg[i] != state->regs[i + 3].value) { + block->reg[i] = state->regs[i + 3].value; + dirty |= R600_BLOCK_STATUS_DIRTY; + } } + + /* We have to flush the shaders before we change the border color + * registers, or previous draw commands that haven't completed yet + * will end up using the new border color. */ + if (dirty & R600_BLOCK_STATUS_DIRTY) + r600_context_ps_partial_flush(ctx); + + r600_context_dirty_block(ctx, block, dirty, 3); } void r600_context_pipe_state_set_ps_sampler(struct r600_context *ctx, struct r600_pipe_state *state, unsigned id) @@ -995,24 +1112,54 @@ struct r600_bo *r600_context_reg_bo(struct r600_context *ctx, unsigned offset) return NULL; } -void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw) +void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *block) { - struct r600_bo *cb[8]; - struct r600_bo *db; - unsigned ndwords = 9; - struct r600_block *dirty_block = NULL; - struct r600_block *next_block; - unsigned rv6xx_surface_base_update = 0; + int id; - if (draw->indices) { - ndwords = 13; - /* make sure there is enough relocation space before scheduling draw */ - if (ctx->creloc >= (ctx->nreloc - 1)) { - r600_context_flush(ctx); + if (block->nreg_dirty == 0 && block->nbo == 0 && !(block->flags & REG_FLAG_DIRTY_ALWAYS)) { + goto out; + } + + for (int j = 0; j < block->nreg; j++) { + if (block->pm4_bo_index[j]) { + /* find relocation */ + id = block->pm4_bo_index[j]; + r600_context_bo_reloc(ctx, + &block->pm4[block->reloc[id].bo_pm4_index], + block->reloc[id].bo); + r600_context_bo_flush(ctx, + block->reloc[id].flush_flags, + block->reloc[id].flush_mask, + block->reloc[id].bo); } } + memcpy(&ctx->pm4[ctx->pm4_cdwords], block->pm4, block->pm4_ndwords * 4); + ctx->pm4_cdwords += block->pm4_ndwords; + + if (block->nreg_dirty != block->nreg && block->nbo == 0 && !(block->flags & REG_FLAG_DIRTY_ALWAYS)) { + int new_dwords = block->nreg_dirty; + uint32_t oldword, newword; + ctx->pm4_cdwords -= block->pm4_ndwords; + newword = oldword = ctx->pm4[ctx->pm4_cdwords]; + newword &= PKT_COUNT_C; + newword |= PKT_COUNT_S(new_dwords); + ctx->pm4[ctx->pm4_cdwords] = newword; + ctx->pm4_cdwords += new_dwords + 2; + } +out: + block->status ^= R600_BLOCK_STATUS_DIRTY; + block->nreg_dirty = 0; + LIST_DELINIT(&block->list); +} + +void r600_context_flush_dest_caches(struct r600_context *ctx) +{ + struct r600_bo *cb[8]; + struct r600_bo *db; + + if (!(ctx->flags & R600_CONTEXT_DST_CACHES_DIRTY)) + return; - /* find number of color buffer */ db = r600_context_reg_bo(ctx, R_02800C_DB_DEPTH_BASE); cb[0] = r600_context_reg_bo(ctx, R_028040_CB_COLOR0_BASE); cb[1] = r600_context_reg_bo(ctx, R_028044_CB_COLOR1_BASE); @@ -1022,16 +1169,64 @@ void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw) cb[5] = r600_context_reg_bo(ctx, R_028054_CB_COLOR5_BASE); cb[6] = r600_context_reg_bo(ctx, R_028058_CB_COLOR6_BASE); cb[7] = r600_context_reg_bo(ctx, R_02805C_CB_COLOR7_BASE); + + /* flush the color buffers */ for (int i = 0; i < 8; i++) { - if (cb[i]) { - ndwords += 7; - rv6xx_surface_base_update |= SURFACE_BASE_UPDATE_COLOR(i); - } + if (!cb[i]) + continue; + + r600_context_bo_flush(ctx, + (S_0085F0_CB0_DEST_BASE_ENA(1) << i) | + S_0085F0_CB_ACTION_ENA(1), + 0, cb[i]); } if (db) { - ndwords += 7; - rv6xx_surface_base_update |= SURFACE_BASE_UPDATE_DEPTH; + r600_context_bo_flush(ctx, S_0085F0_DB_ACTION_ENA(1), 0, db); + } + + ctx->flags &= ~R600_CONTEXT_DST_CACHES_DIRTY; +} + +void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw) +{ + unsigned ndwords = 7; + struct r600_block *dirty_block = NULL; + struct r600_block *next_block; + unsigned rv6xx_surface_base_update = 0; + + if (draw->indices) { + ndwords = 11; + /* make sure there is enough relocation space before scheduling draw */ + if (ctx->creloc >= (ctx->nreloc - 1)) { + r600_context_flush(ctx); + } } + + /* rv6xx surface base update */ + if ((ctx->radeon->family > CHIP_R600) && + (ctx->radeon->family < CHIP_RV770)) { + struct r600_bo *cb[8]; + struct r600_bo *db; + + db = r600_context_reg_bo(ctx, R_02800C_DB_DEPTH_BASE); + cb[0] = r600_context_reg_bo(ctx, R_028040_CB_COLOR0_BASE); + cb[1] = r600_context_reg_bo(ctx, R_028044_CB_COLOR1_BASE); + cb[2] = r600_context_reg_bo(ctx, R_028048_CB_COLOR2_BASE); + cb[3] = r600_context_reg_bo(ctx, R_02804C_CB_COLOR3_BASE); + cb[4] = r600_context_reg_bo(ctx, R_028050_CB_COLOR4_BASE); + cb[5] = r600_context_reg_bo(ctx, R_028054_CB_COLOR5_BASE); + cb[6] = r600_context_reg_bo(ctx, R_028058_CB_COLOR6_BASE); + cb[7] = r600_context_reg_bo(ctx, R_02805C_CB_COLOR7_BASE); + for (int i = 0; i < 8; i++) { + if (cb[i]) { + rv6xx_surface_base_update |= SURFACE_BASE_UPDATE_COLOR(i); + } + } + if (db) { + rv6xx_surface_base_update |= SURFACE_BASE_UPDATE_DEPTH; + } + } + /* XXX also need to update SURFACE_BASE_UPDATE_STRMOUT when we support it */ /* queries need some special values */ @@ -1048,6 +1243,10 @@ void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw) S_028D10_NOOP_CULL_DISABLE(1)); } + /* update the max dword count to make sure we have enough space + * reserved for flushing the destination caches */ + ctx->pm4_ndwords = RADEON_CTX_MAX_PM4 - ctx->num_dest_buffers * 7 - 16; + if ((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) { /* need to flush */ r600_context_flush(ctx); @@ -1057,7 +1256,6 @@ void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw) R600_ERR("context is too big to be scheduled\n"); return; } - /* enough room to copy packet */ LIST_FOR_EACH_ENTRY_SAFE(dirty_block, next_block, &ctx->dirty, list) { r600_context_block_emit_dirty(ctx, dirty_block); @@ -1086,21 +1284,8 @@ void r600_context_draw(struct r600_context *ctx, const struct r600_draw *draw) ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_num_indices; ctx->pm4[ctx->pm4_cdwords++] = draw->vgt_draw_initiator; } - ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0, ctx->predicate_drawing); - ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_EVENT) | EVENT_INDEX(0); - /* flush color buffer */ - for (int i = 0; i < 8; i++) { - if (cb[i]) { - r600_context_bo_flush(ctx, - (S_0085F0_CB0_DEST_BASE_ENA(1) << i) | - S_0085F0_CB_ACTION_ENA(1), - 0, cb[i]); - } - } - if (db) { - r600_context_bo_flush(ctx, S_0085F0_DB_ACTION_ENA(1), 0, db); - } + ctx->flags |= (R600_CONTEXT_DST_CACHES_DIRTY | R600_CONTEXT_DRAW_PENDING); /* all dirty state have been scheduled in current cs */ ctx->pm4_dirty_cdwords = 0; @@ -1120,9 +1305,15 @@ void r600_context_flush(struct r600_context *ctx) /* suspend queries */ r600_context_queries_suspend(ctx); - /* emit fence */ + if (ctx->radeon->family >= CHIP_CEDAR) + evergreen_context_flush_dest_caches(ctx); + else + r600_context_flush_dest_caches(ctx); + + /* partial flush is needed to avoid lockups on some chips with user fences */ ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0, 0); ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_PS_PARTIAL_FLUSH) | EVENT_INDEX(4); + /* emit fence */ ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE_EOP, 4, 0); ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5); ctx->pm4[ctx->pm4_cdwords++] = 0; @@ -1170,6 +1361,7 @@ void r600_context_flush(struct r600_context *ctx) ctx->creloc = 0; ctx->pm4_dirty_cdwords = 0; ctx->pm4_cdwords = 0; + ctx->flags = 0; /* resume queries */ r600_context_queries_resume(ctx); @@ -1184,10 +1376,34 @@ void r600_context_flush(struct r600_context *ctx) } ctx->pm4_dirty_cdwords += ctx->blocks[i]->pm4_ndwords + ctx->blocks[i]->pm4_flush_ndwords; ctx->blocks[i]->status |= R600_BLOCK_STATUS_DIRTY; + ctx->blocks[i]->nreg_dirty = ctx->blocks[i]->nreg; } } } +void r600_context_emit_fence(struct r600_context *ctx, struct r600_bo *fence_bo, unsigned offset, unsigned value) +{ + unsigned ndwords = 10; + + if (((ctx->pm4_dirty_cdwords + ndwords + ctx->pm4_cdwords) > ctx->pm4_ndwords) || + (ctx->creloc >= (ctx->nreloc - 1))) { + /* need to flush */ + r600_context_flush(ctx); + } + + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE, 0, 0); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_PS_PARTIAL_FLUSH) | EVENT_INDEX(4); + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_EVENT_WRITE_EOP, 4, 0); + ctx->pm4[ctx->pm4_cdwords++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_TS_EVENT) | EVENT_INDEX(5); + ctx->pm4[ctx->pm4_cdwords++] = offset << 2; /* ADDRESS_LO */ + ctx->pm4[ctx->pm4_cdwords++] = (1 << 29) | (0 << 24); /* DATA_SEL | INT_EN | ADDRESS_HI */ + ctx->pm4[ctx->pm4_cdwords++] = value; /* DATA_LO */ + ctx->pm4[ctx->pm4_cdwords++] = 0; /* DATA_HI */ + ctx->pm4[ctx->pm4_cdwords++] = PKT3(PKT3_NOP, 0, 0); + ctx->pm4[ctx->pm4_cdwords++] = 0; + r600_context_bo_reloc(ctx, &ctx->pm4[ctx->pm4_cdwords - 1], fence_bo); +} + void r600_context_dump_bof(struct r600_context *ctx, const char *file) { bof_t *bcs, *blob, *array, *bo, *size, *handle, *device_id, *root; diff --git a/src/gallium/winsys/r600/drm/r600_priv.h b/src/gallium/winsys/r600/drm/r600_priv.h index 41c5ee02c38..ed0f3e584d3 100644 --- a/src/gallium/winsys/r600/drm/r600_priv.h +++ b/src/gallium/winsys/r600/drm/r600_priv.h @@ -32,9 +32,13 @@ #include <assert.h> #include <util/u_double_list.h> #include <util/u_inlines.h> +#include "util/u_hash_table.h" #include <os/os_thread.h> #include "r600.h" +#define PKT_COUNT_C 0xC000FFFF +#define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16) + struct r600_bomgr; struct r600_bo; @@ -52,13 +56,20 @@ struct radeon { unsigned clock_crystal_freq; unsigned num_backends; unsigned minor_version; + + /* List of buffer handles and its mutex. */ + struct util_hash_table *bo_handles; + pipe_mutex bo_handles_mutex; }; +#define REG_FLAG_NEED_BO 1 +#define REG_FLAG_DIRTY_ALWAYS 2 + struct r600_reg { unsigned opcode; unsigned offset_base; unsigned offset; - unsigned need_bo; + unsigned flags; unsigned flush_flags; unsigned flush_mask; }; @@ -77,6 +88,7 @@ struct radeon_bo { struct r600_reloc *reloc; unsigned reloc_id; unsigned last_flush; + unsigned name; }; struct r600_bo { @@ -142,7 +154,14 @@ void r600_context_bo_flush(struct r600_context *ctx, unsigned flush_flags, unsigned flush_mask, struct r600_bo *rbo); struct r600_bo *r600_context_reg_bo(struct r600_context *ctx, unsigned offset); int r600_context_add_block(struct r600_context *ctx, const struct r600_reg *reg, unsigned nreg); - +void r600_context_pipe_state_set_resource(struct r600_context *ctx, struct r600_pipe_state *state, unsigned offset); +void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *block); +void r600_context_dirty_block(struct r600_context *ctx, struct r600_block *block, + int dirty, int index); + +void r600_context_reg(struct r600_context *ctx, + unsigned offset, unsigned value, + unsigned mask); /* * r600_bo.c */ @@ -167,50 +186,6 @@ struct r600_bo *r600_bomgr_bo_create(struct r600_bomgr *mgr, #define CTX_RANGE_ID(ctx, offset) (((offset) >> (ctx)->hash_shift) & 255) #define CTX_BLOCK_ID(ctx, offset) ((offset) & ((1 << (ctx)->hash_shift) - 1)) -static void inline r600_context_reg(struct r600_context *ctx, - unsigned offset, unsigned value, - unsigned mask) -{ - struct r600_range *range; - struct r600_block *block; - unsigned id; - - range = &ctx->range[CTX_RANGE_ID(ctx, offset)]; - block = range->blocks[CTX_BLOCK_ID(ctx, offset)]; - id = (offset - block->start_offset) >> 2; - block->reg[id] &= ~mask; - block->reg[id] |= value; - if (!(block->status & R600_BLOCK_STATUS_DIRTY)) { - ctx->pm4_dirty_cdwords += block->pm4_ndwords; - block->status |= R600_BLOCK_STATUS_ENABLED; - block->status |= R600_BLOCK_STATUS_DIRTY; - LIST_ADDTAIL(&block->list,&ctx->dirty); - } -} - -static inline void r600_context_block_emit_dirty(struct r600_context *ctx, struct r600_block *block) -{ - int id; - - for (int j = 0; j < block->nreg; j++) { - if (block->pm4_bo_index[j]) { - /* find relocation */ - id = block->pm4_bo_index[j]; - r600_context_bo_reloc(ctx, - &block->pm4[block->reloc[id].bo_pm4_index], - block->reloc[id].bo); - r600_context_bo_flush(ctx, - block->reloc[id].flush_flags, - block->reloc[id].flush_mask, - block->reloc[id].bo); - } - } - memcpy(&ctx->pm4[ctx->pm4_cdwords], block->pm4, block->pm4_ndwords * 4); - ctx->pm4_cdwords += block->pm4_ndwords; - block->status ^= R600_BLOCK_STATUS_DIRTY; - LIST_DELINIT(&block->list); -} - /* * radeon_bo.c */ diff --git a/src/gallium/winsys/r600/drm/radeon_bo.c b/src/gallium/winsys/r600/drm/radeon_bo.c index 3643ddbcb93..13b1d50b6e5 100644 --- a/src/gallium/winsys/r600/drm/radeon_bo.c +++ b/src/gallium/winsys/r600/drm/radeon_bo.c @@ -74,6 +74,16 @@ struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle, struct radeon_bo *bo; int r; + if (handle) { + pipe_mutex_lock(radeon->bo_handles_mutex); + bo = util_hash_table_get(radeon->bo_handles, + (void *)(uintptr_t)handle); + if (bo) { + struct radeon_bo *b = NULL; + radeon_bo_reference(radeon, &b, bo); + goto done; + } + } bo = calloc(1, sizeof(*bo)); if (bo == NULL) { return NULL; @@ -94,6 +104,7 @@ struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle, free(bo); return NULL; } + bo->name = handle; bo->handle = open_arg.handle; bo->size = open_arg.size; bo->shared = TRUE; @@ -121,6 +132,13 @@ struct radeon_bo *radeon_bo(struct radeon *radeon, unsigned handle, radeon_bo_reference(radeon, &bo, NULL); return bo; } + + if (handle) + util_hash_table_set(radeon->bo_handles, (void *)(uintptr_t)handle, bo); +done: + if (handle) + pipe_mutex_unlock(radeon->bo_handles_mutex); + return bo; } @@ -128,6 +146,12 @@ static void radeon_bo_destroy(struct radeon *radeon, struct radeon_bo *bo) { struct drm_gem_close args; + if (bo->name) { + pipe_mutex_lock(radeon->bo_handles_mutex); + util_hash_table_remove(radeon->bo_handles, + (void *)(uintptr_t)bo->name); + pipe_mutex_unlock(radeon->bo_handles_mutex); + } LIST_DEL(&bo->fencedlist); radeon_bo_fixed_unmap(radeon, bo); memset(&args, 0, sizeof(args)); diff --git a/src/gallium/winsys/r600/drm/radeon_pciid.c b/src/gallium/winsys/r600/drm/radeon_pciid.c index f19956931de..146d6bd3100 100644 --- a/src/gallium/winsys/r600/drm/radeon_pciid.c +++ b/src/gallium/winsys/r600/drm/radeon_pciid.c @@ -445,6 +445,8 @@ static const struct pci_id radeon_pci_id[] = { {0x1002, 0x9803, CHIP_PALM}, {0x1002, 0x9804, CHIP_PALM}, {0x1002, 0x9805, CHIP_PALM}, + {0x1002, 0x9806, CHIP_PALM}, + {0x1002, 0x9807, CHIP_PALM}, {0x1002, 0x6720, CHIP_BARTS}, {0x1002, 0x6721, CHIP_BARTS}, {0x1002, 0x6722, CHIP_BARTS}, diff --git a/src/gallium/winsys/radeon/drm/Makefile b/src/gallium/winsys/radeon/drm/Makefile index e63ae6f5006..d44b7c14250 100644 --- a/src/gallium/winsys/radeon/drm/Makefile +++ b/src/gallium/winsys/radeon/drm/Makefile @@ -7,10 +7,9 @@ LIBNAME = radeonwinsys C_SOURCES = \ radeon_drm_bo.c \ radeon_drm_cs.c \ - radeon_drm_common.c + radeon_drm_winsys.c -LIBRARY_INCLUDES = -I$(TOP)/src/gallium/drivers/r300 \ - $(shell pkg-config libdrm --cflags-only-I) +LIBRARY_INCLUDES = $(shell pkg-config libdrm --cflags-only-I) include ../../../Makefile.template diff --git a/src/gallium/winsys/radeon/drm/SConscript b/src/gallium/winsys/radeon/drm/SConscript index b16e03556d3..39a8c711b84 100644 --- a/src/gallium/winsys/radeon/drm/SConscript +++ b/src/gallium/winsys/radeon/drm/SConscript @@ -5,17 +5,15 @@ env = env.Clone() radeon_sources = [ 'radeon_drm_bo.c', 'radeon_drm_cs.c', - 'radeon_drm_common.c', + 'radeon_drm_winsys.c', ] try: - env.ParseConfig('pkg-config --cflags libdrm_radeon') + env.ParseConfig('pkg-config --cflags libdrm') except: - print 'warning: not building r300g' + print 'warning: not building Gallium Radeon' Return() -env.Append(CPPPATH = '#/src/gallium/drivers/r300') - radeonwinsys = env.ConvenienceLibrary( target ='radeonwinsys', source = radeon_sources, diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c index 9eb833454df..b6f12727e81 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c @@ -87,31 +87,7 @@ static struct radeon_bo *get_radeon_bo(struct pb_buffer *_buf) return bo; } -void radeon_bo_unref(struct radeon_bo *bo) -{ - struct drm_gem_close args = {}; - - if (!p_atomic_dec_zero(&bo->ref_count)) - return; - - if (bo->name) { - pipe_mutex_lock(bo->mgr->bo_handles_mutex); - util_hash_table_remove(bo->mgr->bo_handles, - (void*)(uintptr_t)bo->name); - pipe_mutex_unlock(bo->mgr->bo_handles_mutex); - } - - if (bo->ptr) - munmap(bo->ptr, bo->size); - - /* Close object. */ - args.handle = bo->handle; - drmIoctl(bo->rws->fd, DRM_IOCTL_GEM_CLOSE, &args); - pipe_mutex_destroy(bo->map_mutex); - FREE(bo); -} - -static void radeon_bo_wait(struct r300_winsys_bo *_buf) +static void radeon_bo_wait(struct pb_buffer *_buf) { struct radeon_bo *bo = get_radeon_bo(pb_buffer(_buf)); struct drm_radeon_gem_wait_idle args = {}; @@ -123,33 +99,58 @@ static void radeon_bo_wait(struct r300_winsys_bo *_buf) args.handle = bo->handle; while (drmCommandWriteRead(bo->rws->fd, DRM_RADEON_GEM_WAIT_IDLE, &args, sizeof(args)) == -EBUSY); + + bo->busy_for_write = FALSE; } -static boolean radeon_bo_is_busy(struct r300_winsys_bo *_buf) +static boolean radeon_bo_is_busy(struct pb_buffer *_buf) { struct radeon_bo *bo = get_radeon_bo(pb_buffer(_buf)); struct drm_radeon_gem_busy args = {}; + boolean busy; if (p_atomic_read(&bo->num_active_ioctls)) { return TRUE; } args.handle = bo->handle; - return drmCommandWriteRead(bo->rws->fd, DRM_RADEON_GEM_BUSY, + busy = drmCommandWriteRead(bo->rws->fd, DRM_RADEON_GEM_BUSY, &args, sizeof(args)) != 0; + + if (!busy) + bo->busy_for_write = FALSE; + return busy; } static void radeon_bo_destroy(struct pb_buffer *_buf) { struct radeon_bo *bo = radeon_bo(_buf); + struct drm_gem_close args = {}; - radeon_bo_unref(bo); + if (bo->name) { + pipe_mutex_lock(bo->mgr->bo_handles_mutex); + util_hash_table_remove(bo->mgr->bo_handles, + (void*)(uintptr_t)bo->name); + pipe_mutex_unlock(bo->mgr->bo_handles_mutex); + } + + if (bo->ptr) + munmap(bo->ptr, bo->size); + + /* Close object. */ + args.handle = bo->handle; + drmIoctl(bo->rws->fd, DRM_IOCTL_GEM_CLOSE, &args); + pipe_mutex_destroy(bo->map_mutex); + FREE(bo); } static unsigned get_pb_usage_from_transfer_flags(enum pipe_transfer_usage usage) { unsigned res = 0; + if (usage & PIPE_TRANSFER_WRITE) + res |= PB_USAGE_CPU_WRITE; + if (usage & PIPE_TRANSFER_DONTBLOCK) res |= PB_USAGE_DONTBLOCK; @@ -172,23 +173,44 @@ static void *radeon_bo_map_internal(struct pb_buffer *_buf, /* DONTBLOCK doesn't make sense with UNSYNCHRONIZED. */ if (flags & PB_USAGE_DONTBLOCK) { if (radeon_bo_is_referenced_by_cs(cs, bo)) { - cs->flush_cs(cs->flush_data, R300_FLUSH_ASYNC); + cs->flush_cs(cs->flush_data, RADEON_FLUSH_ASYNC); return NULL; } - if (radeon_bo_is_busy((struct r300_winsys_bo*)bo)) { + if (radeon_bo_is_busy((struct pb_buffer*)bo)) { return NULL; } } else { - if (radeon_bo_is_referenced_by_cs(cs, bo)) { - cs->flush_cs(cs->flush_data, 0); + if (!(flags & PB_USAGE_CPU_WRITE)) { + /* Mapping for read. + * + * Since we are mapping for read, we don't need to wait + * if the GPU is using the buffer for read too + * (neither one is changing it). + * + * Only check whether the buffer is being used for write. */ + if (radeon_bo_is_referenced_by_cs_for_write(cs, bo)) { + cs->flush_cs(cs->flush_data, 0); + radeon_bo_wait((struct pb_buffer*)bo); + } else if (bo->busy_for_write) { + /* Update the busy_for_write field (done by radeon_bo_is_busy) + * and wait if needed. */ + if (radeon_bo_is_busy((struct pb_buffer*)bo)) { + radeon_bo_wait((struct pb_buffer*)bo); + } + } } else { - /* Try to avoid busy-waiting in radeon_bo_wait. */ - if (p_atomic_read(&bo->num_active_ioctls)) - radeon_drm_cs_sync_flush(cs); + /* Mapping for write. */ + if (radeon_bo_is_referenced_by_cs(cs, bo)) { + cs->flush_cs(cs->flush_data, 0); + } else { + /* Try to avoid busy-waiting in radeon_bo_wait. */ + if (p_atomic_read(&bo->num_active_ioctls)) + radeon_drm_cs_sync_flush(cs); + } + + radeon_bo_wait((struct pb_buffer*)bo); } - - radeon_bo_wait((struct r300_winsys_bo*)bo); } } @@ -198,6 +220,11 @@ static void *radeon_bo_map_internal(struct pb_buffer *_buf, /* Map the buffer. */ pipe_mutex_lock(bo->map_mutex); + /* Return the pointer if it's already mapped (in case of a race). */ + if (bo->ptr) { + pipe_mutex_unlock(bo->map_mutex); + return bo->ptr; + } args.handle = bo->handle; args.offset = 0; args.size = (uint64_t)bo->size; @@ -278,10 +305,10 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr, if (drmCommandWriteRead(rws->fd, DRM_RADEON_GEM_CREATE, &args, sizeof(args))) { - fprintf(stderr, "Failed to allocate :\n"); - fprintf(stderr, " size : %d bytes\n", size); - fprintf(stderr, " alignment : %d bytes\n", desc->alignment); - fprintf(stderr, " domains : %d\n", args.initial_domain); + fprintf(stderr, "radeon: Failed to allocate a buffer:\n"); + fprintf(stderr, "radeon: size : %d bytes\n", size); + fprintf(stderr, "radeon: alignment : %d bytes\n", desc->alignment); + fprintf(stderr, "radeon: domains : %d\n", args.initial_domain); return NULL; } @@ -300,7 +327,6 @@ static struct pb_buffer *radeon_bomgr_create_bo(struct pb_manager *_mgr, bo->size = size; pipe_mutex_init(bo->map_mutex); - radeon_bo_ref(bo); return &bo->base; } @@ -319,7 +345,7 @@ static boolean radeon_bomgr_is_buffer_busy(struct pb_manager *_mgr, return TRUE; } - if (radeon_bo_is_busy((struct r300_winsys_bo*)bo)) { + if (radeon_bo_is_busy((struct pb_buffer*)bo)) { return TRUE; } @@ -365,8 +391,8 @@ struct pb_manager *radeon_bomgr_create(struct radeon_drm_winsys *rws) return &mgr->base; } -static void *radeon_bo_map(struct r300_winsys_bo *buf, - struct r300_winsys_cs *cs, +static void *radeon_bo_map(struct pb_buffer *buf, + struct radeon_winsys_cs *cs, enum pipe_transfer_usage usage) { struct pb_buffer *_buf = pb_buffer(buf); @@ -374,9 +400,9 @@ static void *radeon_bo_map(struct r300_winsys_bo *buf, return pb_map(_buf, get_pb_usage_from_transfer_flags(usage), cs); } -static void radeon_bo_get_tiling(struct r300_winsys_bo *_buf, - enum r300_buffer_tiling *microtiled, - enum r300_buffer_tiling *macrotiled) +static void radeon_bo_get_tiling(struct pb_buffer *_buf, + enum radeon_bo_layout *microtiled, + enum radeon_bo_layout *macrotiled) { struct radeon_bo *bo = get_radeon_bo(pb_buffer(_buf)); struct drm_radeon_gem_set_tiling args = {}; @@ -388,19 +414,19 @@ static void radeon_bo_get_tiling(struct r300_winsys_bo *_buf, &args, sizeof(args)); - *microtiled = R300_BUFFER_LINEAR; - *macrotiled = R300_BUFFER_LINEAR; + *microtiled = RADEON_LAYOUT_LINEAR; + *macrotiled = RADEON_LAYOUT_LINEAR; if (args.tiling_flags & RADEON_BO_FLAGS_MICRO_TILE) - *microtiled = R300_BUFFER_TILED; + *microtiled = RADEON_LAYOUT_TILED; if (args.tiling_flags & RADEON_BO_FLAGS_MACRO_TILE) - *macrotiled = R300_BUFFER_TILED; + *macrotiled = RADEON_LAYOUT_TILED; } -static void radeon_bo_set_tiling(struct r300_winsys_bo *_buf, - struct r300_winsys_cs *rcs, - enum r300_buffer_tiling microtiled, - enum r300_buffer_tiling macrotiled, +static void radeon_bo_set_tiling(struct pb_buffer *_buf, + struct radeon_winsys_cs *rcs, + enum radeon_bo_layout microtiled, + enum radeon_bo_layout macrotiled, uint32_t pitch) { struct radeon_bo *bo = get_radeon_bo(pb_buffer(_buf)); @@ -417,12 +443,12 @@ static void radeon_bo_set_tiling(struct r300_winsys_bo *_buf, sched_yield(); } - if (microtiled == R300_BUFFER_TILED) + if (microtiled == RADEON_LAYOUT_TILED) args.tiling_flags |= RADEON_BO_FLAGS_MICRO_TILE; - else if (microtiled == R300_BUFFER_SQUARETILED) + else if (microtiled == RADEON_LAYOUT_SQUARETILED) args.tiling_flags |= RADEON_BO_FLAGS_MICRO_TILE_SQUARE; - if (macrotiled == R300_BUFFER_TILED) + if (macrotiled == RADEON_LAYOUT_TILED) args.tiling_flags |= RADEON_BO_FLAGS_MACRO_TILE; args.handle = bo->handle; @@ -434,38 +460,35 @@ static void radeon_bo_set_tiling(struct r300_winsys_bo *_buf, sizeof(args)); } -static struct r300_winsys_cs_handle *radeon_drm_get_cs_handle( - struct r300_winsys_bo *_buf) +static struct radeon_winsys_cs_handle *radeon_drm_get_cs_handle( + struct pb_buffer *_buf) { /* return radeon_bo. */ - return (struct r300_winsys_cs_handle*) + return (struct radeon_winsys_cs_handle*) get_radeon_bo(pb_buffer(_buf)); } static unsigned get_pb_usage_from_create_flags(unsigned bind, unsigned usage, - enum r300_buffer_domain domain) + enum radeon_bo_domain domain) { unsigned res = 0; - if (bind & (PIPE_BIND_VERTEX_BUFFER | PIPE_BIND_INDEX_BUFFER)) - res |= RADEON_PB_USAGE_CACHE; - - if (domain & R300_DOMAIN_GTT) + if (domain & RADEON_DOMAIN_GTT) res |= RADEON_PB_USAGE_DOMAIN_GTT; - if (domain & R300_DOMAIN_VRAM) + if (domain & RADEON_DOMAIN_VRAM) res |= RADEON_PB_USAGE_DOMAIN_VRAM; return res; } -static struct r300_winsys_bo * -radeon_winsys_bo_create(struct r300_winsys_screen *rws, +static struct pb_buffer * +radeon_winsys_bo_create(struct radeon_winsys *rws, unsigned size, unsigned alignment, unsigned bind, unsigned usage, - enum r300_buffer_domain domain) + enum radeon_bo_domain domain) { struct radeon_drm_winsys *ws = radeon_drm_winsys(rws); struct pb_desc desc; @@ -486,10 +509,10 @@ radeon_winsys_bo_create(struct r300_winsys_screen *rws, if (!buffer) return NULL; - return (struct r300_winsys_bo*)buffer; + return (struct pb_buffer*)buffer; } -static struct r300_winsys_bo *radeon_winsys_bo_from_handle(struct r300_winsys_screen *rws, +static struct pb_buffer *radeon_winsys_bo_from_handle(struct radeon_winsys *rws, struct winsys_handle *whandle, unsigned *stride, unsigned *size) @@ -531,7 +554,6 @@ static struct r300_winsys_bo *radeon_winsys_bo_from_handle(struct r300_winsys_sc bo->handle = open_arg.handle; bo->size = open_arg.size; bo->name = whandle->handle; - radeon_bo_ref(bo); /* Initialize it. */ pipe_reference_init(&bo->base.base.reference, 1); @@ -553,14 +575,14 @@ done: if (size) *size = bo->base.base.size; - return (struct r300_winsys_bo*)bo; + return (struct pb_buffer*)bo; fail: pipe_mutex_unlock(mgr->bo_handles_mutex); return NULL; } -static boolean radeon_winsys_bo_get_handle(struct r300_winsys_bo *buffer, +static boolean radeon_winsys_bo_get_handle(struct pb_buffer *buffer, unsigned stride, struct winsys_handle *whandle) { diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.h b/src/gallium/winsys/radeon/drm/radeon_drm_bo.h index a26866b7e75..b94881bc4ce 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.h +++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.h @@ -29,14 +29,13 @@ * Jérôme Glisse <[email protected]> * Marek Olšák <[email protected]> */ -#ifndef RADEON_DRM_BUFFER_H -#define RADEON_DRM_BUFFER_H +#ifndef RADEON_DRM_BO_H +#define RADEON_DRM_BO_H -#include "radeon_winsys.h" +#include "radeon_drm_winsys.h" #include "pipebuffer/pb_bufmgr.h" #include "os/os_thread.h" -#define RADEON_PB_USAGE_CACHE (1 << 28) #define RADEON_PB_USAGE_DOMAIN_GTT (1 << 29) #define RADEON_PB_USAGE_DOMAIN_VRAM (1 << 30) @@ -54,8 +53,6 @@ struct radeon_bo { uint32_t handle; uint32_t name; - int ref_count; - /* how many command streams is this bo referenced in? */ int num_cs_references; @@ -63,6 +60,13 @@ struct radeon_bo { * thread, is this bo referenced in? */ int num_active_ioctls; + /* Whether the buffer has been relocated for write and is busy since then. + * This field is updated in: + * - radeon_drm_cs_flush (to TRUE if it's relocated for write) + * - radeon_bo_is_busy (to FALSE if it's not busy) + * - radeon_bo_wait (to FALSE) */ + boolean busy_for_write; + boolean flinked; uint32_t flink; }; @@ -70,16 +74,14 @@ struct radeon_bo { struct pb_manager *radeon_bomgr_create(struct radeon_drm_winsys *rws); void radeon_bomgr_init_functions(struct radeon_drm_winsys *ws); -void radeon_bo_unref(struct radeon_bo *buf); - - -static INLINE void radeon_bo_ref(struct radeon_bo *bo) +static INLINE +void radeon_bo_reference(struct radeon_bo **dst, struct radeon_bo *src) { - p_atomic_inc(&bo->ref_count); + pb_reference((struct pb_buffer**)dst, (struct pb_buffer*)src); } static INLINE struct pb_buffer * -pb_buffer(struct r300_winsys_bo *buffer) +pb_buffer(struct pb_buffer *buffer) { return (struct pb_buffer *)buffer; } diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c index 951791a1727..0139de1973a 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c @@ -36,7 +36,7 @@ /* This file replaces libdrm's radeon_cs_gem with our own implemention. - It's optimized specifically for r300g, but r600g could use it as well. + It's optimized specifically for Radeon DRM. Reloc writes and space checking are faster and simpler than their counterparts in libdrm (the time complexity of all the functions is O(1) in nearly all scenarios, thanks to hashing). @@ -111,8 +111,7 @@ static void radeon_cs_context_cleanup(struct radeon_cs_context *csc) for (i = 0; i < csc->crelocs; i++) { p_atomic_dec(&csc->relocs_bo[i]->num_cs_references); - radeon_bo_unref(csc->relocs_bo[i]); - csc->relocs_bo[i] = NULL; + radeon_bo_reference(&csc->relocs_bo[i], NULL); } csc->crelocs = 0; @@ -130,7 +129,7 @@ static void radeon_destroy_cs_context(struct radeon_cs_context *csc) FREE(csc->relocs); } -static struct r300_winsys_cs *radeon_drm_cs_create(struct r300_winsys_screen *rws) +static struct radeon_winsys_cs *radeon_drm_cs_create(struct radeon_winsys *rws) { struct radeon_drm_winsys *ws = radeon_drm_winsys(rws); struct radeon_drm_cs *cs; @@ -164,9 +163,9 @@ static struct r300_winsys_cs *radeon_drm_cs_create(struct r300_winsys_screen *rw #define OUT_CS(cs, value) (cs)->buf[(cs)->cdw++] = (value) static INLINE void update_domains(struct drm_radeon_cs_reloc *reloc, - enum r300_buffer_domain rd, - enum r300_buffer_domain wd, - enum r300_buffer_domain *added_domains) + enum radeon_bo_domain rd, + enum radeon_bo_domain wd, + enum radeon_bo_domain *added_domains) { *added_domains = (rd | wd) & ~(reloc->read_domains | reloc->write_domain); @@ -221,9 +220,9 @@ int radeon_get_reloc(struct radeon_cs_context *csc, struct radeon_bo *bo) static void radeon_add_reloc(struct radeon_cs_context *csc, struct radeon_bo *bo, - enum r300_buffer_domain rd, - enum r300_buffer_domain wd, - enum r300_buffer_domain *added_domains) + enum radeon_bo_domain rd, + enum radeon_bo_domain wd, + enum radeon_bo_domain *added_domains) { struct drm_radeon_cs_reloc *reloc; unsigned i; @@ -266,9 +265,9 @@ static void radeon_add_reloc(struct radeon_cs_context *csc, } /* Initialize the new relocation. */ - radeon_bo_ref(bo); + csc->relocs_bo[csc->crelocs] = NULL; + radeon_bo_reference(&csc->relocs_bo[csc->crelocs], bo); p_atomic_inc(&bo->num_cs_references); - csc->relocs_bo[csc->crelocs] = bo; reloc = &csc->relocs[csc->crelocs]; reloc->handle = bo->handle; reloc->read_domains = rd; @@ -285,27 +284,27 @@ static void radeon_add_reloc(struct radeon_cs_context *csc, *added_domains = rd | wd; } -static void radeon_drm_cs_add_reloc(struct r300_winsys_cs *rcs, - struct r300_winsys_cs_handle *buf, - enum r300_buffer_domain rd, - enum r300_buffer_domain wd) +static void radeon_drm_cs_add_reloc(struct radeon_winsys_cs *rcs, + struct radeon_winsys_cs_handle *buf, + enum radeon_bo_domain rd, + enum radeon_bo_domain wd) { struct radeon_drm_cs *cs = radeon_drm_cs(rcs); struct radeon_bo *bo = (struct radeon_bo*)buf; - enum r300_buffer_domain added_domains; + enum radeon_bo_domain added_domains; radeon_add_reloc(cs->csc, bo, rd, wd, &added_domains); if (!added_domains) return; - if (added_domains & R300_DOMAIN_GTT) + if (added_domains & RADEON_DOMAIN_GTT) cs->csc->used_gart += bo->size; - if (added_domains & R300_DOMAIN_VRAM) + if (added_domains & RADEON_DOMAIN_VRAM) cs->csc->used_vram += bo->size; } -static boolean radeon_drm_cs_validate(struct r300_winsys_cs *rcs) +static boolean radeon_drm_cs_validate(struct radeon_winsys_cs *rcs) { struct radeon_drm_cs *cs = radeon_drm_cs(rcs); @@ -313,8 +312,8 @@ static boolean radeon_drm_cs_validate(struct r300_winsys_cs *rcs) cs->csc->used_vram < cs->ws->vram_size * 0.8; } -static void radeon_drm_cs_write_reloc(struct r300_winsys_cs *rcs, - struct r300_winsys_cs_handle *buf) +static void radeon_drm_cs_write_reloc(struct radeon_winsys_cs *rcs, + struct radeon_winsys_cs_handle *buf) { struct radeon_drm_cs *cs = radeon_drm_cs(rcs); struct radeon_bo *bo = (struct radeon_bo*)buf; @@ -322,7 +321,7 @@ static void radeon_drm_cs_write_reloc(struct r300_winsys_cs *rcs, unsigned index = radeon_get_reloc(cs->csc, bo); if (index == -1) { - fprintf(stderr, "r300: Cannot get a relocation in %s.\n", __func__); + fprintf(stderr, "radeon: Cannot get a relocation in %s.\n", __func__); return; } @@ -366,7 +365,7 @@ void radeon_drm_cs_sync_flush(struct radeon_drm_cs *cs) DEBUG_GET_ONCE_BOOL_OPTION(thread, "RADEON_THREAD", TRUE) -static void radeon_drm_cs_flush(struct r300_winsys_cs *rcs, unsigned flags) +static void radeon_drm_cs_flush(struct radeon_winsys_cs *rcs, unsigned flags) { struct radeon_drm_cs *cs = radeon_drm_cs(rcs); struct radeon_cs_context *tmp; @@ -379,11 +378,18 @@ static void radeon_drm_cs_flush(struct r300_winsys_cs *rcs, unsigned flags) cs->csc->chunks[0].length_dw = cs->base.cdw; - for (i = 0; i < crelocs; i++) + for (i = 0; i < crelocs; i++) { + /* Update the number of active asynchronous CS ioctls for the buffer. */ p_atomic_inc(&cs->csc->relocs_bo[i]->num_active_ioctls); + /* Update whether the buffer is busy for write. */ + if (cs->csc->relocs[i].write_domain) { + cs->csc->relocs_bo[i]->busy_for_write = TRUE; + } + } + if (cs->ws->num_cpus > 1 && debug_get_option_thread() && - (flags & R300_FLUSH_ASYNC)) { + (flags & RADEON_FLUSH_ASYNC)) { cs->thread = pipe_thread_create(radeon_drm_cs_emit_ioctl, cs->csc); assert(cs->thread); } else { @@ -403,7 +409,7 @@ static void radeon_drm_cs_flush(struct r300_winsys_cs *rcs, unsigned flags) cs->base.cdw = 0; } -static void radeon_drm_cs_destroy(struct r300_winsys_cs *rcs) +static void radeon_drm_cs_destroy(struct radeon_winsys_cs *rcs) { struct radeon_drm_cs *cs = radeon_drm_cs(rcs); radeon_drm_cs_sync_flush(cs); @@ -415,7 +421,7 @@ static void radeon_drm_cs_destroy(struct r300_winsys_cs *rcs) FREE(cs); } -static void radeon_drm_cs_set_flush(struct r300_winsys_cs *rcs, +static void radeon_drm_cs_set_flush(struct radeon_winsys_cs *rcs, void (*flush)(void *ctx, unsigned flags), void *user) { @@ -424,8 +430,8 @@ static void radeon_drm_cs_set_flush(struct r300_winsys_cs *rcs, cs->flush_data = user; } -static boolean radeon_bo_is_referenced(struct r300_winsys_cs *rcs, - struct r300_winsys_cs_handle *_buf) +static boolean radeon_bo_is_referenced(struct radeon_winsys_cs *rcs, + struct radeon_winsys_cs_handle *_buf) { struct radeon_drm_cs *cs = radeon_drm_cs(rcs); struct radeon_bo *bo = (struct radeon_bo*)_buf; diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.h b/src/gallium/winsys/radeon/drm/radeon_drm_cs.h index dfaa161c318..339beedc6ab 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.h +++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.h @@ -31,7 +31,7 @@ #include <radeon_drm.h> struct radeon_cs_context { - uint32_t buf[R300_MAX_CMDBUF_DWORDS]; + uint32_t buf[RADEON_MAX_CMDBUF_DWORDS]; int fd; struct drm_radeon_cs cs; @@ -54,7 +54,7 @@ struct radeon_cs_context { }; struct radeon_drm_cs { - struct r300_winsys_cs base; + struct radeon_winsys_cs base; /* We flip between these two CS. While one is being consumed * by the kernel in another thread, the other one is being filled @@ -79,19 +79,37 @@ struct radeon_drm_cs { int radeon_get_reloc(struct radeon_cs_context *csc, struct radeon_bo *bo); static INLINE struct radeon_drm_cs * -radeon_drm_cs(struct r300_winsys_cs *base) +radeon_drm_cs(struct radeon_winsys_cs *base) { return (struct radeon_drm_cs*)base; } -static INLINE boolean radeon_bo_is_referenced_by_cs(struct radeon_drm_cs *cs, - struct radeon_bo *bo) +static INLINE boolean +radeon_bo_is_referenced_by_cs(struct radeon_drm_cs *cs, + struct radeon_bo *bo) { return bo->num_cs_references == bo->rws->num_cs || (bo->num_cs_references && radeon_get_reloc(cs->csc, bo) != -1); } -static INLINE boolean radeon_bo_is_referenced_by_any_cs(struct radeon_bo *bo) +static INLINE boolean +radeon_bo_is_referenced_by_cs_for_write(struct radeon_drm_cs *cs, + struct radeon_bo *bo) +{ + int index; + + if (!bo->num_cs_references) + return FALSE; + + index = radeon_get_reloc(cs->csc, bo); + if (index == -1) + return FALSE; + + return cs->csc->relocs[index].write_domain != 0; +} + +static INLINE boolean +radeon_bo_is_referenced_by_any_cs(struct radeon_bo *bo) { return bo->num_cs_references; } diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_public.h b/src/gallium/winsys/radeon/drm/radeon_drm_public.h index 3a208cdd4c4..76d9dda422d 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_public.h +++ b/src/gallium/winsys/radeon/drm/radeon_drm_public.h @@ -3,9 +3,9 @@ #include "pipe/p_defines.h" -struct r300_winsys_screen; +struct radeon_winsys; -struct r300_winsys_screen *r300_drm_winsys_screen_create(int fd); +struct radeon_winsys *radeon_drm_winsys_create(int fd); static INLINE boolean is_r3xx(int pciid) { diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_common.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c index 72c2ff11125..37f6d18689d 100644 --- a/src/gallium/winsys/radeon/drm/radeon_drm_common.c +++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c @@ -31,7 +31,6 @@ * Marek Olšák <[email protected]> */ -#include "radeon_winsys.h" #include "radeon_drm_bo.h" #include "radeon_drm_cs.h" #include "radeon_drm_public.h" @@ -164,7 +163,7 @@ static void do_ioctls(struct radeon_drm_winsys *winsys) winsys->num_cpus = sysconf(_SC_NPROCESSORS_ONLN); } -static void radeon_winsys_destroy(struct r300_winsys_screen *rws) +static void radeon_winsys_destroy(struct radeon_winsys *rws) { struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws; @@ -173,41 +172,41 @@ static void radeon_winsys_destroy(struct r300_winsys_screen *rws) FREE(rws); } -static uint32_t radeon_get_value(struct r300_winsys_screen *rws, - enum r300_value_id id) +static uint32_t radeon_get_value(struct radeon_winsys *rws, + enum radeon_value_id id) { struct radeon_drm_winsys *ws = (struct radeon_drm_winsys *)rws; switch(id) { - case R300_VID_PCI_ID: + case RADEON_VID_PCI_ID: return ws->pci_id; - case R300_VID_GB_PIPES: + case RADEON_VID_R300_GB_PIPES: return ws->gb_pipes; - case R300_VID_Z_PIPES: + case RADEON_VID_R300_Z_PIPES: return ws->z_pipes; - case R300_VID_GART_SIZE: + case RADEON_VID_GART_SIZE: return ws->gart_size; - case R300_VID_VRAM_SIZE: + case RADEON_VID_VRAM_SIZE: return ws->vram_size; - case R300_VID_DRM_MAJOR: + case RADEON_VID_DRM_MAJOR: return ws->drm_major; - case R300_VID_DRM_MINOR: + case RADEON_VID_DRM_MINOR: return ws->drm_minor; - case R300_VID_DRM_PATCHLEVEL: + case RADEON_VID_DRM_PATCHLEVEL: return ws->drm_patchlevel; - case R300_VID_DRM_2_6_0: + case RADEON_VID_DRM_2_6_0: return ws->drm_major*100 + ws->drm_minor >= 206; - case R300_VID_DRM_2_8_0: + case RADEON_VID_DRM_2_8_0: return ws->drm_major*100 + ws->drm_minor >= 208; - case R300_CAN_HYPERZ: + case RADEON_VID_CAN_HYPERZ: return ws->hyperz; - case R300_CAN_AACOMPRESS: + case RADEON_VID_CAN_AACOMPRESS: return ws->aacompress; } return 0; } -struct r300_winsys_screen *r300_drm_winsys_screen_create(int fd) +struct radeon_winsys *radeon_drm_winsys_create(int fd) { struct radeon_drm_winsys *ws = CALLOC_STRUCT(radeon_drm_winsys); if (!ws) { diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h new file mode 100644 index 00000000000..e1b9493fc10 --- /dev/null +++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h @@ -0,0 +1,67 @@ +/* + * Copyright © 2009 Corbin Simpson + * 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 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 THE COPYRIGHT HOLDERS, AUTHORS + * 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. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + */ +/* + * Authors: + * Corbin Simpson <[email protected]> + */ +#ifndef RADEON_DRM_WINSYS_H +#define RADEON_DRM_WINSYS_H + +#include "radeon_winsys.h" + +struct radeon_drm_winsys { + struct radeon_winsys base; + + int fd; /* DRM file descriptor */ + int num_cs; /* The number of command streams created. */ + + struct pb_manager *kman; + struct pb_manager *cman; + + uint32_t pci_id; /* PCI ID */ + uint32_t gb_pipes; /* GB pipe count */ + uint32_t z_pipes; /* Z pipe count (rv530 only) */ + uint32_t gart_size; /* GART size. */ + uint32_t vram_size; /* VRAM size. */ + uint32_t num_cpus; /* Number of CPUs. */ + + unsigned drm_major; + unsigned drm_minor; + unsigned drm_patchlevel; + + /* Hyper-Z user */ + boolean hyperz; + /* AA compression (CMask) */ + boolean aacompress; +}; + +static INLINE struct radeon_drm_winsys * +radeon_drm_winsys(struct radeon_winsys *base) +{ + return (struct radeon_drm_winsys*)base; +} + +#endif diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h index 9ecbb074572..ca0e6624138 100644 --- a/src/gallium/winsys/radeon/drm/radeon_winsys.h +++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h @@ -1,67 +1,319 @@ /* - * Copyright © 2009 Corbin Simpson - * All Rights Reserved. + * Copyright 2008 Corbin Simpson <[email protected]> + * Copyright 2010 Marek Olšák <[email protected]> * - * 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: + * 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 + * on 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 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 THE COPYRIGHT HOLDERS, AUTHORS - * 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. + * 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 above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - */ -/* - * Authors: - * Corbin Simpson <[email protected]> - */ + * 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 + * THE AUTHOR(S) AND/OR THEIR 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 RADEON_WINSYS_H #define RADEON_WINSYS_H -#include "r300_winsys.h" +/* The public winsys interface header for the radeon driver. */ -struct radeon_drm_winsys { - struct r300_winsys_screen base; +#include "pipebuffer/pb_bufmgr.h" +#include "pipe/p_defines.h" +#include "pipe/p_state.h" - int fd; /* DRM file descriptor */ - int num_cs; /* The number of command streams created. */ +#define RADEON_MAX_CMDBUF_DWORDS (16 * 1024) +#define RADEON_FLUSH_ASYNC (1 << 0) - struct pb_manager *kman; - struct pb_manager *cman; +/* Tiling flags. */ +enum radeon_bo_layout { + RADEON_LAYOUT_LINEAR = 0, + RADEON_LAYOUT_TILED, + RADEON_LAYOUT_SQUARETILED, - uint32_t pci_id; /* PCI ID */ - uint32_t gb_pipes; /* GB pipe count */ - uint32_t z_pipes; /* Z pipe count (rv530 only) */ - uint32_t gart_size; /* GART size. */ - uint32_t vram_size; /* VRAM size. */ - uint32_t num_cpus; /* Number of CPUs. */ + RADEON_LAYOUT_UNKNOWN +}; + +enum radeon_bo_domain { /* bitfield */ + RADEON_DOMAIN_GTT = 2, + RADEON_DOMAIN_VRAM = 4 +}; - unsigned drm_major; - unsigned drm_minor; - unsigned drm_patchlevel; +struct winsys_handle; +struct radeon_winsys_cs_handle; /* for write_reloc etc. */ - /* Hyper-Z user */ - boolean hyperz; - /* AA compression (CMask) */ - boolean aacompress; +struct radeon_winsys_cs { + unsigned cdw; /* Number of used dwords. */ + uint32_t *buf; /* The command buffer. */ }; -static INLINE struct radeon_drm_winsys * -radeon_drm_winsys(struct r300_winsys_screen *base) -{ - return (struct radeon_drm_winsys*)base; -} +enum radeon_value_id { + RADEON_VID_PCI_ID, + RADEON_VID_R300_GB_PIPES, + RADEON_VID_R300_Z_PIPES, + RADEON_VID_GART_SIZE, + RADEON_VID_VRAM_SIZE, + RADEON_VID_DRM_MAJOR, + RADEON_VID_DRM_MINOR, + RADEON_VID_DRM_PATCHLEVEL, + + /* These should probably go away: */ + + /* R300 features: + * - Hyper-Z + * - GB_Z_PEQ_CONFIG on rv350->r4xx + * - R500 FG_ALPHA_VALUE + * + * R600 features: + * - TBD + */ + RADEON_VID_DRM_2_6_0, + + /* R300 features: + * - R500 US_FORMAT regs + * - R500 ARGB2101010 colorbuffer + * - CMask and AA regs + * - R16F/RG16F + * + * R600 features: + * - TBD + */ + RADEON_VID_DRM_2_8_0, + + RADEON_VID_CAN_HYPERZ, /* ZMask + HiZ */ + RADEON_VID_CAN_AACOMPRESS, /* CMask */ +}; + +struct radeon_winsys { + /** + * Destroy this winsys. + * + * \param ws The winsys this function is called from. + */ + void (*destroy)(struct radeon_winsys *ws); + + /** + * Query a system value from a winsys. + * + * \param ws The winsys this function is called from. + * \param vid One of the RADEON_VID_* enums. + */ + uint32_t (*get_value)(struct radeon_winsys *ws, + enum radeon_value_id vid); + + /************************************************************************** + * Buffer management. Buffer attributes are mostly fixed over its lifetime. + * + * Remember that gallium gets to choose the interface it needs, and the + * window systems must then implement that interface (rather than the + * other way around...). + *************************************************************************/ + + /** + * Create a buffer object. + * + * \param ws The winsys this function is called from. + * \param size The size to allocate. + * \param alignment An alignment of the buffer in memory. + * \param bind A bitmask of the PIPE_BIND_* flags. + * \param usage A bitmask of the PIPE_USAGE_* flags. + * \param domain A bitmask of the RADEON_DOMAIN_* flags. + * \return The created buffer object. + */ + struct pb_buffer *(*buffer_create)(struct radeon_winsys *ws, + unsigned size, + unsigned alignment, + unsigned bind, + unsigned usage, + enum radeon_bo_domain domain); + + struct radeon_winsys_cs_handle *(*buffer_get_cs_handle)( + struct pb_buffer *buf); + + /** + * Map the entire data store of a buffer object into the client's address + * space. + * + * \param buf A winsys buffer object to map. + * \param cs A command stream to flush if the buffer is referenced by it. + * \param usage A bitmask of the PIPE_TRANSFER_* flags. + * \return The pointer at the beginning of the buffer. + */ + void *(*buffer_map)(struct pb_buffer *buf, + struct radeon_winsys_cs *cs, + enum pipe_transfer_usage usage); + + /** + * Unmap a buffer object from the client's address space. + * + * \param buf A winsys buffer object to unmap. + */ + void (*buffer_unmap)(struct pb_buffer *buf); + + /** + * Return TRUE if a buffer object is being used by the GPU. + * + * \param buf A winsys buffer object. + */ + boolean (*buffer_is_busy)(struct pb_buffer *buf); + + /** + * Wait for a buffer object until it is not used by a GPU. This is + * equivalent to a fence placed after the last command using the buffer, + * and synchronizing to the fence. + * + * \param buf A winsys buffer object to wait for. + */ + void (*buffer_wait)(struct pb_buffer *buf); + + /** + * Return tiling flags describing a memory layout of a buffer object. + * + * \param buf A winsys buffer object to get the flags from. + * \param macrotile A pointer to the return value of the microtile flag. + * \param microtile A pointer to the return value of the macrotile flag. + * + * \note microtile and macrotile are not bitmasks! + */ + void (*buffer_get_tiling)(struct pb_buffer *buf, + enum radeon_bo_layout *microtile, + enum radeon_bo_layout *macrotile); + + /** + * Set tiling flags describing a memory layout of a buffer object. + * + * \param buf A winsys buffer object to set the flags for. + * \param cs A command stream to flush if the buffer is referenced by it. + * \param macrotile A macrotile flag. + * \param microtile A microtile flag. + * \param stride A stride of the buffer in bytes, for texturing. + * + * \note microtile and macrotile are not bitmasks! + */ + void (*buffer_set_tiling)(struct pb_buffer *buf, + struct radeon_winsys_cs *cs, + enum radeon_bo_layout microtile, + enum radeon_bo_layout macrotile, + unsigned stride); + + /** + * Get a winsys buffer from a winsys handle. The internal structure + * of the handle is platform-specific and only a winsys should access it. + * + * \param ws The winsys this function is called from. + * \param whandle A winsys handle pointer as was received from a state + * tracker. + * \param stride The returned buffer stride in bytes. + * \param size The returned buffer size. + */ + struct pb_buffer *(*buffer_from_handle)(struct radeon_winsys *ws, + struct winsys_handle *whandle, + unsigned *stride, + unsigned *size); + + /** + * Get a winsys handle from a winsys buffer. The internal structure + * of the handle is platform-specific and only a winsys should access it. + * + * \param buf A winsys buffer object to get the handle from. + * \param whandle A winsys handle pointer. + * \param stride A stride of the buffer in bytes, for texturing. + * \return TRUE on success. + */ + boolean (*buffer_get_handle)(struct pb_buffer *buf, + unsigned stride, + struct winsys_handle *whandle); + + /************************************************************************** + * Command submission. + * + * Each pipe context should create its own command stream and submit + * commands independently of other contexts. + *************************************************************************/ + + /** + * Create a command stream. + * + * \param ws The winsys this function is called from. + */ + struct radeon_winsys_cs *(*cs_create)(struct radeon_winsys *ws); + + /** + * Destroy a command stream. + * + * \param cs A command stream to destroy. + */ + void (*cs_destroy)(struct radeon_winsys_cs *cs); + + /** + * Add a new buffer relocation. Every relocation must first be added + * before it can be written. + * + * \param cs A command stream to add buffer for validation against. + * \param buf A winsys buffer to validate. + * \param rd A read domain containing a bitmask of the RADEON_DOMAIN_* flags. + * \param wd A write domain containing a bitmask of the RADEON_DOMAIN_* flags. + */ + void (*cs_add_reloc)(struct radeon_winsys_cs *cs, + struct radeon_winsys_cs_handle *buf, + enum radeon_bo_domain rd, + enum radeon_bo_domain wd); + + /** + * Return TRUE if there is enough memory in VRAM and GTT for the relocs + * added so far. + * + * \param cs A command stream to validate. + */ + boolean (*cs_validate)(struct radeon_winsys_cs *cs); + + /** + * Write a relocated dword to a command buffer. + * + * \param cs A command stream the relocation is written to. + * \param buf A winsys buffer to write the relocation for. + * \param rd A read domain containing a bitmask of the RADEON_DOMAIN_* flags. + * \param wd A write domain containing a bitmask of the RADEON_DOMAIN_* flags. + */ + void (*cs_write_reloc)(struct radeon_winsys_cs *cs, + struct radeon_winsys_cs_handle *buf); + + /** + * Flush a command stream. + * + * \param cs A command stream to flush. + * \param flags, RADEON_FLUSH_ASYNC or 0. + */ + void (*cs_flush)(struct radeon_winsys_cs *cs, unsigned flags); + + /** + * Set a flush callback which is called from winsys when flush is + * required. + * + * \param cs A command stream to set the callback for. + * \param flush A flush callback function associated with the command stream. + * \param user A user pointer that will be passed to the flush callback. + */ + void (*cs_set_flush)(struct radeon_winsys_cs *cs, + void (*flush)(void *ctx, unsigned flags), + void *user); + + /** + * Return TRUE if a buffer is referenced by a command stream. + * + * \param cs A command stream. + * \param buf A winsys buffer. + */ + boolean (*cs_is_buffer_referenced)(struct radeon_winsys_cs *cs, + struct radeon_winsys_cs_handle *buf); +}; #endif |