diff options
Diffstat (limited to 'src/gallium')
276 files changed, 10086 insertions, 6259 deletions
diff --git a/src/gallium/Makefile.template b/src/gallium/Makefile.template index 5d9d2db7866..91a9b54b362 100644 --- a/src/gallium/Makefile.template +++ b/src/gallium/Makefile.template @@ -21,9 +21,6 @@ INCLUDES = \ -I$(TOP)/src/gallium/include \ -I$(TOP)/src/gallium/auxiliary \ -I$(TOP)/src/gallium/drivers \ - -I$(GALLIUM)/src/gallium/include \ - -I$(GALLIUM)/src/gallium/auxiliary \ - -I$(GALLIUM)/src/gallium/drivers \ $(LIBRARY_INCLUDES) @@ -34,10 +31,10 @@ default: depend lib$(LIBNAME).a lib$(LIBNAME).a: $(OBJECTS) $(EXTRA_OBJECTS) Makefile $(TOP)/src/gallium/Makefile.template $(MKLIB) -o $(LIBNAME) -static $(OBJECTS) $(EXTRA_OBJECTS) -depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) +depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES) rm -f depend touch depend - $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) 2> /dev/null + $(MKDEP) $(MKDEP_OPTIONS) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(GENERATED_SOURCES) 2> /dev/null # Emacs tags tags: @@ -45,7 +42,7 @@ tags: # Remove .o and backup files clean: - rm -f $(OBJECTS) lib$(LIBNAME).a depend depend.bak + rm -f $(OBJECTS) $(GENERATED_SOURCES) lib$(LIBNAME).a depend depend.bak # Dummy target install: @@ -54,16 +51,16 @@ install: ##### RULES ##### %.s: %.c - $(CC) -S $(INCLUDES) $(DEFINES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + $(CC) -S $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ %.o: %.c - $(CC) -c $(INCLUDES) $(DEFINES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ %.o: %.cpp - $(CXX) -c $(INCLUDES) $(DEFINES) $(CXXFLAGS) $(LIBRARY_DEFINES) $< -o $@ + $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(LIBRARY_DEFINES) $< -o $@ %.o: %.S - $(CC) -c $(INCLUDES) $(DEFINES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ + $(CC) -c $(INCLUDES) $(CFLAGS) $(LIBRARY_DEFINES) $< -o $@ sinclude depend diff --git a/src/gallium/auxiliary/Makefile b/src/gallium/auxiliary/Makefile index ff7695150e2..68b1a3e8546 100644 --- a/src/gallium/auxiliary/Makefile +++ b/src/gallium/auxiliary/Makefile @@ -54,6 +54,7 @@ C_SOURCES = \ os/os_stream_str.c \ os/os_stream_null.c \ os/os_time.c \ + pipebuffer/pb_buffer_fenced.c \ pipebuffer/pb_buffer_malloc.c \ pipebuffer/pb_bufmgr_alt.c \ pipebuffer/pb_bufmgr_cache.c \ @@ -104,9 +105,9 @@ C_SOURCES = \ util/u_cpu_detect.c \ util/u_dl.c \ util/u_draw_quad.c \ - util/u_format.c \ util/u_format_access.c \ util/u_format_table.c \ + util/u_format_tests.c \ util/u_gen_mipmap.c \ util/u_handle_table.c \ util/u_hash_table.c \ @@ -158,7 +159,14 @@ GALLIVM_SOURCES = \ gallivm/lp_bld_type.c GALLIVM_CPP_SOURCES = \ - gallivm/lp_bld_misc.cpp + gallivm/lp_bld_init.cpp + +GENERATED_SOURCES = \ + indices/u_indices_gen.c \ + indices/u_unfilled_gen.c \ + util/u_format_access.c \ + util/u_format_pack.h \ + util/u_format_table.c ifeq ($(MESA_LLVM),1) @@ -184,5 +192,9 @@ indices/u_unfilled_gen.c: indices/u_unfilled_gen.py util/u_format_table.c: util/u_format_table.py util/u_format_parse.py util/u_format.csv python util/u_format_table.py util/u_format.csv > $@ +util/u_format_pack.h: util/u_format_pack.py util/u_format_parse.py util/u_format.csv + python util/u_format_pack.py util/u_format.csv > $@ + util/u_format_access.c: util/u_format_access.py util/u_format_parse.py util/u_format.csv python util/u_format_access.py util/u_format.csv > $@ + diff --git a/src/gallium/auxiliary/SConscript b/src/gallium/auxiliary/SConscript index b531ad2dbd9..d6185bcb5e3 100644 --- a/src/gallium/auxiliary/SConscript +++ b/src/gallium/auxiliary/SConscript @@ -7,6 +7,8 @@ env.Append(CPPPATH = [ 'util', ]) +env.Tool('udis86') + env.CodeGenerate( target = 'indices/u_indices_gen.c', script = 'indices/u_indices_gen.py', @@ -29,6 +31,13 @@ env.CodeGenerate( ) env.CodeGenerate( + target = File('util/u_format_pack.h').srcnode(), + script = 'util/u_format_pack.py', + source = ['util/u_format.csv'], + command = 'python $SCRIPT $SOURCE > $TARGET' +) + +env.CodeGenerate( target = 'util/u_format_access.c', script = 'util/u_format_access.py', source = ['util/u_format.csv'], @@ -140,9 +149,9 @@ source = [ 'util/u_dump_state.c', 'util/u_dl.c', 'util/u_draw_quad.c', - 'util/u_format.c', 'util/u_format_access.c', 'util/u_format_table.c', + 'util/u_format_tests.c', 'util/u_gen_mipmap.c', 'util/u_handle_table.c', 'util/u_hash.c', @@ -186,7 +195,7 @@ if drawllvm: 'gallivm/lp_bld_interp.c', 'gallivm/lp_bld_intr.c', 'gallivm/lp_bld_logic.c', - 'gallivm/lp_bld_misc.cpp', + 'gallivm/lp_bld_init.cpp', 'gallivm/lp_bld_pack.c', 'gallivm/lp_bld_sample.c', 'gallivm/lp_bld_sample_soa.c', diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 510366a8d47..292e489312b 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -91,6 +91,9 @@ struct cso_context { void *vertex_shader, *vertex_shader_saved, *geometry_shader_saved; void *velements, *velements_saved; + struct pipe_clip_state clip; + struct pipe_clip_state clip_saved; + struct pipe_framebuffer_state fb, fb_saved; struct pipe_viewport_state vp, vp_saved; struct pipe_blend_color blend_color; @@ -1145,6 +1148,56 @@ void cso_restore_geometry_shader(struct cso_context *ctx) ctx->geometry_shader_saved = NULL; } +/* clip state */ + +static INLINE void +clip_state_cpy(struct pipe_clip_state *dst, + const struct pipe_clip_state *src) +{ + dst->nr = src->nr; + if (src->nr) { + memcpy(dst->ucp, src->ucp, src->nr * sizeof(src->ucp[0])); + } +} + +static INLINE int +clip_state_cmp(const struct pipe_clip_state *a, + const struct pipe_clip_state *b) +{ + if (a->nr != b->nr) { + return 1; + } + if (a->nr) { + return memcmp(a->ucp, b->ucp, a->nr * sizeof(a->ucp[0])); + } + return 0; +} + +void +cso_set_clip(struct cso_context *ctx, + const struct pipe_clip_state *clip) +{ + if (clip_state_cmp(&ctx->clip, clip)) { + clip_state_cpy(&ctx->clip, clip); + ctx->pipe->set_clip_state(ctx->pipe, clip); + } +} + +void +cso_save_clip(struct cso_context *ctx) +{ + clip_state_cpy(&ctx->clip_saved, &ctx->clip); +} + +void +cso_restore_clip(struct cso_context *ctx) +{ + if (clip_state_cmp(&ctx->clip, &ctx->clip_saved)) { + clip_state_cpy(&ctx->clip, &ctx->clip_saved); + ctx->pipe->set_clip_state(ctx->pipe, &ctx->clip_saved); + } +} + enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, unsigned count, const struct pipe_vertex_element *states) @@ -1206,4 +1259,4 @@ void cso_restore_vertex_elements(struct cso_context *ctx) ctx->pipe->bind_vertex_elements_state(ctx->pipe, ctx->velements_saved); } ctx->velements_saved = NULL; -}
\ No newline at end of file +} diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index 2caa587516b..9c16abd28dd 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -185,6 +185,19 @@ void cso_save_stencil_ref(struct cso_context *cso); void cso_restore_stencil_ref(struct cso_context *cso); +/* clip state */ + +void +cso_set_clip(struct cso_context *cso, + const struct pipe_clip_state *clip); + +void +cso_save_clip(struct cso_context *cso); + +void +cso_restore_clip(struct cso_context *cso); + + #ifdef __cplusplus } #endif diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c index d5ddc4a6a92..bb0988543f5 100644 --- a/src/gallium/auxiliary/draw/draw_context.c +++ b/src/gallium/auxiliary/draw/draw_context.c @@ -128,9 +128,7 @@ void draw_set_rasterizer_state( struct draw_context *draw, draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); draw->rasterizer = raster; - draw->bypass_clipping = - ((draw->rasterizer && draw->rasterizer->bypass_vs_clip_and_viewport) || - draw->driver.bypass_clipping); + draw->bypass_clipping = draw->driver.bypass_clipping; } @@ -140,9 +138,7 @@ void draw_set_driver_clipping( struct draw_context *draw, draw_do_flush( draw, DRAW_FLUSH_STATE_CHANGE ); draw->driver.bypass_clipping = bypass_clipping; - draw->bypass_clipping = - ((draw->rasterizer && draw->rasterizer->bypass_vs_clip_and_viewport) || - draw->driver.bypass_clipping); + draw->bypass_clipping = draw->driver.bypass_clipping; } diff --git a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c index 97f34808793..9f9fb4312c1 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_aapoint.c +++ b/src/gallium/auxiliary/draw/draw_pipe_aapoint.c @@ -864,7 +864,7 @@ draw_install_aapoint_stage(struct draw_context *draw, */ aapoint = draw_aapoint_stage( draw ); if (aapoint == NULL) - goto fail; + return FALSE; aapoint->pipe = pipe; @@ -881,10 +881,4 @@ draw_install_aapoint_stage(struct draw_context *draw, draw->pipeline.aapoint = &aapoint->stage; return TRUE; - - fail: - if (aapoint) - aapoint->stage.destroy( &aapoint->stage ); - - return FALSE; } diff --git a/src/gallium/auxiliary/draw/draw_pipe_offset.c b/src/gallium/auxiliary/draw/draw_pipe_offset.c index e829492423e..8e321946ced 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_offset.c +++ b/src/gallium/auxiliary/draw/draw_pipe_offset.c @@ -161,7 +161,7 @@ struct draw_stage *draw_offset_stage( struct draw_context *draw ) { struct offset_stage *offset = CALLOC_STRUCT(offset_stage); if (offset == NULL) - goto fail; + return NULL; draw_alloc_temp_verts( &offset->stage, 3 ); @@ -176,10 +176,4 @@ struct draw_stage *draw_offset_stage( struct draw_context *draw ) offset->stage.destroy = offset_destroy; return &offset->stage; - - fail: - if (offset) - offset->stage.destroy( &offset->stage ); - - return NULL; } diff --git a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c index d40c0352401..27099579618 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_vbuf.c +++ b/src/gallium/auxiliary/draw/draw_pipe_vbuf.c @@ -262,7 +262,7 @@ vbuf_start_prim( struct vbuf_stage *vbuf, uint prim ) src_offset = 0; break; case EMIT_4UB: - output_format = PIPE_FORMAT_B8G8R8A8_UNORM; + output_format = PIPE_FORMAT_A8R8G8B8_UNORM; emit_sz = 4 * sizeof(ubyte); break; default: diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c index 51beba50e4d..a8cdc57ad96 100644 --- a/src/gallium/auxiliary/draw/draw_pt.c +++ b/src/gallium/auxiliary/draw/draw_pt.c @@ -87,9 +87,7 @@ draw_pt_arrays(struct draw_context *draw, opt |= PT_CLIPTEST; } - if (!draw->rasterizer->bypass_vs_clip_and_viewport) { - opt |= PT_SHADE; - } + opt |= PT_SHADE; } if (opt == 0) diff --git a/src/gallium/auxiliary/draw/draw_pt_decompose.h b/src/gallium/auxiliary/draw/draw_pt_decompose.h index 4ca5b520204..3c44f7c11ee 100644 --- a/src/gallium/auxiliary/draw/draw_pt_decompose.h +++ b/src/gallium/auxiliary/draw/draw_pt_decompose.h @@ -105,40 +105,20 @@ static void FUNC( ARGS, case PIPE_PRIM_QUADS: - if (flatfirst) { - for (i = 0; i+3 < count; i += 4) { - QUAD( (i + 1), - (i + 2), - (i + 3), - (i + 0) ); - } - } - else { - for (i = 0; i+3 < count; i += 4) { - QUAD( (i + 0), - (i + 1), - (i + 2), - (i + 3)); - } + for (i = 0; i+3 < count; i += 4) { + QUAD( (i + 0), + (i + 1), + (i + 2), + (i + 3)); } break; case PIPE_PRIM_QUAD_STRIP: - if (flatfirst) { - for (i = 0; i+3 < count; i += 2) { - QUAD( (i + 1), - (i + 3), - (i + 2), - (i + 0) ); - } - } - else { - for (i = 0; i+3 < count; i += 2) { - QUAD( (i + 2), - (i + 0), - (i + 1), - (i + 3)); - } + for (i = 0; i+3 < count; i += 2) { + QUAD( (i + 2), + (i + 0), + (i + 1), + (i + 3)); } break; diff --git a/src/gallium/auxiliary/draw/draw_pt_emit.c b/src/gallium/auxiliary/draw/draw_pt_emit.c index 4fb53276bbe..ae357b51226 100644 --- a/src/gallium/auxiliary/draw/draw_pt_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_emit.c @@ -112,7 +112,7 @@ void draw_pt_emit_prepare( struct pt_emit *emit, src_offset = 0; break; case EMIT_4UB: - output_format = PIPE_FORMAT_B8G8R8A8_UNORM; + output_format = PIPE_FORMAT_A8R8G8B8_UNORM; emit_sz = 4 * sizeof(ubyte); break; default: 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 c5dfbcfa3cb..1aecb510777 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_emit.c @@ -100,8 +100,7 @@ static void fse_prepare( struct draw_pt_middle_end *middle, fse->key.nr_elements = MAX2(fse->key.nr_outputs, /* outputs - translate to hw format */ fse->key.nr_inputs); /* inputs - fetch from api format */ - fse->key.viewport = (!draw->rasterizer->bypass_vs_clip_and_viewport && - !draw->identity_viewport); + fse->key.viewport = !draw->identity_viewport; fse->key.clip = !draw->bypass_clipping; fse->key.const_vbuffers = 0; diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c index 56b69354b21..da5106463a7 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline.c @@ -96,8 +96,7 @@ static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle, */ draw_pt_post_vs_prepare( fpme->post_vs, (boolean)draw->bypass_clipping, - (boolean)(draw->identity_viewport || - draw->rasterizer->bypass_vs_clip_and_viewport), + (boolean)draw->identity_viewport, (boolean)draw->rasterizer->gl_rasterization_rules, (draw->vs.edgeflag_output ? true : false) ); @@ -154,9 +153,7 @@ static void fetch_pipeline_run( struct draw_pt_middle_end *middle, (char *)pipeline_verts ); /* Run the shader, note that this overwrites the data[] parts of - * the pipeline verts. If there is no shader, eg if - * bypass_vs_clip_and_viewport, then the inputs == outputs, and are - * already in the correct place. + * the pipeline verts. */ if (opt & PT_SHADE) { @@ -239,9 +236,7 @@ static void fetch_pipeline_linear_run( struct draw_pt_middle_end *middle, (char *)pipeline_verts ); /* Run the shader, note that this overwrites the data[] parts of - * the pipeline verts. If there is no shader, ie if - * bypass_vs_clip_and_viewport, then the inputs == outputs, and are - * already in the correct place. + * the pipeline verts. */ if (opt & PT_SHADE) { @@ -319,9 +314,7 @@ static boolean fetch_pipeline_linear_run_elts( struct draw_pt_middle_end *middle (char *)pipeline_verts ); /* Run the shader, note that this overwrites the data[] parts of - * the pipeline verts. If there is no shader, ie if - * bypass_vs_clip_and_viewport, then the inputs == outputs, and are - * already in the correct place. + * the pipeline verts. */ if (opt & PT_SHADE) { diff --git a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h index 62822a3d562..7cba8547f15 100644 --- a/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h +++ b/src/gallium/auxiliary/draw/draw_pt_vcache_tmp.h @@ -118,39 +118,21 @@ static void FUNC( struct draw_pt_front_end *frontend, case PIPE_PRIM_QUADS: for (i = 0; i+3 < count; i += 4) { - if (flatfirst) { - QUAD( vcache, - get_elt(elts, i + 0), - get_elt(elts, i + 1), - get_elt(elts, i + 2), - get_elt(elts, i + 3) ); - } - else { - QUAD( vcache, - get_elt(elts, i + 0), - get_elt(elts, i + 1), - get_elt(elts, i + 2), - get_elt(elts, i + 3) ); - } + QUAD( vcache, + get_elt(elts, i + 0), + get_elt(elts, i + 1), + get_elt(elts, i + 2), + get_elt(elts, i + 3) ); } break; case PIPE_PRIM_QUAD_STRIP: for (i = 0; i+3 < count; i += 2) { - if (flatfirst) { - QUAD( vcache, - get_elt(elts, i + 0), - get_elt(elts, i + 1), - get_elt(elts, i + 3), - get_elt(elts, i + 2) ); - } - else { - QUAD( vcache, - get_elt(elts, i + 2), - get_elt(elts, i + 0), - get_elt(elts, i + 1), - get_elt(elts, i + 3) ); - } + QUAD( vcache, + get_elt(elts, i + 2), + get_elt(elts, i + 0), + get_elt(elts, i + 1), + get_elt(elts, i + 3) ); } break; diff --git a/src/gallium/auxiliary/draw/draw_vs_aos_io.c b/src/gallium/auxiliary/draw/draw_vs_aos_io.c index a6eb37d1280..ece1ddde0cb 100644 --- a/src/gallium/auxiliary/draw/draw_vs_aos_io.c +++ b/src/gallium/auxiliary/draw/draw_vs_aos_io.c @@ -191,7 +191,7 @@ static boolean load_input( struct aos_compilation *cp, case PIPE_FORMAT_R32G32B32A32_FLOAT: emit_load_R32G32B32A32(cp, dataXMM, src); break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: emit_load_R8G8B8A8_UNORM(cp, dataXMM, src); emit_swizzle(cp, dataXMM, dataXMM, SHUF(Z,Y,X,W)); break; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c index 54b31befe6d..32f9e5201c5 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c @@ -614,6 +614,22 @@ lp_build_max(struct lp_build_context *bld, /** + * Generate clamp(a, min, max) + * Do checks for special cases. + */ +LLVMValueRef +lp_build_clamp(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef min, + LLVMValueRef max) +{ + a = lp_build_min(bld, a, max); + a = lp_build_max(bld, a, min); + return a; +} + + +/** * Generate abs(a) */ LLVMValueRef @@ -653,6 +669,14 @@ lp_build_abs(struct lp_build_context *bld, LLVMValueRef +lp_build_negate(struct lp_build_context *bld, + LLVMValueRef a) +{ + return LLVMBuildNeg(bld->builder, a, ""); +} + + +LLVMValueRef lp_build_sgn(struct lp_build_context *bld, LLVMValueRef a) { @@ -693,6 +717,64 @@ lp_build_sgn(struct lp_build_context *bld, } +/** + * Set the sign of float vector 'a' according to 'sign'. + * If sign==0, return abs(a). + * If sign==1, return -abs(a); + * Other values for sign produce undefined results. + */ +LLVMValueRef +lp_build_set_sign(struct lp_build_context *bld, + LLVMValueRef a, LLVMValueRef sign) +{ + const struct lp_type type = bld->type; + LLVMTypeRef int_vec_type = lp_build_int_vec_type(type); + LLVMTypeRef vec_type = lp_build_vec_type(type); + LLVMValueRef shift = lp_build_int_const_scalar(type, type.width - 1); + LLVMValueRef mask = lp_build_int_const_scalar(type, + ~((unsigned long long) 1 << (type.width - 1))); + LLVMValueRef val, res; + + assert(type.floating); + + /* val = reinterpret_cast<int>(a) */ + val = LLVMBuildBitCast(bld->builder, a, int_vec_type, ""); + /* val = val & mask */ + val = LLVMBuildAnd(bld->builder, val, mask, ""); + /* sign = sign << shift */ + sign = LLVMBuildShl(bld->builder, sign, shift, ""); + /* res = val | sign */ + res = LLVMBuildOr(bld->builder, val, sign, ""); + /* res = reinterpret_cast<float>(res) */ + res = LLVMBuildBitCast(bld->builder, res, vec_type, ""); + + return res; +} + + +/** + * Convert vector of int to vector of float. + */ +LLVMValueRef +lp_build_int_to_float(struct lp_build_context *bld, + LLVMValueRef a) +{ + const struct lp_type type = bld->type; + + assert(type.floating); + /*assert(lp_check_value(type, a));*/ + + { + LLVMTypeRef vec_type = lp_build_vec_type(type); + /*LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);*/ + LLVMValueRef res; + res = LLVMBuildSIToFP(bld->builder, a, vec_type, ""); + return res; + } +} + + + enum lp_build_round_sse41_mode { LP_BUILD_ROUND_SSE41_NEAREST = 0, @@ -818,8 +900,21 @@ lp_build_ceil(struct lp_build_context *bld, /** + * Return fractional part of 'a' computed as a - floor(f) + * Typically used in texture coord arithmetic. + */ +LLVMValueRef +lp_build_fract(struct lp_build_context *bld, + LLVMValueRef a) +{ + assert(bld->type.floating); + return lp_build_sub(bld, a, lp_build_floor(bld, a)); +} + + +/** * Convert to integer, through whichever rounding method that's fastest, - * typically truncating to zero. + * typically truncating toward zero. */ LLVMValueRef lp_build_itrunc(struct lp_build_context *bld, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h b/src/gallium/auxiliary/gallivm/lp_bld_arit.h index 62be4b9aee1..55385e3a66a 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_arit.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h @@ -107,14 +107,32 @@ lp_build_max(struct lp_build_context *bld, LLVMValueRef b); LLVMValueRef +lp_build_clamp(struct lp_build_context *bld, + LLVMValueRef a, + LLVMValueRef min, + LLVMValueRef max); + +LLVMValueRef lp_build_abs(struct lp_build_context *bld, LLVMValueRef a); LLVMValueRef +lp_build_negate(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef lp_build_sgn(struct lp_build_context *bld, LLVMValueRef a); LLVMValueRef +lp_build_set_sign(struct lp_build_context *bld, + LLVMValueRef a, LLVMValueRef sign); + +LLVMValueRef +lp_build_int_to_float(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef lp_build_round(struct lp_build_context *bld, LLVMValueRef a); @@ -131,6 +149,10 @@ lp_build_trunc(struct lp_build_context *bld, LLVMValueRef a); LLVMValueRef +lp_build_fract(struct lp_build_context *bld, + LLVMValueRef a); + +LLVMValueRef lp_build_ifloor(struct lp_build_context *bld, LLVMValueRef a); LLVMValueRef diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c index d438c0e63d7..f08f8eb6d8b 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c @@ -171,7 +171,7 @@ lp_build_depth_test(LLVMBuilderRef builder, unsigned padding_right; unsigned chan; - assert(format_desc->layout == UTIL_FORMAT_LAYOUT_ARITH); + assert(format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); assert(format_desc->channel[z_swizzle].type == UTIL_FORMAT_TYPE_UNSIGNED); assert(format_desc->channel[z_swizzle].size <= format_desc->block.bits); assert(format_desc->channel[z_swizzle].normalized); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c index dfa080b8533..a07f7418f2c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c @@ -70,7 +70,7 @@ lp_build_unpack_rgba_aos(LLVMBuilderRef builder, unsigned i; /* FIXME: Support more formats */ - assert(desc->layout == UTIL_FORMAT_LAYOUT_ARITH); + assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); assert(desc->block.width == 1); assert(desc->block.height == 1); assert(desc->block.bits <= 32); @@ -189,7 +189,7 @@ lp_build_unpack_rgba8_aos(LLVMBuilderRef builder, lp_build_context_init(&bld, builder, type); /* FIXME: Support more formats */ - assert(desc->layout == UTIL_FORMAT_LAYOUT_ARITH); + assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); assert(desc->block.width == 1); assert(desc->block.height == 1); assert(desc->block.bits <= 32); @@ -303,7 +303,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder, unsigned shift; unsigned i, j; - assert(desc->layout == UTIL_FORMAT_LAYOUT_ARITH); + assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); assert(desc->block.width == 1); assert(desc->block.height == 1); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c index 64151d169da..abb27e4c328 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c @@ -92,9 +92,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder, unsigned chan; /* FIXME: Support more formats */ - assert(format_desc->layout == UTIL_FORMAT_LAYOUT_ARITH || - (format_desc->layout == UTIL_FORMAT_LAYOUT_ARRAY && - format_desc->block.bits == format_desc->channel[0].size)); + assert(format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN); assert(format_desc->block.width == 1); assert(format_desc->block.height == 1); assert(format_desc->block.bits <= 32); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_init.cpp index 6e79438ead0..067397a520b 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.cpp @@ -26,39 +26,34 @@ **************************************************************************/ -#include "pipe/p_config.h" +#include <llvm/Config/config.h> +#include <llvm/Target/TargetSelect.h> +#include <llvm/Target/TargetOptions.h> -#include "lp_bld_misc.h" +#include "pipe/p_config.h" +#include "lp_bld_init.h" -#ifndef LLVM_NATIVE_ARCH -namespace llvm { - extern void LinkInJIT(); -} +extern "C" void LLVMLinkInJIT(); -void -LLVMLinkInJIT(void) +extern "C" void +lp_build_init(void) { - llvm::LinkInJIT(); -} - - -extern "C" int X86TargetMachineModule; - - -int -LLVMInitializeNativeTarget(void) -{ -#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) - X86TargetMachineModule = 1; +#if defined(PIPE_OS_WINDOWS) && defined(PIPE_ARCH_X86) + /* + * This is mis-detected on some hardware / software combinations. + */ + llvm::StackAlignment = 4; + llvm::RealignStack = true; #endif - return 0; -} + /* Same as LLVMInitializeNativeTarget(); */ + llvm::InitializeNativeTarget(); -#endif + LLVMLinkInJIT(); +} /* @@ -69,7 +64,6 @@ LLVMInitializeNativeTarget(void) */ #if defined(_MSC_VER) && defined(_DEBUG) #include <crtdefs.h> -extern "C" { - _CRTIMP void __cdecl _invalid_parameter_noinfo(void) {} -} +extern "C" _CRTIMP void __cdecl +_invalid_parameter_noinfo(void) {} #endif diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h index 0e787e0b9cb..07f50d1c433 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h @@ -26,26 +26,17 @@ **************************************************************************/ -#ifndef LP_BLD_MISC_H -#define LP_BLD_MISC_H +#ifndef LP_BLD_INIT_H +#define LP_BLD_INIT_H -#include "llvm/Config/config.h" - #ifdef __cplusplus extern "C" { #endif -#ifndef LLVM_NATIVE_ARCH - void -LLVMLinkInJIT(void); - -int -LLVMInitializeNativeTarget(void); - -#endif /* !LLVM_NATIVE_ARCH */ +lp_build_init(void); #ifdef __cplusplus @@ -53,4 +44,4 @@ LLVMInitializeNativeTarget(void); #endif -#endif /* !LP_BLD_MISC_H */ +#endif /* !LP_BLD_INIT_H */ diff --git a/src/gallium/auxiliary/gallivm/lp_bld_logic.c b/src/gallium/auxiliary/gallivm/lp_bld_logic.c index 41ac81b7441..2726747eaea 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_logic.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_logic.c @@ -45,6 +45,7 @@ /** * Build code to compare two values 'a' and 'b' of 'type' using the given func. * \param func one of PIPE_FUNC_x + * The result values will be 0 for false or ~0 for true. */ LLVMValueRef lp_build_compare(LLVMBuilderRef builder, @@ -311,6 +312,7 @@ lp_build_compare(LLVMBuilderRef builder, /** * Build code to compare two values 'a' and 'b' using the given func. * \param func one of PIPE_FUNC_x + * The result values will be 0 for false or ~0 for true. */ LLVMValueRef lp_build_cmp(struct lp_build_context *bld, @@ -322,6 +324,9 @@ lp_build_cmp(struct lp_build_context *bld, } +/** + * Return mask ? a : b; + */ LLVMValueRef lp_build_select(struct lp_build_context *bld, LLVMValueRef mask, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.c b/src/gallium/auxiliary/gallivm/lp_bld_pack.c index bc360ad77ad..4c61d107494 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_pack.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.c @@ -256,7 +256,9 @@ lp_build_pack2(LLVMBuilderRef builder, LLVMValueRef lo, LLVMValueRef hi) { +#if !(HAVE_LLVM >= 0x0207) LLVMTypeRef src_vec_type = lp_build_vec_type(src_type); +#endif LLVMTypeRef dst_vec_type = lp_build_vec_type(dst_type); LLVMValueRef shuffle; LLVMValueRef res; @@ -272,11 +274,14 @@ lp_build_pack2(LLVMBuilderRef builder, switch(src_type.width) { case 32: if(dst_type.sign) { +#if HAVE_LLVM >= 0x0207 + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packssdw.128", dst_vec_type, lo, hi); +#else res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packssdw.128", src_vec_type, lo, hi); +#endif } else { if (util_cpu_caps.has_sse4_1) { - /* PACKUSDW is the only instrinsic with a consistent signature */ return lp_build_intrinsic_binary(builder, "llvm.x86.sse41.packusdw", dst_vec_type, lo, hi); } else { @@ -288,9 +293,17 @@ lp_build_pack2(LLVMBuilderRef builder, case 16: if(dst_type.sign) +#if HAVE_LLVM >= 0x0207 + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packsswb.128", dst_vec_type, lo, hi); +#else res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packsswb.128", src_vec_type, lo, hi); +#endif else +#if HAVE_LLVM >= 0x0207 + res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packuswb.128", dst_vec_type, lo, hi); +#else res = lp_build_intrinsic_binary(builder, "llvm.x86.sse2.packuswb.128", src_vec_type, lo, hi); +#endif break; default: diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c index a133b56ac55..311c9f1b9e4 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c @@ -44,6 +44,11 @@ #include "lp_bld_sample.h" +/** + * Initialize lp_sampler_static_state object with the gallium sampler + * and texture state. + * The former is considered to be static and the later dynamic. + */ void lp_sampler_static_state(struct lp_sampler_static_state *state, const struct pipe_texture *texture, @@ -57,6 +62,18 @@ lp_sampler_static_state(struct lp_sampler_static_state *state, if(!sampler) return; + /* + * We don't copy sampler state over unless it is actually enabled, to avoid + * spurious recompiles, as the sampler static state is part of the shader + * key. + * + * Ideally the state tracker or cso_cache module would make all state + * canonical, but until that happens it's better to be safe than sorry here. + * + * XXX: Actually there's much more than can be done here, especially + * regarding 1D/2D/3D/CUBE textures, wrap modes, etc. + */ + state->format = texture->format; state->target = texture->target; state->pot_width = util_is_pot(texture->width0); @@ -69,11 +86,20 @@ lp_sampler_static_state(struct lp_sampler_static_state *state, state->min_img_filter = sampler->min_img_filter; state->min_mip_filter = sampler->min_mip_filter; state->mag_img_filter = sampler->mag_img_filter; + state->compare_mode = sampler->compare_mode; - if(sampler->compare_mode != PIPE_TEX_COMPARE_NONE) { - state->compare_func = sampler->compare_func; + if (sampler->compare_mode != PIPE_TEX_COMPARE_NONE) { + state->compare_func = sampler->compare_func; } + state->normalized_coords = sampler->normalized_coords; + state->lod_bias = sampler->lod_bias; + state->min_lod = sampler->min_lod; + state->max_lod = sampler->max_lod; + state->border_color[0] = sampler->border_color[0]; + state->border_color[1] = sampler->border_color[1]; + state->border_color[2] = sampler->border_color[2]; + state->border_color[3] = sampler->border_color[3]; } @@ -136,8 +162,7 @@ lp_build_sample_offset(struct lp_build_context *bld, const struct util_format_description *format_desc, LLVMValueRef x, LLVMValueRef y, - LLVMValueRef y_stride, - LLVMValueRef data_ptr) + LLVMValueRef y_stride) { LLVMValueRef x_stride; LLVMValueRef offset; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h index 39edcf13d14..68db91d6fd6 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h @@ -70,6 +70,8 @@ struct lp_sampler_static_state unsigned compare_mode:1; unsigned compare_func:3; unsigned normalized_coords:1; + float lod_bias, min_lod, max_lod; + float border_color[4]; }; @@ -98,6 +100,18 @@ struct lp_sampler_dynamic_state LLVMBuilderRef builder, unsigned unit); + /** Obtain the base texture depth. */ + LLVMValueRef + (*depth)( struct lp_sampler_dynamic_state *state, + LLVMBuilderRef builder, + unsigned unit); + + /** Obtain the number of mipmap levels (minus one). */ + LLVMValueRef + (*last_level)( struct lp_sampler_dynamic_state *state, + LLVMBuilderRef builder, + unsigned unit); + LLVMValueRef (*stride)( struct lp_sampler_dynamic_state *state, LLVMBuilderRef builder, @@ -134,8 +148,7 @@ lp_build_sample_offset(struct lp_build_context *bld, const struct util_format_description *format_desc, LLVMValueRef x, LLVMValueRef y, - LLVMValueRef y_stride, - LLVMValueRef data_ptr); + LLVMValueRef y_stride); void diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c index e2688622829..1dca29cdd58 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c @@ -69,7 +69,11 @@ struct lp_build_sample_context struct lp_type coord_type; struct lp_build_context coord_bld; - /** Integer coordinates */ + /** Unsigned integer coordinates */ + struct lp_type uint_coord_type; + struct lp_build_context uint_coord_bld; + + /** Signed integer coordinates */ struct lp_type int_coord_type; struct lp_build_context int_coord_bld; @@ -79,36 +83,135 @@ struct lp_build_sample_context }; +/** + * Does the given texture wrap mode allow sampling the texture border color? + * XXX maybe move this into gallium util code. + */ +static boolean +wrap_mode_uses_border_color(unsigned mode) +{ + switch (mode) { + case PIPE_TEX_WRAP_REPEAT: + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + case PIPE_TEX_WRAP_MIRROR_REPEAT: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + return FALSE; + case PIPE_TEX_WRAP_CLAMP: + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + case PIPE_TEX_WRAP_MIRROR_CLAMP: + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + return TRUE; + default: + assert(0 && "unexpected wrap mode"); + return FALSE; + } +} + + + +/** + * Gen code to fetch a texel from a texture at int coords (x, y). + * The result, texel, will be: + * texel[0] = red values + * texel[1] = green values + * texel[2] = blue values + * texel[3] = alpha values + */ static void lp_build_sample_texel_soa(struct lp_build_sample_context *bld, + LLVMValueRef width, + LLVMValueRef height, LLVMValueRef x, LLVMValueRef y, LLVMValueRef y_stride, - LLVMValueRef data_ptr, + LLVMValueRef data_array, LLVMValueRef *texel) { + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; LLVMValueRef offset; LLVMValueRef packed; + LLVMValueRef use_border = NULL; + LLVMValueRef data_ptr; + + /* use_border = x < 0 || x >= width || y < 0 || y >= height */ + if (wrap_mode_uses_border_color(bld->static_state->wrap_s)) { + LLVMValueRef b1, b2; + b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, x, int_coord_bld->zero); + b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, x, width); + use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2"); + } - offset = lp_build_sample_offset(&bld->int_coord_bld, + if (wrap_mode_uses_border_color(bld->static_state->wrap_t)) { + LLVMValueRef b1, b2; + b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, y, int_coord_bld->zero); + b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, y, height); + if (use_border) { + use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1"); + use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2"); + } + else { + use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2"); + } + } + + /* XXX always use mipmap level 0 for now */ + { + const int level = 0; + LLVMValueRef indexes[2]; + indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0); + indexes[1] = LLVMConstInt(LLVMInt32Type(), level, 0); + data_ptr = LLVMBuildGEP(bld->builder, data_array, indexes, 2, ""); + data_ptr = LLVMBuildLoad(bld->builder, data_ptr, ""); + } + + /* + * Note: if we find an app which frequently samples the texture border + * we might want to implement a true conditional here to avoid sampling + * the texture whenever possible (since that's quite a bit of code). + * Ex: + * if (use_border) { + * texel = border_color; + * } + * else { + * texel = sample_texture(coord); + * } + * As it is now, we always sample the texture, then selectively replace + * the texel color results with the border color. + */ + + /* convert x,y coords to linear offset from start of texture, in bytes */ + offset = lp_build_sample_offset(&bld->uint_coord_bld, bld->format_desc, - x, y, y_stride, - data_ptr); + x, y, y_stride); assert(bld->format_desc->block.width == 1); assert(bld->format_desc->block.height == 1); assert(bld->format_desc->block.bits <= bld->texel_type.width); + /* gather the texels from the texture */ packed = lp_build_gather(bld->builder, bld->texel_type.length, bld->format_desc->block.bits, bld->texel_type.width, data_ptr, offset); + /* convert texels to float rgba */ lp_build_unpack_rgba_soa(bld->builder, bld->format_desc, bld->texel_type, packed, texel); + + if (use_border) { + /* select texel color or border color depending on use_border */ + int chan; + for (chan = 0; chan < 4; chan++) { + LLVMValueRef border_chan = + lp_build_const_scalar(bld->texel_type, + bld->static_state->border_color[chan]); + texel[chan] = lp_build_select(&bld->texel_bld, use_border, + border_chan, texel[chan]); + } + } } @@ -117,19 +220,31 @@ lp_build_sample_packed(struct lp_build_sample_context *bld, LLVMValueRef x, LLVMValueRef y, LLVMValueRef y_stride, - LLVMValueRef data_ptr) + LLVMValueRef data_array) { LLVMValueRef offset; + LLVMValueRef data_ptr; - offset = lp_build_sample_offset(&bld->int_coord_bld, + offset = lp_build_sample_offset(&bld->uint_coord_bld, bld->format_desc, - x, y, y_stride, - data_ptr); + x, y, y_stride); assert(bld->format_desc->block.width == 1); assert(bld->format_desc->block.height == 1); assert(bld->format_desc->block.bits <= bld->texel_type.width); + /* XXX always use mipmap level 0 for now */ + { + const int level = 0; + LLVMValueRef indexes[2]; + /* get data_ptr[level] */ + indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0); + indexes[1] = LLVMConstInt(LLVMInt32Type(), level, 0); + data_ptr = LLVMBuildGEP(bld->builder, data_array, indexes, 2, ""); + /* load texture base address */ + data_ptr = LLVMBuildLoad(bld->builder, data_ptr, ""); + } + return lp_build_gather(bld->builder, bld->texel_type.length, bld->format_desc->block.bits, @@ -138,17 +253,77 @@ lp_build_sample_packed(struct lp_build_sample_context *bld, } +/** + * Helper to compute the mirror function for the PIPE_WRAP_MIRROR modes. + */ static LLVMValueRef -lp_build_sample_wrap(struct lp_build_sample_context *bld, - LLVMValueRef coord, - LLVMValueRef length, - boolean is_pot, - unsigned wrap_mode) +lp_build_coord_mirror(struct lp_build_sample_context *bld, + LLVMValueRef coord) { + struct lp_build_context *coord_bld = &bld->coord_bld; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMValueRef fract, flr, isOdd; + + /* fract = coord - floor(coord) */ + fract = lp_build_sub(coord_bld, coord, lp_build_floor(coord_bld, coord)); + + /* flr = ifloor(coord); */ + flr = lp_build_ifloor(coord_bld, coord); + + /* isOdd = flr & 1 */ + isOdd = LLVMBuildAnd(bld->builder, flr, int_coord_bld->one, ""); + + /* make coord positive or negative depending on isOdd */ + coord = lp_build_set_sign(coord_bld, fract, isOdd); + + /* convert isOdd to float */ + isOdd = lp_build_int_to_float(coord_bld, isOdd); + + /* add isOdd to coord */ + coord = lp_build_add(coord_bld, coord, isOdd); + + return coord; +} + + +/** + * We only support a few wrap modes in lp_build_sample_wrap_int() at this time. + * Return whether the given mode is supported by that function. + */ +static boolean +is_simple_wrap_mode(unsigned mode) +{ + switch (mode) { + case PIPE_TEX_WRAP_REPEAT: + case PIPE_TEX_WRAP_CLAMP: + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return TRUE; + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + default: + return FALSE; + } +} + + +/** + * Build LLVM code for texture wrap mode, for scaled integer texcoords. + * \param coord the incoming texcoord (s,t,r or q) scaled to the texture size + * \param length the texture size along one dimension + * \param is_pot if TRUE, length is a power of two + * \param wrap_mode one of PIPE_TEX_WRAP_x + */ +static LLVMValueRef +lp_build_sample_wrap_int(struct lp_build_sample_context *bld, + LLVMValueRef coord, + LLVMValueRef length, + boolean is_pot, + unsigned wrap_mode) +{ + struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld; struct lp_build_context *int_coord_bld = &bld->int_coord_bld; LLVMValueRef length_minus_one; - length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one); + length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one); switch(wrap_mode) { case PIPE_TEX_WRAP_REPEAT: @@ -161,12 +336,12 @@ lp_build_sample_wrap(struct lp_build_sample_context *bld, break; case PIPE_TEX_WRAP_CLAMP: + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: coord = lp_build_max(int_coord_bld, coord, int_coord_bld->zero); coord = lp_build_min(int_coord_bld, coord, length_minus_one); break; - case PIPE_TEX_WRAP_CLAMP_TO_EDGE: - case PIPE_TEX_WRAP_CLAMP_TO_BORDER: case PIPE_TEX_WRAP_MIRROR_REPEAT: case PIPE_TEX_WRAP_MIRROR_CLAMP: case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: @@ -174,8 +349,8 @@ lp_build_sample_wrap(struct lp_build_sample_context *bld, /* FIXME */ _debug_printf("llvmpipe: failed to translate texture wrap mode %s\n", util_dump_tex_wrap(wrap_mode, TRUE)); - coord = lp_build_max(int_coord_bld, coord, int_coord_bld->zero); - coord = lp_build_min(int_coord_bld, coord, length_minus_one); + coord = lp_build_max(uint_coord_bld, coord, uint_coord_bld->zero); + coord = lp_build_min(uint_coord_bld, coord, length_minus_one); break; default: @@ -186,6 +361,380 @@ lp_build_sample_wrap(struct lp_build_sample_context *bld, } +/** + * Build LLVM code for texture wrap mode for linear filtering. + * \param x0_out returns first integer texcoord + * \param x1_out returns second integer texcoord + * \param weight_out returns linear interpolation weight + */ +static void +lp_build_sample_wrap_linear(struct lp_build_sample_context *bld, + LLVMValueRef coord, + LLVMValueRef length, + boolean is_pot, + unsigned wrap_mode, + LLVMValueRef *x0_out, + LLVMValueRef *x1_out, + LLVMValueRef *weight_out) +{ + struct lp_build_context *coord_bld = &bld->coord_bld; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld; + LLVMValueRef two = lp_build_const_scalar(coord_bld->type, 2.0); + LLVMValueRef half = lp_build_const_scalar(coord_bld->type, 0.5); + LLVMValueRef length_f = lp_build_int_to_float(coord_bld, length); + LLVMValueRef length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one); + LLVMValueRef length_f_minus_one = lp_build_sub(coord_bld, length_f, coord_bld->one); + LLVMValueRef coord0, coord1, weight; + + switch(wrap_mode) { + case PIPE_TEX_WRAP_REPEAT: + /* mul by size and subtract 0.5 */ + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_sub(coord_bld, coord, half); + /* convert to int */ + coord0 = lp_build_ifloor(coord_bld, coord); + coord1 = lp_build_add(uint_coord_bld, coord0, uint_coord_bld->one); + /* compute lerp weight */ + weight = lp_build_fract(coord_bld, coord); + /* repeat wrap */ + if (is_pot) { + coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, ""); + coord1 = LLVMBuildAnd(bld->builder, coord1, length_minus_one, ""); + } + else { + /* Signed remainder won't give the right results for negative + * dividends but unsigned remainder does.*/ + coord0 = LLVMBuildURem(bld->builder, coord0, length, ""); + coord1 = LLVMBuildURem(bld->builder, coord1, length, ""); + } + break; + + case PIPE_TEX_WRAP_CLAMP: + if (bld->static_state->normalized_coords) { + coord = lp_build_mul(coord_bld, coord, length_f); + } + weight = lp_build_fract(coord_bld, coord); + coord0 = lp_build_clamp(coord_bld, coord, coord_bld->zero, + length_f_minus_one); + coord1 = lp_build_add(coord_bld, coord, coord_bld->one); + coord1 = lp_build_clamp(coord_bld, coord1, coord_bld->zero, + length_f_minus_one); + coord0 = lp_build_ifloor(coord_bld, coord0); + coord1 = lp_build_ifloor(coord_bld, coord1); + break; + + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + if (bld->static_state->normalized_coords) { + /* clamp to [0,1] */ + coord = lp_build_clamp(coord_bld, coord, coord_bld->zero, coord_bld->one); + /* mul by tex size and subtract 0.5 */ + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_sub(coord_bld, coord, half); + } + else { + LLVMValueRef min, max; + /* clamp to [0.5, length - 0.5] */ + min = lp_build_const_scalar(coord_bld->type, 0.5F); + max = lp_build_sub(coord_bld, length_f, min); + coord = lp_build_clamp(coord_bld, coord, min, max); + } + /* compute lerp weight */ + weight = lp_build_fract(coord_bld, coord); + /* coord0 = floor(coord); */ + coord0 = lp_build_ifloor(coord_bld, coord); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + /* coord0 = max(coord0, 0) */ + coord0 = lp_build_max(int_coord_bld, coord0, int_coord_bld->zero); + /* coord1 = min(coord1, length-1) */ + coord1 = lp_build_min(int_coord_bld, coord1, length_minus_one); + break; + + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + { + LLVMValueRef min, max; + if (bld->static_state->normalized_coords) { + /* min = -1.0 / (2 * length) = -0.5 / length */ + min = lp_build_mul(coord_bld, + lp_build_const_scalar(coord_bld->type, -0.5F), + lp_build_rcp(coord_bld, length_f)); + /* max = 1.0 - min */ + max = lp_build_sub(coord_bld, coord_bld->one, min); + /* coord = clamp(coord, min, max) */ + coord = lp_build_clamp(coord_bld, coord, min, max); + /* scale coord to length (and sub 0.5?) */ + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_sub(coord_bld, coord, half); + } + else { + /* clamp to [-0.5, length + 0.5] */ + min = lp_build_const_scalar(coord_bld->type, -0.5F); + max = lp_build_sub(coord_bld, length_f, min); + coord = lp_build_clamp(coord_bld, coord, min, max); + coord = lp_build_sub(coord_bld, coord, half); + } + /* compute lerp weight */ + weight = lp_build_fract(coord_bld, coord); + /* convert to int */ + coord0 = lp_build_ifloor(coord_bld, coord); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + } + break; + + case PIPE_TEX_WRAP_MIRROR_REPEAT: + /* compute mirror function */ + coord = lp_build_coord_mirror(bld, coord); + + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_sub(coord_bld, coord, half); + + /* compute lerp weight */ + weight = lp_build_fract(coord_bld, coord); + + /* convert to int coords */ + coord0 = lp_build_ifloor(coord_bld, coord); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + + /* coord0 = max(coord0, 0) */ + coord0 = lp_build_max(int_coord_bld, coord0, int_coord_bld->zero); + /* coord1 = min(coord1, length-1) */ + coord1 = lp_build_min(int_coord_bld, coord1, length_minus_one); + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP: + { + LLVMValueRef min, max; + /* min = 1.0 / (2 * length) */ + min = lp_build_rcp(coord_bld, lp_build_mul(coord_bld, two, length_f)); + /* max = 1.0 - min */ + max = lp_build_sub(coord_bld, coord_bld->one, min); + + coord = lp_build_abs(coord_bld, coord); + coord = lp_build_clamp(coord_bld, coord, min, max); + coord = lp_build_mul(coord_bld, coord, length_f); + if(0)coord = lp_build_sub(coord_bld, coord, half); + weight = lp_build_fract(coord_bld, coord); + coord0 = lp_build_ifloor(coord_bld, coord); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + } + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + { + LLVMValueRef min, max; + /* min = 1.0 / (2 * length) */ + min = lp_build_rcp(coord_bld, lp_build_mul(coord_bld, two, length_f)); + /* max = 1.0 - min */ + max = lp_build_sub(coord_bld, coord_bld->one, min); + + coord = lp_build_abs(coord_bld, coord); + coord = lp_build_clamp(coord_bld, coord, min, max); + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_sub(coord_bld, coord, half); + weight = lp_build_fract(coord_bld, coord); + coord0 = lp_build_ifloor(coord_bld, coord); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + } + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + { + LLVMValueRef min, max; + /* min = -1.0 / (2 * length) = -0.5 / length */ + min = lp_build_mul(coord_bld, + lp_build_const_scalar(coord_bld->type, -0.5F), + lp_build_rcp(coord_bld, length_f)); + /* max = 1.0 - min */ + max = lp_build_sub(coord_bld, coord_bld->one, min); + + coord = lp_build_abs(coord_bld, coord); + coord = lp_build_clamp(coord_bld, coord, min, max); + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_sub(coord_bld, coord, half); + weight = lp_build_fract(coord_bld, coord); + coord0 = lp_build_ifloor(coord_bld, coord); + coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one); + } + break; + + default: + assert(0); + coord0 = NULL; + coord1 = NULL; + weight = NULL; + } + + *x0_out = coord0; + *x1_out = coord1; + *weight_out = weight; +} + + +/** + * Build LLVM code for texture wrap mode for nearest filtering. + * \param coord the incoming texcoord (nominally in [0,1]) + * \param length the texture size along one dimension, as int + * \param is_pot if TRUE, length is a power of two + * \param wrap_mode one of PIPE_TEX_WRAP_x + */ +static LLVMValueRef +lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld, + LLVMValueRef coord, + LLVMValueRef length, + boolean is_pot, + unsigned wrap_mode) +{ + struct lp_build_context *coord_bld = &bld->coord_bld; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + struct lp_build_context *uint_coord_bld = &bld->uint_coord_bld; + LLVMValueRef two = lp_build_const_scalar(coord_bld->type, 2.0); + LLVMValueRef length_f = lp_build_int_to_float(coord_bld, length); + LLVMValueRef length_minus_one = lp_build_sub(uint_coord_bld, length, uint_coord_bld->one); + LLVMValueRef length_f_minus_one = lp_build_sub(coord_bld, length_f, coord_bld->one); + LLVMValueRef icoord; + + switch(wrap_mode) { + case PIPE_TEX_WRAP_REPEAT: + coord = lp_build_mul(coord_bld, coord, length_f); + icoord = lp_build_ifloor(coord_bld, coord); + if (is_pot) + icoord = LLVMBuildAnd(bld->builder, icoord, length_minus_one, ""); + else + /* Signed remainder won't give the right results for negative + * dividends but unsigned remainder does.*/ + icoord = LLVMBuildURem(bld->builder, icoord, length, ""); + break; + + case PIPE_TEX_WRAP_CLAMP: + /* mul by size */ + if (bld->static_state->normalized_coords) { + coord = lp_build_mul(coord_bld, coord, length_f); + } + /* floor */ + icoord = lp_build_ifloor(coord_bld, coord); + /* clamp to [0, size-1]. Note: int coord builder type */ + icoord = lp_build_clamp(int_coord_bld, icoord, int_coord_bld->zero, + length_minus_one); + break; + + case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + { + LLVMValueRef min, max; + if (bld->static_state->normalized_coords) { + /* min = 1.0 / (2 * length) */ + min = lp_build_rcp(coord_bld, lp_build_mul(coord_bld, two, length_f)); + /* max = length - min */ + max = lp_build_sub(coord_bld, length_f, min); + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + else { + /* clamp to [0.5, length - 0.5] */ + min = lp_build_const_scalar(coord_bld->type, 0.5F); + max = lp_build_sub(coord_bld, length_f, min); + } + /* coord = clamp(coord, min, max) */ + coord = lp_build_clamp(coord_bld, coord, min, max); + icoord = lp_build_ifloor(coord_bld, coord); + } + break; + + case PIPE_TEX_WRAP_CLAMP_TO_BORDER: + /* Note: this is the same as CLAMP_TO_EDGE, except min = -min */ + { + LLVMValueRef min, max; + if (bld->static_state->normalized_coords) { + /* min = -1.0 / (2 * length) = -0.5 / length */ + min = lp_build_mul(coord_bld, + lp_build_const_scalar(coord_bld->type, -0.5F), + lp_build_rcp(coord_bld, length_f)); + /* max = length - min */ + max = lp_build_sub(coord_bld, length_f, min); + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + } + else { + /* clamp to [-0.5, length + 0.5] */ + min = lp_build_const_scalar(coord_bld->type, -0.5F); + max = lp_build_sub(coord_bld, length_f, min); + } + /* coord = clamp(coord, min, max) */ + coord = lp_build_clamp(coord_bld, coord, min, max); + icoord = lp_build_ifloor(coord_bld, coord); + } + break; + + case PIPE_TEX_WRAP_MIRROR_REPEAT: + { + LLVMValueRef min, max; + /* min = 1.0 / (2 * length) */ + min = lp_build_rcp(coord_bld, lp_build_mul(coord_bld, two, length_f)); + /* max = length - min */ + max = lp_build_sub(coord_bld, length_f, min); + + /* compute mirror function */ + coord = lp_build_coord_mirror(bld, coord); + + /* scale coord to length */ + coord = lp_build_mul(coord_bld, coord, length_f); + + /* coord = clamp(coord, min, max) */ + coord = lp_build_clamp(coord_bld, coord, min, max); + icoord = lp_build_ifloor(coord_bld, coord); + } + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP: + coord = lp_build_abs(coord_bld, coord); + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_clamp(coord_bld, coord, coord_bld->zero, length_f_minus_one); + icoord = lp_build_ifloor(coord_bld, coord); + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: + { + LLVMValueRef min, max; + /* min = 1.0 / (2 * length) */ + min = lp_build_rcp(coord_bld, lp_build_mul(coord_bld, two, length_f)); + /* max = length - min */ + max = lp_build_sub(coord_bld, length_f, min); + + coord = lp_build_abs(coord_bld, coord); + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_clamp(coord_bld, coord, min, max); + icoord = lp_build_ifloor(coord_bld, coord); + } + break; + + case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: + { + LLVMValueRef min, max; + /* min = 1.0 / (2 * length) */ + min = lp_build_rcp(coord_bld, lp_build_mul(coord_bld, two, length_f)); + min = lp_build_negate(coord_bld, min); + /* max = length - min */ + max = lp_build_sub(coord_bld, length_f, min); + + coord = lp_build_abs(coord_bld, coord); + coord = lp_build_mul(coord_bld, coord, length_f); + coord = lp_build_clamp(coord_bld, coord, min, max); + icoord = lp_build_ifloor(coord_bld, coord); + } + break; + + default: + assert(0); + icoord = NULL; + } + + return icoord; +} + + +/** + * Sample 2D texture with nearest filtering. + */ static void lp_build_sample_2d_nearest_soa(struct lp_build_sample_context *bld, LLVMValueRef s, @@ -193,26 +742,28 @@ lp_build_sample_2d_nearest_soa(struct lp_build_sample_context *bld, LLVMValueRef width, LLVMValueRef height, LLVMValueRef stride, - LLVMValueRef data_ptr, + LLVMValueRef data_array, LLVMValueRef *texel) { - LLVMValueRef x; - LLVMValueRef y; + LLVMValueRef x, y; - x = lp_build_ifloor(&bld->coord_bld, s); - y = lp_build_ifloor(&bld->coord_bld, t); - lp_build_name(x, "tex.x.floor"); - lp_build_name(y, "tex.y.floor"); + x = lp_build_sample_wrap_nearest(bld, s, width, + bld->static_state->pot_width, + bld->static_state->wrap_s); + y = lp_build_sample_wrap_nearest(bld, t, height, + bld->static_state->pot_height, + bld->static_state->wrap_t); - x = lp_build_sample_wrap(bld, x, width, bld->static_state->pot_width, bld->static_state->wrap_s); - y = lp_build_sample_wrap(bld, y, height, bld->static_state->pot_height, bld->static_state->wrap_t); lp_build_name(x, "tex.x.wrapped"); lp_build_name(y, "tex.y.wrapped"); - lp_build_sample_texel_soa(bld, x, y, stride, data_ptr, texel); + lp_build_sample_texel_soa(bld, width, height, x, y, stride, data_array, texel); } +/** + * Sample 2D texture with bilinear filtering. + */ static void lp_build_sample_2d_linear_soa(struct lp_build_sample_context *bld, LLVMValueRef s, @@ -220,12 +771,9 @@ lp_build_sample_2d_linear_soa(struct lp_build_sample_context *bld, LLVMValueRef width, LLVMValueRef height, LLVMValueRef stride, - LLVMValueRef data_ptr, + LLVMValueRef data_array, LLVMValueRef *texel) { - LLVMValueRef half; - LLVMValueRef s_ipart; - LLVMValueRef t_ipart; LLVMValueRef s_fpart; LLVMValueRef t_fpart; LLVMValueRef x0, x1; @@ -233,32 +781,15 @@ lp_build_sample_2d_linear_soa(struct lp_build_sample_context *bld, LLVMValueRef neighbors[2][2][4]; unsigned chan; - half = lp_build_const_scalar(bld->coord_type, 0.5); - s = lp_build_sub(&bld->coord_bld, s, half); - t = lp_build_sub(&bld->coord_bld, t, half); - - s_ipart = lp_build_floor(&bld->coord_bld, s); - t_ipart = lp_build_floor(&bld->coord_bld, t); - - s_fpart = lp_build_sub(&bld->coord_bld, s, s_ipart); - t_fpart = lp_build_sub(&bld->coord_bld, t, t_ipart); - - x0 = lp_build_itrunc(&bld->coord_bld, s_ipart); - y0 = lp_build_itrunc(&bld->coord_bld, t_ipart); - - x0 = lp_build_sample_wrap(bld, x0, width, bld->static_state->pot_width, bld->static_state->wrap_s); - y0 = lp_build_sample_wrap(bld, y0, height, bld->static_state->pot_height, bld->static_state->wrap_t); - - x1 = lp_build_add(&bld->int_coord_bld, x0, bld->int_coord_bld.one); - y1 = lp_build_add(&bld->int_coord_bld, y0, bld->int_coord_bld.one); - - x1 = lp_build_sample_wrap(bld, x1, width, bld->static_state->pot_width, bld->static_state->wrap_s); - y1 = lp_build_sample_wrap(bld, y1, height, bld->static_state->pot_height, bld->static_state->wrap_t); + lp_build_sample_wrap_linear(bld, s, width, bld->static_state->pot_width, + bld->static_state->wrap_s, &x0, &x1, &s_fpart); + lp_build_sample_wrap_linear(bld, t, height, bld->static_state->pot_height, + bld->static_state->wrap_t, &y0, &y1, &t_fpart); - lp_build_sample_texel_soa(bld, x0, y0, stride, data_ptr, neighbors[0][0]); - lp_build_sample_texel_soa(bld, x1, y0, stride, data_ptr, neighbors[0][1]); - lp_build_sample_texel_soa(bld, x0, y1, stride, data_ptr, neighbors[1][0]); - lp_build_sample_texel_soa(bld, x1, y1, stride, data_ptr, neighbors[1][1]); + lp_build_sample_texel_soa(bld, width, height, x0, y0, stride, data_array, neighbors[0][0]); + lp_build_sample_texel_soa(bld, width, height, x1, y0, stride, data_array, neighbors[0][1]); + lp_build_sample_texel_soa(bld, width, height, x0, y1, stride, data_array, neighbors[1][0]); + lp_build_sample_texel_soa(bld, width, height, x1, y1, stride, data_array, neighbors[1][1]); /* TODO: Don't interpolate missing channels */ for(chan = 0; chan < 4; ++chan) { @@ -309,7 +840,7 @@ lp_build_sample_2d_linear_aos(struct lp_build_sample_context *bld, LLVMValueRef width, LLVMValueRef height, LLVMValueRef stride, - LLVMValueRef data_ptr, + LLVMValueRef data_array, LLVMValueRef *texel) { LLVMBuilderRef builder = bld->builder; @@ -334,20 +865,33 @@ lp_build_sample_2d_linear_aos(struct lp_build_sample_context *bld, h16_vec_type = lp_build_vec_type(h16.type); u8n_vec_type = lp_build_vec_type(u8n.type); + if (bld->static_state->normalized_coords) { + LLVMTypeRef coord_vec_type = lp_build_vec_type(bld->coord_type); + LLVMValueRef fp_width = LLVMBuildSIToFP(bld->builder, width, coord_vec_type, ""); + LLVMValueRef fp_height = LLVMBuildSIToFP(bld->builder, height, coord_vec_type, ""); + s = lp_build_mul(&bld->coord_bld, s, fp_width); + t = lp_build_mul(&bld->coord_bld, t, fp_height); + } + + /* scale coords by 256 (8 fractional bits) */ s = lp_build_mul_imm(&bld->coord_bld, s, 256); t = lp_build_mul_imm(&bld->coord_bld, t, 256); + /* convert float to int */ s = LLVMBuildFPToSI(builder, s, i32_vec_type, ""); t = LLVMBuildFPToSI(builder, t, i32_vec_type, ""); + /* subtract 0.5 (add -128) */ i32_c128 = lp_build_int_const_scalar(i32.type, -128); s = LLVMBuildAdd(builder, s, i32_c128, ""); t = LLVMBuildAdd(builder, t, i32_c128, ""); + /* compute floor (shift right 8) */ i32_c8 = lp_build_int_const_scalar(i32.type, 8); s_ipart = LLVMBuildAShr(builder, s, i32_c8, ""); t_ipart = LLVMBuildAShr(builder, t, i32_c8, ""); + /* compute fractional part (AND with 0xff) */ i32_c255 = lp_build_int_const_scalar(i32.type, 255); s_fpart = LLVMBuildAnd(builder, s, i32_c255, ""); t_fpart = LLVMBuildAnd(builder, t, i32_c255, ""); @@ -355,14 +899,18 @@ lp_build_sample_2d_linear_aos(struct lp_build_sample_context *bld, x0 = s_ipart; y0 = t_ipart; - x0 = lp_build_sample_wrap(bld, x0, width, bld->static_state->pot_width, bld->static_state->wrap_s); - y0 = lp_build_sample_wrap(bld, y0, height, bld->static_state->pot_height, bld->static_state->wrap_t); - x1 = lp_build_add(&bld->int_coord_bld, x0, bld->int_coord_bld.one); y1 = lp_build_add(&bld->int_coord_bld, y0, bld->int_coord_bld.one); - x1 = lp_build_sample_wrap(bld, x1, width, bld->static_state->pot_width, bld->static_state->wrap_s); - y1 = lp_build_sample_wrap(bld, y1, height, bld->static_state->pot_height, bld->static_state->wrap_t); + x0 = lp_build_sample_wrap_int(bld, x0, width, bld->static_state->pot_width, + bld->static_state->wrap_s); + y0 = lp_build_sample_wrap_int(bld, y0, height, bld->static_state->pot_height, + bld->static_state->wrap_t); + + x1 = lp_build_sample_wrap_int(bld, x1, width, bld->static_state->pot_width, + bld->static_state->wrap_s); + y1 = lp_build_sample_wrap_int(bld, y1, height, bld->static_state->pot_height, + bld->static_state->wrap_t); /* * Transform 4 x i32 in @@ -432,10 +980,10 @@ lp_build_sample_2d_linear_aos(struct lp_build_sample_context *bld, * The higher 8 bits of the resulting elements will be zero. */ - neighbors[0][0] = lp_build_sample_packed(bld, x0, y0, stride, data_ptr); - neighbors[0][1] = lp_build_sample_packed(bld, x1, y0, stride, data_ptr); - neighbors[1][0] = lp_build_sample_packed(bld, x0, y1, stride, data_ptr); - neighbors[1][1] = lp_build_sample_packed(bld, x1, y1, stride, data_ptr); + neighbors[0][0] = lp_build_sample_packed(bld, x0, y0, stride, data_array); + neighbors[0][1] = lp_build_sample_packed(bld, x1, y0, stride, data_array); + neighbors[1][0] = lp_build_sample_packed(bld, x0, y1, stride, data_array); + neighbors[1][1] = lp_build_sample_packed(bld, x1, y1, stride, data_array); neighbors[0][0] = LLVMBuildBitCast(builder, neighbors[0][0], u8n_vec_type, ""); neighbors[0][1] = LLVMBuildBitCast(builder, neighbors[0][1], u8n_vec_type, ""); @@ -518,6 +1066,195 @@ lp_build_sample_compare(struct lp_build_sample_context *bld, } +static int +texture_dims(enum pipe_texture_target tex) +{ + switch (tex) { + case PIPE_TEXTURE_1D: + return 1; + case PIPE_TEXTURE_2D: + case PIPE_TEXTURE_CUBE: + return 2; + case PIPE_TEXTURE_3D: + return 3; + default: + assert(0 && "bad texture target in texture_dims()"); + return 2; + } +} + + +/** + * Generate code to compute texture level of detail (lambda). + * \param s vector of texcoord s values + * \param t vector of texcoord t values + * \param r vector of texcoord r values + * \param width scalar int texture width + * \param height scalar int texture height + * \param depth scalar int texture depth + */ +static LLVMValueRef +lp_build_lod_selector(struct lp_build_sample_context *bld, + LLVMValueRef s, + LLVMValueRef t, + LLVMValueRef r, + LLVMValueRef width, + LLVMValueRef height, + LLVMValueRef depth) + +{ + const int dims = texture_dims(bld->static_state->target); + struct lp_build_context *coord_bld = &bld->coord_bld; + + LLVMValueRef lod_bias = lp_build_const_scalar(bld->coord_bld.type, + bld->static_state->lod_bias); + LLVMValueRef min_lod = lp_build_const_scalar(bld->coord_bld.type, + bld->static_state->min_lod); + LLVMValueRef max_lod = lp_build_const_scalar(bld->coord_bld.type, + bld->static_state->max_lod); + + LLVMValueRef index0 = LLVMConstInt(LLVMInt32Type(), 0, 0); + LLVMValueRef index1 = LLVMConstInt(LLVMInt32Type(), 1, 0); + LLVMValueRef index2 = LLVMConstInt(LLVMInt32Type(), 2, 0); + + LLVMValueRef s0, s1, s2; + LLVMValueRef t0, t1, t2; + LLVMValueRef r0, r1, r2; + LLVMValueRef dsdx, dsdy, dtdx, dtdy, drdx, drdy; + LLVMValueRef rho, lod; + + /* + * dsdx = abs(s[1] - s[0]); + * dsdy = abs(s[2] - s[0]); + * dtdx = abs(t[1] - t[0]); + * dtdy = abs(t[2] - t[0]); + * drdx = abs(r[1] - r[0]); + * drdy = abs(r[2] - r[0]); + * XXX we're assuming a four-element quad in 2x2 layout here. + */ + s0 = LLVMBuildExtractElement(bld->builder, s, index0, "s0"); + s1 = LLVMBuildExtractElement(bld->builder, s, index1, "s1"); + s2 = LLVMBuildExtractElement(bld->builder, s, index2, "s2"); + dsdx = lp_build_abs(coord_bld, lp_build_sub(coord_bld, s1, s0)); + dsdy = lp_build_abs(coord_bld, lp_build_sub(coord_bld, s2, s0)); + if (dims > 1) { + t0 = LLVMBuildExtractElement(bld->builder, t, index0, "t0"); + t1 = LLVMBuildExtractElement(bld->builder, t, index1, "t1"); + t2 = LLVMBuildExtractElement(bld->builder, t, index2, "t2"); + dtdx = lp_build_abs(coord_bld, lp_build_sub(coord_bld, t1, t0)); + dtdy = lp_build_abs(coord_bld, lp_build_sub(coord_bld, t2, t0)); + if (dims > 2) { + r0 = LLVMBuildExtractElement(bld->builder, r, index0, "r0"); + r1 = LLVMBuildExtractElement(bld->builder, r, index1, "r1"); + r2 = LLVMBuildExtractElement(bld->builder, r, index2, "r2"); + drdx = lp_build_abs(coord_bld, lp_build_sub(coord_bld, r1, r0)); + drdy = lp_build_abs(coord_bld, lp_build_sub(coord_bld, r2, r0)); + } + } + + /* Compute rho = max of all partial derivatives scaled by texture size. + * XXX this can be vectorized somewhat + */ + rho = lp_build_mul(coord_bld, + lp_build_max(coord_bld, dsdx, dsdy), + lp_build_int_to_float(coord_bld, width)); + if (dims > 1) { + LLVMValueRef max; + max = lp_build_mul(coord_bld, + lp_build_max(coord_bld, dtdx, dtdy), + lp_build_int_to_float(coord_bld, height)); + rho = lp_build_max(coord_bld, rho, max); + if (dims > 2) { + max = lp_build_mul(coord_bld, + lp_build_max(coord_bld, drdx, drdy), + lp_build_int_to_float(coord_bld, depth)); + rho = lp_build_max(coord_bld, rho, max); + } + } + + /* compute lod = log2(rho) */ + lod = lp_build_log2(coord_bld, rho); + + /* add lod bias */ + lod = lp_build_add(coord_bld, lod, lod_bias); + + /* clamp lod */ + lod = lp_build_clamp(coord_bld, lod, min_lod, max_lod); + + return lod; +} + + +/** + * For PIPE_TEX_MIPFILTER_NEAREST, convert float LOD to integer + * mipmap level index. + * \param lod scalar float texture level of detail + * \param level_out returns integer + */ +static void +lp_build_nearest_mip_level(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef lod, + LLVMValueRef *level_out) +{ + struct lp_build_context *coord_bld = &bld->coord_bld; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMValueRef last_level, level; + + last_level = bld->dynamic_state->last_level(bld->dynamic_state, + bld->builder, unit); + + /* convert float lod to integer */ + level = lp_build_iround(coord_bld, lod); + + /* clamp level to legal range of levels */ + *level_out = lp_build_clamp(int_coord_bld, level, + int_coord_bld->zero, + last_level); +} + + +/** + * For PIPE_TEX_MIPFILTER_LINEAR, convert float LOD to integer to + * two (adjacent) mipmap level indexes. Later, we'll sample from those + * two mipmap levels and interpolate between them. + */ +static void +lp_build_linear_mip_levels(struct lp_build_sample_context *bld, + unsigned unit, + LLVMValueRef lod, + LLVMValueRef *level0_out, + LLVMValueRef *level1_out, + LLVMValueRef *weight_out) +{ + struct lp_build_context *coord_bld = &bld->coord_bld; + struct lp_build_context *int_coord_bld = &bld->int_coord_bld; + LLVMValueRef last_level, level; + + last_level = bld->dynamic_state->last_level(bld->dynamic_state, + bld->builder, unit); + + /* convert float lod to integer */ + level = lp_build_ifloor(coord_bld, lod); + + /* compute level 0 and clamp to legal range of levels */ + *level0_out = lp_build_clamp(int_coord_bld, level, + int_coord_bld->zero, + last_level); + /* compute level 1 and clamp to legal range of levels */ + *level1_out = lp_build_add(int_coord_bld, *level0_out, int_coord_bld->one); + *level1_out = lp_build_min(int_coord_bld, *level1_out, int_coord_bld->zero); + + *weight_out = lp_build_fract(coord_bld, lod); +} + + + +/** + * Build texture sampling code. + * 'texel' will return a vector of four LLVMValueRefs corresponding to + * R, G, B, A. + */ void lp_build_sample_soa(LLVMBuilderRef builder, const struct lp_sampler_static_state *static_state, @@ -533,10 +1270,14 @@ lp_build_sample_soa(LLVMBuilderRef builder, LLVMValueRef width; LLVMValueRef height; LLVMValueRef stride; - LLVMValueRef data_ptr; + LLVMValueRef data_array; LLVMValueRef s; LLVMValueRef t; - LLVMValueRef p; + LLVMValueRef r; + + (void) lp_build_lod_selector; /* temporary to silence warning */ + (void) lp_build_nearest_mip_level; + (void) lp_build_linear_mip_levels; /* Setup our build context */ memset(&bld, 0, sizeof bld); @@ -545,9 +1286,11 @@ lp_build_sample_soa(LLVMBuilderRef builder, bld.dynamic_state = dynamic_state; bld.format_desc = util_format_description(static_state->format); bld.coord_type = type; + bld.uint_coord_type = lp_uint_type(type); bld.int_coord_type = lp_int_type(type); bld.texel_type = type; lp_build_context_init(&bld.coord_bld, builder, bld.coord_type); + lp_build_context_init(&bld.uint_coord_bld, builder, bld.uint_coord_type); lp_build_context_init(&bld.int_coord_bld, builder, bld.int_coord_type); lp_build_context_init(&bld.texel_bld, builder, bld.texel_type); @@ -555,36 +1298,34 @@ lp_build_sample_soa(LLVMBuilderRef builder, width = dynamic_state->width(dynamic_state, builder, unit); height = dynamic_state->height(dynamic_state, builder, unit); stride = dynamic_state->stride(dynamic_state, builder, unit); - data_ptr = dynamic_state->data_ptr(dynamic_state, builder, unit); + data_array = dynamic_state->data_ptr(dynamic_state, builder, unit); + /* Note that data_array is an array[level] of pointers to texture images */ s = coords[0]; t = coords[1]; - p = coords[2]; + r = coords[2]; - width = lp_build_broadcast_scalar(&bld.int_coord_bld, width); - height = lp_build_broadcast_scalar(&bld.int_coord_bld, height); - stride = lp_build_broadcast_scalar(&bld.int_coord_bld, stride); + width = lp_build_broadcast_scalar(&bld.uint_coord_bld, width); + height = lp_build_broadcast_scalar(&bld.uint_coord_bld, height); + stride = lp_build_broadcast_scalar(&bld.uint_coord_bld, stride); if(static_state->target == PIPE_TEXTURE_1D) t = bld.coord_bld.zero; - if(static_state->normalized_coords) { - LLVMTypeRef coord_vec_type = lp_build_vec_type(bld.coord_type); - LLVMValueRef fp_width = LLVMBuildSIToFP(builder, width, coord_vec_type, ""); - LLVMValueRef fp_height = LLVMBuildSIToFP(builder, height, coord_vec_type, ""); - s = lp_build_mul(&bld.coord_bld, s, fp_width); - t = lp_build_mul(&bld.coord_bld, t, fp_height); - } - switch (static_state->min_img_filter) { case PIPE_TEX_FILTER_NEAREST: - lp_build_sample_2d_nearest_soa(&bld, s, t, width, height, stride, data_ptr, texel); + lp_build_sample_2d_nearest_soa(&bld, s, t, width, height, + stride, data_array, texel); break; case PIPE_TEX_FILTER_LINEAR: - if(lp_format_is_rgba8(bld.format_desc)) - lp_build_sample_2d_linear_aos(&bld, s, t, width, height, stride, data_ptr, texel); + if(lp_format_is_rgba8(bld.format_desc) && + is_simple_wrap_mode(static_state->wrap_s) && + is_simple_wrap_mode(static_state->wrap_t)) + lp_build_sample_2d_linear_aos(&bld, s, t, width, height, + stride, data_array, texel); else - lp_build_sample_2d_linear_soa(&bld, s, t, width, height, stride, data_ptr, texel); + lp_build_sample_2d_linear_soa(&bld, s, t, width, height, + stride, data_array, texel); break; default: assert(0); @@ -593,5 +1334,5 @@ lp_build_sample_soa(LLVMBuilderRef builder, /* FIXME: respect static_state->min_mip_filter */; /* FIXME: respect static_state->mag_img_filter */; - lp_build_sample_compare(&bld, p, texel); + lp_build_sample_compare(&bld, r, texel); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c index 4cf28a9f934..fbb664d43a0 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c @@ -52,6 +52,7 @@ #include "lp_bld_swizzle.h" #include "lp_bld_flow.h" #include "lp_bld_tgsi.h" +#include "lp_bld_debug.h" #define LP_MAX_TEMPS 256 @@ -81,6 +82,21 @@ #define QUAD_BOTTOM_LEFT 2 #define QUAD_BOTTOM_RIGHT 3 +#define LP_TGSI_MAX_NESTING 16 + +struct lp_exec_mask { + struct lp_build_context *bld; + + boolean has_mask; + + LLVMTypeRef int_vec_type; + + LLVMValueRef cond_stack[LP_TGSI_MAX_NESTING]; + int cond_stack_size; + LLVMValueRef cond_mask; + + LLVMValueRef exec_mask; +}; struct lp_build_tgsi_soa_context { @@ -97,9 +113,9 @@ struct lp_build_tgsi_soa_context LLVMValueRef temps[LP_MAX_TEMPS][NUM_CHANNELS]; struct lp_build_mask_context *mask; + struct lp_exec_mask exec_mask; }; - static const unsigned char swizzle_left[4] = { QUAD_TOP_LEFT, QUAD_TOP_LEFT, @@ -124,6 +140,72 @@ swizzle_bottom[4] = { QUAD_BOTTOM_LEFT, QUAD_BOTTOM_RIGHT }; +static void lp_exec_mask_init(struct lp_exec_mask *mask, struct lp_build_context *bld) +{ + mask->bld = bld; + mask->has_mask = FALSE; + mask->cond_stack_size = 0; + + mask->int_vec_type = lp_build_int_vec_type(mask->bld->type); +} + +static void lp_exec_mask_update(struct lp_exec_mask *mask) +{ + mask->exec_mask = mask->cond_mask; + mask->has_mask = (mask->cond_stack_size > 0); +} + +static void lp_exec_mask_cond_push(struct lp_exec_mask *mask, + LLVMValueRef val) +{ + mask->cond_stack[mask->cond_stack_size++] = mask->cond_mask; + mask->cond_mask = LLVMBuildBitCast(mask->bld->builder, val, + mask->int_vec_type, ""); + + lp_exec_mask_update(mask); +} + +static void lp_exec_mask_cond_invert(struct lp_exec_mask *mask) +{ + LLVMValueRef prev_mask = mask->cond_stack[mask->cond_stack_size - 1]; + LLVMValueRef inv_mask = LLVMBuildNot(mask->bld->builder, + mask->cond_mask, ""); + + /* means that we didn't have any mask before and that + * we were fully enabled */ + if (mask->cond_stack_size <= 1) { + prev_mask = LLVMConstAllOnes(mask->int_vec_type); + } + + mask->cond_mask = LLVMBuildAnd(mask->bld->builder, + inv_mask, + prev_mask, ""); + lp_exec_mask_update(mask); +} + +static void lp_exec_mask_cond_pop(struct lp_exec_mask *mask) +{ + mask->cond_mask = mask->cond_stack[--mask->cond_stack_size]; + lp_exec_mask_update(mask); +} + +static void lp_exec_mask_store(struct lp_exec_mask *mask, + LLVMValueRef val, + LLVMValueRef dst) +{ + if (mask->has_mask) { + LLVMValueRef real_val, dst_val; + + dst_val = LLVMBuildLoad(mask->bld->builder, dst, ""); + real_val = lp_build_select(mask->bld, + mask->exec_mask, + val, dst_val); + + LLVMBuildStore(mask->bld->builder, real_val, dst); + } else + LLVMBuildStore(mask->bld->builder, val, dst); +} + static LLVMValueRef emit_ddx(struct lp_build_tgsi_soa_context *bld, @@ -287,13 +369,13 @@ emit_store( switch( reg->Register.File ) { case TGSI_FILE_OUTPUT: - LLVMBuildStore(bld->base.builder, value, - bld->outputs[reg->Register.Index][chan_index]); + lp_exec_mask_store(&bld->exec_mask, value, + bld->outputs[reg->Register.Index][chan_index]); break; case TGSI_FILE_TEMPORARY: - LLVMBuildStore(bld->base.builder, value, - bld->temps[reg->Register.Index][chan_index]); + lp_exec_mask_store(&bld->exec_mask, value, + bld->temps[reg->Register.Index][chan_index]); break; case TGSI_FILE_ADDRESS: @@ -301,6 +383,11 @@ emit_store( assert(0); break; + case TGSI_FILE_PREDICATE: + /* FIXME */ + assert(0); + break; + default: assert( 0 ); } @@ -498,6 +585,17 @@ emit_instruction( if (indirect_temp_reference(inst)) return FALSE; + /* + * Stores and write masks are handled in a general fashion after the long + * instruction opcode switch statement. + * + * Although not stricitly necessary, we avoid generating instructions for + * channels which won't be stored, in cases where's that easy. For some + * complex instructions, like texture sampling, it is more convenient to + * assume a full writemask and then let LLVM optimization passes eliminate + * redundant code. + */ + assert(info->num_dst <= 1); if(info->num_dst) { FOR_EACH_DST0_ENABLED_CHANNEL( inst, chan_index ) { @@ -1272,8 +1370,8 @@ emit_instruction( break; case TGSI_OPCODE_IF: - /* FIXME */ - return 0; + tmp0 = emit_fetch(bld, inst, 0, CHAN_X); + lp_exec_mask_cond_push(&bld->exec_mask, tmp0); break; case TGSI_OPCODE_BGNFOR: @@ -1289,13 +1387,11 @@ emit_instruction( break; case TGSI_OPCODE_ELSE: - /* FIXME */ - return 0; + lp_exec_mask_cond_invert(&bld->exec_mask); break; case TGSI_OPCODE_ENDIF: - /* FIXME */ - return 0; + lp_exec_mask_cond_pop(&bld->exec_mask); break; case TGSI_OPCODE_ENDFOR: @@ -1458,6 +1554,8 @@ lp_build_tgsi_soa(LLVMBuilderRef builder, bld.consts_ptr = consts_ptr; bld.sampler = sampler; + lp_exec_mask_init(&bld.exec_mask, &bld.base); + tgsi_parse_init( &parse, tokens ); while( !tgsi_parse_end_of_tokens( &parse ) ) { diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.c b/src/gallium/auxiliary/gallivm/lp_bld_type.c index 8270cd057f6..c327ba045a6 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.c @@ -178,6 +178,25 @@ lp_build_int32_vec4_type(void) } +/** + * Create unsigned integer type variation of given type. + */ +struct lp_type +lp_uint_type(struct lp_type type) +{ + struct lp_type res_type; + + memset(&res_type, 0, sizeof res_type); + res_type.width = type.width; + res_type.length = type.length; + + return res_type; +} + + +/** + * Create signed integer type variation of given type. + */ struct lp_type lp_int_type(struct lp_type type) { @@ -186,6 +205,7 @@ lp_int_type(struct lp_type type) memset(&res_type, 0, sizeof res_type); res_type.width = type.width; res_type.length = type.length; + res_type.sign = 1; return res_type; } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_type.h b/src/gallium/auxiliary/gallivm/lp_bld_type.h index 62ee05be4df..16946cc28a2 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_type.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_type.h @@ -257,6 +257,10 @@ lp_build_int32_vec4_type(void); struct lp_type +lp_uint_type(struct lp_type type); + + +struct lp_type lp_int_type(struct lp_type type); diff --git a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c index 95eb5f65635..d97f749b6ed 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c +++ b/src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c @@ -696,7 +696,7 @@ fenced_buffer_map(struct pb_buffer *buf, * Don't wait for the GPU to finish accessing it, if blocking is forbidden. */ if((flags & PIPE_BUFFER_USAGE_DONTBLOCK) && - ops->fence_signalled(ops, fenced_buf->fence, 0) == 0) { + ops->fence_signalled(ops, fenced_buf->fence, 0) != 0) { goto done; } diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c index 53bc019a204..86f9266c95f 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_cache.c @@ -294,7 +294,7 @@ pb_cache_manager_create_buffer(struct pb_manager *_mgr, LIST_DEL(&buf->head); pipe_mutex_unlock(mgr->mutex); /* Increase refcount */ - pipe_reference(NULL, &buf->base.base.reference); + pipe_reference_init(&buf->base.base.reference, 1); return &buf->base; } diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c index c2593cf1653..a5dbded2bce 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_debug.c @@ -179,7 +179,9 @@ pb_debug_buffer_check(struct pb_debug_buffer *buf) { uint8_t *map; - map = pb_map(buf->buffer, PIPE_BUFFER_USAGE_CPU_READ); + map = pb_map(buf->buffer, + PIPE_BUFFER_USAGE_CPU_READ | + PIPE_BUFFER_USAGE_UNSYNCHRONIZED); assert(map); if(map) { boolean underflow, overflow; diff --git a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c index c445cb578b0..24e2820f881 100644 --- a/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c +++ b/src/gallium/auxiliary/pipebuffer/pb_bufmgr_slab.c @@ -483,11 +483,15 @@ pb_slab_range_manager_create_buffer(struct pb_manager *_mgr, { struct pb_slab_range_manager *mgr = pb_slab_range_manager(_mgr); pb_size bufSize; + pb_size reqSize = size; unsigned i; + if(desc->alignment > reqSize) + reqSize = desc->alignment; + bufSize = mgr->minBufSize; for (i = 0; i < mgr->numBuckets; ++i) { - if(bufSize >= size) + if(bufSize >= reqSize) return mgr->buckets[i]->create_buffer(mgr->buckets[i], size, desc); bufSize *= 2; } diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c index 262422364bf..f853ea2820e 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c @@ -110,6 +110,42 @@ micro_ceil(union tgsi_exec_channel *dst, } static void +micro_clamp(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->f[0] = src0->f[0] < src1->f[0] ? src1->f[0] : src0->f[0] > src2->f[0] ? src2->f[0] : src0->f[0]; + dst->f[1] = src0->f[1] < src1->f[1] ? src1->f[1] : src0->f[1] > src2->f[1] ? src2->f[1] : src0->f[1]; + dst->f[2] = src0->f[2] < src1->f[2] ? src1->f[2] : src0->f[2] > src2->f[2] ? src2->f[2] : src0->f[2]; + dst->f[3] = src0->f[3] < src1->f[3] ? src1->f[3] : src0->f[3] > src2->f[3] ? src2->f[3] : src0->f[3]; +} + +static void +micro_cmp(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->f[0] = src0->f[0] < 0.0f ? src1->f[0] : src2->f[0]; + dst->f[1] = src0->f[1] < 0.0f ? src1->f[1] : src2->f[1]; + dst->f[2] = src0->f[2] < 0.0f ? src1->f[2] : src2->f[2]; + dst->f[3] = src0->f[3] < 0.0f ? src1->f[3] : src2->f[3]; +} + +static void +micro_cnd(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) +{ + dst->f[0] = src2->f[0] > 0.5f ? src0->f[0] : src1->f[0]; + dst->f[1] = src2->f[1] > 0.5f ? src0->f[1] : src1->f[1]; + dst->f[2] = src2->f[2] > 0.5f ? src0->f[2] : src1->f[2]; + dst->f[3] = src2->f[3] > 0.5f ? src0->f[3] : src1->f[3]; +} + +static void micro_cos(union tgsi_exec_channel *dst, const union tgsi_exec_channel *src) { @@ -232,22 +268,26 @@ micro_lg2(union tgsi_exec_channel *dst, static void micro_lrp(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) { - dst->f[0] = src[0].f[0] * (src[1].f[0] - src[2].f[0]) + src[2].f[0]; - dst->f[1] = src[0].f[1] * (src[1].f[1] - src[2].f[1]) + src[2].f[1]; - dst->f[2] = src[0].f[2] * (src[1].f[2] - src[2].f[2]) + src[2].f[2]; - dst->f[3] = src[0].f[3] * (src[1].f[3] - src[2].f[3]) + src[2].f[3]; + dst->f[0] = src0->f[0] * (src1->f[0] - src2->f[0]) + src2->f[0]; + dst->f[1] = src0->f[1] * (src1->f[1] - src2->f[1]) + src2->f[1]; + dst->f[2] = src0->f[2] * (src1->f[2] - src2->f[2]) + src2->f[2]; + dst->f[3] = src0->f[3] * (src1->f[3] - src2->f[3]) + src2->f[3]; } static void micro_mad(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) { - dst->f[0] = src[0].f[0] * src[1].f[0] + src[2].f[0]; - dst->f[1] = src[0].f[1] * src[1].f[1] + src[2].f[1]; - dst->f[2] = src[0].f[2] * src[1].f[2] + src[2].f[2]; - dst->f[3] = src[0].f[3] * src[1].f[3] + src[2].f[3]; + dst->f[0] = src0->f[0] * src1->f[0] + src2->f[0]; + dst->f[1] = src0->f[1] * src1->f[1] + src2->f[1]; + dst->f[2] = src0->f[2] * src1->f[2] + src2->f[2]; + dst->f[3] = src0->f[3] * src1->f[3] + src2->f[3]; } static void @@ -304,22 +344,24 @@ micro_rsq(union tgsi_exec_channel *dst, static void micro_seq(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] == src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] == src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] == src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] == src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] == src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] == src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] == src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] == src1->f[3] ? 1.0f : 0.0f; } static void micro_sge(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] >= src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] >= src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] >= src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] >= src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] >= src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] >= src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] >= src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] >= src1->f[3] ? 1.0f : 0.0f; } static void @@ -334,12 +376,13 @@ micro_sgn(union tgsi_exec_channel *dst, static void micro_sgt(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] > src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] > src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] > src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] > src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] > src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] > src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] > src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] > src1->f[3] ? 1.0f : 0.0f; } static void @@ -354,32 +397,35 @@ micro_sin(union tgsi_exec_channel *dst, static void micro_sle(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] <= src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] <= src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] <= src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] <= src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] <= src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] <= src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] <= src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] <= src1->f[3] ? 1.0f : 0.0f; } static void micro_slt(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] < src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] < src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] < src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] < src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] < src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] < src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] < src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] < src1->f[3] ? 1.0f : 0.0f; } static void micro_sne(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->f[0] = src[0].f[0] != src[1].f[0] ? 1.0f : 0.0f; - dst->f[1] = src[0].f[1] != src[1].f[1] ? 1.0f : 0.0f; - dst->f[2] = src[0].f[2] != src[1].f[2] ? 1.0f : 0.0f; - dst->f[3] = src[0].f[3] != src[1].f[3] ? 1.0f : 0.0f; + dst->f[0] = src0->f[0] != src1->f[0] ? 1.0f : 0.0f; + dst->f[1] = src0->f[1] != src1->f[1] ? 1.0f : 0.0f; + dst->f[2] = src0->f[2] != src1->f[2] ? 1.0f : 0.0f; + dst->f[3] = src0->f[3] != src1->f[3] ? 1.0f : 0.0f; } static void @@ -461,6 +507,10 @@ enum tgsi_exec_datatype { static const union tgsi_exec_channel ZeroVec = { { 0.0, 0.0, 0.0, 0.0 } }; +static const union tgsi_exec_channel OneVec = { + {1.0f, 1.0f, 1.0f, 1.0f} +}; + /** * Assert that none of the float values in 'chan' are infinite or NaN. @@ -759,10 +809,9 @@ tgsi_exec_machine_destroy(struct tgsi_exec_machine *mach) } static void -micro_add( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_add(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] + src1->f[0]; dst->f[1] = src0->f[1] + src1->f[1]; @@ -831,10 +880,9 @@ micro_lt( } static void -micro_max( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_max(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] > src1->f[0] ? src0->f[0] : src1->f[0]; dst->f[1] = src0->f[1] > src1->f[1] ? src0->f[1] : src1->f[1]; @@ -843,10 +891,9 @@ micro_max( } static void -micro_min( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_min(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] < src1->f[0] ? src0->f[0] : src1->f[0]; dst->f[1] = src0->f[1] < src1->f[1] ? src0->f[1] : src1->f[1]; @@ -855,10 +902,9 @@ micro_min( } static void -micro_mul( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_mul(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] * src1->f[0]; dst->f[1] = src0->f[1] * src1->f[1]; @@ -951,20 +997,9 @@ micro_pow( } static void -micro_sqrt( union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src ) -{ - dst->f[0] = sqrtf( src->f[0] ); - dst->f[1] = sqrtf( src->f[1] ); - dst->f[2] = sqrtf( src->f[2] ); - dst->f[3] = sqrtf( src->f[3] ); -} - -static void -micro_sub( - union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src0, - const union tgsi_exec_channel *src1 ) +micro_sub(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { dst->f[0] = src0->f[0] - src1->f[0]; dst->f[1] = src0->f[1] - src1->f[1]; @@ -1804,13 +1839,13 @@ exec_declaration(struct tgsi_exec_machine *mach, } } -typedef void (* micro_op)(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src); +typedef void (* micro_unary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src); static void exec_scalar_unary(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, - micro_op op, + micro_unary_op op, enum tgsi_exec_datatype dst_datatype, enum tgsi_exec_datatype src_datatype) { @@ -1830,7 +1865,7 @@ exec_scalar_unary(struct tgsi_exec_machine *mach, static void exec_vector_unary(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, - micro_op op, + micro_unary_op op, enum tgsi_exec_datatype dst_datatype, enum tgsi_exec_datatype src_datatype) { @@ -1852,10 +1887,14 @@ exec_vector_unary(struct tgsi_exec_machine *mach, } } +typedef void (* micro_binary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1); + static void exec_vector_binary(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, - micro_op op, + micro_binary_op op, enum tgsi_exec_datatype dst_datatype, enum tgsi_exec_datatype src_datatype) { @@ -1868,7 +1907,7 @@ exec_vector_binary(struct tgsi_exec_machine *mach, fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype); fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype); - op(&dst.xyzw[chan], src); + op(&dst.xyzw[chan], &src[0], &src[1]); } } for (chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1878,10 +1917,15 @@ exec_vector_binary(struct tgsi_exec_machine *mach, } } +typedef void (* micro_trinary_op)(union tgsi_exec_channel *dst, + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2); + static void exec_vector_trinary(struct tgsi_exec_machine *mach, const struct tgsi_full_instruction *inst, - micro_op op, + micro_trinary_op op, enum tgsi_exec_datatype dst_datatype, enum tgsi_exec_datatype src_datatype) { @@ -1895,7 +1939,7 @@ exec_vector_trinary(struct tgsi_exec_machine *mach, fetch_source(mach, &src[0], &inst->Src[0], chan, src_datatype); fetch_source(mach, &src[1], &inst->Src[1], chan, src_datatype); fetch_source(mach, &src[2], &inst->Src[2], chan, src_datatype); - op(&dst.xyzw[chan], src); + op(&dst.xyzw[chan], &src[0], &src[1], &src[2]); } } for (chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1919,7 +1963,7 @@ exec_dp3(struct tgsi_exec_machine *mach, for (chan = CHAN_Y; chan <= CHAN_Z; chan++) { fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[2], arg); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); } for (chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1943,7 +1987,7 @@ exec_dp4(struct tgsi_exec_machine *mach, for (chan = CHAN_Y; chan <= CHAN_W; chan++) { fetch_source(mach, &arg[0], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], chan, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[2], arg); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); } for (chan = 0; chan < NUM_CHANNELS; chan++) { @@ -1966,7 +2010,7 @@ exec_dp2a(struct tgsi_exec_machine *mach, fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[0], arg); + micro_mad(&arg[0], &arg[0], &arg[1], &arg[2]); fetch_source(mach, &arg[1], &inst->Src[2], CHAN_X, TGSI_EXEC_DATA_FLOAT); micro_add(&arg[0], &arg[0], &arg[1]); @@ -1991,11 +2035,11 @@ exec_dph(struct tgsi_exec_machine *mach, fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[2], arg); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Z, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Z, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[0], arg); + micro_mad(&arg[0], &arg[0], &arg[1], &arg[2]); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_W, TGSI_EXEC_DATA_FLOAT); micro_add(&arg[0], &arg[0], &arg[1]); @@ -2020,7 +2064,7 @@ exec_dp2(struct tgsi_exec_machine *mach, fetch_source(mach, &arg[0], &inst->Src[0], CHAN_Y, TGSI_EXEC_DATA_FLOAT); fetch_source(mach, &arg[1], &inst->Src[1], CHAN_Y, TGSI_EXEC_DATA_FLOAT); - micro_mad(&arg[2], arg); + micro_mad(&arg[2], &arg[0], &arg[1], &arg[2]); for (chan = 0; chan < NUM_CHANNELS; chan++) { if (inst->Dst[0].Register.WriteMask & (1 << chan)) { @@ -2030,6 +2074,70 @@ exec_dp2(struct tgsi_exec_machine *mach, } static void +exec_nrm4(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + unsigned int chan; + union tgsi_exec_channel arg[4]; + union tgsi_exec_channel scale; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&scale, &arg[0], &arg[0]); + + for (chan = CHAN_Y; chan <= CHAN_W; chan++) { + union tgsi_exec_channel product; + + fetch_source(mach, &arg[chan], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); + micro_mul(&product, &arg[chan], &arg[chan]); + micro_add(&scale, &scale, &product); + } + + micro_rsq(&scale, &scale); + + for (chan = CHAN_X; chan <= CHAN_W; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + micro_mul(&arg[chan], &arg[chan], &scale); + store_dest(mach, &arg[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } +} + +static void +exec_nrm3(struct tgsi_exec_machine *mach, + const struct tgsi_full_instruction *inst) +{ + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_XYZ) { + unsigned int chan; + union tgsi_exec_channel arg[3]; + union tgsi_exec_channel scale; + + fetch_source(mach, &arg[0], &inst->Src[0], CHAN_X, TGSI_EXEC_DATA_FLOAT); + micro_mul(&scale, &arg[0], &arg[0]); + + for (chan = CHAN_Y; chan <= CHAN_Z; chan++) { + union tgsi_exec_channel product; + + fetch_source(mach, &arg[chan], &inst->Src[0], chan, TGSI_EXEC_DATA_FLOAT); + micro_mul(&product, &arg[chan], &arg[chan]); + micro_add(&scale, &scale, &product); + } + + micro_rsq(&scale, &scale); + + for (chan = CHAN_X; chan <= CHAN_Z; chan++) { + if (inst->Dst[0].Register.WriteMask & (1 << chan)) { + micro_mul(&arg[chan], &arg[chan], &scale); + store_dest(mach, &arg[chan], &inst->Dst[0], inst, chan, TGSI_EXEC_DATA_FLOAT); + } + } + } + + if (inst->Dst[0].Register.WriteMask & TGSI_WRITEMASK_W) { + store_dest(mach, &OneVec, &inst->Dst[0], inst, CHAN_W, TGSI_EXEC_DATA_FLOAT); + } +} + +static void exec_break(struct tgsi_exec_machine *mach) { if (mach->BreakType == TGSI_EXEC_BREAK_INSIDE_LOOP) { @@ -2135,42 +2243,46 @@ micro_not(union tgsi_exec_channel *dst, static void micro_shl(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] << src[1].u[0]; - dst->u[1] = src[0].u[1] << src[1].u[1]; - dst->u[2] = src[0].u[2] << src[1].u[2]; - dst->u[3] = src[0].u[3] << src[1].u[3]; + dst->u[0] = src0->u[0] << src1->u[0]; + dst->u[1] = src0->u[1] << src1->u[1]; + dst->u[2] = src0->u[2] << src1->u[2]; + dst->u[3] = src0->u[3] << src1->u[3]; } static void micro_and(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] & src[1].u[0]; - dst->u[1] = src[0].u[1] & src[1].u[1]; - dst->u[2] = src[0].u[2] & src[1].u[2]; - dst->u[3] = src[0].u[3] & src[1].u[3]; + dst->u[0] = src0->u[0] & src1->u[0]; + dst->u[1] = src0->u[1] & src1->u[1]; + dst->u[2] = src0->u[2] & src1->u[2]; + dst->u[3] = src0->u[3] & src1->u[3]; } static void micro_or(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] | src[1].u[0]; - dst->u[1] = src[0].u[1] | src[1].u[1]; - dst->u[2] = src[0].u[2] | src[1].u[2]; - dst->u[3] = src[0].u[3] | src[1].u[3]; + dst->u[0] = src0->u[0] | src1->u[0]; + dst->u[1] = src0->u[1] | src1->u[1]; + dst->u[2] = src0->u[2] | src1->u[2]; + dst->u[3] = src0->u[3] | src1->u[3]; } static void micro_xor(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] ^ src[1].u[0]; - dst->u[1] = src[0].u[1] ^ src[1].u[1]; - dst->u[2] = src[0].u[2] ^ src[1].u[2]; - dst->u[3] = src[0].u[3] ^ src[1].u[3]; + dst->u[0] = src0->u[0] ^ src1->u[0]; + dst->u[1] = src0->u[1] ^ src1->u[1]; + dst->u[2] = src0->u[2] ^ src1->u[2]; + dst->u[3] = src0->u[3] ^ src1->u[3]; } static void @@ -2185,62 +2297,68 @@ micro_f2i(union tgsi_exec_channel *dst, static void micro_idiv(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] / src[1].i[0]; - dst->i[1] = src[0].i[1] / src[1].i[1]; - dst->i[2] = src[0].i[2] / src[1].i[2]; - dst->i[3] = src[0].i[3] / src[1].i[3]; + dst->i[0] = src0->i[0] / src1->i[0]; + dst->i[1] = src0->i[1] / src1->i[1]; + dst->i[2] = src0->i[2] / src1->i[2]; + dst->i[3] = src0->i[3] / src1->i[3]; } static void micro_imax(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] > src[1].i[0] ? src[0].i[0] : src[1].i[0]; - dst->i[1] = src[0].i[1] > src[1].i[1] ? src[0].i[1] : src[1].i[1]; - dst->i[2] = src[0].i[2] > src[1].i[2] ? src[0].i[2] : src[1].i[2]; - dst->i[3] = src[0].i[3] > src[1].i[3] ? src[0].i[3] : src[1].i[3]; + dst->i[0] = src0->i[0] > src1->i[0] ? src0->i[0] : src1->i[0]; + dst->i[1] = src0->i[1] > src1->i[1] ? src0->i[1] : src1->i[1]; + dst->i[2] = src0->i[2] > src1->i[2] ? src0->i[2] : src1->i[2]; + dst->i[3] = src0->i[3] > src1->i[3] ? src0->i[3] : src1->i[3]; } static void micro_imin(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] < src[1].i[0] ? src[0].i[0] : src[1].i[0]; - dst->i[1] = src[0].i[1] < src[1].i[1] ? src[0].i[1] : src[1].i[1]; - dst->i[2] = src[0].i[2] < src[1].i[2] ? src[0].i[2] : src[1].i[2]; - dst->i[3] = src[0].i[3] < src[1].i[3] ? src[0].i[3] : src[1].i[3]; + dst->i[0] = src0->i[0] < src1->i[0] ? src0->i[0] : src1->i[0]; + dst->i[1] = src0->i[1] < src1->i[1] ? src0->i[1] : src1->i[1]; + dst->i[2] = src0->i[2] < src1->i[2] ? src0->i[2] : src1->i[2]; + dst->i[3] = src0->i[3] < src1->i[3] ? src0->i[3] : src1->i[3]; } static void micro_isge(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] >= src[1].i[0] ? -1 : 0; - dst->i[1] = src[0].i[1] >= src[1].i[1] ? -1 : 0; - dst->i[2] = src[0].i[2] >= src[1].i[2] ? -1 : 0; - dst->i[3] = src[0].i[3] >= src[1].i[3] ? -1 : 0; + dst->i[0] = src0->i[0] >= src1->i[0] ? -1 : 0; + dst->i[1] = src0->i[1] >= src1->i[1] ? -1 : 0; + dst->i[2] = src0->i[2] >= src1->i[2] ? -1 : 0; + dst->i[3] = src0->i[3] >= src1->i[3] ? -1 : 0; } static void micro_ishr(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] >> src[1].i[0]; - dst->i[1] = src[0].i[1] >> src[1].i[1]; - dst->i[2] = src[0].i[2] >> src[1].i[2]; - dst->i[3] = src[0].i[3] >> src[1].i[3]; + dst->i[0] = src0->i[0] >> src1->i[0]; + dst->i[1] = src0->i[1] >> src1->i[1]; + dst->i[2] = src0->i[2] >> src1->i[2]; + dst->i[3] = src0->i[3] >> src1->i[3]; } static void micro_islt(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->i[0] = src[0].i[0] < src[1].i[0] ? -1 : 0; - dst->i[1] = src[0].i[1] < src[1].i[1] ? -1 : 0; - dst->i[2] = src[0].i[2] < src[1].i[2] ? -1 : 0; - dst->i[3] = src[0].i[3] < src[1].i[3] ? -1 : 0; + dst->i[0] = src0->i[0] < src1->i[0] ? -1 : 0; + dst->i[1] = src0->i[1] < src1->i[1] ? -1 : 0; + dst->i[2] = src0->i[2] < src1->i[2] ? -1 : 0; + dst->i[3] = src0->i[3] < src1->i[3] ? -1 : 0; } static void @@ -2265,122 +2383,135 @@ micro_u2f(union tgsi_exec_channel *dst, static void micro_uadd(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] + src[1].u[0]; - dst->u[1] = src[0].u[1] + src[1].u[1]; - dst->u[2] = src[0].u[2] + src[1].u[2]; - dst->u[3] = src[0].u[3] + src[1].u[3]; + dst->u[0] = src0->u[0] + src1->u[0]; + dst->u[1] = src0->u[1] + src1->u[1]; + dst->u[2] = src0->u[2] + src1->u[2]; + dst->u[3] = src0->u[3] + src1->u[3]; } static void micro_udiv(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] / src[1].u[0]; - dst->u[1] = src[0].u[1] / src[1].u[1]; - dst->u[2] = src[0].u[2] / src[1].u[2]; - dst->u[3] = src[0].u[3] / src[1].u[3]; + dst->u[0] = src0->u[0] / src1->u[0]; + dst->u[1] = src0->u[1] / src1->u[1]; + dst->u[2] = src0->u[2] / src1->u[2]; + dst->u[3] = src0->u[3] / src1->u[3]; } static void micro_umad(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1, + const union tgsi_exec_channel *src2) { - dst->u[0] = src[0].u[0] * src[1].u[0] + src[2].u[0]; - dst->u[1] = src[0].u[1] * src[1].u[1] + src[2].u[1]; - dst->u[2] = src[0].u[2] * src[1].u[2] + src[2].u[2]; - dst->u[3] = src[0].u[3] * src[1].u[3] + src[2].u[3]; + dst->u[0] = src0->u[0] * src1->u[0] + src2->u[0]; + dst->u[1] = src0->u[1] * src1->u[1] + src2->u[1]; + dst->u[2] = src0->u[2] * src1->u[2] + src2->u[2]; + dst->u[3] = src0->u[3] * src1->u[3] + src2->u[3]; } static void micro_umax(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] > src[1].u[0] ? src[0].u[0] : src[1].u[0]; - dst->u[1] = src[0].u[1] > src[1].u[1] ? src[0].u[1] : src[1].u[1]; - dst->u[2] = src[0].u[2] > src[1].u[2] ? src[0].u[2] : src[1].u[2]; - dst->u[3] = src[0].u[3] > src[1].u[3] ? src[0].u[3] : src[1].u[3]; + dst->u[0] = src0->u[0] > src1->u[0] ? src0->u[0] : src1->u[0]; + dst->u[1] = src0->u[1] > src1->u[1] ? src0->u[1] : src1->u[1]; + dst->u[2] = src0->u[2] > src1->u[2] ? src0->u[2] : src1->u[2]; + dst->u[3] = src0->u[3] > src1->u[3] ? src0->u[3] : src1->u[3]; } static void micro_umin(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] < src[1].u[0] ? src[0].u[0] : src[1].u[0]; - dst->u[1] = src[0].u[1] < src[1].u[1] ? src[0].u[1] : src[1].u[1]; - dst->u[2] = src[0].u[2] < src[1].u[2] ? src[0].u[2] : src[1].u[2]; - dst->u[3] = src[0].u[3] < src[1].u[3] ? src[0].u[3] : src[1].u[3]; + dst->u[0] = src0->u[0] < src1->u[0] ? src0->u[0] : src1->u[0]; + dst->u[1] = src0->u[1] < src1->u[1] ? src0->u[1] : src1->u[1]; + dst->u[2] = src0->u[2] < src1->u[2] ? src0->u[2] : src1->u[2]; + dst->u[3] = src0->u[3] < src1->u[3] ? src0->u[3] : src1->u[3]; } static void micro_umod(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] % src[1].u[0]; - dst->u[1] = src[0].u[1] % src[1].u[1]; - dst->u[2] = src[0].u[2] % src[1].u[2]; - dst->u[3] = src[0].u[3] % src[1].u[3]; + dst->u[0] = src0->u[0] % src1->u[0]; + dst->u[1] = src0->u[1] % src1->u[1]; + dst->u[2] = src0->u[2] % src1->u[2]; + dst->u[3] = src0->u[3] % src1->u[3]; } static void micro_umul(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] * src[1].u[0]; - dst->u[1] = src[0].u[1] * src[1].u[1]; - dst->u[2] = src[0].u[2] * src[1].u[2]; - dst->u[3] = src[0].u[3] * src[1].u[3]; + dst->u[0] = src0->u[0] * src1->u[0]; + dst->u[1] = src0->u[1] * src1->u[1]; + dst->u[2] = src0->u[2] * src1->u[2]; + dst->u[3] = src0->u[3] * src1->u[3]; } static void micro_useq(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] == src[1].u[0] ? ~0 : 0; - dst->u[1] = src[0].u[1] == src[1].u[1] ? ~0 : 0; - dst->u[2] = src[0].u[2] == src[1].u[2] ? ~0 : 0; - dst->u[3] = src[0].u[3] == src[1].u[3] ? ~0 : 0; + dst->u[0] = src0->u[0] == src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] == src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] == src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] == src1->u[3] ? ~0 : 0; } static void micro_usge(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] >= src[1].u[0] ? ~0 : 0; - dst->u[1] = src[0].u[1] >= src[1].u[1] ? ~0 : 0; - dst->u[2] = src[0].u[2] >= src[1].u[2] ? ~0 : 0; - dst->u[3] = src[0].u[3] >= src[1].u[3] ? ~0 : 0; + dst->u[0] = src0->u[0] >= src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] >= src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] >= src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] >= src1->u[3] ? ~0 : 0; } static void micro_ushr(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] >> src[1].u[0]; - dst->u[1] = src[0].u[1] >> src[1].u[1]; - dst->u[2] = src[0].u[2] >> src[1].u[2]; - dst->u[3] = src[0].u[3] >> src[1].u[3]; + dst->u[0] = src0->u[0] >> src1->u[0]; + dst->u[1] = src0->u[1] >> src1->u[1]; + dst->u[2] = src0->u[2] >> src1->u[2]; + dst->u[3] = src0->u[3] >> src1->u[3]; } static void micro_uslt(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] < src[1].u[0] ? ~0 : 0; - dst->u[1] = src[0].u[1] < src[1].u[1] ? ~0 : 0; - dst->u[2] = src[0].u[2] < src[1].u[2] ? ~0 : 0; - dst->u[3] = src[0].u[3] < src[1].u[3] ? ~0 : 0; + dst->u[0] = src0->u[0] < src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] < src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] < src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] < src1->u[3] ? ~0 : 0; } static void micro_usne(union tgsi_exec_channel *dst, - const union tgsi_exec_channel *src) + const union tgsi_exec_channel *src0, + const union tgsi_exec_channel *src1) { - dst->u[0] = src[0].u[0] != src[1].u[0] ? ~0 : 0; - dst->u[1] = src[0].u[1] != src[1].u[1] ? ~0 : 0; - dst->u[2] = src[0].u[2] != src[1].u[2] ? ~0 : 0; - dst->u[3] = src[0].u[3] != src[1].u[3] ? ~0 : 0; + dst->u[0] = src0->u[0] != src1->u[0] ? ~0 : 0; + dst->u[1] = src0->u[1] != src1->u[1] ? ~0 : 0; + dst->u[2] = src0->u[2] != src1->u[2] ? ~0 : 0; + dst->u[3] = src0->u[3] != src1->u[3] ? ~0 : 0; } static void @@ -2487,25 +2618,11 @@ exec_instruction( break; case TGSI_OPCODE_MUL: - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - micro_mul(&d[chan_index], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_mul, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_ADD: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH( &r[0], 0, chan_index ); - FETCH( &r[1], 1, chan_index ); - micro_add(&d[chan_index], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_add, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_DP3: @@ -2544,29 +2661,11 @@ exec_instruction( break; case TGSI_OPCODE_MIN: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - - /* XXX use micro_min()?? */ - micro_lt(&d[chan_index], &r[0], &r[1], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_min, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_MAX: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - - /* XXX use micro_max()?? */ - micro_lt(&d[chan_index], &r[0], &r[1], &r[1], &r[0] ); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_max, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_SLT: @@ -2582,14 +2681,7 @@ exec_instruction( break; case TGSI_OPCODE_SUB: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - micro_sub(&d[chan_index], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_binary(mach, inst, micro_sub, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_LRP: @@ -2597,15 +2689,7 @@ exec_instruction( break; case TGSI_OPCODE_CND: - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - FETCH(&r[2], 2, chan_index); - micro_lt(&d[chan_index], &mach->Temps[TEMP_HALF_I].xyzw[TEMP_HALF_C], &r[2], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_trinary(mach, inst, micro_cnd, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_DP2A: @@ -2617,16 +2701,7 @@ exec_instruction( break; case TGSI_OPCODE_CLAMP: - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - micro_max(&r[0], &r[0], &r[1]); - FETCH(&r[1], 2, chan_index); - micro_min(&d[chan_index], &r[0], &r[1]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_trinary(mach, inst, micro_clamp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_FLR: @@ -3020,15 +3095,7 @@ exec_instruction( break; case TGSI_OPCODE_CMP: - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - FETCH(&r[0], 0, chan_index); - FETCH(&r[1], 1, chan_index); - FETCH(&r[2], 2, chan_index); - micro_lt(&d[chan_index], &r[0], &mach->Temps[TEMP_0_I].xyzw[TEMP_0_C], &r[1], &r[2]); - } - FOR_EACH_ENABLED_CHANNEL(*inst, chan_index) { - STORE(&d[chan_index], 0, chan_index); - } + exec_vector_trinary(mach, inst, micro_cmp, TGSI_EXEC_DATA_FLOAT, TGSI_EXEC_DATA_FLOAT); break; case TGSI_OPCODE_SCS: @@ -3052,70 +3119,11 @@ exec_instruction( break; case TGSI_OPCODE_NRM: - /* 3-component vector normalize */ - if(IS_CHANNEL_ENABLED(*inst, CHAN_X) || - IS_CHANNEL_ENABLED(*inst, CHAN_Y) || - IS_CHANNEL_ENABLED(*inst, CHAN_Z)) { - /* r3 = sqrt(dp3(src0, src0)) */ - FETCH(&r[0], 0, CHAN_X); - micro_mul(&r[3], &r[0], &r[0]); - FETCH(&r[1], 0, CHAN_Y); - micro_mul(&r[4], &r[1], &r[1]); - micro_add(&r[3], &r[3], &r[4]); - FETCH(&r[2], 0, CHAN_Z); - micro_mul(&r[4], &r[2], &r[2]); - micro_add(&r[3], &r[3], &r[4]); - micro_sqrt(&r[3], &r[3]); - - if (IS_CHANNEL_ENABLED(*inst, CHAN_X)) { - micro_div(&r[0], &r[0], &r[3]); - STORE(&r[0], 0, CHAN_X); - } - if (IS_CHANNEL_ENABLED(*inst, CHAN_Y)) { - micro_div(&r[1], &r[1], &r[3]); - STORE(&r[1], 0, CHAN_Y); - } - if (IS_CHANNEL_ENABLED(*inst, CHAN_Z)) { - micro_div(&r[2], &r[2], &r[3]); - STORE(&r[2], 0, CHAN_Z); - } - } - if (IS_CHANNEL_ENABLED(*inst, CHAN_W)) { - STORE(&mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], 0, CHAN_W); - } + exec_nrm3(mach, inst); break; case TGSI_OPCODE_NRM4: - /* 4-component vector normalize */ - { - union tgsi_exec_channel tmp, dot; - - /* tmp = dp4(src0, src0): */ - FETCH( &r[0], 0, CHAN_X ); - micro_mul( &tmp, &r[0], &r[0] ); - - FETCH( &r[1], 0, CHAN_Y ); - micro_mul( &dot, &r[1], &r[1] ); - micro_add( &tmp, &tmp, &dot ); - - FETCH( &r[2], 0, CHAN_Z ); - micro_mul( &dot, &r[2], &r[2] ); - micro_add( &tmp, &tmp, &dot ); - - FETCH( &r[3], 0, CHAN_W ); - micro_mul( &dot, &r[3], &r[3] ); - micro_add( &tmp, &tmp, &dot ); - - /* tmp = 1 / sqrt(tmp) */ - micro_sqrt( &tmp, &tmp ); - micro_div( &tmp, &mach->Temps[TEMP_1_I].xyzw[TEMP_1_C], &tmp ); - - FOR_EACH_ENABLED_CHANNEL( *inst, chan_index ) { - /* chan = chan * tmp */ - micro_mul( &r[chan_index], &tmp, &r[chan_index] ); - STORE( &r[chan_index], 0, chan_index ); - } - } + exec_nrm4(mach, inst); break; case TGSI_OPCODE_DIV: diff --git a/src/gallium/auxiliary/tgsi/tgsi_sanity.c b/src/gallium/auxiliary/tgsi/tgsi_sanity.c index 91e1b27da12..371f690b295 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_sanity.c +++ b/src/gallium/auxiliary/tgsi/tgsi_sanity.c @@ -321,6 +321,9 @@ iter_instruction( reg, "destination", FALSE ); + if (!inst->Dst[i].Register.WriteMask) { + report_error(ctx, "Destination register has empty writemask"); + } } for (i = 0; i < inst->Instruction.NumSrcRegs; i++) { scan_register *reg = create_scan_register_src(&inst->Src[i]); diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c index 24727d49888..c9ec2b32bfe 100644 --- a/src/gallium/auxiliary/translate/translate_generic.c +++ b/src/gallium/auxiliary/translate/translate_generic.c @@ -392,10 +392,10 @@ static fetch_func get_fetch_func( enum pipe_format format ) case PIPE_FORMAT_R8G8B8A8_SSCALED: return &fetch_R8G8B8A8_SSCALED; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return &fetch_A8R8G8B8_UNORM; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: return &fetch_B8G8R8A8_UNORM; case PIPE_FORMAT_R32_FIXED: @@ -551,10 +551,10 @@ static emit_func get_emit_func( enum pipe_format format ) case PIPE_FORMAT_R8G8B8A8_SSCALED: return &emit_R8G8B8A8_SSCALED; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return &emit_A8R8G8B8_UNORM; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: return &emit_B8G8R8A8_UNORM; default: diff --git a/src/gallium/auxiliary/translate/translate_sse.c b/src/gallium/auxiliary/translate/translate_sse.c index c13e7427387..03e093c11ea 100644 --- a/src/gallium/auxiliary/translate/translate_sse.c +++ b/src/gallium/auxiliary/translate/translate_sse.c @@ -336,7 +336,7 @@ static boolean translate_attr( struct translate_sse *p, case PIPE_FORMAT_R32G32B32A32_FLOAT: emit_load_R32G32B32A32(p, dataXMM, srcECX); break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: emit_load_R8G8B8A8_UNORM(p, dataXMM, srcECX); emit_swizzle(p, dataXMM, dataXMM, SHUF(Z,Y,X,W)); break; @@ -360,7 +360,7 @@ static boolean translate_attr( struct translate_sse *p, case PIPE_FORMAT_R32G32B32A32_FLOAT: emit_store_R32G32B32A32(p, dstEAX, dataXMM); break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: emit_swizzle(p, dataXMM, dataXMM, SHUF(Z,Y,X,W)); emit_store_R8G8B8A8_UNORM(p, dstEAX, dataXMM); break; diff --git a/src/gallium/auxiliary/util/.gitignore b/src/gallium/auxiliary/util/.gitignore index 29c586c9b51..448d2f304fb 100644 --- a/src/gallium/auxiliary/util/.gitignore +++ b/src/gallium/auxiliary/util/.gitignore @@ -1,2 +1,3 @@ u_format_access.c u_format_table.c +u_format_pack.h diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 0d93e23df86..4d0737ccd3d 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -62,6 +62,7 @@ struct blit_state struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; struct pipe_viewport_state viewport; + struct pipe_clip_state clip; struct pipe_vertex_element velem[2]; void *vs; @@ -102,7 +103,6 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso) memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer)); ctx->rasterizer.front_winding = PIPE_WINDING_CW; ctx->rasterizer.cull_mode = PIPE_WINDING_NONE; - ctx->rasterizer.bypass_vs_clip_and_viewport = 1; ctx->rasterizer.gl_rasterization_rules = 1; /* samplers */ @@ -115,7 +115,6 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso) ctx->sampler.mag_img_filter = 0; /* set later */ ctx->sampler.normalized_coords = 1; - /* vertex elements state */ memset(&ctx->velem[0], 0, sizeof(ctx->velem[0]) * 2); for (i = 0; i < 2; i++) { @@ -276,7 +275,6 @@ regions_overlap(int srcX0, int srcY0, * \param writemask controls which channels in the dest surface are sourced * from the src surface. Disabled channels are sourced * from (0,0,0,1). - * XXX what about clipping??? * XXX need some control over blitting Z and/or stencil. */ void @@ -417,15 +415,18 @@ util_blit_pixels_writemask(struct blit_state *ctx, cso_save_rasterizer(ctx->cso); cso_save_samplers(ctx->cso); cso_save_sampler_textures(ctx->cso); + cso_save_viewport(ctx->cso); cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); + cso_save_clip(ctx->cso); cso_save_vertex_elements(ctx->cso); /* set misc state we care about */ cso_set_blend(ctx->cso, &ctx->blend); cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil); cso_set_rasterizer(ctx->cso, &ctx->rasterizer); + cso_set_clip(ctx->cso, &ctx->clip); cso_set_vertex_elements(ctx->cso, 2, ctx->velem); /* sampler */ @@ -434,6 +435,17 @@ util_blit_pixels_writemask(struct blit_state *ctx, cso_single_sampler(ctx->cso, 0, &ctx->sampler); cso_single_sampler_done(ctx->cso); + /* viewport */ + ctx->viewport.scale[0] = 0.5f * dst->width; + ctx->viewport.scale[1] = 0.5f * dst->height; + ctx->viewport.scale[2] = 0.5f; + ctx->viewport.scale[3] = 1.0f; + ctx->viewport.translate[0] = 0.5f * dst->width; + ctx->viewport.translate[1] = 0.5f * dst->height; + ctx->viewport.translate[2] = 0.5f; + ctx->viewport.translate[3] = 0.0f; + cso_set_viewport(ctx->cso, &ctx->viewport); + /* texture */ cso_set_sampler_textures(ctx->cso, 1, &tex); @@ -456,8 +468,10 @@ util_blit_pixels_writemask(struct blit_state *ctx, /* draw quad */ offset = setup_vertex_data_tex(ctx, - (float) dstX0, (float) dstY0, - (float) dstX1, (float) dstY1, + (float) dstX0 / dst->width * 2.0f - 1.0f, + (float) dstY0 / dst->height * 2.0f - 1.0f, + (float) dstX1 / dst->width * 2.0f - 1.0f, + (float) dstY1 / dst->height * 2.0f - 1.0f, s0, t0, s1, t1, z); @@ -473,9 +487,11 @@ util_blit_pixels_writemask(struct blit_state *ctx, cso_restore_rasterizer(ctx->cso); cso_restore_samplers(ctx->cso); cso_restore_sampler_textures(ctx->cso); + cso_restore_viewport(ctx->cso); cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); + cso_restore_clip(ctx->cso); cso_restore_vertex_elements(ctx->cso); pipe_texture_reference(&tex, NULL); @@ -560,12 +576,14 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); + cso_save_clip(ctx->cso); cso_save_vertex_elements(ctx->cso); /* set misc state we care about */ cso_set_blend(ctx->cso, &ctx->blend); cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil); cso_set_rasterizer(ctx->cso, &ctx->rasterizer); + cso_set_clip(ctx->cso, &ctx->clip); cso_set_vertex_elements(ctx->cso, 2, ctx->velem); /* sampler */ @@ -574,6 +592,17 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_single_sampler(ctx->cso, 0, &ctx->sampler); cso_single_sampler_done(ctx->cso); + /* viewport */ + ctx->viewport.scale[0] = 0.5f * dst->width; + ctx->viewport.scale[1] = 0.5f * dst->height; + ctx->viewport.scale[2] = 0.5f; + ctx->viewport.scale[3] = 1.0f; + ctx->viewport.translate[0] = 0.5f * dst->width; + ctx->viewport.translate[1] = 0.5f * dst->height; + ctx->viewport.translate[2] = 0.5f; + ctx->viewport.translate[3] = 0.0f; + cso_set_viewport(ctx->cso, &ctx->viewport); + /* texture */ cso_set_sampler_textures(ctx->cso, 1, &tex); @@ -591,8 +620,10 @@ util_blit_pixels_tex(struct blit_state *ctx, /* draw quad */ offset = setup_vertex_data_tex(ctx, - (float) dstX0, (float) dstY0, - (float) dstX1, (float) dstY1, + (float) dstX0 / dst->width * 2.0f - 1.0f, + (float) dstY0 / dst->height * 2.0f - 1.0f, + (float) dstX1 / dst->width * 2.0f - 1.0f, + (float) dstY1 / dst->height * 2.0f - 1.0f, s0, t0, s1, t1, z); @@ -611,5 +642,6 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); + cso_restore_clip(ctx->cso); cso_restore_vertex_elements(ctx->cso); } diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index 3542a2e4446..33d09085f0b 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -95,6 +95,12 @@ struct blitter_context_priv /* Rasterizer state. */ void *rs_state; + + /* Viewport state. */ + struct pipe_viewport_state viewport; + + /* Clip state. */ + struct pipe_clip_state clip; }; struct blitter_context *util_blitter_create(struct pipe_context *pipe) @@ -164,7 +170,6 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) memset(&rs_state, 0, sizeof(rs_state)); rs_state.front_winding = PIPE_WINDING_CW; rs_state.cull_mode = PIPE_WINDING_NONE; - rs_state.bypass_vs_clip_and_viewport = 1; rs_state.gl_rasterization_rules = 1; rs_state.flatshade = 1; ctx->rs_state = pipe->create_rasterizer_state(pipe, &rs_state); @@ -281,6 +286,9 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx) pipe->set_stencil_ref(pipe, &ctx->blitter.saved_stencil_ref); + pipe->set_viewport_state(pipe, &ctx->blitter.saved_viewport); + pipe->set_clip_state(pipe, &ctx->blitter.saved_clip); + /* restore the state objects which are required to be saved before copy/fill */ if (ctx->blitter.saved_fb_state.nr_cbufs != ~0) { @@ -306,25 +314,40 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx) static void blitter_set_rectangle(struct blitter_context_priv *ctx, unsigned x1, unsigned y1, unsigned x2, unsigned y2, + unsigned width, unsigned height, float depth) { int i; /* set vertex positions */ - ctx->vertices[0][0][0] = x1; /*v0.x*/ - ctx->vertices[0][0][1] = y1; /*v0.y*/ + ctx->vertices[0][0][0] = (float)x1 / width * 2.0f - 1.0f; /*v0.x*/ + ctx->vertices[0][0][1] = (float)y1 / height * 2.0f - 1.0f; /*v0.y*/ - ctx->vertices[1][0][0] = x2; /*v1.x*/ - ctx->vertices[1][0][1] = y1; /*v1.y*/ + ctx->vertices[1][0][0] = (float)x2 / width * 2.0f - 1.0f; /*v1.x*/ + ctx->vertices[1][0][1] = (float)y1 / height * 2.0f - 1.0f; /*v1.y*/ - ctx->vertices[2][0][0] = x2; /*v2.x*/ - ctx->vertices[2][0][1] = y2; /*v2.y*/ + ctx->vertices[2][0][0] = (float)x2 / width * 2.0f - 1.0f; /*v2.x*/ + ctx->vertices[2][0][1] = (float)y2 / height * 2.0f - 1.0f; /*v2.y*/ - ctx->vertices[3][0][0] = x1; /*v3.x*/ - ctx->vertices[3][0][1] = y2; /*v3.y*/ + ctx->vertices[3][0][0] = (float)x1 / width * 2.0f - 1.0f; /*v3.x*/ + ctx->vertices[3][0][1] = (float)y2 / height * 2.0f - 1.0f; /*v3.y*/ for (i = 0; i < 4; i++) ctx->vertices[i][0][2] = depth; /*z*/ + + /* viewport */ + ctx->viewport.scale[0] = 0.5f * width; + ctx->viewport.scale[1] = 0.5f * height; + ctx->viewport.scale[2] = 1.0f; + ctx->viewport.scale[3] = 1.0f; + ctx->viewport.translate[0] = 0.5f * width; + ctx->viewport.translate[1] = 0.5f * height; + ctx->viewport.translate[2] = 0.0f; + ctx->viewport.translate[3] = 0.0f; + ctx->pipe->set_viewport_state(ctx->pipe, &ctx->viewport); + + /* clip */ + ctx->pipe->set_clip_state(ctx->pipe, &ctx->clip); } static void blitter_set_clear_color(struct blitter_context_priv *ctx, @@ -569,7 +592,7 @@ void util_blitter_clear(struct blitter_context *blitter, pipe->bind_vs_state(pipe, ctx->vs_col); blitter_set_clear_color(ctx, rgba); - blitter_set_rectangle(ctx, 0, 0, width, height, depth); + blitter_set_rectangle(ctx, 0, 0, width, height, width, height, depth); blitter_draw_quad(ctx); blitter_restore_CSOs(ctx); } @@ -653,7 +676,7 @@ static void util_blitter_do_copy(struct blitter_context *blitter, assert(0); } - blitter_set_rectangle(ctx, dstx, dsty, dstx+width, dsty+height, 0); + blitter_set_rectangle(ctx, dstx, dsty, dstx+width, dsty+height, dst->width, dst->height, 0); blitter_draw_quad(ctx); } @@ -815,7 +838,7 @@ void util_blitter_fill(struct blitter_context *blitter, pipe->set_framebuffer_state(pipe, &fb_state); blitter_set_clear_color(ctx, rgba); - blitter_set_rectangle(ctx, 0, 0, width, height, 0); + blitter_set_rectangle(ctx, 0, 0, width, height, dst->width, dst->height, 0); blitter_draw_quad(ctx); blitter_restore_CSOs(ctx); } diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h index 7d8a09edb53..ecafdabafae 100644 --- a/src/gallium/auxiliary/util/u_blitter.h +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -49,6 +49,8 @@ struct blitter_context struct pipe_framebuffer_state saved_fb_state; /**< framebuffer state */ struct pipe_stencil_ref saved_stencil_ref; /**< stencil ref */ + struct pipe_viewport_state saved_viewport; + struct pipe_clip_state saved_clip; int saved_num_sampler_states; void *saved_sampler_states[32]; @@ -214,6 +216,20 @@ void util_blitter_save_framebuffer(struct blitter_context *blitter, } static INLINE +void util_blitter_save_viewport(struct blitter_context *blitter, + struct pipe_viewport_state *state) +{ + blitter->saved_viewport = *state; +} + +static INLINE +void util_blitter_save_clip(struct blitter_context *blitter, + struct pipe_clip_state *state) +{ + blitter->saved_clip = *state; +} + +static INLINE void util_blitter_save_fragment_sampler_states( struct blitter_context *blitter, int num_sampler_states, diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index 858d52c6efb..94be682c4b1 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/src/gallium/auxiliary/util/u_debug.c @@ -387,7 +387,7 @@ void debug_dump_image(const char *prefix, /* XXX this is a hack */ switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: r = 2; g = 1; b = 0; diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h index efcf065d276..0f4768f3444 100644 --- a/src/gallium/auxiliary/util/u_debug.h +++ b/src/gallium/auxiliary/util/u_debug.h @@ -337,7 +337,7 @@ void debug_dump_float_rgba_bmp(const char *filename, #define debug_dump_surface(prefix, surface) ((void)0) #define debug_dump_surface_bmp(filename, surface) ((void)0) #define debug_dump_transfer_bmp(filename, transfer) ((void)0) -#define debug_dump_rgba_float_bmp(filename, width, height, rgba, stride) ((void)0) +#define debug_dump_float_rgba_bmp(filename, width, height, rgba, stride) ((void)0) #endif diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c index 196c5e06e95..52cf3ef4ce0 100644 --- a/src/gallium/auxiliary/util/u_dump_state.c +++ b/src/gallium/auxiliary/util/u_dump_state.c @@ -318,7 +318,6 @@ util_dump_rasterizer_state(struct os_stream *stream, const struct pipe_rasterize util_dump_member(stream, uint, state, line_stipple_factor); util_dump_member(stream, uint, state, line_stipple_pattern); util_dump_member(stream, bool, state, line_last_pixel); - util_dump_member(stream, bool, state, bypass_vs_clip_and_viewport); util_dump_member(stream, bool, state, flatshade_first); util_dump_member(stream, bool, state, gl_rasterization_rules); diff --git a/src/gallium/auxiliary/util/u_format.csv b/src/gallium/auxiliary/util/u_format.csv index 01f7931aed1..96a0fa65507 100644 --- a/src/gallium/auxiliary/util/u_format.csv +++ b/src/gallium/auxiliary/util/u_format.csv @@ -1,109 +1,186 @@ -PIPE_FORMAT_A8R8G8B8_UNORM , arith , 1, 1, un8 , un8 , un8 , un8 , zyxw, rgb -PIPE_FORMAT_X8R8G8B8_UNORM , arith , 1, 1, un8 , un8 , un8 , un8 , zyx1, rgb -PIPE_FORMAT_B8G8R8A8_UNORM , arith , 1, 1, un8 , un8 , un8 , un8 , yzwx, rgb -PIPE_FORMAT_B8G8R8X8_UNORM , arith , 1, 1, un8 , un8 , un8 , un8 , yzw1, rgb -PIPE_FORMAT_A1R5G5B5_UNORM , arith , 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb -PIPE_FORMAT_A4R4G4B4_UNORM , arith , 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb -PIPE_FORMAT_R5G6B5_UNORM , arith , 1, 1, un5 , un6 , un5 , , zyx1, rgb -PIPE_FORMAT_A2B10G10R10_UNORM , arith , 1, 1, un10, un10, un10, un2 , xyzw, rgb -PIPE_FORMAT_L8_UNORM , arith , 1, 1, un8 , , , , xxx1, rgb -PIPE_FORMAT_A8_UNORM , arith , 1, 1, un8 , , , , 000x, rgb -PIPE_FORMAT_I8_UNORM , arith , 1, 1, un8 , , , , xxxx, rgb -PIPE_FORMAT_A8L8_UNORM , arith , 1, 1, un8 , un8 , , , xxxy, rgb -PIPE_FORMAT_L16_UNORM , arith , 1, 1, un16, , , , xxx1, rgb -PIPE_FORMAT_YCBCR , yuv , 2, 1, x32 , , , , xyz1, yuv -PIPE_FORMAT_YCBCR_REV , yuv , 2, 1, x32 , , , , xyz1, yuv -PIPE_FORMAT_Z16_UNORM , array , 1, 1, un16, , , , x___, zs -PIPE_FORMAT_Z32_UNORM , array , 1, 1, un32, , , , x___, zs -PIPE_FORMAT_Z32_FLOAT , array , 1, 1, f32 , , , , x___, zs -PIPE_FORMAT_S8Z24_UNORM , arith , 1, 1, un24, un8 , , , xy__, zs -PIPE_FORMAT_Z24S8_UNORM , arith , 1, 1, un8 , un24, , , yx__, zs -PIPE_FORMAT_X8Z24_UNORM , arith , 1, 1, un24, un8 , , , x___, zs -PIPE_FORMAT_Z24X8_UNORM , arith , 1, 1, un8 , un24, , , y___, zs -PIPE_FORMAT_S8_UNORM , array , 1, 1, un8 , , , , _x__, zs -PIPE_FORMAT_R64_FLOAT , array , 1, 1, f64 , , , , x001, rgb -PIPE_FORMAT_R64G64_FLOAT , array , 1, 1, f64 , f64 , , , xy01, rgb -PIPE_FORMAT_R64G64B64_FLOAT , array , 1, 1, f64 , f64 , f64 , , xyz1, rgb -PIPE_FORMAT_R64G64B64A64_FLOAT , array , 1, 1, f64 , f64 , f64 , f64 , xyzw, rgb -PIPE_FORMAT_R32_FLOAT , array , 1, 1, f32 , , , , x001, rgb -PIPE_FORMAT_R32G32_FLOAT , array , 1, 1, f32 , f32 , , , xy01, rgb -PIPE_FORMAT_R32G32B32_FLOAT , array , 1, 1, f32 , f32 , f32 , , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_FLOAT , array , 1, 1, f32 , f32 , f32 , f32 , xyzw, rgb -PIPE_FORMAT_R32_UNORM , array , 1, 1, un32, , , , x001, rgb -PIPE_FORMAT_R32G32_UNORM , array , 1, 1, un32, un32, , , xy01, rgb -PIPE_FORMAT_R32G32B32_UNORM , array , 1, 1, un32, un32, un32, , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_UNORM , array , 1, 1, un32, un32, un32, un32, xyzw, rgb -PIPE_FORMAT_R32_USCALED , array , 1, 1, u32 , , , , x001, rgb -PIPE_FORMAT_R32G32_USCALED , array , 1, 1, u32 , u32 , , , xy01, rgb -PIPE_FORMAT_R32G32B32_USCALED , array , 1, 1, u32 , u32 , u32 , , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_USCALED , array , 1, 1, u32 , u32 , u32 , u32 , xyzw, rgb -PIPE_FORMAT_R32_SNORM , array , 1, 1, sn32, , , , x001, rgb -PIPE_FORMAT_R32G32_SNORM , array , 1, 1, sn32, sn32, , , xy01, rgb -PIPE_FORMAT_R32G32B32_SNORM , array , 1, 1, sn32, sn32, sn32, , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_SNORM , array , 1, 1, sn32, sn32, sn32, sn32, xyzw, rgb -PIPE_FORMAT_R32_SSCALED , array , 1, 1, s32 , , , , x001, rgb -PIPE_FORMAT_R32G32_SSCALED , array , 1, 1, s32 , s32 , , , xy01, rgb -PIPE_FORMAT_R32G32B32_SSCALED , array , 1, 1, s32 , s32 , s32 , , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_SSCALED , array , 1, 1, s32 , s32 , s32 , s32 , xyzw, rgb -PIPE_FORMAT_R16_UNORM , array , 1, 1, un16, , , , x001, rgb -PIPE_FORMAT_R16G16_UNORM , array , 1, 1, un16, un16, , , xy01, rgb -PIPE_FORMAT_R16G16B16_UNORM , array , 1, 1, un16, un16, un16, , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_UNORM , array , 1, 1, un16, un16, un16, un16, xyzw, rgb -PIPE_FORMAT_R16_USCALED , array , 1, 1, u16 , , , , x001, rgb -PIPE_FORMAT_R16G16_USCALED , array , 1, 1, u16 , u16 , , , xy01, rgb -PIPE_FORMAT_R16G16B16_USCALED , array , 1, 1, u16 , u16 , u16 , , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_USCALED , array , 1, 1, u16 , u16 , u16 , u16 , xyzw, rgb -PIPE_FORMAT_R16_SNORM , array , 1, 1, sn16, , , , x001, rgb -PIPE_FORMAT_R16G16_SNORM , array , 1, 1, sn16, sn16, , , xy01, rgb -PIPE_FORMAT_R16G16B16_SNORM , array , 1, 1, sn16, sn16, sn16, , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_SNORM , array , 1, 1, sn16, sn16, sn16, sn16, xyzw, rgb -PIPE_FORMAT_R16_SSCALED , array , 1, 1, s16 , , , , x001, rgb -PIPE_FORMAT_R16G16_SSCALED , array , 1, 1, s16 , s16 , , , xy01, rgb -PIPE_FORMAT_R16G16B16_SSCALED , array , 1, 1, s16 , s16 , s16 , , xyz1, rgb -PIPE_FORMAT_R16G16B16A16_SSCALED , array , 1, 1, s16 , s16 , s16 , s16 , xyzw, rgb -PIPE_FORMAT_R8_UNORM , array , 1, 1, un8 , , , , x001, rgb -PIPE_FORMAT_R8G8_UNORM , array , 1, 1, un8 , un8 , , , yx01, rgb -PIPE_FORMAT_R8G8B8_UNORM , array , 1, 1, un8 , un8 , un8 , , zyx1, rgb -PIPE_FORMAT_R8G8B8A8_UNORM , array , 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb -PIPE_FORMAT_R8G8B8X8_UNORM , array , 1, 1, un8 , un8 , un8 , un8 , wzy1, rgb -PIPE_FORMAT_R8_USCALED , array , 1, 1, u8 , , , , x001, rgb -PIPE_FORMAT_R8G8_USCALED , array , 1, 1, u8 , u8 , , , xy01, rgb -PIPE_FORMAT_R8G8B8_USCALED , array , 1, 1, u8 , u8 , u8 , , xyz1, rgb -PIPE_FORMAT_R8G8B8A8_USCALED , array , 1, 1, u8 , u8 , u8 , u8 , xyzw, rgb -PIPE_FORMAT_R8G8B8X8_USCALED , array , 1, 1, u8 , u8 , u8 , u8 , xyz1, rgb -PIPE_FORMAT_R8_SNORM , array , 1, 1, sn8 , , , , x001, rgb -PIPE_FORMAT_R8G8_SNORM , array , 1, 1, sn8 , sn8 , , , xy01, rgb -PIPE_FORMAT_R8G8B8_SNORM , array , 1, 1, sn8 , sn8 , sn8 , , xyz1, rgb -PIPE_FORMAT_R8G8B8A8_SNORM , array , 1, 1, sn8 , sn8 , sn8 , sn8 , xyzw, rgb -PIPE_FORMAT_R8G8B8X8_SNORM , array , 1, 1, sn8 , sn8 , sn8 , sn8 , xyz1, rgb -PIPE_FORMAT_B6G5R5_SNORM , arith , 1, 1, sn5 , sn5 , sn6 , , xyz1, rgb -PIPE_FORMAT_A8B8G8R8_SNORM , array , 1, 1, sn8 , sn8 , sn8 , sn8 , wzyx, rgb -PIPE_FORMAT_X8B8G8R8_SNORM , array , 1, 1, sn8 , sn8 , sn8 , sn8 , wzy1, rgb -PIPE_FORMAT_R8_SSCALED , array , 1, 1, s8 , , , , x001, rgb -PIPE_FORMAT_R8G8_SSCALED , array , 1, 1, s8 , s8 , , , xy01, rgb -PIPE_FORMAT_R8G8B8_SSCALED , array , 1, 1, s8 , s8 , s8 , , xyz1, rgb -PIPE_FORMAT_R8G8B8A8_SSCALED , array , 1, 1, s8 , s8 , s8 , s8 , xyzw, rgb -PIPE_FORMAT_R8G8B8X8_SSCALED , array , 1, 1, s8 , s8 , s8 , s8 , xyz1, rgb -PIPE_FORMAT_R32_FIXED , array , 1, 1, h32 , , , , x001, rgb -PIPE_FORMAT_R32G32_FIXED , array , 1, 1, h32 , h32 , , , xy01, rgb -PIPE_FORMAT_R32G32B32_FIXED , array , 1, 1, h32 , h32 , h32 , , xyz1, rgb -PIPE_FORMAT_R32G32B32A32_FIXED , array , 1, 1, h32 , h32 , h32 , h32 , xyzw, rgb -PIPE_FORMAT_L8_SRGB , arith , 1, 1, u8 , , , , xxx1, srgb -PIPE_FORMAT_A8L8_SRGB , arith , 1, 1, u8 , u8 , , , xxxy, srgb -PIPE_FORMAT_R8G8B8_SRGB , array , 1, 1, u8 , u8 , u8 , , xyz1, srgb -PIPE_FORMAT_R8G8B8A8_SRGB , array , 1, 1, u8 , u8 , u8 , u8 , xyzw, srgb -PIPE_FORMAT_R8G8B8X8_SRGB , array , 1, 1, u8 , u8 , u8 , u8 , xyz1, srgb -PIPE_FORMAT_A8R8G8B8_SRGB , array , 1, 1, u8 , u8 , u8 , u8 , yzwx, srgb -PIPE_FORMAT_X8R8G8B8_SRGB , array , 1, 1, u8 , u8 , u8 , u8 , yzw1, srgb -PIPE_FORMAT_B8G8R8A8_SRGB , array , 1, 1, u8 , u8 , u8 , u8 , zyxw, srgb -PIPE_FORMAT_B8G8R8X8_SRGB , array , 1, 1, u8 , u8 , u8 , u8 , zyx1, srgb -PIPE_FORMAT_X8UB8UG8SR8S_NORM , array , 1, 1, sn8 , sn8 , un8 , x8 , wzy1, rgb -PIPE_FORMAT_B6UG5SR5S_NORM , arith , 1, 1, sn5 , sn5 , un6 , , xyz1, rgb -PIPE_FORMAT_DXT1_RGB , dxt , 4, 4, x64 , , , , xyz1, rgb -PIPE_FORMAT_DXT1_RGBA , dxt , 4, 4, x64 , , , , xyzw, rgb -PIPE_FORMAT_DXT3_RGBA , dxt , 4, 4, x128, , , , xyzw, rgb -PIPE_FORMAT_DXT5_RGBA , dxt , 4, 4, x128, , , , xyzw, rgb -PIPE_FORMAT_DXT1_SRGB , dxt , 4, 4, x64 , , , , xyz1, srgb -PIPE_FORMAT_DXT1_SRGBA , dxt , 4, 4, x64 , , , , xyzw, srgb -PIPE_FORMAT_DXT3_SRGBA , dxt , 4, 4, x128, , , , xyzw, srgb -PIPE_FORMAT_DXT5_SRGBA , dxt , 4, 4, x128, , , , xyzw, srgb +########################################################################### +# +# Copyright 2009-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 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 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. +# +########################################################################### + +# This CSV file has the input data for u_format.h's struct +# util_format_description. +# +# Each format entry contains: +# - name, per enum pipe_format +# - layout, per enum util_format_layout, in shortened lower caps +# - pixel block's width +# - pixel block's height +# - channel encoding (only meaningful for plain layout), containing for each +# channel the following information: +# - type, one of +# - 'x': void +# - 'u': unsigned +# - 's': signed +# - 'h': fixed +# - 'f': FLOAT +# - optionally followed by 'n' if it is normalized +# - number of bits +# - channel swizzle +# - color space: rgb, yub, sz +# +# See also: +# - http://msdn.microsoft.com/en-us/library/ee416489.aspx (D3D9) +# - http://msdn.microsoft.com/en-us/library/ee415668.aspx (D3D9 -> D3D10) +# - http://msdn.microsoft.com/en-us/library/ee418116.aspx (D3D10) +# +# Note that GL doesn't really specify the layout of internal formats. See +# OpenGL 2.1 specification, Table 3.16, on the "Correspondence of sized +# internal formats to base in- ternal formats, and desired component +# resolutions for each sized internal format." + +# Typical rendertarget formats +PIPE_FORMAT_B8G8R8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, rgb +PIPE_FORMAT_B8G8R8X8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , zyx1, rgb +PIPE_FORMAT_A8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, rgb +PIPE_FORMAT_X8R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , yzw1, rgb +PIPE_FORMAT_A8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, rgb +PIPE_FORMAT_X8B8G8R8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , wzy1, rgb +PIPE_FORMAT_B5G5R5A1_UNORM , plain, 1, 1, un5 , un5 , un5 , un1 , zyxw, rgb +PIPE_FORMAT_B4G4R4A4_UNORM , plain, 1, 1, un4 , un4 , un4 , un4 , zyxw, rgb +PIPE_FORMAT_B5G6R5_UNORM , plain, 1, 1, un5 , un6 , un5 , , zyx1, rgb +PIPE_FORMAT_R10G10B10A2_UNORM , plain, 1, 1, un10, un10, un10, un2 , xyzw, rgb + +# Luminance/Intensity/Alpha formats +PIPE_FORMAT_L8_UNORM , plain, 1, 1, un8 , , , , xxx1, rgb +PIPE_FORMAT_A8_UNORM , plain, 1, 1, un8 , , , , 000x, rgb +PIPE_FORMAT_I8_UNORM , plain, 1, 1, un8 , , , , xxxx, rgb +PIPE_FORMAT_L8A8_UNORM , plain, 1, 1, un8 , un8 , , , xxxy, rgb +PIPE_FORMAT_L16_UNORM , plain, 1, 1, un16, , , , xxx1, rgb + +# SRGB formats +PIPE_FORMAT_L8_SRGB , plain, 1, 1, un8 , , , , xxx1, srgb +PIPE_FORMAT_L8A8_SRGB , plain, 1, 1, un8 , un8 , , , xxxy, srgb +PIPE_FORMAT_R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , , xyz1, srgb +PIPE_FORMAT_A8B8G8R8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , wzyx, srgb +PIPE_FORMAT_X8B8G8R8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , wzy1, srgb +PIPE_FORMAT_B8G8R8A8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , zyxw, srgb +PIPE_FORMAT_B8G8R8X8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , zyx1, srgb +PIPE_FORMAT_A8R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , yzwx, srgb +PIPE_FORMAT_X8R8G8B8_SRGB , plain, 1, 1, un8 , un8 , un8 , un8 , yzw1, srgb + +# Mixed-sign formats (typically used for bump map textures) +PIPE_FORMAT_R8SG8SB8UX8U_NORM , plain, 1, 1, sn8 , sn8 , un8 , x8 , xyz1, rgb +PIPE_FORMAT_R5SG5SB6U_NORM , plain, 1, 1, sn5 , sn5 , un6 , , xyz1, rgb + +# Depth-stencil formats +PIPE_FORMAT_S8_UNORM , plain, 1, 1, un8 , , , , _x__, zs +PIPE_FORMAT_Z16_UNORM , plain, 1, 1, un16, , , , x___, zs +PIPE_FORMAT_Z32_UNORM , plain, 1, 1, un32, , , , x___, zs +PIPE_FORMAT_Z32_FLOAT , plain, 1, 1, f32 , , , , x___, zs +PIPE_FORMAT_Z24S8_UNORM , plain, 1, 1, un24, un8 , , , xy__, zs +PIPE_FORMAT_S8Z24_UNORM , plain, 1, 1, un8 , un24, , , yx__, zs +PIPE_FORMAT_Z24X8_UNORM , plain, 1, 1, un24, un8 , , , x___, zs +PIPE_FORMAT_X8Z24_UNORM , plain, 1, 1, un8 , un24, , , y___, zs + +# YUV formats +# http://www.fourcc.org/yuv.php#UYVY +PIPE_FORMAT_UYVY , subsampled, 2, 1, x32 , , , , xyz1, yuv +# http://www.fourcc.org/yuv.php#YUYV (a.k.a http://www.fourcc.org/yuv.php#YUY2) +# XXX: u_tile.c's ycbcr_get_tile_rgba actually interprets it as VYUY but the +# intent should be to match D3DFMT_YUY2 +PIPE_FORMAT_YUYV , subsampled, 2, 1, x32 , , , , xyz1, yuv + +# Compressed formats +PIPE_FORMAT_DXT1_RGB , compressed, 4, 4, x64 , , , , xyz1, rgb +PIPE_FORMAT_DXT1_RGBA , compressed, 4, 4, x64 , , , , xyzw, rgb +PIPE_FORMAT_DXT3_RGBA , compressed, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT5_RGBA , compressed, 4, 4, x128, , , , xyzw, rgb +PIPE_FORMAT_DXT1_SRGB , compressed, 4, 4, x64 , , , , xyz1, srgb +PIPE_FORMAT_DXT1_SRGBA , compressed, 4, 4, x64 , , , , xyzw, srgb +PIPE_FORMAT_DXT3_SRGBA , compressed, 4, 4, x128, , , , xyzw, srgb +PIPE_FORMAT_DXT5_SRGBA , compressed, 4, 4, x128, , , , xyzw, srgb + +# Straightforward D3D10-like formats (also used for +# vertex buffer element description) +# +# See also: +# - src/gallium/auxiliary/translate/translate_generic.c +# - src/mesa/state_tracker/st_draw.c +PIPE_FORMAT_R64_FLOAT , plain, 1, 1, f64 , , , , x001, rgb +PIPE_FORMAT_R64G64_FLOAT , plain, 1, 1, f64 , f64 , , , xy01, rgb +PIPE_FORMAT_R64G64B64_FLOAT , plain, 1, 1, f64 , f64 , f64 , , xyz1, rgb +PIPE_FORMAT_R64G64B64A64_FLOAT , plain, 1, 1, f64 , f64 , f64 , f64 , xyzw, rgb +PIPE_FORMAT_R32_FLOAT , plain, 1, 1, f32 , , , , x001, rgb +PIPE_FORMAT_R32G32_FLOAT , plain, 1, 1, f32 , f32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_FLOAT , plain, 1, 1, f32 , f32 , f32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_FLOAT , plain, 1, 1, f32 , f32 , f32 , f32 , xyzw, rgb +PIPE_FORMAT_R32_UNORM , plain, 1, 1, un32, , , , x001, rgb +PIPE_FORMAT_R32G32_UNORM , plain, 1, 1, un32, un32, , , xy01, rgb +PIPE_FORMAT_R32G32B32_UNORM , plain, 1, 1, un32, un32, un32, , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_UNORM , plain, 1, 1, un32, un32, un32, un32, xyzw, rgb +PIPE_FORMAT_R32_USCALED , plain, 1, 1, u32 , , , , x001, rgb +PIPE_FORMAT_R32G32_USCALED , plain, 1, 1, u32 , u32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_USCALED , plain, 1, 1, u32 , u32 , u32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_USCALED , plain, 1, 1, u32 , u32 , u32 , u32 , xyzw, rgb +PIPE_FORMAT_R32_SNORM , plain, 1, 1, sn32, , , , x001, rgb +PIPE_FORMAT_R32G32_SNORM , plain, 1, 1, sn32, sn32, , , xy01, rgb +PIPE_FORMAT_R32G32B32_SNORM , plain, 1, 1, sn32, sn32, sn32, , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_SNORM , plain, 1, 1, sn32, sn32, sn32, sn32, xyzw, rgb +PIPE_FORMAT_R32_SSCALED , plain, 1, 1, s32 , , , , x001, rgb +PIPE_FORMAT_R32G32_SSCALED , plain, 1, 1, s32 , s32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_SSCALED , plain, 1, 1, s32 , s32 , s32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_SSCALED , plain, 1, 1, s32 , s32 , s32 , s32 , xyzw, rgb +PIPE_FORMAT_R32_FIXED , plain, 1, 1, h32 , , , , x001, rgb +PIPE_FORMAT_R32G32_FIXED , plain, 1, 1, h32 , h32 , , , xy01, rgb +PIPE_FORMAT_R32G32B32_FIXED , plain, 1, 1, h32 , h32 , h32 , , xyz1, rgb +PIPE_FORMAT_R32G32B32A32_FIXED , plain, 1, 1, h32 , h32 , h32 , h32 , xyzw, rgb +PIPE_FORMAT_R16_UNORM , plain, 1, 1, un16, , , , x001, rgb +PIPE_FORMAT_R16G16_UNORM , plain, 1, 1, un16, un16, , , xy01, rgb +PIPE_FORMAT_R16G16B16_UNORM , plain, 1, 1, un16, un16, un16, , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_UNORM , plain, 1, 1, un16, un16, un16, un16, xyzw, rgb +PIPE_FORMAT_R16_USCALED , plain, 1, 1, u16 , , , , x001, rgb +PIPE_FORMAT_R16G16_USCALED , plain, 1, 1, u16 , u16 , , , xy01, rgb +PIPE_FORMAT_R16G16B16_USCALED , plain, 1, 1, u16 , u16 , u16 , , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_USCALED , plain, 1, 1, u16 , u16 , u16 , u16 , xyzw, rgb +PIPE_FORMAT_R16_SNORM , plain, 1, 1, sn16, , , , x001, rgb +PIPE_FORMAT_R16G16_SNORM , plain, 1, 1, sn16, sn16, , , xy01, rgb +PIPE_FORMAT_R16G16B16_SNORM , plain, 1, 1, sn16, sn16, sn16, , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_SNORM , plain, 1, 1, sn16, sn16, sn16, sn16, xyzw, rgb +PIPE_FORMAT_R16_SSCALED , plain, 1, 1, s16 , , , , x001, rgb +PIPE_FORMAT_R16G16_SSCALED , plain, 1, 1, s16 , s16 , , , xy01, rgb +PIPE_FORMAT_R16G16B16_SSCALED , plain, 1, 1, s16 , s16 , s16 , , xyz1, rgb +PIPE_FORMAT_R16G16B16A16_SSCALED , plain, 1, 1, s16 , s16 , s16 , s16 , xyzw, rgb +PIPE_FORMAT_R8_UNORM , plain, 1, 1, un8 , , , , x001, rgb +PIPE_FORMAT_R8G8_UNORM , plain, 1, 1, un8 , un8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_UNORM , plain, 1, 1, un8 , un8 , un8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_UNORM , plain, 1, 1, un8 , un8 , un8 , un8 , xyzw, rgb +PIPE_FORMAT_R8_USCALED , plain, 1, 1, u8 , , , , x001, rgb +PIPE_FORMAT_R8G8_USCALED , plain, 1, 1, u8 , u8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_USCALED , plain, 1, 1, u8 , u8 , u8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_USCALED , plain, 1, 1, u8 , u8 , u8 , u8 , xyzw, rgb +PIPE_FORMAT_R8_SNORM , plain, 1, 1, sn8 , , , , x001, rgb +PIPE_FORMAT_R8G8_SNORM , plain, 1, 1, sn8 , sn8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_SNORM , plain, 1, 1, sn8 , sn8 , sn8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_SNORM , plain, 1, 1, sn8 , sn8 , sn8 , sn8 , xyzw, rgb +PIPE_FORMAT_R8_SSCALED , plain, 1, 1, s8 , , , , x001, rgb +PIPE_FORMAT_R8G8_SSCALED , plain, 1, 1, s8 , s8 , , , xy01, rgb +PIPE_FORMAT_R8G8B8_SSCALED , plain, 1, 1, s8 , s8 , s8 , , xyz1, rgb +PIPE_FORMAT_R8G8B8A8_SSCALED , plain, 1, 1, s8 , s8 , s8 , s8 , xyzw, rgb diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index 6345a11a8cf..20fdaca007f 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2009 Vmware, Inc. + * Copyright 2009-2010 Vmware, Inc. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -39,47 +39,32 @@ extern "C" { /** - * Describe how to best pack/unpack pixels into/from the prescribed format. + * Describe how to pack/unpack pixels into/from the prescribed format. * - * These are used for automatic code generation of pixel packing and unpacking - * routines (in compile time, e.g., u_format_access.py, or in runtime, like - * llvmpipe does). - * - * Thumb rule is: if you're not code generating pixel packing/unpacking then - * these are irrelevant for you. - * - * Note that this can be deduced from other values in util_format_description - * structure. This is by design, to make code generation of pixel - * packing/unpacking/sampling routines simple and efficient. - * - * XXX: This should be renamed to something like util_format_pack. + * XXX: This could be renamed to something like util_format_pack, or broke down + * in flags inside util_format_block that said exactly what we want. */ enum util_format_layout { /** - * Single scalar component. - */ - UTIL_FORMAT_LAYOUT_SCALAR = 0, - - /** - * One or more components of mixed integer formats, arithmetically encoded - * in a word up to 32bits. + * Formats with util_format_block::width == util_format_block::height == 1 + * that can be described as an ordinary data structure. */ - UTIL_FORMAT_LAYOUT_ARITH = 1, + UTIL_FORMAT_LAYOUT_PLAIN = 0, /** - * One or more components, no mixed formats, each with equal power of two - * number of bytes. + * Formats with sub-sampled channels. + * + * This is for formats like YV12 where there is less than one sample per + * pixel. + * + * XXX: This could actually b */ - UTIL_FORMAT_LAYOUT_ARRAY = 2, + UTIL_FORMAT_LAYOUT_SUBSAMPLED = 3, /** - * XXX: Not used yet. These might go away and be replaced by a single entry, - * for formats where multiple pixels have to be - * read in order to determine a single pixel value (i.e., block.width > 1 - * || block.height > 1) + * An unspecified compression algorithm. */ - UTIL_FORMAT_LAYOUT_YUV = 3, - UTIL_FORMAT_LAYOUT_DXT = 4 + UTIL_FORMAT_LAYOUT_COMPRESSED = 4 }; @@ -135,11 +120,66 @@ struct util_format_channel_description struct util_format_description { enum pipe_format format; + const char *name; + + /** + * Short name, striped of the prefix, lower case. + */ + const char *short_name; + + /** + * Pixel block dimensions. + */ struct util_format_block block; + enum util_format_layout layout; + + /** + * The number of channels. + */ + unsigned nr_channels:3; + + /** + * Whether all channels have the same number of (whole) bytes. + */ + unsigned is_array:1; + + /** + * Whether the pixel format can be described as a bitfield structure. + * + * In particular: + * - pixel depth must be 8, 16, or 32 bits; + * - all channels must be unsigned, signed, or void + */ + unsigned is_bitmask:1; + + /** + * Whether channels have mixed types (ignoring UTIL_FORMAT_TYPE_VOID). + */ + unsigned is_mixed:1; + + /** + * Input channel description. + * + * Only valid for UTIL_FORMAT_LAYOUT_PLAIN formats. + */ struct util_format_channel_description channel[4]; + + /** + * Output channel swizzle. + * + * The order is either: + * - RGBA + * - YUV(A) + * - ZS + * depending on the colorspace. + */ unsigned char swizzle[4]; + + /** + * Colorspace transformation. + */ enum util_format_colorspace colorspace; }; @@ -179,7 +219,7 @@ util_format_is_compressed(enum pipe_format format) return FALSE; } - return desc->layout == UTIL_FORMAT_LAYOUT_DXT ? TRUE : FALSE; + return desc->layout == UTIL_FORMAT_LAYOUT_COMPRESSED ? TRUE : FALSE; } static INLINE boolean @@ -253,14 +293,7 @@ util_format_get_blockwidth(enum pipe_format format) return 1; } - switch (desc->layout) { - case UTIL_FORMAT_LAYOUT_YUV: - return 2; - case UTIL_FORMAT_LAYOUT_DXT: - return 4; - default: - return 1; - } + return desc->block.width; } static INLINE uint @@ -273,12 +306,7 @@ util_format_get_blockheight(enum pipe_format format) return 1; } - switch (desc->layout) { - case UTIL_FORMAT_LAYOUT_DXT: - return 4; - default: - return 1; - } + return desc->block.height; } static INLINE unsigned @@ -373,31 +401,14 @@ util_format_has_alpha(enum pipe_format format) return FALSE; } - switch (desc->layout) { - case UTIL_FORMAT_LAYOUT_SCALAR: - case UTIL_FORMAT_LAYOUT_ARITH: - case UTIL_FORMAT_LAYOUT_ARRAY: - /* FIXME: pf_get_component_bits( PIPE_FORMAT_A8L8_UNORM, PIPE_FORMAT_COMP_A ) should not return 0 right? */ - if (format == PIPE_FORMAT_A8_UNORM || - format == PIPE_FORMAT_A8L8_UNORM || - format == PIPE_FORMAT_A8L8_SRGB) { - return TRUE; - } - return util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3) != 0; - case UTIL_FORMAT_LAYOUT_YUV: + switch (desc->colorspace) { + case UTIL_FORMAT_COLORSPACE_RGB: + case UTIL_FORMAT_COLORSPACE_SRGB: + return desc->swizzle[3] != UTIL_FORMAT_SWIZZLE_1; + case UTIL_FORMAT_COLORSPACE_YUV: + return FALSE; + case UTIL_FORMAT_COLORSPACE_ZS: return FALSE; - case UTIL_FORMAT_LAYOUT_DXT: - switch (format) { - case PIPE_FORMAT_DXT1_RGBA: - case PIPE_FORMAT_DXT3_RGBA: - case PIPE_FORMAT_DXT5_RGBA: - case PIPE_FORMAT_DXT1_SRGBA: - case PIPE_FORMAT_DXT3_SRGBA: - case PIPE_FORMAT_DXT5_SRGBA: - return TRUE; - default: - return FALSE; - } default: assert(0); return FALSE; diff --git a/src/gallium/auxiliary/util/u_format_access.py b/src/gallium/auxiliary/util/u_format_access.py index 0b05ddb9312..00424779d28 100644 --- a/src/gallium/auxiliary/util/u_format_access.py +++ b/src/gallium/auxiliary/util/u_format_access.py @@ -37,20 +37,10 @@ ''' +import math import sys -from u_format_parse import * - - -def short_name(format): - '''Make up a short norm for a format, suitable to be used as suffix in - function names.''' - - name = format.name - if name.startswith('PIPE_FORMAT_'): - name = name[len('PIPE_FORMAT_'):] - name = name.lower() - return name +from u_format_pack import * def is_format_supported(format): @@ -63,16 +53,16 @@ def is_format_supported(format): if format.colorspace not in ('rgb', 'zs'): return False - if format.layout not in (ARITH, ARRAY): + if format.layout != PLAIN: return False for i in range(4): - type = format.in_types[i] - if type.kind not in (VOID, UNSIGNED, FLOAT): + channel = format.channels[i] + if channel.type not in (VOID, UNSIGNED, FLOAT): return False # We can only read a color from a depth/stencil format if the depth channel is present - if format.colorspace == 'zs' and format.out_swizzle[0] == SWIZZLE_NONE: + if format.colorspace == 'zs' and format.swizzles[0] == SWIZZLE_NONE: return False return True @@ -81,187 +71,48 @@ def is_format_supported(format): def native_type(format): '''Get the native appropriate for a format.''' - if format.layout == ARITH: - # For arithmetic pixel formats return the integer type that matches the whole pixel - return 'uint%u_t' % format.block_size() - elif format.layout == ARRAY: - # For array pixel formats return the integer type that matches the color channel - type = format.in_types[0] - if type.kind == UNSIGNED: - return 'uint%u_t' % type.size - elif type.kind == SIGNED: - return 'int%u_t' % type.size - elif type.kind == FLOAT: - if type.size == 32: - return 'float' - elif type.size == 64: - return 'double' + if format.layout == PLAIN: + if not format.is_array(): + # For arithmetic pixel formats return the integer type that matches the whole pixel + return 'uint%u_t' % format.block_size() + else: + # For array pixel formats return the integer type that matches the color channel + channel = format.channels[0] + if channel.type == UNSIGNED: + return 'uint%u_t' % channel.size + elif channel.type == SIGNED: + return 'int%u_t' % channel.size + elif channel.type == FLOAT: + if channel.size == 32: + return 'float' + elif channel.size == 64: + return 'double' + else: + assert False else: assert False - else: - assert False - else: - assert False - - -def intermediate_native_type(bits, sign): - '''Find a native type adequate to hold intermediate results of the request bit size.''' - - bytes = 4 # don't use anything smaller than 32bits - while bytes * 8 < bits: - bytes *= 2 - bits = bytes*8 - - if sign: - return 'int%u_t' % bits - else: - return 'uint%u_t' % bits - - -def get_one_shift(type): - '''Get the number of the bit that matches unity for this type.''' - if type.kind == 'FLOAT': - assert False - if not type.norm: - return 0 - if type.kind == UNSIGNED: - return type.size - if type.kind == SIGNED: - return type.size - 1 - if type.kind == FIXED: - return type.size / 2 - assert False - - -def get_one(type): - '''Get the value of unity for this type.''' - if type.kind == 'FLOAT' or not type.norm: - return 1 - else: - return (1 << get_one_shift(type)) - 1 - - -def generate_clamp(): - '''Code generate the clamping functions for each type. - - We don't use a macro so that arguments with side effects, - like *src_pixel++ are correctly handled. - ''' - - for suffix, native_type in [ - ('', 'double'), - ('f', 'float'), - ('ui', 'unsigned int'), - ('si', 'int'), - ]: - print 'static INLINE %s' % native_type - print 'clamp%s(%s value, %s lbound, %s ubound)' % (suffix, native_type, native_type, native_type) - print '{' - print ' if(value < lbound)' - print ' return lbound;' - print ' if(value > ubound)' - print ' return ubound;' - print ' return value;' - print '}' - print - - -def clamp_expr(src_type, dst_type, dst_native_type, value): - '''Generate the expression to clamp the value in the source type to the - destination type range.''' - - if src_type == dst_type: - return value - - # Pick the approriate clamp function - if src_type.kind == FLOAT: - if src_type.size == 32: - func = 'clampf' - elif src_type.size == 64: - func = 'clamp' - else: - assert False - elif src_type.kind == UNSIGNED: - func = 'clampui' - elif src_type.kind == SIGNED: - func = 'clampsi' else: assert False - # Clamp floats to [-1, 1] or [0, 1] range - if src_type.kind == FLOAT and dst_type.norm: - max = 1 - if src_type.sign and dst_type.sign: - min = -1 - else: - min = 0 - return '%s(%s, %s, %s)' % (func, value, min, max) - - # FIXME: Also clamp scaled values - - return value - - -def conversion_expr(src_type, dst_type, dst_native_type, value): - '''Generate the expression to convert a value between two types.''' - - if src_type == dst_type: - return value - if src_type.kind == FLOAT and dst_type.kind == FLOAT: - return '(%s)%s' % (dst_native_type, value) - - if not src_type.norm and not dst_type.norm: - return '(%s)%s' % (dst_native_type, value) - - value = clamp_expr(src_type, dst_type, dst_native_type, value) - - if dst_type.kind == FLOAT: - if src_type.norm: - one = get_one(src_type) - if src_type.size <= 23: - scale = '(1.0f/0x%x)' % one - else: - # bigger than single precision mantissa, use double - scale = '(1.0/0x%x)' % one - value = '(%s * %s)' % (value, scale) - return '(%s)%s' % (dst_native_type, value) - - if src_type.kind == FLOAT: - if dst_type.norm: - dst_one = get_one(dst_type) - if dst_type.size <= 23: - scale = '0x%x' % dst_one - else: - # bigger than single precision mantissa, use double - scale = '(double)0x%x' % dst_one - value = '(%s * %s)' % (value, scale) - return '(%s)%s' % (dst_native_type, value) - - if src_type.kind == dst_type.kind: - src_one = get_one(src_type) - dst_one = get_one(dst_type) - - if src_one > dst_one and src_type.norm and dst_type.norm: - # We can just bitshift - src_shift = get_one_shift(src_type) - dst_shift = get_one_shift(dst_type) - value = '(%s >> %s)' % (value, src_shift - dst_shift) - else: - # We need to rescale using an intermediate type big enough to hold the multiplication of both - tmp_native_type = intermediate_native_type(src_type.size + dst_type.size, src_type.sign and dst_type.sign) - value = '(%s)%s' % (tmp_native_type, value) - value = '%s * 0x%x / 0x%x' % (value, dst_one, src_one) - value = '(%s)%s' % (dst_native_type, value) - return value - - assert False +def generate_srgb_tables(): + print 'static ubyte srgb_to_linear[256] = {' + for i in range(256): + print ' %s,' % (int(math.pow((i / 255.0 + 0.055) / 1.055, 2.4) * 255)) + print '};' + print + print 'static ubyte linear_to_srgb[256] = {' + print ' 0,' + for i in range(1, 256): + print ' %s,' % (int((1.055 * math.pow(i / 255.0, 0.41666) - 0.055) * 255)) + print '};' + print -def generate_format_read(format, dst_type, dst_native_type, dst_suffix): +def generate_format_read(format, dst_channel, dst_native_type, dst_suffix): '''Generate the function to read pixels from a particular format''' - name = short_name(format) + name = format.short_name() src_native_type = native_type(format) @@ -279,11 +130,11 @@ def generate_format_read(format, dst_type, dst_native_type, dst_suffix): names = ['']*4 if format.colorspace == 'rgb': for i in range(4): - swizzle = format.out_swizzle[i] + swizzle = format.swizzles[i] if swizzle < 4: names[swizzle] += 'rgba'[i] elif format.colorspace == 'zs': - swizzle = format.out_swizzle[0] + swizzle = format.swizzles[0] if swizzle < 4: names[swizzle] = 'z' else: @@ -291,64 +142,66 @@ def generate_format_read(format, dst_type, dst_native_type, dst_suffix): else: assert False - if format.layout == ARITH: - print ' %s pixel = *src_pixel++;' % src_native_type - shift = 0; - for i in range(4): - src_type = format.in_types[i] - width = src_type.size - if names[i]: - value = 'pixel' - mask = (1 << width) - 1 - if shift: - value = '(%s >> %u)' % (value, shift) - if shift + width < format.block_size(): - value = '(%s & 0x%x)' % (value, mask) - value = conversion_expr(src_type, dst_type, dst_native_type, value) - print ' %s %s = %s;' % (dst_native_type, names[i], value) - shift += width - elif format.layout == ARRAY: - for i in range(4): - src_type = format.in_types[i] - if names[i]: - value = '(*src_pixel++)' - value = conversion_expr(src_type, dst_type, dst_native_type, value) - print ' %s %s = %s;' % (dst_native_type, names[i], value) + if format.layout == PLAIN: + if not format.is_array(): + print ' %s pixel = *src_pixel++;' % src_native_type + shift = 0; + for i in range(4): + src_channel = format.channels[i] + width = src_channel.size + if names[i]: + value = 'pixel' + mask = (1 << width) - 1 + if shift: + value = '(%s >> %u)' % (value, shift) + if shift + width < format.block_size(): + value = '(%s & 0x%x)' % (value, mask) + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + print ' %s %s = %s;' % (dst_native_type, names[i], value) + shift += width + else: + for i in range(4): + src_channel = format.channels[i] + if names[i]: + value = 'src_pixel[%u]' % i + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + print ' %s %s = %s;' % (dst_native_type, names[i], value) + print ' src_pixel += %u;' % (format.nr_channels()) else: assert False for i in range(4): if format.colorspace == 'rgb': - swizzle = format.out_swizzle[i] + swizzle = format.swizzles[i] if swizzle < 4: value = names[swizzle] elif swizzle == SWIZZLE_0: value = '0' elif swizzle == SWIZZLE_1: - value = get_one(dst_type) + value = get_one(dst_channel) else: assert False elif format.colorspace == 'zs': if i < 3: value = 'z' else: - value = get_one(dst_type) + value = get_one(dst_channel) else: assert False print ' *dst_pixel++ = %s; /* %s */' % (value, 'rgba'[i]) print ' }' print ' src_row += src_stride;' - print ' dst_row += dst_stride/sizeof(%s);' % dst_native_type + print ' dst_row += dst_stride/sizeof(*dst_row);' print ' }' print '}' print -def generate_format_write(format, src_type, src_native_type, src_suffix): +def generate_format_write(format, src_channel, src_native_type, src_suffix): '''Generate the function to write pixels to a particular format''' - name = short_name(format) + name = format.short_name() dst_native_type = native_type(format) @@ -363,58 +216,48 @@ def generate_format_write(format, src_type, src_native_type, src_suffix): print ' const %s *src_pixel = src_row;' %src_native_type print ' for (x = 0; x < w; ++x) {' - inv_swizzle = [None]*4 - if format.colorspace == 'rgb': - for i in range(4): - swizzle = format.out_swizzle[i] - if swizzle < 4: - inv_swizzle[swizzle] = i - elif format.colorspace == 'zs': - swizzle = format.out_swizzle[0] - if swizzle < 4: - inv_swizzle[swizzle] = 0 - else: - assert False - - if format.layout == ARITH: - print ' %s pixel = 0;' % dst_native_type - shift = 0; - for i in range(4): - dst_type = format.in_types[i] - width = dst_type.size - if inv_swizzle[i] is not None: - value = 'src_pixel[%u]' % inv_swizzle[i] - value = conversion_expr(src_type, dst_type, dst_native_type, value) - if shift: - value = '(%s << %u)' % (value, shift) - print ' pixel |= %s;' % value - shift += width - print ' *dst_pixel++ = pixel;' - elif format.layout == ARRAY: - for i in range(4): - dst_type = format.in_types[i] - if inv_swizzle[i] is not None: - value = 'src_pixel[%u]' % inv_swizzle[i] - value = conversion_expr(src_type, dst_type, dst_native_type, value) - print ' *dst_pixel++ = %s;' % value + inv_swizzle = format.inv_swizzles() + + if format.layout == PLAIN: + if not format.is_array(): + print ' %s pixel = 0;' % dst_native_type + shift = 0; + for i in range(4): + dst_channel = format.channels[i] + width = dst_channel.size + if inv_swizzle[i] is not None: + value = 'src_pixel[%u]' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + if shift: + value = '(%s << %u)' % (value, shift) + print ' pixel |= %s;' % value + shift += width + print ' *dst_pixel++ = pixel;' + else: + for i in range(4): + dst_channel = format.channels[i] + if inv_swizzle[i] is not None: + value = 'src_pixel[%u]' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + print ' *dst_pixel++ = %s;' % value else: assert False print ' src_pixel += 4;' print ' }' print ' dst_row += dst_stride;' - print ' src_row += src_stride/sizeof(%s);' % src_native_type + print ' src_row += src_stride/sizeof(*src_row);' print ' }' print '}' print -def generate_read(formats, dst_type, dst_native_type, dst_suffix): +def generate_read(formats, dst_channel, dst_native_type, dst_suffix): '''Generate the dispatch function to read pixels from any format''' for format in formats: if is_format_supported(format): - generate_format_read(format, dst_type, dst_native_type, dst_suffix) + generate_format_read(format, dst_channel, dst_native_type, dst_suffix) print 'void' print 'util_format_read_%s(enum pipe_format format, %s *dst, unsigned dst_stride, const void *src, unsigned src_stride, unsigned x, unsigned y, unsigned w, unsigned h)' % (dst_suffix, dst_native_type) @@ -424,7 +267,7 @@ def generate_read(formats, dst_type, dst_native_type, dst_suffix): for format in formats: if is_format_supported(format): print ' case %s:' % format.name - print ' func = &util_format_%s_read_%s;' % (short_name(format), dst_suffix) + print ' func = &util_format_%s_read_%s;' % (format.short_name(), dst_suffix) print ' break;' print ' default:' print ' debug_printf("unsupported format\\n");' @@ -435,12 +278,12 @@ def generate_read(formats, dst_type, dst_native_type, dst_suffix): print -def generate_write(formats, src_type, src_native_type, src_suffix): +def generate_write(formats, src_channel, src_native_type, src_suffix): '''Generate the dispatch function to write pixels to any format''' for format in formats: if is_format_supported(format): - generate_format_write(format, src_type, src_native_type, src_suffix) + generate_format_write(format, src_channel, src_native_type, src_suffix) print 'void' print 'util_format_write_%s(enum pipe_format format, const %s *src, unsigned src_stride, void *dst, unsigned dst_stride, unsigned x, unsigned y, unsigned w, unsigned h)' % (src_suffix, src_native_type) @@ -451,7 +294,7 @@ def generate_write(formats, src_type, src_native_type, src_suffix): for format in formats: if is_format_supported(format): print ' case %s:' % format.name - print ' func = &util_format_%s_write_%s;' % (short_name(format), src_suffix) + print ' func = &util_format_%s_write_%s;' % (format.short_name(), src_suffix) print ' break;' print ' default:' print ' debug_printf("unsupported format\\n");' @@ -473,20 +316,20 @@ def main(): print __doc__.strip() print print '#include "pipe/p_compiler.h"' - print '#include "u_format.h"' print '#include "u_math.h"' + print '#include "u_format_pack.h"' print - generate_clamp() + generate_srgb_tables() - type = Type(FLOAT, False, 32) + type = Channel(FLOAT, False, 32) native_type = 'float' suffix = '4f' generate_read(formats, type, native_type, suffix) generate_write(formats, type, native_type, suffix) - type = Type(UNSIGNED, True, 8) + type = Channel(UNSIGNED, True, 8) native_type = 'uint8_t' suffix = '4ub' diff --git a/src/gallium/auxiliary/util/u_format_pack.py b/src/gallium/auxiliary/util/u_format_pack.py new file mode 100644 index 00000000000..b49039db39b --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_pack.py @@ -0,0 +1,550 @@ +#!/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. + * + **************************************************************************/ + +/** + * @file + * Pixel format packing and unpacking functions. + * + * @author Jose Fonseca <[email protected]> + */ +''' + + +import sys + +from u_format_parse import * + + +def generate_format_type(format): + '''Generate a structure that describes the format.''' + + print 'union util_format_%s {' % format.short_name() + if format.is_bitmask(): + print ' uint%u_t value;' % (format.block_size(),) + print ' struct {' + for channel in format.channels: + if format.is_bitmask() and not format.is_array(): + if channel.type == VOID: + if channel.size: + print ' unsigned %s:%u;' % (channel.name, channel.size) + elif channel.type == UNSIGNED: + print ' unsigned %s:%u;' % (channel.name, channel.size) + elif channel.type == SIGNED: + print ' int %s:%u;' % (channel.name, channel.size) + else: + assert 0 + else: + assert channel.size % 8 == 0 and is_pot(channel.size) + if channel.type == VOID: + if channel.size: + print ' uint%u_t %s;' % (channel.size, channel.name) + elif channel.type == UNSIGNED: + print ' uint%u_t %s;' % (channel.size, channel.name) + elif channel.type in (SIGNED, FIXED): + print ' int%u_t %s;' % (channel.size, channel.name) + elif channel.type == FLOAT: + if channel.size == 64: + print ' double %s;' % (channel.name) + elif channel.size == 32: + print ' float %s;' % (channel.name) + elif channel.size == 16: + print ' uint16_t %s;' % (channel.name) + else: + assert 0 + else: + assert 0 + print ' } chan;' + print '};' + print + + +def bswap_format(format): + '''Generate a structure that describes the format.''' + + if format.is_bitmask() and not format.is_array(): + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' pixel.value = util_bswap%u(pixel.value);' % format.block_size() + print '#endif' + + +def is_format_supported(format): + '''Determines whether we actually have the plumbing necessary to generate the + to read/write to/from this format.''' + + # FIXME: Ideally we would support any format combination here. + + if format.layout != PLAIN: + return False + + for i in range(4): + channel = format.channels[i] + if channel.type not in (VOID, UNSIGNED, SIGNED, FLOAT): + return False + + # We can only read a color from a depth/stencil format if the depth channel is present + if format.colorspace == 'zs' and format.swizzles[0] == SWIZZLE_NONE: + return False + + return True + + +def native_type(format): + '''Get the native appropriate for a format.''' + + if format.layout == PLAIN: + if not format.is_array(): + # For arithmetic pixel formats return the integer type that matches the whole pixel + return 'uint%u_t' % format.block_size() + else: + # For array pixel formats return the integer type that matches the color channel + type = format.channels[0] + if type.type == UNSIGNED: + return 'uint%u_t' % type.size + elif type.type == SIGNED: + return 'int%u_t' % type.size + elif type.type == FLOAT: + if type.size == 32: + return 'float' + elif type.size == 64: + return 'double' + else: + assert False + else: + assert False + else: + assert False + + +def intermediate_native_type(bits, sign): + '''Find a native type adequate to hold intermediate results of the request bit size.''' + + bytes = 4 # don't use anything smaller than 32bits + while bytes * 8 < bits: + bytes *= 2 + bits = bytes*8 + + if sign: + return 'int%u_t' % bits + else: + return 'uint%u_t' % bits + + +def get_one_shift(type): + '''Get the number of the bit that matches unity for this type.''' + if type.type == 'FLOAT': + assert False + if not type.norm: + return 0 + if type.type == UNSIGNED: + return type.size + if type.type == SIGNED: + return type.size - 1 + if type.type == FIXED: + return type.size / 2 + assert False + + +def get_one(type): + '''Get the value of unity for this type.''' + if type.type == 'FLOAT' or not type.norm: + return 1 + else: + return (1 << get_one_shift(type)) - 1 + + +def generate_clamp(): + '''Code generate the clamping functions for each type. + + We don't use a macro so that arguments with side effects, + like *src_pixel++ are correctly handled. + ''' + + for suffix, native_type in [ + ('', 'double'), + ('f', 'float'), + ('ui', 'unsigned int'), + ('si', 'int'), + ]: + print 'static INLINE %s' % native_type + print 'clamp%s(%s value, %s lbound, %s ubound)' % (suffix, native_type, native_type, native_type) + print '{' + print ' if(value < lbound)' + print ' return lbound;' + print ' if(value > ubound)' + print ' return ubound;' + print ' return value;' + print '}' + print + + +def clamp_expr(src_channel, dst_channel, dst_native_type, value): + '''Generate the expression to clamp the value in the source type to the + destination type range.''' + + if src_channel == dst_channel: + return value + + # Pick the approriate clamp function + if src_channel.type == FLOAT: + if src_channel.size == 32: + func = 'clampf' + elif src_channel.size == 64: + func = 'clamp' + else: + assert False + elif src_channel.type == UNSIGNED: + func = 'clampui' + elif src_channel.type == SIGNED: + func = 'clampsi' + else: + assert False + + src_min = src_channel.min() + src_max = src_channel.max() + dst_min = dst_channel.min() + dst_max = dst_channel.max() + + if src_min < dst_min and src_max > dst_max: + return 'CLAMP(%s, %s, %s)' % (value, dst_min, dst_max) + + if src_max > dst_max: + return 'MIN2(%s, %s)' % (value, dst_max) + + if src_min < dst_min: + return 'MAX2(%s, %s)' % (value, dst_min) + + return value + + +def conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=True): + '''Generate the expression to convert a value between two types.''' + + if src_channel == dst_channel: + return value + + if src_channel.type == FLOAT and dst_channel.type == FLOAT: + return '(%s)%s' % (dst_native_type, value) + + if clamp: + value = clamp_expr(src_channel, dst_channel, dst_native_type, value) + + if dst_channel.type == FLOAT: + if src_channel.norm: + one = get_one(src_channel) + if src_channel.size <= 23: + scale = '(1.0f/0x%x)' % one + else: + # bigger than single precision mantissa, use double + scale = '(1.0/0x%x)' % one + value = '(%s * %s)' % (value, scale) + return '(%s)%s' % (dst_native_type, value) + + if src_channel.type == FLOAT: + if dst_channel.norm: + dst_one = get_one(dst_channel) + if dst_channel.size <= 23: + scale = '0x%x' % dst_one + else: + # bigger than single precision mantissa, use double + scale = '(double)0x%x' % dst_one + value = '(%s * %s)' % (value, scale) + return '(%s)%s' % (dst_native_type, value) + + if src_channel.type in (SIGNED, UNSIGNED) and dst_channel.type in (SIGNED, UNSIGNED): + if not src_channel.norm and not dst_channel.norm: + # neither is normalized -- just cast + return '(%s)%s' % (dst_native_type, value) + + src_one = get_one(src_channel) + dst_one = get_one(dst_channel) + + if src_one > dst_one and src_channel.norm and dst_channel.norm: + # We can just bitshift + src_shift = get_one_shift(src_channel) + dst_shift = get_one_shift(dst_channel) + value = '(%s >> %s)' % (value, src_shift - dst_shift) + else: + # We need to rescale using an intermediate type big enough to hold the multiplication of both + tmp_native_type = intermediate_native_type(src_channel.size + dst_channel.size, src_channel.sign and dst_channel.sign) + value = '((%s)%s)' % (tmp_native_type, value) + value = '(%s * 0x%x / 0x%x)' % (value, dst_one, src_one) + value = '(%s)%s' % (dst_native_type, value) + return value + + assert False + + +def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix): + '''Generate the function to unpack pixels from a particular format''' + + assert format.layout == PLAIN + + name = format.short_name() + + src_native_type = native_type(format) + + print 'static INLINE void' + print 'util_format_%s_unpack_%s(%s *dst, const void *src)' % (name, dst_suffix, dst_native_type) + print '{' + + if format.is_bitmask(): + depth = format.block_size() + print ' uint%u_t value = *(uint%u_t *)src;' % (depth, depth) + + # Declare the intermediate variables + for i in range(format.nr_channels()): + src_channel = format.channels[i] + if src_channel.type == UNSIGNED: + print ' uint%u_t %s;' % (depth, src_channel.name) + elif src_channel.type == SIGNED: + print ' int%u_t %s;' % (depth, src_channel.name) + + print '#ifdef PIPE_ARCH_BIG_ENDIAN' + print ' value = util_bswap%u(value);' % depth + print '#endif' + + # Compute the intermediate unshifted values + shift = 0 + for i in range(format.nr_channels()): + src_channel = format.channels[i] + value = 'value' + if src_channel.type == UNSIGNED: + if shift: + value = '%s >> %u' % (value, shift) + if shift + src_channel.size < depth: + value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1) + elif src_channel.type == SIGNED: + if shift + src_channel.size < depth: + # Align the sign bit + lshift = depth - (shift + src_channel.size) + value = '%s << %u' % (value, lshift) + # Cast to signed + value = '(int%u_t)(%s) ' % (depth, value) + if src_channel.size < depth: + # Align the LSB bit + rshift = depth - src_channel.size + value = '(%s) >> %u' % (value, rshift) + else: + value = None + + if value is not None: + print ' %s = %s;' % (src_channel.name, value) + + shift += src_channel.size + + # Convert, swizzle, and store final values + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + value = src_channel.name + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: + value = get_one(dst_channel) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = 'dst[0]' + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + + else: + print ' union util_format_%s pixel;' % format.short_name() + print ' memcpy(&pixel, src, sizeof pixel);' + bswap_format(format) + + for i in range(4): + swizzle = format.swizzles[i] + if swizzle < 4: + src_channel = format.channels[swizzle] + value = 'pixel.chan.%s' % src_channel.name + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + elif swizzle == SWIZZLE_0: + value = '0' + elif swizzle == SWIZZLE_1: + value = get_one(dst_channel) + elif swizzle == SWIZZLE_NONE: + value = '0' + else: + assert False + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = 'dst[0]' + print ' dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i]) + + print '}' + print + + +def generate_format_pack(format, src_channel, src_native_type, src_suffix): + '''Generate the function to pack pixels to a particular format''' + + name = format.short_name() + + dst_native_type = native_type(format) + + print 'static INLINE void' + print 'util_format_%s_pack_%s(void *dst, %s r, %s g, %s b, %s a)' % (name, src_suffix, src_native_type, src_native_type, src_native_type, src_native_type) + print '{' + print ' union util_format_%s pixel;' % format.short_name() + + assert format.layout == PLAIN + + inv_swizzle = format.inv_swizzles() + + for i in range(4): + dst_channel = format.channels[i] + width = dst_channel.size + if inv_swizzle[i] is None: + continue + value = 'rgba'[inv_swizzle[i]] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value) + if format.colorspace == ZS: + if i == 3: + value = get_one(dst_channel) + elif i >= 1: + value = '0' + print ' pixel.chan.%s = %s;' % (dst_channel.name, value) + + bswap_format(format) + print ' memcpy(dst, &pixel, sizeof pixel);' + print '}' + print + + +def generate_unpack(formats, dst_channel, dst_native_type, dst_suffix): + '''Generate the dispatch function to unpack pixels from any format''' + + for format in formats: + if is_format_supported(format): + generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix) + + print 'static INLINE void' + print 'util_format_unpack_%s(enum pipe_format format, %s *dst, const void *src)' % (dst_suffix, dst_native_type) + print '{' + print ' void (*func)(%s *dst, const void *src);' % dst_native_type + print ' switch(format) {' + for format in formats: + if is_format_supported(format): + print ' case %s:' % format.name + print ' func = &util_format_%s_unpack_%s;' % (format.short_name(), dst_suffix) + print ' break;' + print ' default:' + print ' debug_printf("unsupported format\\n");' + print ' return;' + print ' }' + print ' func(dst, src);' + print '}' + print + + +def generate_pack(formats, src_channel, src_native_type, src_suffix): + '''Generate the dispatch function to pack pixels to any format''' + + for format in formats: + if is_format_supported(format): + generate_format_pack(format, src_channel, src_native_type, src_suffix) + + print 'static INLINE void' + print 'util_format_pack_%s(enum pipe_format format, void *dst, %s r, %s g, %s b, %s a)' % (src_suffix, src_native_type, src_native_type, src_native_type, src_native_type) + print '{' + print ' void (*func)(void *dst, %s r, %s g, %s b, %s a);' % (src_native_type, src_native_type, src_native_type, src_native_type) + print ' switch(format) {' + for format in formats: + if is_format_supported(format): + print ' case %s:' % format.name + print ' func = &util_format_%s_pack_%s;' % (format.short_name(), src_suffix) + print ' break;' + print ' default:' + print ' debug_printf("%s: unsupported format\\n", __FUNCTION__);' + print ' return;' + print ' }' + print ' func(dst, r, g, b, a);' + print '}' + print + + +def main(): + formats = [] + for arg in sys.argv[1:]: + formats.extend(parse(arg)) + + print '/* This file is autogenerated by u_format_pack.py from u_format.csv. Do not edit directly. */' + print + # This will print the copyright message on the top of this file + print __doc__.strip() + + print + print '#ifndef U_FORMAT_PACK_H' + print '#define U_FORMAT_PACK_H' + print + print '#include "pipe/p_compiler.h"' + print '#include "u_math.h"' + print '#include "u_format.h"' + print + + generate_clamp() + + for format in formats: + if format.layout == PLAIN: + generate_format_type(format) + + channel = Channel(FLOAT, False, 32) + native_type = 'float' + suffix = '4f' + + generate_unpack(formats, channel, native_type, suffix) + generate_pack(formats, channel, native_type, suffix) + + channel = Channel(UNSIGNED, True, 8) + native_type = 'uint8_t' + suffix = '4ub' + + generate_unpack(formats, channel, native_type, suffix) + generate_pack(formats, channel, native_type, suffix) + + print + print '#ifdef __cplusplus' + print '}' + print '#endif' + print + print '#endif /* ! U_FORMAT_PACK_H */' + + +if __name__ == '__main__': + main() diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py index 493aff71127..f74dc5e88a4 100755 --- a/src/gallium/auxiliary/util/u_format_parse.py +++ b/src/gallium/auxiliary/util/u_format_parse.py @@ -30,64 +30,163 @@ ''' -import sys - - VOID, UNSIGNED, SIGNED, FIXED, FLOAT = range(5) SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W, SWIZZLE_0, SWIZZLE_1, SWIZZLE_NONE, = range(7) -ARITH = 'arith' -ARRAY = 'array' +PLAIN = 'plain' + +RGB = 'rgb' +SRGB = 'srgb' +YUV = 'yuv' +ZS = 'zs' + +def is_pot(x): + return (x & (x - 1)) == 0; -class Type: - '''Describe the type of a color channel.''' + +VERY_LARGE = 99999999999999999999999 + + +class Channel: + '''Describe the channel of a color channel.''' - def __init__(self, kind, norm, size): - self.kind = kind + def __init__(self, type, norm, size, name = ''): + self.type = type self.norm = norm self.size = size - self.sign = kind in (SIGNED, FIXED, FLOAT) + self.sign = type in (SIGNED, FIXED, FLOAT) + self.name = name def __str__(self): - s = str(self.kind) + s = str(self.type) if self.norm: s += 'n' s += str(self.size) return s def __eq__(self, other): - return self.kind == other.kind and self.norm == other.norm and self.size == other.size + return self.type == other.type and self.norm == other.norm and self.size == other.size + + def max(self): + '''Maximum representable number.''' + if self.type == FLOAT: + return VERY_LARGE + if self.norm: + return 1 + if self.type == UNSIGNED: + return (1 << self.size) - 1 + if self.type == SIGNED: + return (1 << (self.size - 1)) - 1 + assert False + + def min(self): + '''Minimum representable number.''' + if self.type == FLOAT: + return -VERY_LARGE + if self.type == UNSIGNED: + return 0 + if self.norm: + return -1 + if self.type == SIGNED: + return -(1 << (self.size - 1)) + assert False class Format: '''Describe a pixel format.''' - def __init__(self, name, layout, block_width, block_height, in_types, out_swizzle, colorspace): + def __init__(self, name, layout, block_width, block_height, channels, swizzles, colorspace): self.name = name self.layout = layout self.block_width = block_width self.block_height = block_height - self.in_types = in_types - self.out_swizzle = out_swizzle + self.channels = channels + self.swizzles = swizzles self.name = name self.colorspace = colorspace def __str__(self): return self.name + def short_name(self): + '''Make up a short norm for a format, suitable to be used as suffix in + function names.''' + + name = self.name + if name.startswith('PIPE_FORMAT_'): + name = name[len('PIPE_FORMAT_'):] + name = name.lower() + return name + def block_size(self): size = 0 - for type in self.in_types: - size += type.size + for channel in self.channels: + size += channel.size return size + def nr_channels(self): + nr_channels = 0 + for channel in self.channels: + if channel.size: + nr_channels += 1 + return nr_channels + + def is_array(self): + ref_channel = self.channels[0] + for channel in self.channels[1:]: + if channel.size and (channel.size != ref_channel.size or channel.size % 8): + return False + return True + + def is_mixed(self): + ref_channel = self.channels[0] + for channel in self.channels[1:]: + if channel.type != VOID: + if channel.type != ref_channel.type: + return True + if channel.norm != ref_channel.norm: + return True + return False + + def is_pot(self): + return is_pot(self.block_size()) + + def is_int(self): + for channel in self.channels: + if channel.type not in (VOID, UNSIGNED, SIGNED): + return False + return True + + def is_float(self): + for channel in self.channels: + if channel.type not in (VOID, FLOAT): + return False + return True + + def is_bitmask(self): + if self.block_size() not in (8, 16, 32): + return False + for channel in self.channels: + if channel.type not in (VOID, UNSIGNED, SIGNED): + return False + return True + + def inv_swizzles(self): + '''Return an array[4] of inverse swizzle terms''' + inv_swizzle = [None]*4 + for i in range(4): + swizzle = self.swizzles[i] + if swizzle < 4: + inv_swizzle[swizzle] = i + return inv_swizzle + def stride(self): return self.block_size()/8 -_kind_parse_map = { +_type_parse_map = { '': VOID, 'x': VOID, 'u': UNSIGNED, @@ -108,20 +207,55 @@ _swizzle_parse_map = { def parse(filename): '''Parse the format descrition in CSV format in terms of the - Type and Format classes above.''' + Channel and Format classes above.''' stream = open(filename) formats = [] for line in stream: - line = line.rstrip() + try: + comment = line.index('#') + except ValueError: + pass + else: + line = line[:comment] + line = line.strip() + if not line: + continue + fields = [field.strip() for field in line.split(',')] + name = fields[0] layout = fields[1] block_width, block_height = map(int, fields[2:4]) - in_types = [] - for field in fields[4:8]: + + swizzles = [_swizzle_parse_map[swizzle] for swizzle in fields[8]] + colorspace = fields[9] + + if layout == PLAIN: + names = ['']*4 + if colorspace in (RGB, SRGB): + for i in range(4): + swizzle = swizzles[i] + if swizzle < 4: + names[swizzle] += 'rgba'[i] + elif colorspace == ZS: + for i in range(4): + swizzle = swizzles[i] + if swizzle < 4: + names[swizzle] += 'zs'[i] + else: + assert False + for i in range(4): + if names[i] == '': + names[i] = 'x' + else: + names = ['x', 'y', 'z', 'w'] + + channels = [] + for i in range(0, 4): + field = fields[4 + i] if field: - kind = _kind_parse_map[field[0]] + type = _type_parse_map[field[0]] if field[1] == 'n': norm = True size = int(field[2:]) @@ -129,13 +263,13 @@ def parse(filename): norm = False size = int(field[1:]) else: - kind = VOID + type = VOID norm = False size = 0 - in_type = Type(kind, norm, size) - in_types.append(in_type) - out_swizzle = [_swizzle_parse_map[swizzle] for swizzle in fields[8]] - colorspace = fields[9] - formats.append(Format(name, layout, block_width, block_height, in_types, out_swizzle, colorspace)) + channel = Channel(type, norm, size, names[i]) + channels.append(channel) + + format = Format(name, layout, block_width, block_height, channels, swizzles, colorspace) + formats.append(format) return formats diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py index 571cab55dc8..fb68852a530 100755 --- a/src/gallium/auxiliary/util/u_format_table.py +++ b/src/gallium/auxiliary/util/u_format_table.py @@ -51,7 +51,7 @@ colorspace_channels_map = { } -kind_map = { +type_map = { VOID: "UTIL_FORMAT_TYPE_VOID", UNSIGNED: "UTIL_FORMAT_TYPE_UNSIGNED", SIGNED: "UTIL_FORMAT_TYPE_SIGNED", @@ -87,35 +87,48 @@ def write_format_table(formats): print '#include "u_format.h"' print print 'const struct util_format_description' - print 'util_format_description_table[] = ' - print "{" - print " {" - print " PIPE_FORMAT_NONE," - print " \"PIPE_FORMAT_NONE\"," - print " {0, 0, 0}," - print " 0," - print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}," - print " {0, 0, 0, 0}," - print " 0" - print " }," + print 'util_format_none_description = {' + print " PIPE_FORMAT_NONE," + print " \"PIPE_FORMAT_NONE\"," + print " \"none\"," + print " {0, 0, 0}," + print " 0," + print " 0," + print " 0," + print " 0," + print " 0," + print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}," + print " {0, 0, 0, 0}," + print " 0" + print "};" + print for format in formats: + print 'const struct util_format_description' + print 'util_format_%s_description = {' % (format.short_name(),) + print " %s," % (format.name,) + print " \"%s\"," % (format.name,) + print " \"%s\"," % (format.short_name(),) + print " {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size()) + print " %s," % (layout_map(format.layout),) + print " %u,\t/* nr_channels */" % (format.nr_channels(),) + print " %s,\t/* is_array */" % (bool_map(format.is_array()),) + print " %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),) + print " %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),) print " {" - print " %s," % (format.name,) - print " \"%s\"," % (format.name,) - print " {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size()) - print " %s," % (layout_map(format.layout),) - print " {" for i in range(4): - type = format.in_types[i] + channel = format.channels[i] if i < 3: sep = "," else: sep = "" - print " {%s, %s, %u}%s\t/* %s */" % (kind_map[type.kind], bool_map(type.norm), type.size, sep, "xyzw"[i]) - print " }," - print " {" + if channel.size: + print " {%s, %s, %u}%s\t/* %s = %s */" % (type_map[channel.type], bool_map(channel.norm), channel.size, sep, "xyzw"[i], channel.name) + else: + print " {0, 0, 0}%s" % (sep,) + print " }," + print " {" for i in range(4): - swizzle = format.out_swizzle[i] + swizzle = format.swizzles[i] if i < 3: sep = "," else: @@ -124,11 +137,30 @@ def write_format_table(formats): comment = colorspace_channels_map[format.colorspace][i] except (KeyError, IndexError): comment = 'ignored' - print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment) - print " }," - print " %s," % (colorspace_map(format.colorspace),) + print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment) print " }," - print "};" + print " %s," % (colorspace_map(format.colorspace),) + print "};" + print + print "const struct util_format_description *" + print "util_format_description(enum pipe_format format)" + print "{" + print " if (format >= PIPE_FORMAT_COUNT) {" + print " return NULL;" + print " }" + print + print " switch (format) {" + print " case PIPE_FORMAT_NONE:" + print " return &util_format_none_description;" + for format in formats: + print " case %s:" % format.name + print " return &util_format_%s_description;" % (format.short_name(),) + print " default:" + print " assert(0);" + print " return NULL;" + print " }" + print "}" + print def main(): diff --git a/src/gallium/auxiliary/util/u_format_tests.c b/src/gallium/auxiliary/util/u_format_tests.c new file mode 100644 index 00000000000..182a4740448 --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_tests.c @@ -0,0 +1,544 @@ +/************************************************************************** + * + * Copyright 2009-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 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 "u_memory.h" +#include "u_format_tests.h" + + +/* + * Helper macros to create the packed bytes for longer words. + */ + +#define PACKED_1x8(x) {x, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_2x8(x, y) {x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_3x8(x, y, z) {x, y, z, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_4x8(x, y, z, w) {x, y, z, w, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + +#define PACKED_1x16(x) {(x) & 0xff, (x) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_2x16(x, y) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_3x16(x, y, z) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_4x16(x, y, z, w) {(x) & 0xff, (x) >> 8, (y) & 0xff, (y) >> 8, (z) & 0xff, (z) >> 8, (w) & 0xff, (w) >> 8, 0, 0, 0, 0, 0, 0, 0, 0} + +#define PACKED_1x32(x) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_2x32(x, y) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, 0, 0, 0, 0, 0, 0, 0, 0} +#define PACKED_3x32(x, y, z) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, 0, 0, 0, 0} +#define PACKED_4x32(x, y, z, w) {(x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, (x) >> 24, (y) & 0xff, ((y) >> 8) & 0xff, ((y) >> 16) & 0xff, (y) >> 24, (z) & 0xff, ((z) >> 8) & 0xff, ((z) >> 16) & 0xff, (z) >> 24, (w) & 0xff, ((w) >> 8) & 0xff, ((w) >> 16) & 0xff, (w) >> 24} + + +/** + * Test cases. + * + * These were manually entered. We could generate these + * + * To keep this to a we cover only the corner cases, which should produce + * good enough coverage since that pixel format transformations are afine for + * non SRGB formats. + */ +const struct util_format_test_case +util_format_test_cases[] = +{ + + /* + * 32-bit rendertarget formats + */ + + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x0000ff00), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0x00ff0000), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B8G8R8X8_UNORM, PACKED_1x32(0x00ffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_X8R8G8B8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8B8G8R8_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x000000ff), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x0000ff00), {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0x00ff0000), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xff000000), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_X8B8G8R8_UNORM, PACKED_1x32(0xffffff00), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000003ff), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x000ffc00), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x3ff00000), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xc0000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R10G10B10A2_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + /* + * 16-bit rendertarget formats + */ + + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x03e0), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7c00), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00f0), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0f00), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B4G4R4A4_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x001f), {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x07e0), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xf800), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, + + /* + * Luminance/intensity/alpha formats + */ + + {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_L8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {0.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_I8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x00ff), {1.0, 1.0, 1.0, 0.0}}, + {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xff00), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_L8A8_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_L16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 1.0, 1.0, 1.0}}, + + /* + * TODO: SRGB formats + */ + + /* + * Mixed-signed formats + */ + + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x81, 0x00, 0x00, 0x00), {-1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x00, 0x81, 0x00, 0x00), { 0.0, -1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8SG8SB8UX8U_NORM, PACKED_4x8(0xff, 0xff, 0xff, 0x00), PACKED_4x8(0x00, 0x00, 0xff, 0x00), { 0.0, 0.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x000f), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0011), {-1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x01e0), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0x0220), { 0.0, -1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R5SG5SB6U_NORM, PACKED_1x16(0xffff), PACKED_1x16(0xfc00), { 0.0, 0.0, 1.0, 1.0}}, + + /* + * TODO: Depth-stencil formats + */ + + /* + * TODO: YUV formats + */ + + /* + * TODO: Compressed formats + */ + + /* + * Standard 8-bit integer formats + */ + + {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8_UNORM, PACKED_1x8(0xff), PACKED_1x8(0xff), {1.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_UNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), {1.0, 1.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_UNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8A8_UNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8_USCALED, PACKED_1x8(0xff), PACKED_1x8(0xff), {255.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0x00), {255.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0xff), { 0.0, 255.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_USCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0xff, 0xff), {255.0, 255.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0x00, 0x00), {255.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0xff, 0x00), { 0.0, 255.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0xff), { 0.0, 0.0, 255.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_USCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0xff, 0xff, 0xff), {255.0, 255.0, 255.0, 1.0}}, + + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0x00, 0x00, 0x00), {255.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0xff, 0x00, 0x00), { 0.0, 255.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0xff, 0x00), { 0.0, 0.0, 255.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0xff), { 0.0, 0.0, 0.0, 255.0}}, + {PIPE_FORMAT_R8G8B8A8_USCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0xff, 0xff, 0xff, 0xff), {255.0, 255.0, 255.0, 255.0}}, + + {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x7f), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8_SNORM, PACKED_1x8(0xff), PACKED_1x8(0x81), {-1.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x81, 0x00), {-1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_SNORM, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x81), { 0.0, -1.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x81, 0x00, 0x00), {-1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x81, 0x00), { 0.0, -1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), { 0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SNORM, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x81), { 0.0, 0.0, -1.0, 1.0}}, + + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x81, 0x00, 0x00, 0x00), {-1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x81, 0x00, 0x00), { 0.0, -1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), { 0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x81, 0x00), { 0.0, 0.0, -1.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8A8_SNORM, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x81), { 0.0, 0.0, 0.0, -1.0}}, + + {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x7f), { 127.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8_SSCALED, PACKED_1x8(0xff), PACKED_1x8(0x80), {-128.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x7f, 0x00), { 127.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x80, 0x00), {-128.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x7f), { 0.0, 127.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8_SSCALED, PACKED_2x8(0xff, 0xff), PACKED_2x8(0x00, 0x80), { 0.0, -128.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x7f, 0x00, 0x00), { 127.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x80, 0x00, 0x00), {-128.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x7f, 0x00), { 0.0, 127.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x80, 0x00), { 0.0, -128.0, 0.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x7f), { 0.0, 0.0, 127.0, 1.0}}, + {PIPE_FORMAT_R8G8B8_SSCALED, PACKED_3x8(0xff, 0xff, 0xff), PACKED_3x8(0x00, 0x00, 0x80), { 0.0, 0.0, -128.0, 1.0}}, + + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x00), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x7f, 0x00, 0x00, 0x00), { 127.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x80, 0x00, 0x00, 0x00), {-128.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x7f, 0x00, 0x00), { 0.0, 127.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x80, 0x00, 0x00), { 0.0, -128.0, 0.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x7f, 0x00), { 0.0, 0.0, 127.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x80, 0x00), { 0.0, 0.0, -128.0, 0.0}}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x7f), { 0.0, 0.0, 0.0, 127.0}}, + {PIPE_FORMAT_R8G8B8A8_SSCALED, PACKED_4x8(0xff, 0xff, 0xff, 0xff), PACKED_4x8(0x00, 0x00, 0x00, 0x80), { 0.0, 0.0, 0.0, -128.0}}, + + /* + * Standard 16-bit integer formats + */ + + {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16_UNORM, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {1.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_UNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), {1.0, 1.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_UNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16A16_UNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16_USCALED, PACKED_1x16(0xffff), PACKED_1x16(0xffff), {65535.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0x0000), {65535.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0xffff), { 0.0, 65535.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_USCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0xffff, 0xffff), {65535.0, 65535.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0x0000, 0x0000), {65535.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0xffff, 0x0000), { 0.0, 65535.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0xffff), { 0.0, 0.0, 65535.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_USCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0xffff, 0xffff, 0xffff), {65535.0, 65535.0, 65535.0, 1.0}}, + + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0x0000, 0x0000, 0x0000), {65535.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0xffff, 0x0000, 0x0000), { 0.0, 65535.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0xffff, 0x0000), { 0.0, 0.0, 65535.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0xffff), { 0.0, 0.0, 0.0, 65535.0}}, + {PIPE_FORMAT_R16G16B16A16_USCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), {65535.0, 65535.0, 65535.0, 65535.0}}, + + {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16_SNORM, PACKED_1x16(0xffff), PACKED_1x16(0x8001), { -1.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8001, 0x0000), { -1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_SNORM, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8001), { 0.0, -1.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8001, 0x0000, 0x0000), { -1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8001, 0x0000), { 0.0, -1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SNORM, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8001), { 0.0, 0.0, -1.0, 1.0}}, + + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), { 1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8001, 0x0000, 0x0000, 0x0000), { -1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), { 0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8001, 0x0000, 0x0000), { 0.0, -1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), { 0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8001, 0x0000), { 0.0, 0.0, -1.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16A16_SNORM, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8001), { 0.0, 0.0, 0.0, -1.0}}, + + {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x7fff), { 32767.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16_SSCALED, PACKED_1x16(0xffff), PACKED_1x16(0x8000), {-32768.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x7fff, 0x0000), { 32767.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x8000, 0x0000), {-32768.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x7fff), { 0.0, 32767.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16_SSCALED, PACKED_2x16(0xffff, 0xffff), PACKED_2x16(0x0000, 0x8000), { 0.0, -32768.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x7fff, 0x0000, 0x0000), { 32767.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x8000, 0x0000, 0x0000), {-32768.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x7fff, 0x0000), { 0.0, 32767.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x8000, 0x0000), { 0.0, -32768.0, 0.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 32767.0, 1.0}}, + {PIPE_FORMAT_R16G16B16_SSCALED, PACKED_3x16(0xffff, 0xffff, 0xffff), PACKED_3x16(0x0000, 0x0000, 0x8000), { 0.0, 0.0, -32768.0, 1.0}}, + + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x0000), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x7fff, 0x0000, 0x0000, 0x0000), { 32767.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x8000, 0x0000, 0x0000, 0x0000), {-32768.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x7fff, 0x0000, 0x0000), { 0.0, 32767.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x8000, 0x0000, 0x0000), { 0.0, -32768.0, 0.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x7fff, 0x0000), { 0.0, 0.0, 32767.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x8000, 0x0000), { 0.0, 0.0, -32768.0, 0.0}}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x7fff), { 0.0, 0.0, 0.0, 32767.0}}, + {PIPE_FORMAT_R16G16B16A16_SSCALED, PACKED_4x16(0xffff, 0xffff, 0xffff, 0xffff), PACKED_4x16(0x0000, 0x0000, 0x0000, 0x8000), { 0.0, 0.0, 0.0, -32768.0}}, + + /* + * Standard 32-bit integer formats + * + * NOTE: We can't accurately represent integers larger than +/-0x1000000 + * with single precision floats, so that's as far as we test. + */ + + {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32_UNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0xffffffff), {1.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0x00000000), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xffffffff), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_UNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xffffffff, 0xffffffff), {1.0, 1.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0x00000000, 0x00000000), {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xffffffff, 0x00000000), {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xffffffff), {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_UNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0x00000000, 0x00000000, 0x00000000), {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xffffffff, 0x00000000, 0x00000000), {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xffffffff, 0x00000000), {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xffffffff), {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32A32_UNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32_USCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), {16777216.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), {16777216.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), { 0.0, 16777216.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_USCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x01000000), {16777216.0, 16777216.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), {16777216.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), { 0.0, 16777216.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 16777216.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_USCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x01000000, 0x01000000), {16777216.0, 16777216.0, 16777216.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), {16777216.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), { 0.0, 16777216.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), { 0.0, 0.0, 16777216.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 0.0, 16777216.0}}, + {PIPE_FORMAT_R32G32B32A32_USCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x01000000, 0x01000000, 0x01000000), {16777216.0, 16777216.0, 16777216.0, 16777216.0}}, + + {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x7fffffff), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32_SNORM, PACKED_1x32(0xffffffff), PACKED_1x32(0x80000001), { -1.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x7fffffff, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x80000001, 0x00000000), { -1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x7fffffff), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_SNORM, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x80000001), { 0.0, -1.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x7fffffff, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x80000001, 0x00000000, 0x00000000), { -1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x7fffffff, 0x00000000), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x80000001, 0x00000000), { 0.0, -1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x7fffffff), { 0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SNORM, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x80000001), { 0.0, 0.0, -1.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x7fffffff, 0x00000000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x80000001, 0x00000000, 0x00000000, 0x00000000), { -1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x7fffffff, 0x00000000, 0x00000000), { 0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x80000001, 0x00000000, 0x00000000), { 0.0, -1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x7fffffff, 0x00000000), { 0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x80000001, 0x00000000), { 0.0, 0.0, -1.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x7fffffff), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32A32_SNORM, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x80000001), { 0.0, 0.0, 0.0, -1.0}}, + + {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0x01000000), { 16777216.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32_SSCALED, PACKED_1x32(0xffffffff), PACKED_1x32(0xff000000), {-16777216.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x01000000, 0x00000000), { 16777216.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xff000000, 0x00000000), {-16777216.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x01000000), { 0.0, 16777216.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_SSCALED, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xff000000), { 0.0, -16777216.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x01000000, 0x00000000, 0x00000000), { 16777216.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xff000000, 0x00000000, 0x00000000), {-16777216.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x01000000, 0x00000000), { 0.0, 16777216.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xff000000, 0x00000000), { 0.0, -16777216.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 16777216.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_SSCALED, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xff000000), { 0.0, 0.0, -16777216.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x01000000, 0x00000000, 0x00000000, 0x00000000), { 16777216.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xff000000, 0x00000000, 0x00000000, 0x00000000), {-16777216.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x01000000, 0x00000000, 0x00000000), { 0.0, 16777216.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xff000000, 0x00000000, 0x00000000), { 0.0, -16777216.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x01000000, 0x00000000), { 0.0, 0.0, 16777216.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xff000000, 0x00000000), { 0.0, 0.0, -16777216.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x01000000), { 0.0, 0.0, 0.0, 16777216.0}}, + {PIPE_FORMAT_R32G32B32A32_SSCALED, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xff000000), { 0.0, 0.0, 0.0, -16777216.0}}, + + /* + * Standard 32-bit float formats + */ + + {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0x3f800000), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32_FLOAT, PACKED_1x32(0xffffffff), PACKED_1x32(0xbf800000), { -1.0, 0.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0xbf800000, 0x00000000), {-1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0x3f800000), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x00000000, 0xbf800000), { 0.0, -1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32_FLOAT, PACKED_2x32(0xffffffff, 0xffffffff), PACKED_2x32(0x3f800000, 0x3f800000), { 1.0, 1.0, 0.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0xbf800000, 0x00000000, 0x00000000), {-1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x3f800000, 0x00000000), { 0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0xbf800000, 0x00000000), { 0.0, -1.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0x3f800000), { 0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x00000000, 0x00000000, 0xbf800000), { 0.0, 0.0, -1.0, 1.0}}, + {PIPE_FORMAT_R32G32B32_FLOAT, PACKED_3x32(0xffffffff, 0xffffffff, 0xffffffff), PACKED_3x32(0x3f800000, 0x3f800000, 0x3f800000), { 1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x00000000), { 0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x00000000, 0x00000000, 0x00000000), { 1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0xbf800000, 0x00000000, 0x00000000, 0x00000000), {-1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x3f800000, 0x00000000, 0x00000000), { 0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0xbf800000, 0x00000000, 0x00000000), { 0.0, -1.0, 0.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x3f800000, 0x00000000), { 0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0xbf800000, 0x00000000), { 0.0, 0.0, -1.0, 0.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0x3f800000), { 0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x00000000, 0x00000000, 0x00000000, 0xbf800000), { 0.0, 0.0, 0.0, -1.0}}, + {PIPE_FORMAT_R32G32B32A32_FLOAT, PACKED_4x32(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff), PACKED_4x32(0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000), { 1.0, 1.0, 1.0, 1.0}}, +}; + + +const unsigned util_format_nr_test_cases = Elements(util_format_test_cases); diff --git a/src/gallium/auxiliary/util/u_format_tests.h b/src/gallium/auxiliary/util/u_format_tests.h new file mode 100644 index 00000000000..2d4d9d5fa9d --- /dev/null +++ b/src/gallium/auxiliary/util/u_format_tests.h @@ -0,0 +1,69 @@ +/************************************************************************** + * + * 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. + * + **************************************************************************/ + + +#ifndef U_FORMAT_TESTS_H_ +#define U_FORMAT_TESTS_H_ + + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" + + +#define UTIL_FORMAT_MAX_PACKED_BYTES 16 + + +/** + * A (packed, unpacked) color pair. + */ +struct util_format_test_case +{ + enum pipe_format format; + + /** + * Mask of the bits that actually meaningful data. Used to mask out the + * "X" channels. + */ + uint8_t mask[UTIL_FORMAT_MAX_PACKED_BYTES]; + + uint8_t packed[UTIL_FORMAT_MAX_PACKED_BYTES]; + + /** + * RGBA. + */ + double unpacked[4]; +}; + + +extern const struct util_format_test_case +util_format_test_cases[]; + + +extern const unsigned util_format_nr_test_cases; + + +#endif /* U_FORMAT_TESTS_H_ */ diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index db726df9c3b..d421bee8efe 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -61,6 +61,7 @@ struct gen_mipmap_state struct pipe_depth_stencil_alpha_state depthstencil; struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; + struct pipe_clip_state clip; struct pipe_vertex_element velem[2]; void *vs; @@ -923,29 +924,29 @@ format_to_type_comps(enum pipe_format pformat, { /* XXX I think this could be implemented in terms of the pf_*() functions */ switch (pformat) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: case PIPE_FORMAT_B8G8R8A8_UNORM: case PIPE_FORMAT_B8G8R8X8_UNORM: - case PIPE_FORMAT_R8G8B8A8_SRGB: - case PIPE_FORMAT_R8G8B8X8_SRGB: - case PIPE_FORMAT_A8R8G8B8_SRGB: - case PIPE_FORMAT_X8R8G8B8_SRGB: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_A8B8G8R8_SRGB: + case PIPE_FORMAT_X8B8G8R8_SRGB: case PIPE_FORMAT_B8G8R8A8_SRGB: case PIPE_FORMAT_B8G8R8X8_SRGB: + case PIPE_FORMAT_A8R8G8B8_SRGB: + case PIPE_FORMAT_X8R8G8B8_SRGB: case PIPE_FORMAT_R8G8B8_SRGB: *datatype = DTYPE_UBYTE; *comps = 4; return; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: *datatype = DTYPE_USHORT_1_5_5_5_REV; *comps = 4; return; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: *datatype = DTYPE_USHORT_4_4_4_4; *comps = 4; return; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: *datatype = DTYPE_USHORT_5_6_5; *comps = 3; return; @@ -956,8 +957,8 @@ format_to_type_comps(enum pipe_format pformat, *datatype = DTYPE_UBYTE; *comps = 1; return; - case PIPE_FORMAT_A8L8_UNORM: - case PIPE_FORMAT_A8L8_SRGB: + case PIPE_FORMAT_L8A8_UNORM: + case PIPE_FORMAT_L8A8_SRGB: *datatype = DTYPE_UBYTE; *comps = 2; return; @@ -1070,7 +1071,7 @@ reduce_3d(enum pipe_format pformat, */ /* - _mesa_printf("mip3d %d x %d x %d -> %d x %d x %d\n", + printf("mip3d %d x %d x %d -> %d x %d x %d\n", srcWidth, srcHeight, srcDepth, dstWidth, dstHeight, dstDepth); */ @@ -1297,7 +1298,6 @@ util_create_gen_mipmap(struct pipe_context *pipe, memset(&ctx->rasterizer, 0, sizeof(ctx->rasterizer)); ctx->rasterizer.front_winding = PIPE_WINDING_CW; ctx->rasterizer.cull_mode = PIPE_WINDING_NONE; - ctx->rasterizer.bypass_vs_clip_and_viewport = 1; ctx->rasterizer.gl_rasterization_rules = 1; /* sampler state */ @@ -1371,25 +1371,25 @@ get_next_slot(struct gen_mipmap_state *ctx) static unsigned set_vertex_data(struct gen_mipmap_state *ctx, enum pipe_texture_target tex_target, - uint face, float width, float height) + uint face) { unsigned offset; /* vert[0].position */ - ctx->vertices[0][0][0] = 0.0f; /*x*/ - ctx->vertices[0][0][1] = 0.0f; /*y*/ + ctx->vertices[0][0][0] = -1.0f; /*x*/ + ctx->vertices[0][0][1] = -1.0f; /*y*/ /* vert[1].position */ - ctx->vertices[1][0][0] = width; - ctx->vertices[1][0][1] = 0.0f; + ctx->vertices[1][0][0] = 1.0f; + ctx->vertices[1][0][1] = -1.0f; /* vert[2].position */ - ctx->vertices[2][0][0] = width; - ctx->vertices[2][0][1] = height; + ctx->vertices[2][0][0] = 1.0f; + ctx->vertices[2][0][1] = 1.0f; /* vert[3].position */ - ctx->vertices[3][0][0] = 0.0f; - ctx->vertices[3][0][1] = height; + ctx->vertices[3][0][0] = -1.0f; + ctx->vertices[3][0][1] = 1.0f; /* Setup vertex texcoords. This is a little tricky for cube maps. */ if (tex_target == PIPE_TEXTURE_CUBE) { @@ -1509,12 +1509,15 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_save_framebuffer(ctx->cso); cso_save_fragment_shader(ctx->cso); cso_save_vertex_shader(ctx->cso); + cso_save_viewport(ctx->cso); + cso_save_clip(ctx->cso); cso_save_vertex_elements(ctx->cso); /* bind our state */ cso_set_blend(ctx->cso, &ctx->blend); cso_set_depth_stencil_alpha(ctx->cso, &ctx->depthstencil); cso_set_rasterizer(ctx->cso, &ctx->rasterizer); + cso_set_clip(ctx->cso, &ctx->clip); cso_set_vertex_elements(ctx->cso, 2, ctx->velem); cso_set_fragment_shader_handle(ctx->cso, fs); @@ -1534,6 +1537,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, */ for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) { const uint srcLevel = dstLevel - 1; + struct pipe_viewport_state vp; struct pipe_surface *surf = screen->get_tex_surface(screen, pt, face, dstLevel, zslice, @@ -1547,6 +1551,17 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, fb.height = u_minify(pt->height0, dstLevel); cso_set_framebuffer(ctx->cso, &fb); + /* viewport */ + vp.scale[0] = 0.5f * fb.width; + vp.scale[1] = 0.5f * fb.height; + vp.scale[2] = 1.0f; + vp.scale[3] = 1.0f; + vp.translate[0] = 0.5f * fb.width; + vp.translate[1] = 0.5f * fb.height; + vp.translate[2] = 0.0f; + vp.translate[3] = 0.0f; + cso_set_viewport(ctx->cso, &vp); + /* * Setup sampler state * Note: we should only have to set the min/max LOD clamps to ensure @@ -1561,12 +1576,10 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_set_sampler_textures(ctx->cso, 1, &pt); - /* quad coords in window coords (bypassing vs, clip and viewport) */ + /* quad coords in clip coords */ offset = set_vertex_data(ctx, pt->target, - face, - (float) u_minify(pt->width0, dstLevel), - (float) u_minify(pt->height0, dstLevel)); + face); util_draw_vertex_buffer(ctx->pipe, ctx->vbuf, @@ -1590,5 +1603,7 @@ util_gen_mipmap(struct gen_mipmap_state *ctx, cso_restore_framebuffer(ctx->cso); cso_restore_fragment_shader(ctx->cso); cso_restore_vertex_shader(ctx->cso); + cso_restore_viewport(ctx->cso); + cso_restore_clip(ctx->cso); cso_restore_vertex_elements(ctx->cso); } diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index e95d58ea863..0cb3432c6e4 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -90,7 +90,10 @@ pipe_reference(struct pipe_reference *ptr, struct pipe_reference *reference) static INLINE void pipe_buffer_reference(struct pipe_buffer **ptr, struct pipe_buffer *buf) { - struct pipe_buffer *old_buf = *ptr; + struct pipe_buffer *old_buf; + + assert(ptr); + old_buf = *ptr; if (pipe_reference(&(*ptr)->reference, &buf->reference)) old_buf->screen->buffer_destroy(old_buf); diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index b2969a210a7..d1ec13def30 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -532,6 +532,17 @@ util_bswap32(uint32_t n) /** + * Reverse byte order of a 16 bit word. + */ +static INLINE uint16_t +util_bswap16(uint16_t n) +{ + return (n >> 8) | + (n << 8); +} + + +/** * Clamp X to [MIN, MAX]. * This is a macro to allow float, int, uint, etc. types. */ diff --git a/src/gallium/auxiliary/util/u_pack_color.h b/src/gallium/auxiliary/util/u_pack_color.h index 0ab53c75dd6..50f1b1670b6 100644 --- a/src/gallium/auxiliary/util/u_pack_color.h +++ b/src/gallium/auxiliary/util/u_pack_color.h @@ -57,47 +57,47 @@ util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a, enum pipe_format format, union util_color *uc) { switch (format) { - case PIPE_FORMAT_R8G8B8A8_UNORM: + case PIPE_FORMAT_A8B8G8R8_UNORM: { uc->ui = (r << 24) | (g << 16) | (b << 8) | a; } return; - case PIPE_FORMAT_R8G8B8X8_UNORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: { uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff; } return; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: { uc->ui = (a << 24) | (r << 16) | (g << 8) | b; } return; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: { uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b; } return; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: { uc->ui = (b << 24) | (g << 16) | (r << 8) | a; } return; - case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: { uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff; } return; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: { uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); } return; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: { uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); } return; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: { uc->us = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) << 0) | (b >> 4); } @@ -153,7 +153,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, ubyte *r, ubyte *g, ubyte *b, ubyte *a) { switch (format) { - case PIPE_FORMAT_R8G8B8A8_UNORM: + case PIPE_FORMAT_A8B8G8R8_UNORM: { uint p = uc->ui; *r = (ubyte) ((p >> 24) & 0xff); @@ -162,7 +162,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) ((p >> 0) & 0xff); } return; - case PIPE_FORMAT_R8G8B8X8_UNORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: { uint p = uc->ui; *r = (ubyte) ((p >> 24) & 0xff); @@ -171,7 +171,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) 0xff; } return; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: { uint p = uc->ui; *r = (ubyte) ((p >> 16) & 0xff); @@ -180,7 +180,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) ((p >> 24) & 0xff); } return; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: { uint p = uc->ui; *r = (ubyte) ((p >> 16) & 0xff); @@ -189,7 +189,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) 0xff; } return; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: { uint p = uc->ui; *r = (ubyte) ((p >> 8) & 0xff); @@ -198,7 +198,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) ((p >> 0) & 0xff); } return; - case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: { uint p = uc->ui; *r = (ubyte) ((p >> 8) & 0xff); @@ -207,7 +207,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) 0xff; } return; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: { ushort p = uc->us; *r = (ubyte) (((p >> 8) & 0xf8) | ((p >> 13) & 0x7)); @@ -216,7 +216,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) 0xff; } return; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: { ushort p = uc->us; *r = (ubyte) (((p >> 7) & 0xf8) | ((p >> 12) & 0x7)); @@ -225,7 +225,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc, *a = (ubyte) (0xff * (p >> 15)); } return; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: { ushort p = uc->us; *r = (ubyte) (((p >> 4) & 0xf0) | ((p >> 8) & 0xf)); @@ -326,47 +326,47 @@ util_pack_color(const float rgba[4], enum pipe_format format, union util_color * } switch (format) { - case PIPE_FORMAT_R8G8B8A8_UNORM: + case PIPE_FORMAT_A8B8G8R8_UNORM: { uc->ui = (r << 24) | (g << 16) | (b << 8) | a; } return; - case PIPE_FORMAT_R8G8B8X8_UNORM: + case PIPE_FORMAT_X8B8G8R8_UNORM: { uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff; } return; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: { uc->ui = (a << 24) | (r << 16) | (g << 8) | b; } return; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: { uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b; } return; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: { uc->ui = (b << 24) | (g << 16) | (r << 8) | a; } return; - case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_X8R8G8B8_UNORM: { uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff; } return; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: { uc->us = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3); } return; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: { uc->us = ((a & 0x80) << 8) | ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | (b >> 3); } return; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: { uc->ub = ((a & 0xf0) << 8) | ((r & 0xf0) << 4) | ((g & 0xf0) << 0) | (b >> 4); } @@ -427,13 +427,13 @@ util_pack_z(enum pipe_format format, double z) return (uint) (z * 0xffffffff); case PIPE_FORMAT_Z32_FLOAT: return (uint)z; - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: if (z == 1.0) return 0xffffff; return (uint) (z * 0xffffff); - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: if (z == 1.0) return 0xffffff00; return ((uint) (z * 0xffffff)) << 8; @@ -458,10 +458,10 @@ util_pack_z_stencil(enum pipe_format format, double z, uint s) unsigned packed = util_pack_z(format, z); switch (format) { - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: packed |= s << 24; break; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: packed |= s; break; case PIPE_FORMAT_S8_UNORM: diff --git a/src/gallium/auxiliary/util/u_simple_screen.c b/src/gallium/auxiliary/util/u_simple_screen.c index 53f3c16dbcc..9203cb6580c 100644 --- a/src/gallium/auxiliary/util/u_simple_screen.c +++ b/src/gallium/auxiliary/util/u_simple_screen.c @@ -59,22 +59,7 @@ pass_user_buffer_create(struct pipe_screen *screen, return buffer; } -static struct pipe_buffer * -pass_surface_buffer_create(struct pipe_screen *screen, - unsigned width, unsigned height, - enum pipe_format format, - unsigned usage, - unsigned tex_usage, - unsigned *stride) -{ - struct pipe_buffer *buffer = - screen->winsys->surface_buffer_create(screen->winsys, width, height, - format, usage, tex_usage, stride); - buffer->screen = screen; - - return buffer; -} static void * pass_buffer_map(struct pipe_screen *screen, @@ -135,7 +120,6 @@ u_simple_screen_init(struct pipe_screen *screen) { screen->buffer_create = pass_buffer_create; screen->user_buffer_create = pass_user_buffer_create; - screen->surface_buffer_create = pass_surface_buffer_create; screen->buffer_map = pass_buffer_map; screen->buffer_unmap = pass_buffer_unmap; diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index c9f1c9c210f..33306bbc2a6 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -54,9 +54,9 @@ util_create_rgba_surface(struct pipe_screen *screen, struct pipe_surface **surfaceOut) { static const enum pipe_format rgbaFormats[] = { - PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_R8G8B8A8_UNORM, + PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_A8B8G8R8_UNORM, PIPE_FORMAT_NONE }; const uint target = PIPE_TEXTURE_2D; diff --git a/src/gallium/auxiliary/util/u_tile.c b/src/gallium/auxiliary/util/u_tile.c index 0051258e22a..79481b710bf 100644 --- a/src/gallium/auxiliary/util/u_tile.c +++ b/src/gallium/auxiliary/util/u_tile.c @@ -108,7 +108,7 @@ pipe_put_tile_raw(struct pipe_transfer *pt, -/*** PIPE_FORMAT_A8R8G8B8_UNORM ***/ +/*** PIPE_FORMAT_B8G8R8A8_UNORM ***/ static void a8r8g8b8_get_tile_rgba(const unsigned *src, @@ -155,7 +155,7 @@ a8r8g8b8_put_tile_rgba(unsigned *dst, } -/*** PIPE_FORMAT_X8R8G8B8_UNORM ***/ +/*** PIPE_FORMAT_B8G8R8X8_UNORM ***/ static void x8r8g8b8_get_tile_rgba(const unsigned *src, @@ -201,7 +201,7 @@ x8r8g8b8_put_tile_rgba(unsigned *dst, } -/*** PIPE_FORMAT_B8G8R8A8_UNORM ***/ +/*** PIPE_FORMAT_A8R8G8B8_UNORM ***/ static void b8g8r8a8_get_tile_rgba(const unsigned *src, @@ -248,7 +248,7 @@ b8g8r8a8_put_tile_rgba(unsigned *dst, } -/*** PIPE_FORMAT_R8G8B8A8_UNORM ***/ +/*** PIPE_FORMAT_A8B8G8R8_UNORM ***/ static void r8g8b8a8_get_tile_rgba(const unsigned *src, @@ -295,7 +295,7 @@ r8g8b8a8_put_tile_rgba(unsigned *dst, } -/*** PIPE_FORMAT_A1R5G5B5_UNORM ***/ +/*** PIPE_FORMAT_B5G5R5A1_UNORM ***/ static void a1r5g5b5_get_tile_rgba(const ushort *src, @@ -346,7 +346,7 @@ a1r5g5b5_put_tile_rgba(ushort *dst, } -/*** PIPE_FORMAT_A4R4G4B4_UNORM ***/ +/*** PIPE_FORMAT_B4G4R4A4_UNORM ***/ static void a4r4g4b4_get_tile_rgba(const ushort *src, @@ -397,7 +397,7 @@ a4r4g4b4_put_tile_rgba(ushort *dst, } -/*** PIPE_FORMAT_R5G6B5_UNORM ***/ +/*** PIPE_FORMAT_B5G6R5_UNORM ***/ static void r5g6b5_get_tile_rgba(const ushort *src, @@ -691,7 +691,7 @@ r16g16b16a16_put_tile_rgba(short *dst, } -/*** PIPE_FORMAT_R8G8B8A8_SRGB ***/ +/*** PIPE_FORMAT_A8B8G8R8_SRGB ***/ /** * Convert an 8-bit sRGB value from non-linear space to a @@ -784,7 +784,7 @@ a8r8g8b8_srgb_put_tile_rgba(unsigned *dst, } -/*** PIPE_FORMAT_A8L8_SRGB ***/ +/*** PIPE_FORMAT_L8A8_SRGB ***/ static void a8l8_srgb_get_tile_rgba(const ushort *src, @@ -913,7 +913,7 @@ i8_put_tile_rgba(ubyte *dst, } -/*** PIPE_FORMAT_A8L8_UNORM ***/ +/*** PIPE_FORMAT_L8A8_UNORM ***/ static void a8l8_get_tile_rgba(const ushort *src, @@ -987,7 +987,7 @@ z32_get_tile_rgba(const unsigned *src, } -/*** PIPE_FORMAT_S8Z24_UNORM ***/ +/*** PIPE_FORMAT_Z24S8_UNORM ***/ /** * Return Z component as four float in [0,1]. Stencil part ignored. @@ -1014,7 +1014,7 @@ s8z24_get_tile_rgba(const unsigned *src, } -/*** PIPE_FORMAT_Z24S8_UNORM ***/ +/*** PIPE_FORMAT_S8Z24_UNORM ***/ /** * Return Z component as four float in [0,1]. Stencil part ignored. @@ -1067,7 +1067,7 @@ z32f_get_tile_rgba(const float *src, } -/*** PIPE_FORMAT_YCBCR / PIPE_FORMAT_YCBCR_REV ***/ +/*** PIPE_FORMAT_UYVY / PIPE_FORMAT_YUYV ***/ /** * Convert YCbCr (or YCrCb) to RGBA. @@ -1162,25 +1162,25 @@ pipe_tile_raw_to_rgba(enum pipe_format format, float *dst, unsigned dst_stride) { switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: a8r8g8b8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: x8r8g8b8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: b8g8r8a8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_R8G8B8A8_UNORM: + case PIPE_FORMAT_A8B8G8R8_UNORM: r8g8b8a8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: a1r5g5b5_get_tile_rgba((ushort *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: a4r4g4b4_get_tile_rgba((ushort *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: r5g6b5_get_tile_rgba((ushort *) src, w, h, dst, dst_stride); break; case PIPE_FORMAT_R8G8B8_UNORM: @@ -1195,7 +1195,7 @@ pipe_tile_raw_to_rgba(enum pipe_format format, case PIPE_FORMAT_I8_UNORM: i8_get_tile_rgba((ubyte *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: a8l8_get_tile_rgba((ushort *) src, w, h, dst, dst_stride); break; case PIPE_FORMAT_R16_SNORM: @@ -1204,10 +1204,10 @@ pipe_tile_raw_to_rgba(enum pipe_format format, case PIPE_FORMAT_R16G16B16A16_SNORM: r16g16b16a16_get_tile_rgba((short *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_A8R8G8B8_SRGB: + case PIPE_FORMAT_B8G8R8A8_SRGB: a8r8g8b8_srgb_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_A8L8_SRGB: + case PIPE_FORMAT_L8A8_SRGB: a8l8_srgb_get_tile_rgba((ushort *) src, w, h, dst, dst_stride); break; case PIPE_FORMAT_L8_SRGB: @@ -1219,21 +1219,21 @@ pipe_tile_raw_to_rgba(enum pipe_format format, case PIPE_FORMAT_Z32_UNORM: z32_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: - s8z24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); - break; case PIPE_FORMAT_Z24S8_UNORM: case PIPE_FORMAT_Z24X8_UNORM: + s8z24_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); + break; + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: z24s8_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride); break; case PIPE_FORMAT_Z32_FLOAT: z32f_get_tile_rgba((float *) src, w, h, dst, dst_stride); break; - case PIPE_FORMAT_YCBCR: + case PIPE_FORMAT_UYVY: ycbcr_get_tile_rgba((ushort *) src, w, h, dst, dst_stride, FALSE); break; - case PIPE_FORMAT_YCBCR_REV: + case PIPE_FORMAT_YUYV: ycbcr_get_tile_rgba((ushort *) src, w, h, dst, dst_stride, TRUE); break; default: @@ -1262,7 +1262,7 @@ pipe_get_tile_rgba(struct pipe_transfer *pt, if (!packed) return; - if(format == PIPE_FORMAT_YCBCR || format == PIPE_FORMAT_YCBCR_REV) + if(format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) assert((x & 1) == 0); pipe_get_tile_raw(pt, x, y, w, h, packed, 0); @@ -1291,28 +1291,28 @@ pipe_put_tile_rgba(struct pipe_transfer *pt, return; switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: a8r8g8b8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: x8r8g8b8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: b8g8r8a8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_R8G8B8A8_UNORM: + case PIPE_FORMAT_A8B8G8R8_UNORM: r8g8b8a8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: a1r5g5b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: r5g6b5_put_tile_rgba((ushort *) packed, w, h, p, src_stride); break; case PIPE_FORMAT_R8G8B8_UNORM: r8g8b8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: a4r4g4b4_put_tile_rgba((ushort *) packed, w, h, p, src_stride); break; case PIPE_FORMAT_L8_UNORM: @@ -1324,7 +1324,7 @@ pipe_put_tile_rgba(struct pipe_transfer *pt, case PIPE_FORMAT_I8_UNORM: i8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: a8l8_put_tile_rgba((ushort *) packed, w, h, p, src_stride); break; case PIPE_FORMAT_R16_SNORM: @@ -1333,10 +1333,10 @@ pipe_put_tile_rgba(struct pipe_transfer *pt, case PIPE_FORMAT_R16G16B16A16_SNORM: r16g16b16a16_put_tile_rgba((short *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_A8R8G8B8_SRGB: + case PIPE_FORMAT_B8G8R8A8_SRGB: a8r8g8b8_srgb_put_tile_rgba((unsigned *) packed, w, h, p, src_stride); break; - case PIPE_FORMAT_A8L8_SRGB: + case PIPE_FORMAT_L8A8_SRGB: a8l8_srgb_put_tile_rgba((ushort *) packed, w, h, p, src_stride); break; case PIPE_FORMAT_L8_SRGB: @@ -1348,12 +1348,12 @@ pipe_put_tile_rgba(struct pipe_transfer *pt, case PIPE_FORMAT_Z32_UNORM: /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ break; - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: - /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ - break; case PIPE_FORMAT_Z24S8_UNORM: case PIPE_FORMAT_Z24X8_UNORM: + /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ + break; + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: /*z24s8_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/ break; default: @@ -1405,8 +1405,8 @@ pipe_get_tile_z(struct pipe_transfer *pt, } } break; - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: { const uint *ptrc = (const uint *)(map + y * pt->stride + x*4); @@ -1420,8 +1420,8 @@ pipe_get_tile_z(struct pipe_transfer *pt, } } break; - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: { const uint *ptrc = (const uint *)(map + y * pt->stride + x*4); @@ -1489,7 +1489,7 @@ pipe_put_tile_z(struct pipe_transfer *pt, } } break; - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: { uint *pDest = (uint *) (map + y * pt->stride + x*4); assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE); @@ -1503,7 +1503,7 @@ pipe_put_tile_z(struct pipe_transfer *pt, } } break; - case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: { uint *pDest = (uint *) (map + y * pt->stride + x*4); for (i = 0; i < h; i++) { @@ -1516,7 +1516,7 @@ pipe_put_tile_z(struct pipe_transfer *pt, } } break; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: { uint *pDest = (uint *) (map + y * pt->stride + x*4); assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE); @@ -1530,7 +1530,7 @@ pipe_put_tile_z(struct pipe_transfer *pt, } } break; - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: { uint *pDest = (uint *) (map + y * pt->stride + x*4); for (i = 0; i < h; i++) { diff --git a/src/gallium/docs/source/cso/rasterizer.rst b/src/gallium/docs/source/cso/rasterizer.rst index 24cc78c68de..ccd9136a2eb 100644 --- a/src/gallium/docs/source/cso/rasterizer.rst +++ b/src/gallium/docs/source/cso/rasterizer.rst @@ -10,18 +10,6 @@ multisample state, scissoring and flat/smooth shading. Members ------- -bypass_vs_clip_and_viewport -^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Whether the entire TCL pipeline should be bypassed. This implies that -vertices are pre-transformed for the viewport, and will not be run -through the vertex shader. - -.. note:: - - Implementations may still clip away vertices that are not in the viewport - when this is set. - flatshade ^^^^^^^^^ diff --git a/src/gallium/docs/source/cso/sampler.rst b/src/gallium/docs/source/cso/sampler.rst index 77979fc44d1..9bbb784de8e 100644 --- a/src/gallium/docs/source/cso/sampler.rst +++ b/src/gallium/docs/source/cso/sampler.rst @@ -13,38 +13,97 @@ Members ------- wrap_s - How to wrap the S coordinate. One of PIPE_TEX_WRAP. + How to wrap the S coordinate. One of PIPE_TEX_WRAP_*. wrap_t - How to wrap the T coordinate. One of PIPE_TEX_WRAP. + How to wrap the T coordinate. One of PIPE_TEX_WRAP_*. wrap_r - How to wrap the R coordinate. One of PIPE_TEX_WRAP. + How to wrap the R coordinate. One of PIPE_TEX_WRAP_*. + +The wrap modes are: + +* ``PIPE_TEX_WRAP_REPEAT``: Standard coord repeat/wrap-around mode. +* ``PIPE_TEX_WRAP_CLAMP_TO_EDGE``: Clamp coord to edge of texture, the border + color is never sampled. +* ``PIPE_TEX_WRAP_CLAMP_TO_BORDER``: Clamp coord to border of texture, the + border color is sampled when coords go outside the range [0,1]. +* ``PIPE_TEX_WRAP_CLAMP``: The coord is clamped to the range [0,1] before + scaling to the texture size. This corresponds to the legacy OpenGL GL_CLAMP + texture wrap mode. Historically, this mode hasn't acted consistantly across + all graphics hardware. It sometimes acts like CLAMP_TO_EDGE or + CLAMP_TO_BORDER. The behaviour may also vary depending on linear vs. + nearest sampling mode. +* ``PIPE_TEX_WRAP_MIRROR_REPEAT``: If the integer part of the coordinate + is odd, the coord becomes (1 - coord). Then, normal texture REPEAT is + applied to the coord. +* ``PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE``: First, the absolute value of the + coordinate is computed. Then, regular CLAMP_TO_EDGE is applied to the coord. +* ``PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER``: First, the absolute value of the + coordinate is computed. Then, regular CLAMP_TO_BORDER is applied to the + coord. +* ``PIPE_TEX_WRAP_MIRROR_CLAMP``: First, the absolute value of the coord is + computed. Then, regular CLAMP is applied to the coord. + + min_img_filter - The filter to use when minifying texels. One of PIPE_TEX_FILTER. + The image filter to use when minifying texels. One of PIPE_TEX_FILTER_*. +mag_img_filter + The image filter to use when magnifying texels. One of PIPE_TEX_FILTER_*. + +The texture image filter modes are: + +* ``PIPE_TEX_FILTER_NEAREST``: One texel is fetched from the texture image + at the texture coordinate. +* ``PIPE_TEX_FILTER_LINEAR``: Two, four or eight texels (depending on the + texture dimensions; 1D/2D/3D) are fetched from the texture image and + linearly weighted and blended together. + min_mip_filter The filter to use when minifying mipmapped textures. One of - PIPE_TEX_FILTER. -mag_img_filter - The filter to use when magnifying texels. One of PIPE_TEX_FILTER. + PIPE_TEX_MIPFILTER_*. + +The texture mip filter modes are: + +* ``PIPE_TEX_MIPFILTER_NEAREST``: A single mipmap level/image is selected + according to the texture LOD (lambda) value. +* ``PIPE_TEX_MIPFILTER_LINEAR``: The two mipmap levels/images above/below + the texture LOD value are sampled from. The results of sampling from + those two images are blended together with linear interpolation. +* ``PIPE_TEX_MIPFILTER_NONE``: Mipmap filtering is disabled. All texels + are taken from the level 0 image. + + compare_mode - If set to PIPE_TEX_COMPARE_R_TO_TEXTURE, texture output is computed - according to compare_func, using r coord and the texture value as operands. + If set to PIPE_TEX_COMPARE_R_TO_TEXTURE, the result of texture sampling + is not a color but a true/false value which is the result of comparing the + sampled texture value (typically a Z value from a depth texture) to the + texture coordinate's R component. If set to PIPE_TEX_COMPARE_NONE, no comparison calculation is performed. compare_func - How the comparison is computed. One of PIPE_FUNC. + The inequality operator used when compare_mode=1. One of PIPE_FUNC_x. normalized_coords - Whether the texture coordinates are normalized. If normalized, they will - always be in [0, 1]. If not, they will be in the range of each dimension - of the loaded texture. + If set, the incoming texture coordinates (nominally in the range [0,1]) + will be scaled by the texture width, height, depth to compute texel + addresses. Otherwise, the texture coords are used as-is (they are not + scaled by the texture dimensions). + When normalized_coords=0, only a subset of the texture wrap modes are + allowed: PIPE_TEX_WRAP_CLAMP, PIPE_TEX_WRAP_CLAMP_TO_EDGE and + PIPE_TEX_WRAP_CLAMP_TO_BORDER. lod_bias - The bias to apply to the level of detail. + Bias factor which is added to the computed level of detail. + The normal level of detail is computed from the partial derivatives of + the texture coordinates and/or the fragment shader TEX/TXB/TXL + instruction. min_lod - Minimum level of detail, used to clamp LoD after bias. + Minimum level of detail, used to clamp LOD after bias. The LOD values + correspond to mipmap levels where LOD=0 is the level 0 mipmap image. max_lod - Maximum level of detail, used to clamp LoD after bias. + Maximum level of detail, used to clamp LOD after bias. border_color - RGBA color used for out-of-bounds coordinates. + RGBA color used for texel coordinates that are outside the [0,width-1], + [0, height-1] or [0, depth-1] ranges. max_anisotropy - Maximum filtering to apply anisotropically to textures. Setting this to - 0 disables anisotropic filtering. Any other setting enables anisotropic - filtering, however it's not unexpected some drivers only will change their - filtering with a setting of 2 and higher. + Maximum anistropy ratio to use when sampling from textures. For example, + if max_anistropy=4, a region of up to 1 by 4 texels will be sampled. + Set to zero to disable anisotropic filtering. Any other setting enables + anisotropic filtering, however it's not unexpected some drivers only will + change their filtering with a setting of 2 and higher. diff --git a/src/gallium/docs/source/screen.rst b/src/gallium/docs/source/screen.rst index 27f65522b69..e78634e59e9 100644 --- a/src/gallium/docs/source/screen.rst +++ b/src/gallium/docs/source/screen.rst @@ -147,16 +147,30 @@ These flags determine the possible roles a texture may be used for during its lifetime. Texture usage flags are cumulative and may be combined to create a texture that can be used as multiple things. -* ``RENDER_TARGET``: A colorbuffer or pixelbuffer. +* ``RENDER_TARGET``: A color buffer or pixel buffer which will be rendered to. * ``DISPLAY_TARGET``: A sharable buffer that can be given to another process. -* ``PRIMARY``: A frontbuffer or scanout buffer. -* ``DEPTH_STENCIL``: A depthbuffer, stencilbuffer, or Z buffer. Gallium does - not explicitly provide for stencil-only buffers, so any stencilbuffer - validated here is implicitly also a depthbuffer. +* ``PRIMARY``: A front color buffer or scanout buffer. +* ``DEPTH_STENCIL``: A depth (Z) buffer or stencil buffer. Gallium does + not explicitly provide for stencil-only buffers, so any stencil buffer + validated here is implicitly also a depth buffer. * ``SAMPLER``: A texture that may be sampled from in a fragment or vertex shader. * ``DYNAMIC``: A texture that will be mapped frequently. + +PIPE_TEXTURE_GEOM +^^^^^^^^^^^^^^^^^ + +These flags are used when querying whether a particular pipe_format is +supported by the driver (with the `is_format_supported` function). +Some formats may only be supported for certain kinds of textures. +For example, a compressed format might only be used for POT textures. + +* ``PIPE_TEXTURE_GEOM_NON_SQUARE``: The texture may not be square +* ``PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO``: The texture dimensions may not be + powers of two. + + Methods ------- diff --git a/src/gallium/drivers/cell/ppu/cell_gen_fragment.c b/src/gallium/drivers/cell/ppu/cell_gen_fragment.c index 70683bb3676..576d514741d 100644 --- a/src/gallium/drivers/cell/ppu/cell_gen_fragment.c +++ b/src/gallium/drivers/cell/ppu/cell_gen_fragment.c @@ -304,7 +304,7 @@ unpack_colors(struct spe_function *f, spe_comment(f, 0, "Unpack framebuffer colors, convert to floats"); switch (color_format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: /* fbB = fbRGBA & mask */ spe_and(f, fbB_reg, fbRGBA_reg, mask0_reg); @@ -327,7 +327,7 @@ unpack_colors(struct spe_function *f, spe_roti(f, fbA_reg, fbA_reg, -24); break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: /* fbA = fbRGBA & mask */ spe_and(f, fbA_reg, fbRGBA_reg, mask0_reg); @@ -1043,12 +1043,12 @@ gen_pack_colors(struct spe_function *f, spe_rotmi(f, a_reg, a_reg, -24); /* Shift the color bytes according to the surface format */ - if (color_format == PIPE_FORMAT_A8R8G8B8_UNORM) { + if (color_format == PIPE_FORMAT_B8G8R8A8_UNORM) { spe_roti(f, g_reg, g_reg, 8); /* green <<= 8 */ spe_roti(f, r_reg, r_reg, 16); /* red <<= 16 */ spe_roti(f, a_reg, a_reg, 24); /* alpha <<= 24 */ } - else if (color_format == PIPE_FORMAT_B8G8R8A8_UNORM) { + else if (color_format == PIPE_FORMAT_A8R8G8B8_UNORM) { spe_roti(f, r_reg, r_reg, 8); /* red <<= 8 */ spe_roti(f, g_reg, g_reg, 16); /* green <<= 16 */ spe_roti(f, b_reg, b_reg, 24); /* blue <<= 24 */ @@ -1096,14 +1096,14 @@ gen_colormask(struct spe_function *f, * end up, so we can mask them correctly. */ switch(color_format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: /* ARGB */ a_mask = 0xff000000; r_mask = 0x00ff0000; g_mask = 0x0000ff00; b_mask = 0x000000ff; break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: /* BGRA */ b_mask = 0xff000000; g_mask = 0x00ff0000; @@ -1859,8 +1859,8 @@ gen_depth_stencil(struct cell_context *cell, spe_comment(f, 0, "Fetch Z/stencil quad from tile"); switch(zs_format) { - case PIPE_FORMAT_S8Z24_UNORM: /* fall through */ - case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: /* fall through */ + case PIPE_FORMAT_Z24X8_UNORM: /* prepare mask to extract Z vals from ZS vals */ spe_load_uint(f, zmask_reg, 0x00ffffff); @@ -1880,8 +1880,8 @@ gen_depth_stencil(struct cell_context *cell, spe_rotmi(f, fbS_reg, fbZS_reg, -24); break; - case PIPE_FORMAT_Z24S8_UNORM: /* fall through */ - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: /* fall through */ + case PIPE_FORMAT_X8Z24_UNORM: /* convert fragment Z from [0,1] to 32-bit ints */ spe_cfltu(f, fragZ_reg, fragZ_reg, 32); @@ -1969,13 +1969,13 @@ gen_depth_stencil(struct cell_context *cell, * fbS_reg has four 8-bit Z values in bits [7..0]. */ spe_comment(f, 0, "Store quad's depth/stencil values in tile"); - if (zs_format == PIPE_FORMAT_S8Z24_UNORM || - zs_format == PIPE_FORMAT_X8Z24_UNORM) { + if (zs_format == PIPE_FORMAT_Z24S8_UNORM || + zs_format == PIPE_FORMAT_Z24X8_UNORM) { spe_shli(f, fbS_reg, fbS_reg, 24); /* fbS = fbS << 24 */ spe_or(f, fbZS_reg, fbS_reg, fbZ_reg); /* fbZS = fbS | fbZ */ } - else if (zs_format == PIPE_FORMAT_Z24S8_UNORM || - zs_format == PIPE_FORMAT_Z24X8_UNORM) { + else if (zs_format == PIPE_FORMAT_S8Z24_UNORM || + zs_format == PIPE_FORMAT_X8Z24_UNORM) { spe_shli(f, fbZ_reg, fbZ_reg, 8); /* fbZ = fbZ << 8 */ spe_or(f, fbZS_reg, fbS_reg, fbZ_reg); /* fbZS = fbS | fbZ */ } @@ -2015,7 +2015,7 @@ gen_depth_stencil(struct cell_context *cell, * code before the fragment shader to cull fragments/quads that are * totally occluded/discarded. * - * XXX we only support PIPE_FORMAT_Z24S8_UNORM z/stencil buffer right now. + * XXX we only support PIPE_FORMAT_S8Z24_UNORM z/stencil buffer right now. * * See the spu_default_fragment_ops() function to see how the per-fragment * operations would be done with ordinary C code. diff --git a/src/gallium/drivers/cell/ppu/cell_screen.c b/src/gallium/drivers/cell/ppu/cell_screen.c index 449855f539d..a43f8638dcd 100644 --- a/src/gallium/drivers/cell/ppu/cell_screen.c +++ b/src/gallium/drivers/cell/ppu/cell_screen.c @@ -136,7 +136,7 @@ cell_is_format_supported( struct pipe_screen *screen, { /* cell supports most formats, XXX for now anyway */ if (format == PIPE_FORMAT_DXT5_RGBA || - format == PIPE_FORMAT_R8G8B8A8_SRGB) + format == PIPE_FORMAT_A8B8G8R8_SRGB) return FALSE; else return TRUE; diff --git a/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c b/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c index 07be5e92ea7..dc33e7ccc2c 100644 --- a/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c +++ b/src/gallium/drivers/cell/ppu/cell_state_per_fragment.c @@ -1251,7 +1251,7 @@ cell_generate_logic_op(struct spe_function *f, /* Convert fragment colors to framebuffer format in AoS layout. */ switch (surf->format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: data[0] = 0x00010203; data[1] = 0x10111213; data[2] = 0x04050607; @@ -1261,7 +1261,7 @@ cell_generate_logic_op(struct spe_function *f, data[6] = 0x80808080; data[7] = 0x80808080; break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: data[0] = 0x03020100; data[1] = 0x13121110; data[2] = 0x07060504; diff --git a/src/gallium/drivers/cell/spu/spu_command.c b/src/gallium/drivers/cell/spu/spu_command.c index 55bd85bde2b..79f1fb7fb28 100644 --- a/src/gallium/drivers/cell/spu/spu_command.c +++ b/src/gallium/drivers/cell/spu/spu_command.c @@ -337,10 +337,10 @@ cmd_state_framebuffer(const struct cell_command_framebuffer *cmd) spu.fb.zsize = 4; spu.fb.zscale = (float) 0xffffffffu; break; - case PIPE_FORMAT_Z24S8_UNORM: case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: spu.fb.zsize = 4; spu.fb.zscale = (float) 0x00ffffffu; break; diff --git a/src/gallium/drivers/cell/spu/spu_per_fragment_op.c b/src/gallium/drivers/cell/spu/spu_per_fragment_op.c index 53283740805..2c9e7458afe 100644 --- a/src/gallium/drivers/cell/spu/spu_per_fragment_op.c +++ b/src/gallium/drivers/cell/spu/spu_per_fragment_op.c @@ -138,14 +138,14 @@ spu_fallback_fragment_ops(uint x, uint y, if (spu.depth_stencil_alpha.stencil[0].enabled) { /* do stencil test */ - ASSERT(spu.fb.depth_format == PIPE_FORMAT_S8Z24_UNORM); + ASSERT(spu.fb.depth_format == PIPE_FORMAT_Z24S8_UNORM); } else if (spu.depth_stencil_alpha.depth.enabled) { /* do depth test */ - ASSERT(spu.fb.depth_format == PIPE_FORMAT_S8Z24_UNORM || - spu.fb.depth_format == PIPE_FORMAT_X8Z24_UNORM); + ASSERT(spu.fb.depth_format == PIPE_FORMAT_Z24S8_UNORM || + spu.fb.depth_format == PIPE_FORMAT_Z24X8_UNORM); vector unsigned int ifragZ; vector unsigned int zmask; @@ -240,13 +240,13 @@ spu_fallback_fragment_ops(uint x, uint y, { vector float temp[4]; /* float colors in AOS form */ switch (spu.fb.color_format) { - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: temp[0] = spu_unpack_B8G8R8A8(fbc0); temp[1] = spu_unpack_B8G8R8A8(fbc1); temp[2] = spu_unpack_B8G8R8A8(fbc2); temp[3] = spu_unpack_B8G8R8A8(fbc3); break; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: temp[0] = spu_unpack_A8R8G8B8(fbc0); temp[1] = spu_unpack_A8R8G8B8(fbc1); temp[2] = spu_unpack_A8R8G8B8(fbc2); @@ -506,13 +506,13 @@ spu_fallback_fragment_ops(uint x, uint y, * Pack fragment float colors into 32-bit RGBA words. */ switch (spu.fb.color_format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: fragc0 = spu_pack_A8R8G8B8(frag_aos[0]); fragc1 = spu_pack_A8R8G8B8(frag_aos[1]); fragc2 = spu_pack_A8R8G8B8(frag_aos[2]); fragc3 = spu_pack_A8R8G8B8(frag_aos[3]); break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: fragc0 = spu_pack_B8G8R8A8(frag_aos[0]); fragc1 = spu_pack_B8G8R8A8(frag_aos[1]); fragc2 = spu_pack_B8G8R8A8(frag_aos[2]); @@ -532,7 +532,7 @@ spu_fallback_fragment_ops(uint x, uint y, /* Form bitmask depending on color buffer format and colormask bits */ switch (spu.fb.color_format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: if (spu.blend.rt[0].colormask & PIPE_MASK_R) cmask |= 0x00ff0000; /* red */ if (spu.blend.rt[0].colormask & PIPE_MASK_G) @@ -542,7 +542,7 @@ spu_fallback_fragment_ops(uint x, uint y, if (spu.blend.rt[0].colormask & PIPE_MASK_A) cmask |= 0xff000000; /* alpha */ break; - case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_A8R8G8B8_UNORM: if (spu.blend.rt[0].colormask & PIPE_MASK_R) cmask |= 0x0000ff00; /* red */ if (spu.blend.rt[0].colormask & PIPE_MASK_G) diff --git a/src/gallium/drivers/cell/spu/spu_tri.c b/src/gallium/drivers/cell/spu/spu_tri.c index 58be001be4c..f619380d807 100644 --- a/src/gallium/drivers/cell/spu/spu_tri.c +++ b/src/gallium/drivers/cell/spu/spu_tri.c @@ -752,7 +752,7 @@ subtriangle(struct edge *eleft, struct edge *eright, unsigned lines) finish_y -= sy; /* - _mesa_printf("%s %d %d\n", __FUNCTION__, start_y, finish_y); + printf("%s %d %d\n", __FUNCTION__, start_y, finish_y); */ for (y = start_y; y < finish_y; y++) { diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h index 3e383aaa1ca..49945376837 100644 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@ -192,6 +192,9 @@ struct i915_velems_state { struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS]; }; +#define I915_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ +#define I915_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ + struct i915_texture { struct pipe_texture base; @@ -204,7 +207,7 @@ struct i915_texture { unsigned sw_tiled; /**< tiled with software flags */ unsigned hw_tiled; /**< tiled with hardware fences */ - unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; + unsigned nr_images[I915_MAX_TEXTURE_2D_LEVELS]; /* Explicitly store the offset of each image for each cube face or * depth value. Pretty much have to accept that hardware formats @@ -212,7 +215,7 @@ struct i915_texture { * compute the offsets of depth/cube images within a mipmap level, * so have to store them as a lookup table: */ - unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; /**< array [depth] of offsets */ + unsigned *image_offset[I915_MAX_TEXTURE_2D_LEVELS]; /**< array [depth] of offsets */ /* The data is held here: */ diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c index c450854c982..e5bf4a20bd0 100644 --- a/src/gallium/drivers/i915/i915_screen.c +++ b/src/gallium/drivers/i915/i915_screen.c @@ -95,6 +95,10 @@ i915_get_param(struct pipe_screen *screen, int param) switch (param) { case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: return 8; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + return 0; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 8; case PIPE_CAP_NPOT_TEXTURES: return 1; case PIPE_CAP_TWO_SIDED_STENCIL: @@ -112,11 +116,11 @@ i915_get_param(struct pipe_screen *screen, int param) case PIPE_CAP_TEXTURE_SHADOW_MAP: return 1; case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: - return 11; /* max 1024x1024 */ + return I915_MAX_TEXTURE_2D_LEVELS; case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: - return 8; /* max 128x128x128 */ + return I915_MAX_TEXTURE_3D_LEVELS; case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: - return 11; /* max 1024x1024 */ + return I915_MAX_TEXTURE_2D_LEVELS; case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: return 1; @@ -161,22 +165,22 @@ i915_is_format_supported(struct pipe_screen *screen, unsigned geom_flags) { static const enum pipe_format tex_supported[] = { - PIPE_FORMAT_R8G8B8A8_UNORM, - PIPE_FORMAT_A8R8G8B8_UNORM, - PIPE_FORMAT_R5G6B5_UNORM, + PIPE_FORMAT_A8B8G8R8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, PIPE_FORMAT_L8_UNORM, PIPE_FORMAT_A8_UNORM, PIPE_FORMAT_I8_UNORM, - PIPE_FORMAT_A8L8_UNORM, - PIPE_FORMAT_YCBCR, - PIPE_FORMAT_YCBCR_REV, - PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_L8A8_UNORM, + PIPE_FORMAT_UYVY, + PIPE_FORMAT_YUYV, + PIPE_FORMAT_Z24S8_UNORM, PIPE_FORMAT_NONE /* list terminator */ }; static const enum pipe_format surface_supported[] = { - PIPE_FORMAT_A8R8G8B8_UNORM, - PIPE_FORMAT_R5G6B5_UNORM, - PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, + PIPE_FORMAT_Z24S8_UNORM, PIPE_FORMAT_NONE /* list terminator */ }; const enum pipe_format *list; diff --git a/src/gallium/drivers/i915/i915_state_emit.c b/src/gallium/drivers/i915/i915_state_emit.c index a3d4e3b04e5..51f0ef12baf 100644 --- a/src/gallium/drivers/i915/i915_state_emit.c +++ b/src/gallium/drivers/i915/i915_state_emit.c @@ -37,9 +37,9 @@ static unsigned translate_format( enum pipe_format format ) { switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return COLOR_BUF_ARGB8888; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: return COLOR_BUF_RGB565; default: assert(0); @@ -50,7 +50,7 @@ static unsigned translate_format( enum pipe_format format ) static unsigned translate_depth_format( enum pipe_format zformat ) { switch (zformat) { - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: return DEPTH_FRMT_24_FIXED_8_OTHER; case PIPE_FORMAT_Z16_UNORM: return DEPTH_FRMT_16_FIXED; @@ -244,6 +244,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) OUT_BATCH(_3DSTATE_BUF_INFO_CMD); + assert(tex); OUT_BATCH(BUF_3D_ID_DEPTH | BUF_3D_PITCH(tex->stride) | /* pitch in bytes */ ztile); @@ -259,7 +260,7 @@ i915_emit_hardware_state(struct i915_context *i915 ) if (cbuf_surface) cformat = cbuf_surface->format; else - cformat = PIPE_FORMAT_A8R8G8B8_UNORM; /* arbitrary */ + cformat = PIPE_FORMAT_B8G8R8A8_UNORM; /* arbitrary */ cformat = translate_format(cformat); if (depth_surface) diff --git a/src/gallium/drivers/i915/i915_state_sampler.c b/src/gallium/drivers/i915/i915_state_sampler.c index e5c6d87215b..9813290b51b 100644 --- a/src/gallium/drivers/i915/i915_state_sampler.c +++ b/src/gallium/drivers/i915/i915_state_sampler.c @@ -87,8 +87,8 @@ static void update_sampler(struct i915_context *i915, state[1] = sampler->state[1]; state[2] = sampler->state[2]; - if (pt->format == PIPE_FORMAT_YCBCR || - pt->format == PIPE_FORMAT_YCBCR_REV) + if (pt->format == PIPE_FORMAT_UYVY || + pt->format == PIPE_FORMAT_YUYV) state[0] |= SS2_COLORSPACE_CONVERSION; /* 3D textures don't seem to respect the border color. @@ -180,19 +180,19 @@ translate_texture_format(enum pipe_format pipeFormat) return MAPSURF_8BIT | MT_8BIT_I8; case PIPE_FORMAT_A8_UNORM: return MAPSURF_8BIT | MT_8BIT_A8; - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: return MAPSURF_16BIT | MT_16BIT_AY88; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: return MAPSURF_16BIT | MT_16BIT_RGB565; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: return MAPSURF_16BIT | MT_16BIT_ARGB1555; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: return MAPSURF_16BIT | MT_16BIT_ARGB4444; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return MAPSURF_32BIT | MT_32BIT_ARGB8888; - case PIPE_FORMAT_YCBCR_REV: + case PIPE_FORMAT_YUYV: return (MAPSURF_422 | MT_422_YCRCB_NORMAL); - case PIPE_FORMAT_YCBCR: + case PIPE_FORMAT_UYVY: return (MAPSURF_422 | MT_422_YCRCB_SWAPY); #if 0 case PIPE_FORMAT_RGB_FXT1: @@ -210,7 +210,7 @@ translate_texture_format(enum pipe_format pipeFormat) case PIPE_FORMAT_RGBA_DXT5: return (MAPSURF_COMPRESSED | MT_COMPRESS_DXT4_5); #endif - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: return (MAPSURF_32BIT | MT_32BIT_xI824); default: debug_printf("i915: translate_texture_format() bad image format %x\n", diff --git a/src/gallium/drivers/i915/i915_texture.c b/src/gallium/drivers/i915/i915_texture.c index e101c8683ec..3ce52cdcdbd 100644 --- a/src/gallium/drivers/i915/i915_texture.c +++ b/src/gallium/drivers/i915/i915_texture.c @@ -96,7 +96,7 @@ i915_miptree_set_level_info(struct i915_texture *tex, unsigned nr_images, unsigned w, unsigned h, unsigned d) { - assert(level < PIPE_MAX_TEXTURE_LEVELS); + assert(level < Elements(tex->nr_images)); tex->nr_images[level] = nr_images; @@ -219,12 +219,12 @@ i915_miptree_layout_2d(struct i915_texture *tex) unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->width0); /* used for scanouts that need special layouts */ - if (pt->tex_usage & PIPE_TEXTURE_USAGE_PRIMARY) + if (pt->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) if (i915_scanout_layout(tex)) return; - /* for shared buffers we use some very like scanout */ - if (pt->tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) + /* shared buffers needs to be compatible with X servers */ + if (pt->tex_usage & PIPE_TEXTURE_USAGE_SHARED) if (i915_display_target_layout(tex)) return; @@ -369,12 +369,12 @@ i945_miptree_layout_2d(struct i915_texture *tex) unsigned nblocksy = util_format_get_nblocksy(pt->format, pt->height0); /* used for scanouts that need special layouts */ - if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_PRIMARY) + if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) if (i915_scanout_layout(tex)) return; - /* for shared buffers we use some very like scanout */ - if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) + /* shared buffers needs to be compatible with X servers */ + if (tex->base.tex_usage & PIPE_TEXTURE_USAGE_SHARED) if (i915_display_target_layout(tex)) return; @@ -642,7 +642,7 @@ i915_texture_create(struct pipe_screen *screen, /* for scanouts and cursors, cursors arn't scanouts */ - if (templat->tex_usage & PIPE_TEXTURE_USAGE_PRIMARY && templat->width0 != 64) + if (templat->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT && templat->width0 != 64) buf_usage = INTEL_NEW_SCANOUT; else buf_usage = INTEL_NEW_TEXTURE; @@ -673,19 +673,24 @@ fail: } static struct pipe_texture * -i915_texture_blanket(struct pipe_screen * screen, - const struct pipe_texture *base, - const unsigned *stride, - struct pipe_buffer *buffer) +i915_texture_from_handle(struct pipe_screen * screen, + const struct pipe_texture *templat, + struct winsys_handle *whandle) { -#if 0 + struct i915_screen *is = i915_screen(screen); struct i915_texture *tex; + struct intel_winsys *iws = is->iws; + struct intel_buffer *buffer; + unsigned stride; + assert(screen); + buffer = iws->buffer_from_handle(iws, whandle, &stride); + /* Only supports one type */ - if (base->target != PIPE_TEXTURE_2D || - base->last_level != 0 || - base->depth0 != 1) { + if (templat->target != PIPE_TEXTURE_2D || + templat->last_level != 0 || + templat->depth0 != 1) { return NULL; } @@ -693,23 +698,33 @@ i915_texture_blanket(struct pipe_screen * screen, if (!tex) return NULL; - tex->base = *base; + tex->base = *templat; pipe_reference_init(&tex->base.reference, 1); tex->base.screen = screen; - tex->stride = stride[0]; + tex->stride = stride; - i915_miptree_set_level_info(tex, 0, 1, base->width0, base->height0, 1); + i915_miptree_set_level_info(tex, 0, 1, templat->width0, templat->height0, 1); i915_miptree_set_image_offset(tex, 0, 0, 0, 0); - pipe_buffer_reference(&tex->buffer, buffer); + tex->buffer = buffer; return &tex->base; -#else - return NULL; -#endif } +static boolean +i915_texture_get_handle(struct pipe_screen * screen, + struct pipe_texture *texture, + struct winsys_handle *whandle) +{ + struct i915_screen *is = i915_screen(screen); + struct i915_texture *tex = (struct i915_texture *)texture; + struct intel_winsys *iws = is->iws; + + return iws->buffer_get_handle(iws, tex->buffer, whandle, tex->stride); +} + + static void i915_texture_destroy(struct pipe_texture *pt) { @@ -723,7 +738,7 @@ i915_texture_destroy(struct pipe_texture *pt) iws->buffer_destroy(iws, tex->buffer); - for (i = 0; i < PIPE_MAX_TEXTURE_LEVELS; i++) + for (i = 0; i < Elements(tex->image_offset); i++) if (tex->image_offset[i]) FREE(tex->image_offset[i]); @@ -869,7 +884,8 @@ void i915_init_screen_texture_functions(struct i915_screen *is) { is->base.texture_create = i915_texture_create; - is->base.texture_blanket = i915_texture_blanket; + is->base.texture_from_handle = i915_texture_from_handle; + is->base.texture_get_handle = i915_texture_get_handle; is->base.texture_destroy = i915_texture_destroy; is->base.get_tex_surface = i915_get_tex_surface; is->base.tex_surface_destroy = i915_tex_surface_destroy; @@ -878,53 +894,3 @@ i915_init_screen_texture_functions(struct i915_screen *is) is->base.transfer_unmap = i915_transfer_unmap; is->base.tex_transfer_destroy = i915_tex_transfer_destroy; } - -struct pipe_texture * -i915_texture_blanket_intel(struct pipe_screen *screen, - struct pipe_texture *base, - unsigned stride, - struct intel_buffer *buffer) -{ - struct i915_texture *tex; - assert(screen); - - /* Only supports one type */ - if (base->target != PIPE_TEXTURE_2D || - base->last_level != 0 || - base->depth0 != 1) { - return NULL; - } - - tex = CALLOC_STRUCT(i915_texture); - if (!tex) - return NULL; - - tex->base = *base; - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; - - tex->stride = stride; - - i915_miptree_set_level_info(tex, 0, 1, base->width0, base->height0, 1); - i915_miptree_set_image_offset(tex, 0, 0, 0, 0); - - tex->buffer = buffer; - - return &tex->base; -} - -boolean -i915_get_texture_buffer_intel(struct pipe_texture *texture, - struct intel_buffer **buffer, - unsigned *stride) -{ - struct i915_texture *tex = (struct i915_texture *)texture; - - if (!texture) - return FALSE; - - *stride = tex->stride; - *buffer = tex->buffer; - - return TRUE; -} diff --git a/src/gallium/drivers/i915/intel_winsys.h b/src/gallium/drivers/i915/intel_winsys.h index b3a802b0e29..00fd0c1efea 100644 --- a/src/gallium/drivers/i915/intel_winsys.h +++ b/src/gallium/drivers/i915/intel_winsys.h @@ -33,6 +33,7 @@ struct intel_buffer; struct intel_batchbuffer; struct pipe_texture; struct pipe_fence_handle; +struct winsys_handle; enum intel_buffer_usage { @@ -129,6 +130,25 @@ struct intel_winsys { enum intel_buffer_type type); /** + * Creates a buffer from a handle. + * Used to implement pipe_screen::texture_from_handle. + * Also provides the stride information needed for the + * texture via the stride argument. + */ + struct intel_buffer *(*buffer_from_handle)(struct intel_winsys *iws, + struct winsys_handle *whandle, + unsigned *stride); + + /** + * Used to implement pipe_screen::texture_get_handle. + * The winsys might need the stride information. + */ + boolean (*buffer_get_handle)(struct intel_winsys *iws, + struct intel_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride); + + /** * Fence a buffer with a fence reg. * Not to be confused with pipe_fence_handle. */ @@ -204,23 +224,4 @@ struct intel_winsys { struct pipe_screen *i915_create_screen(struct intel_winsys *iws, unsigned pci_id); -/** - * Get the intel_winsys buffer backing the texture. - * - * TODO UGLY - */ -boolean i915_get_texture_buffer_intel(struct pipe_texture *texture, - struct intel_buffer **buffer, - unsigned *stride); - -/** - * Wrap a intel_winsys buffer with a texture blanket. - * - * TODO UGLY - */ -struct pipe_texture * i915_texture_blanket_intel(struct pipe_screen *screen, - struct pipe_texture *tmplt, - unsigned pitch, - struct intel_buffer *buffer); - #endif diff --git a/src/gallium/drivers/i965/brw_misc_state.c b/src/gallium/drivers/i965/brw_misc_state.c index e4b24229db3..e3f25bdf622 100644 --- a/src/gallium/drivers/i965/brw_misc_state.c +++ b/src/gallium/drivers/i965/brw_misc_state.c @@ -265,8 +265,8 @@ static int emit_depthbuffer(struct brw_context *brw) format = BRW_DEPTHFORMAT_D16_UNORM; cpp = 2; break; - case PIPE_FORMAT_X8Z24_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: format = BRW_DEPTHFORMAT_D24_UNORM_S8_UINT; cpp = 4; break; diff --git a/src/gallium/drivers/i965/brw_pipe_clear.c b/src/gallium/drivers/i965/brw_pipe_clear.c index 452e1e89f93..d7048f769b2 100644 --- a/src/gallium/drivers/i965/brw_pipe_clear.c +++ b/src/gallium/drivers/i965/brw_pipe_clear.c @@ -139,8 +139,8 @@ static void zstencil_clear(struct brw_context *brw, unsigned value; switch (bsurface->base.format) { - case PIPE_FORMAT_X8Z24_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: value = ((unsigned)(depth * MASK24) & MASK24); break; case PIPE_FORMAT_Z16_UNORM: @@ -152,8 +152,8 @@ static void zstencil_clear(struct brw_context *brw, } switch (bsurface->base.format) { - case PIPE_FORMAT_X8Z24_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: value = value | (stencil << 24); break; diff --git a/src/gallium/drivers/i965/brw_screen.c b/src/gallium/drivers/i965/brw_screen.c index 184cd490e55..cef83ffea80 100644 --- a/src/gallium/drivers/i965/brw_screen.c +++ b/src/gallium/drivers/i965/brw_screen.c @@ -153,6 +153,10 @@ brw_get_param(struct pipe_screen *screen, int param) switch (param) { case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: return 8; + case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: + return 8; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 16; /* XXX correct? */ case PIPE_CAP_NPOT_TEXTURES: return 1; case PIPE_CAP_TWO_SIDED_STENCIL: @@ -170,11 +174,11 @@ brw_get_param(struct pipe_screen *screen, int param) case PIPE_CAP_TEXTURE_SHADOW_MAP: return 1; case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: - return 11; /* max 1024x1024 */ + return BRW_MAX_TEXTURE_2D_LEVELS; case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: - return 8; /* max 128x128x128 */ + return BRW_MAX_TEXTURE_3D_LEVELS; case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: - return 11; /* max 1024x1024 */ + return BRW_MAX_TEXTURE_2D_LEVELS; case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER: return 1; @@ -225,15 +229,15 @@ brw_is_format_supported(struct pipe_screen *screen, PIPE_FORMAT_L16_UNORM, /*PIPE_FORMAT_I16_UNORM,*/ /*PIPE_FORMAT_A16_UNORM,*/ - PIPE_FORMAT_A8L8_UNORM, - PIPE_FORMAT_R5G6B5_UNORM, - PIPE_FORMAT_A1R5G5B5_UNORM, - PIPE_FORMAT_A4R4G4B4_UNORM, - PIPE_FORMAT_X8R8G8B8_UNORM, - PIPE_FORMAT_A8R8G8B8_UNORM, + PIPE_FORMAT_L8A8_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, + PIPE_FORMAT_B5G5R5A1_UNORM, + PIPE_FORMAT_B4G4R4A4_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, /* video */ - PIPE_FORMAT_YCBCR, - PIPE_FORMAT_YCBCR_REV, + PIPE_FORMAT_UYVY, + PIPE_FORMAT_YUYV, /* compressed */ /*PIPE_FORMAT_FXT1_RGBA,*/ PIPE_FORMAT_DXT1_RGB, @@ -241,14 +245,14 @@ brw_is_format_supported(struct pipe_screen *screen, PIPE_FORMAT_DXT3_RGBA, PIPE_FORMAT_DXT5_RGBA, /* sRGB */ - PIPE_FORMAT_R8G8B8A8_SRGB, - PIPE_FORMAT_A8L8_SRGB, + PIPE_FORMAT_A8B8G8R8_SRGB, + PIPE_FORMAT_L8A8_SRGB, PIPE_FORMAT_L8_SRGB, PIPE_FORMAT_DXT1_SRGB, /* depth */ PIPE_FORMAT_Z32_FLOAT, - PIPE_FORMAT_X8Z24_UNORM, - PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_Z24S8_UNORM, PIPE_FORMAT_Z16_UNORM, /* signed */ PIPE_FORMAT_R8G8_SNORM, @@ -256,15 +260,15 @@ brw_is_format_supported(struct pipe_screen *screen, PIPE_FORMAT_NONE /* list terminator */ }; static const enum pipe_format render_supported[] = { - PIPE_FORMAT_X8R8G8B8_UNORM, - PIPE_FORMAT_A8R8G8B8_UNORM, - PIPE_FORMAT_R5G6B5_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, PIPE_FORMAT_NONE /* list terminator */ }; static const enum pipe_format depth_supported[] = { PIPE_FORMAT_Z32_FLOAT, - PIPE_FORMAT_X8Z24_UNORM, - PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_Z24S8_UNORM, PIPE_FORMAT_Z16_UNORM, PIPE_FORMAT_NONE /* list terminator */ }; diff --git a/src/gallium/drivers/i965/brw_screen.h b/src/gallium/drivers/i965/brw_screen.h index 7226d9228b7..e0f3cd2a9fe 100644 --- a/src/gallium/drivers/i965/brw_screen.h +++ b/src/gallium/drivers/i965/brw_screen.h @@ -100,6 +100,9 @@ struct brw_surface }; +#define BRW_MAX_TEXTURE_2D_LEVELS 11 /* max 1024x1024 */ +#define BRW_MAX_TEXTURE_3D_LEVELS 8 /* max 128x128x128 */ + struct brw_texture { @@ -107,9 +110,9 @@ struct brw_texture struct brw_winsys_buffer *bo; struct brw_surface_state ss; - unsigned *image_offset[PIPE_MAX_TEXTURE_LEVELS]; - unsigned nr_images[PIPE_MAX_TEXTURE_LEVELS]; - unsigned level_offset[PIPE_MAX_TEXTURE_LEVELS]; + unsigned *image_offset[BRW_MAX_TEXTURE_2D_LEVELS]; + unsigned nr_images[BRW_MAX_TEXTURE_2D_LEVELS]; + unsigned level_offset[BRW_MAX_TEXTURE_2D_LEVELS]; boolean compressed; unsigned brw_target; diff --git a/src/gallium/drivers/i965/brw_screen_surface.c b/src/gallium/drivers/i965/brw_screen_surface.c index e2b9954e596..904df813dda 100644 --- a/src/gallium/drivers/i965/brw_screen_surface.c +++ b/src/gallium/drivers/i965/brw_screen_surface.c @@ -231,8 +231,6 @@ static struct pipe_surface *brw_get_tex_surface(struct pipe_screen *screen, case BRW_VIEW_IN_PLACE: surface = create_in_place_view( bscreen, tex, id, usage ); break; - default: - return NULL; } insert_at_head( &tex->views[type], surface ); diff --git a/src/gallium/drivers/i965/brw_screen_texture.c b/src/gallium/drivers/i965/brw_screen_texture.c index feb9d5f7657..cc79bfc7715 100644 --- a/src/gallium/drivers/i965/brw_screen_texture.c +++ b/src/gallium/drivers/i965/brw_screen_texture.c @@ -85,32 +85,32 @@ static GLuint translate_tex_format( enum pipe_format pf ) return BRW_SURFACEFORMAT_A16_UNORM; */ - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: return BRW_SURFACEFORMAT_L8A8_UNORM; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: return BRW_SURFACEFORMAT_B5G6R5_UNORM; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: return BRW_SURFACEFORMAT_B5G5R5A1_UNORM; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: return BRW_SURFACEFORMAT_B4G4R4A4_UNORM; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: return BRW_SURFACEFORMAT_R8G8B8X8_UNORM; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return BRW_SURFACEFORMAT_B8G8R8A8_UNORM; /* * Video formats */ - case PIPE_FORMAT_YCBCR_REV: + case PIPE_FORMAT_YUYV: return BRW_SURFACEFORMAT_YCRCB_NORMAL; - case PIPE_FORMAT_YCBCR: + case PIPE_FORMAT_UYVY: return BRW_SURFACEFORMAT_YCRCB_SWAPUVY; /* @@ -137,10 +137,10 @@ static GLuint translate_tex_format( enum pipe_format pf ) * sRGB formats */ - case PIPE_FORMAT_R8G8B8A8_SRGB: + case PIPE_FORMAT_A8B8G8R8_SRGB: return BRW_SURFACEFORMAT_B8G8R8A8_UNORM_SRGB; - case PIPE_FORMAT_A8L8_SRGB: + case PIPE_FORMAT_L8A8_SRGB: return BRW_SURFACEFORMAT_L8A8_UNORM_SRGB; case PIPE_FORMAT_L8_SRGB: @@ -156,8 +156,8 @@ static GLuint translate_tex_format( enum pipe_format pf ) case PIPE_FORMAT_Z16_UNORM: return BRW_SURFACEFORMAT_I16_UNORM; - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: return BRW_SURFACEFORMAT_I24X8_UNORM; case PIPE_FORMAT_Z32_FLOAT: @@ -191,6 +191,7 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, struct brw_texture *tex; enum brw_buffer_type buffer_type; enum pipe_error ret; + GLuint format; tex = CALLOC_STRUCT(brw_texture); if (tex == NULL) @@ -230,8 +231,8 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, goto fail; - if (templ->tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_PRIMARY)) { + if (templ->tex_usage & (PIPE_TEXTURE_USAGE_SCANOUT | + PIPE_TEXTURE_USAGE_SHARED)) { buffer_type = BRW_BUFFER_TYPE_SCANOUT; } else { @@ -248,8 +249,10 @@ static struct pipe_texture *brw_texture_create( struct pipe_screen *screen, tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; tex->ss.ss0.surface_type = translate_tex_target(tex->base.target); - tex->ss.ss0.surface_format = translate_tex_format(tex->base.format); - assert(tex->ss.ss0.surface_format != BRW_SURFACEFORMAT_INVALID); + + format = translate_tex_format(tex->base.format); + assert(format != BRW_SURFACEFORMAT_INVALID); + tex->ss.ss0.surface_format = format; /* This is ok for all textures with channel width 8bit or less: */ @@ -300,14 +303,121 @@ fail: return NULL; } -static struct pipe_texture *brw_texture_blanket(struct pipe_screen *screen, - const struct pipe_texture *templ, - const unsigned *stride, - struct pipe_buffer *buffer) +static struct pipe_texture * +brw_texture_from_handle(struct pipe_screen *screen, + const struct pipe_texture *templ, + struct winsys_handle *whandle) { + struct brw_screen *bscreen = brw_screen(screen); + struct brw_texture *tex; + struct brw_winsys_buffer *buffer; + unsigned tiling; + unsigned pitch; + + if (templ->target != PIPE_TEXTURE_2D || + templ->last_level != 0 || + templ->depth0 != 1) + return NULL; + + if (util_format_is_compressed(templ->format)) + return NULL; + + tex = CALLOC_STRUCT(brw_texture); + if (!tex) + return NULL; + + if (bscreen->sws->bo_from_handle(bscreen->sws, whandle, &pitch, &tiling, &buffer) != PIPE_OK) + goto fail; + + memcpy(&tex->base, templ, sizeof *templ); + pipe_reference_init(&tex->base.reference, 1); + tex->base.screen = screen; + + /* XXX: cpp vs. blocksize + */ + tex->cpp = util_format_get_blocksize(tex->base.format); + tex->tiling = tiling; + + make_empty_list(&tex->views[0]); + make_empty_list(&tex->views[1]); + + if (!brw_texture_layout(bscreen, tex)) + goto fail; + + /* XXX Maybe some more checks? */ + if ((pitch / tex->cpp) < tex->pitch) + goto fail; + + tex->pitch = pitch / tex->cpp; + + tex->bo = buffer; + + /* fix this warning */ +#if 0 + if (tex->size > buffer->size) + goto fail; +#endif + + tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; + tex->ss.ss0.surface_type = translate_tex_target(tex->base.target); + tex->ss.ss0.surface_format = translate_tex_format(tex->base.format); + assert(tex->ss.ss0.surface_format != BRW_SURFACEFORMAT_INVALID); + + /* This is ok for all textures with channel width 8bit or less: + */ +/* tex->ss.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */ + + + /* XXX: what happens when tex->bo->offset changes??? + */ + tex->ss.ss1.base_addr = 0; /* reloc */ + tex->ss.ss2.mip_count = tex->base.last_level; + tex->ss.ss2.width = tex->base.width0 - 1; + tex->ss.ss2.height = tex->base.height0 - 1; + + switch (tex->tiling) { + case BRW_TILING_NONE: + tex->ss.ss3.tiled_surface = 0; + tex->ss.ss3.tile_walk = 0; + break; + case BRW_TILING_X: + tex->ss.ss3.tiled_surface = 1; + tex->ss.ss3.tile_walk = BRW_TILEWALK_XMAJOR; + break; + case BRW_TILING_Y: + tex->ss.ss3.tiled_surface = 1; + tex->ss.ss3.tile_walk = BRW_TILEWALK_YMAJOR; + break; + } + + tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1; + tex->ss.ss3.depth = tex->base.depth0 - 1; + + tex->ss.ss4.min_lod = 0; + + return &tex->base; + +fail: + FREE(tex); return NULL; } +static boolean +brw_texture_get_handle(struct pipe_screen *screen, + struct pipe_texture *texture, + struct winsys_handle *whandle) +{ + struct brw_screen *bscreen = brw_screen(screen); + struct brw_texture *tex = brw_texture(texture); + unsigned stride; + + stride = tex->pitch * tex->cpp; + + return bscreen->sws->bo_get_handle(tex->bo, whandle, stride); +} + + + static void brw_texture_destroy(struct pipe_texture *pt) { struct brw_texture *tex = brw_texture(pt); @@ -448,124 +558,13 @@ brw_tex_transfer_destroy(struct pipe_transfer *trans) } -/* - * Functions exported to the winsys - */ - -boolean brw_texture_get_winsys_buffer(struct pipe_texture *texture, - struct brw_winsys_buffer **buffer, - unsigned *stride) -{ - struct brw_texture *tex = brw_texture(texture); - - *buffer = tex->bo; - if (stride) - *stride = tex->pitch * tex->cpp; - - return TRUE; -} - -struct pipe_texture * -brw_texture_blanket_winsys_buffer(struct pipe_screen *screen, - const struct pipe_texture *templ, - unsigned pitch, - unsigned tiling, - struct brw_winsys_buffer *buffer) -{ - struct brw_screen *bscreen = brw_screen(screen); - struct brw_texture *tex; - - if (templ->target != PIPE_TEXTURE_2D || - templ->last_level != 0 || - templ->depth0 != 1) - return NULL; - - if (util_format_is_compressed(templ->format)) - return NULL; - - tex = CALLOC_STRUCT(brw_texture); - if (!tex) - return NULL; - - memcpy(&tex->base, templ, sizeof *templ); - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; - - /* XXX: cpp vs. blocksize - */ - tex->cpp = util_format_get_blocksize(tex->base.format); - tex->tiling = tiling; - - make_empty_list(&tex->views[0]); - make_empty_list(&tex->views[1]); - - if (!brw_texture_layout(bscreen, tex)) - goto fail; - - /* XXX Maybe some more checks? */ - if ((pitch / tex->cpp) < tex->pitch) - goto fail; - - tex->pitch = pitch / tex->cpp; - - tex->bo = buffer; - - /* fix this warning */ -#if 0 - if (tex->size > buffer->size) - goto fail; -#endif - - tex->ss.ss0.mipmap_layout_mode = BRW_SURFACE_MIPMAPLAYOUT_BELOW; - tex->ss.ss0.surface_type = translate_tex_target(tex->base.target); - tex->ss.ss0.surface_format = translate_tex_format(tex->base.format); - assert(tex->ss.ss0.surface_format != BRW_SURFACEFORMAT_INVALID); - - /* This is ok for all textures with channel width 8bit or less: - */ -/* tex->ss.ss0.data_return_format = BRW_SURFACERETURNFORMAT_S1; */ - - - /* XXX: what happens when tex->bo->offset changes??? - */ - tex->ss.ss1.base_addr = 0; /* reloc */ - tex->ss.ss2.mip_count = tex->base.last_level; - tex->ss.ss2.width = tex->base.width0 - 1; - tex->ss.ss2.height = tex->base.height0 - 1; - - switch (tex->tiling) { - case BRW_TILING_NONE: - tex->ss.ss3.tiled_surface = 0; - tex->ss.ss3.tile_walk = 0; - break; - case BRW_TILING_X: - tex->ss.ss3.tiled_surface = 1; - tex->ss.ss3.tile_walk = BRW_TILEWALK_XMAJOR; - break; - case BRW_TILING_Y: - tex->ss.ss3.tiled_surface = 1; - tex->ss.ss3.tile_walk = BRW_TILEWALK_YMAJOR; - break; - } - - tex->ss.ss3.pitch = (tex->pitch * tex->cpp) - 1; - tex->ss.ss3.depth = tex->base.depth0 - 1; - - tex->ss.ss4.min_lod = 0; - - return &tex->base; - -fail: - FREE(tex); - return NULL; -} - void brw_screen_tex_init( struct brw_screen *brw_screen ) { brw_screen->base.is_format_supported = brw_is_format_supported; brw_screen->base.texture_create = brw_texture_create; + brw_screen->base.texture_from_handle = brw_texture_from_handle; + brw_screen->base.texture_get_handle = brw_texture_get_handle; brw_screen->base.texture_destroy = brw_texture_destroy; - brw_screen->base.texture_blanket = brw_texture_blanket; brw_screen->base.get_tex_transfer = brw_get_tex_transfer; brw_screen->base.transfer_map = brw_transfer_map; brw_screen->base.transfer_unmap = brw_transfer_unmap; diff --git a/src/gallium/drivers/i965/brw_state_cache.c b/src/gallium/drivers/i965/brw_state_cache.c index 85c20076fb8..c911f3997d1 100644 --- a/src/gallium/drivers/i965/brw_state_cache.c +++ b/src/gallium/drivers/i965/brw_state_cache.c @@ -213,7 +213,7 @@ brw_upload_cache( struct brw_cache *cache, void *aux_return, struct brw_winsys_buffer **bo_out) { - struct brw_cache_item *item = CALLOC_STRUCT(brw_cache_item); + struct brw_cache_item *item; GLuint hash = hash_key(key, key_size, relocs, nr_relocs); GLuint relocs_size = nr_relocs * sizeof relocs[0]; GLuint aux_size = cache->aux_size[cache_id]; @@ -233,6 +233,7 @@ brw_upload_cache( struct brw_cache *cache, if (ret) return ret; + item = CALLOC_STRUCT(brw_cache_item); /* Set up the memory containing the key, aux_data, and relocs */ tmp = MALLOC(key_size + aux_size + relocs_size); diff --git a/src/gallium/drivers/i965/brw_winsys.h b/src/gallium/drivers/i965/brw_winsys.h index c82d00f4a47..f30c7f18132 100644 --- a/src/gallium/drivers/i965/brw_winsys.h +++ b/src/gallium/drivers/i965/brw_winsys.h @@ -162,6 +162,16 @@ struct brw_winsys_screen { unsigned alignment, struct brw_winsys_buffer **bo_out); + enum pipe_error (*bo_from_handle)(struct brw_winsys_screen *sws, + struct winsys_handle *whandle, + unsigned *stride, + unsigned *tiling, + struct brw_winsys_buffer **bo_out); + + enum pipe_error (*bo_get_handle)(struct brw_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride); + /* Destroy a buffer when our refcount goes to zero: */ void (*bo_destroy)(struct brw_winsys_buffer *buffer); @@ -257,28 +267,6 @@ bo_reference(struct brw_winsys_buffer **ptr, struct brw_winsys_buffer *buf) struct pipe_screen *brw_create_screen(struct brw_winsys_screen *iws, unsigned pci_id); -/** - * Get the brw_winsys buffer backing the texture. - * - * TODO UGLY - */ -struct pipe_texture; -boolean brw_texture_get_winsys_buffer(struct pipe_texture *texture, - struct brw_winsys_buffer **buffer, - unsigned *stride); - -/** - * Wrap a brw_winsys buffer with a texture blanket. - * - * TODO UGLY - */ -struct pipe_texture * -brw_texture_blanket_winsys_buffer(struct pipe_screen *screen, - const struct pipe_texture *template, - unsigned pitch, - unsigned tiling, - struct brw_winsys_buffer *buffer); - /************************************************************************* * Cooperative dumping between winsys and driver. TODO: make this diff --git a/src/gallium/drivers/i965/brw_wm.c b/src/gallium/drivers/i965/brw_wm.c index 5164c90ed60..dfb718e64fe 100644 --- a/src/gallium/drivers/i965/brw_wm.c +++ b/src/gallium/drivers/i965/brw_wm.c @@ -254,10 +254,10 @@ static void brw_wm_populate_key( struct brw_context *brw, for (i = 0; i < brw->curr.num_textures; i++) { const struct brw_texture *tex = brw_texture(brw->curr.texture[i]); - if (tex->base.format == PIPE_FORMAT_YCBCR) + if (tex->base.format == PIPE_FORMAT_UYVY) key->yuvtex_mask |= 1 << i; - if (tex->base.format == PIPE_FORMAT_YCBCR_REV) + if (tex->base.format == PIPE_FORMAT_YUYV) key->yuvtex_swap_mask |= 1 << i; /* XXX: shadow texture diff --git a/src/gallium/drivers/i965/brw_wm_sampler_state.c b/src/gallium/drivers/i965/brw_wm_sampler_state.c index a8bc31c9cef..6a6086fc51b 100644 --- a/src/gallium/drivers/i965/brw_wm_sampler_state.c +++ b/src/gallium/drivers/i965/brw_wm_sampler_state.c @@ -130,15 +130,14 @@ brw_wm_sampler_update_default_colors(struct brw_context *brw) const struct brw_texture *tex = brw_texture(brw->curr.texture[i]); const struct brw_sampler *sampler = brw->curr.sampler[i]; const float *bc; - + float bordercolor[4] = { + sampler->border_color[0], + sampler->border_color[0], + sampler->border_color[0], + sampler->border_color[0] + }; + if (util_format_is_depth_or_stencil(tex->base.format)) { - float bordercolor[4] = { - sampler->border_color[0], - sampler->border_color[0], - sampler->border_color[0], - sampler->border_color[0] - }; - bc = bordercolor; } else { diff --git a/src/gallium/drivers/identity/id_drm.c b/src/gallium/drivers/identity/id_drm.c index 12b516b445f..936ccc444a8 100644 --- a/src/gallium/drivers/identity/id_drm.c +++ b/src/gallium/drivers/identity/id_drm.c @@ -28,11 +28,11 @@ #include "state_tracker/drm_api.h" #include "util/u_memory.h" -#include "identity/id_drm.h" -#include "identity/id_screen.h" -#include "identity/id_public.h" -#include "identity/id_screen.h" -#include "identity/id_objects.h" +#include "id_drm.h" +#include "id_screen.h" +#include "id_public.h" +#include "id_screen.h" +#include "id_objects.h" struct identity_drm_api { @@ -63,62 +63,6 @@ identity_drm_create_screen(struct drm_api *_api, int fd, return identity_screen_create(screen); } - -static struct pipe_texture * -identity_drm_texture_from_shared_handle(struct drm_api *_api, - struct pipe_screen *_screen, - struct pipe_texture *templ, - const char *name, - unsigned stride, - unsigned handle) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct identity_drm_api *id_api = identity_drm_api(_api); - struct pipe_screen *screen = id_screen->screen; - struct drm_api *api = id_api->api; - struct pipe_texture *result; - - result = api->texture_from_shared_handle(api, screen, templ, name, stride, handle); - - result = identity_texture_create(identity_screen(_screen), result); - - return result; -} - -static boolean -identity_drm_shared_handle_from_texture(struct drm_api *_api, - struct pipe_screen *_screen, - struct pipe_texture *_texture, - unsigned *stride, - unsigned *handle) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct identity_texture *id_texture = identity_texture(_texture); - struct identity_drm_api *id_api = identity_drm_api(_api); - struct pipe_screen *screen = id_screen->screen; - struct pipe_texture *texture = id_texture->texture; - struct drm_api *api = id_api->api; - - return api->shared_handle_from_texture(api, screen, texture, stride, handle); -} - -static boolean -identity_drm_local_handle_from_texture(struct drm_api *_api, - struct pipe_screen *_screen, - struct pipe_texture *_texture, - unsigned *stride, - unsigned *handle) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct identity_texture *id_texture = identity_texture(_texture); - struct identity_drm_api *id_api = identity_drm_api(_api); - struct pipe_screen *screen = id_screen->screen; - struct pipe_texture *texture = id_texture->texture; - struct drm_api *api = id_api->api; - - return api->local_handle_from_texture(api, screen, texture, stride, handle); -} - static void identity_drm_destroy(struct drm_api *_api) { @@ -142,10 +86,9 @@ identity_drm_create(struct drm_api *api) if (!id_api) goto error; + id_api->base.name = api->name; + id_api->base.driver_name = api->driver_name; id_api->base.create_screen = identity_drm_create_screen; - id_api->base.texture_from_shared_handle = identity_drm_texture_from_shared_handle; - id_api->base.shared_handle_from_texture = identity_drm_shared_handle_from_texture; - id_api->base.local_handle_from_texture = identity_drm_local_handle_from_texture; id_api->base.destroy = identity_drm_destroy; id_api->api = api; diff --git a/src/gallium/drivers/identity/id_screen.c b/src/gallium/drivers/identity/id_screen.c index b85492114a3..b9d0f003d74 100644 --- a/src/gallium/drivers/identity/id_screen.c +++ b/src/gallium/drivers/identity/id_screen.c @@ -135,27 +135,40 @@ identity_screen_texture_create(struct pipe_screen *_screen, } static struct pipe_texture * -identity_screen_texture_blanket(struct pipe_screen *_screen, - const struct pipe_texture *templat, - const unsigned *stride, - struct pipe_buffer *_buffer) +identity_screen_texture_from_handle(struct pipe_screen *_screen, + const struct pipe_texture *templ, + struct winsys_handle *handle) { struct identity_screen *id_screen = identity_screen(_screen); - struct identity_buffer *id_buffer = identity_buffer(_buffer); struct pipe_screen *screen = id_screen->screen; - struct pipe_buffer *buffer = id_buffer->buffer; struct pipe_texture *result; - result = screen->texture_blanket(screen, - templat, - stride, - buffer); + /* TODO trace call */ - if (result) - return identity_texture_create(id_screen, result); - return NULL; + result = screen->texture_from_handle(screen, templ, handle); + + result = identity_texture_create(identity_screen(_screen), result); + + return result; +} + +static boolean +identity_screen_texture_get_handle(struct pipe_screen *_screen, + struct pipe_texture *_texture, + struct winsys_handle *handle) +{ + struct identity_screen *id_screen = identity_screen(_screen); + struct identity_texture *id_texture = identity_texture(_texture); + struct pipe_screen *screen = id_screen->screen; + struct pipe_texture *texture = id_texture->texture; + + /* TODO trace call */ + + return screen->texture_get_handle(screen, texture, handle); } + + static void identity_screen_texture_destroy(struct pipe_texture *_texture) { @@ -298,31 +311,6 @@ identity_screen_user_buffer_create(struct pipe_screen *_screen, return NULL; } -static struct pipe_buffer * -identity_screen_surface_buffer_create(struct pipe_screen *_screen, - unsigned width, - unsigned height, - enum pipe_format format, - unsigned usage, - unsigned tex_usage, - unsigned *stride) -{ - struct identity_screen *id_screen = identity_screen(_screen); - struct pipe_screen *screen = id_screen->screen; - struct pipe_buffer *result; - - result = screen->surface_buffer_create(screen, - width, - height, - format, - usage, - tex_usage, - stride); - - if (result) - return identity_buffer_create(id_screen, result); - return NULL; -} static void * identity_screen_buffer_map(struct pipe_screen *_screen, @@ -495,7 +483,8 @@ identity_screen_create(struct pipe_screen *screen) id_screen->base.is_format_supported = identity_screen_is_format_supported; id_screen->base.context_create = identity_screen_context_create; id_screen->base.texture_create = identity_screen_texture_create; - id_screen->base.texture_blanket = identity_screen_texture_blanket; + id_screen->base.texture_from_handle = identity_screen_texture_from_handle; + id_screen->base.texture_get_handle = identity_screen_texture_get_handle; id_screen->base.texture_destroy = identity_screen_texture_destroy; id_screen->base.get_tex_surface = identity_screen_get_tex_surface; id_screen->base.tex_surface_destroy = identity_screen_tex_surface_destroy; @@ -505,7 +494,6 @@ identity_screen_create(struct pipe_screen *screen) id_screen->base.transfer_unmap = identity_screen_transfer_unmap; id_screen->base.buffer_create = identity_screen_buffer_create; id_screen->base.user_buffer_create = identity_screen_user_buffer_create; - id_screen->base.surface_buffer_create = identity_screen_surface_buffer_create; if (screen->buffer_map) id_screen->base.buffer_map = identity_screen_buffer_map; if (screen->buffer_map_range) diff --git a/src/gallium/drivers/llvmpipe/Makefile b/src/gallium/drivers/llvmpipe/Makefile index 31732514379..41ac1cee72d 100644 --- a/src/gallium/drivers/llvmpipe/Makefile +++ b/src/gallium/drivers/llvmpipe/Makefile @@ -37,6 +37,7 @@ C_SOURCES = \ lp_surface.c \ lp_tex_sample_llvm.c \ lp_texture.c \ + lp_tile_image.c \ lp_tile_soa.c CPP_SOURCES = \ diff --git a/src/gallium/drivers/llvmpipe/README b/src/gallium/drivers/llvmpipe/README index 72d9f39658f..bf4c9a5727c 100644 --- a/src/gallium/drivers/llvmpipe/README +++ b/src/gallium/drivers/llvmpipe/README @@ -49,8 +49,6 @@ To do (probably by this order): Requirements ============ - - Linux - - A x86 or amd64 processor. 64bit mode is preferred. Support for sse2 is strongly encouraged. Support for ssse3, and sse4.1 will @@ -86,7 +84,7 @@ Building To build everything on Linux invoke scons as: - scons debug=yes statetrackers=mesa drivers=trace,llvmpipe winsys=xlib dri=false + scons debug=yes statetrackers=mesa drivers=llvmpipe winsys=xlib dri=false Alternatively, you can build it with GNU make, if you prefer, by invoking it as @@ -96,7 +94,7 @@ but the rest of these instructions assume that scons is used. For windows is everything the except except the winsys: - scons debug=yes statetrackers=mesa drivers=trace,llvmpipe winsys=gdi dri=false + scons debug=yes statetrackers=mesa drivers=llvmpipe winsys=gdi dri=false Using ===== diff --git a/src/gallium/drivers/llvmpipe/SConscript b/src/gallium/drivers/llvmpipe/SConscript index a39283e5e86..13c1a13e87a 100644 --- a/src/gallium/drivers/llvmpipe/SConscript +++ b/src/gallium/drivers/llvmpipe/SConscript @@ -18,6 +18,13 @@ env.CodeGenerate( command = 'python $SCRIPT $SOURCE > $TARGET' ) +# XXX: Our dependency scanner only finds depended modules in relative dirs. +env.Depends('lp_tile_soa.c', [ + '#src/gallium/auxiliary/util/u_format_parse.py', + '#src/gallium/auxiliary/util/u_format_pack.py', + '#src/gallium/auxiliary/util/u_format_access.py', +]) + llvmpipe = env.ConvenienceLibrary( target = 'llvmpipe', source = [ @@ -52,6 +59,7 @@ llvmpipe = env.ConvenienceLibrary( 'lp_surface.c', 'lp_tex_sample_llvm.c', 'lp_texture.c', + 'lp_tile_image.c', 'lp_tile_soa.c', ]) diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c index ccd1cf8eecd..d94efec16a4 100644 --- a/src/gallium/drivers/llvmpipe/lp_context.c +++ b/src/gallium/drivers/llvmpipe/lp_context.c @@ -186,7 +186,7 @@ llvmpipe_create_context( struct pipe_screen *screen, void *priv ) if (debug_get_bool_option( "LP_NO_RAST", FALSE )) llvmpipe->no_rast = TRUE; - llvmpipe->setup = lp_setup_create( screen, + llvmpipe->setup = lp_setup_create( &llvmpipe->pipe, llvmpipe->draw ); if (!llvmpipe->setup) goto fail; diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c b/src/gallium/drivers/llvmpipe/lp_jit.c index d3d7e26882d..08c8f93794d 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.c +++ b/src/gallium/drivers/llvmpipe/lp_jit.c @@ -37,6 +37,7 @@ #include "util/u_memory.h" #include "util/u_cpu_detect.h" +#include "gallivm/lp_bld_init.h" #include "lp_debug.h" #include "lp_screen.h" #include "gallivm/lp_bld_intr.h" @@ -50,12 +51,16 @@ lp_jit_init_globals(struct llvmpipe_screen *screen) /* struct lp_jit_texture */ { - LLVMTypeRef elem_types[4]; + LLVMTypeRef elem_types[6]; elem_types[LP_JIT_TEXTURE_WIDTH] = LLVMInt32Type(); elem_types[LP_JIT_TEXTURE_HEIGHT] = LLVMInt32Type(); + elem_types[LP_JIT_TEXTURE_DEPTH] = LLVMInt32Type(); + elem_types[LP_JIT_TEXTURE_LAST_LEVEL] = LLVMInt32Type(); elem_types[LP_JIT_TEXTURE_STRIDE] = LLVMInt32Type(); - elem_types[LP_JIT_TEXTURE_DATA] = LLVMPointerType(LLVMInt8Type(), 0); + elem_types[LP_JIT_TEXTURE_DATA] = + LLVMArrayType(LLVMPointerType(LLVMInt8Type(), 0), + LP_MAX_TEXTURE_2D_LEVELS); texture_type = LLVMStructType(elem_types, Elements(elem_types), 0); @@ -65,6 +70,12 @@ lp_jit_init_globals(struct llvmpipe_screen *screen) LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, height, screen->target, texture_type, LP_JIT_TEXTURE_HEIGHT); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, depth, + screen->target, texture_type, + LP_JIT_TEXTURE_DEPTH); + LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, last_level, + screen->target, texture_type, + LP_JIT_TEXTURE_LAST_LEVEL); LP_CHECK_MEMBER_OFFSET(struct lp_jit_texture, stride, screen->target, texture_type, LP_JIT_TEXTURE_STRIDE); @@ -148,8 +159,7 @@ lp_jit_screen_init(struct llvmpipe_screen *screen) util_cpu_caps.has_sse4_1 = 0; #endif - LLVMLinkInJIT(); - LLVMInitializeNativeTarget(); + lp_build_init(); screen->module = LLVMModuleCreateWithName("llvmpipe"); diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h b/src/gallium/drivers/llvmpipe/lp_jit.h index 8df3015d4b4..5cc7a12c03b 100644 --- a/src/gallium/drivers/llvmpipe/lp_jit.h +++ b/src/gallium/drivers/llvmpipe/lp_jit.h @@ -39,6 +39,7 @@ #include "gallivm/lp_bld_struct.h" #include "pipe/p_state.h" +#include "lp_texture.h" struct llvmpipe_screen; @@ -48,14 +49,18 @@ struct lp_jit_texture { uint32_t width; uint32_t height; + uint32_t depth; + uint32_t last_level; uint32_t stride; - const void *data; + const void *data[LP_MAX_TEXTURE_2D_LEVELS]; }; enum { LP_JIT_TEXTURE_WIDTH = 0, LP_JIT_TEXTURE_HEIGHT, + LP_JIT_TEXTURE_DEPTH, + LP_JIT_TEXTURE_LAST_LEVEL, LP_JIT_TEXTURE_STRIDE, LP_JIT_TEXTURE_DATA }; diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c index 6dbcb3c9b31..dd9a8e8856f 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.c +++ b/src/gallium/drivers/llvmpipe/lp_rast.c @@ -42,128 +42,73 @@ #include "lp_scene.h" -/** - * Begin the rasterization phase. - * Map the framebuffer surfaces. Initialize the 'rast' state. +/* Begin rasterizing a scene: */ static boolean lp_rast_begin( struct lp_rasterizer *rast, - const struct pipe_framebuffer_state *fb, - boolean write_color, - boolean write_zstencil ) + struct lp_scene *scene ) { - struct pipe_screen *screen = rast->screen; - struct pipe_surface *cbuf, *zsbuf; + const struct pipe_framebuffer_state *fb = &scene->fb; + boolean write_color = fb->nr_cbufs != 0; + boolean write_zstencil = fb->zsbuf != NULL; int i; - LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); + rast->curr_scene = scene; - util_copy_framebuffer_state(&rast->state.fb, fb); + LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); + rast->state.nr_cbufs = scene->fb.nr_cbufs; rast->state.write_zstencil = write_zstencil; rast->state.write_color = write_color; - - rast->check_for_clipped_tiles = (fb->width % TILE_SIZE != 0 || - fb->height % TILE_SIZE != 0); - - for (i = 0; i < rast->state.fb.nr_cbufs; i++) { - cbuf = rast->state.fb.cbufs[i]; - if (cbuf) { - rast->cbuf_transfer[i] = screen->get_tex_transfer(rast->screen, - cbuf->texture, - cbuf->face, - cbuf->level, - cbuf->zslice, - PIPE_TRANSFER_READ_WRITE, - 0, 0, - cbuf->width, - cbuf->height); - if (!rast->cbuf_transfer[i]) - goto fail; - - rast->cbuf_map[i] = screen->transfer_map(rast->screen, - rast->cbuf_transfer[i]); - if (!rast->cbuf_map[i]) - goto fail; - } + for (i = 0; i < rast->state.nr_cbufs; i++) { + rast->cbuf[i].map = scene->cbuf_map[i]; + rast->cbuf[i].format = scene->cbuf_transfer[i]->texture->format; + rast->cbuf[i].width = scene->cbuf_transfer[i]->width; + rast->cbuf[i].height = scene->cbuf_transfer[i]->height; + rast->cbuf[i].stride = scene->cbuf_transfer[i]->stride; } - zsbuf = rast->state.fb.zsbuf; - if (zsbuf) { - rast->zsbuf_transfer = screen->get_tex_transfer(rast->screen, - zsbuf->texture, - zsbuf->face, - zsbuf->level, - zsbuf->zslice, - PIPE_TRANSFER_READ_WRITE, - 0, 0, - zsbuf->width, - zsbuf->height); - if (!rast->zsbuf_transfer) - goto fail; - - rast->zsbuf_map = screen->transfer_map(rast->screen, - rast->zsbuf_transfer); - if (!rast->zsbuf_map) - goto fail; + if (write_zstencil) { + rast->zsbuf.map = scene->zsbuf_map; + rast->zsbuf.stride = scene->zsbuf_transfer->stride; + rast->zsbuf.blocksize = + util_format_get_blocksize(scene->zsbuf_transfer->texture->format); } + lp_scene_bin_iter_begin( scene ); + return TRUE; - -fail: - /* Unmap and release transfers? - */ - return FALSE; } -/** - * Finish the rasterization phase. - * Unmap framebuffer surfaces. - */ static void lp_rast_end( struct lp_rasterizer *rast ) { - struct pipe_screen *screen = rast->screen; - unsigned i; - - for (i = 0; i < rast->state.fb.nr_cbufs; i++) { - if (rast->cbuf_map[i]) - screen->transfer_unmap(screen, rast->cbuf_transfer[i]); - - if (rast->cbuf_transfer[i]) - screen->tex_transfer_destroy(rast->cbuf_transfer[i]); - - rast->cbuf_transfer[i] = NULL; - rast->cbuf_map[i] = NULL; - } + int i; - if (rast->zsbuf_map) - screen->transfer_unmap(screen, rast->zsbuf_transfer); + lp_scene_reset( rast->curr_scene ); - if (rast->zsbuf_transfer) - screen->tex_transfer_destroy(rast->zsbuf_transfer); + for (i = 0; i < rast->state.nr_cbufs; i++) + rast->cbuf[i].map = NULL; - rast->zsbuf_transfer = NULL; - rast->zsbuf_map = NULL; + rast->zsbuf.map = NULL; + rast->curr_scene = NULL; } - /** * Begining rasterization of a tile. * \param x window X position of the tile, in pixels * \param y window Y position of the tile, in pixels */ static void -lp_rast_start_tile( struct lp_rasterizer *rast, - unsigned thread_index, - unsigned x, unsigned y ) +lp_rast_start_tile(struct lp_rasterizer_task *task, + unsigned x, unsigned y) { LP_DBG(DEBUG_RAST, "%s %d,%d\n", __FUNCTION__, x, y); - rast->tasks[thread_index].x = x; - rast->tasks[thread_index].y = y; + task->x = x; + task->y = y; } @@ -171,12 +116,13 @@ lp_rast_start_tile( struct lp_rasterizer *rast, * Clear the rasterizer's current color tile. * This is a bin command called during bin processing. */ -void lp_rast_clear_color( struct lp_rasterizer *rast, - unsigned thread_index, - const union lp_rast_cmd_arg arg ) +void +lp_rast_clear_color(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) { + struct lp_rasterizer *rast = task->rast; const uint8_t *clear_color = arg.clear_color; - uint8_t **color_tile = rast->tasks[thread_index].tile.color; + uint8_t **color_tile = task->tile.color; unsigned i; LP_DBG(DEBUG_RAST, "%s 0x%x,0x%x,0x%x,0x%x\n", __FUNCTION__, @@ -189,7 +135,7 @@ void lp_rast_clear_color( struct lp_rasterizer *rast, clear_color[1] == clear_color[2] && clear_color[2] == clear_color[3]) { /* clear to grayscale value {x, x, x, x} */ - for (i = 0; i < rast->state.fb.nr_cbufs; i++) { + for (i = 0; i < rast->state.nr_cbufs; i++) { memset(color_tile[i], clear_color[0], TILE_SIZE * TILE_SIZE * 4); } } @@ -200,7 +146,7 @@ void lp_rast_clear_color( struct lp_rasterizer *rast, * works. */ const unsigned chunk = TILE_SIZE / 4; - for (i = 0; i < rast->state.fb.nr_cbufs; i++) { + for (i = 0; i < rast->state.nr_cbufs; i++) { uint8_t *c = color_tile[i]; unsigned j; for (j = 0; j < 4 * TILE_SIZE; j++) { @@ -225,24 +171,24 @@ void lp_rast_clear_color( struct lp_rasterizer *rast, * Clear the rasterizer's current z/stencil tile. * This is a bin command called during bin processing. */ -void lp_rast_clear_zstencil( struct lp_rasterizer *rast, - unsigned thread_index, - const union lp_rast_cmd_arg arg) +void +lp_rast_clear_zstencil(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) { - struct lp_rasterizer_task *task = &rast->tasks[thread_index]; + struct lp_rasterizer *rast = task->rast; const unsigned tile_x = task->x; const unsigned tile_y = task->y; - const unsigned height = TILE_SIZE/TILE_VECTOR_HEIGHT; - const unsigned width = TILE_SIZE*TILE_VECTOR_HEIGHT; - unsigned block_size = util_format_get_blocksize(rast->zsbuf_transfer->texture->format); + const unsigned height = TILE_SIZE / TILE_VECTOR_HEIGHT; + const unsigned width = TILE_SIZE * TILE_VECTOR_HEIGHT; + unsigned block_size = rast->zsbuf.blocksize; uint8_t *dst; - unsigned dst_stride = rast->zsbuf_transfer->stride*TILE_VECTOR_HEIGHT; + unsigned dst_stride = rast->zsbuf.stride * TILE_VECTOR_HEIGHT; unsigned i, j; LP_DBG(DEBUG_RAST, "%s 0x%x\n", __FUNCTION__, arg.clear_zstencil); - assert(rast->zsbuf_map); - if (!rast->zsbuf_map) + assert(rast->zsbuf.map); + if (!rast->zsbuf.map) return; LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); @@ -278,8 +224,8 @@ void lp_rast_clear_zstencil( struct lp_rasterizer *rast, } break; default: - assert(0); - break; + assert(0); + break; } } @@ -288,55 +234,42 @@ void lp_rast_clear_zstencil( struct lp_rasterizer *rast, * Load tile color from the framebuffer surface. * This is a bin command called during bin processing. */ -void lp_rast_load_color( struct lp_rasterizer *rast, - unsigned thread_index, - const union lp_rast_cmd_arg arg) +void +lp_rast_load_color(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) { - struct lp_rasterizer_task *task = &rast->tasks[thread_index]; - const unsigned x = task->x; - const unsigned y = task->y; + struct lp_rasterizer *rast = task->rast; + const unsigned x = task->x, y = task->y; unsigned i; LP_DBG(DEBUG_RAST, "%s at %u, %u\n", __FUNCTION__, x, y); - for (i = 0; i < rast->state.fb.nr_cbufs; i++) { - struct pipe_transfer *transfer = rast->cbuf_transfer[i]; - int w = TILE_SIZE; - int h = TILE_SIZE; - - if (x >= transfer->width) - continue; - - if (y >= transfer->height) + for (i = 0; i < rast->state.nr_cbufs; i++) { + if (x >= rast->cbuf[i].width || y >= rast->cbuf[i].height) continue; - assert(w >= 0); - assert(h >= 0); - assert(w <= TILE_SIZE); - assert(h <= TILE_SIZE); - - lp_tile_read_4ub(transfer->texture->format, + lp_tile_read_4ub(rast->cbuf[i].format, task->tile.color[i], - rast->cbuf_map[i], - transfer->stride, + rast->cbuf[i].map, + rast->cbuf[i].stride, x, y, - w, h); + TILE_SIZE, TILE_SIZE); LP_COUNT(nr_color_tile_load); } } -void lp_rast_set_state( struct lp_rasterizer *rast, - unsigned thread_index, - const union lp_rast_cmd_arg arg ) +void +lp_rast_set_state(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) { const struct lp_rast_state *state = arg.set_state; LP_DBG(DEBUG_RAST, "%s %p\n", __FUNCTION__, (void *) state); /* just set the current state pointer for this rasterizer */ - rast->tasks[thread_index].current_state = state; + task->current_state = state; } @@ -346,16 +279,15 @@ void lp_rast_set_state( struct lp_rasterizer *rast, * completely contained inside a triangle. * This is a bin command called during bin processing. */ -void lp_rast_shade_tile( struct lp_rasterizer *rast, - unsigned thread_index, - const union lp_rast_cmd_arg arg ) +void +lp_rast_shade_tile(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) { - struct lp_rasterizer_task *task = &rast->tasks[thread_index]; + struct lp_rasterizer *rast = task->rast; const struct lp_rast_state *state = task->current_state; struct lp_rast_tile *tile = &task->tile; const struct lp_rast_shader_inputs *inputs = arg.shade_tile; - const unsigned tile_x = task->x; - const unsigned tile_y = task->y; + const unsigned tile_x = task->x, tile_y = task->y; unsigned x, y; LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); @@ -371,7 +303,7 @@ void lp_rast_shade_tile( struct lp_rasterizer *rast, block_offset = ((y / 4) * (16 * 16) + (x / 4) * 16); /* color buffer */ - for (i = 0; i < rast->state.fb.nr_cbufs; i++) + for (i = 0; i < rast->state.nr_cbufs; i++) color[i] = tile->color[i] + 4 * block_offset; /* depth buffer */ @@ -396,14 +328,13 @@ void lp_rast_shade_tile( struct lp_rasterizer *rast, * Compute shading for a 4x4 block of pixels. * This is a bin command called during bin processing. */ -void lp_rast_shade_quads( struct lp_rasterizer *rast, - unsigned thread_index, +void lp_rast_shade_quads( struct lp_rasterizer_task *task, const struct lp_rast_shader_inputs *inputs, unsigned x, unsigned y, int32_t c1, int32_t c2, int32_t c3) { - struct lp_rasterizer_task *task = &rast->tasks[thread_index]; const struct lp_rast_state *state = task->current_state; + struct lp_rasterizer *rast = task->rast; struct lp_rast_tile *tile = &task->tile; uint8_t *color[PIPE_MAX_COLOR_BUFS]; void *depth; @@ -411,7 +342,6 @@ void lp_rast_shade_quads( struct lp_rasterizer *rast, unsigned ix, iy; int block_offset; -#ifdef DEBUG assert(state); /* Sanity checks */ @@ -420,7 +350,6 @@ void lp_rast_shade_quads( struct lp_rasterizer *rast, assert((x % 4) == 0); assert((y % 4) == 0); -#endif ix = x % TILE_SIZE; iy = y % TILE_SIZE; @@ -429,22 +358,19 @@ void lp_rast_shade_quads( struct lp_rasterizer *rast, block_offset = ((iy / 4) * (16 * 16) + (ix / 4) * 16); /* color buffer */ - for (i = 0; i < rast->state.fb.nr_cbufs; i++) + for (i = 0; i < rast->state.nr_cbufs; i++) color[i] = tile->color[i] + 4 * block_offset; /* depth buffer */ depth = lp_rast_depth_pointer(rast, x, y); - -#ifdef DEBUG assert(lp_check_alignment(tile->color[0], 16)); assert(lp_check_alignment(state->jit_context.blend_color, 16)); assert(lp_check_alignment(inputs->step[0], 16)); assert(lp_check_alignment(inputs->step[1], 16)); assert(lp_check_alignment(inputs->step[2], 16)); -#endif /* run shader */ state->jit_function[1]( &state->jit_context, @@ -515,66 +441,48 @@ outline_subtiles(uint8_t *tile) /** * Write the rasterizer's color tile to the framebuffer. */ -static void lp_rast_store_color( struct lp_rasterizer *rast, - unsigned thread_index) +static void +lp_rast_store_color(struct lp_rasterizer_task *task) { - struct lp_rasterizer_task *task = &rast->tasks[thread_index]; - const unsigned x = task->x; - const unsigned y = task->y; + struct lp_rasterizer *rast = task->rast; + const unsigned x = task->x, y = task->y; unsigned i; - for (i = 0; i < rast->state.fb.nr_cbufs; i++) { - struct pipe_transfer *transfer = rast->cbuf_transfer[i]; - int w = TILE_SIZE; - int h = TILE_SIZE; - - if (x >= transfer->width) + for (i = 0; i < rast->state.nr_cbufs; i++) { + if (x >= rast->cbuf[i].width) continue; - if (y >= transfer->height) + if (y >= rast->cbuf[i].height) continue; - LP_DBG(DEBUG_RAST, "%s [%u] %d,%d %dx%d\n", __FUNCTION__, - thread_index, x, y, w, h); + LP_DBG(DEBUG_RAST, "%s [%u] %d,%d\n", __FUNCTION__, + task->thread_index, x, y); if (LP_DEBUG & DEBUG_SHOW_SUBTILES) outline_subtiles(task->tile.color[i]); else if (LP_DEBUG & DEBUG_SHOW_TILES) outline_tile(task->tile.color[i]); - lp_tile_write_4ub(transfer->texture->format, + lp_tile_write_4ub(rast->cbuf[i].format, task->tile.color[i], - rast->cbuf_map[i], - transfer->stride, + rast->cbuf[i].map, + rast->cbuf[i].stride, x, y, - w, h); + TILE_SIZE, TILE_SIZE); LP_COUNT(nr_color_tile_store); } } -/** - * Write the rasterizer's tiles to the framebuffer. - */ -static void -lp_rast_end_tile( struct lp_rasterizer *rast, - unsigned thread_index ) -{ - LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); - - if (rast->state.write_color) - lp_rast_store_color(rast, thread_index); -} - /** * Signal on a fence. This is called during bin execution/rasterization. * Called per thread. */ -void lp_rast_fence( struct lp_rasterizer *rast, - unsigned thread_index, - const union lp_rast_cmd_arg arg ) +void +lp_rast_fence(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) { struct lp_fence *fence = arg.fence; @@ -592,20 +500,6 @@ void lp_rast_fence( struct lp_rasterizer *rast, } -/** - * When all the threads are done rasterizing a scene, one thread will - * call this function to reset the scene and put it onto the empty queue. - */ -static void -release_scene( struct lp_rasterizer *rast, - struct lp_scene *scene ) -{ - util_unreference_framebuffer_state( &scene->fb ); - - lp_scene_reset( scene ); - lp_scene_enqueue( rast->empty_scenes, scene ); - rast->curr_scene = NULL; -} /** @@ -615,25 +509,31 @@ release_scene( struct lp_rasterizer *rast, * Called per thread. */ static void -rasterize_bin( struct lp_rasterizer *rast, - unsigned thread_index, - const struct cmd_bin *bin, - int x, int y) +rasterize_bin(struct lp_rasterizer_task *task, + const struct cmd_bin *bin, + int x, int y) { const struct cmd_block_list *commands = &bin->commands; struct cmd_block *block; unsigned k; - lp_rast_start_tile( rast, thread_index, x, y ); + lp_rast_start_tile( task, x * TILE_SIZE, y * TILE_SIZE ); /* simply execute each of the commands in the block list */ for (block = commands->head; block; block = block->next) { for (k = 0; k < block->count; k++) { - block->cmd[k]( rast, thread_index, block->arg[k] ); + block->cmd[k]( task, block->arg[k] ); } } - lp_rast_end_tile( rast, thread_index ); + /* Write the rasterizer's tiles to the framebuffer. + */ + if (task->rast->state.write_color) + lp_rast_store_color(task); + + /* Free data for this bin. + */ + lp_scene_bin_reset( task->rast->curr_scene, x, y); } @@ -717,10 +617,8 @@ is_empty_bin( const struct cmd_bin *bin ) * Called per thread. */ static void -rasterize_scene( struct lp_rasterizer *rast, - unsigned thread_index, - struct lp_scene *scene, - bool write_depth ) +rasterize_scene(struct lp_rasterizer_task *task, + struct lp_scene *scene) { /* loop over scene bins, rasterize each */ #if 0 @@ -728,9 +626,8 @@ rasterize_scene( struct lp_rasterizer *rast, unsigned i, j; for (i = 0; i < scene->tiles_x; i++) { for (j = 0; j < scene->tiles_y; j++) { - struct cmd_bin *bin = lp_get_bin(scene, i, j); - rasterize_bin( rast, thread_index, - bin, i * TILE_SIZE, j * TILE_SIZE ); + struct cmd_bin *bin = lp_scene_get_bin(scene, i, j); + rasterize_bin(task, bin, i, j); } } } @@ -742,7 +639,7 @@ rasterize_scene( struct lp_rasterizer *rast, assert(scene); while ((bin = lp_scene_bin_iter_next(scene, &x, &y))) { if (!is_empty_bin( bin )) - rasterize_bin( rast, thread_index, bin, x * TILE_SIZE, y * TILE_SIZE); + rasterize_bin(task, bin, x, y); } } #endif @@ -753,44 +650,20 @@ rasterize_scene( struct lp_rasterizer *rast, * Called by setup module when it has something for us to render. */ void -lp_rasterize_scene( struct lp_rasterizer *rast, - struct lp_scene *scene, - const struct pipe_framebuffer_state *fb, - bool write_depth ) +lp_rast_queue_scene( struct lp_rasterizer *rast, + struct lp_scene *scene) { - boolean debug = false; - LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); - if (debug) { - unsigned x, y; - debug_printf("rasterize scene:\n"); - debug_printf(" data size: %u\n", lp_scene_data_size(scene)); - for (y = 0; y < scene->tiles_y; y++) { - for (x = 0; x < scene->tiles_x; x++) { - debug_printf(" bin %u, %u size: %u\n", x, y, - lp_scene_bin_size(scene, x, y)); - } - } - } - - /* save framebuffer state in the bin */ - util_copy_framebuffer_state(&scene->fb, fb); - scene->write_depth = write_depth; - if (rast->num_threads == 0) { /* no threading */ - lp_rast_begin( rast, fb, - fb->nr_cbufs != 0, /* always write color if cbufs present */ - fb->zsbuf != NULL && write_depth ); + lp_rast_begin( rast, scene ); - lp_scene_bin_iter_begin( scene ); - rasterize_scene( rast, 0, scene, write_depth ); + rasterize_scene( &rast->tasks[0], scene ); - release_scene( rast, scene ); - - lp_rast_end( rast ); + lp_scene_reset( scene ); + rast->curr_scene = NULL; } else { /* threaded rendering! */ @@ -802,14 +675,26 @@ lp_rasterize_scene( struct lp_rasterizer *rast, for (i = 0; i < rast->num_threads; i++) { pipe_semaphore_signal(&rast->tasks[i].work_ready); } + } + + LP_DBG(DEBUG_SETUP, "%s done \n", __FUNCTION__); +} + + +void +lp_rast_finish( struct lp_rasterizer *rast ) +{ + if (rast->num_threads == 0) { + /* nothing to do */ + } + else { + int i; /* wait for work to complete */ for (i = 0; i < rast->num_threads; i++) { pipe_semaphore_wait(&rast->tasks[i].work_done); } } - - LP_DBG(DEBUG_SETUP, "%s done \n", __FUNCTION__); } @@ -832,24 +717,16 @@ static PIPE_THREAD_ROUTINE( thread_func, init_data ) debug_printf("thread %d waiting for work\n", task->thread_index); pipe_semaphore_wait(&task->work_ready); + if (rast->exit_flag) + break; + if (task->thread_index == 0) { /* thread[0]: * - get next scene to rasterize * - map the framebuffer surfaces */ - const struct pipe_framebuffer_state *fb; - boolean write_depth; - - rast->curr_scene = lp_scene_dequeue( rast->full_scenes, TRUE ); - - lp_scene_bin_iter_begin( rast->curr_scene ); - - fb = &rast->curr_scene->fb; - write_depth = rast->curr_scene->write_depth; - - lp_rast_begin( rast, fb, - fb->nr_cbufs != 0, - fb->zsbuf != NULL && write_depth ); + lp_rast_begin( rast, + lp_scene_dequeue( rast->full_scenes, TRUE ) ); } /* Wait for all threads to get here so that threads[1+] don't @@ -860,26 +737,23 @@ static PIPE_THREAD_ROUTINE( thread_func, init_data ) /* do work */ if (debug) debug_printf("thread %d doing work\n", task->thread_index); - rasterize_scene(rast, - task->thread_index, - rast->curr_scene, - rast->curr_scene->write_depth); + + rasterize_scene(task, + rast->curr_scene); /* wait for all threads to finish with this scene */ pipe_barrier_wait( &rast->barrier ); + /* XXX: shouldn't be necessary: + */ if (task->thread_index == 0) { - /* thread[0]: - * - release the scene object - * - unmap the framebuffer surfaces - */ - release_scene( rast, rast->curr_scene ); lp_rast_end( rast ); } /* signal done with work */ if (debug) debug_printf("thread %d done working\n", task->thread_index); + pipe_semaphore_signal(&task->work_done); } @@ -922,7 +796,7 @@ create_rast_threads(struct lp_rasterizer *rast) * processing them. */ struct lp_rasterizer * -lp_rast_create( struct pipe_screen *screen, struct lp_scene_queue *empty ) +lp_rast_create( void ) { struct lp_rasterizer *rast; unsigned i, cbuf; @@ -931,9 +805,6 @@ lp_rast_create( struct pipe_screen *screen, struct lp_scene_queue *empty ) if(!rast) return NULL; - rast->screen = screen; - - rast->empty_scenes = empty; rast->full_scenes = lp_scene_queue_create(); for (i = 0; i < Elements(rast->tasks); i++) { @@ -961,13 +832,31 @@ void lp_rast_destroy( struct lp_rasterizer *rast ) { unsigned i, cbuf; - util_unreference_framebuffer_state(&rast->state.fb); - for (i = 0; i < Elements(rast->tasks); i++) { for (cbuf = 0; cbuf < PIPE_MAX_COLOR_BUFS; cbuf++ ) align_free(rast->tasks[i].tile.color[cbuf]); } + /* Set exit_flag and signal each thread's work_ready semaphore. + * Each thread will be woken up, notice that the exit_flag is set and + * break out of its main loop. The thread will then exit. + */ + rast->exit_flag = TRUE; + for (i = 0; i < rast->num_threads; i++) { + pipe_semaphore_signal(&rast->tasks[i].work_ready); + } + + /* Wait for threads to terminate before cleaning up per-thread data */ + for (i = 0; i < rast->num_threads; i++) { + pipe_thread_wait(rast->threads[i]); + } + + /* Clean up per-thread data */ + for (i = 0; i < rast->num_threads; i++) { + pipe_semaphore_destroy(&rast->tasks[i].work_ready); + pipe_semaphore_destroy(&rast->tasks[i].work_done); + } + /* for synchronizing rasterization threads */ pipe_barrier_destroy( &rast->barrier ); diff --git a/src/gallium/drivers/llvmpipe/lp_rast.h b/src/gallium/drivers/llvmpipe/lp_rast.h index 875f18e0c0c..dc5fc5fc7d6 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast.h +++ b/src/gallium/drivers/llvmpipe/lp_rast.h @@ -43,16 +43,17 @@ struct lp_rasterizer; struct lp_scene; -struct lp_scene_queue; struct lp_fence; struct cmd_bin; -struct pipe_screen; /** For sub-pixel positioning */ #define FIXED_ORDER 4 #define FIXED_ONE (1<<FIXED_ORDER) +struct lp_rasterizer_task; + + /** * Rasterization state. * Objects of this type are put into the shared data bin and pointed @@ -97,6 +98,10 @@ struct lp_rast_shader_inputs { * Objects of this type are put into the setup_context::data buffer. */ struct lp_rast_triangle { +#ifdef DEBUG + float v[3][2]; +#endif + /* one-pixel sized trivial accept offsets for each plane */ int ei1; int ei2; @@ -126,18 +131,21 @@ struct lp_rast_triangle { -struct lp_rasterizer *lp_rast_create( struct pipe_screen *screen, - struct lp_scene_queue *empty ); +struct lp_rasterizer * +lp_rast_create( void ); -void lp_rast_destroy( struct lp_rasterizer * ); +void +lp_rast_destroy( struct lp_rasterizer * ); -unsigned lp_rast_get_num_threads( struct lp_rasterizer * ); +unsigned +lp_rast_get_num_threads( struct lp_rasterizer * ); -void lp_rasterize_scene( struct lp_rasterizer *rast, - struct lp_scene *scene, - const struct pipe_framebuffer_state *fb, - bool write_depth ); +void +lp_rast_queue_scene( struct lp_rasterizer *rast, + struct lp_scene *scene ); +void +lp_rast_finish( struct lp_rasterizer *rast ); union lp_rast_cmd_arg { @@ -201,32 +209,25 @@ lp_rast_arg_null( void ) * the bins are executed. */ -void lp_rast_clear_color( struct lp_rasterizer *, - unsigned thread_index, +void lp_rast_clear_color( struct lp_rasterizer_task *, const union lp_rast_cmd_arg ); -void lp_rast_clear_zstencil( struct lp_rasterizer *, - unsigned thread_index, +void lp_rast_clear_zstencil( struct lp_rasterizer_task *, const union lp_rast_cmd_arg ); -void lp_rast_load_color( struct lp_rasterizer *, - unsigned thread_index, +void lp_rast_load_color( struct lp_rasterizer_task *, const union lp_rast_cmd_arg ); -void lp_rast_set_state( struct lp_rasterizer *, - unsigned thread_index, +void lp_rast_set_state( struct lp_rasterizer_task *, const union lp_rast_cmd_arg ); -void lp_rast_triangle( struct lp_rasterizer *, - unsigned thread_index, +void lp_rast_triangle( struct lp_rasterizer_task *, const union lp_rast_cmd_arg ); -void lp_rast_shade_tile( struct lp_rasterizer *, - unsigned thread_index, +void lp_rast_shade_tile( struct lp_rasterizer_task *, const union lp_rast_cmd_arg ); -void lp_rast_fence( struct lp_rasterizer *, - unsigned thread_index, +void lp_rast_fence( struct lp_rasterizer_task *, const union lp_rast_cmd_arg ); #endif diff --git a/src/gallium/drivers/llvmpipe/lp_rast_priv.h b/src/gallium/drivers/llvmpipe/lp_rast_priv.h index 5c5497e0929..39bf2c25879 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast_priv.h +++ b/src/gallium/drivers/llvmpipe/lp_rast_priv.h @@ -38,8 +38,6 @@ #define MAX_THREADS 8 /* XXX probably temporary here */ -struct pipe_transfer; -struct pipe_screen; struct lp_rasterizer; @@ -82,19 +80,26 @@ struct lp_rasterizer_task */ struct lp_rasterizer { - boolean clipped_tile; - boolean check_for_clipped_tiles; + boolean exit_flag; /* Framebuffer stuff */ - struct pipe_screen *screen; - struct pipe_transfer *cbuf_transfer[PIPE_MAX_COLOR_BUFS]; - struct pipe_transfer *zsbuf_transfer; - void *cbuf_map[PIPE_MAX_COLOR_BUFS]; - uint8_t *zsbuf_map; + struct { + void *map; + unsigned stride; + unsigned width; + unsigned height; + enum pipe_format format; + } cbuf[PIPE_MAX_COLOR_BUFS]; + + struct { + uint8_t *map; + unsigned stride; + unsigned blocksize; + } zsbuf; struct { - struct pipe_framebuffer_state fb; + unsigned nr_cbufs; boolean write_color; boolean write_zstencil; unsigned clear_color; @@ -104,7 +109,14 @@ struct lp_rasterizer /** The incoming queue of scenes ready to rasterize */ struct lp_scene_queue *full_scenes; - /** The outgoing queue of processed scenes to return to setup modulee */ + + /** + * The outgoing queue of processed scenes to return to setup module + * + * XXX: while scenes are per-context but the rasterizer is + * (potentially) shared, these empty scenes should be returned to + * the context which created them rather than retained here. + */ struct lp_scene_queue *empty_scenes; /** The scene currently being rasterized by the threads */ @@ -121,8 +133,7 @@ struct lp_rasterizer }; -void lp_rast_shade_quads( struct lp_rasterizer *rast, - unsigned thread_index, +void lp_rast_shade_quads( struct lp_rasterizer_task *task, const struct lp_rast_shader_inputs *inputs, unsigned x, unsigned y, int32_t c1, int32_t c2, int32_t c3); @@ -137,17 +148,18 @@ lp_rast_depth_pointer( struct lp_rasterizer *rast, unsigned x, unsigned y ) { void * depth; + assert((x % TILE_VECTOR_WIDTH) == 0); assert((y % TILE_VECTOR_HEIGHT) == 0); - if(!rast->zsbuf_map) + + if (!rast->zsbuf.map) return NULL; - assert(rast->zsbuf_transfer); - depth = rast->zsbuf_map + - y*rast->zsbuf_transfer->stride + - TILE_VECTOR_HEIGHT*x*util_format_get_blocksize(rast->zsbuf_transfer->texture->format); -#ifdef DEBUG + + depth = (rast->zsbuf.map + + rast->zsbuf.stride * y + + rast->zsbuf.blocksize * x * TILE_VECTOR_HEIGHT); + assert(lp_check_alignment(depth, 16)); -#endif return depth; } @@ -159,13 +171,13 @@ lp_rast_depth_pointer( struct lp_rasterizer *rast, * \param x, y location of 4x4 block in window coords */ static INLINE void -lp_rast_shade_quads_all( struct lp_rasterizer *rast, - unsigned thread_index, +lp_rast_shade_quads_all( struct lp_rasterizer_task *task, const struct lp_rast_shader_inputs *inputs, unsigned x, unsigned y ) { - const struct lp_rast_state *state = rast->tasks[thread_index].current_state; - struct lp_rast_tile *tile = &rast->tasks[thread_index].tile; + struct lp_rasterizer *rast = task->rast; + const struct lp_rast_state *state = task->current_state; + struct lp_rast_tile *tile = &task->tile; const unsigned ix = x % TILE_SIZE, iy = y % TILE_SIZE; uint8_t *color[PIPE_MAX_COLOR_BUFS]; void *depth; @@ -175,7 +187,7 @@ lp_rast_shade_quads_all( struct lp_rasterizer *rast, block_offset = (iy / 4) * (16 * 16) + (ix / 4) * 16; /* color buffer */ - for (i = 0; i < rast->state.fb.nr_cbufs; i++) + for (i = 0; i < rast->state.nr_cbufs; i++) color[i] = tile->color[i] + 4 * block_offset; depth = lp_rast_depth_pointer(rast, x, y); diff --git a/src/gallium/drivers/llvmpipe/lp_rast_tri.c b/src/gallium/drivers/llvmpipe/lp_rast_tri.c index 3f76f159df1..a5f0d14c95d 100644 --- a/src/gallium/drivers/llvmpipe/lp_rast_tri.c +++ b/src/gallium/drivers/llvmpipe/lp_rast_tri.c @@ -89,14 +89,11 @@ static const int pos_table16[16][2] = { * Shade all pixels in a 4x4 block. */ static void -block_full_4( struct lp_rasterizer_task *rast_task, - const struct lp_rast_triangle *tri, - int x, int y ) +block_full_4(struct lp_rasterizer_task *task, + const struct lp_rast_triangle *tri, + int x, int y) { - lp_rast_shade_quads_all(rast_task->rast, - rast_task->thread_index, - &tri->inputs, - x, y); + lp_rast_shade_quads_all(task, &tri->inputs, x, y); } @@ -104,16 +101,16 @@ block_full_4( struct lp_rasterizer_task *rast_task, * Shade all pixels in a 16x16 block. */ static void -block_full_16( struct lp_rasterizer_task *rast_task, - const struct lp_rast_triangle *tri, - int x, int y ) +block_full_16(struct lp_rasterizer_task *task, + const struct lp_rast_triangle *tri, + int x, int y) { unsigned ix, iy; assert(x % 16 == 0); assert(y % 16 == 0); for (iy = 0; iy < 16; iy += 4) for (ix = 0; ix < 16; ix += 4) - block_full_4(rast_task, tri, x + ix, y + iy); + block_full_4(task, tri, x + ix, y + iy); } @@ -123,18 +120,15 @@ block_full_16( struct lp_rasterizer_task *rast_task, * will be done as part of the fragment shader. */ static void -do_block_4( struct lp_rasterizer_task *rast_task, - const struct lp_rast_triangle *tri, - int x, int y, - int c1, - int c2, - int c3 ) +do_block_4(struct lp_rasterizer_task *task, + const struct lp_rast_triangle *tri, + int x, int y, + int c1, int c2, int c3) { - lp_rast_shade_quads(rast_task->rast, - rast_task->thread_index, - &tri->inputs, - x, y, - -c1, -c2, -c3); + assert(x >= 0); + assert(y >= 0); + + lp_rast_shade_quads(task, &tri->inputs, x, y, -c1, -c2, -c3); } @@ -143,45 +137,58 @@ do_block_4( struct lp_rasterizer_task *rast_task, * of the triangle's bounds. */ static void -do_block_16( struct lp_rasterizer_task *rast_task, - const struct lp_rast_triangle *tri, - int x, int y, - int c1, - int c2, - int c3 ) +do_block_16(struct lp_rasterizer_task *task, + const struct lp_rast_triangle *tri, + int x, int y, + int c0, int c1, int c2) { - const int eo1 = tri->eo1 * 4; - const int eo2 = tri->eo2 * 4; - const int eo3 = tri->eo3 * 4; - const int *step0 = tri->inputs.step[0]; - const int *step1 = tri->inputs.step[1]; - const int *step2 = tri->inputs.step[2]; - int i; + unsigned mask = 0; + int eo[3]; + int c[3]; + int i, j; + assert(x >= 0); + assert(y >= 0); assert(x % 16 == 0); assert(y % 16 == 0); - for (i = 0; i < 16; i++) { - int cx1 = c1 + step0[i] * 4; - int cx2 = c2 + step1[i] * 4; - int cx3 = c3 + step2[i] * 4; + eo[0] = tri->eo1 * 4; + eo[1] = tri->eo2 * 4; + eo[2] = tri->eo3 * 4; - if (cx1 + eo1 < 0 || - cx2 + eo2 < 0 || - cx3 + eo3 < 0) { - /* the block is completely outside the triangle - nop */ - LP_COUNT(nr_empty_4); - } - else { - int px = x + pos_table4[i][0]; - int py = y + pos_table4[i][1]; - /* Don't bother testing if the 4x4 block is entirely in/out of - * the triangle. It's a little faster to do it in the jit code. - */ - LP_COUNT(nr_non_empty_4); - do_block_4(rast_task, tri, px, py, cx1, cx2, cx3); + c[0] = c0; + c[1] = c1; + c[2] = c2; + + for (j = 0; j < 3; j++) { + const int *step = tri->inputs.step[j]; + const int cx = c[j] + eo[j]; + + /* Mask has bits set whenever we are outside any of the edges. + */ + for (i = 0; i < 16; i++) { + int out = cx + step[i] * 4; + mask |= (out >> 31) & (1 << i); } } + + mask = ~mask & 0xffff; + while (mask) { + int i = ffs(mask) - 1; + int px = x + pos_table4[i][0]; + int py = y + pos_table4[i][1]; + int cx1 = c0 + tri->inputs.step[0][i] * 4; + int cx2 = c1 + tri->inputs.step[1][i] * 4; + int cx3 = c2 + tri->inputs.step[2][i] * 4; + + mask &= ~(1 << i); + + /* Don't bother testing if the 4x4 block is entirely in/out of + * the triangle. It's a little faster to do it in the jit code. + */ + LP_COUNT(nr_non_empty_4); + do_block_4(task, tri, px, py, cx1, cx2, cx3); + } } @@ -190,62 +197,84 @@ do_block_16( struct lp_rasterizer_task *rast_task, * for this triangle. */ void -lp_rast_triangle( struct lp_rasterizer *rast, - unsigned thread_index, - const union lp_rast_cmd_arg arg ) +lp_rast_triangle(struct lp_rasterizer_task *task, + const union lp_rast_cmd_arg arg) { - struct lp_rasterizer_task *rast_task = &rast->tasks[thread_index]; const struct lp_rast_triangle *tri = arg.triangle; + const int x = task->x, y = task->y; + int ei[3], eo[3], c[3]; + unsigned outmask, inmask, partial_mask; + unsigned i, j; - int x = rast_task->x; - int y = rast_task->y; - unsigned i; + c[0] = tri->c1 + tri->dx12 * y - tri->dy12 * x; + c[1] = tri->c2 + tri->dx23 * y - tri->dy23 * x; + c[2] = tri->c3 + tri->dx31 * y - tri->dy31 * x; - int c1 = tri->c1 + tri->dx12 * y - tri->dy12 * x; - int c2 = tri->c2 + tri->dx23 * y - tri->dy23 * x; - int c3 = tri->c3 + tri->dx31 * y - tri->dy31 * x; + eo[0] = tri->eo1 * 16; + eo[1] = tri->eo2 * 16; + eo[2] = tri->eo3 * 16; - int ei1 = tri->ei1 * 16; - int ei2 = tri->ei2 * 16; - int ei3 = tri->ei3 * 16; + ei[0] = tri->ei1 * 16; + ei[1] = tri->ei2 * 16; + ei[2] = tri->ei3 * 16; - int eo1 = tri->eo1 * 16; - int eo2 = tri->eo2 * 16; - int eo3 = tri->eo3 * 16; + outmask = 0; + inmask = 0xffff; - LP_DBG(DEBUG_RAST, "lp_rast_triangle\n"); + for (j = 0; j < 3; j++) { + const int *step = tri->inputs.step[j]; + const int cox = c[j] + eo[j]; + const int cio = ei[j]- eo[j]; - /* Walk over the tile to build a list of 4x4 pixel blocks which will - * be filled/shaded. We do this at two granularities: 16x16 blocks - * and then 4x4 blocks. - */ - for (i = 0; i < 16; i++) { - int cx1 = c1 + (tri->inputs.step[0][i] * 16); - int cx2 = c2 + (tri->inputs.step[1][i] * 16); - int cx3 = c3 + (tri->inputs.step[2][i] * 16); - - if (cx1 + eo1 < 0 || - cx2 + eo2 < 0 || - cx3 + eo3 < 0) { - /* the block is completely outside the triangle - nop */ - LP_COUNT(nr_empty_16); - } - else { - int px = x + pos_table16[i][0]; - int py = y + pos_table16[i][1]; - - if (cx1 + ei1 > 0 && - cx2 + ei2 > 0 && - cx3 + ei3 > 0) { - /* the block is completely inside the triangle */ - LP_COUNT(nr_fully_covered_16); - block_full_16(rast_task, tri, px, py); - } - else { - /* the block is partially in/out of the triangle */ - LP_COUNT(nr_partially_covered_16); - do_block_16(rast_task, tri, px, py, cx1, cx2, cx3); - } + /* Outmask has bits set whenever we are outside any of the + * edges. + */ + /* Inmask has bits set whenever we are inside all of the edges. + */ + for (i = 0; i < 16; i++) { + int out = cox + step[i] * 16; + int in = out + cio; + outmask |= (out >> 31) & (1 << i); + inmask &= ~((in >> 31) & (1 << i)); } } + + assert((outmask & inmask) == 0); + + if (outmask == 0xffff) + return; + + /* Invert mask, so that bits are set whenever we are at least + * partially inside all of the edges: + */ + partial_mask = ~inmask & ~outmask & 0xffff; + + /* Iterate over partials: + */ + while (partial_mask) { + int i = ffs(partial_mask) - 1; + int px = x + pos_table16[i][0]; + int py = y + pos_table16[i][1]; + int cx1 = c[0] + tri->inputs.step[0][i] * 16; + int cx2 = c[1] + tri->inputs.step[1][i] * 16; + int cx3 = c[2] + tri->inputs.step[2][i] * 16; + + partial_mask &= ~(1 << i); + + LP_COUNT(nr_partially_covered_16); + do_block_16(task, tri, px, py, cx1, cx2, cx3); + } + + /* Iterate over fulls: + */ + while (inmask) { + int i = ffs(inmask) - 1; + int px = x + pos_table16[i][0]; + int py = y + pos_table16[i][1]; + + inmask &= ~(1 << i); + + LP_COUNT(nr_fully_covered_16); + block_full_16(task, tri, px, py); + } } diff --git a/src/gallium/drivers/llvmpipe/lp_scene.c b/src/gallium/drivers/llvmpipe/lp_scene.c index b7116297ece..72492c0f0ca 100644 --- a/src/gallium/drivers/llvmpipe/lp_scene.c +++ b/src/gallium/drivers/llvmpipe/lp_scene.c @@ -29,44 +29,67 @@ #include "util/u_memory.h" #include "util/u_inlines.h" #include "util/u_simple_list.h" +#include "util/u_surface.h" #include "lp_scene.h" +#include "lp_scene_queue.h" +#include "lp_debug.h" struct lp_scene * -lp_scene_create(void) +lp_scene_create( struct pipe_context *pipe, + struct lp_scene_queue *queue ) { + unsigned i, j; struct lp_scene *scene = CALLOC_STRUCT(lp_scene); - if (scene) - lp_scene_init(scene); + if (!scene) + return NULL; + + scene->pipe = pipe; + scene->empty_queue = queue; + + for (i = 0; i < TILES_X; i++) { + for (j = 0; j < TILES_Y; j++) { + struct cmd_bin *bin = lp_scene_get_bin(scene, i, j); + bin->commands.head = bin->commands.tail = CALLOC_STRUCT(cmd_block); + } + } + + scene->data.head = + scene->data.tail = CALLOC_STRUCT(data_block); + + make_empty_list(&scene->textures); + + pipe_mutex_init(scene->mutex); + return scene; } +/** + * Free all data associated with the given scene, and free(scene). + */ void lp_scene_destroy(struct lp_scene *scene) { - lp_scene_reset(scene); - lp_scene_free_bin_data(scene); - FREE(scene); -} + unsigned i, j; + lp_scene_reset(scene); -void -lp_scene_init(struct lp_scene *scene) -{ - unsigned i, j; for (i = 0; i < TILES_X; i++) for (j = 0; j < TILES_Y; j++) { struct cmd_bin *bin = lp_scene_get_bin(scene, i, j); - bin->commands.head = bin->commands.tail = CALLOC_STRUCT(cmd_block); + assert(bin->commands.head == bin->commands.tail); + FREE(bin->commands.head); + bin->commands.head = NULL; + bin->commands.tail = NULL; } - scene->data.head = - scene->data.tail = CALLOC_STRUCT(data_block); + FREE(scene->data.head); + scene->data.head = NULL; - make_empty_list(&scene->textures); + pipe_mutex_destroy(scene->mutex); - pipe_mutex_init(scene->mutex); + FREE(scene); } @@ -92,6 +115,9 @@ lp_scene_is_empty(struct lp_scene *scene ) } +/* Free data for one particular bin. May be called from the + * rasterizer thread(s). + */ void lp_scene_bin_reset(struct lp_scene *scene, unsigned x, unsigned y) { @@ -100,6 +126,9 @@ lp_scene_bin_reset(struct lp_scene *scene, unsigned x, unsigned y) struct cmd_block *block; struct cmd_block *tmp; + assert(x < TILES_X); + assert(y < TILES_Y); + for (block = list->head; block != list->tail; block = tmp) { tmp = block->next; FREE(block); @@ -112,7 +141,8 @@ lp_scene_bin_reset(struct lp_scene *scene, unsigned x, unsigned y) /** - * Set scene to empty state. + * Free all the temporary data in a scene. May be called from the + * rasterizer thread(s). */ void lp_scene_reset(struct lp_scene *scene ) @@ -159,40 +189,8 @@ lp_scene_reset(struct lp_scene *scene ) } -/** - * Free all data associated with the given bin, but don't free(scene). - */ -void -lp_scene_free_bin_data(struct lp_scene *scene) -{ - unsigned i, j; - for (i = 0; i < TILES_X; i++) - for (j = 0; j < TILES_Y; j++) { - struct cmd_bin *bin = lp_scene_get_bin(scene, i, j); - /* lp_reset_scene() should have been already called */ - assert(bin->commands.head == bin->commands.tail); - FREE(bin->commands.head); - bin->commands.head = NULL; - bin->commands.tail = NULL; - } - FREE(scene->data.head); - scene->data.head = NULL; - - pipe_mutex_destroy(scene->mutex); -} - - -void -lp_scene_set_framebuffer_size( struct lp_scene *scene, - unsigned width, unsigned height ) -{ - assert(lp_scene_is_empty(scene)); - - scene->tiles_x = align(width, TILE_SIZE) / TILE_SIZE; - scene->tiles_y = align(height, TILE_SIZE) / TILE_SIZE; -} void @@ -390,3 +388,158 @@ end: pipe_mutex_unlock(scene->mutex); return bin; } + + +/** + * Prepare this scene for the rasterizer. + * Map the framebuffer surfaces. Initialize the 'rast' state. + */ +static boolean +lp_scene_map_buffers( struct lp_scene *scene ) +{ + struct pipe_screen *screen = scene->pipe->screen; + struct pipe_surface *cbuf, *zsbuf; + int i; + + LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); + + + /* Map all color buffers + */ + for (i = 0; i < scene->fb.nr_cbufs; i++) { + cbuf = scene->fb.cbufs[i]; + if (cbuf) { + scene->cbuf_transfer[i] = screen->get_tex_transfer(screen, + cbuf->texture, + cbuf->face, + cbuf->level, + cbuf->zslice, + PIPE_TRANSFER_READ_WRITE, + 0, 0, + cbuf->width, + cbuf->height); + if (!scene->cbuf_transfer[i]) + goto fail; + + scene->cbuf_map[i] = screen->transfer_map(screen, + scene->cbuf_transfer[i]); + if (!scene->cbuf_map[i]) + goto fail; + } + } + + /* Map the zsbuffer + */ + zsbuf = scene->fb.zsbuf; + if (zsbuf) { + scene->zsbuf_transfer = screen->get_tex_transfer(screen, + zsbuf->texture, + zsbuf->face, + zsbuf->level, + zsbuf->zslice, + PIPE_TRANSFER_READ_WRITE, + 0, 0, + zsbuf->width, + zsbuf->height); + if (!scene->zsbuf_transfer) + goto fail; + + scene->zsbuf_map = screen->transfer_map(screen, + scene->zsbuf_transfer); + if (!scene->zsbuf_map) + goto fail; + } + + return TRUE; + +fail: + /* Unmap and release transfers? + */ + return FALSE; +} + + + +/** + * Called after rasterizer as finished rasterizing a scene. + * + * We want to call this from the pipe_context's current thread to + * avoid having to have mutexes on the transfer functions. + */ +static void +lp_scene_unmap_buffers( struct lp_scene *scene ) +{ + struct pipe_screen *screen = scene->pipe->screen; + unsigned i; + + for (i = 0; i < scene->fb.nr_cbufs; i++) { + if (scene->cbuf_map[i]) + screen->transfer_unmap(screen, scene->cbuf_transfer[i]); + + if (scene->cbuf_transfer[i]) + screen->tex_transfer_destroy(scene->cbuf_transfer[i]); + + scene->cbuf_transfer[i] = NULL; + scene->cbuf_map[i] = NULL; + } + + if (scene->zsbuf_map) + screen->transfer_unmap(screen, scene->zsbuf_transfer); + + if (scene->zsbuf_transfer) + screen->tex_transfer_destroy(scene->zsbuf_transfer); + + scene->zsbuf_transfer = NULL; + scene->zsbuf_map = NULL; + + util_unreference_framebuffer_state( &scene->fb ); +} + + +void lp_scene_begin_binning( struct lp_scene *scene, + struct pipe_framebuffer_state *fb ) +{ + assert(lp_scene_is_empty(scene)); + + util_copy_framebuffer_state(&scene->fb, fb); + + scene->tiles_x = align(fb->width, TILE_SIZE) / TILE_SIZE; + scene->tiles_y = align(fb->height, TILE_SIZE) / TILE_SIZE; +} + + +void lp_scene_rasterize( struct lp_scene *scene, + struct lp_rasterizer *rast, + boolean write_depth ) +{ + if (0) { + unsigned x, y; + debug_printf("rasterize scene:\n"); + debug_printf(" data size: %u\n", lp_scene_data_size(scene)); + for (y = 0; y < scene->tiles_y; y++) { + for (x = 0; x < scene->tiles_x; x++) { + debug_printf(" bin %u, %u size: %u\n", x, y, + lp_scene_bin_size(scene, x, y)); + } + } + } + + + scene->write_depth = (scene->fb.zsbuf != NULL && + write_depth); + + lp_scene_map_buffers( scene ); + + /* Enqueue the scene for rasterization, then immediately wait for + * it to finish. + */ + lp_rast_queue_scene( rast, scene ); + + /* Currently just wait for the rasterizer to finish. Some + * threading interactions need to be worked out, particularly once + * transfers become per-context: + */ + lp_rast_finish( rast ); + lp_scene_unmap_buffers( scene ); + lp_scene_enqueue( scene->empty_queue, scene ); +} diff --git a/src/gallium/drivers/llvmpipe/lp_scene.h b/src/gallium/drivers/llvmpipe/lp_scene.h index fb478cc2eb5..739ac229089 100644 --- a/src/gallium/drivers/llvmpipe/lp_scene.h +++ b/src/gallium/drivers/llvmpipe/lp_scene.h @@ -39,6 +39,7 @@ #include "lp_tile_soa.h" #include "lp_rast.h" +struct lp_scene_queue; /* We're limited to 2K by 2K for 32bit fixed point rasterization. * Will need a 64-bit version for larger framebuffers. @@ -56,8 +57,7 @@ /* switch to a non-pointer value for this: */ -typedef void (*lp_rast_cmd)( struct lp_rasterizer *, - unsigned thread_index, +typedef void (*lp_rast_cmd)( struct lp_rasterizer_task *, const union lp_rast_cmd_arg ); struct cmd_block { @@ -113,8 +113,14 @@ struct texture_ref { * scenes: */ struct lp_scene { - struct cmd_bin tile[TILES_X][TILES_Y]; - struct data_block_list data; + struct pipe_context *pipe; + struct pipe_transfer *cbuf_transfer[PIPE_MAX_COLOR_BUFS]; + struct pipe_transfer *zsbuf_transfer; + + /* Scene's buffers are mapped at the time the scene is enqueued: + */ + void *cbuf_map[PIPE_MAX_COLOR_BUFS]; + uint8_t *zsbuf_map; /** the framebuffer to render the scene into */ struct pipe_framebuffer_state fb; @@ -132,25 +138,28 @@ struct lp_scene { int curr_x, curr_y; /**< for iterating over bins */ pipe_mutex mutex; + + /* Where to place this scene once it has been rasterized: + */ + struct lp_scene_queue *empty_queue; + + struct cmd_bin tile[TILES_X][TILES_Y]; + struct data_block_list data; }; -struct lp_scene *lp_scene_create(void); +struct lp_scene *lp_scene_create(struct pipe_context *pipe, + struct lp_scene_queue *empty_queue); void lp_scene_destroy(struct lp_scene *scene); -void lp_scene_init(struct lp_scene *scene); boolean lp_scene_is_empty(struct lp_scene *scene ); void lp_scene_reset(struct lp_scene *scene ); -void lp_scene_free_bin_data(struct lp_scene *scene); - -void lp_scene_set_framebuffer_size( struct lp_scene *scene, - unsigned width, unsigned height ); void lp_bin_new_data_block( struct data_block_list *list ); @@ -297,5 +306,13 @@ lp_scene_bin_iter_begin( struct lp_scene *scene ); struct cmd_bin * lp_scene_bin_iter_next( struct lp_scene *scene, int *bin_x, int *bin_y ); +void +lp_scene_rasterize( struct lp_scene *scene, + struct lp_rasterizer *rast, + boolean write_depth ); + +void +lp_scene_begin_binning( struct lp_scene *scene, + struct pipe_framebuffer_state *fb ); #endif /* LP_BIN_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c index 1cd3ea9a840..934b0d8439e 100644 --- a/src/gallium/drivers/llvmpipe/lp_screen.c +++ b/src/gallium/drivers/llvmpipe/lp_screen.c @@ -83,7 +83,7 @@ llvmpipe_get_param(struct pipe_screen *screen, int param) case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS: return PIPE_MAX_SAMPLERS; case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS: - return PIPE_MAX_VERTEX_SAMPLERS; + return 0; case PIPE_CAP_MAX_COMBINED_SAMPLERS: return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS; case PIPE_CAP_NPOT_TEXTURES: @@ -107,11 +107,11 @@ llvmpipe_get_param(struct pipe_screen *screen, int param) case PIPE_CAP_TEXTURE_SHADOW_MAP: return 1; case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: - return 13; /* max 4Kx4K */ + return LP_MAX_TEXTURE_2D_LEVELS; case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: - return 9; /* max 256x256x256 */ + return LP_MAX_TEXTURE_3D_LEVELS; case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: - return 13; /* max 4Kx4K */ + return LP_MAX_TEXTURE_2D_LEVELS; case PIPE_CAP_TGSI_CONT_SUPPORTED: return 1; case PIPE_CAP_BLEND_EQUATION_SEPARATE: @@ -194,9 +194,7 @@ llvmpipe_is_format_supported( struct pipe_screen *_screen, format_desc->block.height != 1) return FALSE; - if(format_desc->layout != UTIL_FORMAT_LAYOUT_SCALAR && - format_desc->layout != UTIL_FORMAT_LAYOUT_ARITH && - format_desc->layout != UTIL_FORMAT_LAYOUT_ARRAY) + if(format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) return FALSE; if(format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB && @@ -224,33 +222,22 @@ llvmpipe_is_format_supported( struct pipe_screen *_screen, format_desc->block.height != 1) return FALSE; - if(format_desc->layout != UTIL_FORMAT_LAYOUT_SCALAR && - format_desc->layout != UTIL_FORMAT_LAYOUT_ARITH && - format_desc->layout != UTIL_FORMAT_LAYOUT_ARRAY) + if(format_desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) return FALSE; if(format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB && - format_desc->colorspace != UTIL_FORMAT_COLORSPACE_SRGB && format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS) return FALSE; + + /* not supported yet */ + if (format == PIPE_FORMAT_Z16_UNORM) + return FALSE; } return TRUE; } -static struct pipe_buffer * -llvmpipe_surface_buffer_create(struct pipe_screen *screen, - unsigned width, unsigned height, - enum pipe_format format, - unsigned tex_usage, - unsigned usage, - unsigned *stride) -{ - /* This function should never be used */ - assert(0); - return NULL; -} static void @@ -310,7 +297,6 @@ llvmpipe_create_screen(struct llvmpipe_winsys *winsys) screen->base.get_paramf = llvmpipe_get_paramf; screen->base.is_format_supported = llvmpipe_is_format_supported; - screen->base.surface_buffer_create = llvmpipe_surface_buffer_create; screen->base.context_create = llvmpipe_create_context; screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer; diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index cb873667a20..cc7c18c8c0c 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -64,11 +64,10 @@ lp_setup_get_current_scene(struct setup_context *setup) */ setup->scene = lp_scene_dequeue(setup->empty_scenes, TRUE); - if(0)lp_scene_reset( setup->scene ); /* XXX temporary? */ + assert(lp_scene_is_empty(setup->scene)); - lp_scene_set_framebuffer_size(setup->scene, - setup->fb.width, - setup->fb.height); + lp_scene_begin_binning(setup->scene, + &setup->fb ); } return setup->scene; } @@ -133,13 +132,12 @@ static void reset_context( struct setup_context *setup ) /** Rasterize all scene's bins */ static void lp_setup_rasterize_scene( struct setup_context *setup, - boolean write_depth ) + boolean write_depth ) { struct lp_scene *scene = lp_setup_get_current_scene(setup); - lp_rasterize_scene(setup->rast, - scene, - &setup->fb, + lp_scene_rasterize(scene, + setup->rast, write_depth); reset_context( setup ); @@ -244,19 +242,16 @@ void lp_setup_bind_framebuffer( struct setup_context *setup, const struct pipe_framebuffer_state *fb ) { - struct lp_scene *scene = lp_setup_get_current_scene(setup); - LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); + /* Flush any old scene. + */ set_scene_state( setup, SETUP_FLUSHED ); - /* re-get scene pointer, may have a new scene after flushing */ - (void) scene; - scene = lp_setup_get_current_scene(setup); - + /* Set new state. This will be picked up later when we next need a + * scene. + */ util_copy_framebuffer_state(&setup->fb, fb); - - lp_scene_set_framebuffer_size(scene, setup->fb.width, setup->fb.height); } @@ -474,20 +469,28 @@ lp_setup_set_sampler_textures( struct setup_context *setup, jit_tex = &setup->fs.current.jit_context.textures[i]; jit_tex->width = tex->width0; jit_tex->height = tex->height0; + jit_tex->depth = tex->depth0; + jit_tex->last_level = tex->last_level; jit_tex->stride = lp_tex->stride[0]; - if(!lp_tex->dt) { - jit_tex->data = lp_tex->data; + if (!lp_tex->dt) { + /* regular texture - setup array of mipmap level pointers */ + int j; + for (j = 0; j < LP_MAX_TEXTURE_2D_LEVELS; j++) { + jit_tex->data[j] = + (ubyte *) lp_tex->data + lp_tex->level_offset[j]; + } } else { + /* display target texture/surface */ /* * XXX: Where should this be unmapped? */ struct llvmpipe_screen *screen = llvmpipe_screen(tex->screen); struct llvmpipe_winsys *winsys = screen->winsys; - jit_tex->data = winsys->displaytarget_map(winsys, lp_tex->dt, - PIPE_BUFFER_USAGE_CPU_READ); - assert(jit_tex->data); + jit_tex->data[0] = winsys->displaytarget_map(winsys, lp_tex->dt, + PIPE_BUFFER_USAGE_CPU_READ); + assert(jit_tex->data[0]); } /* the scene references this texture */ @@ -681,7 +684,7 @@ lp_setup_destroy( struct setup_context *setup ) * it. */ struct setup_context * -lp_setup_create( struct pipe_screen *screen, +lp_setup_create( struct pipe_context *pipe, struct draw_context *draw ) { unsigned i; @@ -696,7 +699,9 @@ lp_setup_create( struct pipe_screen *screen, if (!setup->empty_scenes) goto fail; - setup->rast = lp_rast_create( screen, setup->empty_scenes ); + /* XXX: move this to the screen and share between contexts: + */ + setup->rast = lp_rast_create(); if (!setup->rast) goto fail; @@ -709,7 +714,8 @@ lp_setup_create( struct pipe_screen *screen, /* create some empty scenes */ for (i = 0; i < MAX_SCENES; i++) { - setup->scenes[i] = lp_scene_create(); + setup->scenes[i] = lp_scene_create( pipe, setup->empty_scenes ); + lp_scene_enqueue(setup->empty_scenes, setup->scenes[i]); } diff --git a/src/gallium/drivers/llvmpipe/lp_setup.h b/src/gallium/drivers/llvmpipe/lp_setup.h index 0e155a7dc31..17c112b5289 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.h +++ b/src/gallium/drivers/llvmpipe/lp_setup.h @@ -62,7 +62,7 @@ struct lp_fragment_shader; struct lp_jit_context; struct setup_context * -lp_setup_create( struct pipe_screen *screen, +lp_setup_create( struct pipe_context *pipe, struct draw_context *draw ); void diff --git a/src/gallium/drivers/llvmpipe/lp_setup_tri.c b/src/gallium/drivers/llvmpipe/lp_setup_tri.c index a8bf540803b..e75412ac9aa 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_tri.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_tri.c @@ -297,6 +297,15 @@ do_triangle_ccw(struct setup_context *setup, tri = alloc_triangle(scene, setup->fs.nr_inputs, &tri_bytes); +#ifdef DEBUG + tri->v[0][0] = v1[0][0]; + tri->v[1][0] = v2[0][0]; + tri->v[2][0] = v3[0][0]; + tri->v[0][1] = v1[0][1]; + tri->v[1][1] = v2[0][1]; + tri->v[2][1] = v3[0][1]; +#endif + tri->dx12 = x1 - x2; tri->dx23 = x2 - x3; tri->dx31 = x3 - x1; diff --git a/src/gallium/drivers/llvmpipe/lp_setup_vbuf.c b/src/gallium/drivers/llvmpipe/lp_setup_vbuf.c index 24291da91e4..671e74465c0 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_vbuf.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_vbuf.c @@ -231,57 +231,29 @@ lp_setup_draw(struct vbuf_render *vbr, const ushort *indices, uint nr) break; case PIPE_PRIM_QUADS: - if (setup->flatshade_first) { - for (i = 3; i < nr; i += 4) { - setup->triangle( setup, - get_vert(vertex_buffer, indices[i-2], stride), - get_vert(vertex_buffer, indices[i-1], stride), - get_vert(vertex_buffer, indices[i-3], stride) ); - setup->triangle( setup, - get_vert(vertex_buffer, indices[i-1], stride), - get_vert(vertex_buffer, indices[i-0], stride), - get_vert(vertex_buffer, indices[i-3], stride) ); - } - } - else { - for (i = 3; i < nr; i += 4) { - setup->triangle( setup, - get_vert(vertex_buffer, indices[i-3], stride), - get_vert(vertex_buffer, indices[i-2], stride), - get_vert(vertex_buffer, indices[i-0], stride) ); + for (i = 3; i < nr; i += 4) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); - setup->triangle( setup, - get_vert(vertex_buffer, indices[i-2], stride), - get_vert(vertex_buffer, indices[i-1], stride), - get_vert(vertex_buffer, indices[i-0], stride) ); - } + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); } break; case PIPE_PRIM_QUAD_STRIP: - if (setup->flatshade_first) { - for (i = 3; i < nr; i += 2) { - setup->triangle( setup, - get_vert(vertex_buffer, indices[i-0], stride), - get_vert(vertex_buffer, indices[i-1], stride), - get_vert(vertex_buffer, indices[i-3], stride)); - setup->triangle( setup, - get_vert(vertex_buffer, indices[i-2], stride), - get_vert(vertex_buffer, indices[i-0], stride), - get_vert(vertex_buffer, indices[i-3], stride) ); - } - } - else { - for (i = 3; i < nr; i += 2) { - setup->triangle( setup, - get_vert(vertex_buffer, indices[i-3], stride), - get_vert(vertex_buffer, indices[i-2], stride), - get_vert(vertex_buffer, indices[i-0], stride) ); - setup->triangle( setup, - get_vert(vertex_buffer, indices[i-1], stride), - get_vert(vertex_buffer, indices[i-3], stride), - get_vert(vertex_buffer, indices[i-0], stride) ); - } + for (i = 3; i < nr; i += 2) { + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-2], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, indices[i-1], stride), + get_vert(vertex_buffer, indices[i-3], stride), + get_vert(vertex_buffer, indices[i-0], stride) ); } break; @@ -415,57 +387,28 @@ lp_setup_draw_arrays(struct vbuf_render *vbr, uint start, uint nr) break; case PIPE_PRIM_QUADS: - if (setup->flatshade_first) { - for (i = 3; i < nr; i += 4) { - setup->triangle( setup, - get_vert(vertex_buffer, i-2, stride), - get_vert(vertex_buffer, i-1, stride), - get_vert(vertex_buffer, i-3, stride) ); - setup->triangle( setup, - get_vert(vertex_buffer, i-1, stride), - get_vert(vertex_buffer, i-0, stride), - get_vert(vertex_buffer, i-3, stride) ); - } - } - else { - for (i = 3; i < nr; i += 4) { - setup->triangle( setup, - get_vert(vertex_buffer, i-3, stride), - get_vert(vertex_buffer, i-2, stride), - get_vert(vertex_buffer, i-0, stride) ); - setup->triangle( setup, - get_vert(vertex_buffer, i-2, stride), - get_vert(vertex_buffer, i-1, stride), - get_vert(vertex_buffer, i-0, stride) ); - } + for (i = 3; i < nr; i += 4) { + setup->triangle( setup, + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-0, stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-0, stride) ); } break; case PIPE_PRIM_QUAD_STRIP: - if (setup->flatshade_first) { - for (i = 3; i < nr; i += 2) { - setup->triangle( setup, - get_vert(vertex_buffer, i-0, stride), - get_vert(vertex_buffer, i-1, stride), - get_vert(vertex_buffer, i-3, stride) ); - setup->triangle( setup, - - get_vert(vertex_buffer, i-2, stride), - get_vert(vertex_buffer, i-0, stride), - get_vert(vertex_buffer, i-3, stride) ); - } - } - else { - for (i = 3; i < nr; i += 2) { - setup->triangle( setup, - get_vert(vertex_buffer, i-3, stride), - get_vert(vertex_buffer, i-2, stride), - get_vert(vertex_buffer, i-0, stride) ); - setup->triangle( setup, - get_vert(vertex_buffer, i-1, stride), - get_vert(vertex_buffer, i-3, stride), - get_vert(vertex_buffer, i-0, stride) ); - } + for (i = 3; i < nr; i += 2) { + setup->triangle( setup, + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-2, stride), + get_vert(vertex_buffer, i-0, stride) ); + setup->triangle( setup, + get_vert(vertex_buffer, i-1, stride), + get_vert(vertex_buffer, i-3, stride), + get_vert(vertex_buffer, i-0, stride) ); } break; diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 90dae3f9101..c4b79dd4156 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -974,6 +974,13 @@ llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs) assert(fs != llvmpipe->fs); (void) llvmpipe; + /* + * XXX: we need to flush the context until we have some sort of reference + * counting in fragment shaders as they may still be binned + */ + draw_flush(llvmpipe->draw); + lp_setup_flush(llvmpipe->setup, 0); + variant = shader->variants; while(variant) { struct lp_fragment_shader_variant *next = variant->next; diff --git a/src/gallium/drivers/llvmpipe/lp_test_format.c b/src/gallium/drivers/llvmpipe/lp_test_format.c index 48828bd0a0f..d05157991bb 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_format.c +++ b/src/gallium/drivers/llvmpipe/lp_test_format.c @@ -52,25 +52,25 @@ struct pixel_test_case struct pixel_test_case test_cases[] = { - {PIPE_FORMAT_R5G6B5_UNORM, 0x0000, {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5G6B5_UNORM, 0x001f, {0.0, 0.0, 1.0, 1.0}}, - {PIPE_FORMAT_R5G6B5_UNORM, 0x07e0, {0.0, 1.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5G6B5_UNORM, 0xf800, {1.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_R5G6B5_UNORM, 0xffff, {1.0, 1.0, 1.0, 1.0}}, - - {PIPE_FORMAT_A1R5G5B5_UNORM, 0x0000, {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, 0x001f, {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, 0x03e0, {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, 0x7c00, {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, 0x8000, {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A1R5G5B5_UNORM, 0xffff, {1.0, 1.0, 1.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, 0x0000, {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, 0x001f, {0.0, 0.0, 1.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, 0x07e0, {0.0, 1.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, 0xf800, {1.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G6R5_UNORM, 0xffff, {1.0, 1.0, 1.0, 1.0}}, + + {PIPE_FORMAT_B5G5R5A1_UNORM, 0x0000, {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, 0x001f, {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, 0x03e0, {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, 0x7c00, {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, 0x8000, {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B5G5R5A1_UNORM, 0xffff, {1.0, 1.0, 1.0, 1.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, 0x00000000, {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, 0x000000ff, {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, 0x0000ff00, {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, 0x00ff0000, {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, 0xff000000, {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_A8R8G8B8_UNORM, 0xffffffff, {1.0, 1.0, 1.0, 1.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, 0x00000000, {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, 0x000000ff, {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, 0x0000ff00, {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, 0x00ff0000, {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, 0xff000000, {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_B8G8R8A8_UNORM, 0xffffffff, {1.0, 1.0, 1.0, 1.0}}, #if 0 {PIPE_FORMAT_R8G8B8A8_UNORM, 0x00000000, {0.0, 0.0, 0.0, 0.0}}, @@ -81,12 +81,12 @@ struct pixel_test_case test_cases[] = {PIPE_FORMAT_R8G8B8A8_UNORM, 0xffffffff, {1.0, 1.0, 1.0, 1.0}}, #endif - {PIPE_FORMAT_B8G8R8A8_UNORM, 0x00000000, {0.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, 0x000000ff, {0.0, 0.0, 0.0, 1.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, 0x0000ff00, {1.0, 0.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, 0x00ff0000, {0.0, 1.0, 0.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, 0xff000000, {0.0, 0.0, 1.0, 0.0}}, - {PIPE_FORMAT_B8G8R8A8_UNORM, 0xffffffff, {1.0, 1.0, 1.0, 1.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, 0x00000000, {0.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, 0x000000ff, {0.0, 0.0, 0.0, 1.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, 0x0000ff00, {1.0, 0.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, 0x00ff0000, {0.0, 1.0, 0.0, 0.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, 0xff000000, {0.0, 0.0, 1.0, 0.0}}, + {PIPE_FORMAT_A8R8G8B8_UNORM, 0xffffffff, {1.0, 1.0, 1.0, 1.0}}, }; diff --git a/src/gallium/drivers/llvmpipe/lp_test_main.c b/src/gallium/drivers/llvmpipe/lp_test_main.c index 14ff00469b0..f9dce8b9c25 100644 --- a/src/gallium/drivers/llvmpipe/lp_test_main.c +++ b/src/gallium/drivers/llvmpipe/lp_test_main.c @@ -37,7 +37,7 @@ #include "util/u_cpu_detect.h" #include "gallivm/lp_bld_const.h" -#include "gallivm/lp_bld_misc.h" +#include "gallivm/lp_bld_init.h" #include "lp_test.h" @@ -380,8 +380,7 @@ int main(int argc, char **argv) n = atoi(argv[i]); } - LLVMLinkInJIT(); - LLVMInitializeNativeTarget(); + lp_build_init(); util_cpu_detect(); diff --git a/src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c b/src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c index 2533275dc18..5a3cf37d6d8 100644 --- a/src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c +++ b/src/gallium/drivers/llvmpipe/lp_tex_sample_llvm.c @@ -51,10 +51,11 @@ /** - * This provides the bridge between the sampler state store in lp_jit_context - * and lp_jit_texture and the sampler code generator. It provides the - * texture layout information required by the texture sampler code generator - * in terms of the state stored in lp_jit_context and lp_jit_texture in runtime. + * This provides the bridge between the sampler state store in + * lp_jit_context and lp_jit_texture and the sampler code + * generator. It provides the texture layout information required by + * the texture sampler code generator in terms of the state stored in + * lp_jit_context and lp_jit_texture in runtime. */ struct llvmpipe_sampler_dynamic_state { @@ -79,6 +80,9 @@ struct lp_llvm_sampler_soa /** * Fetch the specified member of the lp_jit_texture structure. + * \param emit_load if TRUE, emit the LLVM load instruction to actually + * fetch the field's value. Otherwise, just emit the + * GEP code to address the field. * * @sa http://llvm.org/docs/GetElementPtr.html */ @@ -87,9 +91,11 @@ lp_llvm_texture_member(struct lp_sampler_dynamic_state *base, LLVMBuilderRef builder, unsigned unit, unsigned member_index, - const char *member_name) + const char *member_name, + boolean emit_load) { - struct llvmpipe_sampler_dynamic_state *state = (struct llvmpipe_sampler_dynamic_state *)base; + struct llvmpipe_sampler_dynamic_state *state = + (struct llvmpipe_sampler_dynamic_state *)base; LLVMValueRef indices[4]; LLVMValueRef ptr; LLVMValueRef res; @@ -107,7 +113,10 @@ lp_llvm_texture_member(struct lp_sampler_dynamic_state *base, ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), ""); - res = LLVMBuildLoad(builder, ptr, ""); + if (emit_load) + res = LLVMBuildLoad(builder, ptr, ""); + else + res = ptr; lp_build_name(res, "context.texture%u.%s", unit, member_name); @@ -116,26 +125,30 @@ lp_llvm_texture_member(struct lp_sampler_dynamic_state *base, /** - * Helper macro to instantiate the functions that generate the code to fetch - * the members of lp_jit_texture to fulfill the sampler code generator requests. + * Helper macro to instantiate the functions that generate the code to + * fetch the members of lp_jit_texture to fulfill the sampler code + * generator requests. * - * This complexity is the price we have to pay to keep the texture sampler code - * generator a reusable module without dependencies to llvmpipe internals. + * This complexity is the price we have to pay to keep the texture + * sampler code generator a reusable module without dependencies to + * llvmpipe internals. */ -#define LP_LLVM_TEXTURE_MEMBER(_name, _index) \ +#define LP_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load) \ static LLVMValueRef \ lp_llvm_texture_##_name( struct lp_sampler_dynamic_state *base, \ LLVMBuilderRef builder, \ unsigned unit) \ { \ - return lp_llvm_texture_member(base, builder, unit, _index, #_name ); \ + return lp_llvm_texture_member(base, builder, unit, _index, #_name, _emit_load ); \ } -LP_LLVM_TEXTURE_MEMBER(width, LP_JIT_TEXTURE_WIDTH) -LP_LLVM_TEXTURE_MEMBER(height, LP_JIT_TEXTURE_HEIGHT) -LP_LLVM_TEXTURE_MEMBER(stride, LP_JIT_TEXTURE_STRIDE) -LP_LLVM_TEXTURE_MEMBER(data_ptr, LP_JIT_TEXTURE_DATA) +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(last_level, LP_JIT_TEXTURE_LAST_LEVEL, TRUE) +LP_LLVM_TEXTURE_MEMBER(stride, LP_JIT_TEXTURE_STRIDE, TRUE) +LP_LLVM_TEXTURE_MEMBER(data_ptr, LP_JIT_TEXTURE_DATA, FALSE) static void @@ -145,6 +158,10 @@ lp_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler) } +/** + * Fetch filtered values from texture. + * The 'texel' parameter returns four vectors corresponding to R, G, B, A. + */ static void lp_llvm_sampler_soa_emit_fetch_texel(struct lp_build_sampler_soa *base, LLVMBuilderRef builder, @@ -185,6 +202,8 @@ lp_llvm_sampler_soa_create(const struct lp_sampler_static_state *static_state, sampler->base.emit_fetch_texel = lp_llvm_sampler_soa_emit_fetch_texel; 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.last_level = lp_llvm_texture_last_level; sampler->dynamic_state.base.stride = lp_llvm_texture_stride; sampler->dynamic_state.base.data_ptr = lp_llvm_texture_data_ptr; sampler->dynamic_state.static_state = static_state; diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index 022bf92cb46..e41d6238ed2 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -124,14 +124,9 @@ llvmpipe_texture_create(struct pipe_screen *_screen, pipe_reference_init(&lpt->base.reference, 1); lpt->base.screen = &screen->base; - /* XXX: The xlib state tracker is brain-dead and will request - * PIPE_FORMAT_Z16_UNORM no matter how much we tell it we don't support it. - */ - if (lpt->base.format == PIPE_FORMAT_Z16_UNORM) - lpt->base.format = PIPE_FORMAT_Z32_UNORM; - if (lpt->base.tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_PRIMARY)) { + PIPE_TEXTURE_USAGE_SCANOUT | + PIPE_TEXTURE_USAGE_SHARED)) { if (!llvmpipe_displaytarget_layout(screen, lpt)) goto fail; } @@ -148,43 +143,6 @@ llvmpipe_texture_create(struct pipe_screen *_screen, } -static struct pipe_texture * -llvmpipe_texture_blanket(struct pipe_screen * screen, - const struct pipe_texture *base, - const unsigned *stride, - struct pipe_buffer *buffer) -{ - /* FIXME */ -#if 0 - struct llvmpipe_texture *lpt; - assert(screen); - - /* Only supports one type */ - if (base->target != PIPE_TEXTURE_2D || - base->last_level != 0 || - base->depth0 != 1) { - return NULL; - } - - lpt = CALLOC_STRUCT(llvmpipe_texture); - if (!lpt) - return NULL; - - lpt->base = *base; - pipe_reference_init(&lpt->base.reference, 1); - lpt->base.screen = screen; - lpt->stride[0] = stride[0]; - - pipe_buffer_reference(&lpt->buffer, buffer); - - return &lpt->base; -#else - debug_printf("llvmpipe_texture_blanket() not implemented!"); - return NULL; -#endif -} - - static void llvmpipe_texture_destroy(struct pipe_texture *pt) { @@ -414,7 +372,6 @@ void llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = llvmpipe_texture_create; - screen->texture_blanket = llvmpipe_texture_blanket; screen->texture_destroy = llvmpipe_texture_destroy; screen->get_tex_surface = llvmpipe_get_tex_surface; diff --git a/src/gallium/drivers/llvmpipe/lp_texture.h b/src/gallium/drivers/llvmpipe/lp_texture.h index 87c905bc027..c511a012987 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.h +++ b/src/gallium/drivers/llvmpipe/lp_texture.h @@ -32,6 +32,10 @@ #include "pipe/p_state.h" +#define LP_MAX_TEXTURE_2D_LEVELS 13 /* 4K x 4K for now */ +#define LP_MAX_TEXTURE_3D_LEVELS 10 /* 512 x 512 x 512 for now */ + + struct pipe_context; struct pipe_screen; struct llvmpipe_context; @@ -42,8 +46,8 @@ struct llvmpipe_texture { struct pipe_texture base; - unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS]; - unsigned stride[PIPE_MAX_TEXTURE_LEVELS]; + unsigned long level_offset[LP_MAX_TEXTURE_2D_LEVELS]; + unsigned stride[LP_MAX_TEXTURE_2D_LEVELS]; /** * Display target, for textures with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET diff --git a/src/gallium/drivers/llvmpipe/lp_tile_image.c b/src/gallium/drivers/llvmpipe/lp_tile_image.c new file mode 100644 index 00000000000..c1980b316d5 --- /dev/null +++ b/src/gallium/drivers/llvmpipe/lp_tile_image.c @@ -0,0 +1,126 @@ +/************************************************************************** + * + * 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 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 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. + * + **************************************************************************/ + + +#include "lp_tile_soa.h" +#include "lp_tile_image.h" + + +#define BYTES_PER_TILE (TILE_SIZE * TILE_SIZE * 4) + + +/** + * Convert a tiled image into a linear image. + * \param src_stride source row stride in bytes (bytes per row of tiles) + * \param dst_stride dest row stride in bytes + */ +void +lp_tiled_to_linear(const uint8_t *src, + uint8_t *dst, + unsigned width, unsigned height, + enum pipe_format format, + unsigned src_stride, + unsigned dst_stride) +{ + const unsigned tiles_per_row = src_stride / BYTES_PER_TILE; + unsigned i, j; + + for (j = 0; j < height; j += TILE_SIZE) { + for (i = 0; i < width; i += TILE_SIZE) { + unsigned tile_offset = + ((j / TILE_SIZE) * tiles_per_row + i / TILE_SIZE); + unsigned byte_offset = tile_offset * BYTES_PER_TILE; + const uint8_t *src_tile = src + byte_offset; + + lp_tile_write_4ub(format, + src_tile, + dst, + dst_stride, + i, j, TILE_SIZE, TILE_SIZE); + } + } +} + + +/** + * Convert a linear image into a tiled image. + * \param src_stride source row stride in bytes + * \param dst_stride dest row stride in bytes (bytes per row of tiles) + */ +void +lp_linear_to_tiled(const uint8_t *src, + uint8_t *dst, + unsigned width, unsigned height, + enum pipe_format format, + unsigned src_stride, + unsigned dst_stride) +{ + const unsigned tiles_per_row = dst_stride / BYTES_PER_TILE; + unsigned i, j; + + for (j = 0; j < height; j += TILE_SIZE) { + for (i = 0; i < width; i += TILE_SIZE) { + unsigned tile_offset = + ((j / TILE_SIZE) * tiles_per_row + i / TILE_SIZE); + unsigned byte_offset = tile_offset * BYTES_PER_TILE; + uint8_t *dst_tile = dst + byte_offset; + + lp_tile_read_4ub(format, + dst_tile, + src, + src_stride, + i, j, TILE_SIZE, TILE_SIZE); + } + } +} + + +/** + * For testing only. + */ +void +test_tiled_linear_conversion(uint8_t *data, + enum pipe_format format, + unsigned width, unsigned height, + unsigned stride) +{ + /* size in tiles */ + unsigned wt = (width + TILE_SIZE - 1) / TILE_SIZE; + unsigned ht = (height + TILE_SIZE - 1) / TILE_SIZE; + + uint8_t *tiled = malloc(wt * ht * TILE_SIZE * TILE_SIZE * 4); + + unsigned tiled_stride = wt * TILE_SIZE * TILE_SIZE * 4; + + lp_linear_to_tiled(data, tiled, width, height, format, + stride, tiled_stride); + + lp_tiled_to_linear(tiled, data, width, height, format, + tiled_stride, stride); + + free(tiled); +} + diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/drivers/llvmpipe/lp_tile_image.h index e0724a1a8be..60d472e8c5b 100644 --- a/src/gallium/auxiliary/util/u_format.c +++ b/src/gallium/drivers/llvmpipe/lp_tile_image.h @@ -1,8 +1,7 @@ /************************************************************************** - * - * Copyright 2009 Vmware, Inc. - * All Rights Reserved. - * + * + * 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 @@ -10,36 +9,49 @@ * 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 + * IN NO EVENT SHALL THE 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. - * + * **************************************************************************/ -#include "u_format.h" +#ifndef LP_TILE_IMAGE_H +#define LP_TILE_IMAGE_H -const struct util_format_description * -util_format_description(enum pipe_format format) -{ - const struct util_format_description *desc; +void +lp_tiled_to_linear(const uint8_t *src, + uint8_t *dst, + unsigned width, unsigned height, + enum pipe_format format, + unsigned src_stride, + unsigned dst_stride); - if (format >= PIPE_FORMAT_COUNT) { - return NULL; - } - desc = &util_format_description_table[format]; - assert(desc->format == format); +void +lp_linear_to_tiled(const uint8_t *src, + uint8_t *dst, + unsigned width, unsigned height, + enum pipe_format format, + unsigned src_stride, + unsigned dst_stride); - return desc; -} + +void +test_tiled_linear_conversion(uint8_t *data, + enum pipe_format format, + unsigned width, unsigned height, + unsigned stride); + + +#endif /* LP_TILE_IMAGE_H */ diff --git a/src/gallium/drivers/llvmpipe/lp_tile_soa.py b/src/gallium/drivers/llvmpipe/lp_tile_soa.py index 5d53689a3db..00b8d4fc382 100644 --- a/src/gallium/drivers/llvmpipe/lp_tile_soa.py +++ b/src/gallium/drivers/llvmpipe/lp_tile_soa.py @@ -45,10 +45,10 @@ sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '../../auxiliary/u from u_format_access import * -def generate_format_read(format, dst_type, dst_native_type, dst_suffix): +def generate_format_read(format, dst_channel, dst_native_type, dst_suffix): '''Generate the function to read pixels from a particular format''' - name = short_name(format) + name = format.short_name() src_native_type = native_type(format) @@ -64,11 +64,11 @@ def generate_format_read(format, dst_type, dst_native_type, dst_suffix): names = ['']*4 if format.colorspace == 'rgb': for i in range(4): - swizzle = format.out_swizzle[i] + swizzle = format.swizzles[i] if swizzle < 4: names[swizzle] += 'rgba'[i] elif format.colorspace == 'zs': - swizzle = format.out_swizzle[0] + swizzle = format.swizzles[0] if swizzle < 4: names[swizzle] = 'z' else: @@ -76,48 +76,49 @@ def generate_format_read(format, dst_type, dst_native_type, dst_suffix): else: assert False - if format.layout == ARITH: - print ' %s pixel = *src_pixel++;' % src_native_type - shift = 0; - for i in range(4): - src_type = format.in_types[i] - width = src_type.size - if names[i]: - value = 'pixel' - mask = (1 << width) - 1 - if shift: - value = '(%s >> %u)' % (value, shift) - if shift + width < format.block_size(): - value = '(%s & 0x%x)' % (value, mask) - value = conversion_expr(src_type, dst_type, dst_native_type, value) - print ' %s %s = %s;' % (dst_native_type, names[i], value) - shift += width - elif format.layout == ARRAY: - for i in range(4): - src_type = format.in_types[i] - if names[i]: - value = '(*src_pixel++)' - value = conversion_expr(src_type, dst_type, dst_native_type, value) - print ' %s %s = %s;' % (dst_native_type, names[i], value) + if format.layout == PLAIN: + if not format.is_array(): + print ' %s pixel = *src_pixel++;' % src_native_type + shift = 0; + for i in range(4): + src_channel = format.channels[i] + width = src_channel.size + if names[i]: + value = 'pixel' + mask = (1 << width) - 1 + if shift: + value = '(%s >> %u)' % (value, shift) + if shift + width < format.block_size(): + value = '(%s & 0x%x)' % (value, mask) + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + print ' %s %s = %s;' % (dst_native_type, names[i], value) + shift += width + else: + for i in range(4): + src_channel = format.channels[i] + if names[i]: + value = '(*src_pixel++)' + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + print ' %s %s = %s;' % (dst_native_type, names[i], value) else: assert False for i in range(4): if format.colorspace == 'rgb': - swizzle = format.out_swizzle[i] + swizzle = format.swizzles[i] if swizzle < 4: value = names[swizzle] elif swizzle == SWIZZLE_0: value = '0' elif swizzle == SWIZZLE_1: - value = '1' + value = get_one(dst_channel) else: assert False elif format.colorspace == 'zs': if i < 3: value = 'z' else: - value = '1' + value = get_one(dst_channel) else: assert False print ' TILE_PIXEL(dst, x, y, %u) = %s; /* %s */' % (i, value, 'rgba'[i]) @@ -129,31 +130,16 @@ def generate_format_read(format, dst_type, dst_native_type, dst_suffix): print -def compute_inverse_swizzle(format): - '''Return an array[4] of inverse swizzle terms''' - inv_swizzle = [None]*4 - if format.colorspace == 'rgb': - for i in range(4): - swizzle = format.out_swizzle[i] - if swizzle < 4: - inv_swizzle[swizzle] = i - elif format.colorspace == 'zs': - swizzle = format.out_swizzle[0] - if swizzle < 4: - inv_swizzle[swizzle] = 0 - return inv_swizzle - - -def pack_rgba(format, src_type, r, g, b, a): +def pack_rgba(format, src_channel, r, g, b, a): """Return an expression for packing r, g, b, a into a pixel of the given format. Ex: '(b << 24) | (g << 16) | (r << 8) | (a << 0)' """ assert format.colorspace == 'rgb' - inv_swizzle = compute_inverse_swizzle(format) + inv_swizzle = format.inv_swizzles() shift = 0 expr = None for i in range(4): - # choose r, g, b, or a depending on the inverse swizzle term + # choose r, g, b, or a depending on the inverse swizzle term if inv_swizzle[i] == 0: value = r elif inv_swizzle[i] == 1: @@ -166,25 +152,25 @@ def pack_rgba(format, src_type, r, g, b, a): value = None if value: - dst_type = format.in_types[i] + dst_channel = format.channels[i] dst_native_type = native_type(format) - value = conversion_expr(src_type, dst_type, dst_native_type, value) + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) term = "((%s) << %d)" % (value, shift) if expr: expr = expr + " | " + term else: expr = term - width = format.in_types[i].size + width = format.channels[i].size shift = shift + width return expr -def emit_unrolled_write_code(format, src_type): +def emit_unrolled_write_code(format, src_channel): '''Emit code for writing a block based on unrolled loops. This is considerably faster than the TILE_PIXEL-based code below. ''' - dst_native_type = native_type(format) + dst_native_type = 'uint%u_t' % format.block_size() print ' const unsigned dstpix_stride = dst_stride / %d;' % format.stride() print ' %s *dstpix = (%s *) dst;' % (dst_native_type, dst_native_type) print ' unsigned int qx, qy, i;' @@ -199,8 +185,8 @@ def emit_unrolled_write_code(format, src_type): print ' const uint8_t *a = src + 3 * TILE_C_STRIDE;' print ' (void) r; (void) g; (void) b; (void) a; /* silence warnings */' print ' for (i = 0; i < TILE_C_STRIDE; i += 2) {' - print ' const uint32_t pixel0 = %s;' % pack_rgba(format, src_type, "r[i+0]", "g[i+0]", "b[i+0]", "a[i+0]") - print ' const uint32_t pixel1 = %s;' % pack_rgba(format, src_type, "r[i+1]", "g[i+1]", "b[i+1]", "a[i+1]") + print ' const uint32_t pixel0 = %s;' % pack_rgba(format, src_channel, "r[i+0]", "g[i+0]", "b[i+0]", "a[i+0]") + print ' const uint32_t pixel1 = %s;' % pack_rgba(format, src_channel, "r[i+1]", "g[i+1]", "b[i+1]", "a[i+1]") print ' const unsigned offset = (py + tile_y_offset[i]) * dstpix_stride + (px + tile_x_offset[i]);' print ' dstpix[offset + 0] = pixel0;' print ' dstpix[offset + 1] = pixel1;' @@ -210,11 +196,11 @@ def emit_unrolled_write_code(format, src_type): print ' }' -def emit_tile_pixel_write_code(format, src_type): +def emit_tile_pixel_write_code(format, src_channel): '''Emit code for writing a block based on the TILE_PIXEL macro.''' dst_native_type = native_type(format) - inv_swizzle = compute_inverse_swizzle(format) + inv_swizzle = format.inv_swizzles() print ' unsigned x, y;' print ' uint8_t *dst_row = dst + y0*dst_stride;' @@ -222,27 +208,28 @@ def emit_tile_pixel_write_code(format, src_type): print ' %s *dst_pixel = (%s *)(dst_row + x0*%u);' % (dst_native_type, dst_native_type, format.stride()) print ' for (x = 0; x < w; ++x) {' - if format.layout == ARITH: - print ' %s pixel = 0;' % dst_native_type - shift = 0; - for i in range(4): - dst_type = format.in_types[i] - width = dst_type.size - if inv_swizzle[i] is not None: - value = 'TILE_PIXEL(src, x, y, %u)' % inv_swizzle[i] - value = conversion_expr(src_type, dst_type, dst_native_type, value) - if shift: - value = '(%s << %u)' % (value, shift) - print ' pixel |= %s;' % value - shift += width - print ' *dst_pixel++ = pixel;' - elif format.layout == ARRAY: - for i in range(4): - dst_type = format.in_types[i] - if inv_swizzle[i] is not None: - value = 'TILE_PIXEL(src, x, y, %u)' % inv_swizzle[i] - value = conversion_expr(src_type, dst_type, dst_native_type, value) - print ' *dst_pixel++ = %s;' % value + if format.layout == PLAIN: + if not format.is_array(): + print ' %s pixel = 0;' % dst_native_type + shift = 0; + for i in range(4): + dst_channel = format.channels[i] + width = dst_channel.size + if inv_swizzle[i] is not None: + value = 'TILE_PIXEL(src, x, y, %u)' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + if shift: + value = '(%s << %u)' % (value, shift) + print ' pixel |= %s;' % value + shift += width + print ' *dst_pixel++ = pixel;' + else: + for i in range(4): + dst_channel = format.channels[i] + if inv_swizzle[i] is not None: + value = 'TILE_PIXEL(src, x, y, %u)' % inv_swizzle[i] + value = conversion_expr(src_channel, dst_channel, dst_native_type, value, clamp=False) + print ' *dst_pixel++ = %s;' % value else: assert False @@ -251,28 +238,33 @@ def emit_tile_pixel_write_code(format, src_type): print ' }' -def generate_format_write(format, src_type, src_native_type, src_suffix): +def generate_format_write(format, src_channel, src_native_type, src_suffix): '''Generate the function to write pixels to a particular format''' - name = short_name(format) + name = format.short_name() print 'static void' print 'lp_tile_%s_write_%s(const %s *src, uint8_t *dst, unsigned dst_stride, unsigned x0, unsigned y0, unsigned w, unsigned h)' % (name, src_suffix, src_native_type) print '{' - if format.layout == ARITH and format.colorspace == 'rgb': - emit_unrolled_write_code(format, src_type) + if format.layout == PLAIN \ + and format.colorspace == 'rgb' \ + and format.block_size() <= 32 \ + and format.is_pot() \ + and not format.is_mixed() \ + and format.channels[0].type == UNSIGNED: + emit_unrolled_write_code(format, src_channel) else: - emit_tile_pixel_write_code(format, src_type) + emit_tile_pixel_write_code(format, src_channel) print '}' print -def generate_read(formats, dst_type, dst_native_type, dst_suffix): +def generate_read(formats, dst_channel, dst_native_type, dst_suffix): '''Generate the dispatch function to read pixels from any format''' for format in formats: if is_format_supported(format): - generate_format_read(format, dst_type, dst_native_type, dst_suffix) + generate_format_read(format, dst_channel, dst_native_type, dst_suffix) print 'void' print 'lp_tile_read_%s(enum pipe_format format, %s *dst, const void *src, unsigned src_stride, unsigned x, unsigned y, unsigned w, unsigned h)' % (dst_suffix, dst_native_type) @@ -282,7 +274,7 @@ def generate_read(formats, dst_type, dst_native_type, dst_suffix): for format in formats: if is_format_supported(format): print ' case %s:' % format.name - print ' func = &lp_tile_%s_read_%s;' % (short_name(format), dst_suffix) + print ' func = &lp_tile_%s_read_%s;' % (format.short_name(), dst_suffix) print ' break;' print ' default:' print ' debug_printf("unsupported format\\n");' @@ -293,12 +285,12 @@ def generate_read(formats, dst_type, dst_native_type, dst_suffix): print -def generate_write(formats, src_type, src_native_type, src_suffix): +def generate_write(formats, src_channel, src_native_type, src_suffix): '''Generate the dispatch function to write pixels to any format''' for format in formats: if is_format_supported(format): - generate_format_write(format, src_type, src_native_type, src_suffix) + generate_format_write(format, src_channel, src_native_type, src_suffix) print 'void' print 'lp_tile_write_%s(enum pipe_format format, const %s *src, void *dst, unsigned dst_stride, unsigned x, unsigned y, unsigned w, unsigned h)' % (src_suffix, src_native_type) @@ -309,7 +301,7 @@ def generate_write(formats, src_type, src_native_type, src_suffix): for format in formats: if is_format_supported(format): print ' case %s:' % format.name - print ' func = &lp_tile_%s_write_%s;' % (short_name(format), src_suffix) + print ' func = &lp_tile_%s_write_%s;' % (format.short_name(), src_suffix) print ' break;' print ' default:' print ' debug_printf("unsupported format\\n");' @@ -359,12 +351,12 @@ def main(): generate_clamp() - type = Type(UNSIGNED, True, 8) + channel = Channel(UNSIGNED, True, 8) native_type = 'uint8_t' suffix = '4ub' - generate_read(formats, type, native_type, suffix) - generate_write(formats, type, native_type, suffix) + generate_read(formats, channel, native_type, suffix) + generate_write(formats, channel, native_type, suffix) if __name__ == '__main__': diff --git a/src/gallium/drivers/nouveau/nouveau_context.c b/src/gallium/drivers/nouveau/nouveau_context.c index 23443869e68..15174983e7f 100644 --- a/src/gallium/drivers/nouveau/nouveau_context.c +++ b/src/gallium/drivers/nouveau/nouveau_context.c @@ -1,5 +1,5 @@ -#include <pipe/p_defines.h> -#include <pipe/p_context.h> +#include "pipe/p_defines.h" +#include "pipe/p_context.h" #include "nouveau/nouveau_screen.h" #include "nouveau/nouveau_context.h" diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c index 81bc296ab44..f7d10a591f6 100644 --- a/src/gallium/drivers/nouveau/nouveau_screen.c +++ b/src/gallium/drivers/nouveau/nouveau_screen.c @@ -1,9 +1,10 @@ -#include <pipe/p_defines.h> -#include <pipe/p_screen.h> -#include <pipe/p_state.h> +#include "pipe/p_defines.h" +#include "pipe/p_screen.h" +#include "pipe/p_state.h" -#include <util/u_memory.h> -#include <util/u_inlines.h> +#include "util/u_memory.h" +#include "util/u_inlines.h" +#include "util/u_format.h" #include <stdio.h> #include <errno.h> @@ -12,6 +13,9 @@ #include "nouveau_winsys.h" #include "nouveau_screen.h" +/* XXX this should go away */ +#include "state_tracker/drm_api.h" + static const char * nouveau_screen_get_name(struct pipe_screen *pscreen) { @@ -231,6 +235,72 @@ nouveau_screen_fence_finish(struct pipe_screen *screen, return 0; } + +/* + * Both texture_{from|get}_handle use drm api defines directly which they + * shouldn't do. The problem is that from|get are pipe functions and as + * such they should be defined in the pipe level. If nouveau had a propper + * winsys interface we would have added from|get to that interface using + * the winsys_handle struct as done with other drivers. However this code + * calls directly into the libdrm_nouveau.so functions (nouveau_bo_*). So + * we need to translate the handle into something they understand. + */ +static struct pipe_texture * +nouveau_screen_texture_from_handle(struct pipe_screen *pscreen, + const struct pipe_texture *templ, + struct winsys_handle *whandle) +{ + struct nouveau_device *dev = nouveau_screen(pscreen)->device; + struct pipe_texture *pt; + struct pipe_buffer *pb; + int ret; + + pb = CALLOC(1, sizeof(struct pipe_buffer) + sizeof(struct nouveau_bo*)); + if (!pb) + return NULL; + + ret = nouveau_bo_handle_ref(dev, whandle->handle, (struct nouveau_bo**)(pb+1)); + if (ret) { + debug_printf("%s: ref name 0x%08x failed with %d\n", + __func__, whandle->handle, ret); + FREE(pb); + return NULL; + } + + pipe_reference_init(&pb->reference, 1); + pb->screen = pscreen; + pb->alignment = 0; + pb->usage = PIPE_BUFFER_USAGE_GPU_READ_WRITE | + PIPE_BUFFER_USAGE_CPU_READ_WRITE; + pb->size = nouveau_bo(pb)->size; + pt = nouveau_screen(pscreen)->texture_blanket(pscreen, templ, + &whandle->stride, pb); + pipe_buffer_reference(&pb, NULL); + return pt; +} + +static boolean +nouveau_screen_texture_get_handle(struct pipe_screen *pscreen, + struct pipe_texture *pt, + struct winsys_handle *whandle) +{ + struct nouveau_miptree *mt = nouveau_miptree(pt); + + if (!mt || !mt->bo) + return false; + + whandle->stride = util_format_get_stride(mt->base.format, mt->base.width0); + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + return nouveau_bo_handle_get(mt->bo, &whandle->handle) == 0; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = mt->bo->handle; + return TRUE; + } else { + return FALSE; + } +} + int nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev) { @@ -258,6 +328,9 @@ nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev) pscreen->fence_signalled = nouveau_screen_fence_signalled; pscreen->fence_finish = nouveau_screen_fence_finish; + pscreen->texture_from_handle = nouveau_screen_texture_from_handle; + pscreen->texture_get_handle = nouveau_screen_texture_get_handle; + return 0; } diff --git a/src/gallium/drivers/nouveau/nouveau_screen.h b/src/gallium/drivers/nouveau/nouveau_screen.h index a7927d88dfc..f4a7a2bc234 100644 --- a/src/gallium/drivers/nouveau/nouveau_screen.h +++ b/src/gallium/drivers/nouveau/nouveau_screen.h @@ -6,6 +6,18 @@ struct nouveau_screen { struct nouveau_device *device; struct nouveau_channel *channel; + /** + * Create a new texture object, using the given template info, but on top of + * existing memory. + * + * It is assumed that the buffer data is layed out according to the expected + * by the hardware. NULL will be returned if any inconsistency is found. + */ + struct pipe_texture * (*texture_blanket)(struct pipe_screen *, + const struct pipe_texture *templat, + const unsigned *stride, + struct pipe_buffer *buffer); + int (*pre_pipebuffer_map_callback) (struct pipe_screen *pscreen, struct pipe_buffer *pb, unsigned usage); }; diff --git a/src/gallium/drivers/nouveau/nv04_surface_2d.c b/src/gallium/drivers/nouveau/nv04_surface_2d.c index 42c2ca932d8..b074547c4da 100644 --- a/src/gallium/drivers/nouveau/nv04_surface_2d.c +++ b/src/gallium/drivers/nouveau/nv04_surface_2d.c @@ -18,15 +18,15 @@ nv04_surface_format(enum pipe_format format) case PIPE_FORMAT_I8_UNORM: return NV04_CONTEXT_SURFACES_2D_FORMAT_Y8; case PIPE_FORMAT_R16_SNORM: - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_Z16_UNORM: - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: return NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5; - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return NV04_CONTEXT_SURFACES_2D_FORMAT_A8R8G8B8; - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: return NV04_CONTEXT_SURFACES_2D_FORMAT_Y32; default: return -1; @@ -39,14 +39,14 @@ nv04_rect_format(enum pipe_format format) switch (format) { case PIPE_FORMAT_A8_UNORM: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; - case PIPE_FORMAT_R5G6B5_UNORM: - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: + case PIPE_FORMAT_L8A8_UNORM: case PIPE_FORMAT_Z16_UNORM: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A16R5G6B5; - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; default: return -1; @@ -61,15 +61,15 @@ nv04_scaled_image_format(enum pipe_format format) case PIPE_FORMAT_L8_UNORM: case PIPE_FORMAT_I8_UNORM: return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_Y8; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A1R5G5B5; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A8R8G8B8; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_X8R8G8B8; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_R16_SNORM: - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_R5G6B5; default: return -1; diff --git a/src/gallium/drivers/nv30/nv30_context.h b/src/gallium/drivers/nv30/nv30_context.h index e48f531b942..1786460aec1 100644 --- a/src/gallium/drivers/nv30/nv30_context.h +++ b/src/gallium/drivers/nv30/nv30_context.h @@ -101,7 +101,6 @@ struct nv30_blend_state { struct nv30_state { unsigned scissor_enabled; unsigned stipple_enabled; - unsigned viewport_bypass; unsigned fp_samplers; uint64_t dirty; diff --git a/src/gallium/drivers/nv30/nv30_fragtex.c b/src/gallium/drivers/nv30/nv30_fragtex.c index 9f4a104f673..f7d98f3f208 100644 --- a/src/gallium/drivers/nv30/nv30_fragtex.c +++ b/src/gallium/drivers/nv30/nv30_fragtex.c @@ -23,17 +23,17 @@ struct nv30_texture_format { static struct nv30_texture_format nv30_texture_formats[] = { - _(X8R8G8B8_UNORM, A8R8G8B8, S1, S1, S1, ONE, X, Y, Z, W), - _(A8R8G8B8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W), - _(A1R5G5B5_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W), - _(A4R4G4B4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W), - _(R5G6B5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W), + _(B8G8R8X8_UNORM, A8R8G8B8, S1, S1, S1, ONE, X, Y, Z, W), + _(B8G8R8A8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W), + _(B5G5R5A1_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W), + _(B4G4R4A4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W), + _(B5G6R5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W), _(L8_UNORM , L8 , S1, S1, S1, ONE, X, X, X, X), _(A8_UNORM , L8 , ZERO, ZERO, ZERO, S1, X, X, X, X), _(I8_UNORM , L8 , S1, S1, S1, S1, X, X, X, X), - _(A8L8_UNORM , A8L8 , S1, S1, S1, S1, X, X, X, Y), + _(L8A8_UNORM , A8L8 , S1, S1, S1, S1, X, X, X, Y), _(Z16_UNORM , R5G6B5 , S1, S1, S1, ONE, X, X, X, X), - _(Z24S8_UNORM , A8R8G8B8, S1, S1, S1, ONE, X, X, X, X), + _(S8Z24_UNORM , A8R8G8B8, S1, S1, S1, ONE, X, X, X, X), _(DXT1_RGB , DXT1 , S1, S1, S1, ONE, X, Y, Z, W), _(DXT1_RGBA , DXT1 , S1, S1, S1, S1, X, Y, Z, W), _(DXT3_RGBA , DXT3 , S1, S1, S1, S1, X, Y, Z, W), diff --git a/src/gallium/drivers/nv30/nv30_miptree.c b/src/gallium/drivers/nv30/nv30_miptree.c index c29c36e20aa..bfa27b632f7 100644 --- a/src/gallium/drivers/nv30/nv30_miptree.c +++ b/src/gallium/drivers/nv30/nv30_miptree.c @@ -18,7 +18,7 @@ nv30_miptree_layout(struct nv30_miptree *nv30mt) PIPE_TEXTURE_USAGE_DEPTH_STENCIL | PIPE_TEXTURE_USAGE_RENDER_TARGET | PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_PRIMARY); + PIPE_TEXTURE_USAGE_SCANOUT); if (pt->target == PIPE_TEXTURE_CUBE) { nr_faces = 6; @@ -78,7 +78,7 @@ nv30_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) pt->height0 & (pt->height0 - 1)) mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR; else - if (pt->tex_usage & (PIPE_TEXTURE_USAGE_PRIMARY | + if (pt->tex_usage & (PIPE_TEXTURE_USAGE_SCANOUT | PIPE_TEXTURE_USAGE_DISPLAY_TARGET | PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR; @@ -88,11 +88,11 @@ nv30_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) else { switch (pt->format) { /* TODO: Figure out which formats can be swizzled */ - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: case PIPE_FORMAT_R16_SNORM: - case PIPE_FORMAT_R5G6B5_UNORM: - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: + case PIPE_FORMAT_L8A8_UNORM: case PIPE_FORMAT_A8_UNORM: case PIPE_FORMAT_L8_UNORM: case PIPE_FORMAT_I8_UNORM: @@ -232,8 +232,9 @@ void nv30_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv30_miptree_create; - pscreen->texture_blanket = nv30_miptree_blanket; pscreen->texture_destroy = nv30_miptree_destroy; pscreen->get_tex_surface = nv30_miptree_surface_new; pscreen->tex_surface_destroy = nv30_miptree_surface_del; + + nouveau_screen(pscreen)->texture_blanket = nv30_miptree_blanket; } diff --git a/src/gallium/drivers/nv30/nv30_screen.c b/src/gallium/drivers/nv30/nv30_screen.c index aef37d303d8..85433d20953 100644 --- a/src/gallium/drivers/nv30/nv30_screen.c +++ b/src/gallium/drivers/nv30/nv30_screen.c @@ -112,8 +112,8 @@ nv30_screen_surface_format_supported(struct pipe_screen *pscreen, if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) { switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: return TRUE; default: break; @@ -121,12 +121,12 @@ nv30_screen_surface_format_supported(struct pipe_screen *pscreen, } else if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) { switch (format) { - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: return TRUE; case PIPE_FORMAT_Z16_UNORM: if (front) { - return (front->format == PIPE_FORMAT_R5G6B5_UNORM); + return (front->format == PIPE_FORMAT_B5G6R5_UNORM); } return TRUE; default: @@ -134,16 +134,16 @@ nv30_screen_surface_format_supported(struct pipe_screen *pscreen, } } else { switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_A1R5G5B5_UNORM: - case PIPE_FORMAT_A4R4G4B4_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_L8_UNORM: case PIPE_FORMAT_A8_UNORM: case PIPE_FORMAT_I8_UNORM: - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: case PIPE_FORMAT_Z16_UNORM: - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: return TRUE; default: break; diff --git a/src/gallium/drivers/nv30/nv30_state.h b/src/gallium/drivers/nv30/nv30_state.h index e42e872de75..66c26360cb2 100644 --- a/src/gallium/drivers/nv30/nv30_state.h +++ b/src/gallium/drivers/nv30/nv30_state.h @@ -70,6 +70,8 @@ struct nv30_fragment_program { struct nouveau_stateobj *so; }; +#define NV30_MAX_TEXTURE_LEVELS 16 + struct nv30_miptree { struct pipe_texture base; struct nouveau_bo *bo; @@ -80,7 +82,7 @@ struct nv30_miptree { struct { uint pitch; uint *image_offset; - } level[PIPE_MAX_TEXTURE_LEVELS]; + } level[NV30_MAX_TEXTURE_LEVELS]; }; #endif diff --git a/src/gallium/drivers/nv30/nv30_state_fb.c b/src/gallium/drivers/nv30/nv30_state_fb.c index 2ed2ea55e84..f7fe9833c77 100644 --- a/src/gallium/drivers/nv30/nv30_state_fb.c +++ b/src/gallium/drivers/nv30/nv30_state_fb.c @@ -66,14 +66,14 @@ nv30_state_framebuffer_validate(struct nv30_context *nv30) } switch (colour_format) { - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: rt_format |= NV34TCL_RT_FORMAT_COLOR_X8R8G8B8; break; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: case 0: rt_format |= NV34TCL_RT_FORMAT_COLOR_A8R8G8B8; break; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: rt_format |= NV34TCL_RT_FORMAT_COLOR_R5G6B5; colour_bits = 16; break; @@ -86,8 +86,8 @@ nv30_state_framebuffer_validate(struct nv30_context *nv30) rt_format |= NV34TCL_RT_FORMAT_ZETA_Z16; zeta_bits = 16; break; - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: case 0: rt_format |= NV34TCL_RT_FORMAT_ZETA_Z24S8; break; diff --git a/src/gallium/drivers/nv30/nv30_state_viewport.c b/src/gallium/drivers/nv30/nv30_state_viewport.c index 2d7781292bd..6fccd6b60e7 100644 --- a/src/gallium/drivers/nv30/nv30_state_viewport.c +++ b/src/gallium/drivers/nv30/nv30_state_viewport.c @@ -5,55 +5,25 @@ nv30_state_viewport_validate(struct nv30_context *nv30) { struct pipe_viewport_state *vpt = &nv30->viewport; struct nouveau_stateobj *so; - unsigned bypass; - - if (/*nv30->render_mode == HW &&*/ - !nv30->rasterizer->pipe.bypass_vs_clip_and_viewport) - bypass = 0; - else - bypass = 1; if (nv30->state.hw[NV30_STATE_VIEWPORT] && - (bypass || !(nv30->dirty & NV30_NEW_VIEWPORT)) && - nv30->state.viewport_bypass == bypass) + !(nv30->dirty & NV30_NEW_VIEWPORT)) return FALSE; - nv30->state.viewport_bypass = bypass; so = so_new(3, 10, 0); - if (!bypass) { - so_method(so, nv30->screen->rankine, - NV34TCL_VIEWPORT_TRANSLATE_X, 8); - so_data (so, fui(vpt->translate[0])); - so_data (so, fui(vpt->translate[1])); - so_data (so, fui(vpt->translate[2])); - so_data (so, fui(vpt->translate[3])); - so_data (so, fui(vpt->scale[0])); - so_data (so, fui(vpt->scale[1])); - so_data (so, fui(vpt->scale[2])); - so_data (so, fui(vpt->scale[3])); -/* so_method(so, nv30->screen->rankine, 0x1d78, 1); - so_data (so, 1); -*/ } else { - so_method(so, nv30->screen->rankine, - NV34TCL_VIEWPORT_TRANSLATE_X, 8); - so_data (so, fui(0.0)); - so_data (so, fui(0.0)); - so_data (so, fui(0.0)); - so_data (so, fui(0.0)); - so_data (so, fui(1.0)); - so_data (so, fui(1.0)); - so_data (so, fui(1.0)); - so_data (so, fui(0.0)); - /* Not entirely certain what this is yet. The DDX uses this - * value also as it fixes rendering when you pass - * pre-transformed vertices to the GPU. My best gusss is that - * this bypasses some culling/clipping stage. Might be worth - * noting that points/lines are uneffected by whatever this - * value fixes, only filled polygons are effected. - */ -/* so_method(so, nv30->screen->rankine, 0x1d78, 1); - so_data (so, 0x110); -*/ } + so_method(so, nv30->screen->rankine, + NV34TCL_VIEWPORT_TRANSLATE_X, 8); + so_data (so, fui(vpt->translate[0])); + so_data (so, fui(vpt->translate[1])); + so_data (so, fui(vpt->translate[2])); + so_data (so, fui(vpt->translate[3])); + so_data (so, fui(vpt->scale[0])); + so_data (so, fui(vpt->scale[1])); + so_data (so, fui(vpt->scale[2])); + so_data (so, fui(vpt->scale[3])); +/* so_method(so, nv30->screen->rankine, 0x1d78, 1); + so_data (so, 1); +*/ /* TODO/FIXME: never saw value 0x0110 in renouveau dumps, only 0x0001 */ so_method(so, nv30->screen->rankine, 0x1d78, 1); so_data (so, 1); diff --git a/src/gallium/drivers/nv30/nv30_transfer.c b/src/gallium/drivers/nv30/nv30_transfer.c index 554bcbbdd0e..3aeda51ea19 100644 --- a/src/gallium/drivers/nv30/nv30_transfer.c +++ b/src/gallium/drivers/nv30/nv30_transfer.c @@ -1,10 +1,10 @@ -#include <pipe/p_state.h> -#include <pipe/p_defines.h> -#include <util/u_inlines.h> -#include <util/u_format.h> -#include <util/u_memory.h> -#include <util/u_math.h> -#include <nouveau/nouveau_winsys.h> +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "nouveau/nouveau_winsys.h" #include "nv30_context.h" #include "nv30_screen.h" #include "nv30_state.h" diff --git a/src/gallium/drivers/nv40/nv40_context.h b/src/gallium/drivers/nv40/nv40_context.h index f96f2b89bf9..2550ec654b3 100644 --- a/src/gallium/drivers/nv40/nv40_context.h +++ b/src/gallium/drivers/nv40/nv40_context.h @@ -101,7 +101,6 @@ struct nv40_blend_state { struct nv40_state { unsigned scissor_enabled; unsigned stipple_enabled; - unsigned viewport_bypass; unsigned fp_samplers; uint64_t dirty; diff --git a/src/gallium/drivers/nv40/nv40_fragtex.c b/src/gallium/drivers/nv40/nv40_fragtex.c index 7a28d577b14..b60118922a2 100644 --- a/src/gallium/drivers/nv40/nv40_fragtex.c +++ b/src/gallium/drivers/nv40/nv40_fragtex.c @@ -25,18 +25,18 @@ struct nv40_texture_format { static struct nv40_texture_format nv40_texture_formats[] = { - _(X8R8G8B8_UNORM, A8R8G8B8, S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), - _(A8R8G8B8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - _(A1R5G5B5_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - _(A4R4G4B4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), - _(R5G6B5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), + _(B8G8R8X8_UNORM, A8R8G8B8, S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), + _(B8G8R8A8_UNORM, A8R8G8B8, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + _(B5G5R5A1_UNORM, A1R5G5B5, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + _(B4G4R4A4_UNORM, A4R4G4B4, S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), + _(B5G6R5_UNORM , R5G6B5 , S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), _(L8_UNORM , L8 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), _(A8_UNORM , L8 , ZERO, ZERO, ZERO, S1, X, X, X, X, 0, 0, 0, 0), _(R16_SNORM , A16 , ZERO, ZERO, S1, ONE, X, X, X, Y, 1, 1, 1, 1), _(I8_UNORM , L8 , S1, S1, S1, S1, X, X, X, X, 0, 0, 0, 0), - _(A8L8_UNORM , A8L8 , S1, S1, S1, S1, X, X, X, Y, 0, 0, 0, 0), + _(L8A8_UNORM , A8L8 , S1, S1, S1, S1, X, X, X, Y, 0, 0, 0, 0), _(Z16_UNORM , Z16 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), - _(Z24S8_UNORM , Z24 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), + _(S8Z24_UNORM , Z24 , S1, S1, S1, ONE, X, X, X, X, 0, 0, 0, 0), _(DXT1_RGB , DXT1 , S1, S1, S1, ONE, X, Y, Z, W, 0, 0, 0, 0), _(DXT1_RGBA , DXT1 , S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), _(DXT3_RGBA , DXT3 , S1, S1, S1, S1, X, Y, Z, W, 0, 0, 0, 0), diff --git a/src/gallium/drivers/nv40/nv40_miptree.c b/src/gallium/drivers/nv40/nv40_miptree.c index ad1a9a51952..62e97bcea48 100644 --- a/src/gallium/drivers/nv40/nv40_miptree.c +++ b/src/gallium/drivers/nv40/nv40_miptree.c @@ -20,7 +20,7 @@ nv40_miptree_layout(struct nv40_miptree *mt) PIPE_TEXTURE_USAGE_DEPTH_STENCIL | PIPE_TEXTURE_USAGE_RENDER_TARGET | PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_PRIMARY); + PIPE_TEXTURE_USAGE_SCANOUT); if (pt->target == PIPE_TEXTURE_CUBE) { nr_faces = 6; @@ -80,7 +80,7 @@ nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) pt->height0 & (pt->height0 - 1)) mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR; else - if (pt->tex_usage & (PIPE_TEXTURE_USAGE_PRIMARY | + if (pt->tex_usage & (PIPE_TEXTURE_USAGE_SCANOUT | PIPE_TEXTURE_USAGE_DISPLAY_TARGET | PIPE_TEXTURE_USAGE_DEPTH_STENCIL)) mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR; @@ -90,8 +90,8 @@ nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt) else { switch (pt->format) { /* TODO: Figure out which formats can be swizzled */ - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: case PIPE_FORMAT_R16_SNORM: { if (debug_get_bool_option("NOUVEAU_NO_SWIZZLE", FALSE)) @@ -227,9 +227,10 @@ void nv40_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv40_miptree_create; - pscreen->texture_blanket = nv40_miptree_blanket; pscreen->texture_destroy = nv40_miptree_destroy; pscreen->get_tex_surface = nv40_miptree_surface_new; pscreen->tex_surface_destroy = nv40_miptree_surface_del; + + nouveau_screen(pscreen)->texture_blanket = nv40_miptree_blanket; } diff --git a/src/gallium/drivers/nv40/nv40_screen.c b/src/gallium/drivers/nv40/nv40_screen.c index 001147e752f..b216c5e38c9 100644 --- a/src/gallium/drivers/nv40/nv40_screen.c +++ b/src/gallium/drivers/nv40/nv40_screen.c @@ -62,6 +62,8 @@ nv40_screen_get_param(struct pipe_screen *pscreen, int param) case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT: case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER: return 0; + case PIPE_CAP_MAX_COMBINED_SAMPLERS: + return 16; default: NOUVEAU_ERR("Unknown PIPE_CAP %d\n", param); return 0; @@ -96,8 +98,8 @@ nv40_screen_surface_format_supported(struct pipe_screen *pscreen, { if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) { switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: return TRUE; default: break; @@ -105,8 +107,8 @@ nv40_screen_surface_format_supported(struct pipe_screen *pscreen, } else if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) { switch (format) { - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: case PIPE_FORMAT_Z16_UNORM: return TRUE; default: @@ -114,17 +116,17 @@ nv40_screen_surface_format_supported(struct pipe_screen *pscreen, } } else { switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_A1R5G5B5_UNORM: - case PIPE_FORMAT_A4R4G4B4_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_R16_SNORM: case PIPE_FORMAT_L8_UNORM: case PIPE_FORMAT_A8_UNORM: case PIPE_FORMAT_I8_UNORM: - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: case PIPE_FORMAT_Z16_UNORM: - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: case PIPE_FORMAT_DXT1_RGB: case PIPE_FORMAT_DXT1_RGBA: case PIPE_FORMAT_DXT3_RGBA: diff --git a/src/gallium/drivers/nv40/nv40_state.c b/src/gallium/drivers/nv40/nv40_state.c index 449e246b8c2..ee471e6ce4c 100644 --- a/src/gallium/drivers/nv40/nv40_state.c +++ b/src/gallium/drivers/nv40/nv40_state.c @@ -310,7 +310,7 @@ nv40_rasterizer_state_create(struct pipe_context *pipe, { struct nv40_context *nv40 = nv40_context(pipe); struct nv40_rasterizer_state *rsso = CALLOC(1, sizeof(*rsso)); - struct nouveau_stateobj *so = so_new(8, 18, 0); + struct nouveau_stateobj *so = so_new(9, 19, 0); struct nouveau_grobj *curie = nv40->screen->curie; /*XXX: ignored: diff --git a/src/gallium/drivers/nv40/nv40_state.h b/src/gallium/drivers/nv40/nv40_state.h index 192074e7471..e2e69420eae 100644 --- a/src/gallium/drivers/nv40/nv40_state.h +++ b/src/gallium/drivers/nv40/nv40_state.h @@ -73,6 +73,8 @@ struct nv40_fragment_program { struct nouveau_stateobj *so; }; +#define NV40_MAX_TEXTURE_LEVELS 16 + struct nv40_miptree { struct pipe_texture base; struct nouveau_bo *bo; @@ -83,7 +85,7 @@ struct nv40_miptree { struct { uint pitch; uint *image_offset; - } level[PIPE_MAX_TEXTURE_LEVELS]; + } level[NV40_MAX_TEXTURE_LEVELS]; }; #endif diff --git a/src/gallium/drivers/nv40/nv40_state_fb.c b/src/gallium/drivers/nv40/nv40_state_fb.c index a58fe9ddb19..fd3fdfddc09 100644 --- a/src/gallium/drivers/nv40/nv40_state_fb.c +++ b/src/gallium/drivers/nv40/nv40_state_fb.c @@ -57,14 +57,14 @@ nv40_state_framebuffer_validate(struct nv40_context *nv40) rt_format = NV40TCL_RT_FORMAT_TYPE_LINEAR; switch (colour_format) { - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: rt_format |= NV40TCL_RT_FORMAT_COLOR_X8R8G8B8; break; - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: case 0: rt_format |= NV40TCL_RT_FORMAT_COLOR_A8R8G8B8; break; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: rt_format |= NV40TCL_RT_FORMAT_COLOR_R5G6B5; break; default: @@ -75,8 +75,8 @@ nv40_state_framebuffer_validate(struct nv40_context *nv40) case PIPE_FORMAT_Z16_UNORM: rt_format |= NV40TCL_RT_FORMAT_ZETA_Z16; break; - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: case 0: rt_format |= NV40TCL_RT_FORMAT_ZETA_Z24S8; break; diff --git a/src/gallium/drivers/nv40/nv40_state_viewport.c b/src/gallium/drivers/nv40/nv40_state_viewport.c index 9919ba1d0b0..3aacb00f996 100644 --- a/src/gallium/drivers/nv40/nv40_state_viewport.c +++ b/src/gallium/drivers/nv40/nv40_state_viewport.c @@ -5,55 +5,24 @@ nv40_state_viewport_validate(struct nv40_context *nv40) { struct pipe_viewport_state *vpt = &nv40->viewport; struct nouveau_stateobj *so; - unsigned bypass; - - if (nv40->render_mode == HW && - !nv40->rasterizer->pipe.bypass_vs_clip_and_viewport) - bypass = 0; - else - bypass = 1; if (nv40->state.hw[NV40_STATE_VIEWPORT] && - (bypass || !(nv40->dirty & NV40_NEW_VIEWPORT)) && - nv40->state.viewport_bypass == bypass) + !(nv40->dirty & NV40_NEW_VIEWPORT)) return FALSE; - nv40->state.viewport_bypass = bypass; so = so_new(2, 9, 0); - if (!bypass) { - so_method(so, nv40->screen->curie, - NV40TCL_VIEWPORT_TRANSLATE_X, 8); - so_data (so, fui(vpt->translate[0])); - so_data (so, fui(vpt->translate[1])); - so_data (so, fui(vpt->translate[2])); - so_data (so, fui(vpt->translate[3])); - so_data (so, fui(vpt->scale[0])); - so_data (so, fui(vpt->scale[1])); - so_data (so, fui(vpt->scale[2])); - so_data (so, fui(vpt->scale[3])); - so_method(so, nv40->screen->curie, 0x1d78, 1); - so_data (so, 1); - } else { - so_method(so, nv40->screen->curie, - NV40TCL_VIEWPORT_TRANSLATE_X, 8); - so_data (so, fui(0.0)); - so_data (so, fui(0.0)); - so_data (so, fui(0.0)); - so_data (so, fui(0.0)); - so_data (so, fui(1.0)); - so_data (so, fui(1.0)); - so_data (so, fui(1.0)); - so_data (so, fui(0.0)); - /* Not entirely certain what this is yet. The DDX uses this - * value also as it fixes rendering when you pass - * pre-transformed vertices to the GPU. My best gusss is that - * this bypasses some culling/clipping stage. Might be worth - * noting that points/lines are uneffected by whatever this - * value fixes, only filled polygons are effected. - */ - so_method(so, nv40->screen->curie, 0x1d78, 1); - so_data (so, 0x110); - } + so_method(so, nv40->screen->curie, + NV40TCL_VIEWPORT_TRANSLATE_X, 8); + so_data (so, fui(vpt->translate[0])); + so_data (so, fui(vpt->translate[1])); + so_data (so, fui(vpt->translate[2])); + so_data (so, fui(vpt->translate[3])); + so_data (so, fui(vpt->scale[0])); + so_data (so, fui(vpt->scale[1])); + so_data (so, fui(vpt->scale[2])); + so_data (so, fui(vpt->scale[3])); + so_method(so, nv40->screen->curie, 0x1d78, 1); + so_data (so, 1); so_ref(so, &nv40->state.hw[NV40_STATE_VIEWPORT]); so_ref(NULL, &so); diff --git a/src/gallium/drivers/nv40/nv40_transfer.c b/src/gallium/drivers/nv40/nv40_transfer.c index ee266c6cfb1..0462a042c38 100644 --- a/src/gallium/drivers/nv40/nv40_transfer.c +++ b/src/gallium/drivers/nv40/nv40_transfer.c @@ -1,10 +1,10 @@ -#include <pipe/p_state.h> -#include <pipe/p_defines.h> -#include <util/u_inlines.h> -#include <util/u_format.h> -#include <util/u_memory.h> -#include <util/u_math.h> -#include <nouveau/nouveau_winsys.h> +#include "pipe/p_state.h" +#include "pipe/p_defines.h" +#include "util/u_inlines.h" +#include "util/u_format.h" +#include "util/u_memory.h" +#include "util/u_math.h" +#include "nouveau/nouveau_winsys.h" #include "nv40_context.h" #include "nv40_screen.h" #include "nv40_state.h" diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h index 811b3ef9fea..e91a61b27dd 100644 --- a/src/gallium/drivers/nv50/nv50_context.h +++ b/src/gallium/drivers/nv50/nv50_context.h @@ -96,10 +96,12 @@ struct nv50_miptree_level { unsigned tile_mode; }; +#define NV50_MAX_TEXTURE_LEVELS 16 + struct nv50_miptree { struct nouveau_miptree base; - struct nv50_miptree_level level[PIPE_MAX_TEXTURE_LEVELS]; + struct nv50_miptree_level level[NV50_MAX_TEXTURE_LEVELS]; int image_nr; int total_size; }; @@ -133,7 +135,6 @@ struct nv50_state { struct nouveau_stateobj *scissor; unsigned scissor_enabled; struct nouveau_stateobj *viewport; - unsigned viewport_bypass; struct nouveau_stateobj *tsc_upload; struct nouveau_stateobj *tic_upload; unsigned miptree_nr[PIPE_SHADER_TYPES]; diff --git a/src/gallium/drivers/nv50/nv50_miptree.c b/src/gallium/drivers/nv50/nv50_miptree.c index 7297c74a83c..e091cae6024 100644 --- a/src/gallium/drivers/nv50/nv50_miptree.c +++ b/src/gallium/drivers/nv50/nv50_miptree.c @@ -89,14 +89,14 @@ nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *tmp) case PIPE_FORMAT_Z32_FLOAT: tile_flags = 0x4800; break; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: tile_flags = 0x1800; break; case PIPE_FORMAT_Z16_UNORM: tile_flags = 0x6c00; break; - case PIPE_FORMAT_X8Z24_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: tile_flags = 0x2800; break; case PIPE_FORMAT_R32G32B32A32_FLOAT: @@ -104,7 +104,7 @@ nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *tmp) tile_flags = 0x7400; break; default: - if ((pt->tex_usage & PIPE_TEXTURE_USAGE_PRIMARY) && + if ((pt->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) && util_format_get_blocksizebits(pt->format) == 32) tile_flags = 0x7a00; else @@ -255,9 +255,10 @@ void nv50_screen_init_miptree_functions(struct pipe_screen *pscreen) { pscreen->texture_create = nv50_miptree_create; - pscreen->texture_blanket = nv50_miptree_blanket; pscreen->texture_destroy = nv50_miptree_destroy; pscreen->get_tex_surface = nv50_miptree_surface_new; pscreen->tex_surface_destroy = nv50_miptree_surface_del; + + nouveau_screen(pscreen)->texture_blanket = nv50_miptree_blanket; } diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c index 2232461b9b6..eed6031eafa 100644 --- a/src/gallium/drivers/nv50/nv50_screen.c +++ b/src/gallium/drivers/nv50/nv50_screen.c @@ -35,9 +35,9 @@ nv50_screen_is_format_supported(struct pipe_screen *pscreen, { if (tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) { switch (format) { - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_R16G16B16A16_SNORM: case PIPE_FORMAT_R16G16B16A16_UNORM: case PIPE_FORMAT_R32G32B32A32_FLOAT: @@ -51,32 +51,32 @@ nv50_screen_is_format_supported(struct pipe_screen *pscreen, if (tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) { switch (format) { case PIPE_FORMAT_Z32_FLOAT: - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: return TRUE; default: break; } } else { switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_A8R8G8B8_SRGB: - case PIPE_FORMAT_X8R8G8B8_SRGB: - case PIPE_FORMAT_A1R5G5B5_UNORM: - case PIPE_FORMAT_A4R4G4B4_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_SRGB: + case PIPE_FORMAT_B8G8R8X8_SRGB: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: case PIPE_FORMAT_L8_UNORM: case PIPE_FORMAT_A8_UNORM: case PIPE_FORMAT_I8_UNORM: - case PIPE_FORMAT_A8L8_UNORM: + case PIPE_FORMAT_L8A8_UNORM: case PIPE_FORMAT_DXT1_RGB: case PIPE_FORMAT_DXT1_RGBA: case PIPE_FORMAT_DXT3_RGBA: case PIPE_FORMAT_DXT5_RGBA: - case PIPE_FORMAT_Z24S8_UNORM: case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: case PIPE_FORMAT_Z32_FLOAT: case PIPE_FORMAT_R16G16B16A16_SNORM: case PIPE_FORMAT_R16G16B16A16_UNORM: diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c index efab94cab74..c974cc92dcc 100644 --- a/src/gallium/drivers/nv50/nv50_state_validate.c +++ b/src/gallium/drivers/nv50/nv50_state_validate.c @@ -25,12 +25,6 @@ #include "nv50_context.h" #include "nouveau/nouveau_stateobj.h" -#define NV50_CBUF_FORMAT_CASE(n) \ - case PIPE_FORMAT_##n: so_data(so, NV50TCL_RT_FORMAT_##n); break - -#define NV50_ZETA_FORMAT_CASE(n) \ - case PIPE_FORMAT_##n: so_data(so, NV50TCL_ZETA_FORMAT_##n); break - static void nv50_state_validate_fb(struct nv50_context *nv50) { @@ -71,14 +65,30 @@ nv50_state_validate_fb(struct nv50_context *nv50) so_reloc (so, bo, fb->cbufs[i]->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW | NOUVEAU_BO_RDWR, 0, 0); switch (fb->cbufs[i]->format) { - NV50_CBUF_FORMAT_CASE(A8R8G8B8_UNORM); - NV50_CBUF_FORMAT_CASE(X8R8G8B8_UNORM); - NV50_CBUF_FORMAT_CASE(R5G6B5_UNORM); - NV50_CBUF_FORMAT_CASE(R16G16B16A16_SNORM); - NV50_CBUF_FORMAT_CASE(R16G16B16A16_UNORM); - NV50_CBUF_FORMAT_CASE(R32G32B32A32_FLOAT); - NV50_CBUF_FORMAT_CASE(R16G16_SNORM); - NV50_CBUF_FORMAT_CASE(R16G16_UNORM); + case PIPE_FORMAT_B8G8R8A8_UNORM: + so_data(so, NV50TCL_RT_FORMAT_A8R8G8B8_UNORM); + break; + case PIPE_FORMAT_B8G8R8X8_UNORM: + so_data(so, NV50TCL_RT_FORMAT_X8R8G8B8_UNORM); + break; + case PIPE_FORMAT_B5G6R5_UNORM: + so_data(so, NV50TCL_RT_FORMAT_R5G6B5_UNORM); + break; + case PIPE_FORMAT_R16G16B16A16_SNORM: + so_data(so, NV50TCL_RT_FORMAT_R16G16B16A16_SNORM); + break; + case PIPE_FORMAT_R16G16B16A16_UNORM: + so_data(so, NV50TCL_RT_FORMAT_R16G16B16A16_UNORM); + break; + case PIPE_FORMAT_R32G32B32A32_FLOAT: + so_data(so, NV50TCL_RT_FORMAT_R32G32B32A32_FLOAT); + break; + case PIPE_FORMAT_R16G16_SNORM: + so_data(so, NV50TCL_RT_FORMAT_R16G16_SNORM); + break; + case PIPE_FORMAT_R16G16_UNORM: + so_data(so, NV50TCL_RT_FORMAT_R16G16_UNORM); + break; default: NOUVEAU_ERR("AIIII unknown format %s\n", util_format_name(fb->cbufs[i]->format)); @@ -112,10 +122,18 @@ nv50_state_validate_fb(struct nv50_context *nv50) so_reloc (so, bo, fb->zsbuf->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW | NOUVEAU_BO_RDWR, 0, 0); switch (fb->zsbuf->format) { - NV50_ZETA_FORMAT_CASE(S8Z24_UNORM); - NV50_ZETA_FORMAT_CASE(X8Z24_UNORM); - NV50_ZETA_FORMAT_CASE(Z24S8_UNORM); - NV50_ZETA_FORMAT_CASE(Z32_FLOAT); + case PIPE_FORMAT_Z24S8_UNORM: + so_data(so, NV50TCL_ZETA_FORMAT_S8Z24_UNORM); + break; + case PIPE_FORMAT_Z24X8_UNORM: + so_data(so, NV50TCL_ZETA_FORMAT_X8Z24_UNORM); + break; + case PIPE_FORMAT_S8Z24_UNORM: + so_data(so, NV50TCL_ZETA_FORMAT_Z24S8_UNORM); + break; + case PIPE_FORMAT_Z32_FLOAT: + so_data(so, NV50TCL_ZETA_FORMAT_Z32_FLOAT); + break; default: NOUVEAU_ERR("AIIII unknown format %s\n", util_format_name(fb->zsbuf->format)); @@ -375,50 +393,32 @@ nv50_state_validate(struct nv50_context *nv50) scissor_uptodate: if (nv50->dirty & (NV50_NEW_VIEWPORT | NV50_NEW_RASTERIZER)) { - unsigned bypass; - - if (!nv50->rasterizer->pipe.bypass_vs_clip_and_viewport) - bypass = 0; - else - bypass = 1; - if (nv50->state.viewport && - (bypass || !(nv50->dirty & NV50_NEW_VIEWPORT)) && - nv50->state.viewport_bypass == bypass) + !(nv50->dirty & NV50_NEW_VIEWPORT)) goto viewport_uptodate; - nv50->state.viewport_bypass = bypass; so = so_new(5, 9, 0); - if (!bypass) { - so_method(so, tesla, NV50TCL_VIEWPORT_TRANSLATE_X(0), 3); - so_data (so, fui(nv50->viewport.translate[0])); - so_data (so, fui(nv50->viewport.translate[1])); - so_data (so, fui(nv50->viewport.translate[2])); - so_method(so, tesla, NV50TCL_VIEWPORT_SCALE_X(0), 3); - so_data (so, fui(nv50->viewport.scale[0])); - so_data (so, fui(nv50->viewport.scale[1])); - so_data (so, fui(nv50->viewport.scale[2])); - - so_method(so, tesla, NV50TCL_VIEWPORT_TRANSFORM_EN, 1); - so_data (so, 1); - /* 0x0000 = remove whole primitive only (xyz) - * 0x1018 = remove whole primitive only (xy), clamp z - * 0x1080 = clip primitive (xyz) - * 0x1098 = clip primitive (xy), clamp z - */ - so_method(so, tesla, NV50TCL_VIEW_VOLUME_CLIP_CTRL, 1); - so_data (so, 0x1080); - /* no idea what 0f90 does */ - so_method(so, tesla, 0x0f90, 1); - so_data (so, 0); - } else { - so_method(so, tesla, NV50TCL_VIEWPORT_TRANSFORM_EN, 1); - so_data (so, 0); - so_method(so, tesla, NV50TCL_VIEW_VOLUME_CLIP_CTRL, 1); - so_data (so, 0x0000); - so_method(so, tesla, 0x0f90, 1); - so_data (so, 1); - } + so_method(so, tesla, NV50TCL_VIEWPORT_TRANSLATE_X(0), 3); + so_data (so, fui(nv50->viewport.translate[0])); + so_data (so, fui(nv50->viewport.translate[1])); + so_data (so, fui(nv50->viewport.translate[2])); + so_method(so, tesla, NV50TCL_VIEWPORT_SCALE_X(0), 3); + so_data (so, fui(nv50->viewport.scale[0])); + so_data (so, fui(nv50->viewport.scale[1])); + so_data (so, fui(nv50->viewport.scale[2])); + + so_method(so, tesla, NV50TCL_VIEWPORT_TRANSFORM_EN, 1); + so_data (so, 1); + /* 0x0000 = remove whole primitive only (xyz) + * 0x1018 = remove whole primitive only (xy), clamp z + * 0x1080 = clip primitive (xyz) + * 0x1098 = clip primitive (xy), clamp z + */ + so_method(so, tesla, NV50TCL_VIEW_VOLUME_CLIP_CTRL, 1); + so_data (so, 0x1080); + /* no idea what 0f90 does */ + so_method(so, tesla, 0x0f90, 1); + so_data (so, 0); so_ref(so, &nv50->state.viewport); so_ref(NULL, &so); diff --git a/src/gallium/drivers/nv50/nv50_surface.c b/src/gallium/drivers/nv50/nv50_surface.c index 7405b67414a..cabd148bc5b 100644 --- a/src/gallium/drivers/nv50/nv50_surface.c +++ b/src/gallium/drivers/nv50/nv50_surface.c @@ -33,11 +33,11 @@ static INLINE int nv50_format(enum pipe_format format) { switch (format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return NV50_2D_DST_FORMAT_A8R8G8B8_UNORM; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: return NV50_2D_DST_FORMAT_X8R8G8B8_UNORM; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: return NV50_2D_DST_FORMAT_R5G6B5_UNORM; case PIPE_FORMAT_A8_UNORM: return NV50_2D_DST_FORMAT_R8_UNORM; diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c index 9f1a1713032..de0560e20cd 100644 --- a/src/gallium/drivers/nv50/nv50_tex.c +++ b/src/gallium/drivers/nv50/nv50_tex.c @@ -49,28 +49,28 @@ struct nv50_texture_format { static const struct nv50_texture_format nv50_tex_format_list[] = { - _(A8R8G8B8_UNORM, UNORM, C2, C1, C0, C3, 8_8_8_8), - _(A8R8G8B8_SRGB, UNORM, C2, C1, C0, C3, 8_8_8_8), - _(X8R8G8B8_UNORM, UNORM, C2, C1, C0, ONE, 8_8_8_8), - _(X8R8G8B8_SRGB, UNORM, C2, C1, C0, ONE, 8_8_8_8), - _(A1R5G5B5_UNORM, UNORM, C2, C1, C0, C3, 1_5_5_5), - _(A4R4G4B4_UNORM, UNORM, C2, C1, C0, C3, 4_4_4_4), + _(B8G8R8A8_UNORM, UNORM, C2, C1, C0, C3, 8_8_8_8), + _(B8G8R8A8_SRGB, UNORM, C2, C1, C0, C3, 8_8_8_8), + _(B8G8R8X8_UNORM, UNORM, C2, C1, C0, ONE, 8_8_8_8), + _(B8G8R8X8_SRGB, UNORM, C2, C1, C0, ONE, 8_8_8_8), + _(B5G5R5A1_UNORM, UNORM, C2, C1, C0, C3, 1_5_5_5), + _(B4G4R4A4_UNORM, UNORM, C2, C1, C0, C3, 4_4_4_4), - _(R5G6B5_UNORM, UNORM, C2, C1, C0, ONE, 5_6_5), + _(B5G6R5_UNORM, UNORM, C2, C1, C0, ONE, 5_6_5), _(L8_UNORM, UNORM, C0, C0, C0, ONE, 8), _(A8_UNORM, UNORM, ZERO, ZERO, ZERO, C0, 8), _(I8_UNORM, UNORM, C0, C0, C0, C0, 8), - _(A8L8_UNORM, UNORM, C0, C0, C0, C1, 8_8), + _(L8A8_UNORM, UNORM, C0, C0, C0, C1, 8_8), _(DXT1_RGB, UNORM, C0, C1, C2, ONE, DXT1), _(DXT1_RGBA, UNORM, C0, C1, C2, C3, DXT1), _(DXT3_RGBA, UNORM, C0, C1, C2, C3, DXT3), _(DXT5_RGBA, UNORM, C0, C1, C2, C3, DXT5), - _MIXED(Z24S8_UNORM, UINT, UNORM, UINT, UINT, C1, C1, C1, ONE, 24_8), - _MIXED(S8Z24_UNORM, UNORM, UINT, UINT, UINT, C0, C0, C0, ONE, 8_24), + _MIXED(S8Z24_UNORM, UINT, UNORM, UINT, UINT, C1, C1, C1, ONE, 24_8), + _MIXED(Z24S8_UNORM, UNORM, UINT, UINT, UINT, C0, C0, C0, ONE, 8_24), _(R16G16B16A16_SNORM, UNORM, C0, C1, C2, C3, 16_16_16_16), _(R16G16B16A16_UNORM, SNORM, C0, C1, C2, C3, 16_16_16_16), diff --git a/src/gallium/drivers/r300/Makefile b/src/gallium/drivers/r300/Makefile index afddcb161fa..61b54af4ddf 100644 --- a/src/gallium/drivers/r300/Makefile +++ b/src/gallium/drivers/r300/Makefile @@ -19,7 +19,8 @@ C_SOURCES = \ r300_state_invariant.c \ r300_vs.c \ r300_texture.c \ - r300_tgsi_to_rc.c + r300_tgsi_to_rc.c \ + r300_transfer.c LIBRARY_INCLUDES = \ -I$(TOP)/src/mesa/drivers/dri/r300/compiler \ @@ -32,7 +33,5 @@ EXTRA_OBJECTS = \ include ../../Makefile.template -.PHONY : $(COMPILER_ARCHIVE) - $(COMPILER_ARCHIVE): $(MAKE) -C $(TOP)/src/mesa/drivers/dri/r300/compiler diff --git a/src/gallium/drivers/r300/SConscript b/src/gallium/drivers/r300/SConscript index 183aa17f9b3..27b2e309932 100644 --- a/src/gallium/drivers/r300/SConscript +++ b/src/gallium/drivers/r300/SConscript @@ -30,6 +30,7 @@ r300 = env.ConvenienceLibrary( 'r300_vs.c', 'r300_texture.c', 'r300_tgsi_to_rc.c', + 'r300_transfer.c', ] + r300compiler) + r300compiler Export('r300') diff --git a/src/gallium/drivers/r300/r300_blit.c b/src/gallium/drivers/r300/r300_blit.c index 297768e5cf4..b7ad6b20206 100644 --- a/src/gallium/drivers/r300/r300_blit.c +++ b/src/gallium/drivers/r300/r300_blit.c @@ -33,7 +33,9 @@ static void r300_blitter_save_states(struct r300_context* r300) util_blitter_save_stencil_ref(r300->blitter, &(r300->stencil_ref)); util_blitter_save_rasterizer(r300->blitter, r300->rs_state.state); util_blitter_save_fragment_shader(r300->blitter, r300->fs); - util_blitter_save_vertex_shader(r300->blitter, r300->vs); + util_blitter_save_vertex_shader(r300->blitter, r300->vs_state.state); + util_blitter_save_viewport(r300->blitter, &r300->viewport); + util_blitter_save_clip(r300->blitter, &r300->clip); util_blitter_save_vertex_elements(r300->blitter, r300->velems); } @@ -99,6 +101,8 @@ static void r300_hw_copy(struct pipe_context* pipe, unsigned width, unsigned height) { struct r300_context* r300 = r300_context(pipe); + struct r300_textures_state* state = + (struct r300_textures_state*)r300->textures_state.state; /* Yeah we have to save all those states to ensure this blitter operation * is really transparent. The states will be restored by the blitter once @@ -107,11 +111,11 @@ static void r300_hw_copy(struct pipe_context* pipe, util_blitter_save_framebuffer(r300->blitter, r300->fb_state.state); util_blitter_save_fragment_sampler_states( - r300->blitter, r300->sampler_count, (void**)r300->sampler_states); + r300->blitter, state->sampler_count, (void**)state->sampler_states); util_blitter_save_fragment_sampler_textures( - r300->blitter, r300->texture_count, - (struct pipe_texture**)r300->textures); + r300->blitter, state->texture_count, + (struct pipe_texture**)state->textures); /* Do a copy */ util_blitter_copy(r300->blitter, @@ -140,10 +144,10 @@ void r300_surface_copy(struct pipe_context* pipe, new_format = PIPE_FORMAT_I8_UNORM; break; case 2: - new_format = PIPE_FORMAT_A4R4G4B4_UNORM; + new_format = PIPE_FORMAT_B4G4R4A4_UNORM; break; case 4: - new_format = PIPE_FORMAT_A8R8G8B8_UNORM; + new_format = PIPE_FORMAT_B8G8R8A8_UNORM; break; default: debug_printf("r300: surface_copy: Unhandled format: %s. Falling back to software.\n" diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c index f631b4ed27f..e0a55323273 100644 --- a/src/gallium/drivers/r300/r300_context.c +++ b/src/gallium/drivers/r300/r300_context.c @@ -59,7 +59,9 @@ static void r300_destroy_context(struct pipe_context* context) FREE(r300->fb_state.state); FREE(r300->rs_block_state.state); FREE(r300->scissor_state.state); - FREE(r300->vertex_format_state.state); + FREE(r300->textures_state.state); + FREE(r300->vertex_stream_state.state); + FREE(r300->vap_output_state.state); FREE(r300->viewport_state.state); FREE(r300->ztop_state.state); FREE(r300); @@ -70,11 +72,8 @@ r300_is_texture_referenced(struct pipe_context *pipe, struct pipe_texture *texture, unsigned face, unsigned level) { - struct pipe_buffer* buf = 0; - - r300_get_texture_buffer(pipe->screen, texture, &buf, NULL); - - return pipe->is_buffer_referenced(pipe, buf); + return pipe->is_buffer_referenced(pipe, + ((struct r300_texture *)texture)->buffer); } static unsigned int @@ -84,7 +83,14 @@ r300_is_buffer_referenced(struct pipe_context *pipe, /* This only checks to see whether actual hardware buffers are * referenced. Since we use managed BOs and transfers, it's actually not * possible for pipe_buffers to ever reference the actual hardware, so - * buffers are never referenced. */ + * buffers are never referenced. + */ + + /* XXX: that doesn't make sense given that + * r300_is_texture_referenced is implemented on top of this + * function and hardware can certainly refer to textures + * directly... + */ return 0; } @@ -96,39 +102,55 @@ static void r300_flush_cb(void *data) } #define R300_INIT_ATOM(atomname, atomsize) \ - r300->atomname##_state.name = #atomname; \ - r300->atomname##_state.state = NULL; \ - r300->atomname##_state.size = atomsize; \ - r300->atomname##_state.emit = r300_emit_##atomname##_state; \ - r300->atomname##_state.dirty = FALSE; \ - insert_at_tail(&r300->atom_list, &r300->atomname##_state); + r300->atomname.name = #atomname; \ + r300->atomname.state = NULL; \ + r300->atomname.size = atomsize; \ + r300->atomname.emit = r300_emit_##atomname; \ + r300->atomname.dirty = FALSE; \ + insert_at_tail(&r300->atom_list, &r300->atomname); static void r300_setup_atoms(struct r300_context* r300) { + boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500; + boolean has_tcl = r300_screen(r300->context.screen)->caps->has_tcl; + /* Create the actual atom list. * * Each atom is examined and emitted in the order it appears here, which * can affect performance and conformance if not handled with care. * - * Some atoms never change size, others change every emit. This is just - * an upper bound on each atom, to keep the emission machinery from - * underallocating space. */ + * Some atoms never change size, others change every emit - those have + * the size of 0 here. */ make_empty_list(&r300->atom_list); - R300_INIT_ATOM(invariant, 71); - R300_INIT_ATOM(ztop, 2); - R300_INIT_ATOM(blend, 8); - R300_INIT_ATOM(blend_color, 3); - R300_INIT_ATOM(clip, 29); - R300_INIT_ATOM(dsa, 8); - R300_INIT_ATOM(fb, 56); - R300_INIT_ATOM(rs, 25); - R300_INIT_ATOM(scissor, 3); - R300_INIT_ATOM(viewport, 9); - R300_INIT_ATOM(rs_block, 21); - R300_INIT_ATOM(vertex_format, 26); + R300_INIT_ATOM(invariant_state, 71); + R300_INIT_ATOM(ztop_state, 2); + R300_INIT_ATOM(blend_state, 8); + R300_INIT_ATOM(blend_color_state, is_r500 ? 3 : 2); + R300_INIT_ATOM(clip_state, has_tcl ? 5 + (6 * 4) : 2); + R300_INIT_ATOM(dsa_state, is_r500 ? 8 : 6); + R300_INIT_ATOM(fb_state, 0); + R300_INIT_ATOM(rs_state, 0); + R300_INIT_ATOM(scissor_state, 3); + R300_INIT_ATOM(viewport_state, 9); + R300_INIT_ATOM(rs_block_state, 0); + R300_INIT_ATOM(vertex_stream_state, 0); + R300_INIT_ATOM(vap_output_state, 6); + R300_INIT_ATOM(pvs_flush, 2); + R300_INIT_ATOM(vs_state, 0); + R300_INIT_ATOM(texture_cache_inval, 2); + R300_INIT_ATOM(textures_state, 0); /* Some non-CSO atoms need explicit space to store the state locally. */ + r300->blend_color_state.state = CALLOC_STRUCT(r300_blend_color_state); + r300->clip_state.state = CALLOC_STRUCT(pipe_clip_state); r300->fb_state.state = CALLOC_STRUCT(pipe_framebuffer_state); + r300->rs_block_state.state = CALLOC_STRUCT(r300_rs_block); + r300->scissor_state.state = CALLOC_STRUCT(pipe_scissor_state); + r300->textures_state.state = CALLOC_STRUCT(r300_textures_state); + r300->vertex_stream_state.state = CALLOC_STRUCT(r300_vertex_stream_state); + r300->vap_output_state.state = CALLOC_STRUCT(r300_vap_output_state); + r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state); + r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state); } struct pipe_context* r300_create_context(struct pipe_screen* screen, @@ -141,6 +163,8 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, if (!r300) return NULL; + r300screen->ctx = (struct pipe_context*)r300; + r300->winsys = radeon_winsys; r300->context.winsys = (struct pipe_winsys*)radeon_winsys; @@ -178,14 +202,6 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, r300_setup_atoms(r300); - r300->blend_color_state.state = CALLOC_STRUCT(r300_blend_color_state); - r300->clip_state.state = CALLOC_STRUCT(pipe_clip_state); - r300->rs_block_state.state = CALLOC_STRUCT(r300_rs_block); - r300->scissor_state.state = CALLOC_STRUCT(pipe_scissor_state); - r300->vertex_format_state.state = CALLOC_STRUCT(r300_vertex_info); - r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state); - r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state); - /* Open up the OQ BO. */ r300->oqbo = screen->buffer_create(screen, 4096, PIPE_BUFFER_USAGE_VERTEX, 4096); @@ -202,7 +218,6 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen, r300->invariant_state.dirty = TRUE; r300->winsys->set_flush_cb(r300->winsys, r300_flush_cb, r300); - r300->dirty_state = R300_NEW_KITCHEN_SINK; r300->dirty_hw++; r300->blitter = util_blitter_create(&r300->context); diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index f372743c5b8..80e69924f08 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -45,7 +45,7 @@ struct r300_atom { /* Opaque state. */ void* state; /* Emit the state to the context. */ - void (*emit)(struct r300_context*, void*); + void (*emit)(struct r300_context*, unsigned, void*); /* Upper bound on number of dwords to emit. */ unsigned size; /* Whether this atom should be emitted. */ @@ -86,7 +86,6 @@ struct r300_rs_state { uint32_t vap_control_status; /* R300_VAP_CNTL_STATUS: 0x2140 */ uint32_t antialiasing_config; /* R300_GB_AA_CONFIG: 0x4020 */ uint32_t point_size; /* R300_GA_POINT_SIZE: 0x421c */ - uint32_t point_minmax; /* R300_GA_POINT_MINMAX: 0x4230 */ uint32_t line_control; /* R300_GA_LINE_CNTL: 0x4234 */ float depth_scale; /* R300_SU_POLY_OFFSET_FRONT_SCALE: 0x42a4 */ /* R300_SU_POLY_OFFSET_BACK_SCALE: 0x42ac */ @@ -119,12 +118,58 @@ struct r300_sampler_state { unsigned min_lod, max_lod; }; -struct r300_texture_state { +struct r300_texture_format_state { uint32_t format0; /* R300_TX_FORMAT0: 0x4480 */ uint32_t format1; /* R300_TX_FORMAT1: 0x44c0 */ uint32_t format2; /* R300_TX_FORMAT2: 0x4500 */ }; +#define R300_MAX_TEXTURE_LEVELS 13 + +struct r300_texture_fb_state { + /* Colorbuffer. */ + uint32_t colorpitch[R300_MAX_TEXTURE_LEVELS]; /* R300_RB3D_COLORPITCH[0-3]*/ + uint32_t us_out_fmt; /* R300_US_OUT_FMT[0-3] */ + + /* Zbuffer. */ + uint32_t depthpitch[R300_MAX_TEXTURE_LEVELS]; /* R300_RB3D_DEPTHPITCH */ + uint32_t zb_format; /* R300_ZB_FORMAT */ +}; + +struct r300_textures_state { + /* Textures. */ + struct r300_texture *textures[8]; + int texture_count; + /* Sampler states. */ + struct r300_sampler_state *sampler_states[8]; + int sampler_count; + + /* These is the merge of the texture and sampler states. */ + unsigned count; + uint32_t tx_enable; /* R300_TX_ENABLE: 0x4101 */ + struct r300_texture_sampler_state { + uint32_t format[3]; /* R300_TX_FORMAT[0-2] */ + uint32_t filter[2]; /* R300_TX_FILTER[0-1] */ + uint32_t border_color; /* R300_TX_BORDER_COLOR: 0x45c0 */ + uint32_t tile_config; /* R300_TX_OFFSET (subset thereof) */ + } regs[8]; +}; + +struct r300_vertex_stream_state { + /* R300_VAP_PROG_STREAK_CNTL_[0-7] */ + uint32_t vap_prog_stream_cntl[8]; + /* R300_VAP_PROG_STREAK_CNTL_EXT_[0-7] */ + uint32_t vap_prog_stream_cntl_ext[8]; + + unsigned count; +}; + +struct r300_vap_output_state { + uint32_t vap_vtx_state_cntl; /* R300_VAP_VTX_STATE_CNTL: 0x2180 */ + uint32_t vap_vsm_vtx_assm; /* R300_VAP_VSM_VTX_ASSM: 0x2184 */ + uint32_t vap_out_vtx_fmt[2]; /* R300_VAP_OUTPUT_VTX_FMT_[0-1]: 0x2090 */ +}; + struct r300_viewport_state { float xscale; /* R300_VAP_VPORT_XSCALE: 0x2098 */ float xoffset; /* R300_VAP_VPORT_XOFFSET: 0x209c */ @@ -141,11 +186,6 @@ struct r300_ztop_state { #define R300_NEW_FRAGMENT_SHADER 0x00000020 #define R300_NEW_FRAGMENT_SHADER_CONSTANTS 0x00000040 -#define R300_NEW_SAMPLER 0x00000200 -#define R300_ANY_NEW_SAMPLERS 0x0001fe00 -#define R300_NEW_TEXTURE 0x00040000 -#define R300_ANY_NEW_TEXTURES 0x03fc0000 -#define R300_NEW_VERTEX_SHADER 0x08000000 #define R300_NEW_VERTEX_SHADER_CONSTANTS 0x10000000 #define R300_NEW_QUERY 0x40000000 #define R300_NEW_KITCHEN_SINK 0x7fffffff @@ -198,16 +238,16 @@ struct r300_texture { struct pipe_texture tex; /* Offsets into the buffer. */ - unsigned offset[PIPE_MAX_TEXTURE_LEVELS]; + unsigned offset[R300_MAX_TEXTURE_LEVELS]; /* A pitch for each mip-level */ - unsigned pitch[PIPE_MAX_TEXTURE_LEVELS]; + unsigned pitch[R300_MAX_TEXTURE_LEVELS]; /* Size of one zslice or face based on the texture target */ - unsigned layer_size[PIPE_MAX_TEXTURE_LEVELS]; + unsigned layer_size[R300_MAX_TEXTURE_LEVELS]; /* Whether the mipmap level is macrotiled. */ - enum r300_buffer_tiling mip_macrotile[PIPE_MAX_TEXTURE_LEVELS]; + enum r300_buffer_tiling mip_macrotile[R300_MAX_TEXTURE_LEVELS]; /** * If non-zero, override the natural texture layout with @@ -231,7 +271,8 @@ struct r300_texture { struct pipe_buffer* buffer; /* Registers carrying texture format data. */ - struct r300_texture_state state; + struct r300_texture_format_state state; + struct r300_texture_fb_state fb_state; /* Buffer tiling */ enum r300_buffer_tiling microtile, macrotile; @@ -276,9 +317,6 @@ struct r300_context { struct r300_query *query_current; struct r300_query query_list; - /* Vertex formatting information. */ - struct r300_atom vertex_format_state; - /* Various CSO state objects. */ /* Beginning of atom list. */ struct r300_atom atom_list; @@ -300,20 +338,24 @@ struct r300_context { struct r300_atom rs_state; /* RS block state. */ struct r300_atom rs_block_state; - /* Sampler states. */ - struct r300_sampler_state* sampler_states[8]; - int sampler_count; /* Scissor state. */ struct r300_atom scissor_state; - /* Texture states. */ - struct r300_texture* textures[8]; - int texture_count; + /* Textures state. */ + struct r300_atom textures_state; + /* Vertex stream formatting state. */ + struct r300_atom vertex_stream_state; + /* VAP (vertex shader) output mapping state. */ + struct r300_atom vap_output_state; /* Vertex shader. */ - struct r300_vertex_shader* vs; + struct r300_atom vs_state; /* Viewport state. */ struct r300_atom viewport_state; /* ZTOP state. */ struct r300_atom ztop_state; + /* PVS flush. */ + struct r300_atom pvs_flush; + /* Texture cache invalidate. */ + struct r300_atom texture_cache_inval; /* Invariant state. This must be emitted to get the engine started. */ struct r300_atom invariant_state; @@ -321,21 +363,29 @@ struct r300_context { /* Vertex buffers for Gallium. */ struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; int vertex_buffer_count; + int vertex_buffer_max_index; /* Vertex elements for Gallium. */ struct r300_velems_state *velems; + /* Vertex info for Draw. */ + struct vertex_info vertex_info; + struct pipe_stencil_ref stencil_ref; + struct pipe_clip_state clip; + + struct pipe_viewport_state viewport; + /* Bitmask of dirty state objects. */ uint32_t dirty_state; /* Flag indicating whether or not the HW is dirty. */ uint32_t dirty_hw; - /* Whether the TCL engine should be in bypass mode. */ - boolean tcl_bypass; /* Whether polygon offset is enabled. */ boolean polygon_offset_enabled; /* Z buffer bit depth. */ uint32_t zbuffer_bpp; + /* Whether scissor is enabled. */ + boolean scissor_enabled; }; /* Convenience cast wrapper. */ diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index fa3df9a23b6..65377b3865a 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -32,17 +32,17 @@ #include "r300_emit.h" #include "r300_fs.h" #include "r300_screen.h" -#include "r300_state_inlines.h" #include "r300_vs.h" -void r300_emit_blend_state(struct r300_context* r300, void* state) +void r300_emit_blend_state(struct r300_context* r300, + unsigned size, void* state) { struct r300_blend_state* blend = (struct r300_blend_state*)state; struct pipe_framebuffer_state* fb = (struct pipe_framebuffer_state*)r300->fb_state.state; CS_LOCALS(r300); - BEGIN_CS(8); + BEGIN_CS(size); OUT_CS_REG(R300_RB3D_ROPCNTL, blend->rop); OUT_CS_REG_SEQ(R300_RB3D_CBLEND, 3); if (fb->nr_cbufs) { @@ -59,26 +59,28 @@ void r300_emit_blend_state(struct r300_context* r300, void* state) END_CS; } -void r300_emit_blend_color_state(struct r300_context* r300, void* state) +void r300_emit_blend_color_state(struct r300_context* r300, + unsigned size, void* state) { struct r300_blend_color_state* bc = (struct r300_blend_color_state*)state; struct r300_screen* r300screen = r300_screen(r300->context.screen); CS_LOCALS(r300); if (r300screen->caps->is_r500) { - BEGIN_CS(3); + BEGIN_CS(size); OUT_CS_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2); OUT_CS(bc->blend_color_red_alpha); OUT_CS(bc->blend_color_green_blue); END_CS; } else { - BEGIN_CS(2); + BEGIN_CS(size); OUT_CS_REG(R300_RB3D_BLEND_COLOR, bc->blend_color); END_CS; } } -void r300_emit_clip_state(struct r300_context* r300, void* state) +void r300_emit_clip_state(struct r300_context* r300, + unsigned size, void* state) { struct pipe_clip_state* clip = (struct pipe_clip_state*)state; int i; @@ -86,7 +88,7 @@ void r300_emit_clip_state(struct r300_context* r300, void* state) CS_LOCALS(r300); if (r300screen->caps->has_tcl) { - BEGIN_CS(5 + (6 * 4)); + BEGIN_CS(size); OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, (r300screen->caps->is_r500 ? R500_PVS_UCP_START : R300_PVS_UCP_START)); @@ -101,14 +103,14 @@ void r300_emit_clip_state(struct r300_context* r300, void* state) R300_PS_UCP_MODE_CLIP_AS_TRIFAN); END_CS; } else { - BEGIN_CS(2); + BEGIN_CS(size); OUT_CS_REG(R300_VAP_CLIP_CNTL, R300_CLIP_DISABLE); END_CS; } } -void r300_emit_dsa_state(struct r300_context* r300, void* state) +void r300_emit_dsa_state(struct r300_context* r300, unsigned size, void* state) { struct r300_dsa_state* dsa = (struct r300_dsa_state*)state; struct r300_screen* r300screen = r300_screen(r300->context.screen); @@ -117,7 +119,7 @@ void r300_emit_dsa_state(struct r300_context* r300, void* state) struct pipe_stencil_ref stencil_ref = r300->stencil_ref; CS_LOCALS(r300); - BEGIN_CS(r300screen->caps->is_r500 ? 8 : 6); + BEGIN_CS(size); OUT_CS_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function); OUT_CS_REG_SEQ(R300_ZB_CNTL, 3); @@ -144,6 +146,8 @@ static const float * get_shader_constant( { struct r300_viewport_state* viewport = (struct r300_viewport_state*)r300->viewport_state.state; + struct r300_textures_state* texstate = + (struct r300_textures_state*)r300->textures_state.state; static float vec[4] = { 0.0, 0.0, 0.0, 1.0 }; struct pipe_texture *tex; @@ -159,7 +163,7 @@ static const float * get_shader_constant( /* Factor for converting rectangle coords to * normalized coords. Should only show up on non-r500. */ case RC_STATE_R300_TEXRECT_FACTOR: - tex = &r300->textures[constant->u.State[1]]->tex; + tex = &texstate->textures[constant->u.State[1]]->tex; vec[0] = 1.0 / tex->width0; vec[1] = 1.0 / tex->height0; break; @@ -171,23 +175,15 @@ static const float * get_shader_constant( break; case RC_STATE_R300_VIEWPORT_SCALE: - if (r300->tcl_bypass) { - vec[0] = 1; - vec[1] = 1; - vec[2] = 1; - } else { - vec[0] = viewport->xscale; - vec[1] = viewport->yscale; - vec[2] = viewport->zscale; - } + vec[0] = viewport->xscale; + vec[1] = viewport->yscale; + vec[2] = viewport->zscale; break; case RC_STATE_R300_VIEWPORT_OFFSET: - if (!r300->tcl_bypass) { - vec[0] = viewport->xoffset; - vec[1] = viewport->yoffset; - vec[2] = viewport->zoffset; - } + vec[0] = viewport->xoffset; + vec[1] = viewport->yoffset; + vec[2] = viewport->zoffset; break; default: @@ -379,7 +375,7 @@ void r500_emit_fs_constant_buffer(struct r300_context* r300, END_CS; } -void r300_emit_fb_state(struct r300_context* r300, void* state) +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_screen* r300screen = r300_screen(r300->context.screen); @@ -388,7 +384,7 @@ void r300_emit_fb_state(struct r300_context* r300, void* state) int i; CS_LOCALS(r300); - BEGIN_CS((10 * fb->nr_cbufs) + (fb->zsbuf ? 10 : 0) + 6); + BEGIN_CS(size); /* Flush and free renderbuffer caches. */ OUT_CS_REG(R300_RB3D_DSTCACHE_CTLSTAT, @@ -422,14 +418,13 @@ void r300_emit_fb_state(struct r300_context* r300, void* state) OUT_CS_RELOC(tex->buffer, surf->offset, 0, RADEON_GEM_DOMAIN_VRAM, 0); OUT_CS_REG_SEQ(R300_RB3D_COLORPITCH0 + (4 * i), 1); - OUT_CS_RELOC(tex->buffer, tex->pitch[surf->level] | - r300_translate_colorformat(tex->tex.format) | - R300_COLOR_TILE(tex->mip_macrotile[surf->level]) | - R300_COLOR_MICROTILE(tex->microtile), + OUT_CS_RELOC(tex->buffer, tex->fb_state.colorpitch[surf->level], 0, RADEON_GEM_DOMAIN_VRAM, 0); - OUT_CS_REG(R300_US_OUT_FMT_0 + (4 * i), - r300_translate_out_fmt(surf->format)); + OUT_CS_REG(R300_US_OUT_FMT_0 + (4 * i), tex->fb_state.us_out_fmt); + } + for (; i < 4; i++) { + OUT_CS_REG(R300_US_OUT_FMT_0 + (4 * i), R300_US_OUT_FMT_UNUSED); } /* Set up a zbuffer. */ @@ -441,15 +436,15 @@ void r300_emit_fb_state(struct r300_context* r300, void* state) OUT_CS_REG_SEQ(R300_ZB_DEPTHOFFSET, 1); OUT_CS_RELOC(tex->buffer, surf->offset, 0, RADEON_GEM_DOMAIN_VRAM, 0); - OUT_CS_REG(R300_ZB_FORMAT, r300_translate_zsformat(tex->tex.format)); + OUT_CS_REG(R300_ZB_FORMAT, tex->fb_state.zb_format); OUT_CS_REG_SEQ(R300_ZB_DEPTHPITCH, 1); - OUT_CS_RELOC(tex->buffer, tex->pitch[surf->level] | - R300_DEPTHMACROTILE(tex->mip_macrotile[surf->level]) | - R300_DEPTHMICROTILE(tex->microtile), + OUT_CS_RELOC(tex->buffer, tex->fb_state.depthpitch[surf->level], 0, RADEON_GEM_DOMAIN_VRAM, 0); } + OUT_CS_REG(R300_GA_POINT_MINMAX, + (MAX2(fb->width, fb->height) * 6) << R300_GA_POINT_MINMAX_MAX_SHIFT); END_CS; } @@ -579,21 +574,19 @@ void r300_emit_query_end(struct r300_context* r300) r300_emit_query_finish(r300, query); } -void r300_emit_rs_state(struct r300_context* r300, void* state) +void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state) { struct r300_rs_state* rs = (struct r300_rs_state*)state; float scale, offset; CS_LOCALS(r300); - BEGIN_CS(18 + (rs->polygon_offset_enable ? 5 : 0)); + BEGIN_CS(size); OUT_CS_REG(R300_VAP_CNTL_STATUS, rs->vap_control_status); OUT_CS_REG(R300_GB_AA_CONFIG, rs->antialiasing_config); OUT_CS_REG(R300_GA_POINT_SIZE, rs->point_size); - OUT_CS_REG_SEQ(R300_GA_POINT_MINMAX, 2); - OUT_CS(rs->point_minmax); - OUT_CS(rs->line_control); + OUT_CS_REG(R300_GA_LINE_CNTL, rs->line_control); if (rs->polygon_offset_enable) { scale = rs->depth_scale * 12; @@ -624,7 +617,8 @@ void r300_emit_rs_state(struct r300_context* r300, void* state) END_CS; } -void r300_emit_rs_block_state(struct r300_context* r300, void* state) +void r300_emit_rs_block_state(struct r300_context* r300, + unsigned size, void* state) { struct r300_rs_block* rs = (struct r300_rs_block*)state; unsigned i; @@ -635,7 +629,7 @@ void r300_emit_rs_block_state(struct r300_context* r300, void* state) DBG(r300, DBG_DRAW, "r300: RS emit:\n"); - BEGIN_CS(5 + count*2); + BEGIN_CS(size); if (r300screen->caps->is_r500) { OUT_CS_REG_SEQ(R500_RS_IP_0, count); } else { @@ -666,7 +660,8 @@ void r300_emit_rs_block_state(struct r300_context* r300, void* state) END_CS; } -void r300_emit_scissor_state(struct r300_context* r300, void* state) +void r300_emit_scissor_state(struct r300_context* r300, + unsigned size, void* state) { unsigned minx, miny, maxx, maxy; uint32_t top_left, bottom_right; @@ -680,7 +675,7 @@ void r300_emit_scissor_state(struct r300_context* r300, void* state) maxx = fb->width; maxy = fb->height; - if (((struct r300_rs_state*)r300->rs_state.state)->rs.scissor) { + if (r300->scissor_enabled) { minx = MAX2(minx, scissor->minx); miny = MAX2(miny, scissor->miny); maxx = MIN2(maxx, scissor->maxx); @@ -720,56 +715,42 @@ void r300_emit_scissor_state(struct r300_context* r300, void* state) (((maxy - 1) + 1440) << R300_SCISSORS_Y_SHIFT); } - BEGIN_CS(3); + BEGIN_CS(size); OUT_CS_REG_SEQ(R300_SC_SCISSORS_TL, 2); OUT_CS(top_left); OUT_CS(bottom_right); END_CS; } -void r300_emit_texture(struct r300_context* r300, - struct r300_sampler_state* sampler, - struct r300_texture* tex, - unsigned offset) +void r300_emit_textures_state(struct r300_context *r300, + unsigned size, void *state) { - uint32_t filter0 = sampler->filter0; - uint32_t format0 = tex->state.format0; - unsigned min_level, max_level; + struct r300_textures_state *allstate = (struct r300_textures_state*)state; + struct r300_texture_sampler_state *texstate; + unsigned i; CS_LOCALS(r300); - /* to emulate 1D textures through 2D ones correctly */ - if (tex->tex.target == PIPE_TEXTURE_1D) { - filter0 &= ~R300_TX_WRAP_T_MASK; - filter0 |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE); - } + BEGIN_CS(size); + OUT_CS_REG(R300_TX_ENABLE, allstate->tx_enable); - if (tex->is_npot) { - /* NPOT textures don't support mip filter, unfortunately. - * This prevents incorrect rendering. */ - filter0 &= ~R300_TX_MIN_FILTER_MIP_MASK; - } else { - /* determine min/max levels */ - /* the MAX_MIP level is the largest (finest) one */ - max_level = MIN2(sampler->max_lod, tex->tex.last_level); - min_level = MIN2(sampler->min_lod, max_level); - format0 |= R300_TX_NUM_LEVELS(max_level); - filter0 |= R300_TX_MAX_MIP_LEVEL(min_level); - } + for (i = 0; i < allstate->count; i++) { + if ((1 << i) & allstate->tx_enable) { + texstate = &allstate->regs[i]; + + OUT_CS_REG(R300_TX_FILTER0_0 + (i * 4), texstate->filter[0]); + OUT_CS_REG(R300_TX_FILTER1_0 + (i * 4), texstate->filter[1]); + OUT_CS_REG(R300_TX_BORDER_COLOR_0 + (i * 4), + texstate->border_color); - BEGIN_CS(16); - OUT_CS_REG(R300_TX_FILTER0_0 + (offset * 4), filter0 | - (offset << 28)); - OUT_CS_REG(R300_TX_FILTER1_0 + (offset * 4), sampler->filter1); - OUT_CS_REG(R300_TX_BORDER_COLOR_0 + (offset * 4), sampler->border_color); - - OUT_CS_REG(R300_TX_FORMAT0_0 + (offset * 4), format0); - OUT_CS_REG(R300_TX_FORMAT1_0 + (offset * 4), tex->state.format1); - OUT_CS_REG(R300_TX_FORMAT2_0 + (offset * 4), tex->state.format2); - OUT_CS_REG_SEQ(R300_TX_OFFSET_0 + (offset * 4), 1); - OUT_CS_RELOC(tex->buffer, - R300_TXO_MACRO_TILE(tex->macrotile) | - R300_TXO_MICRO_TILE(tex->microtile), - RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0, 0); + OUT_CS_REG(R300_TX_FORMAT0_0 + (i * 4), texstate->format[0]); + OUT_CS_REG(R300_TX_FORMAT1_0 + (i * 4), texstate->format[1]); + OUT_CS_REG(R300_TX_FORMAT2_0 + (i * 4), texstate->format[2]); + + OUT_CS_REG_SEQ(R300_TX_OFFSET_0 + (i * 4), 1); + OUT_CS_RELOC(allstate->textures[i]->buffer, texstate->tile_config, + RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0, 0); + } + } END_CS; } @@ -813,68 +794,110 @@ void r300_emit_aos(struct r300_context* r300, unsigned offset) END_CS; } -void r300_emit_vertex_format_state(struct r300_context* r300, void* state) +void r300_emit_vertex_buffer(struct r300_context* r300) { - struct r300_vertex_info* vertex_info = (struct r300_vertex_info*)state; - unsigned i; CS_LOCALS(r300); - DBG(r300, DBG_DRAW, "r300: VAP/PSC emit:\n"); + DBG(r300, DBG_DRAW, "r300: Preparing vertex buffer %p for render, " + "vertex size %d\n", r300->vbo, + r300->vertex_info.size); + /* Set the pointer to our vertex buffer. The emitted values are this: + * PACKET3 [3D_LOAD_VBPNTR] + * COUNT [1] + * FORMAT [size | stride << 8] + * OFFSET [offset into BO] + * VBPNTR [relocated BO] + */ + BEGIN_CS(7); + OUT_CS_PKT3(R300_PACKET3_3D_LOAD_VBPNTR, 3); + OUT_CS(1); + OUT_CS(r300->vertex_info.size | + (r300->vertex_info.size << 8)); + OUT_CS(r300->vbo_offset); + OUT_CS_RELOC(r300->vbo, 0, RADEON_GEM_DOMAIN_GTT, 0, 0); + END_CS; +} - BEGIN_CS(26); - OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_info->vinfo.size); +void r300_emit_vertex_stream_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_vertex_stream_state *streams = + (struct r300_vertex_stream_state*)state; + unsigned i; + CS_LOCALS(r300); - OUT_CS_REG_SEQ(R300_VAP_VTX_STATE_CNTL, 2); - OUT_CS(vertex_info->vinfo.hwfmt[0]); - OUT_CS(vertex_info->vinfo.hwfmt[1]); - OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2); - OUT_CS(vertex_info->vinfo.hwfmt[2]); - OUT_CS(vertex_info->vinfo.hwfmt[3]); - for (i = 0; i < 4; i++) { - DBG(r300, DBG_DRAW, " : hwfmt%d: 0x%08x\n", i, - vertex_info->vinfo.hwfmt[i]); - } + DBG(r300, DBG_DRAW, "r300: PSC emit:\n"); - OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_0, 8); - for (i = 0; i < 8; i++) { - OUT_CS(vertex_info->vap_prog_stream_cntl[i]); + BEGIN_CS(size); + OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_0, streams->count); + for (i = 0; i < streams->count; i++) { + OUT_CS(streams->vap_prog_stream_cntl[i]); DBG(r300, DBG_DRAW, " : prog_stream_cntl%d: 0x%08x\n", i, - vertex_info->vap_prog_stream_cntl[i]); + streams->vap_prog_stream_cntl[i]); } - OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_EXT_0, 8); - for (i = 0; i < 8; i++) { - OUT_CS(vertex_info->vap_prog_stream_cntl_ext[i]); + OUT_CS_REG_SEQ(R300_VAP_PROG_STREAM_CNTL_EXT_0, streams->count); + for (i = 0; i < streams->count; i++) { + OUT_CS(streams->vap_prog_stream_cntl_ext[i]); DBG(r300, DBG_DRAW, " : prog_stream_cntl_ext%d: 0x%08x\n", i, - vertex_info->vap_prog_stream_cntl_ext[i]); + streams->vap_prog_stream_cntl_ext[i]); } END_CS; } +void r300_emit_vap_output_state(struct r300_context* r300, + unsigned size, void* state) +{ + struct r300_vap_output_state *vap_out_state = + (struct r300_vap_output_state*)state; + CS_LOCALS(r300); + + DBG(r300, DBG_DRAW, "r300: VAP emit:\n"); -void r300_emit_vertex_program_code(struct r300_context* r300, - struct r300_vertex_program_code* code) + BEGIN_CS(size); + OUT_CS_REG_SEQ(R300_VAP_VTX_STATE_CNTL, 2); + OUT_CS(vap_out_state->vap_vtx_state_cntl); + OUT_CS(vap_out_state->vap_vsm_vtx_assm); + OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2); + OUT_CS(vap_out_state->vap_out_vtx_fmt[0]); + OUT_CS(vap_out_state->vap_out_vtx_fmt[1]); + END_CS; +} + +void r300_emit_pvs_flush(struct r300_context* r300, unsigned size, void* state) { - int i; + CS_LOCALS(r300); + + BEGIN_CS(size); + OUT_CS_REG(R300_VAP_PVS_STATE_FLUSH_REG, 0x0); + END_CS; +} + +void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state) +{ + struct r300_vertex_shader* vs = (struct r300_vertex_shader*)state; + struct r300_vertex_program_code* code = &vs->code; struct r300_screen* r300screen = r300_screen(r300->context.screen); unsigned instruction_count = code->length / 4; + unsigned i; + + unsigned vtx_mem_size = r300screen->caps->is_r500 ? 128 : 72; + unsigned input_count = MAX2(util_bitcount(code->InputsRead), 1); + unsigned output_count = MAX2(util_bitcount(code->OutputsWritten), 1); + unsigned temp_count = MAX2(code->num_temporaries, 1); - int vtx_mem_size = r300screen->caps->is_r500 ? 128 : 72; - int input_count = MAX2(util_bitcount(code->InputsRead), 1); - int output_count = MAX2(util_bitcount(code->OutputsWritten), 1); - int temp_count = MAX2(code->num_temporaries, 1); - int pvs_num_slots = MIN3(vtx_mem_size / input_count, - vtx_mem_size / output_count, 10); - int pvs_num_controllers = MIN2(vtx_mem_size / temp_count, 6); + unsigned pvs_num_slots = MIN3(vtx_mem_size / input_count, + vtx_mem_size / output_count, 10); + unsigned pvs_num_controllers = MIN2(vtx_mem_size / temp_count, 6); CS_LOCALS(r300); if (!r300screen->caps->has_tcl) { - debug_printf("r300: Implementation error: emit_vertex_shader called," + debug_printf("r300: Implementation error: emit_vs_state called," " but has_tcl is FALSE!\n"); return; } - BEGIN_CS(9 + code->length); + BEGIN_CS(size); /* R300_VAP_PVS_CODE_CNTL_0 * R300_VAP_PVS_CONST_CNTL * R300_VAP_PVS_CODE_CNTL_1 @@ -888,8 +911,9 @@ void r300_emit_vertex_program_code(struct r300_context* r300, OUT_CS_REG(R300_VAP_PVS_VECTOR_INDX_REG, 0); OUT_CS_ONE_REG(R300_VAP_PVS_UPLOAD_DATA, code->length); - for (i = 0; i < code->length; i++) + for (i = 0; i < code->length; i++) { OUT_CS(code->body.d[i]); + } OUT_CS_REG(R300_VAP_CNTL, R300_PVS_NUM_SLOTS(pvs_num_slots) | R300_PVS_NUM_CNTLRS(pvs_num_controllers) | @@ -899,12 +923,6 @@ void r300_emit_vertex_program_code(struct r300_context* r300, END_CS; } -void r300_emit_vertex_shader(struct r300_context* r300, - struct r300_vertex_shader* vs) -{ - r300_emit_vertex_program_code(r300, &vs->code); -} - void r300_emit_vs_constant_buffer(struct r300_context* r300, struct rc_constant_list* constants) { @@ -913,7 +931,7 @@ void r300_emit_vs_constant_buffer(struct r300_context* r300, CS_LOCALS(r300); if (!r300screen->caps->has_tcl) { - debug_printf("r300: Implementation error: emit_vertex_shader called," + debug_printf("r300: Implementation error: emit_vs_constant_buffer called," " but has_tcl is FALSE!\n"); return; } @@ -938,83 +956,56 @@ void r300_emit_vs_constant_buffer(struct r300_context* r300, END_CS; } -void r300_emit_viewport_state(struct r300_context* r300, void* state) +void r300_emit_viewport_state(struct r300_context* r300, + unsigned size, void* state) { struct r300_viewport_state* viewport = (struct r300_viewport_state*)state; CS_LOCALS(r300); - if (r300->tcl_bypass) { - BEGIN_CS(2); - OUT_CS_REG(R300_VAP_VTE_CNTL, 0); - END_CS; - } else { - BEGIN_CS(9); - OUT_CS_REG_SEQ(R300_SE_VPORT_XSCALE, 6); - OUT_CS_32F(viewport->xscale); - OUT_CS_32F(viewport->xoffset); - OUT_CS_32F(viewport->yscale); - OUT_CS_32F(viewport->yoffset); - OUT_CS_32F(viewport->zscale); - OUT_CS_32F(viewport->zoffset); - OUT_CS_REG(R300_VAP_VTE_CNTL, viewport->vte_control); - END_CS; - } -} - -void r300_emit_texture_count(struct r300_context* r300) -{ - uint32_t tx_enable = 0; - int i; - CS_LOCALS(r300); - - /* Notice that texture_count and sampler_count are just sizes - * of the respective arrays. We still have to check for the individual - * elements. */ - for (i = 0; i < MIN2(r300->sampler_count, r300->texture_count); i++) { - if (r300->textures[i]) { - tx_enable |= 1 << i; - } - } - - BEGIN_CS(2); - OUT_CS_REG(R300_TX_ENABLE, tx_enable); - END_CS; - + BEGIN_CS(size); + OUT_CS_REG_SEQ(R300_SE_VPORT_XSCALE, 6); + OUT_CS_32F(viewport->xscale); + OUT_CS_32F(viewport->xoffset); + OUT_CS_32F(viewport->yscale); + OUT_CS_32F(viewport->yoffset); + OUT_CS_32F(viewport->zscale); + OUT_CS_32F(viewport->zoffset); + OUT_CS_REG(R300_VAP_VTE_CNTL, viewport->vte_control); + END_CS; } -void r300_emit_ztop_state(struct r300_context* r300, void* state) +void r300_emit_ztop_state(struct r300_context* r300, + unsigned size, void* state) { struct r300_ztop_state* ztop = (struct r300_ztop_state*)state; CS_LOCALS(r300); - BEGIN_CS(2); + BEGIN_CS(size); OUT_CS_REG(R300_ZB_ZTOP, ztop->z_buffer_top); END_CS; } -void r300_flush_textures(struct r300_context* r300) +void r300_emit_texture_cache_inval(struct r300_context* r300, unsigned size, void* state) { CS_LOCALS(r300); - BEGIN_CS(2); + BEGIN_CS(size); OUT_CS_REG(R300_TX_INVALTAGS, 0); END_CS; } -static void r300_flush_pvs(struct r300_context* r300) -{ - CS_LOCALS(r300); - - BEGIN_CS(2); - OUT_CS_REG(R300_VAP_PVS_STATE_FLUSH_REG, 0x0); - END_CS; -} - -void r300_emit_buffer_validate(struct r300_context *r300) +void r300_emit_buffer_validate(struct r300_context *r300, + boolean do_validate_vertex_buffers, + struct pipe_buffer *index_buffer) { struct pipe_framebuffer_state* fb = (struct pipe_framebuffer_state*)r300->fb_state.state; + struct r300_textures_state *texstate = + (struct r300_textures_state*)r300->textures_state.state; struct r300_texture* tex; + struct pipe_vertex_buffer *vbuf = r300->vertex_buffer; + struct pipe_vertex_element *velem = r300->vertex_element; + struct pipe_buffer *pbuf; unsigned i; boolean invalid = FALSE; @@ -1043,9 +1034,9 @@ validate: } } /* ...textures... */ - for (i = 0; i < r300->texture_count; i++) { - tex = r300->textures[i]; - if (!tex) + for (i = 0; i < texstate->count; i++) { + tex = texstate->textures[i]; + if (!tex || !texstate->sampler_states[i]) continue; if (!r300->winsys->add_buffer(r300->winsys, tex->buffer, RADEON_GEM_DOMAIN_GTT | RADEON_GEM_DOMAIN_VRAM, 0)) { @@ -1061,16 +1052,35 @@ validate: goto validate; } } - /* ...and vertex buffer. */ + /* ...vertex buffer for SWTCL path... */ if (r300->vbo) { if (!r300->winsys->add_buffer(r300->winsys, r300->vbo, RADEON_GEM_DOMAIN_GTT, 0)) { r300->context.flush(&r300->context, 0, NULL); goto validate; } - } else { - /* debug_printf("No VBO while emitting dirty state!\n"); */ } + /* ...vertex buffers for HWTCL path... */ + if (do_validate_vertex_buffers) { + for (i = 0; i < r300->vertex_element_count; i++) { + pbuf = vbuf[velem[i].vertex_buffer_index].buffer; + + if (!r300->winsys->add_buffer(r300->winsys, pbuf, + RADEON_GEM_DOMAIN_GTT, 0)) { + r300->context.flush(&r300->context, 0, NULL); + goto validate; + } + } + } + /* ...and index buffer for HWTCL path. */ + if (index_buffer) { + if (!r300->winsys->add_buffer(r300->winsys, index_buffer, + RADEON_GEM_DOMAIN_GTT, 0)) { + r300->context.flush(&r300->context, 0, NULL); + goto validate; + } + } + if (!r300->winsys->validate(r300->winsys)) { r300->context.flush(&r300->context, 0, NULL); if (invalid) { @@ -1083,16 +1093,10 @@ validate: } } -/* Emit all dirty state. */ -void r300_emit_dirty_state(struct r300_context* r300) +unsigned r300_get_num_dirty_dwords(struct r300_context *r300) { - struct r300_screen* r300screen = r300_screen(r300->context.screen); struct r300_atom* atom; - unsigned i, dwords = 1024; - int dirty_tex = 0; - - /* Check the required number of dwords against the space remaining in the - * current CS object. If we need more, then flush. */ + unsigned dwords = 0; foreach(atom, &r300->atom_list) { if (atom->dirty || atom->always_dirty) { @@ -1100,12 +1104,17 @@ void r300_emit_dirty_state(struct r300_context* r300) } } - /* Make sure we have at least 2*1024 spare dwords. */ - /* XXX It would be nice to know the number of dwords we really need to - * XXX emit. */ - while (!r300->winsys->check_cs(r300->winsys, dwords)) { - r300->context.flush(&r300->context, 0, NULL); - } + /* XXX This is the compensation for the non-atomized states. */ + dwords += 1024; + + return dwords; +} + +/* Emit all dirty state. */ +void r300_emit_dirty_state(struct r300_context* r300) +{ + struct r300_screen* r300screen = r300_screen(r300->context.screen); + struct r300_atom* atom; if (r300->dirty_state & R300_NEW_QUERY) { r300_emit_query_start(r300); @@ -1114,7 +1123,7 @@ void r300_emit_dirty_state(struct r300_context* r300) foreach(atom, &r300->atom_list) { if (atom->dirty || atom->always_dirty) { - atom->emit(r300, atom->state); + atom->emit(r300, atom->size, atom->state); atom->dirty = FALSE; } } @@ -1140,43 +1149,9 @@ void r300_emit_dirty_state(struct r300_context* r300) r300->dirty_state &= ~R300_NEW_FRAGMENT_SHADER_CONSTANTS; } - /* Samplers and textures are tracked separately but emitted together. */ - if (r300->dirty_state & - (R300_ANY_NEW_SAMPLERS | R300_ANY_NEW_TEXTURES)) { - r300_emit_texture_count(r300); - - for (i = 0; i < MIN2(r300->sampler_count, r300->texture_count); i++) { - if (r300->dirty_state & - ((R300_NEW_SAMPLER << i) | (R300_NEW_TEXTURE << i))) { - if (r300->textures[i]) { - r300_emit_texture(r300, - r300->sampler_states[i], - r300->textures[i], - i); - dirty_tex |= r300->dirty_state & (R300_NEW_TEXTURE << i); - } - r300->dirty_state &= - ~((R300_NEW_SAMPLER << i) | (R300_NEW_TEXTURE << i)); - } - } - r300->dirty_state &= ~(R300_ANY_NEW_SAMPLERS | R300_ANY_NEW_TEXTURES); - } - - if (dirty_tex) { - r300_flush_textures(r300); - } - - if (r300->dirty_state & (R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS)) { - r300_flush_pvs(r300); - } - - if (r300->dirty_state & R300_NEW_VERTEX_SHADER) { - r300_emit_vertex_shader(r300, r300->vs); - r300->dirty_state &= ~R300_NEW_VERTEX_SHADER; - } - if (r300->dirty_state & R300_NEW_VERTEX_SHADER_CONSTANTS) { - r300_emit_vs_constant_buffer(r300, &r300->vs->code.constants); + struct r300_vertex_shader* vs = r300->vs_state.state; + r300_emit_vs_constant_buffer(r300, &vs->code.constants); r300->dirty_state &= ~R300_NEW_VERTEX_SHADER_CONSTANTS; } @@ -1184,8 +1159,10 @@ void r300_emit_dirty_state(struct r300_context* r300) assert(r300->dirty_state == 0); */ - /* Finally, emit the VBO. */ - /* r300_emit_vertex_buffer(r300); */ + /* Emit the VBO for SWTCL. */ + if (!r300screen->caps->has_tcl) { + r300_emit_vertex_buffer(r300); + } r300->dirty_hw++; } diff --git a/src/gallium/drivers/r300/r300_emit.h b/src/gallium/drivers/r300/r300_emit.h index 6b96d9b57c0..449e640a884 100644 --- a/src/gallium/drivers/r300/r300_emit.h +++ b/src/gallium/drivers/r300/r300_emit.h @@ -31,13 +31,17 @@ struct r300_vertex_program_code; void r300_emit_aos(struct r300_context* r300, unsigned offset); -void r300_emit_blend_state(struct r300_context* r300, void* state); +void r300_emit_blend_state(struct r300_context* r300, + unsigned size, void* state); -void r300_emit_blend_color_state(struct r300_context* r300, void* state); +void r300_emit_blend_color_state(struct r300_context* r300, + unsigned size, void* state); -void r300_emit_clip_state(struct r300_context* r300, void* state); +void r300_emit_clip_state(struct r300_context* r300, + unsigned size, void* state); -void r300_emit_dsa_state(struct r300_context* r300, void* state); +void r300_emit_dsa_state(struct r300_context* r300, + unsigned size, void* state); void r300_emit_fragment_program_code(struct r300_context* r300, struct rX00_fragment_program_code* generic_code); @@ -51,48 +55,54 @@ void r500_emit_fragment_program_code(struct r300_context* r300, void r500_emit_fs_constant_buffer(struct r300_context* r300, struct rc_constant_list* constants); -void r300_emit_fb_state(struct r300_context* r300, void* state); +void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state); void r300_emit_query_begin(struct r300_context* r300, struct r300_query* query); void r300_emit_query_end(struct r300_context* r300); -void r300_emit_rs_state(struct r300_context* r300, void* state); +void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state); -void r300_emit_rs_block_state(struct r300_context* r300, void* state); +void r300_emit_rs_block_state(struct r300_context* r300, + unsigned size, void* state); -void r300_emit_scissor_state(struct r300_context* r300, void* state); +void r300_emit_scissor_state(struct r300_context* r300, + unsigned size, void* state); -void r300_emit_texture(struct r300_context* r300, - struct r300_sampler_state* sampler, - struct r300_texture* tex, - unsigned offset); +void r300_emit_textures_state(struct r300_context *r300, + unsigned size, void *state); void r300_emit_vertex_buffer(struct r300_context* r300); -void r300_emit_vertex_format_state(struct r300_context* r300, void* state); +void r300_emit_vertex_stream_state(struct r300_context* r300, + unsigned size, void* state); -void r300_emit_vertex_program_code(struct r300_context* r300, - struct r300_vertex_program_code* code); +void r300_emit_vap_output_state(struct r300_context* r300, + unsigned size, void* state); void r300_emit_vs_constant_buffer(struct r300_context* r300, struct rc_constant_list* constants); -void r300_emit_vertex_shader(struct r300_context* r300, - struct r300_vertex_shader* vs); +void r300_emit_vs_state(struct r300_context* r300, unsigned size, void* state); -void r300_emit_viewport_state(struct r300_context* r300, void* state); +void r300_emit_viewport_state(struct r300_context* r300, + unsigned size, void* state); -void r300_emit_texture_count(struct r300_context* r300); +void r300_emit_ztop_state(struct r300_context* r300, + unsigned size, void* state); -void r300_emit_ztop_state(struct r300_context* r300, void* state); +void r300_emit_pvs_flush(struct r300_context* r300, unsigned size, void* state); -void r300_flush_textures(struct r300_context* r300); +void r300_emit_texture_cache_inval(struct r300_context* r300, unsigned size, void* state); + +unsigned r300_get_num_dirty_dwords(struct r300_context *r300); /* Emit all dirty state. */ void r300_emit_dirty_state(struct r300_context* r300); -void r300_emit_buffer_validate(struct r300_context *r300); +void r300_emit_buffer_validate(struct r300_context *r300, + boolean do_validate_vertex_buffers, + struct pipe_buffer *index_buffer); #endif /* R300_EMIT_H */ diff --git a/src/gallium/drivers/r300/r300_flush.c b/src/gallium/drivers/r300/r300_flush.c index e37d3092703..70de152713d 100644 --- a/src/gallium/drivers/r300/r300_flush.c +++ b/src/gallium/drivers/r300/r300_flush.c @@ -61,6 +61,12 @@ static void r300_flush(struct pipe_context* pipe, atom->dirty = TRUE; } } + + /* Unmark HWTCL state for SWTCL. */ + if (!r300_screen(pipe->screen)->caps->has_tcl) { + r300->vs_state.dirty = FALSE; + r300->dirty_state &= ~R300_NEW_VERTEX_SHADER_CONSTANTS; + } } /* reset flushed query */ diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c index ae4c62b2f1d..9e71e61c303 100644 --- a/src/gallium/drivers/r300/r300_fs.c +++ b/src/gallium/drivers/r300/r300_fs.c @@ -133,10 +133,13 @@ static void get_compare_state( struct r300_fragment_program_external_state* state, unsigned shadow_samplers) { + struct r300_textures_state *texstate = + (struct r300_textures_state*)r300->textures_state.state; + memset(state, 0, sizeof(*state)); - for (int i = 0; i < r300->sampler_count; i++) { - struct r300_sampler_state* s = r300->sampler_states[i]; + for (int i = 0; i < texstate->sampler_count; i++) { + struct r300_sampler_state* s = texstate->sampler_states[i]; if (s && s->state.compare_mode == PIPE_TEX_COMPARE_R_TO_TEXTURE) { /* XXX Gallium doesn't provide us with any information regarding @@ -204,6 +207,7 @@ static void r300_translate_fragment_shader( DBG(r300, DBG_FP, "r300: Error compiling fragment program: %s\n", compiler.Base.ErrorMsg); assert(0); + abort(); } /* And, finally... */ diff --git a/src/gallium/drivers/r300/r300_reg.h b/src/gallium/drivers/r300/r300_reg.h index a049da69e2e..a249e8b36be 100644 --- a/src/gallium/drivers/r300/r300_reg.h +++ b/src/gallium/drivers/r300/r300_reg.h @@ -113,11 +113,14 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. /* index size - when not set the indices are assumed to be 16 bit */ # define R300_VAP_VF_CNTL__INDEX_SIZE_32bit (1<<11) +# define R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS (1<<14) /* number of vertices */ # define R300_VAP_VF_CNTL__NUM_VERTICES__SHIFT 16 #define R500_VAP_INDEX_OFFSET 0x208c +#define R500_VAP_ALT_NUM_VERTICES 0x2088 + #define R300_VAP_OUTPUT_VTX_FMT_0 0x2090 # define R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT (1<<0) # define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT (1<<1) diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 1850a6f247a..d0e06ade40f 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -42,6 +42,9 @@ /* r300_render: Vertex and index buffer primitive emission. */ #define R300_MAX_VBO_SIZE (1024 * 1024) +/* XXX The DRM rejects VAP_ALT_NUM_VERTICES.. */ +//#define ENABLE_ALT_NUM_VERTS + uint32_t r300_translate_primitive(unsigned prim) { switch (prim) { @@ -115,6 +118,18 @@ static uint32_t r300_provoking_vertex_fixes(struct r300_context *r300, return color_control; } +/* Check if the requested number of dwords is available in the CS and + * if not, flush. Return TRUE if the flush occured. */ +static boolean r300_reserve_cs_space(struct r300_context *r300, + unsigned dwords) +{ + if (!r300->winsys->check_cs(r300->winsys, dwords)) { + r300->context.flush(&r300->context, 0, NULL); + return TRUE; + } + return FALSE; +} + static boolean immd_is_good_idea(struct r300_context *r300, unsigned count) { @@ -129,7 +144,7 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300, struct pipe_vertex_element* velem; struct pipe_vertex_buffer* vbuf; unsigned vertex_element_count = r300->velems->count; - unsigned i, v, vbi, dw, elem_offset; + unsigned i, v, vbi, dw, elem_offset, dwords; /* Size of the vertex, in dwords. */ unsigned vertex_size = 0; @@ -168,9 +183,13 @@ static void r300_emit_draw_arrays_immediate(struct r300_context *r300, } } + dwords = 10 + count * vertex_size; + + r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + dwords); + r300_emit_buffer_validate(r300, FALSE, NULL); r300_emit_dirty_state(r300); - BEGIN_CS(10 + count * vertex_size); + BEGIN_CS(dwords); OUT_CS_REG(R300_GA_COLOR_CONTROL, r300_provoking_vertex_fixes(r300, mode)); OUT_CS_REG(R300_VAP_VTX_SIZE, vertex_size); @@ -210,16 +229,28 @@ static void r300_emit_draw_arrays(struct r300_context *r300, unsigned mode, unsigned count) { +#if defined(ENABLE_ALT_NUM_VERTS) + boolean alt_num_verts = count > 65535; +#else + boolean alt_num_verts = FALSE; +#endif CS_LOCALS(r300); - BEGIN_CS(8); + if (alt_num_verts) { + assert(count < (1 << 24)); + BEGIN_CS(10); + OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count); + } else { + BEGIN_CS(8); + } OUT_CS_REG(R300_GA_COLOR_CONTROL, r300_provoking_vertex_fixes(r300, mode)); OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, 0); OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count - 1); OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0); OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) | - r300_translate_primitive(mode)); + r300_translate_primitive(mode) | + (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0)); END_CS; } @@ -234,41 +265,54 @@ static void r300_emit_draw_elements(struct r300_context *r300, { uint32_t count_dwords; uint32_t offset_dwords = indexSize * start / sizeof(uint32_t); +#if defined(ENABLE_ALT_NUM_VERTS) + boolean alt_num_verts = count > 65535; +#else + boolean alt_num_verts = FALSE; +#endif CS_LOCALS(r300); - /* XXX most of these are stupid */ - assert(indexSize == 4 || indexSize == 2); assert((start * indexSize) % 4 == 0); - assert(offset_dwords == 0); + assert(count < (1 << 24)); + + DBG(r300, DBG_DRAW, "r300: Indexbuf of %u indices, min %u max %u\n", + count, minIndex, maxIndex); + + maxIndex = MIN2(maxIndex, r300->vertex_buffer_max_index); - BEGIN_CS(14); + if (alt_num_verts) { + BEGIN_CS(16); + OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count); + } else { + BEGIN_CS(14); + } OUT_CS_REG(R300_GA_COLOR_CONTROL, r300_provoking_vertex_fixes(r300, mode)); OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, minIndex); OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, maxIndex); OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, 0); if (indexSize == 4) { - count_dwords = count + start; + count_dwords = count; OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | R300_VAP_VF_CNTL__INDEX_SIZE_32bit | - r300_translate_primitive(mode)); + r300_translate_primitive(mode) | + (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0)); } else { - count_dwords = (count + start + 1) / 2; + count_dwords = (count + 1) / 2; OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | - r300_translate_primitive(mode)); + r300_translate_primitive(mode) | + (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0)); } /* INDX_BUFFER is a truly special packet3. * Unlike most other packet3, where the offset is after the count, * the order is reversed, so the relocation ends up carrying the * size of the indexbuf instead of the offset. - * - * XXX Fix offset */ OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2); OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) | (0 << R300_INDX_BUFFER_SKIP_SHIFT)); - OUT_CS(offset_dwords); + OUT_CS(offset_dwords << 2); OUT_CS_RELOC(indexBuffer, count_dwords, RADEON_GEM_DOMAIN_GTT, 0, 0); @@ -343,48 +387,52 @@ void r300_draw_range_elements(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); struct pipe_buffer* orgIndexBuffer = indexBuffer; +#if defined(ENABLE_ALT_NUM_VERTS) + boolean alt_num_verts = r300_screen(pipe->screen)->caps->is_r500 && + count > 65536; +#else + boolean alt_num_verts = FALSE; +#endif + unsigned short_count; if (!u_trim_pipe_prim(mode, &count)) { return; } - if (count > 65535) { - /* XXX: use aux/indices functions to split this into smaller - * primitives. - */ - return; - } - - r300_update_derived_state(r300); - - r300_emit_buffer_validate(r300); - - if (!r300_setup_vertex_buffers(r300)) { - return; - } - if (indexSize == 1) { r300_shorten_ubyte_elts(r300, &indexBuffer, count); indexSize = 2; } - if (!r300->winsys->add_buffer(r300->winsys, indexBuffer, - RADEON_GEM_DOMAIN_GTT, 0)) { - goto cleanup; - } - - if (!r300->winsys->validate(r300->winsys)) { - goto cleanup; - } + r300_update_derived_state(r300); + /* 128 dwords for emit_aos and emit_draw_elements */ + r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + 128); + r300_emit_buffer_validate(r300, TRUE, indexBuffer); r300_emit_dirty_state(r300); - r300_emit_aos(r300, 0); - r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex, - mode, start, count); + if (alt_num_verts || count <= 65535) { + r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, + maxIndex, mode, start, count); + } else { + do { + short_count = MIN2(count, 65534); + r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, + maxIndex, mode, start, short_count); + + start += short_count; + count -= short_count; + + /* 16 spare dwords are enough for emit_draw_elements. */ + if (count && r300_reserve_cs_space(r300, 16)) { + r300_emit_buffer_validate(r300, TRUE, indexBuffer); + r300_emit_dirty_state(r300); + r300_emit_aos(r300, 0); + } + } while (count); + } -cleanup: if (indexBuffer != orgIndexBuffer) { pipe->screen->buffer_destroy(indexBuffer); } @@ -396,40 +444,60 @@ void r300_draw_elements(struct pipe_context* pipe, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { - pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0, ~0, - mode, start, count); + struct r300_context *r300 = r300_context(pipe); + + pipe->draw_range_elements(pipe, indexBuffer, indexSize, 0, + r300->vertex_buffer_max_index, + mode, start, count); } void r300_draw_arrays(struct pipe_context* pipe, unsigned mode, unsigned start, unsigned count) { struct r300_context* r300 = r300_context(pipe); +#if defined(ENABLE_ALT_NUM_VERTS) + boolean alt_num_verts = r300_screen(pipe->screen)->caps->is_r500 && + count > 65536; +#else + boolean alt_num_verts = FALSE; +#endif + unsigned short_count; if (!u_trim_pipe_prim(mode, &count)) { return; } - if (count > 65535) { - /* XXX: driver needs to handle this -- use the functions in - * aux/indices to split this into several smaller primitives. - */ - return; - } - r300_update_derived_state(r300); - r300_emit_buffer_validate(r300); - if (immd_is_good_idea(r300, count)) { r300_emit_draw_arrays_immediate(r300, mode, start, count); } else { - if (!r300_setup_vertex_buffers(r300)) { - return; - } - + /* Make sure there are at least 128 spare dwords in the command buffer. + * (most of it being consumed by emit_aos) */ + r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + 128); + r300_emit_buffer_validate(r300, TRUE, NULL); r300_emit_dirty_state(r300); - r300_emit_aos(r300, start); - r300_emit_draw_arrays(r300, mode, count); + + if (alt_num_verts || count <= 65535) { + r300_emit_aos(r300, start); + r300_emit_draw_arrays(r300, mode, count); + } else { + do { + short_count = MIN2(count, 65535); + r300_emit_aos(r300, start); + r300_emit_draw_arrays(r300, mode, short_count); + + start += short_count; + count -= short_count; + + /* Again, we emit both AOS and draw_arrays so there should be + * at least 128 spare dwords. */ + if (count && r300_reserve_cs_space(r300, 128)) { + r300_emit_buffer_validate(r300, TRUE, NULL); + r300_emit_dirty_state(r300); + } + } while (count); + } } } @@ -559,7 +627,7 @@ r300_render_get_vertex_info(struct vbuf_render* render) r300_update_derived_state(r300); - return (struct vertex_info*)r300->vertex_format_state.state; + return &r300->vertex_info; } static boolean r300_render_allocate_vertices(struct vbuf_render* render, @@ -644,6 +712,8 @@ static void r300_render_draw_arrays(struct vbuf_render* render, CS_LOCALS(r300); + r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + 2); + r300_emit_buffer_validate(r300, FALSE, NULL); r300_emit_dirty_state(r300); DBG(r300, DBG_DRAW, "r300: Doing vbuf render, count %d\n", count); @@ -662,12 +732,15 @@ static void r300_render_draw(struct vbuf_render* render, struct r300_render* r300render = r300_render(render); struct r300_context* r300 = r300render->r300; int i; + unsigned dwords = 2 + (count+1)/2; CS_LOCALS(r300); + r300_reserve_cs_space(r300, r300_get_num_dirty_dwords(r300) + dwords); + r300_emit_buffer_validate(r300, FALSE, NULL); r300_emit_dirty_state(r300); - BEGIN_CS(2 + (count+1)/2); + BEGIN_CS(dwords); OUT_CS_PKT3(R300_PACKET3_3D_DRAW_INDX_2, (count+1)/2); OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) | r300render->hwprim); diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c index b892c084c04..5880eecd5fe 100644 --- a/src/gallium/drivers/r300/r300_screen.c +++ b/src/gallium/drivers/r300/r300_screen.c @@ -1,5 +1,6 @@ /* * 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"), @@ -20,14 +21,13 @@ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "util/u_inlines.h" #include "util/u_format.h" #include "util/u_memory.h" #include "util/u_simple_screen.h" #include "r300_context.h" -#include "r300_screen.h" #include "r300_texture.h" +#include "r300_transfer.h" #include "radeon_winsys.h" #include "r300_winsys.h" @@ -210,6 +210,9 @@ static boolean r300_is_format_supported(struct pipe_screen* screen, { uint32_t retval = 0; boolean is_r500 = r300_screen(screen)->caps->is_r500; + boolean is_z24 = format == PIPE_FORMAT_X8Z24_UNORM || + format == PIPE_FORMAT_S8Z24_UNORM; + boolean is_color2101010 = format == PIPE_FORMAT_R10G10B10A2_UNORM; if (target >= PIPE_MAX_TEXTURE_TYPES) { debug_printf("r300: Implementation error: Received bogus texture " @@ -217,154 +220,36 @@ static boolean r300_is_format_supported(struct pipe_screen* screen, return FALSE; } - switch (format) { - /* Supported formats. */ - /* Colorbuffer */ - case PIPE_FORMAT_A8_UNORM: - case PIPE_FORMAT_L8_UNORM: - retval = usage & - (PIPE_TEXTURE_USAGE_RENDER_TARGET | - PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_PRIMARY); - break; - - /* Texture */ - case PIPE_FORMAT_A8R8G8B8_SRGB: - case PIPE_FORMAT_R8G8B8A8_SRGB: - case PIPE_FORMAT_DXT1_RGB: - case PIPE_FORMAT_DXT1_RGBA: - case PIPE_FORMAT_DXT3_RGBA: - case PIPE_FORMAT_DXT5_RGBA: - case PIPE_FORMAT_YCBCR: - case PIPE_FORMAT_L8_SRGB: - case PIPE_FORMAT_A8L8_SRGB: - case PIPE_FORMAT_A8L8_UNORM: - retval = usage & PIPE_TEXTURE_USAGE_SAMPLER; - break; - - /* Colorbuffer or texture */ - case PIPE_FORMAT_R5G6B5_UNORM: - case PIPE_FORMAT_A1R5G5B5_UNORM: - case PIPE_FORMAT_A4R4G4B4_UNORM: - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_R8G8B8A8_UNORM: - case PIPE_FORMAT_R8G8B8X8_UNORM: - case PIPE_FORMAT_I8_UNORM: - retval = usage & - (PIPE_TEXTURE_USAGE_RENDER_TARGET | - PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_PRIMARY | - PIPE_TEXTURE_USAGE_SAMPLER); - break; - - /* Z buffer or texture */ - case PIPE_FORMAT_Z16_UNORM: - retval = usage & - (PIPE_TEXTURE_USAGE_DEPTH_STENCIL | - PIPE_TEXTURE_USAGE_SAMPLER); - break; - - /* 24bit Z buffer can only be used as a texture on R500. */ - case PIPE_FORMAT_Z24X8_UNORM: - /* Z buffer with stencil or texture */ - case PIPE_FORMAT_Z24S8_UNORM: - retval = usage & - (PIPE_TEXTURE_USAGE_DEPTH_STENCIL | - (is_r500 ? PIPE_TEXTURE_USAGE_SAMPLER : 0)); - break; - - /* Definitely unsupported formats. */ - /* Non-usable Z buffer/stencil formats. */ - case PIPE_FORMAT_Z32_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: - SCREEN_DBG(r300_screen(screen), DBG_TEX, - "r300: Note: Got unsupported format: %s in %s\n", - util_format_name(format), __FUNCTION__); - return FALSE; - - /* XXX Add all remaining gallium-supported formats, - * see util/u_format.csv. */ - - default: - /* Unknown format... */ - debug_printf("r300: Warning: Got unknown format: %s in %s\n", - util_format_name(format), __FUNCTION__); - break; + /* Check sampler format support. */ + if ((usage & PIPE_TEXTURE_USAGE_SAMPLER) && + /* Z24 cannot be sampled from on non-r5xx. */ + (is_r500 || !is_z24) && + r300_is_sampler_format_supported(format)) { + retval |= PIPE_TEXTURE_USAGE_SAMPLER; } - /* If usage was a mask that contained multiple bits, and not all of them - * are supported, this will catch that and return FALSE. - * e.g. usage = 2 | 4; retval = 4; (retval >= usage) == FALSE - * - * This also returns FALSE for any unknown formats. - */ - return (retval >= usage); -} - -static struct pipe_transfer* -r300_get_tex_transfer(struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned face, unsigned level, unsigned zslice, - enum pipe_transfer_usage usage, unsigned x, unsigned y, - unsigned w, unsigned h) -{ - struct r300_texture *tex = (struct r300_texture *)texture; - struct r300_transfer *trans; - struct r300_screen *rscreen = r300_screen(screen); - unsigned offset; - - offset = r300_texture_get_offset(tex, level, zslice, face); /* in bytes */ - - trans = CALLOC_STRUCT(r300_transfer); - if (trans) { - pipe_texture_reference(&trans->transfer.texture, texture); - trans->transfer.x = x; - trans->transfer.y = y; - trans->transfer.width = w; - trans->transfer.height = h; - trans->transfer.stride = r300_texture_get_stride(rscreen, tex, level); - trans->transfer.usage = usage; - trans->transfer.zslice = zslice; - trans->transfer.face = face; - - trans->offset = offset; + /* Check colorbuffer format support. */ + if ((usage & (PIPE_TEXTURE_USAGE_RENDER_TARGET | + PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_SCANOUT | + PIPE_TEXTURE_USAGE_SHARED)) && + /* 2101010 cannot be rendered to on non-r5xx. */ + (is_r500 || !is_color2101010) && + r300_is_colorbuffer_format_supported(format)) { + retval |= usage & + (PIPE_TEXTURE_USAGE_RENDER_TARGET | + PIPE_TEXTURE_USAGE_DISPLAY_TARGET | + PIPE_TEXTURE_USAGE_SCANOUT | + PIPE_TEXTURE_USAGE_SHARED); } - return &trans->transfer; -} - -static void -r300_tex_transfer_destroy(struct pipe_transfer *trans) -{ - pipe_texture_reference(&trans->texture, NULL); - FREE(trans); -} - -static void* r300_transfer_map(struct pipe_screen* screen, - struct pipe_transfer* transfer) -{ - struct r300_texture* tex = (struct r300_texture*)transfer->texture; - char* map; - enum pipe_format format = tex->tex.format; - map = pipe_buffer_map(screen, tex->buffer, - pipe_transfer_buffer_flags(transfer)); - - if (!map) { - return NULL; + /* Check depth-stencil format support. */ + if (usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL && + r300_is_zs_format_supported(format)) { + retval |= PIPE_TEXTURE_USAGE_DEPTH_STENCIL; } - return map + r300_transfer(transfer)->offset + - transfer->y / util_format_get_blockheight(format) * transfer->stride + - transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); -} - -static void r300_transfer_unmap(struct pipe_screen* screen, - struct pipe_transfer* transfer) -{ - struct r300_texture* tex = (struct r300_texture*)transfer->texture; - pipe_buffer_unmap(screen, tex->buffer); + return retval == usage; } static void r300_destroy_screen(struct pipe_screen* pscreen) @@ -403,13 +288,11 @@ struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys) r300screen->screen.get_paramf = r300_get_paramf; r300screen->screen.is_format_supported = r300_is_format_supported; r300screen->screen.context_create = r300_create_context; - r300screen->screen.get_tex_transfer = r300_get_tex_transfer; - r300screen->screen.tex_transfer_destroy = r300_tex_transfer_destroy; - r300screen->screen.transfer_map = r300_transfer_map; - r300screen->screen.transfer_unmap = r300_transfer_unmap; r300_init_screen_texture_functions(&r300screen->screen); + r300_init_screen_transfer_functions(&r300screen->screen); u_simple_screen_init(&r300screen->screen); return &r300screen->screen; } + diff --git a/src/gallium/drivers/r300/r300_screen.h b/src/gallium/drivers/r300/r300_screen.h index 502fbfa5a24..484bde6a6be 100644 --- a/src/gallium/drivers/r300/r300_screen.h +++ b/src/gallium/drivers/r300/r300_screen.h @@ -1,5 +1,6 @@ /* * 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"), @@ -27,6 +28,8 @@ #include "r300_chipset.h" +#define R300_TEXTURE_USAGE_TRANSFER PIPE_TEXTURE_USAGE_CUSTOM + struct radeon_winsys; struct r300_screen { @@ -35,6 +38,10 @@ struct r300_screen { struct radeon_winsys* radeon_winsys; + /* XXX This hack will be removed once texture transfers become part of + * pipe_context. */ + struct pipe_context* ctx; + /* Chipset capabilities */ struct r300_capabilities* caps; @@ -42,25 +49,14 @@ struct r300_screen { unsigned debug; }; -struct r300_transfer { - /* Parent class */ - struct pipe_transfer transfer; - - /* Offset from start of buffer. */ - unsigned offset; -}; /* Convenience cast wrapper. */ static INLINE struct r300_screen* r300_screen(struct pipe_screen* screen) { return (struct r300_screen*)screen; } -/* Convenience cast wrapper. */ -static INLINE struct r300_transfer* -r300_transfer(struct pipe_transfer* transfer) -{ - return (struct r300_transfer*)transfer; -} +/* Creates a new r300 screen. */ +struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys); /* Debug functionality. */ diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index 995664d9000..7683a423f2f 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -43,6 +43,12 @@ /* r300_state: Functions used to intialize state context by translating * Gallium state objects into semi-native r300 state objects. */ +#define UPDATE_STATE(cso, atom) \ + if (cso != atom.state) { \ + atom.state = cso; \ + atom.dirty = TRUE; \ + } + static boolean blend_discard_if_src_alpha_0(unsigned srcRGB, unsigned srcA, unsigned dstRGB, unsigned dstA) { @@ -328,8 +334,7 @@ static void r300_bind_blend_state(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); - r300->blend_state.state = state; - r300->blend_state.dirty = TRUE; + UPDATE_STATE(state, r300->blend_state); } /* Free blend state. */ @@ -356,7 +361,7 @@ static void r300_set_blend_color(struct pipe_context* pipe, (struct r300_blend_color_state*)r300->blend_color_state.state; union util_color uc; - util_pack_color(color->color, PIPE_FORMAT_A8R8G8B8_UNORM, &uc); + util_pack_color(color->color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); state->blend_color = uc.ui; /* XXX if FP16 blending is enabled, we should use the FP16 format */ @@ -376,6 +381,8 @@ static void r300_set_clip_state(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); + r300->clip = *state; + if (r300_screen(pipe->screen)->caps->has_tcl) { memcpy(r300->clip_state.state, state, sizeof(struct pipe_clip_state)); r300->clip_state.size = 29; @@ -476,11 +483,8 @@ static void r300_bind_dsa_state(struct pipe_context* pipe, void* state) { struct r300_context* r300 = r300_context(pipe); - struct r300_screen* r300screen = r300_screen(pipe->screen); - r300->dsa_state.state = state; - r300->dsa_state.size = r300screen->caps->is_r500 ? 8 : 6; - r300->dsa_state.dirty = TRUE; + UPDATE_STATE(state, r300->dsa_state); } /* Free DSA state. */ @@ -567,6 +571,7 @@ static void { struct r300_context* r300 = r300_context(pipe); struct r300_screen* r300screen = r300_screen(pipe->screen); + struct pipe_framebuffer_state *old_state = r300->fb_state.state; unsigned max_width, max_height; uint32_t zbuffer_bpp = 0; @@ -591,22 +596,30 @@ static void return; } - if (r300->draw) { draw_flush(r300->draw); } - memcpy(r300->fb_state.state, state, sizeof(struct pipe_framebuffer_state)); + r300->fb_state.dirty = TRUE; - r300->fb_state.size = (10 * state->nr_cbufs) + (state->zsbuf ? 10 : 0) + 6; + /* If nr_cbufs is changed from zero to non-zero or vice versa... */ + if (!!old_state->nr_cbufs != !!state->nr_cbufs) { + r300->blend_state.dirty = TRUE; + } + /* If zsbuf is set from NULL to non-NULL or vice versa.. */ + if (!!old_state->zsbuf != !!state->zsbuf) { + r300->dsa_state.dirty = TRUE; + } + if (!r300->scissor_enabled) { + r300->scissor_state.dirty = TRUE; + } r300_fb_update_tiling_flags(r300, r300->fb_state.state, state); - /* XXX wait what */ - r300->blend_state.dirty = TRUE; - r300->dsa_state.dirty = TRUE; - r300->fb_state.dirty = TRUE; - r300->scissor_state.dirty = TRUE; + memcpy(r300->fb_state.state, state, sizeof(struct pipe_framebuffer_state)); + + r300->fb_state.size = (10 * state->nr_cbufs) + (2 * (4 - state->nr_cbufs)) + + (state->zsbuf ? 10 : 0) + 8; /* Polygon offset depends on the zbuffer bit depth. */ if (state->zsbuf && r300->polygon_offset_enabled) { @@ -658,8 +671,10 @@ static void r300_bind_fs_state(struct pipe_context* pipe, void* shader) r300->fs = fs; r300_pick_fragment_shader(r300); - if (r300->vs && r300_vertex_shader_setup_wpos(r300)) { - r300->vertex_format_state.dirty = TRUE; + r300->rs_block_state.dirty = TRUE; /* Will be updated before the emission. */ + + if (r300->vs_state.state && r300_vertex_shader_setup_wpos(r300)) { + r300->vap_output_state.dirty = TRUE; } r300->dirty_state |= R300_NEW_FRAGMENT_SHADER | R300_NEW_FRAGMENT_SHADER_CONSTANTS; @@ -709,32 +724,14 @@ static void* r300_create_rs_state(struct pipe_context* pipe, rs->vap_control_status = R300_VC_32BIT_SWAP; #endif - /* If bypassing TCL, or if no TCL engine is present, turn off the HW TCL. - * Else, enable HW TCL and force Draw's TCL off. */ - if (state->bypass_vs_clip_and_viewport || - !r300screen->caps->has_tcl) { + /* If no TCL engine is present, turn off the HW TCL. */ + if (!r300screen->caps->has_tcl) { rs->vap_control_status |= R300_VAP_TCL_BYPASS; } rs->point_size = pack_float_16_6x(state->point_size) | (pack_float_16_6x(state->point_size) << R300_POINTSIZE_X_SHIFT); - /* Point minimum and maximum sizes. This register has to be emitted, - * and it'd be a step backwards to put it in invariant state. */ - if (r300screen->caps->is_r500) { - rs->point_minmax = - ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) | - ((int)(4096.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT); - } else if (r300screen->caps->is_r400) { - rs->point_minmax = - ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) | - ((int)(4021.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT); - } else { - rs->point_minmax = - ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) | - ((int)(2560.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT); - } - rs->line_control = pack_float_16_6x(state->line_width) | R300_GA_LINE_CNTL_END_TYPE_COMP; @@ -817,6 +814,7 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) { struct r300_context* r300 = r300_context(pipe); struct r300_rs_state* rs = (struct r300_rs_state*)state; + boolean scissor_was_enabled = r300->scissor_enabled; if (r300->draw) { draw_flush(r300->draw); @@ -824,22 +822,18 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state) } if (rs) { - r300->tcl_bypass = rs->rs.bypass_vs_clip_and_viewport; r300->polygon_offset_enabled = rs->rs.offset_cw || rs->rs.offset_ccw; + r300->scissor_enabled = rs->rs.scissor; } else { - r300->tcl_bypass = FALSE; r300->polygon_offset_enabled = FALSE; + r300->scissor_enabled = FALSE; } - r300->rs_state.state = rs; - r300->rs_state.dirty = TRUE; - /* XXX Why is this still needed, dammit!? */ - r300->scissor_state.dirty = TRUE; - r300->viewport_state.dirty = TRUE; + UPDATE_STATE(state, r300->rs_state); + r300->rs_state.size = 17 + (r300->polygon_offset_enabled ? 5 : 0); - /* XXX Clean these up when we move to atom emits */ - if (r300->fs && r300->fs->inputs.wpos != ATTR_UNUSED) { - r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS; + if (scissor_was_enabled != r300->scissor_enabled) { + r300->scissor_state.dirty = TRUE; } } @@ -871,7 +865,7 @@ static void* state->max_anisotropy > 0); /* Unfortunately, r300-r500 don't support floating-point mipmap lods. */ - /* We must pass these to the emit function to clamp them properly. */ + /* We must pass these to the merge function to clamp them properly. */ sampler->min_lod = MAX2((unsigned)state->min_lod, 0); sampler->max_lod = MAX2((unsigned)ceilf(state->max_lod), 0); @@ -881,7 +875,7 @@ static void* sampler->filter1 |= r300_anisotropy(state->max_anisotropy); - util_pack_color(state->border_color, PIPE_FORMAT_A8R8G8B8_UNORM, &uc); + util_pack_color(state->border_color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); sampler->border_color = uc.ui; /* R500-specific fixups and optimizations */ @@ -897,23 +891,20 @@ static void r300_bind_sampler_states(struct pipe_context* pipe, void** states) { struct r300_context* r300 = r300_context(pipe); - int i; + struct r300_textures_state* state = + (struct r300_textures_state*)r300->textures_state.state; if (count > 8) { return; } - for (i = 0; i < count; i++) { - if (r300->sampler_states[i] != states[i]) { - r300->sampler_states[i] = (struct r300_sampler_state*)states[i]; - r300->dirty_state |= (R300_NEW_SAMPLER << i); - } - } + memcpy(state->sampler_states, states, sizeof(void*) * count); + state->sampler_count = count; - r300->sampler_count = count; + r300->textures_state.dirty = TRUE; /* Pick a fragment shader based on the texture compare state. */ - if (r300->fs && (r300->dirty_state & R300_ANY_NEW_SAMPLERS)) { + if (r300->fs && count) { if (r300_pick_fragment_shader(r300)) { r300->dirty_state |= R300_NEW_FRAGMENT_SHADER | R300_NEW_FRAGMENT_SHADER_CONSTANTS; @@ -937,22 +928,25 @@ static void r300_set_sampler_textures(struct pipe_context* pipe, struct pipe_texture** texture) { struct r300_context* r300 = r300_context(pipe); + struct r300_textures_state* state = + (struct r300_textures_state*)r300->textures_state.state; + unsigned i; boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500; - int i; + boolean dirty_tex = FALSE; /* XXX magic num */ if (count > 8) { return; } - + for (i = 0; i < count; i++) { - if (r300->textures[i] != (struct r300_texture*)texture[i]) { - pipe_texture_reference((struct pipe_texture**)&r300->textures[i], - texture[i]); - r300->dirty_state |= (R300_NEW_TEXTURE << i); + if (state->textures[i] != (struct r300_texture*)texture[i]) { + pipe_texture_reference((struct pipe_texture**)&state->textures[i], + texture[i]); + dirty_tex = TRUE; - /* R300-specific - set the texrect factor in a fragment shader */ - if (!is_r500 && r300->textures[i]->is_npot) { + /* R300-specific - set the texrect factor in the fragment shader */ + if (!is_r500 && state->textures[i]->is_npot) { /* XXX It would be nice to re-emit just 1 constant, * XXX not all of them */ r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS; @@ -961,14 +955,19 @@ static void r300_set_sampler_textures(struct pipe_context* pipe, } for (i = count; i < 8; i++) { - if (r300->textures[i]) { - pipe_texture_reference((struct pipe_texture**)&r300->textures[i], + if (state->textures[i]) { + pipe_texture_reference((struct pipe_texture**)&state->textures[i], NULL); - r300->dirty_state |= (R300_NEW_TEXTURE << i); } } - r300->texture_count = count; + state->texture_count = count; + + r300->textures_state.dirty = TRUE; + + if (dirty_tex) { + r300->texture_cache_inval.dirty = TRUE; + } } static void r300_set_scissor_state(struct pipe_context* pipe, @@ -979,7 +978,9 @@ static void r300_set_scissor_state(struct pipe_context* pipe, memcpy(r300->scissor_state.state, state, sizeof(struct pipe_scissor_state)); - r300->scissor_state.dirty = TRUE; + if (r300->scissor_enabled) { + r300->scissor_state.dirty = TRUE; + } } static void r300_set_viewport_state(struct pipe_context* pipe, @@ -989,6 +990,8 @@ static void r300_set_viewport_state(struct pipe_context* pipe, struct r300_viewport_state* viewport = (struct r300_viewport_state*)r300->viewport_state.state; + r300->viewport = *state; + /* Do the transform in HW. */ viewport->vte_control = R300_VTX_W0_FMT; @@ -1028,17 +1031,24 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe, const struct pipe_vertex_buffer* buffers) { struct r300_context* r300 = r300_context(pipe); + unsigned i, max_index = ~0; memcpy(r300->vertex_buffer, buffers, sizeof(struct pipe_vertex_buffer) * count); + + for (i = 0; i < count; i++) { + max_index = MIN2(buffers[i].max_index, max_index); + } + r300->vertex_buffer_count = count; + r300->vertex_buffer_max_index = max_index; if (r300->draw) { draw_flush(r300->draw); draw_set_vertex_buffers(r300->draw, count, buffers); + } else { + r300->vertex_stream_state.dirty = TRUE; } - - r300->vertex_format_state.dirty = TRUE; } static boolean r300_validate_aos(struct r300_context *r300) @@ -1107,64 +1117,71 @@ static void* r300_create_vs_state(struct pipe_context* pipe, { struct r300_context* r300 = r300_context(pipe); - if (r300_screen(pipe->screen)->caps->has_tcl) { - struct r300_vertex_shader* vs = CALLOC_STRUCT(r300_vertex_shader); - /* Copy state directly into shader. */ - vs->state = *shader; - vs->state.tokens = tgsi_dup_tokens(shader->tokens); - - tgsi_scan_shader(shader->tokens, &vs->info); + struct r300_vertex_shader* vs = CALLOC_STRUCT(r300_vertex_shader); + r300_vertex_shader_common_init(vs, shader); - return (void*)vs; + if (r300_screen(pipe->screen)->caps->has_tcl) { + r300_translate_vertex_shader(r300, vs); } else { - return draw_create_vertex_shader(r300->draw, shader); + vs->draw_vs = draw_create_vertex_shader(r300->draw, shader); } + + return vs; } static void r300_bind_vs_state(struct pipe_context* pipe, void* shader) { struct r300_context* r300 = r300_context(pipe); + struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader; - if (r300_screen(pipe->screen)->caps->has_tcl) { - struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader; + if (vs == NULL) { + r300->vs_state.state = NULL; + return; + } + if (vs == r300->vs_state.state) { + return; + } + r300->vs_state.state = vs; - if (vs == NULL) { - r300->vs = NULL; - return; - } else if (!vs->translated) { - r300_translate_vertex_shader(r300, vs); - } + // VS output mapping for HWTCL or stream mapping for SWTCL to the RS block + if (r300->fs) { + r300_vertex_shader_setup_wpos(r300); + } + memcpy(r300->vap_output_state.state, &vs->vap_out, + sizeof(struct r300_vap_output_state)); + r300->vap_output_state.dirty = TRUE; - r300->vs = vs; - if (r300->fs) { - r300_vertex_shader_setup_wpos(r300); - } + /* The majority of the RS block bits is dependent on the vertex shader. */ + r300->rs_block_state.dirty = TRUE; /* Will be updated before the emission. */ + + if (r300_screen(pipe->screen)->caps->has_tcl) { + r300->vs_state.dirty = TRUE; + r300->vs_state.size = vs->code.length + 9; - r300->vertex_format_state.dirty = TRUE; + r300->pvs_flush.dirty = TRUE; - r300->dirty_state |= - R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS; + r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS; } else { draw_flush(r300->draw); draw_bind_vertex_shader(r300->draw, - (struct draw_vertex_shader*)shader); + (struct draw_vertex_shader*)vs->draw_vs); } } static void r300_delete_vs_state(struct pipe_context* pipe, void* shader) { struct r300_context* r300 = r300_context(pipe); + struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader; if (r300_screen(pipe->screen)->caps->has_tcl) { - struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader; - rc_constants_destroy(&vs->code.constants); - FREE((void*)vs->state.tokens); - FREE(shader); } else { draw_delete_vertex_shader(r300->draw, - (struct draw_vertex_shader*)shader); + (struct draw_vertex_shader*)vs->draw_vs); } + + FREE((void*)vs->state.tokens); + FREE(shader); } static void r300_set_constant_buffer(struct pipe_context *pipe, @@ -1215,8 +1232,12 @@ static void r300_set_constant_buffer(struct pipe_context *pipe, r300->shader_constants[shader].count = buf->size / (4 * sizeof(float)); pipe_buffer_unmap(pipe->screen, buf); - if (shader == PIPE_SHADER_VERTEX) - r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS; + if (shader == PIPE_SHADER_VERTEX) { + if (r300screen->caps->has_tcl) { + r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS; + r300->pvs_flush.dirty = TRUE; + } + } else if (shader == PIPE_SHADER_FRAGMENT) r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS; } diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index c43a93601cb..4422581b514 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -42,20 +42,20 @@ static void r300_draw_emit_attrib(struct r300_context* r300, enum interp_mode interp, int index) { - struct tgsi_shader_info* info = &r300->vs->info; + struct r300_vertex_shader* vs = r300->vs_state.state; + struct tgsi_shader_info* info = &vs->info; int output; output = draw_find_shader_output(r300->draw, info->output_semantic_name[index], info->output_semantic_index[index]); - draw_emit_vertex_attr( - (struct vertex_info*)r300->vertex_format_state.state, - emit, interp, output); + draw_emit_vertex_attr(&r300->vertex_info, emit, interp, output); } static void r300_draw_emit_all_attribs(struct r300_context* r300) { - struct r300_shader_semantics* vs_outputs = &r300->vs->outputs; + struct r300_vertex_shader* vs = r300->vs_state.state; + struct r300_shader_semantics* vs_outputs = &vs->outputs; int i, gen_count; /* Position. */ @@ -104,31 +104,31 @@ static void r300_draw_emit_all_attribs(struct r300_context* r300) } /* Update the PSC tables. */ +/* XXX move this function into r300_state.c after TCL-bypass gets removed + * XXX because this one is dependent only on vertex elements. */ static void r300_vertex_psc(struct r300_context* r300) { - struct r300_vertex_info *vformat = - (struct r300_vertex_info*)r300->vertex_format_state.state; + struct r300_vertex_shader* vs = r300->vs_state.state; + struct r300_vertex_stream_state *vformat = + (struct r300_vertex_stream_state*)r300->vertex_stream_state.state; uint16_t type, swizzle; enum pipe_format format; unsigned i; int identity[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; int* stream_tab; - /* If TCL is bypassed, map vertex streams to equivalent VS output - * locations. */ - if (r300->tcl_bypass) { - stream_tab = r300->vs->stream_loc_notcl; - } else { - stream_tab = identity; - } + memset(vformat, 0, sizeof(struct r300_vertex_stream_state)); + + stream_tab = identity; /* Vertex shaders have no semantics on their inputs, * so PSC should just route stuff based on the vertex elements, * and not on attrib information. */ DBG(r300, DBG_DRAW, "r300: vs expects %d attribs, routing %d elements" " in psc\n", - r300->vs->info.num_inputs, + vs->info.num_inputs, r300->velems->count); + r300->vertex_element_count); for (i = 0; i < r300->velems->count; i++) { format = r300->velems->velem[i].src_format; @@ -154,18 +154,24 @@ static void r300_vertex_psc(struct r300_context* r300) } vformat->vap_prog_stream_cntl[i >> 1] |= (R300_LAST_VEC << (i & 1 ? 16 : 0)); + + vformat->count = (i >> 1) + 1; + r300->vertex_stream_state.size = (1 + vformat->count) * 2; } /* Update the PSC tables for SW TCL, using Draw. */ static void r300_swtcl_vertex_psc(struct r300_context* r300) { - struct r300_vertex_info *vformat = - (struct r300_vertex_info*)r300->vertex_format_state.state; - struct vertex_info* vinfo = &vformat->vinfo; + struct r300_vertex_shader* vs = r300->vs_state.state; + struct r300_vertex_stream_state *vformat = + (struct r300_vertex_stream_state*)r300->vertex_stream_state.state; + struct vertex_info* vinfo = &r300->vertex_info; uint16_t type, swizzle; enum pipe_format format; unsigned i, attrib_count; - int* vs_output_tab = r300->vs->stream_loc_notcl; + int* vs_output_tab = vs->stream_loc_notcl; + + memset(vformat, 0, sizeof(struct r300_vertex_stream_state)); /* For each Draw attribute, route it to the fragment shader according * to the vs_output_tab. */ @@ -208,6 +214,9 @@ static void r300_swtcl_vertex_psc(struct r300_context* r300) } vformat->vap_prog_stream_cntl[i >> 1] |= (R300_LAST_VEC << (i & 1 ? 16 : 0)); + + vformat->count = (i >> 1) + 1; + r300->vertex_stream_state.size = (1 + vformat->count) * 2; } static void r300_rs_col(struct r300_rs_block* rs, int id, int ptr, @@ -416,31 +425,24 @@ static void r300_update_rs_block(struct r300_context* r300, /* Now, after all that, see if we actually need to update the state. */ if (memcmp(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block))) { memcpy(r300->rs_block_state.state, &rs, sizeof(struct r300_rs_block)); - r300->rs_block_state.size = 5 + count; - r300->rs_block_state.dirty = TRUE; + r300->rs_block_state.size = 5 + count*2; } } /* Update the shader-dependant states. */ static void r300_update_derived_shader_state(struct r300_context* r300) { + struct r300_vertex_shader* vs = r300->vs_state.state; struct r300_screen* r300screen = r300_screen(r300->context.screen); - struct r300_vertex_info *vformat = - (struct r300_vertex_info*)r300->vertex_format_state.state; - struct vertex_info* vinfo = &vformat->vinfo; - - /* Mmm, delicious hax */ - memset(r300->vertex_format_state.state, 0, sizeof(struct r300_vertex_info)); - memcpy(vinfo->hwfmt, r300->vs->hwfmt, sizeof(uint)*4); - r300_update_rs_block(r300, &r300->vs->outputs, &r300->fs->inputs); + r300_update_rs_block(r300, &vs->outputs, &r300->fs->inputs); if (r300screen->caps->has_tcl) { r300_vertex_psc(r300); } else { + memset(&r300->vertex_info, 0, sizeof(struct vertex_info)); r300_draw_emit_all_attribs(r300); - draw_compute_vertex_size( - (struct vertex_info*)r300->vertex_format_state.state); + draw_compute_vertex_size(&r300->vertex_info); r300_swtcl_vertex_psc(r300); } } @@ -516,14 +518,73 @@ static void r300_update_ztop(struct r300_context* r300) r300->ztop_state.dirty = TRUE; } +static void r300_merge_textures_and_samplers(struct r300_context* r300) +{ + struct r300_textures_state *state = + (struct r300_textures_state*)r300->textures_state.state; + struct r300_texture_sampler_state *texstate; + struct r300_sampler_state *sampler; + struct r300_texture *tex; + unsigned min_level, max_level, i, size; + unsigned count = MIN2(state->texture_count, state->sampler_count); + + state->tx_enable = 0; + size = 2; + + for (i = 0; i < count; i++) { + if (state->textures[i] && state->sampler_states[i]) { + state->tx_enable |= 1 << i; + + tex = state->textures[i]; + sampler = state->sampler_states[i]; + + texstate = &state->regs[i]; + memcpy(texstate->format, &tex->state, sizeof(uint32_t)*3); + texstate->filter[0] = sampler->filter0; + texstate->filter[1] = sampler->filter1; + texstate->border_color = sampler->border_color; + texstate->tile_config = R300_TXO_MACRO_TILE(tex->macrotile) | + R300_TXO_MICRO_TILE(tex->microtile); + + /* to emulate 1D textures through 2D ones correctly */ + if (tex->tex.target == PIPE_TEXTURE_1D) { + texstate->filter[0] &= ~R300_TX_WRAP_T_MASK; + texstate->filter[0] |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE); + } + + if (tex->is_npot) { + /* NPOT textures don't support mip filter, unfortunately. + * This prevents incorrect rendering. */ + texstate->filter[0] &= ~R300_TX_MIN_FILTER_MIP_MASK; + } else { + /* determine min/max levels */ + /* the MAX_MIP level is the largest (finest) one */ + max_level = MIN2(sampler->max_lod, tex->tex.last_level); + min_level = MIN2(sampler->min_lod, max_level); + texstate->format[0] |= R300_TX_NUM_LEVELS(max_level); + texstate->filter[0] |= R300_TX_MAX_MIP_LEVEL(min_level); + } + + texstate->filter[0] |= i << 28; + + size += 16; + state->count = i+1; + } + } + + r300->textures_state.size = size; +} + void r300_update_derived_state(struct r300_context* r300) { - /* XXX */ - if (r300->dirty_state & - (R300_NEW_FRAGMENT_SHADER | R300_NEW_VERTEX_SHADER) || - r300->vertex_format_state.dirty || r300->rs_state.dirty) { + if (r300->rs_block_state.dirty || + r300->vertex_stream_state.dirty) { /* XXX put updating PSC out of this file */ r300_update_derived_shader_state(r300); } + if (r300->textures_state.dirty) { + r300_merge_textures_and_samplers(r300); + } + r300_update_ztop(r300); } diff --git a/src/gallium/drivers/r300/r300_state_inlines.h b/src/gallium/drivers/r300/r300_state_inlines.h index 6ee6cd0e3f2..af7827820cc 100644 --- a/src/gallium/drivers/r300/r300_state_inlines.h +++ b/src/gallium/drivers/r300/r300_state_inlines.h @@ -327,118 +327,6 @@ static INLINE uint32_t r300_anisotropy(unsigned max_aniso) } } -/* Buffer formats. */ - -/* Colorbuffer formats. This is the unswizzled format of the RB3D block's - * output. For the swizzling of the targets, check the shader's format. */ -static INLINE uint32_t r300_translate_colorformat(enum pipe_format format) -{ - switch (format) { - /* 8-bit buffers */ - case PIPE_FORMAT_A8_UNORM: - case PIPE_FORMAT_I8_UNORM: - case PIPE_FORMAT_L8_UNORM: - /* case PIPE_FORMAT_S8_UNORM: ??? */ - return R300_COLOR_FORMAT_I8; - /* 16-bit buffers */ - case PIPE_FORMAT_R5G6B5_UNORM: - return R300_COLOR_FORMAT_RGB565; - case PIPE_FORMAT_A1R5G5B5_UNORM: - return R300_COLOR_FORMAT_ARGB1555; - case PIPE_FORMAT_A4R4G4B4_UNORM: - return R300_COLOR_FORMAT_ARGB4444; - /* 32-bit buffers */ - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_R8G8B8A8_UNORM: - case PIPE_FORMAT_R8G8B8X8_UNORM: - return R300_COLOR_FORMAT_ARGB8888; - /* XXX Not in pipe_format - case PIPE_FORMAT_A32R32G32B32: - return R300_COLOR_FORMAT_ARGB32323232; - case PIPE_FORMAT_A16R16G16B16: - return R300_COLOR_FORMAT_ARGB16161616; - case PIPE_FORMAT_A10R10G10B10_UNORM: - return R500_COLOR_FORMAT_ARGB10101010; - case PIPE_FORMAT_A2R10G10B10_UNORM: - return R500_COLOR_FORMAT_ARGB2101010; - case PIPE_FORMAT_I10_UNORM: - return R500_COLOR_FORMAT_I10; */ - default: - debug_printf("r300: Implementation error: " - "Got unsupported color format %s in %s\n", - util_format_name(format), __FUNCTION__); - assert(0); - break; - } - return 0; -} - -/* Depthbuffer and stencilbuffer. Thankfully, we only support two flavors. */ -static INLINE uint32_t r300_translate_zsformat(enum pipe_format format) -{ - switch (format) { - /* 16-bit depth, no stencil */ - case PIPE_FORMAT_Z16_UNORM: - return R300_DEPTHFORMAT_16BIT_INT_Z; - /* 24-bit depth, ignored stencil */ - case PIPE_FORMAT_Z24X8_UNORM: - /* 24-bit depth, 8-bit stencil */ - case PIPE_FORMAT_Z24S8_UNORM: - return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL; - default: - debug_printf("r300: Implementation error: " - "Got unsupported ZS format %s in %s\n", - util_format_name(format), __FUNCTION__); - assert(0); - break; - } - return 0; -} - -/* Shader output formats. This is essentially the swizzle from the shader - * to the RB3D block. - * - * Note that formats are stored from C3 to C0. */ -static INLINE uint32_t r300_translate_out_fmt(enum pipe_format format) -{ - switch (format) { - case PIPE_FORMAT_R5G6B5_UNORM: - /* C_5_6_5 is missing in US_OUT_FMT, but C4_8 works just fine. */ - case PIPE_FORMAT_A1R5G5B5_UNORM: - /* C_1_5_5_5 is missing in US_OUT_FMT, but C4_8 works just fine. */ - case PIPE_FORMAT_A4R4G4B4_UNORM: - /* C4_4 is missing in US_OUT_FMT, but C4_8 works just fine. */ - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: - return R300_US_OUT_FMT_C4_8 | - R300_C0_SEL_B | R300_C1_SEL_G | - R300_C2_SEL_R | R300_C3_SEL_A; - case PIPE_FORMAT_R8G8B8A8_UNORM: - case PIPE_FORMAT_R8G8B8X8_UNORM: - return R300_US_OUT_FMT_C4_8 | - R300_C0_SEL_A | R300_C1_SEL_B | - R300_C2_SEL_G | R300_C3_SEL_R; - - /* 8-bit outputs */ - case PIPE_FORMAT_A8_UNORM: - return R300_US_OUT_FMT_C4_8 | - R300_C0_SEL_A; - case PIPE_FORMAT_I8_UNORM: - case PIPE_FORMAT_L8_UNORM: - return R300_US_OUT_FMT_C4_8 | - R300_C0_SEL_R; - /* R300_OUT_SIGN(x) */ - default: - debug_printf("r300: Implementation error: " - "Got unsupported output format %s in %s\n", - util_format_name(format), __FUNCTION__); - assert(0); - return R300_US_OUT_FMT_UNUSED; - } - return 0; -} - /* Non-CSO state. (For now.) */ static INLINE uint32_t r300_translate_gb_pipes(int pipe_count) @@ -496,8 +384,7 @@ r300_translate_vertex_data_type(enum pipe_format format) { desc = util_format_description(format); - if (desc->layout != UTIL_FORMAT_LAYOUT_ARITH && - desc->layout != UTIL_FORMAT_LAYOUT_ARRAY) { + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { debug_printf("r300: Bad format %s in %s:%d\n", util_format_name(format), __FUNCTION__, __LINE__); assert(0); @@ -566,36 +453,19 @@ r300_translate_vertex_data_type(enum pipe_format format) { static INLINE uint16_t r300_translate_vertex_data_swizzle(enum pipe_format format) { const struct util_format_description *desc = util_format_description(format); - unsigned swizzle[4], i; assert(format); - if (desc->layout != UTIL_FORMAT_LAYOUT_ARITH && - desc->layout != UTIL_FORMAT_LAYOUT_ARRAY) { + if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) { debug_printf("r300: Bad format %s in %s:%d\n", util_format_name(format), __FUNCTION__, __LINE__); return 0; } - /* Swizzles for 8bits formats are in the reversed order, not sure why. */ - if (desc->channel[0].size == 8) { - for (i = 0; i < 4; i++) { - if (desc->swizzle[i] <= 3) { - swizzle[i] = 3 - desc->swizzle[i]; - } else { - swizzle[i] = desc->swizzle[i]; - } - } - } else { - for (i = 0; i < 4; i++) { - swizzle[i] = desc->swizzle[i]; - } - } - - return ((swizzle[0] << R300_SWIZZLE_SELECT_X_SHIFT) | - (swizzle[1] << R300_SWIZZLE_SELECT_Y_SHIFT) | - (swizzle[2] << R300_SWIZZLE_SELECT_Z_SHIFT) | - (swizzle[3] << R300_SWIZZLE_SELECT_W_SHIFT) | + return ((desc->swizzle[0] << R300_SWIZZLE_SELECT_X_SHIFT) | + (desc->swizzle[1] << R300_SWIZZLE_SELECT_Y_SHIFT) | + (desc->swizzle[2] << R300_SWIZZLE_SELECT_Z_SHIFT) | + (desc->swizzle[3] << R300_SWIZZLE_SELECT_W_SHIFT) | (0xf << R300_WRITE_ENA_SHIFT)); } diff --git a/src/gallium/drivers/r300/r300_state_invariant.c b/src/gallium/drivers/r300/r300_state_invariant.c index 97927acf1b4..4a2c68269b1 100644 --- a/src/gallium/drivers/r300/r300_state_invariant.c +++ b/src/gallium/drivers/r300/r300_state_invariant.c @@ -38,7 +38,8 @@ struct pipe_viewport_state r300_viewport_identity = { * * Note that eventually this should be empty, but it's useful for development * and general unduplication of code. */ -void r300_emit_invariant_state(struct r300_context* r300, void* state) +void r300_emit_invariant_state(struct r300_context* r300, + unsigned size, void* state) { struct r300_capabilities* caps = r300_screen(r300->context.screen)->caps; CS_LOCALS(r300); diff --git a/src/gallium/drivers/r300/r300_state_invariant.h b/src/gallium/drivers/r300/r300_state_invariant.h index 5d1a9636545..83d031c7fe9 100644 --- a/src/gallium/drivers/r300/r300_state_invariant.h +++ b/src/gallium/drivers/r300/r300_state_invariant.h @@ -25,6 +25,7 @@ struct r300_context; -void r300_emit_invariant_state(struct r300_context* r300, void* state); +void r300_emit_invariant_state(struct r300_context* r300, + unsigned size, void* state); #endif /* R300_STATE_INVARIANT_H */ diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c index 34a49bec34c..04124afd4dc 100644 --- a/src/gallium/drivers/r300/r300_texture.c +++ b/src/gallium/drivers/r300/r300_texture.c @@ -1,5 +1,6 @@ /* * 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"), @@ -29,6 +30,7 @@ #include "r300_context.h" #include "r300_texture.h" #include "r300_screen.h" +#include "r300_state_inlines.h" #include "radeon_winsys.h" @@ -44,12 +46,465 @@ static const unsigned microblock_table[5][3][2] = { {{ 2, 1}, {0, 0}, {0, 0}} /* 128 bits per pixel */ }; +/* Translate a pipe_format into a useful texture format for sampling. + * + * Some special formats are translated directly using R300_EASY_TX_FORMAT, + * but the majority of them is translated in a generic way, automatically + * supporting all the formats hw can support. + * + * R300_EASY_TX_FORMAT swizzles the texture. + * Note the signature of R300_EASY_TX_FORMAT: + * R300_EASY_TX_FORMAT(B, G, R, A, FORMAT); + * + * The FORMAT specifies how the texture sampler will treat the texture, and + * makes available X, Y, Z, W, ZERO, and ONE for swizzling. */ +static uint32_t r300_translate_texformat(enum pipe_format format) +{ + uint32_t result = 0; + const struct util_format_description *desc; + unsigned components = 0, i; + boolean uniform = TRUE; + const uint32_t swizzle_shift[4] = { + R300_TX_FORMAT_R_SHIFT, + R300_TX_FORMAT_G_SHIFT, + R300_TX_FORMAT_B_SHIFT, + R300_TX_FORMAT_A_SHIFT + }; + const uint32_t swizzle[4] = { + R300_TX_FORMAT_X, + R300_TX_FORMAT_Y, + R300_TX_FORMAT_Z, + R300_TX_FORMAT_W + }; + 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, + }; + + desc = util_format_description(format); + + /* Colorspace (return non-RGB formats directly). */ + switch (desc->colorspace) { + /* Depth stencil formats. */ + case UTIL_FORMAT_COLORSPACE_ZS: + switch (format) { + case PIPE_FORMAT_Z16_UNORM: + return R300_EASY_TX_FORMAT(X, X, X, X, X16); + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + return R300_EASY_TX_FORMAT(X, X, X, X, W24_FP); + default: + return ~0; /* Unsupported. */ + } + + /* YUV formats. */ + case UTIL_FORMAT_COLORSPACE_YUV: + result |= R300_TX_FORMAT_YUV_TO_RGB; + + switch (format) { + case PIPE_FORMAT_UYVY: + return R300_EASY_TX_FORMAT(X, Y, Z, ONE, YVYU422) | result; + case PIPE_FORMAT_YUYV: + return R300_EASY_TX_FORMAT(X, Y, Z, ONE, VYUY422) | result; + default: + return ~0; /* Unsupported/unknown. */ + } + + /* Add gamma correction. */ + case UTIL_FORMAT_COLORSPACE_SRGB: + result |= R300_TX_FORMAT_GAMMA; + break; + + default:; + } + + /* Add swizzle. */ + for (i = 0; i < 4; i++) { + switch (desc->swizzle[i]) { + case UTIL_FORMAT_SWIZZLE_X: + case UTIL_FORMAT_SWIZZLE_NONE: + result |= swizzle[0] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_Y: + result |= swizzle[1] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_Z: + result |= swizzle[2] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_W: + result |= swizzle[3] << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_0: + result |= R300_TX_FORMAT_ZERO << swizzle_shift[i]; + break; + case UTIL_FORMAT_SWIZZLE_1: + result |= R300_TX_FORMAT_ONE << swizzle_shift[i]; + break; + default: + return ~0; /* Unsupported. */ + } + } + + /* Compressed formats. */ + if (desc->layout == UTIL_FORMAT_LAYOUT_COMPRESSED) { + switch (format) { + case PIPE_FORMAT_DXT1_RGB: + case PIPE_FORMAT_DXT1_RGBA: + case PIPE_FORMAT_DXT1_SRGB: + case PIPE_FORMAT_DXT1_SRGBA: + return R300_TX_FORMAT_DXT1 | result; + case PIPE_FORMAT_DXT3_RGBA: + case PIPE_FORMAT_DXT3_SRGBA: + return R300_TX_FORMAT_DXT3 | result; + case PIPE_FORMAT_DXT5_RGBA: + case PIPE_FORMAT_DXT5_SRGBA: + return R300_TX_FORMAT_DXT5 | result; + default: + return ~0; /* Unsupported/unknown. */ + } + } + + /* Get the number of components. */ + for (i = 0; i < 4; i++) { + if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) { + ++components; + } + } + + /* Add sign. */ + for (i = 0; i < components; i++) { + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + result |= sign_bit[i]; + } + } + + /* See whether the components are of the same size. */ + for (i = 1; i < components; i++) { + uniform = uniform && desc->channel[0].size == desc->channel[i].size; + } + + /* Non-uniform formats. */ + if (!uniform) { + switch (components) { + case 3: + if (desc->channel[0].size == 5 && + desc->channel[1].size == 6 && + desc->channel[2].size == 5) { + return R300_TX_FORMAT_Z5Y6X5 | result; + } + if (desc->channel[0].size == 5 && + desc->channel[1].size == 5 && + desc->channel[2].size == 6) { + return R300_TX_FORMAT_Z6Y5X5 | result; + } + return ~0; /* Unsupported/unknown. */ + + case 4: + if (desc->channel[0].size == 5 && + desc->channel[1].size == 5 && + desc->channel[2].size == 5 && + desc->channel[3].size == 1) { + return R300_TX_FORMAT_W1Z5Y5X5 | result; + } + if (desc->channel[0].size == 10 && + desc->channel[1].size == 10 && + desc->channel[2].size == 10 && + desc->channel[3].size == 2) { + return R300_TX_FORMAT_W2Z10Y10X10 | result; + } + } + return ~0; /* Unsupported/unknown. */ + } + + /* And finally, uniform formats. */ + switch (desc->channel[0].type) { + case UTIL_FORMAT_TYPE_UNSIGNED: + case UTIL_FORMAT_TYPE_SIGNED: + if (!desc->channel[0].normalized && + desc->colorspace != UTIL_FORMAT_COLORSPACE_SRGB) { + return ~0; + } + + switch (desc->channel[0].size) { + case 4: + switch (components) { + case 2: + return R300_TX_FORMAT_Y4X4 | result; + case 4: + return R300_TX_FORMAT_W4Z4Y4X4 | result; + } + return ~0; + + case 8: + switch (components) { + case 1: + return R300_TX_FORMAT_X8 | result; + case 2: + return R300_TX_FORMAT_Y8X8 | result; + case 4: + return R300_TX_FORMAT_W8Z8Y8X8 | result; + } + return ~0; + + case 16: + switch (components) { + case 1: + return R300_TX_FORMAT_X16 | result; + case 2: + return R300_TX_FORMAT_Y16X16 | result; + case 4: + return R300_TX_FORMAT_W16Z16Y16X16 | result; + } + } + return ~0; + +/* XXX Enable float textures here. */ +#if 0 + case UTIL_FORMAT_TYPE_FLOAT: + switch (desc->channel[0].size) { + case 16: + switch (components) { + case 1: + return R300_TX_FORMAT_16F | result; + case 2: + return R300_TX_FORMAT_16F_16F | result; + case 4: + return R300_TX_FORMAT_16F_16F_16F_16F | result; + } + return ~0; + + case 32: + switch (components) { + case 1: + return R300_TX_FORMAT_32F | result; + case 2: + return R300_TX_FORMAT_32F_32F | result; + case 4: + return R300_TX_FORMAT_32F_32F_32F_32F | result; + } + } +#endif + } + + return ~0; /* Unsupported/unknown. */ +} + +/* Buffer formats. */ + +/* Colorbuffer formats. This is the unswizzled format of the RB3D block's + * output. For the swizzling of the targets, check the shader's format. */ +static uint32_t r300_translate_colorformat(enum pipe_format format) +{ + switch (format) { + /* 8-bit buffers. */ + case PIPE_FORMAT_A8_UNORM: + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_L8_SRGB: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R8_SNORM: + return R300_COLOR_FORMAT_I8; + + /* 16-bit buffers. */ + case PIPE_FORMAT_B5G6R5_UNORM: + return R300_COLOR_FORMAT_RGB565; + case PIPE_FORMAT_B5G5R5A1_UNORM: + return R300_COLOR_FORMAT_ARGB1555; + case PIPE_FORMAT_B4G4R4A4_UNORM: + return R300_COLOR_FORMAT_ARGB4444; + + /* 32-bit buffers. */ + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8A8_SRGB: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8X8_SRGB: + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_A8R8G8B8_SRGB: + case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_SRGB: + case PIPE_FORMAT_A8B8G8R8_UNORM: + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_A8B8G8R8_SRGB: + case PIPE_FORMAT_X8B8G8R8_UNORM: + case PIPE_FORMAT_X8B8G8R8_SRGB: + case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + return R300_COLOR_FORMAT_ARGB8888; + case PIPE_FORMAT_R10G10B10A2_UNORM: + 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: /* not in pipe_format */ + return R300_COLOR_FORMAT_ARGB16161616; + +/* XXX Enable float textures here. */ +#if 0 + /* 128-bit buffers. */ + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return R300_COLOR_FORMAT_ARGB32323232; +#endif + + /* YUV buffers. */ + case PIPE_FORMAT_UYVY: + return R300_COLOR_FORMAT_YVYU; + case PIPE_FORMAT_YUYV: + return R300_COLOR_FORMAT_VYUY; + default: + return ~0; /* Unsupported. */ + } +} + +/* Depthbuffer and stencilbuffer. Thankfully, we only support two flavors. */ +static uint32_t r300_translate_zsformat(enum pipe_format format) +{ + switch (format) { + /* 16-bit depth, no stencil */ + case PIPE_FORMAT_Z16_UNORM: + return R300_DEPTHFORMAT_16BIT_INT_Z; + /* 24-bit depth, ignored stencil */ + case PIPE_FORMAT_X8Z24_UNORM: + /* 24-bit depth, 8-bit stencil */ + case PIPE_FORMAT_S8Z24_UNORM: + return R300_DEPTHFORMAT_24BIT_INT_Z_8BIT_STENCIL; + default: + return ~0; /* Unsupported. */ + } +} + +/* Shader output formats. This is essentially the swizzle from the shader + * to the RB3D block. + * + * Note that formats are stored from C3 to C0. */ +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), + }; + + desc = util_format_description(format); + + /* Specifies how the shader output is written to the fog unit. */ + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + /* The gamma correction causes precision loss so we need + * higher precision to maintain reasonable quality. + * It has nothing to do with the colorbuffer format. */ + modifier |= R300_US_OUT_FMT_C4_10_GAMMA; + } else if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) { + if (desc->channel[0].size == 32) { + modifier |= R300_US_OUT_FMT_C4_32_FP; + } else { + modifier |= R300_US_OUT_FMT_C4_16_FP; + } + } else { + if (desc->channel[0].size == 16) { + modifier |= R300_US_OUT_FMT_C4_16; + } else { + /* C4_8 seems to be used for the formats whose pixel size + * is <= 32 bits. */ + modifier |= R300_US_OUT_FMT_C4_8; + } + } + + /* Add sign. */ + for (i = 0; i < 4; i++) + if (desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED) { + modifier |= sign_bit[i]; + } + + /* Add swizzles and return. */ + switch (format) { + /* 8-bit outputs. + * COLORFORMAT_I8 stores the C2 component. */ + case PIPE_FORMAT_A8_UNORM: + return modifier | R300_C2_SEL_A; + case PIPE_FORMAT_I8_UNORM: + case PIPE_FORMAT_L8_UNORM: + case PIPE_FORMAT_L8_SRGB: + case PIPE_FORMAT_R8_UNORM: + case PIPE_FORMAT_R8_SNORM: + return modifier | R300_C2_SEL_R; + + /* ARGB 32-bit outputs. */ + case PIPE_FORMAT_B5G6R5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8A8_SRGB: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8X8_SRGB: + return modifier | + R300_C0_SEL_B | R300_C1_SEL_G | + R300_C2_SEL_R | R300_C3_SEL_A; + + /* BGRA 32-bit outputs. */ + case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_A8R8G8B8_SRGB: + case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_X8R8G8B8_SRGB: + return modifier | + R300_C0_SEL_A | R300_C1_SEL_R | + R300_C2_SEL_G | R300_C3_SEL_B; + + /* RGBA 32-bit outputs. */ + case PIPE_FORMAT_A8B8G8R8_UNORM: + case PIPE_FORMAT_R8G8B8A8_SNORM: + case PIPE_FORMAT_A8B8G8R8_SRGB: + case PIPE_FORMAT_X8B8G8R8_UNORM: + case PIPE_FORMAT_X8B8G8R8_SRGB: + return modifier | + R300_C0_SEL_A | R300_C1_SEL_B | + R300_C2_SEL_G | R300_C3_SEL_R; + + /* ABGR 32-bit outputs. */ + case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + case PIPE_FORMAT_R10G10B10A2_UNORM: + /* RGBA high precision outputs (same swizzles as ABGR low precision) */ + case PIPE_FORMAT_R16G16B16A16_UNORM: + case PIPE_FORMAT_R16G16B16A16_SNORM: + //case PIPE_FORMAT_R16G16B16A16_FLOAT: /* not in pipe_format */ + case PIPE_FORMAT_R32G32B32A32_FLOAT: + return modifier | + R300_C0_SEL_R | R300_C1_SEL_G | + R300_C2_SEL_B | R300_C3_SEL_A; + + default: + return ~0; /* Unsupported. */ + } +} + +boolean r300_is_colorbuffer_format_supported(enum pipe_format format) +{ + return r300_translate_colorformat(format) != ~0 && + r300_translate_out_fmt(format) != ~0; +} + +boolean r300_is_zs_format_supported(enum pipe_format format) +{ + return r300_translate_zsformat(format) != ~0; +} + +boolean r300_is_sampler_format_supported(enum pipe_format format) +{ + return r300_translate_texformat(format) != ~0; +} + static void r300_setup_texture_state(struct r300_screen* screen, struct r300_texture* tex) { - struct r300_texture_state* state = &tex->state; + struct r300_texture_format_state* state = &tex->state; struct pipe_texture *pt = &tex->tex; + unsigned i; boolean is_r500 = screen->caps->is_r500; + /* Set sampler state. */ state->format0 = R300_TX_WIDTH((pt->width0 - 1) & 0x7ff) | R300_TX_HEIGHT((pt->height0 - 1) & 0x7ff); @@ -83,6 +538,26 @@ static void r300_setup_texture_state(struct r300_screen* screen, struct r300_tex SCREEN_DBG(screen, DBG_TEX, "r300: Set texture state (%dx%d, %d levels)\n", pt->width0, pt->height0, pt->last_level); + + /* Set framebuffer state. */ + if (util_format_is_depth_or_stencil(tex->tex.format)) { + for (i = 0; i <= tex->tex.last_level; i++) { + tex->fb_state.depthpitch[i] = + tex->pitch[i] | + R300_DEPTHMACROTILE(tex->mip_macrotile[i]) | + R300_DEPTHMICROTILE(tex->microtile); + } + tex->fb_state.zb_format = r300_translate_zsformat(tex->tex.format); + } else { + for (i = 0; i <= tex->tex.last_level; i++) { + tex->fb_state.colorpitch[i] = + tex->pitch[i] | + r300_translate_colorformat(tex->tex.format) | + R300_COLOR_TILE(tex->mip_macrotile[i]) | + R300_COLOR_MICROTILE(tex->microtile); + } + tex->fb_state.us_out_fmt = r300_translate_out_fmt(tex->tex.format); + } } void r300_texture_reinterpret_format(struct pipe_screen *screen, @@ -142,18 +617,23 @@ static unsigned r300_texture_get_tile_size(struct r300_texture* tex, /* Return true if macrotiling should be enabled on the miplevel. */ static boolean r300_texture_macro_switch(struct r300_texture *tex, unsigned level, - boolean rv350_mode) + boolean rv350_mode, + int dim) { - unsigned tile_width, width; + unsigned tile, texdim; - tile_width = r300_texture_get_tile_size(tex, TILE_WIDTH, TRUE); - width = u_minify(tex->tex.width0, level); + tile = r300_texture_get_tile_size(tex, dim, TRUE); + if (dim == TILE_WIDTH) { + texdim = u_minify(tex->tex.width0, level); + } else { + texdim = u_minify(tex->tex.height0, level); + } /* See TX_FILTER1_n.MACRO_SWITCH. */ if (rv350_mode) { - return width >= tile_width; + return texdim >= tile; } else { - return width > tile_width; + return texdim > tile; } } @@ -217,9 +697,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->mip_macrotile[i] = (tex->macrotile == R300_BUFFER_TILED && - r300_texture_macro_switch(tex, i, rv350_mode)) ? - R300_BUFFER_TILED : R300_BUFFER_LINEAR; + tex->mip_macrotile[i] = + (tex->macrotile == R300_BUFFER_TILED && + r300_texture_macro_switch(tex, i, rv350_mode, TILE_WIDTH)) ? + R300_BUFFER_TILED : R300_BUFFER_LINEAR; stride = r300_texture_get_stride(screen, tex, i); nblocksy = r300_texture_get_nblocksy(tex, i); @@ -249,10 +730,46 @@ static void r300_setup_flags(struct r300_texture* tex) !util_is_power_of_two(tex->tex.height0); } +static void r300_setup_tiling(struct pipe_screen *screen, + struct r300_texture *tex) +{ + enum pipe_format format = tex->tex.format; + boolean rv350_mode = r300_screen(screen)->caps->family >= CHIP_FAMILY_RV350; + + if (util_format_is_compressed(format)) { + return; + } + + if (tex->tex.width0 == 1 || + tex->tex.height0 == 1) { + return; + } + + /* Set microtiling. */ + switch (util_format_get_blocksize(format)) { + case 1: + case 4: + tex->microtile = R300_BUFFER_TILED; + break; + + /* XXX Square-tiling doesn't work with kernel older than 2.6.34, + * XXX need to check the DRM version */ + /*case 2: + case 8: + tex->microtile = R300_BUFFER_SQUARETILED; + break;*/ + } + + /* Set macrotiling. */ + if (r300_texture_macro_switch(tex, 0, rv350_mode, TILE_WIDTH) && + r300_texture_macro_switch(tex, 0, rv350_mode, TILE_HEIGHT)) { + tex->macrotile = R300_BUFFER_TILED; + } +} + /* Create a new texture. */ -static struct pipe_texture* - r300_texture_create(struct pipe_screen* screen, - const struct pipe_texture* template) +static struct pipe_texture* r300_texture_create(struct pipe_screen* screen, + const struct pipe_texture* template) { struct r300_texture* tex = CALLOC_STRUCT(r300_texture); struct r300_screen* rscreen = r300_screen(screen); @@ -267,6 +784,9 @@ static struct pipe_texture* tex->tex.screen = screen; r300_setup_flags(tex); + if (!(template->tex_usage & R300_TEXTURE_USAGE_TRANSFER)) { + r300_setup_tiling(screen, tex); + } r300_setup_miptree(rscreen, tex); r300_setup_texture_state(rscreen, tex); @@ -331,14 +851,17 @@ static void r300_tex_surface_destroy(struct pipe_surface* s) FREE(s); } + static struct pipe_texture* - r300_texture_blanket(struct pipe_screen* screen, - const struct pipe_texture* base, - const unsigned* stride, - struct pipe_buffer* buffer) + r300_texture_from_handle(struct pipe_screen* screen, + const struct pipe_texture* base, + struct winsys_handle *whandle) { - struct r300_texture* tex; + struct radeon_winsys* winsys = (struct radeon_winsys*)screen->winsys; struct r300_screen* rscreen = r300_screen(screen); + struct pipe_buffer *buffer; + struct r300_texture* tex; + unsigned stride; /* Support only 2D textures without mipmaps */ if (base->target != PIPE_TEXTURE_2D || @@ -347,6 +870,11 @@ static struct pipe_texture* return NULL; } + buffer = winsys->buffer_from_handle(winsys, screen, whandle, &stride); + if (!buffer) { + return NULL; + } + tex = CALLOC_STRUCT(r300_texture); if (!tex) { return NULL; @@ -356,17 +884,38 @@ static struct pipe_texture* pipe_reference_init(&tex->tex.reference, 1); tex->tex.screen = screen; - tex->stride_override = *stride; - tex->pitch[0] = *stride / util_format_get_blocksize(base->format); + tex->stride_override = stride; + tex->pitch[0] = stride / util_format_get_blocksize(base->format); r300_setup_flags(tex); r300_setup_texture_state(rscreen, tex); - pipe_buffer_reference(&tex->buffer, buffer); + /* one ref already taken */ + tex->buffer = buffer; return (struct pipe_texture*)tex; } +static boolean + r300_texture_get_handle(struct pipe_screen* screen, + struct pipe_texture *texture, + struct winsys_handle *whandle) +{ + struct radeon_winsys* winsys = (struct radeon_winsys*)screen->winsys; + struct r300_texture* tex = (struct r300_texture*)texture; + unsigned stride; + + if (!tex) { + return FALSE; + } + + stride = r300_texture_get_stride(r300_screen(screen), tex, 0); + + winsys->buffer_get_handle(winsys, tex->buffer, stride, whandle); + + return TRUE; +} + static struct pipe_video_surface * r300_video_surface_create(struct pipe_screen *screen, enum pipe_video_chroma_format chroma_format, @@ -390,7 +939,7 @@ r300_video_surface_create(struct pipe_screen *screen, memset(&template, 0, sizeof(struct pipe_texture)); template.target = PIPE_TEXTURE_2D; - template.format = PIPE_FORMAT_X8R8G8B8_UNORM; + template.format = PIPE_FORMAT_B8G8R8X8_UNORM; template.last_level = 0; template.width0 = util_next_power_of_two(width); template.height0 = util_next_power_of_two(height); @@ -418,30 +967,13 @@ static void r300_video_surface_destroy(struct pipe_video_surface *vsfc) void r300_init_screen_texture_functions(struct pipe_screen* screen) { screen->texture_create = r300_texture_create; + screen->texture_from_handle = r300_texture_from_handle; + screen->texture_get_handle = r300_texture_get_handle; screen->texture_destroy = r300_texture_destroy; screen->get_tex_surface = r300_get_tex_surface; screen->tex_surface_destroy = r300_tex_surface_destroy; - screen->texture_blanket = r300_texture_blanket; screen->video_surface_create = r300_video_surface_create; screen->video_surface_destroy= r300_video_surface_destroy; } -boolean r300_get_texture_buffer(struct pipe_screen* screen, - struct pipe_texture* texture, - struct pipe_buffer** buffer, - unsigned* stride) -{ - struct r300_texture* tex = (struct r300_texture*)texture; - if (!tex) { - return FALSE; - } - - pipe_buffer_reference(buffer, tex->buffer); - - if (stride) { - *stride = r300_texture_get_stride(r300_screen(screen), tex, 0); - } - - return TRUE; -} diff --git a/src/gallium/drivers/r300/r300_texture.h b/src/gallium/drivers/r300/r300_texture.h index b9c3ab80932..138b62784e6 100644 --- a/src/gallium/drivers/r300/r300_texture.h +++ b/src/gallium/drivers/r300/r300_texture.h @@ -42,92 +42,11 @@ void r300_texture_reinterpret_format(struct pipe_screen *screen, struct pipe_texture *tex, enum pipe_format new_format); -/* Translate a pipe_format into a useful texture format for sampling. - * - * R300_EASY_TX_FORMAT swizzles the texture. - * Note the signature of R300_EASY_TX_FORMAT: - * R300_EASY_TX_FORMAT(B, G, R, A, FORMAT); - * - * The FORMAT specifies how the texture sampler will treat the texture, and - * makes available X, Y, Z, W, ZERO, and ONE for swizzling. */ -static INLINE uint32_t r300_translate_texformat(enum pipe_format format) -{ - switch (format) { - /* X8 */ - case PIPE_FORMAT_A8_UNORM: - return R300_EASY_TX_FORMAT(ZERO, ZERO, ZERO, X, X8); - case PIPE_FORMAT_I8_UNORM: - return R300_EASY_TX_FORMAT(X, X, X, X, X8); - case PIPE_FORMAT_L8_UNORM: - return R300_EASY_TX_FORMAT(X, X, X, ONE, X8); - case PIPE_FORMAT_L8_SRGB: - return R300_EASY_TX_FORMAT(X, X, X, ONE, X8) | - R300_TX_FORMAT_GAMMA; - /* X16 */ - case PIPE_FORMAT_A4R4G4B4_UNORM: - return R300_EASY_TX_FORMAT(X, Y, Z, W, W4Z4Y4X4); - case PIPE_FORMAT_R16_UNORM: - case PIPE_FORMAT_Z16_UNORM: - return R300_EASY_TX_FORMAT(X, X, X, X, X16); - case PIPE_FORMAT_R16_SNORM: - return R300_EASY_TX_FORMAT(X, X, X, X, X16) | - R300_TX_FORMAT_SIGNED; - /* Z5Y6X5 */ - case PIPE_FORMAT_R5G6B5_UNORM: - return R300_EASY_TX_FORMAT(X, Y, Z, ONE, Z5Y6X5); - /* W1Z5Y5X5*/ - case PIPE_FORMAT_A1R5G5B5_UNORM: - return R300_EASY_TX_FORMAT(X, Y, Z, W, W1Z5Y5X5); - /* Y8X8 */ - case PIPE_FORMAT_A8L8_UNORM: - return R300_EASY_TX_FORMAT(X, X, X, Y, Y8X8); - case PIPE_FORMAT_A8L8_SRGB: - return R300_EASY_TX_FORMAT(X, X, X, Y, Y8X8) | - R300_TX_FORMAT_GAMMA; - /* W8Z8Y8X8 */ - case PIPE_FORMAT_A8R8G8B8_UNORM: - return R300_EASY_TX_FORMAT(X, Y, Z, W, W8Z8Y8X8); - case PIPE_FORMAT_R8G8B8A8_UNORM: - return R300_EASY_TX_FORMAT(Y, Z, W, X, W8Z8Y8X8); - case PIPE_FORMAT_X8R8G8B8_UNORM: - return R300_EASY_TX_FORMAT(X, Y, Z, ONE, W8Z8Y8X8); - case PIPE_FORMAT_R8G8B8X8_UNORM: - return R300_EASY_TX_FORMAT(Y, Z, ONE, X, W8Z8Y8X8); - case PIPE_FORMAT_A8R8G8B8_SRGB: - return R300_EASY_TX_FORMAT(X, Y, Z, W, W8Z8Y8X8) | - R300_TX_FORMAT_GAMMA; - case PIPE_FORMAT_R8G8B8A8_SRGB: - return R300_EASY_TX_FORMAT(Y, Z, W, X, W8Z8Y8X8) | - R300_TX_FORMAT_GAMMA; - /* DXT1 */ - case PIPE_FORMAT_DXT1_RGB: - return R300_EASY_TX_FORMAT(X, Y, Z, ONE, DXT1); - case PIPE_FORMAT_DXT1_RGBA: - return R300_EASY_TX_FORMAT(X, Y, Z, W, DXT1); - /* DXT3 */ - case PIPE_FORMAT_DXT3_RGBA: - return R300_EASY_TX_FORMAT(X, Y, Z, W, DXT3); - /* DXT5 */ - case PIPE_FORMAT_DXT5_RGBA: - return R300_EASY_TX_FORMAT(Y, Z, W, X, DXT5); - /* YVYU422 */ - case PIPE_FORMAT_YCBCR: - return R300_EASY_TX_FORMAT(X, Y, Z, ONE, YVYU422) | - R300_TX_FORMAT_YUV_TO_RGB; - /* W24_FP */ - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: - return R300_EASY_TX_FORMAT(X, X, X, X, W24_FP); +boolean r300_is_colorbuffer_format_supported(enum pipe_format format); - default: - debug_printf("r300: Implementation error: " - "Got unsupported texture format %s in %s\n", - util_format_name(format), __FUNCTION__); - assert(0); - break; - } - return 0; -} +boolean r300_is_zs_format_supported(enum pipe_format format); + +boolean r300_is_sampler_format_supported(enum pipe_format format); struct r300_video_surface { @@ -141,13 +60,11 @@ r300_video_surface(struct pipe_video_surface *pvs) return (struct r300_video_surface *)pvs; } -#ifndef R300_WINSYS_H - +/* Used internally for texture_is_referenced() + */ boolean r300_get_texture_buffer(struct pipe_screen* screen, struct pipe_texture* texture, struct pipe_buffer** buffer, unsigned* stride); -#endif /* R300_WINSYS_H */ - #endif /* R300_TEXTURE_H */ diff --git a/src/gallium/drivers/r300/r300_transfer.c b/src/gallium/drivers/r300/r300_transfer.c new file mode 100644 index 00000000000..ec89681a3c0 --- /dev/null +++ b/src/gallium/drivers/r300/r300_transfer.c @@ -0,0 +1,270 @@ +/* + * 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. */ + +#include "r300_context.h" +#include "r300_transfer.h" +#include "r300_texture.h" +#include "r300_screen.h" + +#include "util/u_memory.h" +#include "util/u_format.h" + +struct r300_transfer { + /* Parent class */ + struct pipe_transfer transfer; + + /* Pipe context. */ + struct pipe_context *ctx; + + /* Parameters of get_tex_transfer. */ + unsigned x, y, level, zslice, face; + + /* Offset from start of buffer. */ + unsigned offset; + + /* Detiled texture. */ + struct r300_texture *detiled_texture; + + /* Transfer and format flags. */ + unsigned buffer_usage, render_target_usage; +}; + +/* Convenience cast wrapper. */ +static INLINE struct r300_transfer* +r300_transfer(struct pipe_transfer* transfer) +{ + return (struct r300_transfer*)transfer; +} + +/* Copy from a tiled texture to a detiled one. */ +static void r300_copy_from_tiled_texture(struct pipe_context *ctx, + struct r300_transfer *r300transfer) +{ + struct pipe_screen *screen = ctx->screen; + struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer; + struct pipe_texture *tex = transfer->texture; + struct pipe_surface *src, *dst; + + src = screen->get_tex_surface(screen, tex, r300transfer->face, + r300transfer->level, r300transfer->zslice, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_PIXEL); + + dst = screen->get_tex_surface(screen, &r300transfer->detiled_texture->tex, + 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_PIXEL | + r300transfer->buffer_usage); + + ctx->surface_copy(ctx, dst, 0, 0, src, r300transfer->x, r300transfer->y, + transfer->width, transfer->height); + + pipe_surface_reference(&src, NULL); + pipe_surface_reference(&dst, NULL); +} + +/* Copy a detiled texture to a tiled one. */ +static void r300_copy_into_tiled_texture(struct pipe_context *ctx, + struct r300_transfer *r300transfer) +{ + struct pipe_screen *screen = ctx->screen; + struct pipe_transfer *transfer = (struct pipe_transfer*)r300transfer; + struct pipe_texture *tex = transfer->texture; + struct pipe_surface *src, *dst; + + src = screen->get_tex_surface(screen, &r300transfer->detiled_texture->tex, + 0, 0, 0, + PIPE_BUFFER_USAGE_GPU_READ | + PIPE_BUFFER_USAGE_PIXEL); + + dst = screen->get_tex_surface(screen, tex, r300transfer->face, + r300transfer->level, r300transfer->zslice, + PIPE_BUFFER_USAGE_GPU_WRITE | + PIPE_BUFFER_USAGE_PIXEL); + + /* XXX this flush prevents the following DRM error from occuring: + * [drm:radeon_cs_ioctl] *ERROR* Failed to parse relocation ! + * Reproducible with perf/copytex. */ + ctx->flush(ctx, 0, NULL); + + ctx->surface_copy(ctx, dst, r300transfer->x, r300transfer->y, src, 0, 0, + transfer->width, transfer->height); + + /* XXX this flush fixes a few piglit tests (e.g. glean/pixelFormats). */ + ctx->flush(ctx, 0, NULL); + + pipe_surface_reference(&src, NULL); + pipe_surface_reference(&dst, NULL); +} + +static struct pipe_transfer* +r300_get_tex_transfer(struct pipe_screen *screen, + struct pipe_texture *texture, + unsigned face, unsigned level, unsigned zslice, + enum pipe_transfer_usage usage, unsigned x, unsigned y, + unsigned w, unsigned h) +{ + struct r300_texture *tex = (struct r300_texture *)texture; + struct r300_transfer *trans; + struct r300_screen *r300screen = r300_screen(screen); + struct pipe_texture template; + + trans = CALLOC_STRUCT(r300_transfer); + if (trans) { + /* Initialize the transfer object. */ + pipe_texture_reference(&trans->transfer.texture, texture); + trans->transfer.usage = usage; + trans->transfer.width = w; + trans->transfer.height = h; + trans->ctx = r300screen->ctx; + trans->x = x; + trans->y = y; + trans->level = level; + trans->zslice = zslice; + trans->face = face; + + /* If the texture is tiled, we must create a temporary detiled texture + * for this transfer. */ + if (tex->microtile || tex->macrotile) { + trans->buffer_usage = pipe_transfer_buffer_flags(&trans->transfer); + trans->render_target_usage = + util_format_is_depth_or_stencil(texture->format) ? + PIPE_TEXTURE_USAGE_DEPTH_STENCIL : + PIPE_TEXTURE_USAGE_RENDER_TARGET; + + template.target = PIPE_TEXTURE_2D; + template.format = texture->format; + template.width0 = w; + template.height0 = h; + template.depth0 = 0; + template.last_level = 0; + template.nr_samples = 0; + template.tex_usage = PIPE_TEXTURE_USAGE_DYNAMIC | + R300_TEXTURE_USAGE_TRANSFER; + + /* For texture reading, the temporary (detiled) texture is used as + * a render target when blitting from a tiled texture. */ + if (usage & PIPE_TRANSFER_READ) { + template.tex_usage |= trans->render_target_usage; + } + /* For texture writing, the temporary texture is used as a sampler + * when blitting into a tiled texture. */ + if (usage & PIPE_TRANSFER_WRITE) { + template.tex_usage |= PIPE_TEXTURE_USAGE_SAMPLER; + } + + /* Create the temporary texture. */ + trans->detiled_texture = + (struct r300_texture*)screen->texture_create(screen, &template); + assert(!trans->detiled_texture->microtile && + !trans->detiled_texture->macrotile); + + /* Set the stride. + * Parameters x, y, level, zslice, and face remain zero. */ + trans->transfer.stride = + r300_texture_get_stride(r300screen, trans->detiled_texture, 0); + + if (usage & PIPE_TRANSFER_READ) { + /* We cannot map a tiled texture directly because the data is + * in a different order, therefore we do detiling using a blit. */ + r300_copy_from_tiled_texture(r300screen->ctx, trans); + } + } else { + trans->transfer.x = x; + trans->transfer.y = y; + trans->transfer.stride = + r300_texture_get_stride(r300screen, tex, level); + trans->transfer.level = level; + trans->transfer.zslice = zslice; + trans->transfer.face = face; + trans->offset = r300_texture_get_offset(tex, level, zslice, face); + } + } + return &trans->transfer; +} + +static void r300_tex_transfer_destroy(struct pipe_transfer *trans) +{ + struct r300_transfer *r300transfer = r300_transfer(trans); + + if (r300transfer->detiled_texture) { + if (trans->usage & PIPE_TRANSFER_WRITE) { + r300_copy_into_tiled_texture(r300transfer->ctx, r300transfer); + } + + pipe_texture_reference( + (struct pipe_texture**)&r300transfer->detiled_texture, NULL); + } + pipe_texture_reference(&trans->texture, NULL); + FREE(trans); +} + +static void* r300_transfer_map(struct pipe_screen *screen, + struct pipe_transfer *transfer) +{ + struct r300_transfer *r300transfer = r300_transfer(transfer); + struct r300_texture *tex = (struct r300_texture*)transfer->texture; + char *map; + enum pipe_format format = tex->tex.format; + + if (r300transfer->detiled_texture) { + /* The detiled texture is of the same size as the region being mapped + * (no offset needed). */ + return pipe_buffer_map(screen, + r300transfer->detiled_texture->buffer, + pipe_transfer_buffer_flags(transfer)); + } else { + /* Tiling is disabled. */ + map = pipe_buffer_map(screen, tex->buffer, + pipe_transfer_buffer_flags(transfer)); + + if (!map) { + return NULL; + } + + return map + r300_transfer(transfer)->offset + + transfer->y / util_format_get_blockheight(format) * transfer->stride + + transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + } +} + +static void r300_transfer_unmap(struct pipe_screen *screen, + struct pipe_transfer *transfer) +{ + struct r300_transfer *r300transfer = r300_transfer(transfer); + struct r300_texture *tex = (struct r300_texture*)transfer->texture; + + if (r300transfer->detiled_texture) { + pipe_buffer_unmap(screen, r300transfer->detiled_texture->buffer); + } else { + pipe_buffer_unmap(screen, tex->buffer); + } +} + +void r300_init_screen_transfer_functions(struct pipe_screen *screen) +{ + screen->get_tex_transfer = r300_get_tex_transfer; + screen->tex_transfer_destroy = r300_tex_transfer_destroy; + screen->transfer_map = r300_transfer_map; + screen->transfer_unmap = r300_transfer_unmap; +} diff --git a/src/gallium/drivers/r300/r300_transfer.h b/src/gallium/drivers/r300/r300_transfer.h new file mode 100644 index 00000000000..60d1d3dc85c --- /dev/null +++ b/src/gallium/drivers/r300/r300_transfer.h @@ -0,0 +1,31 @@ +/* + * 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_TRANSFER +#define R300_TRANSFER + +#include "pipe/p_screen.h" + +void r300_init_screen_transfer_functions(struct pipe_screen *screen); + +#endif diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c index a6786c321c6..379939ac750 100644 --- a/src/gallium/drivers/r300/r300_vs.c +++ b/src/gallium/drivers/r300/r300_vs.c @@ -89,95 +89,41 @@ static void r300_shader_read_vs_outputs( assert(0); } } + + /* WPOS is a straight copy of POSITION and it's always emitted. */ + vs_outputs->wpos = i; } -static void r300_shader_vap_output_fmt(struct r300_vertex_shader* vs) +/* This function sets up: + * - VAP mapping, which maps VS registers to output semantics and + * at the same time it indicates which attributes are enabled and should + * be rasterized. + * - Stream mapping to VS outputs if TCL is not present. */ +static void r300_init_vs_output_mapping(struct r300_vertex_shader* vs) { struct r300_shader_semantics* vs_outputs = &vs->outputs; - uint32_t* hwfmt = vs->hwfmt; - int i, gen_count; + struct r300_vap_output_state *vap_out = &vs->vap_out; + int *stream_loc = vs->stream_loc_notcl; + int i, gen_count, tabi = 0; boolean any_bcolor_used = vs_outputs->bcolor[0] != ATTR_UNUSED || vs_outputs->bcolor[1] != ATTR_UNUSED; - /* Do the actual vertex_info setup. - * - * vertex_info has four uints of hardware-specific data in it. - * vinfo.hwfmt[0] is R300_VAP_VTX_STATE_CNTL - * vinfo.hwfmt[1] is R300_VAP_VSM_VTX_ASSM - * vinfo.hwfmt[2] is R300_VAP_OUTPUT_VTX_FMT_0 - * vinfo.hwfmt[3] is R300_VAP_OUTPUT_VTX_FMT_1 */ - - hwfmt[0] = 0x5555; /* XXX this is classic Mesa bonghits */ + vap_out->vap_vtx_state_cntl = 0x5555; /* XXX this is classic Mesa bonghits */ /* Position. */ if (vs_outputs->pos != ATTR_UNUSED) { - hwfmt[1] |= R300_INPUT_CNTL_POS; - hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; + vap_out->vap_vsm_vtx_assm |= R300_INPUT_CNTL_POS; + vap_out->vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; + + stream_loc[tabi++] = 0; } else { assert(0); } /* Point size. */ if (vs_outputs->psize != ATTR_UNUSED) { - hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT; - } - - /* Colors. */ - for (i = 0; i < ATTR_COLOR_COUNT; i++) { - if (vs_outputs->color[i] != ATTR_UNUSED || any_bcolor_used || - vs_outputs->color[1] != ATTR_UNUSED) { - hwfmt[1] |= R300_INPUT_CNTL_COLOR; - hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i; - } - } - - /* Back-face colors. */ - if (any_bcolor_used) { - for (i = 0; i < ATTR_COLOR_COUNT; i++) { - hwfmt[1] |= R300_INPUT_CNTL_COLOR; - hwfmt[2] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << (2+i); - } - } + vap_out->vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT; - /* Texture coordinates. */ - gen_count = 0; - for (i = 0; i < ATTR_GENERIC_COUNT; i++) { - if (vs_outputs->generic[i] != ATTR_UNUSED) { - hwfmt[1] |= (R300_INPUT_CNTL_TC0 << gen_count); - hwfmt[3] |= (4 << (3 * gen_count)); - gen_count++; - } - } - - /* Fog coordinates. */ - if (vs_outputs->fog != ATTR_UNUSED) { - hwfmt[1] |= (R300_INPUT_CNTL_TC0 << gen_count); - hwfmt[3] |= (4 << (3 * gen_count)); - gen_count++; - } - - /* XXX magic */ - assert(gen_count <= 8); - - /* WPOS. */ - vs->wpos_tex_output = gen_count; -} - -/* Sets up stream mapping to equivalent VS outputs if TCL is bypassed - * or isn't present. */ -static void r300_stream_locations_notcl( - struct r300_shader_semantics* vs_outputs, - int* stream_loc) -{ - int i, tabi = 0, gen_count; - boolean any_bcolor_used = vs_outputs->bcolor[0] != ATTR_UNUSED || - vs_outputs->bcolor[1] != ATTR_UNUSED; - - /* Position. */ - stream_loc[tabi++] = 0; - - /* Point size. */ - if (vs_outputs->psize != ATTR_UNUSED) { stream_loc[tabi++] = 1; } @@ -185,6 +131,9 @@ static void r300_stream_locations_notcl( for (i = 0; i < ATTR_COLOR_COUNT; i++) { if (vs_outputs->color[i] != ATTR_UNUSED || any_bcolor_used || vs_outputs->color[1] != ATTR_UNUSED) { + vap_out->vap_vsm_vtx_assm |= R300_INPUT_CNTL_COLOR; + vap_out->vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << i; + stream_loc[tabi++] = 2 + i; } } @@ -192,6 +141,9 @@ static void r300_stream_locations_notcl( /* Back-face colors. */ if (any_bcolor_used) { for (i = 0; i < ATTR_COLOR_COUNT; i++) { + vap_out->vap_vsm_vtx_assm |= R300_INPUT_CNTL_COLOR; + vap_out->vap_out_vtx_fmt[0] |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << (2+i); + stream_loc[tabi++] = 4 + i; } } @@ -200,6 +152,9 @@ static void r300_stream_locations_notcl( gen_count = 0; for (i = 0; i < ATTR_GENERIC_COUNT; i++) { if (vs_outputs->generic[i] != ATTR_UNUSED) { + vap_out->vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << gen_count); + vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * gen_count)); + assert(tabi < 16); stream_loc[tabi++] = 6 + gen_count; gen_count++; @@ -208,17 +163,22 @@ static void r300_stream_locations_notcl( /* Fog coordinates. */ if (vs_outputs->fog != ATTR_UNUSED) { + vap_out->vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << gen_count); + vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * gen_count)); + assert(tabi < 16); stream_loc[tabi++] = 6 + gen_count; gen_count++; } + /* XXX magic */ + assert(gen_count <= 8); + /* WPOS. */ - if (vs_outputs->wpos != ATTR_UNUSED) { - assert(tabi < 16); - stream_loc[tabi++] = 6 + gen_count; - gen_count++; - } + vs->wpos_tex_output = gen_count; + + assert(tabi < 16); + stream_loc[tabi++] = 6 + gen_count; for (; tabi < 16;) { stream_loc[tabi++] = -1; @@ -294,26 +254,16 @@ static void set_vertex_inputs_outputs(struct r300_vertex_program_compiler * c) } } -static void r300_insert_wpos(struct r300_vertex_program_compiler* c, - struct r300_shader_semantics* outputs) +void r300_vertex_shader_common_init(struct r300_vertex_shader *vs, + const struct pipe_shader_state *shader) { - int i, lastOutput = 0; - - /* Find the max output index. */ - lastOutput = MAX2(lastOutput, outputs->psize); - for (i = 0; i < ATTR_COLOR_COUNT; i++) { - lastOutput = MAX2(lastOutput, outputs->color[i]); - lastOutput = MAX2(lastOutput, outputs->bcolor[i]); - } - for (i = 0; i < ATTR_GENERIC_COUNT; i++) { - lastOutput = MAX2(lastOutput, outputs->generic[i]); - } - lastOutput = MAX2(lastOutput, outputs->fog); + /* Copy state directly into shader. */ + vs->state = *shader; + vs->state.tokens = tgsi_dup_tokens(shader->tokens); + tgsi_scan_shader(shader->tokens, &vs->info); - /* Set WPOS after the last output. */ - lastOutput++; - rc_copy_output(&c->Base, 0, lastOutput); /* out[lastOutput] = out[0]; */ - outputs->wpos = lastOutput; + r300_shader_read_vs_outputs(&vs->info, &vs->outputs); + r300_init_vs_output_mapping(vs); } void r300_translate_vertex_shader(struct r300_context* r300, @@ -322,9 +272,6 @@ void r300_translate_vertex_shader(struct r300_context* r300, struct r300_vertex_program_compiler compiler; struct tgsi_to_rc ttr; - /* Initialize. */ - r300_shader_read_vs_outputs(&vs->info, &vs->outputs); - /* Setup the compiler */ rc_init(&compiler.Base); @@ -348,10 +295,7 @@ void r300_translate_vertex_shader(struct r300_context* r300, compiler.SetHwInputOutput = &set_vertex_inputs_outputs; /* Insert the WPOS output. */ - r300_insert_wpos(&compiler, &vs->outputs); - - r300_shader_vap_output_fmt(vs); - r300_stream_locations_notcl(&vs->outputs, vs->stream_loc_notcl); + rc_copy_output(&compiler.Base, 0, vs->outputs.wpos); /* Invoke the compiler */ r3xx_compile_vertex_program(&compiler); @@ -363,30 +307,29 @@ void r300_translate_vertex_shader(struct r300_context* r300, /* And, finally... */ rc_destroy(&compiler.Base); - vs->translated = TRUE; } boolean r300_vertex_shader_setup_wpos(struct r300_context* r300) { - struct r300_vertex_shader* vs = r300->vs; - int tex_output = r300->vs->wpos_tex_output; + struct r300_vertex_shader* vs = r300->vs_state.state; + struct r300_vap_output_state *vap_out = &vs->vap_out; + int tex_output = vs->wpos_tex_output; uint32_t tex_fmt = R300_INPUT_CNTL_TC0 << tex_output; - uint32_t* hwfmt = vs->hwfmt; if (r300->fs->inputs.wpos != ATTR_UNUSED) { /* Enable WPOS in VAP. */ - if (!(hwfmt[1] & tex_fmt)) { - hwfmt[1] |= tex_fmt; - hwfmt[3] |= (4 << (3 * tex_output)); + if (!(vap_out->vap_vsm_vtx_assm & tex_fmt)) { + vap_out->vap_vsm_vtx_assm |= tex_fmt; + vap_out->vap_out_vtx_fmt[1] |= (4 << (3 * tex_output)); assert(tex_output < 8); return TRUE; } } else { /* Disable WPOS in VAP. */ - if (hwfmt[1] & tex_fmt) { - hwfmt[1] &= ~tex_fmt; - hwfmt[3] &= ~(4 << (3 * tex_output)); + if (vap_out->vap_vsm_vtx_assm & tex_fmt) { + vap_out->vap_vsm_vtx_assm &= ~tex_fmt; + vap_out->vap_out_vtx_fmt[1] &= ~(4 << (3 * tex_output)); return TRUE; } } diff --git a/src/gallium/drivers/r300/r300_vs.h b/src/gallium/drivers/r300/r300_vs.h index 18cfeee3cd4..f6f0b86b683 100644 --- a/src/gallium/drivers/r300/r300_vs.h +++ b/src/gallium/drivers/r300/r300_vs.h @@ -28,6 +28,7 @@ #include "tgsi/tgsi_scan.h" #include "radeon_code.h" +#include "r300_context.h" #include "r300_shader_semantics.h" struct r300_context; @@ -38,7 +39,7 @@ struct r300_vertex_shader { struct tgsi_shader_info info; struct r300_shader_semantics outputs; - uint hwfmt[4]; + struct r300_vap_output_state vap_out; /* Stream locations for SWTCL or if TCL is bypassed. */ int stream_loc_notcl[16]; @@ -46,13 +47,17 @@ struct r300_vertex_shader { /* Output stream location for WPOS. */ int wpos_tex_output; - /* Has this shader been translated yet? */ - boolean translated; - + /* HWTCL-specific. */ /* Machine code (if translated) */ struct r300_vertex_program_code code; + + /* SWTCL-specific. */ + void *draw_vs; }; +void r300_vertex_shader_common_init(struct r300_vertex_shader *vs, + const struct pipe_shader_state *shader); + void r300_translate_vertex_shader(struct r300_context* r300, struct r300_vertex_shader* vs); diff --git a/src/gallium/drivers/r300/r300_winsys.h b/src/gallium/drivers/r300/r300_winsys.h index 40fb8a95ca5..ddf2b790039 100644 --- a/src/gallium/drivers/r300/r300_winsys.h +++ b/src/gallium/drivers/r300/r300_winsys.h @@ -40,11 +40,6 @@ struct radeon_winsys; struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys); -boolean r300_get_texture_buffer(struct pipe_screen* screen, - struct pipe_texture* texture, - struct pipe_buffer** buffer, - unsigned* stride); - #ifdef __cplusplus } #endif diff --git a/src/gallium/drivers/softpipe/sp_prim_vbuf.c b/src/gallium/drivers/softpipe/sp_prim_vbuf.c index 98c08eaffaf..6749243ab41 100644 --- a/src/gallium/drivers/softpipe/sp_prim_vbuf.c +++ b/src/gallium/drivers/softpipe/sp_prim_vbuf.c @@ -264,57 +264,29 @@ sp_vbuf_draw(struct vbuf_render *vbr, const ushort *indices, uint nr) break; case PIPE_PRIM_QUADS: - if (softpipe->rasterizer->flatshade_first) { - for (i = 3; i < nr; i += 4) { - sp_setup_tri( setup_ctx, - get_vert(vertex_buffer, indices[i-2], stride), - get_vert(vertex_buffer, indices[i-1], stride), - get_vert(vertex_buffer, indices[i-3], stride) ); - sp_setup_tri( setup_ctx, - get_vert(vertex_buffer, indices[i-1], stride), - get_vert(vertex_buffer, indices[i-0], stride), - get_vert(vertex_buffer, indices[i-3], stride) ); - } - } - else { - for (i = 3; i < nr; i += 4) { - sp_setup_tri( setup_ctx, + for (i = 3; i < nr; i += 4) { + sp_setup_tri( setup_ctx, get_vert(vertex_buffer, indices[i-3], stride), get_vert(vertex_buffer, indices[i-2], stride), get_vert(vertex_buffer, indices[i-0], stride) ); - sp_setup_tri( setup_ctx, + sp_setup_tri( setup_ctx, get_vert(vertex_buffer, indices[i-2], stride), get_vert(vertex_buffer, indices[i-1], stride), get_vert(vertex_buffer, indices[i-0], stride) ); - } } break; case PIPE_PRIM_QUAD_STRIP: - if (softpipe->rasterizer->flatshade_first) { - for (i = 3; i < nr; i += 2) { - sp_setup_tri( setup_ctx, - get_vert(vertex_buffer, indices[i-0], stride), - get_vert(vertex_buffer, indices[i-1], stride), - get_vert(vertex_buffer, indices[i-3], stride)); - sp_setup_tri( setup_ctx, - get_vert(vertex_buffer, indices[i-2], stride), - get_vert(vertex_buffer, indices[i-0], stride), - get_vert(vertex_buffer, indices[i-3], stride) ); - } - } - else { - for (i = 3; i < nr; i += 2) { - sp_setup_tri( setup_ctx, + for (i = 3; i < nr; i += 2) { + sp_setup_tri( setup_ctx, get_vert(vertex_buffer, indices[i-3], stride), get_vert(vertex_buffer, indices[i-2], stride), get_vert(vertex_buffer, indices[i-0], stride) ); - sp_setup_tri( setup_ctx, + sp_setup_tri( setup_ctx, get_vert(vertex_buffer, indices[i-1], stride), get_vert(vertex_buffer, indices[i-3], stride), get_vert(vertex_buffer, indices[i-0], stride) ); - } } break; @@ -448,56 +420,28 @@ sp_vbuf_draw_arrays(struct vbuf_render *vbr, uint start, uint nr) break; case PIPE_PRIM_QUADS: - if (softpipe->rasterizer->flatshade_first) { - for (i = 3; i < nr; i += 4) { - sp_setup_tri( setup_ctx, - get_vert(vertex_buffer, i-2, stride), - get_vert(vertex_buffer, i-1, stride), - get_vert(vertex_buffer, i-3, stride) ); - sp_setup_tri( setup_ctx, - get_vert(vertex_buffer, i-1, stride), - get_vert(vertex_buffer, i-0, stride), - get_vert(vertex_buffer, i-3, stride) ); - } - } - else { - for (i = 3; i < nr; i += 4) { - sp_setup_tri( setup_ctx, + for (i = 3; i < nr; i += 4) { + sp_setup_tri( setup_ctx, get_vert(vertex_buffer, i-3, stride), get_vert(vertex_buffer, i-2, stride), get_vert(vertex_buffer, i-0, stride) ); - sp_setup_tri( setup_ctx, + sp_setup_tri( setup_ctx, get_vert(vertex_buffer, i-2, stride), get_vert(vertex_buffer, i-1, stride), get_vert(vertex_buffer, i-0, stride) ); - } } break; case PIPE_PRIM_QUAD_STRIP: - if (softpipe->rasterizer->flatshade_first) { - for (i = 3; i < nr; i += 2) { - sp_setup_tri( setup_ctx, - get_vert(vertex_buffer, i-0, stride), - get_vert(vertex_buffer, i-1, stride), - get_vert(vertex_buffer, i-3, stride) ); - sp_setup_tri( setup_ctx, - get_vert(vertex_buffer, i-2, stride), - get_vert(vertex_buffer, i-0, stride), - get_vert(vertex_buffer, i-3, stride) ); - } - } - else { - for (i = 3; i < nr; i += 2) { - sp_setup_tri( setup_ctx, + for (i = 3; i < nr; i += 2) { + sp_setup_tri( setup_ctx, get_vert(vertex_buffer, i-3, stride), get_vert(vertex_buffer, i-2, stride), get_vert(vertex_buffer, i-0, stride) ); - sp_setup_tri( setup_ctx, + sp_setup_tri( setup_ctx, get_vert(vertex_buffer, i-1, stride), get_vert(vertex_buffer, i-3, stride), get_vert(vertex_buffer, i-0, stride) ); - } } break; diff --git a/src/gallium/drivers/softpipe/sp_quad_depth_test.c b/src/gallium/drivers/softpipe/sp_quad_depth_test.c index 499eebd671b..4815a0d49f1 100644 --- a/src/gallium/drivers/softpipe/sp_quad_depth_test.c +++ b/src/gallium/drivers/softpipe/sp_quad_depth_test.c @@ -73,8 +73,8 @@ get_depth_stencil_values( struct depth_data *data, data->bzzzz[j] = tile->data.depth32[y][x]; } break; - case PIPE_FORMAT_X8Z24_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->input.x0 % TILE_SIZE + (j & 1); int y = quad->input.y0 % TILE_SIZE + (j >> 1); @@ -82,8 +82,8 @@ get_depth_stencil_values( struct depth_data *data, data->stencilVals[j] = tile->data.depth32[y][x] >> 24; } break; - case PIPE_FORMAT_Z24X8_UNORM: - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->input.x0 % TILE_SIZE + (j & 1); int y = quad->input.y0 % TILE_SIZE + (j >> 1); @@ -146,8 +146,8 @@ convert_quad_depth( struct depth_data *data, } } break; - case PIPE_FORMAT_X8Z24_UNORM: - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: { float scale = (float) ((1 << 24) - 1); @@ -156,8 +156,8 @@ convert_quad_depth( struct depth_data *data, } } break; - case PIPE_FORMAT_Z24X8_UNORM: - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: { float scale = (float) ((1 << 24) - 1); @@ -189,7 +189,7 @@ write_depth_stencil_values( struct depth_data *data, tile->data.depth16[y][x] = (ushort) data->bzzzz[j]; } break; - case PIPE_FORMAT_X8Z24_UNORM: + case PIPE_FORMAT_Z24X8_UNORM: case PIPE_FORMAT_Z32_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->input.x0 % TILE_SIZE + (j & 1); @@ -197,21 +197,21 @@ write_depth_stencil_values( struct depth_data *data, tile->data.depth32[y][x] = data->bzzzz[j]; } break; - case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_Z24S8_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->input.x0 % TILE_SIZE + (j & 1); int y = quad->input.y0 % TILE_SIZE + (j >> 1); tile->data.depth32[y][x] = (data->stencilVals[j] << 24) | data->bzzzz[j]; } break; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->input.x0 % TILE_SIZE + (j & 1); int y = quad->input.y0 % TILE_SIZE + (j >> 1); tile->data.depth32[y][x] = (data->bzzzz[j] << 8) | data->stencilVals[j]; } break; - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: for (j = 0; j < QUAD_SIZE; j++) { int x = quad->input.x0 % TILE_SIZE + (j & 1); int y = quad->input.y0 % TILE_SIZE + (j >> 1); @@ -728,9 +728,14 @@ depth_test_quads_fallback(struct quad_stage *qs, qs->next->run(qs->next, quads, nr); } -/* XXX: this function assumes setup function actually emits linear - * spans of quads. It seems a lot more natural to do (early) - * depth-testing on spans rather than quads. + +/** + * Special-case Z testing for 16-bit Zbuffer, PIPE_FUNC_LESS and + * Z buffer writes enabled. + * + * NOTE: there's no guarantee that the quads are sequentially side by + * side. The fragment shader may have culled some quads, etc. Sliver + * triangles may generate non-sequential quads. */ static void depth_interp_z16_less_write(struct quad_stage *qs, @@ -747,25 +752,33 @@ depth_interp_z16_less_write(struct quad_stage *qs, const float z0 = quads[0]->posCoef->a0[2] + dzdx * fx + dzdy * fy; struct softpipe_cached_tile *tile; ushort (*depth16)[TILE_SIZE]; - ushort idepth[4], depth_step; + ushort init_idepth[4], idepth[4], depth_step; const float scale = 65535.0; - idepth[0] = (ushort)((z0) * scale); - idepth[1] = (ushort)((z0 + dzdx) * scale); - idepth[2] = (ushort)((z0 + dzdy) * scale); - idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale); + /* compute scaled depth of the four pixels in first quad */ + init_idepth[0] = (ushort)((z0) * scale); + init_idepth[1] = (ushort)((z0 + dzdx) * scale); + init_idepth[2] = (ushort)((z0 + dzdy) * scale); + init_idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale); - depth_step = (ushort)(dzdx * 2 * scale); + depth_step = (ushort)(dzdx * scale); tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, ix, iy); - depth16 = (ushort (*)[TILE_SIZE]) - &tile->data.depth16[iy % TILE_SIZE][ix % TILE_SIZE]; - for (i = 0; i < nr; i++) { - unsigned outmask = quads[i]->inout.mask; + const unsigned outmask = quads[i]->inout.mask; + const int dx = quads[i]->input.x0 - ix; unsigned mask = 0; - + + /* compute depth for this quad */ + idepth[0] = init_idepth[0] + dx * depth_step; + idepth[1] = init_idepth[1] + dx * depth_step; + idepth[2] = init_idepth[2] + dx * depth_step; + idepth[3] = init_idepth[3] + dx * depth_step; + + depth16 = (ushort (*)[TILE_SIZE]) + &tile->data.depth16[iy % TILE_SIZE][(ix + dx)% TILE_SIZE]; + if ((outmask & 1) && idepth[0] < depth16[0][0]) { depth16[0][0] = idepth[0]; mask |= (1 << 0); @@ -786,13 +799,6 @@ depth_interp_z16_less_write(struct quad_stage *qs, mask |= (1 << 3); } - idepth[0] += depth_step; - idepth[1] += depth_step; - idepth[2] += depth_step; - idepth[3] += depth_step; - - depth16 = (ushort (*)[TILE_SIZE]) &depth16[0][2]; - quads[i]->inout.mask = mask; if (quads[i]->inout.mask) quads[pass++] = quads[i]; @@ -804,6 +810,14 @@ depth_interp_z16_less_write(struct quad_stage *qs, } +/** + * Special-case Z testing for 16-bit Zbuffer, PIPE_FUNC_LEQUAL and + * Z buffer writes enabled. + * + * NOTE: there's no guarantee that the quads are sequentially side by + * side. The fragment shader may have culled some quads, etc. Sliver + * triangles may generate non-sequential quads. + */ static void depth_interp_z16_lequal_write(struct quad_stage *qs, struct quad_header *quads[], @@ -819,25 +833,33 @@ depth_interp_z16_lequal_write(struct quad_stage *qs, const float z0 = quads[0]->posCoef->a0[2] + dzdx * fx + dzdy * fy; struct softpipe_cached_tile *tile; ushort (*depth16)[TILE_SIZE]; - ushort idepth[4], depth_step; + ushort init_idepth[4], idepth[4], depth_step; const float scale = 65535.0; - idepth[0] = (ushort)((z0) * scale); - idepth[1] = (ushort)((z0 + dzdx) * scale); - idepth[2] = (ushort)((z0 + dzdy) * scale); - idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale); + /* compute scaled depth of the four pixels in first quad */ + init_idepth[0] = (ushort)((z0) * scale); + init_idepth[1] = (ushort)((z0 + dzdx) * scale); + init_idepth[2] = (ushort)((z0 + dzdy) * scale); + init_idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale); - depth_step = (ushort)(dzdx * 2 * scale); + depth_step = (ushort)(dzdx * scale); tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, ix, iy); - depth16 = (ushort (*)[TILE_SIZE]) - &tile->data.depth16[iy % TILE_SIZE][ix % TILE_SIZE]; - for (i = 0; i < nr; i++) { - unsigned outmask = quads[i]->inout.mask; + const unsigned outmask = quads[i]->inout.mask; + const int dx = quads[i]->input.x0 - ix; unsigned mask = 0; + /* compute depth for this quad */ + idepth[0] = init_idepth[0] + dx * depth_step; + idepth[1] = init_idepth[1] + dx * depth_step; + idepth[2] = init_idepth[2] + dx * depth_step; + idepth[3] = init_idepth[3] + dx * depth_step; + + depth16 = (ushort (*)[TILE_SIZE]) + &tile->data.depth16[iy % TILE_SIZE][(ix + dx)% TILE_SIZE]; + if ((outmask & 1) && idepth[0] <= depth16[0][0]) { depth16[0][0] = idepth[0]; mask |= (1 << 0); @@ -858,11 +880,6 @@ depth_interp_z16_lequal_write(struct quad_stage *qs, mask |= (1 << 3); } - idepth[0] += depth_step; - idepth[1] += depth_step; - idepth[2] += depth_step; - idepth[3] += depth_step; - depth16 = (ushort (*)[TILE_SIZE]) &depth16[0][2]; quads[i]->inout.mask = mask; diff --git a/src/gallium/drivers/softpipe/sp_quad_fs.c b/src/gallium/drivers/softpipe/sp_quad_fs.c index ad04dc2afc3..8ae5a7f028b 100644 --- a/src/gallium/drivers/softpipe/sp_quad_fs.c +++ b/src/gallium/drivers/softpipe/sp_quad_fs.c @@ -65,6 +65,7 @@ quad_shade_stage(struct quad_stage *qs) /** * Execute fragment shader for the four fragments in the quad. + * \return TRUE if quad is alive, FALSE if all four pixels are killed */ static INLINE boolean shade_quad(struct quad_stage *qs, struct quad_header *quad) @@ -98,11 +99,14 @@ coverage_quad(struct quad_stage *qs, struct quad_header *quad) } - +/** + * Shade/write an array of quads + * Called via quad_stage::run() + */ static void shade_quads(struct quad_stage *qs, - struct quad_header *quads[], - unsigned nr) + struct quad_header *quads[], + unsigned nr) { struct quad_shade_stage *qss = quad_shade_stage( qs ); struct softpipe_context *softpipe = qs->softpipe; @@ -116,7 +120,7 @@ shade_quads(struct quad_stage *qs, for (i = 0; i < nr; i++) { if (!shade_quad(qs, quads[i])) - continue; + continue; /* quad totally culled/killed */ if (/*do_coverage*/ 0) coverage_quad( qs, quads[i] ); @@ -129,9 +133,6 @@ shade_quads(struct quad_stage *qs, } - - - /** * Per-primitive (or per-begin?) setup */ diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c index 87415f43404..3405a043c6b 100644 --- a/src/gallium/drivers/softpipe/sp_screen.c +++ b/src/gallium/drivers/softpipe/sp_screen.c @@ -83,11 +83,11 @@ softpipe_get_param(struct pipe_screen *screen, int param) case PIPE_CAP_TEXTURE_SHADOW_MAP: return 1; case PIPE_CAP_MAX_TEXTURE_2D_LEVELS: - return 13; /* max 4Kx4K */ + return SP_MAX_TEXTURE_2D_LEVELS; case PIPE_CAP_MAX_TEXTURE_3D_LEVELS: - return 9; /* max 256x256x256 */ + return SP_MAX_TEXTURE_3D_LEVELS; case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS: - return 13; /* max 4Kx4K */ + return SP_MAX_TEXTURE_2D_LEVELS; case PIPE_CAP_TGSI_CONT_SUPPORTED: return 1; case PIPE_CAP_BLEND_EQUATION_SEPARATE: @@ -152,17 +152,17 @@ softpipe_is_format_supported( struct pipe_screen *screen, switch(format) { case PIPE_FORMAT_L16_UNORM: - case PIPE_FORMAT_YCBCR_REV: - case PIPE_FORMAT_YCBCR: + case PIPE_FORMAT_YUYV: + case PIPE_FORMAT_UYVY: case PIPE_FORMAT_DXT1_RGB: case PIPE_FORMAT_DXT1_RGBA: case PIPE_FORMAT_DXT3_RGBA: case PIPE_FORMAT_DXT5_RGBA: case PIPE_FORMAT_Z32_FLOAT: case PIPE_FORMAT_R8G8_SNORM: - case PIPE_FORMAT_B6UG5SR5S_NORM: - case PIPE_FORMAT_X8UB8UG8SR8S_NORM: - case PIPE_FORMAT_A8B8G8R8_SNORM: + case PIPE_FORMAT_R5SG5SB6U_NORM: + case PIPE_FORMAT_R8SG8SB8UX8U_NORM: + case PIPE_FORMAT_R8G8B8A8_SNORM: case PIPE_FORMAT_NONE: return FALSE; default: diff --git a/src/gallium/drivers/softpipe/sp_setup.c b/src/gallium/drivers/softpipe/sp_setup.c index b8590a8cc2c..85966bc5e49 100644 --- a/src/gallium/drivers/softpipe/sp_setup.c +++ b/src/gallium/drivers/softpipe/sp_setup.c @@ -211,11 +211,11 @@ static void flush_spans( struct setup_context *setup ) const int xright1 = setup->span.right[1]; struct quad_stage *pipe = setup->softpipe->quad.first; - - int minleft = block_x(MIN2(xleft0, xleft1)); - int maxright = MAX2(xright0, xright1); + const int minleft = block_x(MIN2(xleft0, xleft1)); + const int maxright = MAX2(xright0, xright1); int x; + /* process quads in horizontal chunks of 16 */ for (x = minleft; x < maxright; x += step) { unsigned skip_left0 = CLAMP(xleft0 - x, 0, step); unsigned skip_left1 = CLAMP(xleft1 - x, 0, step); diff --git a/src/gallium/drivers/softpipe/sp_tex_sample.c b/src/gallium/drivers/softpipe/sp_tex_sample.c index ecd6b39863c..ef7ccf41898 100644 --- a/src/gallium/drivers/softpipe/sp_tex_sample.c +++ b/src/gallium/drivers/softpipe/sp_tex_sample.c @@ -55,7 +55,7 @@ static INLINE float frac(float f) { - return f - util_ifloor(f); + return f - floorf(f); } @@ -201,11 +201,9 @@ wrap_nearest_mirror_repeat(const float s[4], unsigned size, int icoord[4]) const float max = 1.0F - min; for (ch = 0; ch < 4; ch++) { const int flr = util_ifloor(s[ch]); - float u; + float u = frac(s[ch]); if (flr & 1) - u = 1.0F - (s[ch] - (float) flr); - else - u = s[ch] - (float) flr; + u = 1.0F - u; if (u < min) icoord[ch] = 0; else if (u > max) @@ -358,11 +356,9 @@ wrap_linear_mirror_repeat(const float s[4], unsigned size, uint ch; for (ch = 0; ch < 4; ch++) { const int flr = util_ifloor(s[ch]); - float u; + float u = frac(s[ch]); if (flr & 1) - u = 1.0F - (s[ch] - (float) flr); - else - u = s[ch] - (float) flr; + u = 1.0F - u; u = u * size - 0.5F; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; @@ -441,8 +437,7 @@ wrap_linear_mirror_clamp_to_border(const float s[4], unsigned size, /** - * For RECT textures / unnormalized texcoords - * Only a subset of wrap modes supported. + * PIPE_TEX_WRAP_CLAMP for nearest sampling, unnormalized coords. */ static void wrap_nearest_unorm_clamp(const float s[4], unsigned size, int icoord[4]) @@ -456,7 +451,7 @@ wrap_nearest_unorm_clamp(const float s[4], unsigned size, int icoord[4]) /** - * Handles clamp_to_edge and clamp_to_border: + * PIPE_TEX_WRAP_CLAMP_TO_BORDER for nearest sampling, unnormalized coords. */ static void wrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size, @@ -464,14 +459,27 @@ wrap_nearest_unorm_clamp_to_border(const float s[4], unsigned size, { uint ch; for (ch = 0; ch < 4; ch++) { + icoord[ch]= util_ifloor( CLAMP(s[ch], -0.5F, (float) size + 0.5F) ); + } +} + + +/** + * PIPE_TEX_WRAP_CLAMP_TO_EDGE for nearest sampling, unnormalized coords. + */ +static void +wrap_nearest_unorm_clamp_to_edge(const float s[4], unsigned size, + int icoord[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { icoord[ch]= util_ifloor( CLAMP(s[ch], 0.5F, (float) size - 0.5F) ); } } /** - * For RECT textures / unnormalized texcoords. - * Only a subset of wrap modes supported. + * PIPE_TEX_WRAP_CLAMP for linear sampling, unnormalized coords. */ static void wrap_linear_unorm_clamp(const float s[4], unsigned size, @@ -488,13 +496,36 @@ wrap_linear_unorm_clamp(const float s[4], unsigned size, } +/** + * PIPE_TEX_WRAP_CLAMP_TO_BORDER for linear sampling, unnormalized coords. + */ static void wrap_linear_unorm_clamp_to_border(const float s[4], unsigned size, int icoord0[4], int icoord1[4], float w[4]) { uint ch; for (ch = 0; ch < 4; ch++) { - float u = CLAMP(s[ch], 0.5F, (float) size - 0.5F); + float u = CLAMP(s[ch], -0.5F, (float) size + 0.5F); + u -= 0.5F; + icoord0[ch] = util_ifloor(u); + icoord1[ch] = icoord0[ch] + 1; + if (icoord1[ch] > (int) size - 1) + icoord1[ch] = size - 1; + w[ch] = frac(u); + } +} + + +/** + * PIPE_TEX_WRAP_CLAMP_TO_EDGE for linear sampling, unnormalized coords. + */ +static void +wrap_linear_unorm_clamp_to_edge(const float s[4], unsigned size, + int icoord0[4], int icoord1[4], float w[4]) +{ + uint ch; + for (ch = 0; ch < 4; ch++) { + float u = CLAMP(s[ch], +0.5F, (float) size - 0.5F); u -= 0.5F; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; @@ -1711,6 +1742,7 @@ get_nearest_unorm_wrap(unsigned mode) case PIPE_TEX_WRAP_CLAMP: return wrap_nearest_unorm_clamp; case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return wrap_nearest_unorm_clamp_to_edge; case PIPE_TEX_WRAP_CLAMP_TO_BORDER: return wrap_nearest_unorm_clamp_to_border; default: @@ -1754,6 +1786,7 @@ get_linear_unorm_wrap(unsigned mode) case PIPE_TEX_WRAP_CLAMP: return wrap_linear_unorm_clamp; case PIPE_TEX_WRAP_CLAMP_TO_EDGE: + return wrap_linear_unorm_clamp_to_edge; case PIPE_TEX_WRAP_CLAMP_TO_BORDER: return wrap_linear_unorm_clamp_to_border; default: diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 371c4e20251..c0052359fdc 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -36,6 +36,7 @@ #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/u_simple_screen.h" #include "sp_context.h" #include "sp_texture.h" @@ -91,13 +92,13 @@ softpipe_displaytarget_layout(struct pipe_screen *screen, PIPE_BUFFER_USAGE_GPU_READ_WRITE); unsigned tex_usage = spt->base.tex_usage; - spt->buffer = screen->surface_buffer_create( screen, - spt->base.width0, - spt->base.height0, - spt->base.format, - usage, - tex_usage, - &spt->stride[0]); + spt->buffer = screen->winsys->surface_buffer_create( screen->winsys, + spt->base.width0, + spt->base.height0, + spt->base.format, + usage, + tex_usage, + &spt->stride[0]); return spt->buffer != NULL; } @@ -123,7 +124,8 @@ softpipe_texture_create(struct pipe_screen *screen, util_is_power_of_two(template->depth0)); if (spt->base.tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET | - PIPE_TEXTURE_USAGE_PRIMARY)) { + PIPE_TEXTURE_USAGE_SCANOUT | + PIPE_TEXTURE_USAGE_SHARED)) { if (!softpipe_displaytarget_layout(screen, spt)) goto fail; } @@ -140,38 +142,6 @@ softpipe_texture_create(struct pipe_screen *screen, } -/** - * Create a new pipe_texture which wraps an existing buffer. - */ -static struct pipe_texture * -softpipe_texture_blanket(struct pipe_screen * screen, - const struct pipe_texture *base, - const unsigned *stride, - struct pipe_buffer *buffer) -{ - struct softpipe_texture *spt; - assert(screen); - - /* Only supports one type */ - if (base->target != PIPE_TEXTURE_2D || - base->last_level != 0 || - base->depth0 != 1) { - return NULL; - } - - spt = CALLOC_STRUCT(softpipe_texture); - if (!spt) - return NULL; - - spt->base = *base; - pipe_reference_init(&spt->base.reference, 1); - spt->base.screen = screen; - spt->stride[0] = stride[0]; - - pipe_buffer_reference(&spt->buffer, buffer); - - return &spt->base; -} static void @@ -426,7 +396,7 @@ softpipe_video_surface_create(struct pipe_screen *screen, memset(&template, 0, sizeof(struct pipe_texture)); template.target = PIPE_TEXTURE_2D; - template.format = PIPE_FORMAT_X8R8G8B8_UNORM; + template.format = PIPE_FORMAT_B8G8R8X8_UNORM; template.last_level = 0; /* vl_mpeg12_mc_renderer expects this when it's initialized with pot_buffers=true */ template.width0 = util_next_power_of_two(width); @@ -458,7 +428,6 @@ void softpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = softpipe_texture_create; - screen->texture_blanket = softpipe_texture_blanket; screen->texture_destroy = softpipe_texture_destroy; screen->get_tex_surface = softpipe_get_tex_surface; @@ -474,24 +443,4 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen) } -/** - * Return pipe_buffer handle and stride for given texture object. - * XXX used for??? - */ -boolean -softpipe_get_texture_buffer( struct pipe_texture *texture, - struct pipe_buffer **buf, - unsigned *stride ) -{ - struct softpipe_texture *tex = (struct softpipe_texture *) texture; - - if (!tex) - return FALSE; - pipe_buffer_reference(buf, tex->buffer); - - if (stride) - *stride = tex->stride[0]; - - return TRUE; -} diff --git a/src/gallium/drivers/softpipe/sp_texture.h b/src/gallium/drivers/softpipe/sp_texture.h index 2ef64e1e7c3..b54cf33ef5c 100644 --- a/src/gallium/drivers/softpipe/sp_texture.h +++ b/src/gallium/drivers/softpipe/sp_texture.h @@ -33,6 +33,10 @@ #include "pipe/p_video_state.h" +#define SP_MAX_TEXTURE_2D_LEVELS 13 /* 4K x 4K */ +#define SP_MAX_TEXTURE_3D_LEVELS 9 /* 512 x 512 x 512 */ + + struct pipe_context; struct pipe_screen; struct softpipe_context; @@ -42,8 +46,8 @@ struct softpipe_texture { struct pipe_texture base; - unsigned long level_offset[PIPE_MAX_TEXTURE_LEVELS]; - unsigned stride[PIPE_MAX_TEXTURE_LEVELS]; + unsigned long level_offset[SP_MAX_TEXTURE_2D_LEVELS]; + unsigned stride[SP_MAX_TEXTURE_2D_LEVELS]; /* The data is held here: */ diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c index 1b50bd7ffe5..aedfdf1b469 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -162,10 +162,10 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, PIPE_TRANSFER_READ_WRITE, 0, 0, ps->width, ps->height); - tc->depth_stencil = (ps->format == PIPE_FORMAT_S8Z24_UNORM || - ps->format == PIPE_FORMAT_X8Z24_UNORM || - ps->format == PIPE_FORMAT_Z24S8_UNORM || + tc->depth_stencil = (ps->format == PIPE_FORMAT_Z24S8_UNORM || ps->format == PIPE_FORMAT_Z24X8_UNORM || + ps->format == PIPE_FORMAT_S8Z24_UNORM || + ps->format == PIPE_FORMAT_X8Z24_UNORM || ps->format == PIPE_FORMAT_Z16_UNORM || ps->format == PIPE_FORMAT_Z32_UNORM || ps->format == PIPE_FORMAT_S8_UNORM); @@ -299,13 +299,14 @@ sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc) x, y, TILE_SIZE, TILE_SIZE, tc->tile.data.color32, 0/*STRIDE*/); - /* do this? */ - clear_clear_flag(tc->clear_flags, addr); - numCleared++; } } } + + /* reset all clear flags to zero */ + memset(tc->clear_flags, 0, sizeof(tc->clear_flags)); + #if 0 debug_printf("num cleared: %u\n", numCleared); #endif diff --git a/src/gallium/drivers/softpipe/sp_video_context.c b/src/gallium/drivers/softpipe/sp_video_context.c index 7a3a6361670..242aaac4665 100644 --- a/src/gallium/drivers/softpipe/sp_video_context.c +++ b/src/gallium/drivers/softpipe/sp_video_context.c @@ -25,10 +25,12 @@ * **************************************************************************/ +#include "util/u_inlines.h" +#include "util/u_memory.h" + #include "sp_video_context.h" -#include <util/u_inlines.h> -#include <util/u_memory.h> -#include "softpipe/sp_texture.h" +#include "sp_texture.h" + static void sp_mpeg12_destroy(struct pipe_video_context *vpipe) @@ -174,7 +176,6 @@ init_pipe_state(struct sp_mpeg12_context *ctx) rast.line_stipple_factor = 0; rast.line_stipple_pattern = 0; rast.line_last_pixel = 0; - rast.bypass_vs_clip_and_viewport = 0; rast.line_width = 1; rast.point_smooth = 0; rast.point_quad_rasterization = 0; diff --git a/src/gallium/drivers/softpipe/sp_winsys.c b/src/gallium/drivers/softpipe/sp_winsys.c index f6598927d35..0a6245ed2cd 100644 --- a/src/gallium/drivers/softpipe/sp_winsys.c +++ b/src/gallium/drivers/softpipe/sp_winsys.c @@ -37,13 +37,13 @@ #include "util/u_simple_screen.h"/* port to just p_screen */ -#include "pipe/p_format.h" -#include "pipe/p_context.h" #include "util/u_format.h" #include "util/u_math.h" #include "util/u_memory.h" #include "util/u_inlines.h" -#include "softpipe/sp_winsys.h" +#include "pipe/p_format.h" +#include "pipe/p_context.h" +#include "sp_winsys.h" struct st_softpipe_buffer diff --git a/src/gallium/drivers/softpipe/sp_winsys.h b/src/gallium/drivers/softpipe/sp_winsys.h index 6e3920c49b2..edc49f256d2 100644 --- a/src/gallium/drivers/softpipe/sp_winsys.h +++ b/src/gallium/drivers/softpipe/sp_winsys.h @@ -60,12 +60,6 @@ struct pipe_screen *softpipe_create_screen( struct pipe_winsys * ); */ struct pipe_screen *softpipe_create_screen_malloc(void); -boolean -softpipe_get_texture_buffer( struct pipe_texture *texture, - struct pipe_buffer **buf, - unsigned *stride ); - - #ifdef __cplusplus } #endif diff --git a/src/gallium/drivers/svga/svga_cmd.c b/src/gallium/drivers/svga/svga_cmd.c index a0da7d7e5d5..04307d17fe0 100644 --- a/src/gallium/drivers/svga/svga_cmd.c +++ b/src/gallium/drivers/svga/svga_cmd.c @@ -478,7 +478,8 @@ SVGA3D_BufferDMA(struct svga_winsys_context *swc, struct svga_winsys_surface *host, SVGA3dTransferType transfer, // IN uint32 size, // IN - uint32 offset, // IN + uint32 guest_offset, // IN + uint32 host_offset, // IN SVGA3dSurfaceDMAFlags flags) // IN { SVGA3dCmdSurfaceDMA *cmd; @@ -517,19 +518,19 @@ SVGA3D_BufferDMA(struct svga_winsys_context *swc, cmd->transfer = transfer; box = (SVGA3dCopyBox *)&cmd[1]; - box->x = offset; + box->x = host_offset; box->y = 0; box->z = 0; box->w = size; box->h = 1; box->d = 1; - box->srcx = offset; + box->srcx = guest_offset; box->srcy = 0; box->srcz = 0; pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + sizeof *box); pSuffix->suffixSize = sizeof *pSuffix; - pSuffix->maximumOffset = offset + size; + pSuffix->maximumOffset = guest_offset + size; pSuffix->flags = flags; swc->commit(swc); diff --git a/src/gallium/drivers/svga/svga_cmd.h b/src/gallium/drivers/svga/svga_cmd.h index 80410547690..da9fc4355fa 100644 --- a/src/gallium/drivers/svga/svga_cmd.h +++ b/src/gallium/drivers/svga/svga_cmd.h @@ -111,7 +111,8 @@ SVGA3D_BufferDMA(struct svga_winsys_context *swc, struct svga_winsys_surface *host, SVGA3dTransferType transfer, uint32 size, - uint32 offset, + uint32 guest_offset, + uint32 host_offset, SVGA3dSurfaceDMAFlags flags); /* diff --git a/src/gallium/drivers/svga/svga_pipe_blend.c b/src/gallium/drivers/svga/svga_pipe_blend.c index b60117f090e..594eec7166e 100644 --- a/src/gallium/drivers/svga/svga_pipe_blend.c +++ b/src/gallium/drivers/svga/svga_pipe_blend.c @@ -92,6 +92,7 @@ svga_create_blend_state(struct pipe_context *pipe, if (templ->logicop_enable) { switch (templ->logicop_func) { case PIPE_LOGICOP_XOR: + case PIPE_LOGICOP_INVERT: blend->need_white_fragments = TRUE; blend->rt[i].blend_enable = TRUE; blend->rt[i].srcblend = SVGA3D_BLENDOP_ONE; @@ -125,12 +126,6 @@ svga_create_blend_state(struct pipe_context *pipe, blend->rt[i].dstblend = SVGA3D_BLENDOP_ONE; blend->rt[i].blendeq = SVGA3D_BLENDEQ_MAXIMUM; break; - case PIPE_LOGICOP_INVERT: - blend->rt[i].blend_enable = TRUE; - blend->rt[i].srcblend = SVGA3D_BLENDOP_INVSRCCOLOR; - blend->rt[i].dstblend = SVGA3D_BLENDOP_ZERO; - blend->rt[i].blendeq = SVGA3D_BLENDEQ_ADD; - break; case PIPE_LOGICOP_AND: /* Approximate with minimum - works for the 0 & anything case: */ blend->rt[i].blend_enable = TRUE; diff --git a/src/gallium/drivers/svga/svga_pipe_clear.c b/src/gallium/drivers/svga/svga_pipe_clear.c index 409b3b41cbc..8483a3fad74 100644 --- a/src/gallium/drivers/svga/svga_pipe_clear.c +++ b/src/gallium/drivers/svga/svga_pipe_clear.c @@ -54,7 +54,7 @@ try_clear(struct svga_context *svga, if ((buffers & PIPE_CLEAR_COLOR) && fb->cbufs[0]) { flags |= SVGA3D_CLEAR_COLOR; - util_pack_color(rgba, PIPE_FORMAT_A8R8G8B8_UNORM, &uc); + util_pack_color(rgba, PIPE_FORMAT_B8G8R8A8_UNORM, &uc); rect.w = fb->cbufs[0]->width; rect.h = fb->cbufs[0]->height; @@ -63,7 +63,7 @@ try_clear(struct svga_context *svga, if ((buffers & PIPE_CLEAR_DEPTHSTENCIL) && fb->zsbuf) { flags |= SVGA3D_CLEAR_DEPTH; - if (svga->curr.framebuffer.zsbuf->format == PIPE_FORMAT_Z24S8_UNORM) + if (svga->curr.framebuffer.zsbuf->format == PIPE_FORMAT_S8Z24_UNORM) flags |= SVGA3D_CLEAR_STENCIL; rect.w = MAX2(rect.w, fb->zsbuf->width); diff --git a/src/gallium/drivers/svga/svga_pipe_misc.c b/src/gallium/drivers/svga/svga_pipe_misc.c index 49b43bebc29..95bf0e6f91b 100644 --- a/src/gallium/drivers/svga/svga_pipe_misc.c +++ b/src/gallium/drivers/svga/svga_pipe_misc.c @@ -118,10 +118,10 @@ static void svga_set_framebuffer_state(struct pipe_context *pipe, case PIPE_FORMAT_Z16_UNORM: svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D16; break; - case PIPE_FORMAT_S8Z24_UNORM: - case PIPE_FORMAT_X8Z24_UNORM: case PIPE_FORMAT_Z24S8_UNORM: case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D24S8; break; case PIPE_FORMAT_Z32_UNORM: diff --git a/src/gallium/drivers/svga/svga_pipe_sampler.c b/src/gallium/drivers/svga/svga_pipe_sampler.c index 224c4f4c183..acba2b8f9da 100644 --- a/src/gallium/drivers/svga/svga_pipe_sampler.c +++ b/src/gallium/drivers/svga/svga_pipe_sampler.c @@ -201,7 +201,7 @@ static void svga_set_sampler_textures(struct pipe_context *pipe, if (!texture[i]) continue; - if (texture[i]->format == PIPE_FORMAT_A8R8G8B8_SRGB) + if (texture[i]->format == PIPE_FORMAT_B8G8R8A8_SRGB) flag_srgb |= 1 << i; if (texture[i]->target == PIPE_TEXTURE_1D) diff --git a/src/gallium/drivers/svga/svga_pipe_vertex.c b/src/gallium/drivers/svga/svga_pipe_vertex.c index d4a1280e74c..1715a47fc62 100644 --- a/src/gallium/drivers/svga/svga_pipe_vertex.c +++ b/src/gallium/drivers/svga/svga_pipe_vertex.c @@ -50,7 +50,7 @@ static void svga_set_vertex_buffers(struct pipe_context *pipe, /* Adjust refcounts */ for (i = 0; i < count; i++) { pipe_buffer_reference(&svga->curr.vb[i].buffer, buffers[i].buffer); - if (svga_buffer(buffers[i].buffer)->user) + if (svga_buffer_is_user_buffer(buffers[i].buffer)) any_user_buffer = TRUE; } diff --git a/src/gallium/drivers/svga/svga_screen.c b/src/gallium/drivers/svga/svga_screen.c index 414ac52e1f6..6022c38cfca 100644 --- a/src/gallium/drivers/svga/svga_screen.c +++ b/src/gallium/drivers/svga/svga_screen.c @@ -196,23 +196,23 @@ svga_translate_format_cap(enum pipe_format format) { switch(format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return SVGA3D_DEVCAP_SURFACEFMT_A8R8G8B8; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: return SVGA3D_DEVCAP_SURFACEFMT_X8R8G8B8; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: return SVGA3D_DEVCAP_SURFACEFMT_R5G6B5; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: return SVGA3D_DEVCAP_SURFACEFMT_A1R5G5B5; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: return SVGA3D_DEVCAP_SURFACEFMT_A4R4G4B4; case PIPE_FORMAT_Z16_UNORM: return SVGA3D_DEVCAP_SURFACEFMT_Z_D16; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: return SVGA3D_DEVCAP_SURFACEFMT_Z_D24S8; - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: return SVGA3D_DEVCAP_SURFACEFMT_Z_D24X8; case PIPE_FORMAT_A8_UNORM: @@ -254,8 +254,8 @@ svga_is_format_supported( struct pipe_screen *screen, /* Often unsupported/problematic. This means we end up with the same * visuals for all virtual hardware implementations. */ - case PIPE_FORMAT_A4R4G4B4_UNORM: - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: return FALSE; /* Simulate ability to render into compressed textures */ diff --git a/src/gallium/drivers/svga/svga_screen_buffer.c b/src/gallium/drivers/svga/svga_screen_buffer.c index c9e9bef5406..1ff6a3a5b31 100644 --- a/src/gallium/drivers/svga/svga_screen_buffer.c +++ b/src/gallium/drivers/svga/svga_screen_buffer.c @@ -83,7 +83,7 @@ svga_buffer_create_host_surface(struct svga_screen *ss, * as svga_screen_surface_create might have passed a recycled host * buffer. */ - sbuf->hw.flags.discard = TRUE; + sbuf->dma.flags.discard = TRUE; SVGA_DBG(DEBUG_DMA, " --> got sid %p sz %d (buffer)\n", sbuf->handle, sbuf->base.size); } @@ -109,10 +109,10 @@ svga_buffer_destroy_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf) struct svga_winsys_screen *sws = ss->sws; assert(!sbuf->map.count); - assert(sbuf->hw.buf); - if(sbuf->hw.buf) { - sws->buffer_destroy(sws, sbuf->hw.buf); - sbuf->hw.buf = NULL; + assert(sbuf->hwbuf); + if(sbuf->hwbuf) { + sws->buffer_destroy(sws, sbuf->hwbuf); + sbuf->hwbuf = NULL; } } @@ -151,16 +151,18 @@ static INLINE enum pipe_error svga_buffer_create_hw_storage(struct svga_screen *ss, struct svga_buffer *sbuf) { - if(!sbuf->hw.buf) { + assert(!sbuf->user); + + if(!sbuf->hwbuf) { unsigned alignment = sbuf->base.alignment; unsigned usage = 0; unsigned size = sbuf->base.size; - sbuf->hw.buf = svga_winsys_buffer_create(ss, alignment, usage, size); - if(!sbuf->hw.buf) + sbuf->hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size); + if(!sbuf->hwbuf) return PIPE_ERROR_OUT_OF_MEMORY; - assert(!sbuf->needs_flush); + assert(!sbuf->dma.pending); } return PIPE_OK; @@ -175,12 +177,11 @@ svga_buffer_upload_command(struct svga_context *svga, struct svga_buffer *sbuf) { struct svga_winsys_context *swc = svga->swc; - struct svga_winsys_buffer *guest = sbuf->hw.buf; + struct svga_winsys_buffer *guest = sbuf->hwbuf; struct svga_winsys_surface *host = sbuf->handle; SVGA3dTransferType transfer = SVGA3D_WRITE_HOST_VRAM; - SVGA3dSurfaceDMAFlags flags = sbuf->hw.flags; SVGA3dCmdSurfaceDMA *cmd; - uint32 numBoxes = sbuf->hw.num_ranges; + uint32 numBoxes = sbuf->map.num_ranges; SVGA3dCopyBox *boxes; SVGA3dCmdSurfaceDMASuffix *pSuffix; unsigned region_flags; @@ -218,8 +219,8 @@ svga_buffer_upload_command(struct svga_context *svga, cmd->transfer = transfer; - sbuf->hw.boxes = (SVGA3dCopyBox *)&cmd[1]; - sbuf->hw.svga = svga; + sbuf->dma.boxes = (SVGA3dCopyBox *)&cmd[1]; + sbuf->dma.svga = svga; /* Increment reference count */ dummy = NULL; @@ -228,9 +229,11 @@ svga_buffer_upload_command(struct svga_context *svga, pSuffix = (SVGA3dCmdSurfaceDMASuffix *)((uint8_t*)cmd + sizeof *cmd + numBoxes * sizeof *boxes); pSuffix->suffixSize = sizeof *pSuffix; pSuffix->maximumOffset = sbuf->base.size; - pSuffix->flags = flags; + pSuffix->flags = sbuf->dma.flags; + + SVGA_FIFOCommitAll(swc); - swc->commit(swc); + sbuf->dma.flags.discard = FALSE; return PIPE_OK; } @@ -248,10 +251,10 @@ svga_buffer_upload_flush(struct svga_context *svga, unsigned i; assert(sbuf->handle); - assert(sbuf->hw.buf); - assert(sbuf->hw.num_ranges); - assert(sbuf->hw.svga == svga); - assert(sbuf->hw.boxes); + assert(sbuf->hwbuf); + assert(sbuf->map.num_ranges); + assert(sbuf->dma.svga == svga); + assert(sbuf->dma.boxes); /* * Patch the DMA command with the final copy box. @@ -259,36 +262,33 @@ svga_buffer_upload_flush(struct svga_context *svga, SVGA_DBG(DEBUG_DMA, "dma to sid %p\n", sbuf->handle); - boxes = sbuf->hw.boxes; - for(i = 0; i < sbuf->hw.num_ranges; ++i) { + boxes = sbuf->dma.boxes; + for(i = 0; i < sbuf->map.num_ranges; ++i) { SVGA_DBG(DEBUG_DMA, " bytes %u - %u\n", - sbuf->hw.ranges[i].start, sbuf->hw.ranges[i].end); + sbuf->map.ranges[i].start, sbuf->map.ranges[i].end); - boxes[i].x = sbuf->hw.ranges[i].start; + boxes[i].x = sbuf->map.ranges[i].start; boxes[i].y = 0; boxes[i].z = 0; - boxes[i].w = sbuf->hw.ranges[i].end - sbuf->hw.ranges[i].start; + boxes[i].w = sbuf->map.ranges[i].end - sbuf->map.ranges[i].start; boxes[i].h = 1; boxes[i].d = 1; - boxes[i].srcx = sbuf->hw.ranges[i].start; + boxes[i].srcx = sbuf->map.ranges[i].start; boxes[i].srcy = 0; boxes[i].srcz = 0; } - sbuf->hw.num_ranges = 0; - memset(&sbuf->hw.flags, 0, sizeof sbuf->hw.flags); + sbuf->map.num_ranges = 0; assert(sbuf->head.prev && sbuf->head.next); LIST_DEL(&sbuf->head); #ifdef DEBUG sbuf->head.next = sbuf->head.prev = NULL; #endif - sbuf->needs_flush = FALSE; - - sbuf->hw.svga = NULL; - sbuf->hw.boxes = NULL; + sbuf->dma.pending = FALSE; - sbuf->host_written = TRUE; + sbuf->dma.svga = NULL; + sbuf->dma.boxes = NULL; /* Decrement reference count */ pipe_reference(&(sbuf->base.reference), NULL); @@ -297,7 +297,7 @@ svga_buffer_upload_flush(struct svga_context *svga, /** - * Queue a DMA upload of a range of this buffer to the host. + * Note a dirty range. * * This function only notes the range down. It doesn't actually emit a DMA * upload command. That only happens when a context tries to refer to this @@ -306,15 +306,24 @@ svga_buffer_upload_flush(struct svga_context *svga, * We try to lump as many contiguous DMA transfers together as possible. */ static void -svga_buffer_upload_queue(struct svga_buffer *sbuf, - unsigned start, - unsigned end) +svga_buffer_add_range(struct svga_buffer *sbuf, + unsigned start, + unsigned end) { unsigned i; + unsigned nearest_range; + unsigned nearest_dist; - assert(sbuf->hw.buf); assert(end > start); + if (sbuf->map.num_ranges < SVGA_BUFFER_MAX_RANGES) { + nearest_range = sbuf->map.num_ranges; + nearest_dist = ~0; + } else { + nearest_range = SVGA_BUFFER_MAX_RANGES - 1; + nearest_dist = 0; + } + /* * Try to grow one of the ranges. * @@ -325,12 +334,34 @@ svga_buffer_upload_queue(struct svga_buffer *sbuf, * buffer should be flushed. */ - for(i = 0; i < sbuf->hw.num_ranges; ++i) { - if(start <= sbuf->hw.ranges[i].end && sbuf->hw.ranges[i].start <= end) { - sbuf->hw.ranges[i].start = MIN2(sbuf->hw.ranges[i].start, start); - sbuf->hw.ranges[i].end = MAX2(sbuf->hw.ranges[i].end, end); + for(i = 0; i < sbuf->map.num_ranges; ++i) { + int left_dist; + int right_dist; + int dist; + + left_dist = start - sbuf->map.ranges[i].end; + right_dist = sbuf->map.ranges[i].start - end; + dist = MAX2(left_dist, right_dist); + + if (dist <= 0) { + /* + * Ranges are contiguous or overlapping -- extend this one and return. + */ + + sbuf->map.ranges[i].start = MIN2(sbuf->map.ranges[i].start, start); + sbuf->map.ranges[i].end = MAX2(sbuf->map.ranges[i].end, end); return; } + else { + /* + * Discontiguous ranges -- keep track of the nearest range. + */ + + if (dist < nearest_dist) { + nearest_range = i; + nearest_dist = dist; + } + } } /* @@ -338,20 +369,34 @@ svga_buffer_upload_queue(struct svga_buffer *sbuf, * pending DMA upload and start clean. */ - if(sbuf->needs_flush) - svga_buffer_upload_flush(sbuf->hw.svga, sbuf); + if(sbuf->dma.pending) + svga_buffer_upload_flush(sbuf->dma.svga, sbuf); - assert(!sbuf->needs_flush); - assert(!sbuf->hw.svga); - assert(!sbuf->hw.boxes); + assert(!sbuf->dma.pending); + assert(!sbuf->dma.svga); + assert(!sbuf->dma.boxes); - /* - * Add a new range. - */ + if (sbuf->map.num_ranges < SVGA_BUFFER_MAX_RANGES) { + /* + * Add a new range. + */ + + sbuf->map.ranges[sbuf->map.num_ranges].start = start; + sbuf->map.ranges[sbuf->map.num_ranges].end = end; + ++sbuf->map.num_ranges; + } else { + /* + * Everything else failed, so just extend the nearest range. + * + * It is OK to do this because we always keep a local copy of the + * host buffer data, for SW TNL, and the host never modifies the buffer. + */ - sbuf->hw.ranges[sbuf->hw.num_ranges].start = start; - sbuf->hw.ranges[sbuf->hw.num_ranges].end = end; - ++sbuf->hw.num_ranges; + assert(nearest_range < SVGA_BUFFER_MAX_RANGES); + assert(nearest_range < sbuf->map.num_ranges); + sbuf->map.ranges[nearest_range].start = MIN2(sbuf->map.ranges[nearest_range].start, start); + sbuf->map.ranges[nearest_range].end = MAX2(sbuf->map.ranges[nearest_range].end, end); + } } @@ -366,55 +411,30 @@ svga_buffer_map_range( struct pipe_screen *screen, struct svga_buffer *sbuf = svga_buffer( buf ); void *map; - if(sbuf->swbuf) { + if (!sbuf->swbuf && !sbuf->hwbuf) { + if (svga_buffer_create_hw_storage(ss, sbuf) != PIPE_OK) { + /* + * We can't create a hardware buffer big enough, so create a malloc + * buffer instead. + */ + + debug_printf("%s: failed to allocate %u KB of DMA, splitting DMA transfers\n", + __FUNCTION__, + (sbuf->base.size + 1023)/1024); + + sbuf->swbuf = align_malloc(sbuf->base.size, sbuf->base.alignment); + } + } + + if (sbuf->swbuf) { /* User/malloc buffer */ map = sbuf->swbuf; } + else if (sbuf->hwbuf) { + map = sws->buffer_map(sws, sbuf->hwbuf, usage); + } else { - if(!sbuf->hw.buf) { - if(svga_buffer_create_hw_storage(ss, sbuf) != PIPE_OK) - return NULL; - - /* Populate the hardware storage if the host surface pre-existed */ - if(sbuf->host_written) { - SVGA3dSurfaceDMAFlags flags; - enum pipe_error ret; - struct pipe_fence_handle *fence = NULL; - - assert(sbuf->handle); - - SVGA_DBG(DEBUG_DMA|DEBUG_PERF, "dma from sid %p (buffer), bytes %u - %u\n", - sbuf->handle, 0, sbuf->base.size); - - memset(&flags, 0, sizeof flags); - - ret = SVGA3D_BufferDMA(ss->swc, - sbuf->hw.buf, - sbuf->handle, - SVGA3D_READ_HOST_VRAM, - sbuf->base.size, - 0, - flags); - if(ret != PIPE_OK) { - ss->swc->flush(ss->swc, NULL); - - ret = SVGA3D_BufferDMA(ss->swc, - sbuf->hw.buf, - sbuf->handle, - SVGA3D_READ_HOST_VRAM, - sbuf->base.size, - 0, - flags); - assert(ret == PIPE_OK); - } - - ss->swc->flush(ss->swc, &fence); - sws->fence_finish(sws, fence, 0); - sws->fence_reference(sws, &fence, NULL); - } - } - - map = sws->buffer_map(sws, sbuf->hw.buf, usage); + map = NULL; } if(map) { @@ -447,8 +467,7 @@ svga_buffer_flush_mapped_range( struct pipe_screen *screen, assert(sbuf->map.writing); if(sbuf->map.writing) { assert(sbuf->map.flush_explicit); - if(sbuf->hw.buf) - svga_buffer_upload_queue(sbuf, offset, offset + length); + svga_buffer_add_range(sbuf, offset, offset + length); } pipe_mutex_unlock(ss->swc_mutex); } @@ -467,16 +486,15 @@ svga_buffer_unmap( struct pipe_screen *screen, if(sbuf->map.count) --sbuf->map.count; - if(sbuf->hw.buf) - sws->buffer_unmap(sws, sbuf->hw.buf); + if(sbuf->hwbuf) + sws->buffer_unmap(sws, sbuf->hwbuf); if(sbuf->map.writing) { if(!sbuf->map.flush_explicit) { /* No mapped range was flushed -- flush the whole buffer */ SVGA_DBG(DEBUG_DMA, "flushing the whole buffer\n"); - if(sbuf->hw.buf) - svga_buffer_upload_queue(sbuf, 0, sbuf->base.size); + svga_buffer_add_range(sbuf, 0, sbuf->base.size); } sbuf->map.writing = FALSE; @@ -494,12 +512,15 @@ svga_buffer_destroy( struct pipe_buffer *buf ) assert(!p_atomic_read(&buf->reference.count)); - assert(!sbuf->needs_flush); + assert(!sbuf->dma.pending); if(sbuf->handle) svga_buffer_destroy_host_surface(ss, sbuf); - if(sbuf->hw.buf) + if(sbuf->uploaded.buffer) + pipe_buffer_reference(&sbuf->uploaded.buffer, NULL); + + if(sbuf->hwbuf) svga_buffer_destroy_hw_storage(ss, sbuf); if(sbuf->swbuf && !sbuf->user) @@ -596,13 +617,14 @@ svga_screen_init_buffer_functions(struct pipe_screen *screen) } -/** - * Copy the contents of the user buffer / malloc buffer to a hardware buffer. +/** + * Copy the contents of the malloc buffer to a hardware buffer. */ static INLINE enum pipe_error svga_buffer_update_hw(struct svga_screen *ss, struct svga_buffer *sbuf) { - if(!sbuf->hw.buf) { + assert(!sbuf->user); + if(!sbuf->hwbuf) { enum pipe_error ret; void *map; @@ -611,20 +633,20 @@ svga_buffer_update_hw(struct svga_screen *ss, struct svga_buffer *sbuf) return PIPE_ERROR; ret = svga_buffer_create_hw_storage(ss, sbuf); - assert(ret == PIPE_OK); if(ret != PIPE_OK) return ret; pipe_mutex_lock(ss->swc_mutex); - map = ss->sws->buffer_map(ss->sws, sbuf->hw.buf, PIPE_BUFFER_USAGE_CPU_WRITE); + map = ss->sws->buffer_map(ss->sws, sbuf->hwbuf, PIPE_BUFFER_USAGE_CPU_WRITE); assert(map); if(!map) { pipe_mutex_unlock(ss->swc_mutex); - return PIPE_ERROR_OUT_OF_MEMORY; + svga_buffer_destroy_hw_storage(ss, sbuf); + return PIPE_ERROR; } memcpy(map, sbuf->swbuf, sbuf->base.size); - ss->sws->buffer_unmap(ss->sws, sbuf->hw.buf); + ss->sws->buffer_unmap(ss->sws, sbuf->hwbuf); /* This user/malloc buffer is now indistinguishable from a gpu buffer */ assert(!sbuf->map.count); @@ -636,10 +658,89 @@ svga_buffer_update_hw(struct svga_screen *ss, struct svga_buffer *sbuf) sbuf->swbuf = NULL; } - svga_buffer_upload_queue(sbuf, 0, sbuf->base.size); + pipe_mutex_unlock(ss->swc_mutex); } - pipe_mutex_unlock(ss->swc_mutex); + return PIPE_OK; +} + + +/** + * Upload the buffer to the host in a piecewise fashion. + * + * Used when the buffer is too big to fit in the GMR aperture. + */ +static INLINE enum pipe_error +svga_buffer_upload_piecewise(struct svga_screen *ss, + struct svga_context *svga, + struct svga_buffer *sbuf) +{ + struct svga_winsys_screen *sws = ss->sws; + const unsigned alignment = sizeof(void *); + const unsigned usage = 0; + unsigned i; + + assert(sbuf->map.num_ranges); + assert(!sbuf->dma.pending); + + SVGA_DBG(DEBUG_DMA, "dma to sid %p\n", sbuf->handle); + + for (i = 0; i < sbuf->map.num_ranges; ++i) { + struct svga_buffer_range *range = &sbuf->map.ranges[i]; + unsigned offset = range->start; + unsigned size = range->end - range->start; + + while (offset < range->end) { + struct svga_winsys_buffer *hwbuf; + uint8_t *map; + enum pipe_error ret; + + if (offset + size > range->end) + size = range->end - offset; + + hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size); + while (!hwbuf) { + size /= 2; + if (!size) + return PIPE_ERROR_OUT_OF_MEMORY; + hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size); + } + + SVGA_DBG(DEBUG_DMA, " bytes %u - %u\n", + offset, offset + size); + + map = sws->buffer_map(sws, hwbuf, + PIPE_BUFFER_USAGE_CPU_WRITE | + PIPE_BUFFER_USAGE_DISCARD); + assert(map); + if (map) { + memcpy(map, sbuf->swbuf, size); + sws->buffer_unmap(sws, hwbuf); + } + + ret = SVGA3D_BufferDMA(svga->swc, + hwbuf, sbuf->handle, + SVGA3D_WRITE_HOST_VRAM, + size, 0, offset, sbuf->dma.flags); + if(ret != PIPE_OK) { + svga_context_flush(svga, NULL); + ret = SVGA3D_BufferDMA(svga->swc, + hwbuf, sbuf->handle, + SVGA3D_WRITE_HOST_VRAM, + size, 0, offset, sbuf->dma.flags); + assert(ret == PIPE_OK); + } + + sbuf->dma.flags.discard = FALSE; + + sws->buffer_destroy(sws, hwbuf); + + offset += size; + } + } + + sbuf->map.num_ranges = 0; + return PIPE_OK; } @@ -659,34 +760,74 @@ svga_buffer_handle(struct svga_context *svga, sbuf = svga_buffer(buf); assert(!sbuf->map.count); + assert(!sbuf->user); if(!sbuf->handle) { ret = svga_buffer_create_host_surface(ss, sbuf); if(ret != PIPE_OK) return NULL; - - ret = svga_buffer_update_hw(ss, sbuf); - if(ret != PIPE_OK) - return NULL; } - if(!sbuf->needs_flush && sbuf->hw.num_ranges) { - /* Queue the buffer for flushing */ - ret = svga_buffer_upload_command(svga, sbuf); - if(ret != PIPE_OK) - /* XXX: Should probably have a richer return value */ - return NULL; - - assert(sbuf->hw.svga == svga); + assert(sbuf->handle); + + if (sbuf->map.num_ranges) { + if (!sbuf->dma.pending) { + /* + * No pending DMA upload yet, so insert a DMA upload command now. + */ + + /* + * Migrate the data from swbuf -> hwbuf if necessary. + */ + ret = svga_buffer_update_hw(ss, sbuf); + if (ret == PIPE_OK) { + /* + * Queue a dma command. + */ + + ret = svga_buffer_upload_command(svga, sbuf); + if (ret == PIPE_ERROR_OUT_OF_MEMORY) { + svga_context_flush(svga, NULL); + ret = svga_buffer_upload_command(svga, sbuf); + assert(ret == PIPE_OK); + } + if (ret == PIPE_OK) { + sbuf->dma.pending = TRUE; + assert(!sbuf->head.prev && !sbuf->head.next); + LIST_ADDTAIL(&sbuf->head, &svga->dirty_buffers); + } + } + else if (ret == PIPE_ERROR_OUT_OF_MEMORY) { + /* + * The buffer is too big to fit in the GMR aperture, so break it in + * smaller pieces. + */ + ret = svga_buffer_upload_piecewise(ss, svga, sbuf); + } - sbuf->needs_flush = TRUE; - assert(!sbuf->head.prev && !sbuf->head.next); - LIST_ADDTAIL(&sbuf->head, &svga->dirty_buffers); + if (ret != PIPE_OK) { + /* + * Something unexpected happened above. There is very little that + * we can do other than proceeding while ignoring the dirty ranges. + */ + assert(0); + sbuf->map.num_ranges = 0; + } + } + else { + /* + * There a pending dma already. Make sure it is from this context. + */ + assert(sbuf->dma.svga == svga); + } } + assert(!sbuf->map.num_ranges || sbuf->dma.pending); + return sbuf->handle; } + struct pipe_buffer * svga_screen_buffer_wrap_surface(struct pipe_screen *screen, enum SVGA3dSurfaceFormat format, @@ -739,7 +880,7 @@ svga_context_flush_buffers(struct svga_context *svga) sbuf = LIST_ENTRY(struct svga_buffer, curr, head); assert(p_atomic_read(&sbuf->base.reference.count) != 0); - assert(sbuf->needs_flush); + assert(sbuf->dma.pending); svga_buffer_upload_flush(svga, sbuf); diff --git a/src/gallium/drivers/svga/svga_screen_buffer.h b/src/gallium/drivers/svga/svga_screen_buffer.h index 448ac107c7f..8c862fa62d6 100644 --- a/src/gallium/drivers/svga/svga_screen_buffer.h +++ b/src/gallium/drivers/svga/svga_screen_buffer.h @@ -57,35 +57,6 @@ struct svga_buffer_range /** - * Describe a - * - * This holds the information to emit a SVGA3dCmdSurfaceDMA. - */ -struct svga_buffer_upload -{ - /** - * Guest memory region. - */ - struct svga_winsys_buffer *buf; - - struct svga_buffer_range ranges[SVGA_BUFFER_MAX_RANGES]; - unsigned num_ranges; - - SVGA3dSurfaceDMAFlags flags; - - /** - * Pointer to the DMA copy box *inside* the command buffer. - */ - SVGA3dCopyBox *boxes; - - /** - * Context that has the pending DMA to this buffer. - */ - struct svga_context *svga; -}; - - -/** * SVGA pipe buffer. */ struct svga_buffer @@ -111,14 +82,6 @@ struct svga_buffer boolean user; /** - * DMA'ble memory. - * - * A piece of GMR memory. It is created when mapping the buffer, and will be - * used to upload/download vertex data from the host. - */ - struct svga_buffer_upload hw; - - /** * Creation key for the host surface handle. * * This structure describes all the host surface characteristics so that it @@ -134,19 +97,94 @@ struct svga_buffer * trying to bind */ struct svga_winsys_surface *handle; - + /** - * Whether the host has been ever written. + * Information about ongoing and past map operations. */ - boolean host_written; - struct { + /** + * Number of concurrent mappings. + * + * XXX: It is impossible to guarantee concurrent maps work in all + * circumstances -- pipe_buffers really need transfer objects too. + */ unsigned count; + + /** + * Whether this buffer is currently mapped for writing. + */ boolean writing; + + /** + * Whether the application will tell us explicity which ranges it touched + * or not. + */ boolean flush_explicit; + + /** + * Dirty ranges. + * + * Ranges that were touched by the application and need to be uploaded to + * the host. + * + * This information will be copied into dma.boxes, when emiting the + * SVGA3dCmdSurfaceDMA command. + */ + struct svga_buffer_range ranges[SVGA_BUFFER_MAX_RANGES]; + unsigned num_ranges; } map; - - boolean needs_flush; + + /** + * Information about uploaded version of user buffers. + */ + struct { + struct pipe_buffer *buffer; + + /** + * We combine multiple user buffers into the same hardware buffer. This + * is the relative offset within that buffer. + */ + unsigned offset; + } uploaded; + + /** + * DMA'ble memory. + * + * A piece of GMR memory, with the same size of the buffer. It is created + * when mapping the buffer, and will be used to upload vertex data to the + * host. + */ + struct svga_winsys_buffer *hwbuf; + + /** + * Information about pending DMA uploads. + * + */ + struct { + /** + * Whether this buffer has an unfinished DMA upload command. + * + * If not set then the rest of the information is null. + */ + boolean pending; + + SVGA3dSurfaceDMAFlags flags; + + /** + * Pointer to the DMA copy box *inside* the command buffer. + */ + SVGA3dCopyBox *boxes; + + /** + * Context that has the pending DMA to this buffer. + */ + struct svga_context *svga; + } dma; + + /** + * Linked list head, used to gather all buffers with pending dma uploads on + * a context. It is only valid if the dma.pending is set above. + */ struct list_head head; }; @@ -176,6 +214,16 @@ svga_buffer_is_user_buffer( struct pipe_buffer *buffer ) void svga_screen_init_buffer_functions(struct pipe_screen *screen); + +/** + * Get the host surface handle for this buffer. + * + * This will ensure the host surface is updated, issuing DMAs as needed. + * + * NOTE: This may insert new commands in the context, so it *must* be called + * before reserving command buffer space. And, in order to insert commands + * it may need to call svga_context_flush(). + */ struct svga_winsys_surface * svga_buffer_handle(struct svga_context *svga, struct pipe_buffer *buf); diff --git a/src/gallium/drivers/svga/svga_screen_texture.c b/src/gallium/drivers/svga/svga_screen_texture.c index 12f3531a1df..5b581debfc7 100644 --- a/src/gallium/drivers/svga/svga_screen_texture.c +++ b/src/gallium/drivers/svga/svga_screen_texture.c @@ -59,21 +59,21 @@ svga_translate_format(enum pipe_format format) { switch(format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return SVGA3D_A8R8G8B8; - case PIPE_FORMAT_X8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: return SVGA3D_X8R8G8B8; /* Required for GL2.1: */ - case PIPE_FORMAT_A8R8G8B8_SRGB: + case PIPE_FORMAT_B8G8R8A8_SRGB: return SVGA3D_A8R8G8B8; - case PIPE_FORMAT_R5G6B5_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: return SVGA3D_R5G6B5; - case PIPE_FORMAT_A1R5G5B5_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: return SVGA3D_A1R5G5B5; - case PIPE_FORMAT_A4R4G4B4_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: return SVGA3D_A4R4G4B4; @@ -83,9 +83,9 @@ svga_translate_format(enum pipe_format format) */ case PIPE_FORMAT_Z16_UNORM: return SVGA3D_Z_D16; - case PIPE_FORMAT_Z24S8_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: return SVGA3D_Z_D24S8; - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: return SVGA3D_Z_D24X8; case PIPE_FORMAT_A8_UNORM: @@ -111,13 +111,13 @@ SVGA3dSurfaceFormat svga_translate_format_render(enum pipe_format format) { switch(format) { - case PIPE_FORMAT_A8R8G8B8_UNORM: - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_A1R5G5B5_UNORM: - case PIPE_FORMAT_A4R4G4B4_UNORM: - case PIPE_FORMAT_R5G6B5_UNORM: - case PIPE_FORMAT_Z24S8_UNORM: - case PIPE_FORMAT_Z24X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B5G5R5A1_UNORM: + case PIPE_FORMAT_B4G4R4A4_UNORM: + case PIPE_FORMAT_B5G6R5_UNORM: + case PIPE_FORMAT_S8Z24_UNORM: + case PIPE_FORMAT_X8Z24_UNORM: case PIPE_FORMAT_Z32_UNORM: case PIPE_FORMAT_Z16_UNORM: case PIPE_FORMAT_L8_UNORM: @@ -315,7 +315,11 @@ svga_texture_create(struct pipe_screen *screen, tex->key.cachable = 0; } - if(templat->tex_usage & PIPE_TEXTURE_USAGE_PRIMARY) { + if(templat->tex_usage & PIPE_TEXTURE_USAGE_SHARED) { + tex->key.cachable = 0; + } + + if(templat->tex_usage & PIPE_TEXTURE_USAGE_SCANOUT) { tex->key.flags |= SVGA3D_SURFACE_HINT_SCANOUT; tex->key.cachable = 0; } @@ -355,80 +359,18 @@ error1: } -static struct pipe_texture * -svga_texture_blanket(struct pipe_screen * screen, - const struct pipe_texture *base, - const unsigned *stride, - struct pipe_buffer *buffer) -{ - struct svga_texture *tex; - struct svga_buffer *sbuf = svga_buffer(buffer); - struct svga_winsys_screen *sws = svga_winsys_screen(screen); - assert(screen); - - /* Only supports one type */ - if (base->target != PIPE_TEXTURE_2D || - base->last_level != 0 || - base->depth0 != 1) { - return NULL; - } - - /** - * We currently can't do texture blanket on - * SVGA3D_BUFFER. Need to blit to a temporary surface? - */ - - assert(sbuf->handle); - if (!sbuf->handle) - return NULL; - - if (svga_translate_format(base->format) != sbuf->key.format) { - unsigned f1 = svga_translate_format(base->format); - unsigned f2 = sbuf->key.format; - - /* It's okay for XRGB and ARGB or depth with/out stencil to get mixed up */ - if ( !( (f1 == SVGA3D_X8R8G8B8 && f2 == SVGA3D_A8R8G8B8) || - (f1 == SVGA3D_A8R8G8B8 && f2 == SVGA3D_X8R8G8B8) || - (f1 == SVGA3D_Z_D24X8 && f2 == SVGA3D_Z_D24S8) ) ) { - debug_printf("%s wrong format %u != %u\n", __FUNCTION__, f1, f2); - return NULL; - } - } - - tex = CALLOC_STRUCT(svga_texture); - if (!tex) - return NULL; - - tex->base = *base; - - - if (sbuf->key.format == 1) - tex->base.format = PIPE_FORMAT_X8R8G8B8_UNORM; - else if (sbuf->key.format == 2) - tex->base.format = PIPE_FORMAT_A8R8G8B8_UNORM; - - pipe_reference_init(&tex->base.reference, 1); - tex->base.screen = screen; - - SVGA_DBG(DEBUG_DMA, "blanket sid %p\n", sbuf->handle); - - /* We don't own this storage, so don't try to cache it. - */ - assert(sbuf->key.cachable == 0); - tex->key.cachable = 0; - sws->surface_reference(sws, &tex->handle, sbuf->handle); - return &tex->base; -} -struct pipe_texture * -svga_screen_texture_wrap_surface(struct pipe_screen *screen, - struct pipe_texture *base, - enum SVGA3dSurfaceFormat format, - struct svga_winsys_surface *srf) +static struct pipe_texture * +svga_screen_texture_from_handle(struct pipe_screen *screen, + const struct pipe_texture *base, + struct winsys_handle *whandle) { + struct svga_winsys_screen *sws = svga_winsys_screen(screen); + struct svga_winsys_surface *srf; struct svga_texture *tex; + enum SVGA3dSurfaceFormat format = 0; assert(screen); /* Only supports one type */ @@ -438,6 +380,8 @@ svga_screen_texture_wrap_surface(struct pipe_screen *screen, return NULL; } + srf = sws->surface_from_handle(sws, whandle, &format); + if (!srf) return NULL; @@ -462,9 +406,9 @@ svga_screen_texture_wrap_surface(struct pipe_screen *screen, if (format == 1) - tex->base.format = PIPE_FORMAT_X8R8G8B8_UNORM; + tex->base.format = PIPE_FORMAT_B8G8R8X8_UNORM; else if (format == 2) - tex->base.format = PIPE_FORMAT_A8R8G8B8_UNORM; + tex->base.format = PIPE_FORMAT_B8G8R8A8_UNORM; pipe_reference_init(&tex->base.reference, 1); tex->base.screen = screen; @@ -478,6 +422,22 @@ svga_screen_texture_wrap_surface(struct pipe_screen *screen, } +static boolean +svga_screen_texture_get_handle(struct pipe_screen *screen, + struct pipe_texture *texture, + struct winsys_handle *whandle) +{ + struct svga_winsys_screen *sws = svga_winsys_screen(texture->screen); + unsigned stride; + + assert(svga_texture(texture)->key.cachable == 0); + svga_texture(texture)->key.cachable = 0; + stride = util_format_get_nblocksx(texture->format, texture->width0) * + util_format_get_blocksize(texture->format); + return sws->surface_get_handle(sws, svga_texture(texture)->handle, stride, whandle); +} + + static void svga_texture_destroy(struct pipe_texture *pt) { @@ -955,10 +915,11 @@ void svga_screen_init_texture_functions(struct pipe_screen *screen) { screen->texture_create = svga_texture_create; + screen->texture_from_handle = svga_screen_texture_from_handle; + screen->texture_get_handle = svga_screen_texture_get_handle; screen->texture_destroy = svga_texture_destroy; screen->get_tex_surface = svga_get_tex_surface; screen->tex_surface_destroy = svga_tex_surface_destroy; - screen->texture_blanket = svga_texture_blanket; screen->get_tex_transfer = svga_get_tex_transfer; screen->transfer_map = svga_transfer_map; screen->transfer_unmap = svga_transfer_unmap; @@ -1120,33 +1081,3 @@ svga_destroy_sampler_view_priv(struct svga_sampler_view *v) pipe_texture_reference(&v->texture, NULL); FREE(v); } - -boolean -svga_screen_buffer_from_texture(struct pipe_texture *texture, - struct pipe_buffer **buffer, - unsigned *stride) -{ - struct svga_texture *stex = svga_texture(texture); - - *buffer = svga_screen_buffer_wrap_surface - (texture->screen, - svga_translate_format(texture->format), - stex->handle); - - *stride = util_format_get_stride(texture->format, texture->width0); - - return *buffer != NULL; -} - - -struct svga_winsys_surface * -svga_screen_texture_get_winsys_surface(struct pipe_texture *texture) -{ - struct svga_winsys_screen *sws = svga_winsys_screen(texture->screen); - struct svga_winsys_surface *vsurf = NULL; - - assert(svga_texture(texture)->key.cachable == 0); - svga_texture(texture)->key.cachable = 0; - sws->surface_reference(sws, &vsurf, svga_texture(texture)->handle); - return vsurf; -} diff --git a/src/gallium/drivers/svga/svga_screen_texture.h b/src/gallium/drivers/svga/svga_screen_texture.h index 24c1f78ca55..ca6602b4369 100644 --- a/src/gallium/drivers/svga/svga_screen_texture.h +++ b/src/gallium/drivers/svga/svga_screen_texture.h @@ -78,7 +78,7 @@ struct svga_texture { struct pipe_texture base; - boolean defined[6][PIPE_MAX_TEXTURE_LEVELS]; + boolean defined[6][SVGA_MAX_TEXTURE_LEVELS]; struct svga_sampler_view *cached_view; diff --git a/src/gallium/drivers/svga/svga_state_framebuffer.c b/src/gallium/drivers/svga/svga_state_framebuffer.c index b4cafb8f219..b710914acda 100644 --- a/src/gallium/drivers/svga/svga_state_framebuffer.c +++ b/src/gallium/drivers/svga/svga_state_framebuffer.c @@ -70,7 +70,7 @@ static int emit_framebuffer( struct svga_context *svga, return ret; if (curr->zsbuf && - curr->zsbuf->format == PIPE_FORMAT_Z24S8_UNORM) { + curr->zsbuf->format == PIPE_FORMAT_S8Z24_UNORM) { ret = SVGA3D_SetRenderTarget(svga->swc, SVGA3D_RT_STENCIL, curr->zsbuf); if (ret != PIPE_OK) return ret; @@ -120,174 +120,153 @@ static int emit_viewport( struct svga_context *svga, float fb_width = svga->curr.framebuffer.width; float fb_height = svga->curr.framebuffer.height; - memset( &prescale, 0, sizeof(prescale) ); - - if (svga->curr.rast->templ.bypass_vs_clip_and_viewport) { - - /* Avoid POSITIONT as it has a non trivial implementation outside the D3D - * API. Always generate a vertex shader. - */ - rect.x = 0; - rect.y = 0; - rect.w = svga->curr.framebuffer.width; - rect.h = svga->curr.framebuffer.height; - - prescale.scale[0] = 2.0 / (float)rect.w; - prescale.scale[1] = - 2.0 / (float)rect.h; - prescale.scale[2] = 1.0; - prescale.scale[3] = 1.0; - prescale.translate[0] = -1.0f; - prescale.translate[1] = 1.0f; - prescale.translate[2] = 0; - prescale.translate[3] = 0; - prescale.enabled = TRUE; - } else { - - /* Examine gallium viewport transformation and produce a screen - * rectangle and possibly vertex shader pre-transformation to - * get the same results. - */ - float fx = viewport->scale[0] * -1.0 + viewport->translate[0]; - float fy = flip * viewport->scale[1] * -1.0 + viewport->translate[1]; - float fw = viewport->scale[0] * 2; - float fh = flip * viewport->scale[1] * 2; - - SVGA_DBG(DEBUG_VIEWPORT, - "\ninitial %f,%f %fx%f\n", - fx, - fy, - fw, - fh); - - prescale.scale[0] = 1.0; - prescale.scale[1] = 1.0; - prescale.scale[2] = 1.0; - prescale.scale[3] = 1.0; - prescale.translate[0] = 0; - prescale.translate[1] = 0; - prescale.translate[2] = 0; - prescale.translate[3] = 0; - prescale.enabled = TRUE; - - - - if (fw < 0) { - prescale.scale[0] *= -1.0; - prescale.translate[0] += -fw; - fw = -fw; - fx = viewport->scale[0] * 1.0 + viewport->translate[0]; - } + float fx = viewport->scale[0] * -1.0 + viewport->translate[0]; + float fy = flip * viewport->scale[1] * -1.0 + viewport->translate[1]; + float fw = viewport->scale[0] * 2; + float fh = flip * viewport->scale[1] * 2; - if (fh < 0) { - prescale.scale[1] *= -1.0; - prescale.translate[1] += -fh; - fh = -fh; - fy = flip * viewport->scale[1] * 1.0 + viewport->translate[1]; - } + memset( &prescale, 0, sizeof(prescale) ); - if (fx < 0) { - prescale.translate[0] += fx; - prescale.scale[0] *= fw / (fw + fx); - fw += fx; - fx = 0; - } + /* Examine gallium viewport transformation and produce a screen + * rectangle and possibly vertex shader pre-transformation to + * get the same results. + */ - if (fy < 0) { - prescale.translate[1] += fy; - prescale.scale[1] *= fh / (fh + fy); - fh += fy; - fy = 0; - } + SVGA_DBG(DEBUG_VIEWPORT, + "\ninitial %f,%f %fx%f\n", + fx, + fy, + fw, + fh); + + prescale.scale[0] = 1.0; + prescale.scale[1] = 1.0; + prescale.scale[2] = 1.0; + prescale.scale[3] = 1.0; + prescale.translate[0] = 0; + prescale.translate[1] = 0; + prescale.translate[2] = 0; + prescale.translate[3] = 0; + prescale.enabled = TRUE; + + + + if (fw < 0) { + prescale.scale[0] *= -1.0; + prescale.translate[0] += -fw; + fw = -fw; + fx = viewport->scale[0] * 1.0 + viewport->translate[0]; + } - if (fx + fw > fb_width) { - prescale.scale[0] *= fw / (fb_width - fx); - prescale.translate[0] -= fx * (fw / (fb_width - fx)); - prescale.translate[0] += fx; - fw = fb_width - fx; - - } + if (fh < 0) { + prescale.scale[1] *= -1.0; + prescale.translate[1] += -fh; + fh = -fh; + fy = flip * viewport->scale[1] * 1.0 + viewport->translate[1]; + } - if (fy + fh > fb_height) { - prescale.scale[1] *= fh / (fb_height - fy); - prescale.translate[1] -= fy * (fh / (fb_height - fy)); - prescale.translate[1] += fy; - fh = fb_height - fy; - } + if (fx < 0) { + prescale.translate[0] += fx; + prescale.scale[0] *= fw / (fw + fx); + fw += fx; + fx = 0; + } - if (fw < 0 || fh < 0) { - fw = fh = fx = fy = 0; - degenerate = TRUE; - goto out; - } + if (fy < 0) { + prescale.translate[1] += fy; + prescale.scale[1] *= fh / (fh + fy); + fh += fy; + fy = 0; + } + if (fx + fw > fb_width) { + prescale.scale[0] *= fw / (fb_width - fx); + prescale.translate[0] -= fx * (fw / (fb_width - fx)); + prescale.translate[0] += fx; + fw = fb_width - fx; + + } - /* D3D viewport is integer space. Convert fx,fy,etc. to - * integers. - * - * TODO: adjust pretranslate correct for any subpixel error - * introduced converting to integers. - */ - rect.x = fx; - rect.y = fy; - rect.w = fw; - rect.h = fh; + if (fy + fh > fb_height) { + prescale.scale[1] *= fh / (fb_height - fy); + prescale.translate[1] -= fy * (fh / (fb_height - fy)); + prescale.translate[1] += fy; + fh = fb_height - fy; + } - SVGA_DBG(DEBUG_VIEWPORT, - "viewport error %f,%f %fx%f\n", - fabs((float)rect.x - fx), - fabs((float)rect.y - fy), - fabs((float)rect.w - fw), - fabs((float)rect.h - fh)); + if (fw < 0 || fh < 0) { + fw = fh = fx = fy = 0; + degenerate = TRUE; + goto out; + } - SVGA_DBG(DEBUG_VIEWPORT, - "viewport %d,%d %dx%d\n", - rect.x, - rect.y, - rect.w, - rect.h); - - /* Finally, to get GL rasterization rules, need to tweak the - * screen-space coordinates slightly relative to D3D which is - * what hardware implements natively. - */ - if (svga->curr.rast->templ.gl_rasterization_rules) { - float adjust_x = 0.0; - float adjust_y = 0.0; - - switch (svga->curr.reduced_prim) { - case PIPE_PRIM_LINES: - adjust_x = -0.5; - adjust_y = 0; - break; - case PIPE_PRIM_POINTS: - case PIPE_PRIM_TRIANGLES: - adjust_x = -0.375; - adjust_y = -0.5; - break; - } - - prescale.translate[0] += adjust_x; - prescale.translate[1] += adjust_y; - prescale.translate[2] = 0.5; /* D3D clip space */ - prescale.scale[2] = 0.5; /* D3D clip space */ + /* D3D viewport is integer space. Convert fx,fy,etc. to + * integers. + * + * TODO: adjust pretranslate correct for any subpixel error + * introduced converting to integers. + */ + rect.x = fx; + rect.y = fy; + rect.w = fw; + rect.h = fh; + + SVGA_DBG(DEBUG_VIEWPORT, + "viewport error %f,%f %fx%f\n", + fabs((float)rect.x - fx), + fabs((float)rect.y - fy), + fabs((float)rect.w - fw), + fabs((float)rect.h - fh)); + + SVGA_DBG(DEBUG_VIEWPORT, + "viewport %d,%d %dx%d\n", + rect.x, + rect.y, + rect.w, + rect.h); + + + /* Finally, to get GL rasterization rules, need to tweak the + * screen-space coordinates slightly relative to D3D which is + * what hardware implements natively. + */ + if (svga->curr.rast->templ.gl_rasterization_rules) { + float adjust_x = 0.0; + float adjust_y = 0.0; + + switch (svga->curr.reduced_prim) { + case PIPE_PRIM_LINES: + adjust_x = -0.5; + adjust_y = 0; + break; + case PIPE_PRIM_POINTS: + case PIPE_PRIM_TRIANGLES: + adjust_x = -0.375; + adjust_y = -0.5; + break; } + prescale.translate[0] += adjust_x; + prescale.translate[1] += adjust_y; + prescale.translate[2] = 0.5; /* D3D clip space */ + prescale.scale[2] = 0.5; /* D3D clip space */ + } - range_min = viewport->scale[2] * -1.0 + viewport->translate[2]; - range_max = viewport->scale[2] * 1.0 + viewport->translate[2]; - /* D3D (and by implication SVGA) doesn't like dealing with zmax - * less than zmin. Detect that case, flip the depth range and - * invert our z-scale factor to achieve the same effect. - */ - if (range_min > range_max) { - float range_tmp; - range_tmp = range_min; - range_min = range_max; - range_max = range_tmp; - prescale.scale[2] = -prescale.scale[2]; - } + range_min = viewport->scale[2] * -1.0 + viewport->translate[2]; + range_max = viewport->scale[2] * 1.0 + viewport->translate[2]; + + /* D3D (and by implication SVGA) doesn't like dealing with zmax + * less than zmin. Detect that case, flip the depth range and + * invert our z-scale factor to achieve the same effect. + */ + if (range_min > range_max) { + float range_tmp; + range_tmp = range_min; + range_min = range_max; + range_max = range_tmp; + prescale.scale[2] = -prescale.scale[2]; } if (prescale.enabled) { diff --git a/src/gallium/drivers/svga/svga_state_need_swtnl.c b/src/gallium/drivers/svga/svga_state_need_swtnl.c index 94fe0bc9682..10d473584d1 100644 --- a/src/gallium/drivers/svga/svga_state_need_swtnl.c +++ b/src/gallium/drivers/svga/svga_state_need_swtnl.c @@ -43,7 +43,7 @@ svga_translate_vertex_format(enum pipe_format format) case PIPE_FORMAT_R32G32_FLOAT: return SVGA3D_DECLTYPE_FLOAT2; case PIPE_FORMAT_R32G32B32_FLOAT: return SVGA3D_DECLTYPE_FLOAT3; case PIPE_FORMAT_R32G32B32A32_FLOAT: return SVGA3D_DECLTYPE_FLOAT4; - case PIPE_FORMAT_B8G8R8A8_UNORM: return SVGA3D_DECLTYPE_D3DCOLOR; + case PIPE_FORMAT_A8R8G8B8_UNORM: return SVGA3D_DECLTYPE_D3DCOLOR; case PIPE_FORMAT_R8G8B8A8_USCALED: return SVGA3D_DECLTYPE_UBYTE4; case PIPE_FORMAT_R16G16_SSCALED: return SVGA3D_DECLTYPE_SHORT2; case PIPE_FORMAT_R16G16B16A16_SSCALED: return SVGA3D_DECLTYPE_SHORT4; @@ -129,8 +129,7 @@ static int update_need_pipeline( struct svga_context *svga, /* SVGA_NEW_CLIP */ - if (!svga->curr.rast->templ.bypass_vs_clip_and_viewport && - svga->curr.clip.nr) { + if (svga->curr.clip.nr) { SVGA_DBG(DEBUG_SWTNL, "%s: userclip\n", __FUNCTION__); need_pipeline = TRUE; } diff --git a/src/gallium/drivers/svga/svga_state_vdecl.c b/src/gallium/drivers/svga/svga_state_vdecl.c index 91854f65305..f531e223048 100644 --- a/src/gallium/drivers/svga/svga_state_vdecl.c +++ b/src/gallium/drivers/svga/svga_state_vdecl.c @@ -54,33 +54,30 @@ upload_user_buffers( struct svga_context *svga ) { if (svga_buffer_is_user_buffer(svga->curr.vb[i].buffer)) { - struct pipe_buffer *upload_buffer = NULL; - unsigned offset = /*svga->curr.vb[i].buffer_offset*/ 0; - unsigned size = svga->curr.vb[i].buffer->size /*- offset*/; - unsigned upload_offset; - - ret = u_upload_buffer( svga->upload_vb, - offset, - size, - svga->curr.vb[i].buffer, - &upload_offset, - &upload_buffer ); - if (ret) - return ret; - - if (0) - debug_printf("%s: %d: orig buf %p upl buf %p ofs %d sz %d\n", - __FUNCTION__, - i, - svga->curr.vb[i].buffer, - upload_buffer, upload_offset, size); - - /* Make sure we release the old buffer and end up with the - * correct refcount on the uploaded buffer. - */ - pipe_buffer_reference( &svga->curr.vb[i].buffer, NULL ); - svga->curr.vb[i].buffer = upload_buffer; - svga->curr.vb[i].buffer_offset = upload_offset; + struct svga_buffer *buffer = svga_buffer(svga->curr.vb[i].buffer); + + if (!buffer->uploaded.buffer) { + ret = u_upload_buffer( svga->upload_vb, + 0, + buffer->base.size, + &buffer->base, + &buffer->uploaded.offset, + &buffer->uploaded.buffer ); + if (ret) + return ret; + + if (0) + debug_printf("%s: %d: orig buf %p upl buf %p ofs %d sz %d\n", + __FUNCTION__, + i, + buffer, + buffer->uploaded.buffer, + buffer->uploaded.offset, + buffer->base.size); + } + + pipe_buffer_reference( &svga->curr.vb[i].buffer, buffer->uploaded.buffer ); + svga->curr.vb[i].buffer_offset = buffer->uploaded.offset; } } diff --git a/src/gallium/drivers/svga/svga_tgsi_emit.h b/src/gallium/drivers/svga/svga_tgsi_emit.h index e8f75485d55..48eced2ecea 100644 --- a/src/gallium/drivers/svga/svga_tgsi_emit.h +++ b/src/gallium/drivers/svga/svga_tgsi_emit.h @@ -138,6 +138,7 @@ static INLINE boolean emit_dst( struct svga_shader_emitter *emit, SVGA3dShaderDestToken dest ) { assert(dest.reserved0); + assert(dest.mask); return svga_shader_emit_dword( emit, dest.value ); } @@ -267,6 +268,7 @@ static INLINE SVGA3dShaderDestToken writemask( SVGA3dShaderDestToken dest, unsigned mask ) { + assert(dest.mask & mask); dest.mask &= mask; return dest; } diff --git a/src/gallium/drivers/svga/svga_tgsi_insn.c b/src/gallium/drivers/svga/svga_tgsi_insn.c index 6debd98b7a1..3d4f56a67bd 100644 --- a/src/gallium/drivers/svga/svga_tgsi_insn.c +++ b/src/gallium/drivers/svga/svga_tgsi_insn.c @@ -112,6 +112,7 @@ translate_dst_register( struct svga_shader_emitter *emit, } dest.mask = reg->Register.WriteMask; + assert(dest.mask); if (insn->Instruction.Saturate) dest.dstMod = SVGA3DDSTMOD_SATURATE; @@ -1410,34 +1411,42 @@ static boolean emit_tex(struct svga_shader_emitter *emit, if (compare) { - SVGA3dShaderDestToken src0_zdivw = get_temp( emit ); - struct src_register tex_src_x = scalar(src(tex_result), TGSI_SWIZZLE_Y); - struct src_register one = - scalar( get_zero_immediate( emit ), TGSI_SWIZZLE_W ); - - /* Divide texcoord R by Q */ - if (!submit_op1( emit, inst_token( SVGA3DOP_RCP ), - src0_zdivw, - scalar(src0, TGSI_SWIZZLE_W) )) - return FALSE; + if (dst.mask & TGSI_WRITEMASK_XYZ) { + SVGA3dShaderDestToken src0_zdivw = get_temp( emit ); + struct src_register tex_src_x = scalar(src(tex_result), TGSI_SWIZZLE_Y); + + /* Divide texcoord R by Q */ + if (!submit_op1( emit, inst_token( SVGA3DOP_RCP ), + writemask(src0_zdivw, TGSI_WRITEMASK_X), + scalar(src0, TGSI_SWIZZLE_W) )) + return FALSE; - if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), - src0_zdivw, - scalar(src0, TGSI_SWIZZLE_Z), - src(src0_zdivw) )) - return FALSE; + if (!submit_op2( emit, inst_token( SVGA3DOP_MUL ), + writemask(src0_zdivw, TGSI_WRITEMASK_X), + scalar(src0, TGSI_SWIZZLE_Z), + scalar(src(src0_zdivw), TGSI_SWIZZLE_X) )) + return FALSE; - if (!emit_select( - emit, - emit->key.fkey.tex[src1.base.num].compare_func, - dst, - src(src0_zdivw), - tex_src_x)) - return FALSE; + if (!emit_select( + emit, + emit->key.fkey.tex[src1.base.num].compare_func, + writemask( dst, TGSI_WRITEMASK_XYZ ), + scalar(src(src0_zdivw), TGSI_SWIZZLE_X), + tex_src_x)) + return FALSE; + } - return submit_op1( emit, inst_token( SVGA3DOP_MOV ), - writemask( dst, TGSI_WRITEMASK_W), - one ); + if (dst.mask & TGSI_WRITEMASK_W) { + struct src_register one = + scalar( get_zero_immediate( emit ), TGSI_SWIZZLE_W ); + + if (!submit_op1( emit, inst_token( SVGA3DOP_MOV ), + writemask( dst, TGSI_WRITEMASK_W ), + one )) + return FALSE; + } + + return TRUE; } else if (!emit->use_sm30 && dst.mask != TGSI_WRITEMASK_XYZW) { @@ -1811,6 +1820,8 @@ static boolean emit_exp(struct svga_shader_emitter *emit, fraction = dst; else if (dst.mask & TGSI_WRITEMASK_X) fraction = get_temp( emit ); + else + fraction.value = 0; /* If y is being written, fill it with src0 - floor(src0). */ @@ -1825,13 +1836,13 @@ static boolean emit_exp(struct svga_shader_emitter *emit, */ if (dst.mask & TGSI_WRITEMASK_X) { if (!submit_op2( emit, inst_token( SVGA3DOP_ADD ), - writemask( dst, dst.mask & TGSI_WRITEMASK_X ), + writemask( dst, TGSI_WRITEMASK_X ), src0, scalar( negate( src( fraction ) ), TGSI_SWIZZLE_Y ) ) ) return FALSE; if (!submit_op1( emit, inst_token( SVGA3DOP_EXP ), - writemask( dst, dst.mask & TGSI_WRITEMASK_X ), + writemask( dst, TGSI_WRITEMASK_X ), scalar( src( dst ), TGSI_SWIZZLE_X ) ) ) return FALSE; @@ -1843,7 +1854,7 @@ static boolean emit_exp(struct svga_shader_emitter *emit, */ if (dst.mask & TGSI_WRITEMASK_Z) { if (!submit_op1( emit, inst_token( SVGA3DOP_EXPP ), - writemask( dst, dst.mask & TGSI_WRITEMASK_Z ), + writemask( dst, TGSI_WRITEMASK_Z ), src0 ) ) return FALSE; } @@ -2005,10 +2016,14 @@ static boolean emit_log(struct svga_shader_emitter *emit, struct src_register abs_src0; SVGA3dShaderDestToken log2_abs; + abs_tmp.value = 0; + if (dst.mask & TGSI_WRITEMASK_Z) log2_abs = dst; else if (dst.mask & TGSI_WRITEMASK_XY) log2_abs = get_temp( emit ); + else + log2_abs.value = 0; /* If z is being written, fill it with log2( abs( src0 ) ). */ diff --git a/src/gallium/drivers/svga/svga_winsys.h b/src/gallium/drivers/svga/svga_winsys.h index b4e3af0eafc..d4bb176f9a8 100644 --- a/src/gallium/drivers/svga/svga_winsys.h +++ b/src/gallium/drivers/svga/svga_winsys.h @@ -51,6 +51,7 @@ struct pipe_context; struct pipe_fence_handle; struct pipe_texture; struct svga_region; +struct winsys_handle; #define SVGA_BUFFER_USAGE_PINNED (PIPE_BUFFER_USAGE_CUSTOM << 0) @@ -187,6 +188,25 @@ struct svga_winsys_screen uint32 numMipLevels); /** + * Creates a surface from a winsys handle. + * Used to implement pipe_screen::texture_from_handle. + */ + struct svga_winsys_surface * + (*surface_from_handle)(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format); + + /** + * Get a winsys_handle from a surface. + * Used to implement pipe_screen::texture_get_handle. + */ + boolean + (*surface_get_handle)(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle); + + /** * Whether this surface is sitting in a validate list */ boolean @@ -284,19 +304,6 @@ svga_screen_buffer_wrap_surface(struct pipe_screen *screen, struct svga_winsys_surface *srf); struct svga_winsys_surface * -svga_screen_texture_get_winsys_surface(struct pipe_texture *texture); -struct svga_winsys_surface * svga_screen_buffer_get_winsys_surface(struct pipe_buffer *buffer); -boolean -svga_screen_buffer_from_texture(struct pipe_texture *texture, - struct pipe_buffer **buffer, - unsigned *stride); - -struct pipe_texture * -svga_screen_texture_wrap_surface(struct pipe_screen *screen, - struct pipe_texture *base, - enum SVGA3dSurfaceFormat format, - struct svga_winsys_surface *srf); - #endif /* SVGA_WINSYS_H_ */ diff --git a/src/gallium/drivers/trace/tr_drm.c b/src/gallium/drivers/trace/tr_drm.c index 919dc1b309f..c16989fa529 100644 --- a/src/gallium/drivers/trace/tr_drm.c +++ b/src/gallium/drivers/trace/tr_drm.c @@ -28,11 +28,11 @@ #include "state_tracker/drm_api.h" #include "util/u_memory.h" -#include "trace/tr_drm.h" -#include "trace/tr_screen.h" -#include "trace/tr_context.h" -#include "trace/tr_buffer.h" -#include "trace/tr_texture.h" +#include "tr_drm.h" +#include "tr_screen.h" +#include "tr_context.h" +#include "tr_buffer.h" +#include "tr_texture.h" struct trace_drm_api { @@ -62,69 +62,8 @@ trace_drm_create_screen(struct drm_api *_api, int fd, screen = api->create_screen(api, fd, arg); - return trace_screen_create(screen); -} - - -static struct pipe_texture * -trace_drm_texture_from_shared_handle(struct drm_api *_api, - struct pipe_screen *_screen, - struct pipe_texture *templ, - const char *name, - unsigned stride, - unsigned handle) -{ - struct trace_screen *tr_screen = trace_screen(_screen); - struct trace_drm_api *tr_api = trace_drm_api(_api); - struct pipe_screen *screen = tr_screen->screen; - struct drm_api *api = tr_api->api; - struct pipe_texture *result; - - /* TODO trace call */ - - result = api->texture_from_shared_handle(api, screen, templ, name, stride, handle); - - result = trace_texture_create(trace_screen(_screen), result); - - return result; -} - -static boolean -trace_drm_shared_handle_from_texture(struct drm_api *_api, - struct pipe_screen *_screen, - struct pipe_texture *_texture, - unsigned *stride, - unsigned *handle) -{ - struct trace_screen *tr_screen = trace_screen(_screen); - struct trace_texture *tr_texture = trace_texture(_texture); - struct trace_drm_api *tr_api = trace_drm_api(_api); - struct pipe_screen *screen = tr_screen->screen; - struct pipe_texture *texture = tr_texture->texture; - struct drm_api *api = tr_api->api; - - /* TODO trace call */ - - return api->shared_handle_from_texture(api, screen, texture, stride, handle); -} -static boolean -trace_drm_local_handle_from_texture(struct drm_api *_api, - struct pipe_screen *_screen, - struct pipe_texture *_texture, - unsigned *stride, - unsigned *handle) -{ - struct trace_screen *tr_screen = trace_screen(_screen); - struct trace_texture *tr_texture = trace_texture(_texture); - struct trace_drm_api *tr_api = trace_drm_api(_api); - struct pipe_screen *screen = tr_screen->screen; - struct pipe_texture *texture = tr_texture->texture; - struct drm_api *api = tr_api->api; - - /* TODO trace call */ - - return api->local_handle_from_texture(api, screen, texture, stride, handle); + return trace_screen_create(screen); } static void @@ -155,11 +94,9 @@ trace_drm_create(struct drm_api *api) if (!tr_api) goto error; + tr_api->base.name = api->name; tr_api->base.driver_name = api->driver_name; tr_api->base.create_screen = trace_drm_create_screen; - tr_api->base.texture_from_shared_handle = trace_drm_texture_from_shared_handle; - tr_api->base.shared_handle_from_texture = trace_drm_shared_handle_from_texture; - tr_api->base.local_handle_from_texture = trace_drm_local_handle_from_texture; tr_api->base.destroy = trace_drm_destroy; tr_api->api = api; diff --git a/src/gallium/drivers/trace/tr_dump_state.c b/src/gallium/drivers/trace/tr_dump_state.c index b9ccc0ca694..f82dd01c697 100644 --- a/src/gallium/drivers/trace/tr_dump_state.c +++ b/src/gallium/drivers/trace/tr_dump_state.c @@ -112,7 +112,6 @@ void trace_dump_rasterizer_state(const struct pipe_rasterizer_state *state) trace_dump_member(uint, state, line_stipple_factor); trace_dump_member(uint, state, line_stipple_pattern); trace_dump_member(bool, state, line_last_pixel); - trace_dump_member(bool, state, bypass_vs_clip_and_viewport); trace_dump_member(bool, state, flatshade_first); trace_dump_member(bool, state, gl_rasterization_rules); diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c index 388d83eb5c2..a15addeb8cf 100644 --- a/src/gallium/drivers/trace/tr_screen.c +++ b/src/gallium/drivers/trace/tr_screen.c @@ -236,39 +236,41 @@ trace_screen_texture_create(struct pipe_screen *_screen, return result; } - static struct pipe_texture * -trace_screen_texture_blanket(struct pipe_screen *_screen, - const struct pipe_texture *templat, - const unsigned *ppitch, - struct pipe_buffer *_buffer) +trace_screen_texture_from_handle(struct pipe_screen *_screen, + const struct pipe_texture *templ, + struct winsys_handle *handle) { - struct trace_screen *tr_scr = trace_screen(_screen); - struct trace_buffer *tr_buf = trace_buffer(_buffer); - struct pipe_screen *screen = tr_scr->screen; - struct pipe_buffer *buffer = tr_buf->buffer; - unsigned pitch = *ppitch; + struct trace_screen *tr_screen = trace_screen(_screen); + struct pipe_screen *screen = tr_screen->screen; struct pipe_texture *result; - trace_dump_call_begin("pipe_screen", "texture_blanket"); + /* TODO trace call */ - trace_dump_arg(ptr, screen); - trace_dump_arg(template, templat); - trace_dump_arg(uint, pitch); - trace_dump_arg(ptr, buffer); + result = screen->texture_from_handle(screen, templ, handle); - result = screen->texture_blanket(screen, templat, ppitch, buffer); + result = trace_texture_create(trace_screen(_screen), result); - trace_dump_ret(ptr, result); + return result; +} - trace_dump_call_end(); +static boolean +trace_screen_texture_get_handle(struct pipe_screen *_screen, + struct pipe_texture *_texture, + struct winsys_handle *handle) +{ + struct trace_screen *tr_screen = trace_screen(_screen); + struct trace_texture *tr_texture = trace_texture(_texture); + struct pipe_screen *screen = tr_screen->screen; + struct pipe_texture *texture = tr_texture->texture; - result = trace_texture_create(tr_scr, result); + /* TODO trace call */ - return result; + return screen->texture_get_handle(screen, texture, handle); } + static void trace_screen_texture_destroy(struct pipe_texture *_texture) { @@ -484,45 +486,7 @@ trace_screen_transfer_unmap(struct pipe_screen *_screen, */ -static struct pipe_buffer * -trace_screen_surface_buffer_create(struct pipe_screen *_screen, - unsigned width, unsigned height, - enum pipe_format format, - unsigned usage, - unsigned tex_usage, - unsigned *pstride) -{ - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - unsigned stride; - struct pipe_buffer *result; - - trace_dump_call_begin("pipe_screen", "surface_buffer_create"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(uint, width); - trace_dump_arg(uint, height); - trace_dump_arg(format, format); - trace_dump_arg(uint, usage); - trace_dump_arg(uint, tex_usage); - result = screen->surface_buffer_create(screen, - width, height, - format, - usage, - tex_usage, - pstride); - - stride = *pstride; - - trace_dump_arg(uint, stride); - - trace_dump_ret(ptr, result); - - trace_dump_call_end(); - - return trace_buffer_create(tr_scr, result); -} static struct pipe_buffer * @@ -931,7 +895,8 @@ trace_screen_create(struct pipe_screen *screen) assert(screen->context_create); tr_scr->base.context_create = trace_screen_context_create; tr_scr->base.texture_create = trace_screen_texture_create; - tr_scr->base.texture_blanket = trace_screen_texture_blanket; + tr_scr->base.texture_from_handle = trace_screen_texture_from_handle; + tr_scr->base.texture_get_handle = trace_screen_texture_get_handle; tr_scr->base.texture_destroy = trace_screen_texture_destroy; tr_scr->base.get_tex_surface = trace_screen_get_tex_surface; tr_scr->base.tex_surface_destroy = trace_screen_tex_surface_destroy; @@ -941,7 +906,6 @@ trace_screen_create(struct pipe_screen *screen) tr_scr->base.transfer_unmap = trace_screen_transfer_unmap; tr_scr->base.buffer_create = trace_screen_buffer_create; tr_scr->base.user_buffer_create = trace_screen_user_buffer_create; - tr_scr->base.surface_buffer_create = trace_screen_surface_buffer_create; if (screen->buffer_map) tr_scr->base.buffer_map = trace_screen_buffer_map; if (screen->buffer_map_range) diff --git a/src/gallium/include/pipe/p_compiler.h b/src/gallium/include/pipe/p_compiler.h index c7d35074948..b93b38310ac 100644 --- a/src/gallium/include/pipe/p_compiler.h +++ b/src/gallium/include/pipe/p_compiler.h @@ -106,8 +106,7 @@ typedef unsigned char boolean; /* Function visibility */ #ifndef PUBLIC -# if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303) \ - || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) +# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) # define PUBLIC __attribute__((visibility("default"))) # else # define PUBLIC @@ -119,7 +118,7 @@ typedef unsigned char boolean; * If we're not using gcc, define __FUNCTION__ as a cpp symbol here. */ #ifndef __FUNCTION__ -# if (!defined(__GNUC__) || (__GNUC__ < 2)) +# if !defined(__GNUC__) # if (__STDC_VERSION__ >= 199901L) /* C99 */ || \ (defined(__SUNPRO_C) && defined(__C99FEATURES__)) # define __FUNCTION__ __func__ @@ -145,7 +144,7 @@ typedef unsigned char boolean; -#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) +#if defined(__GNUC__) #define PIPE_DEPRECATED __attribute__((__deprecated__)) #else #define PIPE_DEPRECATED diff --git a/src/gallium/include/pipe/p_defines.h b/src/gallium/include/pipe/p_defines.h index 5cebd43ace2..5c97dc87e82 100644 --- a/src/gallium/include/pipe/p_defines.h +++ b/src/gallium/include/pipe/p_defines.h @@ -176,11 +176,12 @@ enum pipe_texture_target { #define PIPE_TEX_COMPARE_R_TO_TEXTURE 1 #define PIPE_TEXTURE_USAGE_RENDER_TARGET 0x1 -#define PIPE_TEXTURE_USAGE_DISPLAY_TARGET 0x2 /* ie a backbuffer */ -#define PIPE_TEXTURE_USAGE_PRIMARY 0x4 /* ie a frontbuffer */ +#define PIPE_TEXTURE_USAGE_DISPLAY_TARGET 0x2 /* windows presentable buffer, ie a backbuffer */ +#define PIPE_TEXTURE_USAGE_SCANOUT 0x4 /* ie a frontbuffer */ #define PIPE_TEXTURE_USAGE_DEPTH_STENCIL 0x8 #define PIPE_TEXTURE_USAGE_SAMPLER 0x10 #define PIPE_TEXTURE_USAGE_DYNAMIC 0x20 +#define PIPE_TEXTURE_USAGE_SHARED 0x40 /** Pipe driver custom usage flags should be greater or equal to this value */ #define PIPE_TEXTURE_USAGE_CUSTOM (1 << 16) diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h index f33b0639ef9..cbf3273ec8d 100644 --- a/src/gallium/include/pipe/p_format.h +++ b/src/gallium/include/pipe/p_format.h @@ -45,28 +45,28 @@ extern "C" { enum pipe_format { PIPE_FORMAT_NONE = 0, - PIPE_FORMAT_A8R8G8B8_UNORM = 1, - PIPE_FORMAT_X8R8G8B8_UNORM = 2, - PIPE_FORMAT_B8G8R8A8_UNORM = 3, - PIPE_FORMAT_B8G8R8X8_UNORM = 4, - PIPE_FORMAT_A1R5G5B5_UNORM = 5, - PIPE_FORMAT_A4R4G4B4_UNORM = 6, - PIPE_FORMAT_R5G6B5_UNORM = 7, - PIPE_FORMAT_A2B10G10R10_UNORM = 8, + PIPE_FORMAT_B8G8R8A8_UNORM = 1, + PIPE_FORMAT_B8G8R8X8_UNORM = 2, + PIPE_FORMAT_A8R8G8B8_UNORM = 3, + PIPE_FORMAT_X8R8G8B8_UNORM = 4, + PIPE_FORMAT_B5G5R5A1_UNORM = 5, + PIPE_FORMAT_B4G4R4A4_UNORM = 6, + PIPE_FORMAT_B5G6R5_UNORM = 7, + PIPE_FORMAT_R10G10B10A2_UNORM = 8, PIPE_FORMAT_L8_UNORM = 9, /**< ubyte luminance */ PIPE_FORMAT_A8_UNORM = 10, /**< ubyte alpha */ PIPE_FORMAT_I8_UNORM = 11, /**< ubyte intensity */ - PIPE_FORMAT_A8L8_UNORM = 12, /**< ubyte alpha, luminance */ + PIPE_FORMAT_L8A8_UNORM = 12, /**< ubyte alpha, luminance */ PIPE_FORMAT_L16_UNORM = 13, /**< ushort luminance */ - PIPE_FORMAT_YCBCR = 14, - PIPE_FORMAT_YCBCR_REV = 15, + PIPE_FORMAT_UYVY = 14, + PIPE_FORMAT_YUYV = 15, PIPE_FORMAT_Z16_UNORM = 16, PIPE_FORMAT_Z32_UNORM = 17, PIPE_FORMAT_Z32_FLOAT = 18, - PIPE_FORMAT_S8Z24_UNORM = 19, - PIPE_FORMAT_Z24S8_UNORM = 20, - PIPE_FORMAT_X8Z24_UNORM = 21, - PIPE_FORMAT_Z24X8_UNORM = 22, + PIPE_FORMAT_Z24S8_UNORM = 19, + PIPE_FORMAT_S8Z24_UNORM = 20, + PIPE_FORMAT_Z24X8_UNORM = 21, + PIPE_FORMAT_X8Z24_UNORM = 22, PIPE_FORMAT_S8_UNORM = 23, /**< ubyte stencil */ PIPE_FORMAT_R64_FLOAT = 24, PIPE_FORMAT_R64G64_FLOAT = 25, @@ -112,43 +112,37 @@ enum pipe_format { PIPE_FORMAT_R8G8_UNORM = 65, PIPE_FORMAT_R8G8B8_UNORM = 66, PIPE_FORMAT_R8G8B8A8_UNORM = 67, - PIPE_FORMAT_R8G8B8X8_UNORM = 68, + PIPE_FORMAT_X8B8G8R8_UNORM = 68, PIPE_FORMAT_R8_USCALED = 69, PIPE_FORMAT_R8G8_USCALED = 70, PIPE_FORMAT_R8G8B8_USCALED = 71, PIPE_FORMAT_R8G8B8A8_USCALED = 72, - PIPE_FORMAT_R8G8B8X8_USCALED = 73, PIPE_FORMAT_R8_SNORM = 74, PIPE_FORMAT_R8G8_SNORM = 75, PIPE_FORMAT_R8G8B8_SNORM = 76, PIPE_FORMAT_R8G8B8A8_SNORM = 77, - PIPE_FORMAT_R8G8B8X8_SNORM = 78, - PIPE_FORMAT_B6G5R5_SNORM = 79, - PIPE_FORMAT_A8B8G8R8_SNORM = 80, - PIPE_FORMAT_X8B8G8R8_SNORM = 81, PIPE_FORMAT_R8_SSCALED = 82, PIPE_FORMAT_R8G8_SSCALED = 83, PIPE_FORMAT_R8G8B8_SSCALED = 84, PIPE_FORMAT_R8G8B8A8_SSCALED = 85, - PIPE_FORMAT_R8G8B8X8_SSCALED = 86, PIPE_FORMAT_R32_FIXED = 87, PIPE_FORMAT_R32G32_FIXED = 88, PIPE_FORMAT_R32G32B32_FIXED = 89, PIPE_FORMAT_R32G32B32A32_FIXED = 90, /* sRGB formats */ PIPE_FORMAT_L8_SRGB = 91, - PIPE_FORMAT_A8L8_SRGB = 92, + PIPE_FORMAT_L8A8_SRGB = 92, PIPE_FORMAT_R8G8B8_SRGB = 93, - PIPE_FORMAT_R8G8B8A8_SRGB = 94, - PIPE_FORMAT_R8G8B8X8_SRGB = 95, - PIPE_FORMAT_A8R8G8B8_SRGB = 96, - PIPE_FORMAT_X8R8G8B8_SRGB = 97, - PIPE_FORMAT_B8G8R8A8_SRGB = 98, - PIPE_FORMAT_B8G8R8X8_SRGB = 99, + PIPE_FORMAT_A8B8G8R8_SRGB = 94, + PIPE_FORMAT_X8B8G8R8_SRGB = 95, + PIPE_FORMAT_B8G8R8A8_SRGB = 96, + PIPE_FORMAT_B8G8R8X8_SRGB = 97, + PIPE_FORMAT_A8R8G8B8_SRGB = 98, + PIPE_FORMAT_X8R8G8B8_SRGB = 99, /* mixed formats */ - PIPE_FORMAT_X8UB8UG8SR8S_NORM = 100, - PIPE_FORMAT_B6UG5SR5S_NORM = 101, + PIPE_FORMAT_R8SG8SB8UX8U_NORM = 100, + PIPE_FORMAT_R5SG5SB6U_NORM = 101, /* compressed formats */ PIPE_FORMAT_DXT1_RGB = 102, @@ -162,6 +156,8 @@ enum pipe_format { PIPE_FORMAT_DXT3_SRGBA = 108, PIPE_FORMAT_DXT5_SRGBA = 109, + PIPE_FORMAT_A8B8G8R8_UNORM = 110, + PIPE_FORMAT_COUNT }; diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index 48625bf3127..690455f7222 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -50,6 +50,8 @@ extern "C" { /** Opaque type */ +struct winsys_handle; +/** Opaque type */ struct pipe_fence_handle; struct pipe_winsys; struct pipe_buffer; @@ -108,20 +110,29 @@ struct pipe_screen { const struct pipe_texture *templat); /** - * Create a new texture object, using the given template info, but on top of - * existing memory. - * - * It is assumed that the buffer data is layed out according to the expected - * by the hardware. NULL will be returned if any inconsistency is found. + * Create a texture from a winsys_handle. The handle is often created in + * another process by first creating a pipe texture and then calling + * texture_get_handle. + */ + struct pipe_texture * (*texture_from_handle)(struct pipe_screen *, + const struct pipe_texture *templat, + struct winsys_handle *handle); + + /** + * Get a winsys_handle from a texture. Some platforms/winsys requires + * that the texture is created with a special usage flag like + * DISPLAYTARGET or PRIMARY. */ - struct pipe_texture * (*texture_blanket)(struct pipe_screen *, - const struct pipe_texture *templat, - const unsigned *stride, - struct pipe_buffer *buffer); + boolean (*texture_get_handle)(struct pipe_screen *, + struct pipe_texture *tex, + struct winsys_handle *handle); + void (*texture_destroy)(struct pipe_texture *pt); - /** Get a surface which is a "view" into a texture */ + /** Get a 2D surface which is a "view" into a texture + * \param usage bitmaks of PIPE_BUFFER_USAGE_* read/write flags + */ struct pipe_surface *(*get_tex_surface)(struct pipe_screen *, struct pipe_texture *texture, unsigned face, unsigned level, @@ -185,23 +196,6 @@ struct pipe_screen { void *ptr, unsigned bytes); - /** - * Allocate storage for a display target surface. - * - * Often surfaces which are meant to be blitted to the front screen (i.e., - * display targets) must be allocated with special characteristics, memory - * pools, or obtained directly from the windowing system. - * - * This callback is invoked by the pipe_screenwhen creating a texture marked - * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying - * buffer storage. - */ - struct pipe_buffer *(*surface_buffer_create)(struct pipe_screen *screen, - unsigned width, unsigned height, - enum pipe_format format, - unsigned usage, - unsigned tex_usage, - unsigned *stride); /** diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 5670f7a0887..3a97d888ce6 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -114,16 +114,6 @@ struct pipe_rasterizer_state unsigned line_last_pixel:1; /** - * Vertex coordinates are pre-transformed to screen space. Skip - * the vertex shader, clipping and viewport processing. Note that - * a vertex shader is still needed though, to indicate the mapping - * from vertex elements to fragment shader input semantics. - * - * XXX: considered for removal. - */ - unsigned bypass_vs_clip_and_viewport:1; - - /** * Use the first vertex of a primitive as the provoking vertex for * flat shading. */ @@ -259,7 +249,7 @@ struct pipe_framebuffer_state { unsigned width, height; - /** multiple colorbuffers for multiple render targets */ + /** multiple color buffers for multiple render targets */ unsigned nr_cbufs; struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS]; @@ -295,12 +285,12 @@ struct pipe_sampler_state struct pipe_surface { struct pipe_reference reference; - enum pipe_format format; /**< PIPE_FORMAT_x */ + enum pipe_format format; unsigned width; /**< logical width in pixels */ unsigned height; /**< logical height in pixels */ unsigned layout; /**< PIPE_SURFACE_LAYOUT_x */ unsigned offset; /**< offset from start of buffer, in bytes */ - unsigned usage; /**< PIPE_BUFFER_USAGE_* */ + unsigned usage; /**< bitmask of PIPE_BUFFER_USAGE_x */ unsigned zslice; struct pipe_texture *texture; /**< texture into which this is a view */ @@ -346,7 +336,7 @@ struct pipe_texture unsigned nr_samples:8; /**< for multisampled surfaces, nr of samples */ - unsigned tex_usage; /* PIPE_TEXTURE_USAGE_* */ + unsigned tex_usage; /**< bitmask of PIPE_TEXTURE_USAGE_* */ struct pipe_screen *screen; /**< screen that this texture belongs to */ }; @@ -384,7 +374,7 @@ struct pipe_vertex_element */ unsigned vertex_buffer_index:8; - enum pipe_format src_format; /**< PIPE_FORMAT_* */ + enum pipe_format src_format; }; diff --git a/src/gallium/include/state_tracker/drm_api.h b/src/gallium/include/state_tracker/drm_api.h index e9fa9b4d2a3..fe7ef253ef0 100644 --- a/src/gallium/include/state_tracker/drm_api.h +++ b/src/gallium/include/state_tracker/drm_api.h @@ -17,6 +17,32 @@ enum drm_create_screen_mode { DRM_CREATE_MAX }; +#define DRM_API_HANDLE_TYPE_SHARED 0 +#define DRM_API_HANDLE_TYPE_KMS 1 + +/** + * For use with pipe_screen::{texture_from_handle|texture_get_handle}. + */ +struct winsys_handle +{ + /** + * Unused for texture_from_handle, always + * DRM_API_HANDLE_TYPE_SHARED. Input to texture_get_handle, + * use TEXTURE_USAGE to select handle for kms or ipc. + */ + unsigned type; + /** + * Input to texture_from_handle. + * Output for texture_get_handle. + */ + unsigned handle; + /** + * Input to texture_from_handle. + * Output for texture_get_handle. + */ + unsigned stride; +}; + /** * Modes other than DRM_CREATE_NORMAL derive from this struct. */ @@ -28,6 +54,8 @@ struct drm_create_screen_arg { struct drm_api { + void (*destroy)(struct drm_api *api); + const char *name; /** @@ -36,37 +64,10 @@ struct drm_api const char *driver_name; /** - * Special buffer functions + * Create a pipe srcreen. */ - /*@{*/ struct pipe_screen* (*create_screen)(struct drm_api *api, int drm_fd, struct drm_create_screen_arg *arg); - /*@}*/ - - /** - * Special buffer functions - */ - /*@{*/ - struct pipe_texture* - (*texture_from_shared_handle)(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *templ, - const char *name, - unsigned stride, - unsigned handle); - boolean (*shared_handle_from_texture)(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *stride, - unsigned *handle); - boolean (*local_handle_from_texture)(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *stride, - unsigned *handle); - /*@}*/ - - void (*destroy)(struct drm_api *api); }; extern struct drm_api * drm_api_create(void); diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index 5033c3c85b8..908cef454e9 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -166,10 +166,8 @@ dri_make_current(__DRIcontext * cPriv, if (__dri1_api_hooks) { dri1_update_drawables(ctx, draw, read); } else { - if (driDrawPriv) - dri_get_buffers(driDrawPriv); - if (driDrawPriv != driReadPriv && driReadPriv) - dri_get_buffers(driReadPriv); + dri_update_buffer(ctx->pipe->screen, + ctx->pipe->priv); } } else { st_make_current(NULL, NULL, NULL); diff --git a/src/gallium/state_trackers/dri/dri_drawable.c b/src/gallium/state_trackers/dri/dri_drawable.c index 97277c05072..458473853cf 100644 --- a/src/gallium/state_trackers/dri/dri_drawable.c +++ b/src/gallium/state_trackers/dri/dri_drawable.c @@ -58,6 +58,7 @@ dri_surface_from_handle(struct drm_api *api, struct pipe_surface *surface = NULL; struct pipe_texture *texture = NULL; struct pipe_texture templat; + struct winsys_handle whandle; memset(&templat, 0, sizeof(templat)); templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET; @@ -68,8 +69,11 @@ dri_surface_from_handle(struct drm_api *api, templat.width0 = width; templat.height0 = height; - texture = api->texture_from_shared_handle(api, screen, &templat, - "dri2 buffer", pitch, handle); + memset(&whandle, 0, sizeof(whandle)); + whandle.handle = handle; + whandle.stride = pitch; + + texture = screen->texture_from_handle(screen, &templat, &whandle); if (!texture) { debug_printf("%s: Failed to blanket the buffer with a texture\n", __func__); @@ -134,12 +138,13 @@ dri_get_buffers(__DRIdrawable * dPriv) if ((dri_screen->dri2.loader && (dri_screen->dri2.loader->base.version > 2) - && (dri_screen->dri2.loader->getBuffersWithFormat != NULL))) + && (dri_screen->dri2.loader->getBuffersWithFormat != NULL))) { buffers = (*dri_screen->dri2.loader->getBuffersWithFormat) (dri_drawable, &dri_drawable->w, &dri_drawable->h, drawable->attachments, drawable->num_attachments, &count, dri_drawable->loaderPrivate); - else + } else { + assert(dri_screen->dri2.loader); buffers = (*dri_screen->dri2.loader->getBuffers) (dri_drawable, &dri_drawable->w, &dri_drawable->h, @@ -148,6 +153,7 @@ dri_get_buffers(__DRIdrawable * dPriv) num_attachments, &count, dri_drawable-> loaderPrivate); + } if (buffers == NULL) { return; @@ -284,7 +290,18 @@ dri_update_buffer(struct pipe_screen *screen, void *context_private) { struct dri_context *ctx = (struct dri_context *)context_private; + if (ctx->d_stamp == *ctx->dPriv->pStamp && + ctx->r_stamp == *ctx->rPriv->pStamp) + return; + + ctx->d_stamp = *ctx->dPriv->pStamp; + ctx->r_stamp = *ctx->rPriv->pStamp; + + /* Ask the X server for new renderbuffers. */ dri_get_buffers(ctx->dPriv); + if (ctx->dPriv != ctx->rPriv) + dri_get_buffers(ctx->rPriv); + } void @@ -336,11 +353,11 @@ dri_create_buffer(__DRIscreen * sPriv, if (visual->redBits == 8) { if (visual->alphaBits == 8) - drawable->color_format = PIPE_FORMAT_A8R8G8B8_UNORM; + drawable->color_format = PIPE_FORMAT_B8G8R8A8_UNORM; else - drawable->color_format = PIPE_FORMAT_X8R8G8B8_UNORM; + drawable->color_format = PIPE_FORMAT_B8G8R8X8_UNORM; } else { - drawable->color_format = PIPE_FORMAT_R5G6B5_UNORM; + drawable->color_format = PIPE_FORMAT_B5G6R5_UNORM; } switch(visual->depthBits) { @@ -354,12 +371,12 @@ dri_create_buffer(__DRIscreen * sPriv, case 24: if (visual->stencilBits == 0) { drawable->depth_stencil_format = (screen->d_depth_bits_last) ? - PIPE_FORMAT_X8Z24_UNORM: - PIPE_FORMAT_Z24X8_UNORM; + PIPE_FORMAT_Z24X8_UNORM: + PIPE_FORMAT_X8Z24_UNORM; } else { drawable->depth_stencil_format = (screen->sd_depth_bits_last) ? - PIPE_FORMAT_S8Z24_UNORM: - PIPE_FORMAT_Z24S8_UNORM; + PIPE_FORMAT_Z24S8_UNORM: + PIPE_FORMAT_S8Z24_UNORM; } break; case 32: diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index b36ea43db5f..60bc560049c 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -61,6 +61,17 @@ static const __DRItexBufferExtension dri2TexBufferExtension = { dri2_set_tex_buffer2, }; +static void +dri2_flush_drawable(__DRIdrawable *draw) +{ +} + +static const __DRI2flushExtension dri2FlushExtension = { + { __DRI2_FLUSH, __DRI2_FLUSH_VERSION }, + dri2_flush_drawable, + dri2InvalidateDrawable, +}; + static const __DRIextension *dri_screen_extensions[] = { &driReadDrawableExtension, &driCopySubBufferExtension.base, @@ -68,6 +79,7 @@ static const __DRItexBufferExtension dri2TexBufferExtension = { &driFrameTrackingExtension.base, &driMediaStreamCounterExtension.base, &dri2TexBufferExtension.base, + &dri2FlushExtension.base, NULL }; @@ -97,22 +109,22 @@ dri_fill_in_modes(struct dri_screen *screen, stencil_bits_array[0] = 0; depth_buffer_factor = 1; - pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8Z24_UNORM, + pf_x8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_z24x8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24X8_UNORM, + pf_z24x8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8Z24_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_s8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_S8Z24_UNORM, + pf_s8z24 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24S8_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_z24s8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z24S8_UNORM, + pf_z24s8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_S8Z24_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_a8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_A8R8G8B8_UNORM, + pf_a8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8A8_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); - pf_x8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_X8R8G8B8_UNORM, + pf_x8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); @@ -127,7 +139,7 @@ dri_fill_in_modes(struct dri_screen *screen, pf_z32 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z32_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); - pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_R5G6B5_UNORM, + pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); } else { diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c index 80dd1269955..50774b03f35 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.c +++ b/src/gallium/state_trackers/egl/common/egl_g3d.c @@ -36,6 +36,7 @@ #include "native.h" #include "egl_g3d.h" +#include "egl_g3d_image.h" #include "egl_st.h" /** @@ -528,15 +529,27 @@ static void egl_g3d_update_buffer(struct pipe_screen *screen, void *context_private) { struct egl_g3d_context *gctx = egl_g3d_context(context_private); - - /** - * It is likely that the surface has changed when this function is called. - * Set force_validate to skip an unnecessary check. - */ - gctx->force_validate = EGL_TRUE; egl_g3d_validate_context(gctx->base.Resource.Display, &gctx->base); } +static void +egl_g3d_invalid_surface(struct native_display *ndpy, + struct native_surface *nsurf, + unsigned int seq_num) +{ + /* XXX not thread safe? */ + struct egl_g3d_surface *gsurf = egl_g3d_surface(nsurf->user_data); + struct egl_g3d_context *gctx = egl_g3d_context(gsurf->base.CurrentContext); + + /* set force_validate to skip an unnecessary check */ + if (gctx) + gctx->force_validate = TRUE; +} + +static struct native_event_handler egl_g3d_native_event_handler = { + .invalid_surface = egl_g3d_invalid_surface +}; + static EGLBoolean egl_g3d_terminate(_EGLDriver *drv, _EGLDisplay *dpy) { @@ -581,31 +594,37 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy, } dpy->DriverData = gdpy; - gdpy->native = native_create_display(dpy->NativeDisplay); + gdpy->native = native_create_display(dpy->NativeDisplay, + &egl_g3d_native_event_handler); if (!gdpy->native) { _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)"); goto fail; } + gdpy->native->user_data = (void *) dpy; gdpy->native->screen->flush_frontbuffer = egl_g3d_flush_frontbuffer; gdpy->native->screen->update_buffer = egl_g3d_update_buffer; egl_g3d_init_st(&gdrv->base); dpy->ClientAPIsMask = gdrv->api_mask; - if (egl_g3d_add_configs(drv, dpy, 1) == 1) { - _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)"); - goto fail; - } - #ifdef EGL_MESA_screen_surface - /* enable MESA_screen_surface */ + /* enable MESA_screen_surface before adding (and validating) configs */ if (gdpy->native->modeset) { dpy->Extensions.MESA_screen_surface = EGL_TRUE; egl_g3d_add_screens(drv, dpy); } #endif + dpy->Extensions.KHR_image_base = EGL_TRUE; + if (gdpy->native->get_param(gdpy->native, NATIVE_PARAM_USE_NATIVE_BUFFER)) + dpy->Extensions.KHR_image_pixmap = EGL_TRUE; + + if (egl_g3d_add_configs(drv, dpy, 1) == 1) { + _eglError(EGL_NOT_INITIALIZED, "eglInitialize(unable to add configs)"); + goto fail; + } + *major = 1; *minor = 4; @@ -693,131 +712,144 @@ egl_g3d_destroy_context(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx) return EGL_TRUE; } -static EGLBoolean -init_surface_geometry(_EGLSurface *surf) -{ - struct egl_g3d_surface *gsurf = egl_g3d_surface(surf); - - return gsurf->native->validate(gsurf->native, 0x0, - &gsurf->sequence_number, NULL, - &gsurf->base.Width, &gsurf->base.Height); -} +struct egl_g3d_create_surface_arg { + EGLint type; + union { + EGLNativeWindowType win; + EGLNativePixmapType pix; + } u; +}; static _EGLSurface * -egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLConfig *conf, EGLNativeWindowType win, - const EGLint *attribs) +egl_g3d_create_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, + struct egl_g3d_create_surface_arg *arg, + const EGLint *attribs) { struct egl_g3d_display *gdpy = egl_g3d_display(dpy); struct egl_g3d_config *gconf = egl_g3d_config(conf); struct egl_g3d_surface *gsurf; + struct native_surface *nsurf; + const char *err; + + switch (arg->type) { + case EGL_WINDOW_BIT: + err = "eglCreateWindowSurface"; + break; + case EGL_PIXMAP_BIT: + err = "eglCreatePixmapSurface"; + break; + case EGL_PBUFFER_BIT: + err = "eglCreatePBufferSurface"; + break; +#ifdef EGL_MESA_screen_surface + case EGL_SCREEN_BIT_MESA: + err = "eglCreateScreenSurface"; + break; +#endif + default: + err = "eglCreateUnknownSurface"; + break; + } gsurf = CALLOC_STRUCT(egl_g3d_surface); if (!gsurf) { - _eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface"); + _eglError(EGL_BAD_ALLOC, err); return NULL; } - if (!_eglInitSurface(&gsurf->base, dpy, EGL_WINDOW_BIT, conf, attribs)) { + if (!_eglInitSurface(&gsurf->base, dpy, arg->type, conf, attribs)) { free(gsurf); return NULL; } - gsurf->native = - gdpy->native->create_window_surface(gdpy->native, win, gconf->native); - if (!gsurf->native) { + /* create the native surface */ + switch (arg->type) { + case EGL_WINDOW_BIT: + nsurf = gdpy->native->create_window_surface(gdpy->native, + arg->u.win, gconf->native); + break; + case EGL_PIXMAP_BIT: + nsurf = gdpy->native->create_pixmap_surface(gdpy->native, + arg->u.pix, gconf->native); + break; + case EGL_PBUFFER_BIT: + nsurf = gdpy->native->create_pbuffer_surface(gdpy->native, + gconf->native, gsurf->base.Width, gsurf->base.Height); + break; +#ifdef EGL_MESA_screen_surface + case EGL_SCREEN_BIT_MESA: + /* prefer back buffer (move to _eglInitSurface?) */ + gsurf->base.RenderBuffer = EGL_BACK_BUFFER; + nsurf = gdpy->native->modeset->create_scanout_surface(gdpy->native, + gconf->native, gsurf->base.Width, gsurf->base.Height); + break; +#endif + default: + nsurf = NULL; + break; + } + + if (!nsurf) { free(gsurf); return NULL; } - - if (!init_surface_geometry(&gsurf->base)) { - gsurf->native->destroy(gsurf->native); + /* initialize the geometry */ + if (!nsurf->validate(nsurf, 0x0, &gsurf->sequence_number, NULL, + &gsurf->base.Width, &gsurf->base.Height)) { + nsurf->destroy(nsurf); free(gsurf); return NULL; } - gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER || - !gconf->native->mode.doubleBufferMode) ? + nsurf->user_data = &gsurf->base; + gsurf->native = nsurf; + + gsurf->render_att = (gsurf->base.RenderBuffer == EGL_SINGLE_BUFFER) ? NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT; + if (!gconf->native->mode.doubleBufferMode) + gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT; return &gsurf->base; } static _EGLSurface * -egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, - _EGLConfig *conf, EGLNativePixmapType pix, +egl_g3d_create_window_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, EGLNativeWindowType win, const EGLint *attribs) { - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_config *gconf = egl_g3d_config(conf); - struct egl_g3d_surface *gsurf; + struct egl_g3d_create_surface_arg arg; - gsurf = CALLOC_STRUCT(egl_g3d_surface); - if (!gsurf) { - _eglError(EGL_BAD_ALLOC, "eglCreatePixmapSurface"); - return NULL; - } + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_WINDOW_BIT; + arg.u.win = win; - if (!_eglInitSurface(&gsurf->base, dpy, EGL_PIXMAP_BIT, conf, attribs)) { - free(gsurf); - return NULL; - } - - gsurf->native = - gdpy->native->create_pixmap_surface(gdpy->native, pix, gconf->native); - if (!gsurf->native) { - free(gsurf); - return NULL; - } + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); +} - if (!init_surface_geometry(&gsurf->base)) { - gsurf->native->destroy(gsurf->native); - free(gsurf); - return NULL; - } +static _EGLSurface * +egl_g3d_create_pixmap_surface(_EGLDriver *drv, _EGLDisplay *dpy, + _EGLConfig *conf, EGLNativePixmapType pix, + const EGLint *attribs) +{ + struct egl_g3d_create_surface_arg arg; - gsurf->render_att = NATIVE_ATTACHMENT_FRONT_LEFT; + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_PIXMAP_BIT; + arg.u.pix = pix; - return &gsurf->base; + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); } static _EGLSurface * egl_g3d_create_pbuffer_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attribs) { - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_config *gconf = egl_g3d_config(conf); - struct egl_g3d_surface *gsurf; - - gsurf = CALLOC_STRUCT(egl_g3d_surface); - if (!gsurf) { - _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface"); - return NULL; - } - - if (!_eglInitSurface(&gsurf->base, dpy, EGL_PBUFFER_BIT, conf, attribs)) { - free(gsurf); - return NULL; - } - - gsurf->native = - gdpy->native->create_pbuffer_surface(gdpy->native, gconf->native, - gsurf->base.Width, gsurf->base.Height); - if (!gsurf->native) { - free(gsurf); - return NULL; - } - - if (!init_surface_geometry(&gsurf->base)) { - gsurf->native->destroy(gsurf->native); - free(gsurf); - return NULL; - } + struct egl_g3d_create_surface_arg arg; - gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ? - NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT; + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_PBUFFER_BIT; - return &gsurf->base; + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); } /** @@ -925,32 +957,14 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf) if (gctx) gctx->stapi->st_notify_swapbuffers(gctx->draw.st_fb); - /* - * We drew on the back buffer, unless there was no back buffer. - * In that case, we drew on the front buffer. Either case, we call - * swap_buffers. - */ - if (!gsurf->native->swap_buffers(gsurf->native)) - return EGL_FALSE; - - if (gctx) { - struct egl_g3d_config *gconf = egl_g3d_config(gsurf->base.Config); - - /* force validation if the swap method is not copy */ - if (gconf->native->mode.swapMethod != GLX_SWAP_COPY_OML) { - gctx->force_validate = EGL_TRUE; - egl_g3d_validate_context(dpy, &gctx->base); - } - } - - return EGL_TRUE; + return gsurf->native->swap_buffers(gsurf->native); } /** * Find a config that supports the pixmap. */ -static _EGLConfig * -find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix) +_EGLConfig * +egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix) { struct egl_g3d_display *gdpy = egl_g3d_display(dpy); struct egl_g3d_config *gconf; @@ -1002,7 +1016,7 @@ egl_g3d_copy_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, if (!gsurf->render_surface) return EGL_TRUE; - gconf = egl_g3d_config(find_pixmap_config(dpy, target)); + gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, target)); if (!gconf) return _eglError(EGL_BAD_NATIVE_PIXMAP, "eglCopyBuffers"); @@ -1109,7 +1123,7 @@ egl_g3d_bind_tex_image(_EGLDriver *drv, _EGLDisplay *dpy, target_format = PIPE_FORMAT_R8G8B8_UNORM; break; case EGL_TEXTURE_RGBA: - target_format = PIPE_FORMAT_A8R8G8B8_UNORM; + target_format = PIPE_FORMAT_B8G8R8A8_UNORM; break; default: return _eglError(EGL_BAD_MATCH, "eglBindTexImage"); @@ -1177,34 +1191,12 @@ static _EGLSurface * egl_g3d_create_screen_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, const EGLint *attribs) { - struct egl_g3d_display *gdpy = egl_g3d_display(dpy); - struct egl_g3d_config *gconf = egl_g3d_config(conf); - struct egl_g3d_surface *gsurf; + struct egl_g3d_create_surface_arg arg; - gsurf = CALLOC_STRUCT(egl_g3d_surface); - if (!gsurf) { - _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface"); - return NULL; - } - - if (!_eglInitSurface(&gsurf->base, dpy, - EGL_SCREEN_BIT_MESA, conf, attribs)) { - free(gsurf); - return NULL; - } - - gsurf->native = - gdpy->native->modeset->create_scanout_surface(gdpy->native, - gconf->native, gsurf->base.Width, gsurf->base.Height); - if (!gsurf->native) { - free(gsurf); - return NULL; - } + memset(&arg, 0, sizeof(arg)); + arg.type = EGL_SCREEN_BIT_MESA; - gsurf->render_att = (!gconf->native->mode.doubleBufferMode) ? - NATIVE_ATTACHMENT_FRONT_LEFT : NATIVE_ATTACHMENT_BACK_LEFT; - - return &gsurf->base; + return egl_g3d_create_surface(drv, dpy, conf, &arg, attribs); } static EGLBoolean @@ -1335,6 +1327,9 @@ _eglMain(const char *args) gdrv->base.API.BindTexImage = egl_g3d_bind_tex_image; gdrv->base.API.ReleaseTexImage = egl_g3d_release_tex_image; + gdrv->base.API.CreateImageKHR = egl_g3d_create_image; + gdrv->base.API.DestroyImageKHR = egl_g3d_destroy_image; + #ifdef EGL_MESA_screen_surface gdrv->base.API.CreateScreenSurfaceMESA = egl_g3d_create_screen_surface; gdrv->base.API.ShowScreenSurfaceMESA = egl_g3d_show_screen_surface; diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.h b/src/gallium/state_trackers/egl/common/egl_g3d.h index 5d2d9c481ab..e3e55e46d3b 100644 --- a/src/gallium/state_trackers/egl/common/egl_g3d.h +++ b/src/gallium/state_trackers/egl/common/egl_g3d.h @@ -34,6 +34,7 @@ #include "eglcontext.h" #include "eglsurface.h" #include "eglconfig.h" +#include "eglimage.h" #include "eglscreen.h" #include "eglmode.h" @@ -81,6 +82,14 @@ struct egl_g3d_config { const struct native_config *native; }; +struct egl_g3d_image { + _EGLImage base; + struct pipe_texture *texture; + unsigned face; + unsigned level; + unsigned zslice; +}; + struct egl_g3d_screen { _EGLScreen base; const struct native_connector *native; @@ -90,5 +99,10 @@ struct egl_g3d_screen { /* standard typecasts */ _EGL_DRIVER_STANDARD_TYPECASTS(egl_g3d) _EGL_DRIVER_TYPECAST(egl_g3d_screen, _EGLScreen, obj) +_EGL_DRIVER_TYPECAST(egl_g3d_image, _EGLImage, obj) + + +_EGLConfig * +egl_g3d_find_pixmap_config(_EGLDisplay *dpy, EGLNativePixmapType pix); #endif /* _EGL_G3D_H_ */ diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.c b/src/gallium/state_trackers/egl/common/egl_g3d_image.c new file mode 100644 index 00000000000..d701f9c9a88 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.c @@ -0,0 +1,136 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2010 LunarG Inc. + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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. + * + * Authors: + * Chia-I Wu <[email protected]> + */ + +#include <assert.h> +#include "pipe/p_screen.h" +#include "util/u_memory.h" +#include "util/u_rect.h" +#include "util/u_inlines.h" +#include "eglcurrent.h" +#include "egllog.h" + +#include "native.h" +#include "egl_g3d.h" +#include "egl_g3d_image.h" + +/** + * Reference and return the front left buffer of the native pixmap. + */ +static struct pipe_texture * +egl_g3d_reference_native_pixmap(_EGLDisplay *dpy, EGLNativePixmapType pix) +{ + struct egl_g3d_display *gdpy = egl_g3d_display(dpy); + struct egl_g3d_config *gconf; + struct native_surface *nsurf; + struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; + enum native_attachment natt; + + gconf = egl_g3d_config(egl_g3d_find_pixmap_config(dpy, pix)); + if (!gconf) + return NULL; + + nsurf = gdpy->native->create_pixmap_surface(gdpy->native, + pix, gconf->native); + if (!nsurf) + return NULL; + + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + if (!nsurf->validate(nsurf, 1 << natt, NULL, textures, NULL, NULL)) + textures[natt] = NULL; + + nsurf->destroy(nsurf); + + return textures[natt]; +} + +_EGLImage * +egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, + EGLenum target, EGLClientBuffer buffer, + const EGLint *attribs) +{ + struct pipe_texture *ptex; + struct egl_g3d_image *gimg; + unsigned face = 0, level = 0, zslice = 0; + + gimg = CALLOC_STRUCT(egl_g3d_image); + if (!gimg) { + _eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface"); + return NULL; + } + + if (!_eglInitImage(&gimg->base, dpy, attribs)) { + free(gimg); + return NULL; + } + + switch (target) { + case EGL_NATIVE_PIXMAP_KHR: + ptex = egl_g3d_reference_native_pixmap(dpy, + (EGLNativePixmapType) buffer); + break; + default: + ptex = NULL; + break; + } + + if (!ptex) { + free(gimg); + return NULL; + } + + if (level > ptex->last_level) { + _eglError(EGL_BAD_MATCH, "eglCreateEGLImageKHR"); + pipe_texture_reference(&gimg->texture, NULL); + free(gimg); + return NULL; + } + if (zslice > ptex->depth0) { + _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR"); + pipe_texture_reference(&gimg->texture, NULL); + free(gimg); + return NULL; + } + + /* transfer the ownership to the image */ + gimg->texture = ptex; + gimg->face = face; + gimg->level = level; + gimg->zslice = zslice; + + return &gimg->base; +} + +EGLBoolean +egl_g3d_destroy_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *img) +{ + struct egl_g3d_image *gimg = egl_g3d_image(img); + + pipe_texture_reference(&gimg->texture, NULL); + free(gimg); + + return EGL_TRUE; +} diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_image.h b/src/gallium/state_trackers/egl/common/egl_g3d_image.h new file mode 100644 index 00000000000..c199c466456 --- /dev/null +++ b/src/gallium/state_trackers/egl/common/egl_g3d_image.h @@ -0,0 +1,41 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2010 LunarG Inc. + * + * 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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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. + * + * Authors: + * Chia-I Wu <[email protected]> + */ + +#ifndef _EGL_G3D_IMAGE_H_ +#define _EGL_G3D_IMAGE_H_ + +#include "egl_g3d.h" + +_EGLImage * +egl_g3d_create_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, + EGLenum target, EGLClientBuffer buffer, + const EGLint *attribs); + +EGLBoolean +egl_g3d_destroy_image(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image); + +#endif /* _EGL_G3D_IMAGE_H_ */ diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h index 4f9758545ab..9c22ff3e432 100644 --- a/src/gallium/state_trackers/egl/common/native.h +++ b/src/gallium/state_trackers/egl/common/native.h @@ -34,6 +34,8 @@ #include "pipe/p_context.h" #include "pipe/p_state.h" +#include "native_modeset.h" + /** * Only color buffers are listed. The others are allocated privately through, * for example, st_renderbuffer_alloc_storage(). @@ -47,6 +49,14 @@ enum native_attachment { NUM_NATIVE_ATTACHMENTS }; +enum native_param_type { + /* + * Return TRUE if window/pixmap surfaces use the buffers of the native + * types. + */ + NATIVE_PARAM_USE_NATIVE_BUFFER +}; + /** * Enumerations for probe results. */ @@ -69,6 +79,11 @@ struct native_probe { }; struct native_surface { + /** + * Available for caller's use. + */ + void *user_data; + void (*destroy)(struct native_surface *nsurf); /** @@ -117,18 +132,6 @@ struct native_config { boolean scanout_bit; }; -struct native_connector { - int dummy; -}; - -struct native_mode { - const char *desc; - int width, height; - int refresh_rate; -}; - -struct native_display_modeset; - /** * A pipe winsys abstracts the OS. A pipe screen abstracts the graphcis * hardware. A native display consists of a pipe winsys, a pipe screen, and @@ -143,9 +146,22 @@ struct native_display { */ struct pipe_screen *screen; + /** + * Available for caller's use. + */ + void *user_data; + void (*destroy)(struct native_display *ndpy); /** + * Query the parameters of the native display. + * + * The return value is defined by the parameter. + */ + int (*get_param)(struct native_display *ndpy, + enum native_param_type param); + + /** * Get the supported configs. The configs are owned by the display, but * the returned array should be free()ed. * @@ -196,46 +212,17 @@ struct native_display { }; /** - * Mode setting interface of the native display. It exposes the mode setting - * capabilities of the underlying graphics hardware. + * The handler for events that a native display may generate. The events are + * generated asynchronously and the handler may be called by any thread at any + * time. */ -struct native_display_modeset { - /** - * Get the available physical connectors and the number of CRTCs. - */ - const struct native_connector **(*get_connectors)(struct native_display *ndpy, - int *num_connectors, - int *num_crtcs); - +struct native_event_handler { /** - * Get the current supported modes of a connector. The returned modes may - * change every time this function is called and those from previous calls - * might become invalid. - */ - const struct native_mode **(*get_modes)(struct native_display *ndpy, - const struct native_connector *nconn, - int *num_modes); - - /** - * Create a scan-out surface. Required unless no config has - * GLX_SCREEN_BIT_MESA set. - */ - struct native_surface *(*create_scanout_surface)(struct native_display *ndpy, - const struct native_config *nconf, - uint width, uint height); - - /** - * Program the CRTC to output the surface to the given connectors with the - * given mode. When surface is not given, the CRTC is disabled. - * - * This interface does not export a way to query capabilities of the CRTCs. - * The native display usually needs to dynamically map the index to a CRTC - * that supports the given connectors. + * This function is called when a surface needs to be validated. */ - boolean (*program)(struct native_display *ndpy, int crtc_idx, - struct native_surface *nsurf, uint x, uint y, - const struct native_connector **nconns, int num_nconns, - const struct native_mode *nmode); + void (*invalid_surface)(struct native_display *ndpy, + struct native_surface *nsurf, + unsigned int seq_num); }; /** @@ -267,6 +254,7 @@ const char * native_get_name(void); struct native_display * -native_create_display(EGLNativeDisplayType dpy); +native_create_display(EGLNativeDisplayType dpy, + struct native_event_handler *handler); #endif /* _NATIVE_H_ */ diff --git a/src/gallium/state_trackers/egl/common/native_modeset.h b/src/gallium/state_trackers/egl/common/native_modeset.h new file mode 100644 index 00000000000..71dc3ec860e --- /dev/null +++ b/src/gallium/state_trackers/egl/common/native_modeset.h @@ -0,0 +1,87 @@ +/* + * Mesa 3-D graphics library + * Version: 7.8 + * + * Copyright (C) 2009-2010 Chia-I Wu <[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, sublicense, + * 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 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 NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL 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 _NATIVE_MODESET_H_ +#define _NATIVE_MODESET_H_ + +#include "pipe/p_compiler.h" + +struct native_display; +struct native_surface; +struct native_config; + +struct native_connector { + int dummy; +}; + +struct native_mode { + const char *desc; + int width, height; + int refresh_rate; +}; + +/** + * Mode setting interface of the native display. It exposes the mode setting + * capabilities of the underlying graphics hardware. + */ +struct native_display_modeset { + /** + * Get the available physical connectors and the number of CRTCs. + */ + const struct native_connector **(*get_connectors)(struct native_display *ndpy, + int *num_connectors, + int *num_crtcs); + + /** + * Get the current supported modes of a connector. The returned modes may + * change every time this function is called and those from previous calls + * might become invalid. + */ + const struct native_mode **(*get_modes)(struct native_display *ndpy, + const struct native_connector *nconn, + int *num_modes); + + /** + * Create a scan-out surface. Required unless no config has + * GLX_SCREEN_BIT_MESA set. + */ + struct native_surface *(*create_scanout_surface)(struct native_display *ndpy, + const struct native_config *nconf, + uint width, uint height); + + /** + * Program the CRTC to output the surface to the given connectors with the + * given mode. When surface is not given, the CRTC is disabled. + * + * This interface does not export a way to query capabilities of the CRTCs. + * The native display usually needs to dynamically map the index to a CRTC + * that supports the given connectors. + */ + boolean (*program)(struct native_display *ndpy, int crtc_idx, + struct native_surface *nsurf, uint x, uint y, + const struct native_connector **nconns, int num_nconns, + const struct native_mode *nmode); +}; + +#endif /* _NATIVE_MODESET_H_ */ diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c index 91cefc538d1..73222408565 100644 --- a/src/gallium/state_trackers/egl/kms/native_kms.c +++ b/src/gallium/state_trackers/egl/kms/native_kms.c @@ -55,7 +55,7 @@ kms_surface_validate(struct native_surface *nsurf, uint attachment_mask, templ.format = ksurf->color_format; templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; if (ksurf->type == KMS_SURFACE_TYPE_SCANOUT) - templ.tex_usage |= PIPE_TEXTURE_USAGE_PRIMARY; + templ.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; } /* create textures */ @@ -100,7 +100,7 @@ kms_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back) for (i = 0; i < num_framebuffers; i++) { struct kms_framebuffer *fb; enum native_attachment natt; - unsigned int handle, stride; + struct winsys_handle whandle; uint block_bits; if (i == 0) { @@ -128,13 +128,17 @@ kms_surface_init_framebuffers(struct native_surface *nsurf, boolean need_back) /* TODO detect the real value */ fb->is_passive = TRUE; - if (!kdpy->api->local_handle_from_texture(kdpy->api, - kdpy->base.screen, fb->texture, &stride, &handle)) + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_KMS; + + if (!kdpy->base.screen->texture_get_handle(kdpy->base.screen, + fb->texture, &whandle)) return FALSE; block_bits = util_format_get_blocksizebits(ksurf->color_format); err = drmModeAddFB(kdpy->fd, ksurf->width, ksurf->height, - block_bits, block_bits, stride, handle, &fb->buffer_id); + block_bits, block_bits, whandle.stride, whandle.handle, + &fb->buffer_id); if (err) { fb->buffer_id = 0; return FALSE; @@ -201,6 +205,8 @@ kms_surface_swap_buffers(struct native_surface *nsurf) /* the front/back textures are swapped */ ksurf->sequence_number++; + kdpy->event_handler->invalid_surface(&kdpy->base, + &ksurf->base, ksurf->sequence_number); return TRUE; } @@ -499,7 +505,10 @@ kms_display_get_modes(struct native_display *ndpy, kmode->base.desc = kmode->mode.name; kmode->base.width = kmode->mode.hdisplay; kmode->base.height = kmode->mode.vdisplay; - kmode->base.refresh_rate = kmode->mode.vrefresh / 1000; + kmode->base.refresh_rate = kmode->mode.vrefresh; + /* not all kernels have vrefresh = refresh_rate * 1000 */ + if (kmode->base.refresh_rate > 1000) + kmode->base.refresh_rate = (kmode->base.refresh_rate + 500) / 1000; } nmodes_return = malloc(count * sizeof(*nmodes_return)); @@ -606,9 +615,9 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs) /* always double-buffered */ nconf->mode.doubleBufferMode = TRUE; - format = PIPE_FORMAT_A8R8G8B8_UNORM; + format = PIPE_FORMAT_B8G8R8A8_UNORM; if (!kms_display_is_format_supported(&kdpy->base, format, TRUE)) { - format = PIPE_FORMAT_B8G8R8A8_UNORM; + format = PIPE_FORMAT_A8R8G8B8_UNORM; if (!kms_display_is_format_supported(&kdpy->base, format, TRUE)) format = PIPE_FORMAT_NONE; } @@ -622,9 +631,9 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs) nconf->mode.alphaBits = 8; nconf->mode.rgbBits = 32; - format = PIPE_FORMAT_S8Z24_UNORM; + format = PIPE_FORMAT_Z24S8_UNORM; if (!kms_display_is_format_supported(&kdpy->base, format, FALSE)) { - format = PIPE_FORMAT_Z24S8_UNORM; + format = PIPE_FORMAT_S8Z24_UNORM; if (!kms_display_is_format_supported(&kdpy->base, format, FALSE)) format = PIPE_FORMAT_NONE; } @@ -660,6 +669,21 @@ kms_display_get_configs(struct native_display *ndpy, int *num_configs) return configs; } +static int +kms_display_get_param(struct native_display *ndpy, + enum native_param_type param) +{ + int val; + + switch (param) { + default: + val = 0; + break; + } + + return val; +} + static void kms_display_destroy(struct native_display *ndpy) { @@ -759,7 +783,9 @@ static struct native_display_modeset kms_display_modeset = { }; static struct native_display * -kms_create_display(EGLNativeDisplayType dpy, struct drm_api *api) +kms_create_display(EGLNativeDisplayType dpy, + struct native_event_handler *event_handler, + struct drm_api *api) { struct kms_display *kdpy; @@ -767,6 +793,8 @@ kms_create_display(EGLNativeDisplayType dpy, struct drm_api *api) if (!kdpy) return NULL; + kdpy->event_handler = event_handler; + kdpy->api = api; if (!kdpy->api) { _eglLog(_EGL_WARNING, "failed to create DRM API"); @@ -802,6 +830,7 @@ kms_create_display(EGLNativeDisplayType dpy, struct drm_api *api) } kdpy->base.destroy = kms_display_destroy; + kdpy->base.get_param = kms_display_get_param; kdpy->base.get_configs = kms_display_get_configs; kdpy->base.create_pbuffer_surface = kms_display_create_pbuffer_surface; @@ -842,7 +871,8 @@ native_get_name(void) } struct native_display * -native_create_display(EGLNativeDisplayType dpy) +native_create_display(EGLNativeDisplayType dpy, + struct native_event_handler *event_handler) { struct native_display *ndpy = NULL; @@ -850,7 +880,7 @@ native_create_display(EGLNativeDisplayType dpy) drm_api = drm_api_create(); if (drm_api) - ndpy = kms_create_display(dpy, drm_api); + ndpy = kms_create_display(dpy, event_handler, drm_api); return ndpy; } diff --git a/src/gallium/state_trackers/egl/kms/native_kms.h b/src/gallium/state_trackers/egl/kms/native_kms.h index 095186e3cf3..f9cbcb158b5 100644 --- a/src/gallium/state_trackers/egl/kms/native_kms.h +++ b/src/gallium/state_trackers/egl/kms/native_kms.h @@ -53,6 +53,8 @@ struct kms_crtc { struct kms_display { struct native_display base; + struct native_event_handler *event_handler; + int fd; struct drm_api *api; drmModeResPtr resources; diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c index 5f2fd412604..98399792311 100644 --- a/src/gallium/state_trackers/egl/x11/native_dri2.c +++ b/src/gallium/state_trackers/egl/x11/native_dri2.c @@ -26,6 +26,7 @@ #include "util/u_math.h" #include "util/u_format.h" #include "util/u_inlines.h" +#include "util/u_hash_table.h" #include "pipe/p_compiler.h" #include "pipe/p_screen.h" #include "pipe/p_context.h" @@ -47,12 +48,18 @@ struct dri2_display { Display *dpy; boolean own_dpy; + struct native_event_handler *event_handler; + struct drm_api *api; struct x11_screen *xscr; int xscr_number; + const char *dri_driver; + int dri_major, dri_minor; struct dri2_config *configs; int num_configs; + + struct util_hash_table *surfaces; }; struct dri2_surface { @@ -62,10 +69,16 @@ struct dri2_surface { enum pipe_format color_format; struct dri2_display *dri2dpy; - struct pipe_texture *pbuffer_textures[NUM_NATIVE_ATTACHMENTS]; - boolean have_back, have_fake; + unsigned int server_stamp; + unsigned int client_stamp; int width, height; - unsigned int sequence_number; + struct pipe_texture *textures[NUM_NATIVE_ATTACHMENTS]; + uint valid_mask; + + boolean have_back, have_fake; + + struct x11_drawable_buffer *last_xbufs; + int last_num_xbufs; }; struct dri2_config { @@ -90,110 +103,103 @@ dri2_config(const struct native_config *nconf) return (struct dri2_config *) nconf; } -static boolean -dri2_surface_flush_frontbuffer(struct native_surface *nsurf) +/** + * Process the buffers returned by the server. + */ +static void +dri2_surface_process_drawable_buffers(struct native_surface *nsurf, + struct x11_drawable_buffer *xbufs, + int num_xbufs) { struct dri2_surface *dri2surf = dri2_surface(nsurf); struct dri2_display *dri2dpy = dri2surf->dri2dpy; + struct pipe_texture templ; + struct winsys_handle whandle; + uint valid_mask; + int i; - /* pbuffer is private */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) - return TRUE; + /* free the old textures */ + for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) + pipe_texture_reference(&dri2surf->textures[i], NULL); + dri2surf->valid_mask = 0x0; - /* copy to real front buffer */ - if (dri2surf->have_fake) - x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, - 0, 0, dri2surf->width, dri2surf->height, - DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft); + dri2surf->have_back = FALSE; + dri2surf->have_fake = FALSE; - return TRUE; -} + if (!xbufs) + return; -static boolean -dri2_surface_swap_buffers(struct native_surface *nsurf) -{ - struct dri2_surface *dri2surf = dri2_surface(nsurf); - struct dri2_display *dri2dpy = dri2surf->dri2dpy; + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; + templ.width0 = dri2surf->width; + templ.height0 = dri2surf->height; + templ.depth0 = 1; + templ.format = dri2surf->color_format; + templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - /* pbuffer is private */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) - return TRUE; + valid_mask = 0x0; + for (i = 0; i < num_xbufs; i++) { + struct x11_drawable_buffer *xbuf = &xbufs[i]; + const char *desc; + enum native_attachment natt; - /* copy to front buffer */ - if (dri2surf->have_back) - x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, - 0, 0, dri2surf->width, dri2surf->height, - DRI2BufferBackLeft, DRI2BufferFrontLeft); + switch (xbuf->attachment) { + case DRI2BufferFrontLeft: + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + desc = "DRI2 Front Buffer"; + break; + case DRI2BufferFakeFrontLeft: + natt = NATIVE_ATTACHMENT_FRONT_LEFT; + desc = "DRI2 Fake Front Buffer"; + dri2surf->have_fake = TRUE; + break; + case DRI2BufferBackLeft: + natt = NATIVE_ATTACHMENT_BACK_LEFT; + desc = "DRI2 Back Buffer"; + dri2surf->have_back = TRUE; + break; + default: + desc = NULL; + break; + } - /* and update fake front buffer */ - if (dri2surf->have_fake) - x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, - 0, 0, dri2surf->width, dri2surf->height, - DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); + if (!desc || dri2surf->textures[natt]) { + if (!desc) + _eglLog(_EGL_WARNING, "unknown buffer %d", xbuf->attachment); + else + _eglLog(_EGL_WARNING, "both real and fake front buffers are listed"); + continue; + } - return TRUE; + memset(&whandle, 0, sizeof(whandle)); + whandle.stride = xbuf->pitch; + whandle.handle = xbuf->name; + dri2surf->textures[natt] = dri2dpy->base.screen->texture_from_handle( + dri2dpy->base.screen, &templ, &whandle); + if (dri2surf->textures[natt]) + valid_mask |= 1 << natt; + } + + dri2surf->valid_mask = valid_mask; } -static boolean -dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask, - unsigned int *seq_num, struct pipe_texture **textures, - int *width, int *height) +/** + * Get the buffers from the server. + */ +static void +dri2_surface_get_buffers(struct native_surface *nsurf, uint buffer_mask) { struct dri2_surface *dri2surf = dri2_surface(nsurf); struct dri2_display *dri2dpy = dri2surf->dri2dpy; unsigned int dri2atts[NUM_NATIVE_ATTACHMENTS]; - struct pipe_texture templ; + int num_ins, num_outs, att; struct x11_drawable_buffer *xbufs; - int num_ins, num_outs, att, i; - - if (attachment_mask) { - memset(&templ, 0, sizeof(templ)); - templ.target = PIPE_TEXTURE_2D; - templ.last_level = 0; - templ.width0 = dri2surf->width; - templ.height0 = dri2surf->height; - templ.depth0 = 1; - templ.format = dri2surf->color_format; - templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - - if (textures) - memset(textures, 0, sizeof(*textures) * NUM_NATIVE_ATTACHMENTS); - } - - /* create textures for pbuffer */ - if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) { - struct pipe_screen *screen = dri2dpy->base.screen; - - for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { - struct pipe_texture *ptex = dri2surf->pbuffer_textures[att]; - - /* delay the allocation */ - if (!native_attachment_mask_test(attachment_mask, att)) - continue; - - if (!ptex) { - ptex = screen->texture_create(screen, &templ); - dri2surf->pbuffer_textures[att] = ptex; - } - - if (textures) - pipe_texture_reference(&textures[att], ptex); - } - - if (seq_num) - *seq_num = dri2surf->sequence_number; - if (width) - *width = dri2surf->width; - if (height) - *height = dri2surf->height; - - return TRUE; - } /* prepare the attachments */ num_ins = 0; for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { - if (native_attachment_mask_test(attachment_mask, att)) { + if (native_attachment_mask_test(buffer_mask, att)) { unsigned int dri2att; switch (att) { @@ -220,79 +226,178 @@ dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask, } } - dri2surf->have_back = FALSE; - dri2surf->have_fake = FALSE; - - /* remember old geometry */ - templ.width0 = dri2surf->width; - templ.height0 = dri2surf->height; - xbufs = x11_drawable_get_buffers(dri2dpy->xscr, dri2surf->drawable, &dri2surf->width, &dri2surf->height, dri2atts, FALSE, num_ins, &num_outs); - if (!xbufs) - return FALSE; - if (templ.width0 != dri2surf->width || templ.height0 != dri2surf->height) { - /* are there cases where the buffers change and the geometry doesn't? */ - dri2surf->sequence_number++; + /* we should be able to do better... */ + if (xbufs && dri2surf->last_num_xbufs == num_outs && + memcmp(dri2surf->last_xbufs, xbufs, sizeof(*xbufs) * num_outs) == 0) { + free(xbufs); + dri2surf->client_stamp = dri2surf->server_stamp; + return; + } + + dri2_surface_process_drawable_buffers(&dri2surf->base, xbufs, num_outs); + dri2surf->server_stamp++; + dri2surf->client_stamp = dri2surf->server_stamp; + + if (dri2surf->last_xbufs) + free(dri2surf->last_xbufs); + dri2surf->last_xbufs = xbufs; + dri2surf->last_num_xbufs = num_outs; +} + +/** + * Update the buffers of the surface. This is a slow function due to the + * round-trip to the server. + */ +static boolean +dri2_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + struct dri2_display *dri2dpy = dri2surf->dri2dpy; + + /* create textures for pbuffer */ + if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) { + struct pipe_screen *screen = dri2dpy->base.screen; + struct pipe_texture templ; + uint new_valid = 0x0; + int att; + + buffer_mask &= ~dri2surf->valid_mask; + if (!buffer_mask) + return TRUE; + + memset(&templ, 0, sizeof(templ)); + templ.target = PIPE_TEXTURE_2D; + templ.last_level = 0; templ.width0 = dri2surf->width; templ.height0 = dri2surf->height; - } - - for (i = 0; i < num_outs; i++) { - struct x11_drawable_buffer *xbuf = &xbufs[i]; - const char *desc; - enum native_attachment natt; + templ.depth0 = 1; + templ.format = dri2surf->color_format; + templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; - switch (xbuf->attachment) { - case DRI2BufferFrontLeft: - natt = NATIVE_ATTACHMENT_FRONT_LEFT; - desc = "DRI2 Front Buffer"; - break; - case DRI2BufferFakeFrontLeft: - natt = NATIVE_ATTACHMENT_FRONT_LEFT; - desc = "DRI2 Fake Front Buffer"; - dri2surf->have_fake = TRUE; - break; - case DRI2BufferBackLeft: - natt = NATIVE_ATTACHMENT_BACK_LEFT; - desc = "DRI2 Back Buffer"; - dri2surf->have_back = TRUE; - break; - default: - desc = NULL; - break; - } + for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { + if (native_attachment_mask_test(buffer_mask, att)) { + assert(!dri2surf->textures[att]); - if (!desc || !native_attachment_mask_test(attachment_mask, natt) || - (textures && textures[natt])) { - if (!desc) - _eglLog(_EGL_WARNING, "unknown buffer %d", xbuf->attachment); - else if (!native_attachment_mask_test(attachment_mask, natt)) - _eglLog(_EGL_WARNING, "unexpected buffer %d", xbuf->attachment); - else - _eglLog(_EGL_WARNING, "both real and fake front buffers are listed"); - continue; - } + dri2surf->textures[att] = screen->texture_create(screen, &templ); + if (!dri2surf->textures[att]) + break; - if (textures) { - struct pipe_texture *ptex = - dri2dpy->api->texture_from_shared_handle(dri2dpy->api, - dri2dpy->base.screen, &templ, - desc, xbuf->pitch, xbuf->name); - if (ptex) { - /* the caller owns the textures */ - textures[natt] = ptex; + new_valid |= 1 << att; + if (new_valid == buffer_mask) + break; } } + dri2surf->valid_mask |= new_valid; + /* no need to update the stamps */ + } + else { + dri2_surface_get_buffers(&dri2surf->base, buffer_mask); + } + + return ((dri2surf->valid_mask & buffer_mask) == buffer_mask); +} + +/** + * Return TRUE if the surface receives DRI2_InvalidateBuffers events. + */ +static INLINE boolean +dri2_surface_receive_events(struct native_surface *nsurf) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + return (dri2surf->dri2dpy->dri_minor >= 3); +} + +static boolean +dri2_surface_flush_frontbuffer(struct native_surface *nsurf) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + struct dri2_display *dri2dpy = dri2surf->dri2dpy; + + /* pbuffer is private */ + if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) + return TRUE; + + /* copy to real front buffer */ + if (dri2surf->have_fake) + x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, + 0, 0, dri2surf->width, dri2surf->height, + DRI2BufferFakeFrontLeft, DRI2BufferFrontLeft); + + /* force buffers to be updated in next validation call */ + if (!dri2_surface_receive_events(&dri2surf->base)) { + dri2surf->server_stamp++; + dri2dpy->event_handler->invalid_surface(&dri2dpy->base, + &dri2surf->base, dri2surf->server_stamp); } - free(xbufs); + return TRUE; +} + +static boolean +dri2_surface_swap_buffers(struct native_surface *nsurf) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + struct dri2_display *dri2dpy = dri2surf->dri2dpy; + + /* pbuffer is private */ + if (dri2surf->type == DRI2_SURFACE_TYPE_PBUFFER) + return TRUE; + + /* copy to front buffer */ + if (dri2surf->have_back) + x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, + 0, 0, dri2surf->width, dri2surf->height, + DRI2BufferBackLeft, DRI2BufferFrontLeft); + + /* and update fake front buffer */ + if (dri2surf->have_fake) + x11_drawable_copy_buffers(dri2dpy->xscr, dri2surf->drawable, + 0, 0, dri2surf->width, dri2surf->height, + DRI2BufferFrontLeft, DRI2BufferFakeFrontLeft); + + /* force buffers to be updated in next validation call */ + if (!dri2_surface_receive_events(&dri2surf->base)) { + dri2surf->server_stamp++; + dri2dpy->event_handler->invalid_surface(&dri2dpy->base, + &dri2surf->base, dri2surf->server_stamp); + } + + return TRUE; +} + +static boolean +dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask, + unsigned int *seq_num, struct pipe_texture **textures, + int *width, int *height) +{ + struct dri2_surface *dri2surf = dri2_surface(nsurf); + + if (dri2surf->server_stamp != dri2surf->client_stamp || + (dri2surf->valid_mask & attachment_mask) != attachment_mask) { + if (!dri2_surface_update_buffers(&dri2surf->base, attachment_mask)) + return FALSE; + } if (seq_num) - *seq_num = dri2surf->sequence_number; + *seq_num = dri2surf->client_stamp; + + if (textures) { + int att; + for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { + if (native_attachment_mask_test(attachment_mask, att)) { + struct pipe_texture *ptex = dri2surf->textures[att]; + + textures[att] = NULL; + pipe_texture_reference(&textures[att], ptex); + } + } + } + if (width) *width = dri2surf->width; if (height) @@ -320,14 +425,21 @@ dri2_surface_destroy(struct native_surface *nsurf) struct dri2_surface *dri2surf = dri2_surface(nsurf); int i; + if (dri2surf->last_xbufs) + free(dri2surf->last_xbufs); + for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) { - struct pipe_texture *ptex = dri2surf->pbuffer_textures[i]; + struct pipe_texture *ptex = dri2surf->textures[i]; pipe_texture_reference(&ptex, NULL); } - if (dri2surf->drawable) + if (dri2surf->drawable) { x11_drawable_enable_dri2(dri2surf->dri2dpy->xscr, dri2surf->drawable, FALSE); + + util_hash_table_remove(dri2surf->dri2dpy->surfaces, + (void *) dri2surf->drawable); + } free(dri2surf); } @@ -345,9 +457,6 @@ dri2_display_create_surface(struct native_display *ndpy, if (!dri2surf) return NULL; - if (drawable) - x11_drawable_enable_dri2(dri2dpy->xscr, drawable, TRUE); - dri2surf->dri2dpy = dri2dpy; dri2surf->type = type; dri2surf->drawable = drawable; @@ -359,6 +468,15 @@ dri2_display_create_surface(struct native_display *ndpy, dri2surf->base.validate = dri2_surface_validate; dri2surf->base.wait = dri2_surface_wait; + if (drawable) { + x11_drawable_enable_dri2(dri2dpy->xscr, drawable, TRUE); + /* initialize the geometry */ + dri2_surface_update_buffers(&dri2surf->base, 0x0); + + util_hash_table_set(dri2surf->dri2dpy->surfaces, + (void *) dri2surf->drawable, (void *) &dri2surf->base); + } + return dri2surf; } @@ -409,17 +527,17 @@ choose_color_format(const __GLcontextModes *mode, enum pipe_format formats[32]) switch (mode->rgbBits) { case 32: - formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM; formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM; + formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM; break; case 24: - formats[count++] = PIPE_FORMAT_X8R8G8B8_UNORM; formats[count++] = PIPE_FORMAT_B8G8R8X8_UNORM; - formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM; + formats[count++] = PIPE_FORMAT_X8R8G8B8_UNORM; formats[count++] = PIPE_FORMAT_B8G8R8A8_UNORM; + formats[count++] = PIPE_FORMAT_A8R8G8B8_UNORM; break; case 16: - formats[count++] = PIPE_FORMAT_R5G6B5_UNORM; + formats[count++] = PIPE_FORMAT_B5G6R5_UNORM; break; default: break; @@ -440,12 +558,12 @@ choose_depth_stencil_format(const __GLcontextModes *mode, break; case 24: if (mode->stencilBits) { - formats[count++] = PIPE_FORMAT_S8Z24_UNORM; formats[count++] = PIPE_FORMAT_Z24S8_UNORM; + formats[count++] = PIPE_FORMAT_S8Z24_UNORM; } else { - formats[count++] = PIPE_FORMAT_X8Z24_UNORM; formats[count++] = PIPE_FORMAT_Z24X8_UNORM; + formats[count++] = PIPE_FORMAT_X8Z24_UNORM; } break; case 16: @@ -592,6 +710,25 @@ dri2_display_is_pixmap_supported(struct native_display *ndpy, return (depth == nconf_depth || (depth == 24 && depth + 8 == nconf_depth)); } +static int +dri2_display_get_param(struct native_display *ndpy, + enum native_param_type param) +{ + int val; + + switch (param) { + case NATIVE_PARAM_USE_NATIVE_BUFFER: + /* DRI2GetBuffers use the native buffers */ + val = TRUE; + break; + default: + val = 0; + break; + } + + return val; +} + static void dri2_display_destroy(struct native_display *ndpy) { @@ -603,6 +740,9 @@ dri2_display_destroy(struct native_display *ndpy) if (dri2dpy->base.screen) dri2dpy->base.screen->destroy(dri2dpy->base.screen); + if (dri2dpy->surfaces) + util_hash_table_destroy(dri2dpy->surfaces); + if (dri2dpy->xscr) x11_screen_destroy(dri2dpy->xscr); if (dri2dpy->own_dpy) @@ -612,6 +752,27 @@ dri2_display_destroy(struct native_display *ndpy) free(dri2dpy); } +static void +dri2_display_invalidate_buffers(struct x11_screen *xscr, Drawable drawable, + void *user_data) +{ + struct native_display *ndpy = (struct native_display* ) user_data; + struct dri2_display *dri2dpy = dri2_display(ndpy); + struct native_surface *nsurf; + struct dri2_surface *dri2surf; + + nsurf = (struct native_surface *) + util_hash_table_get(dri2dpy->surfaces, (void *) drawable); + if (!nsurf) + return; + + dri2surf = dri2_surface(nsurf); + + dri2surf->server_stamp++; + dri2dpy->event_handler->invalid_surface(&dri2dpy->base, + &dri2surf->base, dri2surf->server_stamp); +} + /** * Initialize DRI2 and pipe screen. */ @@ -629,7 +790,17 @@ dri2_display_init_screen(struct native_display *ndpy) return FALSE; } - fd = x11_screen_enable_dri2(dri2dpy->xscr, driver); + dri2dpy->dri_driver = x11_screen_probe_dri2(dri2dpy->xscr, + &dri2dpy->dri_major, &dri2dpy->dri_minor); + if (!dri2dpy->dri_driver || !driver || + strcmp(dri2dpy->dri_driver, driver) != 0) { + _eglLog(_EGL_WARNING, "Driver mismatch: %s != %s", + dri2dpy->dri_driver, dri2dpy->api->name); + return FALSE; + } + + fd = x11_screen_enable_dri2(dri2dpy->xscr, + dri2_display_invalidate_buffers, &dri2dpy->base); if (fd < 0) return FALSE; @@ -644,8 +815,23 @@ dri2_display_init_screen(struct native_display *ndpy) return TRUE; } +static unsigned +dri2_display_hash_table_hash(void *key) +{ + XID drawable = pointer_to_uintptr(key); + return (unsigned) drawable; +} + +static int +dri2_display_hash_table_compare(void *key1, void *key2) +{ + return (key1 - key2); +} + struct native_display * -x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api) +x11_create_dri2_display(EGLNativeDisplayType dpy, + struct native_event_handler *event_handler, + struct drm_api *api) { struct dri2_display *dri2dpy; @@ -653,12 +839,8 @@ x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api) if (!dri2dpy) return NULL; + dri2dpy->event_handler = event_handler; dri2dpy->api = api; - if (!dri2dpy->api) { - _eglLog(_EGL_WARNING, "failed to create DRM API"); - free(dri2dpy); - return NULL; - } dri2dpy->dpy = dpy; if (!dri2dpy->dpy) { @@ -682,7 +864,15 @@ x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api) return NULL; } + dri2dpy->surfaces = util_hash_table_create(dri2_display_hash_table_hash, + dri2_display_hash_table_compare); + if (!dri2dpy->surfaces) { + dri2_display_destroy(&dri2dpy->base); + return NULL; + } + dri2dpy->base.destroy = dri2_display_destroy; + dri2dpy->base.get_param = dri2_display_get_param; dri2dpy->base.get_configs = dri2_display_get_configs; dri2dpy->base.is_pixmap_supported = dri2_display_is_pixmap_supported; dri2dpy->base.create_window_surface = dri2_display_create_window_surface; diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c index 8eb542bd827..7b4fe63fa07 100644 --- a/src/gallium/state_trackers/egl/x11/native_x11.c +++ b/src/gallium/state_trackers/egl/x11/native_x11.c @@ -70,7 +70,7 @@ native_create_probe(EGLNativeDisplayType dpy) xscr = x11_screen_create(xdpy, scr); if (xscr) { if (x11_screen_support(xscr, X11_SCREEN_EXTENSION_DRI2)) { - driver_name = x11_screen_probe_dri2(xscr); + driver_name = x11_screen_probe_dri2(xscr, NULL, NULL); if (driver_name) nprobe->data = strdup(driver_name); } @@ -126,7 +126,8 @@ native_get_name(void) } struct native_display * -native_create_display(EGLNativeDisplayType dpy) +native_create_display(EGLNativeDisplayType dpy, + struct native_event_handler *event_handler) { struct native_display *ndpy = NULL; boolean force_sw; @@ -136,14 +137,21 @@ native_create_display(EGLNativeDisplayType dpy) force_sw = debug_get_bool_option("EGL_SOFTWARE", FALSE); if (api && !force_sw) { - ndpy = x11_create_dri2_display(dpy, api); + ndpy = x11_create_dri2_display(dpy, event_handler, api); } if (!ndpy) { EGLint level = (force_sw) ? _EGL_INFO : _EGL_WARNING; - - _eglLog(level, "use software fallback"); - ndpy = x11_create_ximage_display(dpy, TRUE); + boolean use_shm; + + /* + * XXX st/mesa calls pipe_screen::update_buffer in st_validate_state. + * When SHM is used, there is a good chance that the shared memory + * segment is detached before the softpipe tile cache is flushed. + */ + use_shm = FALSE; + _eglLog(level, "use software%s fallback", (use_shm) ? " (SHM)" : ""); + ndpy = x11_create_ximage_display(dpy, event_handler, use_shm); } return ndpy; diff --git a/src/gallium/state_trackers/egl/x11/native_x11.h b/src/gallium/state_trackers/egl/x11/native_x11.h index 622ddac5df6..8c6a7d93497 100644 --- a/src/gallium/state_trackers/egl/x11/native_x11.h +++ b/src/gallium/state_trackers/egl/x11/native_x11.h @@ -29,9 +29,13 @@ #include "common/native.h" struct native_display * -x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm); +x11_create_ximage_display(EGLNativeDisplayType dpy, + struct native_event_handler *event_handler, + boolean use_xshm); struct native_display * -x11_create_dri2_display(EGLNativeDisplayType dpy, struct drm_api *api); +x11_create_dri2_display(EGLNativeDisplayType dpy, + struct native_event_handler *event_handler, + struct drm_api *api); #endif /* _NATIVE_X11_H_ */ diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c index 92a62f230e0..a94b1ca6c66 100644 --- a/src/gallium/state_trackers/egl/x11/native_ximage.c +++ b/src/gallium/state_trackers/egl/x11/native_ximage.c @@ -56,6 +56,8 @@ struct ximage_display { struct x11_screen *xscr; int xscr_number; + struct native_event_handler *event_handler; + boolean use_xshm; struct pipe_winsys *winsys; @@ -79,11 +81,13 @@ struct ximage_surface { XVisualInfo visual; struct ximage_display *xdpy; - int width, height; GC gc; + unsigned int server_stamp; + unsigned int client_stamp; + int width, height; struct ximage_buffer buffers[NUM_NATIVE_ATTACHMENTS]; - unsigned int sequence_number; + uint valid_mask; }; struct ximage_config { @@ -152,6 +156,11 @@ ximage_surface_alloc_buffer(struct native_surface *nsurf, templ.depth0 = 1; templ.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET; +#if 0 + /* Interesting and suprising use of texture_blanket + + * user_buffer_create... To be superceded by the sw_winsys branch, + * but currently disabled. + */ if (xbuf->shm_info) { struct pipe_buffer *pbuf; unsigned stride, size; @@ -184,7 +193,9 @@ ximage_surface_alloc_buffer(struct native_surface *nsurf, } } } - else { + else +#endif + { xbuf->texture = screen->texture_create(screen, &templ); } @@ -195,6 +206,100 @@ ximage_surface_alloc_buffer(struct native_surface *nsurf, return (xbuf->texture != NULL); } +/** + * Update the geometry of the surface. Return TRUE if the geometry has changed + * since last call. + */ +static boolean +ximage_surface_update_geometry(struct native_surface *nsurf) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + Status ok; + Window root; + int x, y; + unsigned int w, h, border, depth; + boolean updated = FALSE; + + /* pbuffer has fixed geometry */ + if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER) + return FALSE; + + ok = XGetGeometry(xsurf->xdpy->dpy, xsurf->drawable, + &root, &x, &y, &w, &h, &border, &depth); + if (ok && (xsurf->width != w || xsurf->height != h)) { + xsurf->width = w; + xsurf->height = h; + + xsurf->server_stamp++; + updated = TRUE; + } + + return updated; +} + +static void +ximage_surface_notify_invalid(struct native_surface *nsurf) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + struct ximage_display *xdpy = xsurf->xdpy; + + xdpy->event_handler->invalid_surface(&xdpy->base, + &xsurf->base, xsurf->server_stamp); +} + +/** + * Update the buffers of the surface. It is a slow function due to the + * round-trip to the server. + */ +static boolean +ximage_surface_update_buffers(struct native_surface *nsurf, uint buffer_mask) +{ + struct ximage_surface *xsurf = ximage_surface(nsurf); + boolean updated; + uint new_valid; + int att; + + updated = ximage_surface_update_geometry(&xsurf->base); + if (updated) { + /* all buffers become invalid */ + xsurf->valid_mask = 0x0; + } + else { + buffer_mask &= ~xsurf->valid_mask; + /* all requested buffers are valid */ + if (!buffer_mask) { + xsurf->client_stamp = xsurf->server_stamp; + return TRUE; + } + } + + new_valid = 0x0; + for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { + if (native_attachment_mask_test(buffer_mask, att)) { + struct ximage_buffer *xbuf = &xsurf->buffers[att]; + + /* reallocate the texture */ + if (!ximage_surface_alloc_buffer(&xsurf->base, att)) + break; + + /* update ximage */ + if (xbuf->ximage) { + xbuf->ximage->width = xsurf->width; + xbuf->ximage->height = xsurf->height; + } + + new_valid |= (1 << att); + if (buffer_mask == new_valid) + break; + } + } + + xsurf->valid_mask |= new_valid; + xsurf->client_stamp = xsurf->server_stamp; + + return (new_valid == buffer_mask); +} + static boolean ximage_surface_draw_buffer(struct native_surface *nsurf, enum native_attachment which) @@ -246,7 +351,16 @@ ximage_surface_draw_buffer(struct native_surface *nsurf, static boolean ximage_surface_flush_frontbuffer(struct native_surface *nsurf) { - return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT); + struct ximage_surface *xsurf = ximage_surface(nsurf); + boolean ret; + + ret = ximage_surface_draw_buffer(&xsurf->base, + NATIVE_ATTACHMENT_FRONT_LEFT); + /* force buffers to be updated in next validation call */ + xsurf->server_stamp++; + ximage_surface_notify_invalid(&xsurf->base); + + return ret; } static boolean @@ -254,44 +368,26 @@ ximage_surface_swap_buffers(struct native_surface *nsurf) { struct ximage_surface *xsurf = ximage_surface(nsurf); struct ximage_buffer *xfront, *xback, xtmp; + boolean ret; + + /* display the back buffer first */ + ret = ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_BACK_LEFT); + /* force buffers to be updated in next validation call */ + xsurf->server_stamp++; + ximage_surface_notify_invalid(&xsurf->base); xfront = &xsurf->buffers[NATIVE_ATTACHMENT_FRONT_LEFT]; xback = &xsurf->buffers[NATIVE_ATTACHMENT_BACK_LEFT]; - /* draw the back buffer directly if there is no front buffer */ + /* skip swapping so that the front buffer is allocated only when needed */ if (!xfront->texture) - return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_BACK_LEFT); + return ret; - /* swap the buffers */ xtmp = *xfront; *xfront = *xback; *xback = xtmp; - /* the front/back textures are swapped */ - xsurf->sequence_number++; - - return ximage_surface_draw_buffer(nsurf, NATIVE_ATTACHMENT_FRONT_LEFT); -} - -static void -ximage_surface_update_geometry(struct native_surface *nsurf) -{ - struct ximage_surface *xsurf = ximage_surface(nsurf); - Status ok; - Window root; - int x, y; - unsigned int w, h, border, depth; - - /* pbuffer has fixed geometry */ - if (xsurf->type == XIMAGE_SURFACE_TYPE_PBUFFER) - return; - - ok = XGetGeometry(xsurf->xdpy->dpy, xsurf->drawable, - &root, &x, &y, &w, &h, &border, &depth); - if (ok) { - xsurf->width = w; - xsurf->height = h; - } + return ret; } static boolean @@ -300,44 +396,28 @@ ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask, int *width, int *height) { struct ximage_surface *xsurf = ximage_surface(nsurf); - boolean new_buffers = FALSE; - int att; - ximage_surface_update_geometry(&xsurf->base); + if (xsurf->client_stamp != xsurf->server_stamp || + (xsurf->valid_mask & attachment_mask) != attachment_mask) { + if (!ximage_surface_update_buffers(&xsurf->base, attachment_mask)) + return FALSE; + } - for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { - struct ximage_buffer *xbuf = &xsurf->buffers[att]; - - /* delay the allocation */ - if (!native_attachment_mask_test(attachment_mask, att)) - continue; - - /* reallocate the texture */ - if (!xbuf->texture || - xsurf->width != xbuf->texture->width0 || - xsurf->height != xbuf->texture->height0) { - new_buffers = TRUE; - if (ximage_surface_alloc_buffer(&xsurf->base, att)) { - /* update ximage */ - if (xbuf->ximage) { - xbuf->ximage->width = xsurf->width; - xbuf->ximage->height = xsurf->height; - } - } - } + if (seq_num) + *seq_num = xsurf->client_stamp; - if (textures) { - textures[att] = NULL; - pipe_texture_reference(&textures[att], xbuf->texture); + if (textures) { + int att; + for (att = 0; att < NUM_NATIVE_ATTACHMENTS; att++) { + if (native_attachment_mask_test(attachment_mask, att)) { + struct ximage_buffer *xbuf = &xsurf->buffers[att]; + + textures[att] = NULL; + pipe_texture_reference(&textures[att], xbuf->texture); + } } } - /* increase the sequence number so that caller knows */ - if (new_buffers) - xsurf->sequence_number++; - - if (seq_num) - *seq_num = xsurf->sequence_number; if (width) *width = xsurf->width; if (height) @@ -405,6 +485,9 @@ ximage_display_create_surface(struct native_display *ndpy, return NULL; } + /* initialize the geometry */ + ximage_surface_update_buffers(&xsurf->base, 0x0); + for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++) { struct ximage_buffer *xbuf = &xsurf->buffers[i]; @@ -499,13 +582,13 @@ choose_format(const XVisualInfo *vinfo) /* TODO elaborate the formats */ switch (vinfo->depth) { case 32: - fmt = PIPE_FORMAT_A8R8G8B8_UNORM; + fmt = PIPE_FORMAT_B8G8R8A8_UNORM; break; case 24: - fmt = PIPE_FORMAT_X8R8G8B8_UNORM; + fmt = PIPE_FORMAT_B8G8R8X8_UNORM; break; case 16: - fmt = PIPE_FORMAT_R5G6B5_UNORM; + fmt = PIPE_FORMAT_B5G6R5_UNORM; break; default: fmt = PIPE_FORMAT_NONE; @@ -558,8 +641,8 @@ ximage_display_get_configs(struct native_display *ndpy, int *num_configs) xconf->base.stencil_format = PIPE_FORMAT_NONE; /* create the second config with depth/stencil buffer */ if (j == 1) { - xconf->base.depth_format = PIPE_FORMAT_S8Z24_UNORM; - xconf->base.stencil_format = PIPE_FORMAT_S8Z24_UNORM; + xconf->base.depth_format = PIPE_FORMAT_Z24S8_UNORM; + xconf->base.stencil_format = PIPE_FORMAT_Z24S8_UNORM; mode->depthBits = 24; mode->stencilBits = 8; mode->haveDepthBuffer = TRUE; @@ -607,13 +690,13 @@ ximage_display_is_pixmap_supported(struct native_display *ndpy, depth = x11_drawable_get_depth(xdpy->xscr, (Drawable) pix); switch (depth) { case 32: - fmt = PIPE_FORMAT_A8R8G8B8_UNORM; + fmt = PIPE_FORMAT_B8G8R8A8_UNORM; break; case 24: - fmt = PIPE_FORMAT_X8R8G8B8_UNORM; + fmt = PIPE_FORMAT_B8G8R8X8_UNORM; break; case 16: - fmt = PIPE_FORMAT_R5G6B5_UNORM; + fmt = PIPE_FORMAT_B5G6R5_UNORM; break; default: fmt = PIPE_FORMAT_NONE; @@ -623,6 +706,25 @@ ximage_display_is_pixmap_supported(struct native_display *ndpy, return (fmt == nconf->color_format); } +static int +ximage_display_get_param(struct native_display *ndpy, + enum native_param_type param) +{ + int val; + + switch (param) { + case NATIVE_PARAM_USE_NATIVE_BUFFER: + /* private buffers are allocated */ + val = FALSE; + break; + default: + val = 0; + break; + } + + return val; +} + static void ximage_display_destroy(struct native_display *ndpy) { @@ -641,7 +743,9 @@ ximage_display_destroy(struct native_display *ndpy) } struct native_display * -x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm) +x11_create_ximage_display(EGLNativeDisplayType dpy, + struct native_event_handler *event_handler, + boolean use_xshm) { struct ximage_display *xdpy; @@ -666,6 +770,8 @@ x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm) return NULL; } + xdpy->event_handler = event_handler; + xdpy->use_xshm = (use_xshm && x11_screen_support(xdpy->xscr, X11_SCREEN_EXTENSION_XSHM)); @@ -673,6 +779,7 @@ x11_create_ximage_display(EGLNativeDisplayType dpy, boolean use_xshm) xdpy->base.screen = softpipe_create_screen(xdpy->winsys); xdpy->base.destroy = ximage_display_destroy; + xdpy->base.get_param = ximage_display_get_param; xdpy->base.get_configs = ximage_display_get_configs; xdpy->base.is_pixmap_supported = ximage_display_is_pixmap_supported; diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.c b/src/gallium/state_trackers/egl/x11/x11_screen.c index d72bfc99d3e..f4096114844 100644 --- a/src/gallium/state_trackers/egl/x11/x11_screen.c +++ b/src/gallium/state_trackers/egl/x11/x11_screen.c @@ -39,6 +39,9 @@ #include "glxinit.h" struct x11_screen { + /* dummy base class */ + struct __GLXDRIdisplayRec base; + Display *dpy; int number; @@ -53,6 +56,9 @@ struct x11_screen { char *dri_device; int dri_fd; + x11_drawable_invalidate_buffers dri_invalidate_buffers; + void *dri_user_data; + XVisualInfo *visuals; int num_visuals; @@ -98,6 +104,8 @@ x11_screen_destroy(struct x11_screen *xscr) Xfree(xscr->dri_device); /* xscr->glx_dpy will be destroyed with the X display */ + if (xscr->glx_dpy) + xscr->glx_dpy->dri2Display = NULL; if (xscr->visuals) XFree(xscr->visuals); @@ -247,24 +255,25 @@ x11_screen_get_glx_visuals(struct x11_screen *xscr) : NULL; } -static boolean -x11_screen_is_driver_equal(struct x11_screen *xscr, const char *driver) -{ - return (strcmp(xscr->dri_driver, driver) == 0); -} - /** * Probe the screen for the DRI2 driver name. */ const char * -x11_screen_probe_dri2(struct x11_screen *xscr) +x11_screen_probe_dri2(struct x11_screen *xscr, int *major, int *minor) { + if (!x11_screen_init_dri2(xscr)) + return NULL; + /* get the driver name and the device name */ if (!xscr->dri_driver) { if (!DRI2Connect(xscr->dpy, RootWindow(xscr->dpy, xscr->number), &xscr->dri_driver, &xscr->dri_device)) xscr->dri_driver = xscr->dri_device = NULL; } + if (major) + *major = xscr->dri_major; + if (minor) + *minor = xscr->dri_minor; return xscr->dri_driver; } @@ -274,21 +283,17 @@ x11_screen_probe_dri2(struct x11_screen *xscr) * descriptor will be closed automatically when the screen is destoryed. */ int -x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver) +x11_screen_enable_dri2(struct x11_screen *xscr, + x11_drawable_invalidate_buffers invalidate_buffers, + void *user_data) { if (xscr->dri_fd < 0) { int fd; drm_magic_t magic; /* get the driver name and the device name first */ - if (!x11_screen_probe_dri2(xscr)) - return -1; - - if (!x11_screen_is_driver_equal(xscr, driver)) { - _eglLog(_EGL_WARNING, "Driver mismatch: %s != %s", - xscr->dri_driver, driver); + if (!x11_screen_probe_dri2(xscr, NULL, NULL)) return -1; - } fd = open(xscr->dri_device, O_RDWR); if (fd < 0) { @@ -310,6 +315,22 @@ x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver) return -1; } + if (!x11_screen_init_glx(xscr)) { + _eglLog(_EGL_WARNING, "failed to initialize GLX"); + close(fd); + return -1; + } + if (xscr->glx_dpy->dri2Display) { + _eglLog(_EGL_WARNING, + "display is already managed by another x11 screen"); + close(fd); + return -1; + } + + xscr->glx_dpy->dri2Display = (__GLXDRIdisplay *) xscr; + xscr->dri_invalidate_buffers = invalidate_buffers; + xscr->dri_user_data = user_data; + xscr->dri_fd = fd; } @@ -451,3 +472,20 @@ x11_context_modes_count(const __GLcontextModes *modes) count++; return count; } + +/** + * This is called from src/glx/dri2.c. + */ +void +dri2InvalidateBuffers(Display *dpy, XID drawable) +{ + __GLXdisplayPrivate *priv = __glXInitialize(dpy); + struct x11_screen *xscr = NULL; + + if (priv && priv->dri2Display) + xscr = (struct x11_screen *) priv->dri2Display; + if (!xscr || !xscr->dri_invalidate_buffers) + return; + + xscr->dri_invalidate_buffers(xscr, drawable, xscr->dri_user_data); +} diff --git a/src/gallium/state_trackers/egl/x11/x11_screen.h b/src/gallium/state_trackers/egl/x11/x11_screen.h index 5432858ac3e..37e8d5a40e6 100644 --- a/src/gallium/state_trackers/egl/x11/x11_screen.h +++ b/src/gallium/state_trackers/egl/x11/x11_screen.h @@ -48,6 +48,10 @@ struct x11_drawable_buffer { struct x11_screen; +typedef void (*x11_drawable_invalidate_buffers)(struct x11_screen *xscr, + Drawable drawable, + void *user_data); + struct x11_screen * x11_screen_create(Display *dpy, int screen); @@ -71,10 +75,12 @@ const __GLcontextModes * x11_screen_get_glx_visuals(struct x11_screen *xscr); const char * -x11_screen_probe_dri2(struct x11_screen *xscr); +x11_screen_probe_dri2(struct x11_screen *xscr, int *major, int *minor); int -x11_screen_enable_dri2(struct x11_screen *xscr, const char *driver); +x11_screen_enable_dri2(struct x11_screen *xscr, + x11_drawable_invalidate_buffers invalidate_buffers, + void *user_data); __GLcontextModes * x11_context_modes_create(unsigned count); diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c index 3caf56e924b..08bf624b5c1 100644 --- a/src/gallium/state_trackers/glx/xlib/glx_api.c +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c @@ -280,7 +280,7 @@ default_depth_bits(void) int zBits; const char *zEnv = _mesa_getenv("MESA_GLX_DEPTH_BITS"); if (zEnv) - zBits = _mesa_atoi(zEnv); + zBits = atoi(zEnv); else zBits = DEFAULT_SOFTWARE_DEPTH_BITS; return zBits; @@ -292,7 +292,7 @@ default_alpha_bits(void) int aBits; const char *aEnv = _mesa_getenv("MESA_GLX_ALPHA_BITS"); if (aEnv) - aBits = _mesa_atoi(aEnv); + aBits = atoi(aEnv); else aBits = 0; return aBits; @@ -442,17 +442,17 @@ get_env_visual(Display *dpy, int scr, const char *varname) return NULL; } - _mesa_strncpy( value, _mesa_getenv(varname), 100 ); + strncpy( value, _mesa_getenv(varname), 100 ); value[99] = 0; sscanf( value, "%s %d", type, &depth ); - if (_mesa_strcmp(type,"TrueColor")==0) xclass = TrueColor; - else if (_mesa_strcmp(type,"DirectColor")==0) xclass = DirectColor; - else if (_mesa_strcmp(type,"PseudoColor")==0) xclass = PseudoColor; - else if (_mesa_strcmp(type,"StaticColor")==0) xclass = StaticColor; - else if (_mesa_strcmp(type,"GrayScale")==0) xclass = GrayScale; - else if (_mesa_strcmp(type,"StaticGray")==0) xclass = StaticGray; + if (strcmp(type,"TrueColor")==0) xclass = TrueColor; + else if (strcmp(type,"DirectColor")==0) xclass = DirectColor; + else if (strcmp(type,"PseudoColor")==0) xclass = PseudoColor; + else if (strcmp(type,"StaticColor")==0) xclass = StaticColor; + else if (strcmp(type,"GrayScale")==0) xclass = GrayScale; + else if (strcmp(type,"StaticGray")==0) xclass = StaticGray; if (xclass>-1 && depth>0) { vis = get_visual( dpy, scr, depth, xclass ); @@ -689,6 +689,8 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig ) int desiredVisualID = -1; int numAux = 0; + xmesa_init(); + parselist = list; while (*parselist) { @@ -941,9 +943,6 @@ choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig ) /* give the visual some useful GLX attributes */ double_flag = GL_TRUE; rgb_flag = GL_TRUE; - depth_size = default_depth_bits(); - stencil_size = STENCIL_BITS; - /* XXX accum??? */ } } else if (level==0) { @@ -1018,9 +1017,9 @@ glXChooseVisual( Display *dpy, int screen, int *list ) xmvis = choose_visual(dpy, screen, list, GL_FALSE); if (xmvis) { /* create a new vishandle - the cached one may be stale */ - xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo)); + xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo)); if (xmvis->vishandle) { - _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); + memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); } return xmvis->vishandle; } @@ -1055,7 +1054,7 @@ glXCreateContext( Display *dpy, XVisualInfo *visinfo, xmvis = create_glx_visual( dpy, visinfo ); if (!xmvis) { /* unusable visual */ - _mesa_free(glxCtx); + free(glxCtx); return NULL; } } @@ -1063,7 +1062,7 @@ glXCreateContext( Display *dpy, XVisualInfo *visinfo, glxCtx->xmesaContext = XMesaCreateContext(xmvis, shareCtx ? shareCtx->xmesaContext : NULL); if (!glxCtx->xmesaContext) { - _mesa_free(glxCtx); + free(glxCtx); return NULL; } @@ -1336,7 +1335,7 @@ glXDestroyContext( Display *dpy, GLXContext ctx ) MakeCurrent_PrevReadBuffer = 0; XMesaDestroyContext( glxCtx->xmesaContext ); XMesaGarbageCollect(); - _mesa_free(glxCtx); + free(glxCtx); } @@ -1679,8 +1678,8 @@ PUBLIC const char * glXQueryServerString( Display *dpy, int screen, int name ) { static char version[1000]; - _mesa_sprintf(version, "%d.%d %s", - SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION); + sprintf(version, "%d.%d %s", + SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION); (void) dpy; (void) screen; @@ -1704,8 +1703,8 @@ PUBLIC const char * glXGetClientString( Display *dpy, int name ) { static char version[1000]; - _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION, - CLIENT_MINOR_VERSION, MESA_GLX_VERSION); + sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION, + CLIENT_MINOR_VERSION, MESA_GLX_VERSION); (void) dpy; @@ -1755,7 +1754,7 @@ glXGetFBConfigs( Display *dpy, int screen, int *nelements ) visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements); if (*nelements > 0) { XMesaVisual *results; - results = (XMesaVisual *) _mesa_malloc(*nelements * sizeof(XMesaVisual)); + results = (XMesaVisual *) malloc(*nelements * sizeof(XMesaVisual)); if (!results) { *nelements = 0; return NULL; @@ -1782,7 +1781,7 @@ glXChooseFBConfig( Display *dpy, int screen, xmvis = choose_visual(dpy, screen, attribList, GL_TRUE); if (xmvis) { - GLXFBConfig *config = (GLXFBConfig *) _mesa_malloc(sizeof(XMesaVisual)); + GLXFBConfig *config = (GLXFBConfig *) malloc(sizeof(XMesaVisual)); if (!config) { *nitems = 0; return NULL; @@ -1807,9 +1806,9 @@ glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config ) return xmvis->vishandle; #else /* create a new vishandle - the cached one may be stale */ - xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo)); + xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo)); if (xmvis->vishandle) { - _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); + memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo)); } return xmvis->vishandle; #endif @@ -2112,7 +2111,7 @@ glXCreateNewContext( Display *dpy, GLXFBConfig config, glxCtx->xmesaContext = XMesaCreateContext(xmvis, shareCtx ? shareCtx->xmesaContext : NULL); if (!glxCtx->xmesaContext) { - _mesa_free(glxCtx); + free(glxCtx); return NULL; } @@ -2332,7 +2331,7 @@ glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_ glxCtx->xmesaContext = XMesaCreateContext(xmvis, shareCtx ? shareCtx->xmesaContext : NULL); if (!glxCtx->xmesaContext) { - _mesa_free(glxCtx); + free(glxCtx); return NULL; } diff --git a/src/gallium/state_trackers/glx/xlib/glx_usefont.c b/src/gallium/state_trackers/glx/xlib/glx_usefont.c index e502198b204..8903b0e6cbd 100644 --- a/src/gallium/state_trackers/glx/xlib/glx_usefont.c +++ b/src/gallium/state_trackers/glx/xlib/glx_usefont.c @@ -343,7 +343,7 @@ glXUseXFont(Font font, int first, int count, int listbase) glNewList(list, GL_COMPILE); if (valid && (bm_width > 0) && (bm_height > 0)) { - MEMSET(bm, '\0', bm_width * bm_height); + memset(bm, '\0', bm_width * bm_height); fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm); glBitmap(width, height, x0, y0, dx, dy, bm); diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index fb314f3b528..217bdeff75e 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -175,7 +175,7 @@ bits_per_pixel( XMesaVisual xmv ) /* grab the bits/pixel value */ bitsPerPixel = img->bits_per_pixel; /* free the XImage */ - _mesa_free( img->data ); + free( img->data ); img->data = NULL; XDestroyImage( img ); return bitsPerPixel; @@ -274,10 +274,10 @@ choose_pixel_format(XMesaVisual v) && v->BitsPerPixel == 32) { if (native_byte_order) { /* no byteswapping needed */ - return 0 /* PIXEL_FORMAT_U_A8_B8_G8_R8 */; + return PIPE_FORMAT_R8G8B8A8_UNORM; } else { - return PIPE_FORMAT_R8G8B8A8_UNORM; + return PIPE_FORMAT_A8B8G8R8_UNORM; } } else if ( GET_REDMASK(v) == 0xff0000 @@ -286,10 +286,10 @@ choose_pixel_format(XMesaVisual v) && v->BitsPerPixel == 32) { if (native_byte_order) { /* no byteswapping needed */ - return PIPE_FORMAT_A8R8G8B8_UNORM; + return PIPE_FORMAT_B8G8R8A8_UNORM; } else { - return PIPE_FORMAT_B8G8R8A8_UNORM; + return PIPE_FORMAT_A8R8G8B8_UNORM; } } else if ( GET_REDMASK(v) == 0x0000ff00 @@ -298,10 +298,10 @@ choose_pixel_format(XMesaVisual v) && v->BitsPerPixel == 32) { if (native_byte_order) { /* no byteswapping needed */ - return PIPE_FORMAT_B8G8R8A8_UNORM; + return PIPE_FORMAT_A8R8G8B8_UNORM; } else { - return PIPE_FORMAT_A8R8G8B8_UNORM; + return PIPE_FORMAT_B8G8R8A8_UNORM; } } else if ( GET_REDMASK(v) == 0xf800 @@ -310,7 +310,7 @@ choose_pixel_format(XMesaVisual v) && native_byte_order && v->BitsPerPixel == 16) { /* 5-6-5 RGB */ - return PIPE_FORMAT_R5G6B5_UNORM; + return PIPE_FORMAT_B5G6R5_UNORM; } assert(0); @@ -319,6 +319,51 @@ choose_pixel_format(XMesaVisual v) +/** + * Query the default gallium screen for a Z/Stencil format that + * at least matches the given depthBits and stencilBits. + */ +static void +xmesa_choose_z_stencil_format(int depthBits, int stencilBits, + enum pipe_format *depthFormat, + enum pipe_format *stencilFormat) +{ + const enum pipe_texture_target target = PIPE_TEXTURE_2D; + const unsigned tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL; + const unsigned geom_flags = (PIPE_TEXTURE_GEOM_NON_SQUARE | + PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO); + static enum pipe_format formats[] = { + PIPE_FORMAT_S8Z24_UNORM, + PIPE_FORMAT_Z24S8_UNORM, + PIPE_FORMAT_Z16_UNORM, + PIPE_FORMAT_Z32_UNORM + }; + int i; + + assert(screen); + + *depthFormat = *stencilFormat = PIPE_FORMAT_NONE; + + /* search for supported format */ + for (i = 0; i < Elements(formats); i++) { + if (screen->is_format_supported(screen, formats[i], + target, tex_usage, geom_flags)) { + *depthFormat = formats[i]; + break; + } + } + + if (stencilBits) { + *stencilFormat = *depthFormat; + } + + /* XXX we should check that he chosen format has at least as many bits + * as what was requested. + */ +} + + + /**********************************************************************/ /***** Linked list of XMesaBuffers *****/ /**********************************************************************/ @@ -361,34 +406,9 @@ create_xmesa_buffer(Drawable d, BufferType type, /* determine PIPE_FORMATs for buffers */ colorFormat = choose_pixel_format(vis); - if (vis->mesa_visual.depthBits == 0) - depthFormat = PIPE_FORMAT_NONE; -#ifdef GALLIUM_CELL /* XXX temporary for Cell! */ - else - depthFormat = PIPE_FORMAT_S8Z24_UNORM; -#else - else if (vis->mesa_visual.depthBits <= 16) - depthFormat = PIPE_FORMAT_Z16_UNORM; - else if (vis->mesa_visual.depthBits <= 24) - depthFormat = PIPE_FORMAT_S8Z24_UNORM; - else - depthFormat = PIPE_FORMAT_Z32_UNORM; -#endif - - if (vis->mesa_visual.stencilBits == 8) { - if (depthFormat == PIPE_FORMAT_S8Z24_UNORM) - stencilFormat = depthFormat; - else - stencilFormat = PIPE_FORMAT_S8_UNORM; - } - else { - /* no stencil */ - stencilFormat = PIPE_FORMAT_NONE; - if (depthFormat == PIPE_FORMAT_S8Z24_UNORM) { - /* use 24-bit Z, undefined stencil channel */ - depthFormat = PIPE_FORMAT_X8Z24_UNORM; - } - } + xmesa_choose_z_stencil_format(vis->mesa_visual.depthBits, + vis->mesa_visual.stencilBits, + &depthFormat, &stencilFormat); get_drawable_size(vis->display, d, &width, &height); @@ -550,10 +570,10 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, * reports bugs. */ if (_mesa_getenv("MESA_INFO")) { - _mesa_printf("X/Mesa visual = %p\n", (void *) v); - _mesa_printf("X/Mesa level = %d\n", v->mesa_visual.level); - _mesa_printf("X/Mesa depth = %d\n", v->visinfo->depth); - _mesa_printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); + printf("X/Mesa visual = %p\n", (void *) v); + printf("X/Mesa level = %d\n", v->mesa_visual.level); + printf("X/Mesa depth = %d\n", v->visinfo->depth); + printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); } if (b && window) { @@ -653,6 +673,8 @@ XMesaVisual XMesaCreateVisual( Display *display, XMesaVisual v; GLint red_bits, green_bits, blue_bits, alpha_bits; + xmesa_init(); + /* For debugging only */ if (_mesa_getenv("MESA_XSYNC")) { /* This makes debugging X easier. @@ -669,16 +691,16 @@ XMesaVisual XMesaCreateVisual( Display *display, v->display = display; - /* Save a copy of the XVisualInfo struct because the user may X_mesa_free() + /* Save a copy of the XVisualInfo struct because the user may Xfree() * the struct but we may need some of the information contained in it * at a later time. */ v->visinfo = (XVisualInfo *) MALLOC(sizeof(*visinfo)); if (!v->visinfo) { - _mesa_free(v); + free(v); return NULL; } - MEMCPY(v->visinfo, visinfo, sizeof(*visinfo)); + memcpy(v->visinfo, visinfo, sizeof(*visinfo)); v->ximage_flag = ximage_flag; @@ -724,10 +746,9 @@ XMesaVisual XMesaCreateVisual( Display *display, } _mesa_initialize_visual( &v->mesa_visual, - rgb_flag, db_flag, stereo_flag, + db_flag, stereo_flag, red_bits, green_bits, blue_bits, alpha_bits, - v->mesa_visual.indexBits, depth_size, stencil_size, accum_red_size, accum_green_size, @@ -743,11 +764,26 @@ XMesaVisual XMesaCreateVisual( Display *display, PUBLIC void XMesaDestroyVisual( XMesaVisual v ) { - _mesa_free(v->visinfo); - _mesa_free(v); + free(v->visinfo); + free(v); } +/** + * Do one-time initializations. + */ +void +xmesa_init(void) +{ + static GLboolean firstTime = GL_TRUE; + if (firstTime) { + pipe_mutex_init(_xmesa_lock); + _screen = driver.create_pipe_screen(); + screen = trace_screen_create( _screen ); + firstTime = GL_FALSE; + } +} + /** * Create a new XMesaContext. @@ -759,18 +795,12 @@ void XMesaDestroyVisual( XMesaVisual v ) PUBLIC XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) { - static GLboolean firstTime = GL_TRUE; struct pipe_context *pipe = NULL; XMesaContext c; GLcontext *mesaCtx; uint pf; - if (firstTime) { - pipe_mutex_init(_xmesa_lock); - _screen = driver.create_pipe_screen(); - screen = trace_screen_create( _screen ); - firstTime = GL_FALSE; - } + xmesa_init(); /* Note: the XMesaContext contains a Mesa GLcontext struct (inheritance) */ c = (XMesaContext) CALLOC_STRUCT(xmesa_context); @@ -811,7 +841,7 @@ fail: else if (pipe) pipe->destroy(pipe); - _mesa_free(c); + free(c); return NULL; } @@ -828,7 +858,7 @@ void XMesaDestroyContext( XMesaContext c ) screen->destroy(screen); */ - _mesa_free(c); + free(c); } @@ -1148,6 +1178,7 @@ void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) if (!surf_front || !surf_back) return; + assert(pipe); pipe->surface_copy(pipe, surf_front, x, y, /* dest */ surf_back, x, y, /* src */ diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.h b/src/gallium/state_trackers/glx/xlib/xm_api.h index 63a329cbe05..004cb260dcd 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.h +++ b/src/gallium/state_trackers/glx/xlib/xm_api.h @@ -367,6 +367,9 @@ xmesa_buffer(GLframebuffer *fb) extern void +xmesa_init(void); + +extern void xmesa_delete_framebuffer(struct gl_framebuffer *fb); extern XMesaBuffer diff --git a/src/gallium/state_trackers/python/README b/src/gallium/state_trackers/python/README index 4a060730242..e24a262aba9 100644 --- a/src/gallium/state_trackers/python/README +++ b/src/gallium/state_trackers/python/README @@ -18,7 +18,7 @@ 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,trace winsys=none + scons debug=yes statetrackers=python drivers=softpipe winsys=none To use it set PYTHONPATH appropriately, e.g, in Linux do: diff --git a/src/gallium/state_trackers/python/p_state.i b/src/gallium/state_trackers/python/p_state.i index 5afe4d49082..eda77b56f8e 100644 --- a/src/gallium/state_trackers/python/p_state.i +++ b/src/gallium/state_trackers/python/p_state.i @@ -69,7 +69,7 @@ pipe_blend_state(const char *STRING, unsigned LENGTH) { struct pipe_blend_state *state; - state = CALLOC_STRUCT(pipe_framebuffer_state); + state = CALLOC_STRUCT(pipe_blend_state); if (state) { LENGTH = MIN2(sizeof *state, LENGTH); memcpy(state, STRING, LENGTH); diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index a3798a55212..45e78417500 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -244,7 +244,7 @@ st_context_create(struct st_device *st_dev) memset( &templat, 0, sizeof( templat ) ); templat.target = PIPE_TEXTURE_2D; - templat.format = PIPE_FORMAT_A8R8G8B8_UNORM; + templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; templat.width0 = 1; templat.height0 = 1; templat.depth0 = 1; diff --git a/src/gallium/state_trackers/python/st_sample.c b/src/gallium/state_trackers/python/st_sample.c index 32a6551a87a..e1808153461 100644 --- a/src/gallium/state_trackers/python/st_sample.c +++ b/src/gallium/state_trackers/python/st_sample.c @@ -485,7 +485,7 @@ st_sample_generic_pixel_block(enum pipe_format format, w, h, rgba, rgba_stride); - if(format == PIPE_FORMAT_YCBCR || format == PIPE_FORMAT_YCBCR_REV) { + 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) { 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 differnew file mode 100644 index 00000000000..c947a7b8813 --- /dev/null +++ b/src/gallium/state_trackers/python/tests/regress/fragment-shader/frag-abs.png diff --git a/src/gallium/state_trackers/vega/Makefile b/src/gallium/state_trackers/vega/Makefile index 037d8dc911a..7f04b2aa832 100644 --- a/src/gallium/state_trackers/vega/Makefile +++ b/src/gallium/state_trackers/vega/Makefile @@ -53,7 +53,7 @@ INCLUDE_DIRS = \ .c.o: - $(CC) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) $< -o $@ + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ default: depend $(TOP)/$(LIB_DIR)/$(VG_LIB_NAME) diff --git a/src/gallium/state_trackers/vega/api_filters.c b/src/gallium/state_trackers/vega/api_filters.c index 20c72c1ff54..02248ad4337 100644 --- a/src/gallium/state_trackers/vega/api_filters.c +++ b/src/gallium/state_trackers/vega/api_filters.c @@ -67,7 +67,7 @@ static INLINE struct pipe_texture *create_texture_1d(struct vg_context *ctx, memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_1D; - templ.format = PIPE_FORMAT_A8R8G8B8_UNORM; + templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; templ.last_level = 0; templ.width0 = color_data_len; templ.height0 = 1; diff --git a/src/gallium/state_trackers/vega/image.c b/src/gallium/state_trackers/vega/image.c index 2e10965be4f..41c979bfecf 100644 --- a/src/gallium/state_trackers/vega/image.c +++ b/src/gallium/state_trackers/vega/image.c @@ -48,16 +48,16 @@ static enum pipe_format vg_format_to_pipe(VGImageFormat format) { switch(format) { case VG_sRGB_565: - return PIPE_FORMAT_R5G6B5_UNORM; + return PIPE_FORMAT_B5G6R5_UNORM; case VG_sRGBA_5551: - return PIPE_FORMAT_A1R5G5B5_UNORM; + return PIPE_FORMAT_B5G5R5A1_UNORM; case VG_sRGBA_4444: - return PIPE_FORMAT_A4R4G4B4_UNORM; + return PIPE_FORMAT_B4G4R4A4_UNORM; case VG_sL_8: case VG_lL_8: return PIPE_FORMAT_L8_UNORM; case VG_BW_1: - return PIPE_FORMAT_A8R8G8B8_UNORM; + return PIPE_FORMAT_B8G8R8A8_UNORM; case VG_A_8: return PIPE_FORMAT_A8_UNORM; #ifdef OPENVG_VERSION_1_1 @@ -66,7 +66,7 @@ static enum pipe_format vg_format_to_pipe(VGImageFormat format) return PIPE_FORMAT_A8_UNORM; #endif default: - return PIPE_FORMAT_A8R8G8B8_UNORM; + return PIPE_FORMAT_B8G8R8A8_UNORM; } } diff --git a/src/gallium/state_trackers/vega/mask.c b/src/gallium/state_trackers/vega/mask.c index 467b95b7519..839dc19a3b8 100644 --- a/src/gallium/state_trackers/vega/mask.c +++ b/src/gallium/state_trackers/vega/mask.c @@ -488,7 +488,7 @@ struct vg_mask_layer * mask_layer_create(VGint width, VGint height) memset(&pt, 0, sizeof(pt)); pt.target = PIPE_TEXTURE_2D; - pt.format = PIPE_FORMAT_A8R8G8B8_UNORM; + pt.format = PIPE_FORMAT_B8G8R8A8_UNORM; pt.last_level = 0; pt.width0 = width; pt.height0 = height; diff --git a/src/gallium/state_trackers/vega/paint.c b/src/gallium/state_trackers/vega/paint.c index 3405d635f0c..cdb87d3bf68 100644 --- a/src/gallium/state_trackers/vega/paint.c +++ b/src/gallium/state_trackers/vega/paint.c @@ -151,7 +151,7 @@ static INLINE struct pipe_texture *create_gradient_texture(struct vg_paint *p) memset(&templ, 0, sizeof(templ)); templ.target = PIPE_TEXTURE_1D; - templ.format = PIPE_FORMAT_A8R8G8B8_UNORM; + templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; templ.last_level = 0; templ.width0 = 1024; templ.height0 = 1; @@ -639,9 +639,6 @@ VGint paint_bind_samplers(struct vg_paint *paint, struct pipe_sampler_state **sa } break; default: - samplers[0] = &paint->pattern.sampler; /* dummy */ - textures[0] = 0; - return 0; break; } return 0; diff --git a/src/gallium/state_trackers/vega/vg_tracker.c b/src/gallium/state_trackers/vega/vg_tracker.c index a94dfb160c9..57d3baad7fb 100644 --- a/src/gallium/state_trackers/vega/vg_tracker.c +++ b/src/gallium/state_trackers/vega/vg_tracker.c @@ -51,7 +51,7 @@ create_texture(struct pipe_context *pipe, enum pipe_format format, templ.format = format; } else { - templ.format = PIPE_FORMAT_A8R8G8B8_UNORM; + templ.format = PIPE_FORMAT_B8G8R8A8_UNORM; } templ.target = PIPE_TEXTURE_2D; @@ -186,7 +186,7 @@ struct st_framebuffer * st_create_framebuffer(const void *visual, if (stencilFormat == depthFormat) stfb->dsrb = st_new_renderbuffer_fb(stencilFormat); else - stfb->dsrb = st_new_renderbuffer_fb(PIPE_FORMAT_S8Z24_UNORM); + stfb->dsrb = st_new_renderbuffer_fb(PIPE_FORMAT_Z24S8_UNORM); /*### currently we always allocate it but it's possible it's not necessary if EGL_ALPHA_MASK_SIZE was 0 @@ -209,12 +209,12 @@ static void setup_new_alpha_mask(struct vg_context *ctx, struct pipe_texture *old_texture = stfb->alpha_mask; /* - we use PIPE_FORMAT_A8R8G8B8_UNORM because we want to render to + we use PIPE_FORMAT_B8G8R8A8_UNORM because we want to render to this texture and use it as a sampler, so while this wastes some space it makes both of those a lot simpler */ stfb->alpha_mask = - create_texture(pipe, PIPE_FORMAT_A8R8G8B8_UNORM, width, height); + create_texture(pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height); if (!stfb->alpha_mask) { if (old_texture) @@ -327,7 +327,7 @@ void st_resize_framebuffer(struct st_framebuffer *stfb, setup_new_alpha_mask(ctx, stfb, width, height); pipe_texture_reference( &stfb->blend_texture, NULL ); - stfb->blend_texture = create_texture(ctx->pipe, PIPE_FORMAT_A8R8G8B8_UNORM, + stfb->blend_texture = create_texture(ctx->pipe, PIPE_FORMAT_B8G8R8A8_UNORM, width, height); } diff --git a/src/gallium/state_trackers/wgl/stw_device.c b/src/gallium/state_trackers/wgl/stw_device.c index e5fa6ac8eb4..472a2a5379a 100644 --- a/src/gallium/state_trackers/wgl/stw_device.c +++ b/src/gallium/state_trackers/wgl/stw_device.c @@ -47,7 +47,6 @@ #ifdef WIN32_THREADS extern _glthread_Mutex OneTimeLock; -extern void FreeAllTSD(void); #endif @@ -183,7 +182,8 @@ stw_cleanup(void) #ifdef WIN32_THREADS _glthread_DESTROY_MUTEX(OneTimeLock); - FreeAllTSD(); + + _glapi_destroy_multithread(); #endif #ifdef DEBUG diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.c b/src/gallium/state_trackers/wgl/stw_pixelformat.c index b750b03695f..bc28f31ed1c 100644 --- a/src/gallium/state_trackers/wgl/stw_pixelformat.c +++ b/src/gallium/state_trackers/wgl/stw_pixelformat.c @@ -74,17 +74,17 @@ struct stw_pf_depth_info static const struct stw_pf_color_info stw_pf_color[] = { /* no-alpha */ - { PIPE_FORMAT_X8R8G8B8_UNORM, { 8, 8, 8, 0}, {16, 8, 0, 0} }, - { PIPE_FORMAT_B8G8R8X8_UNORM, { 8, 8, 8, 0}, { 8, 16, 24, 0} }, - { PIPE_FORMAT_R5G6B5_UNORM, { 5, 6, 5, 0}, {11, 5, 0, 0} }, + { PIPE_FORMAT_B8G8R8X8_UNORM, { 8, 8, 8, 0}, {16, 8, 0, 0} }, + { PIPE_FORMAT_X8R8G8B8_UNORM, { 8, 8, 8, 0}, { 8, 16, 24, 0} }, + { PIPE_FORMAT_B5G6R5_UNORM, { 5, 6, 5, 0}, {11, 5, 0, 0} }, /* alpha */ - { PIPE_FORMAT_A8R8G8B8_UNORM, { 8, 8, 8, 8}, {16, 8, 0, 24} }, - { PIPE_FORMAT_B8G8R8A8_UNORM, { 8, 8, 8, 8}, { 8, 16, 24, 0} }, + { PIPE_FORMAT_B8G8R8A8_UNORM, { 8, 8, 8, 8}, {16, 8, 0, 24} }, + { PIPE_FORMAT_A8R8G8B8_UNORM, { 8, 8, 8, 8}, { 8, 16, 24, 0} }, #if 0 - { PIPE_FORMAT_A2B10G10R10_UNORM, {10, 10, 10, 2}, { 0, 10, 20, 30} }, + { PIPE_FORMAT_R10G10B10A2_UNORM, {10, 10, 10, 2}, { 0, 10, 20, 30} }, #endif - { PIPE_FORMAT_A1R5G5B5_UNORM, { 5, 5, 5, 1}, {10, 5, 0, 15} }, - { PIPE_FORMAT_A4R4G4B4_UNORM, { 4, 4, 4, 4}, {16, 4, 0, 12} } + { PIPE_FORMAT_B5G5R5A1_UNORM, { 5, 5, 5, 1}, {10, 5, 0, 15} }, + { PIPE_FORMAT_B4G4R4A4_UNORM, { 4, 4, 4, 4}, {16, 4, 0, 12} } }; @@ -92,12 +92,12 @@ static const struct stw_pf_depth_info stw_pf_depth_stencil[] = { /* pure depth */ { PIPE_FORMAT_Z32_UNORM, {32, 0} }, - { PIPE_FORMAT_Z24X8_UNORM, {24, 0} }, { PIPE_FORMAT_X8Z24_UNORM, {24, 0} }, + { PIPE_FORMAT_Z24X8_UNORM, {24, 0} }, { PIPE_FORMAT_Z16_UNORM, {16, 0} }, /* combined depth-stencil */ - { PIPE_FORMAT_S8Z24_UNORM, {24, 8} }, - { PIPE_FORMAT_Z24S8_UNORM, {24, 8} } + { PIPE_FORMAT_Z24S8_UNORM, {24, 8} }, + { PIPE_FORMAT_S8Z24_UNORM, {24, 8} } }; @@ -271,14 +271,12 @@ stw_pixelformat_visual(GLvisual *visual, memset(visual, 0, sizeof *visual); _mesa_initialize_visual( visual, - (pfi->pfd.iPixelType == PFD_TYPE_RGBA) ? GL_TRUE : GL_FALSE, (pfi->pfd.dwFlags & PFD_DOUBLEBUFFER) ? GL_TRUE : GL_FALSE, (pfi->pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE, pfi->pfd.cRedBits, pfi->pfd.cGreenBits, pfi->pfd.cBlueBits, pfi->pfd.cAlphaBits, - (pfi->pfd.iPixelType == PFD_TYPE_COLORINDEX) ? pfi->pfd.cColorBits : 0, pfi->pfd.cDepthBits, pfi->pfd.cStencilBits, pfi->pfd.cAccumRedBits, diff --git a/src/gallium/state_trackers/xorg/xorg_crtc.c b/src/gallium/state_trackers/xorg/xorg_crtc.c index 221ce772af9..44f7da0f960 100644 --- a/src/gallium/state_trackers/xorg/xorg_crtc.c +++ b/src/gallium/state_trackers/xorg/xorg_crtc.c @@ -197,25 +197,26 @@ crtc_load_cursor_argb_ga3d(xf86CrtcPtr crtc, CARD32 * image) if (!crtcp->cursor_tex) { struct pipe_texture templat; - unsigned pitch; + struct winsys_handle whandle; memset(&templat, 0, sizeof(templat)); templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET; - templat.tex_usage |= PIPE_TEXTURE_USAGE_PRIMARY; + templat.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; templat.target = PIPE_TEXTURE_2D; templat.last_level = 0; templat.depth0 = 1; - templat.format = PIPE_FORMAT_A8R8G8B8_UNORM; + templat.format = PIPE_FORMAT_B8G8R8A8_UNORM; templat.width0 = 64; templat.height0 = 64; + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_KMS; + crtcp->cursor_tex = ms->screen->texture_create(ms->screen, &templat); - ms->api->local_handle_from_texture(ms->api, - ms->screen, - crtcp->cursor_tex, - &pitch, - &crtcp->cursor_handle); + ms->screen->texture_get_handle(ms->screen, crtcp->cursor_tex, &whandle); + + crtcp->cursor_handle = whandle.handle; } transfer = ms->screen->get_tex_transfer(ms->screen, crtcp->cursor_tex, diff --git a/src/gallium/state_trackers/xorg/xorg_dri2.c b/src/gallium/state_trackers/xorg/xorg_dri2.c index 5b673924350..f23e4c6cc7c 100644 --- a/src/gallium/state_trackers/xorg/xorg_dri2.c +++ b/src/gallium/state_trackers/xorg/xorg_dri2.c @@ -67,7 +67,7 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form struct exa_pixmap_priv *exa_priv; BufferPrivatePtr private = buffer->driverPrivate; PixmapPtr pPixmap; - unsigned stride, handle; + struct winsys_handle whandle; if (pDraw->type == DRAWABLE_PIXMAP) pPixmap = (PixmapPtr) pDraw; @@ -75,6 +75,7 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form pPixmap = (*pScreen->GetWindowPixmap)((WindowPtr) pDraw); exa_priv = exaGetPixmapDriverPrivate(pPixmap); + switch (buffer->attachment) { default: if (buffer->attachment != DRI2BufferFakeFrontLeft || @@ -116,19 +117,19 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form break; default: template.format = ms->ds_depth_bits_last ? - PIPE_FORMAT_X8Z24_UNORM : PIPE_FORMAT_Z24X8_UNORM; + PIPE_FORMAT_Z24X8_UNORM : PIPE_FORMAT_X8Z24_UNORM; break; } } else { template.format = ms->ds_depth_bits_last ? - PIPE_FORMAT_S8Z24_UNORM : PIPE_FORMAT_Z24S8_UNORM; + PIPE_FORMAT_Z24S8_UNORM : PIPE_FORMAT_S8Z24_UNORM; } template.width0 = pDraw->width; template.height0 = pDraw->height; template.depth0 = 1; template.last_level = 0; template.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL | - PIPE_TEXTURE_USAGE_DISPLAY_TARGET; + PIPE_TEXTURE_USAGE_SHARED; tex = ms->screen->texture_create(ms->screen, &template); pipe_texture_reference(&exa_priv->depth_stencil_tex, tex); } @@ -153,10 +154,13 @@ dri2_do_create_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, unsigned int form if (!tex) FatalError("NO TEXTURE IN DRI2\n"); - ms->api->shared_handle_from_texture(ms->api, ms->screen, tex, &stride, &handle); + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_SHARED; + + ms->screen->texture_get_handle(ms->screen, tex, &whandle); - buffer->name = handle; - buffer->pitch = stride; + buffer->name = whandle.handle; + buffer->pitch = whandle.stride; buffer->cpp = 4; buffer->driverPrivate = private; buffer->flags = 0; /* not tiled */ @@ -431,11 +435,11 @@ xorg_dri2_init(ScreenPtr pScreen) dri2info.Wait = NULL; ms->d_depth_bits_last = - ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_X8Z24_UNORM, + ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24X8_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); ms->ds_depth_bits_last = - ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_S8Z24_UNORM, + ms->screen->is_format_supported(ms->screen, PIPE_FORMAT_Z24S8_UNORM, PIPE_TEXTURE_2D, PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); diff --git a/src/gallium/state_trackers/xorg/xorg_driver.c b/src/gallium/state_trackers/xorg/xorg_driver.c index f53a879a14a..004a28f00e1 100644 --- a/src/gallium/state_trackers/xorg/xorg_driver.c +++ b/src/gallium/state_trackers/xorg/xorg_driver.c @@ -155,7 +155,7 @@ drv_get_rec(ScrnInfoPtr pScrn) if (pScrn->driverPrivate) return TRUE; - pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1); + pScrn->driverPrivate = xnfcalloc(1, sizeof(modesettingRec)); return TRUE; } @@ -183,31 +183,66 @@ drv_probe_ddc(ScrnInfoPtr pScrn, int index) static Bool drv_crtc_resize(ScrnInfoPtr pScrn, int width, int height) { + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); modesettingPtr ms = modesettingPTR(pScrn); - PixmapPtr rootPixmap; ScreenPtr pScreen = pScrn->pScreen; + int old_width, old_height; + PixmapPtr rootPixmap; + int i; if (width == pScrn->virtualX && height == pScrn->virtualY) return TRUE; + old_width = pScrn->virtualX; + old_height = pScrn->virtualY; pScrn->virtualX = width; pScrn->virtualY = height; - /* - * Remove the old framebuffer & texture. - */ - drmModeRmFB(ms->fd, ms->fb_id); - if (!ms->destroy_front_buffer(pScrn)) - FatalError("failed to destroy front buffer\n"); + /* ms->create_front_buffer will remove the old front buffer */ rootPixmap = pScreen->GetScreenPixmap(pScreen); if (!pScreen->ModifyPixmapHeader(rootPixmap, width, height, -1, -1, -1, NULL)) - return FALSE; + goto error_modify; pScrn->displayWidth = rootPixmap->devKind / (rootPixmap->drawable.bitsPerPixel / 8); - /* now create new frontbuffer */ - return ms->create_front_buffer(pScrn) && ms->bind_front_buffer(pScrn); + if (!ms->create_front_buffer(pScrn) || !ms->bind_front_buffer(pScrn)) + goto error_create; + + /* + * create && bind will turn off all crtc(s) in the kernel so we need to + * re-enable all the crtcs again. For real HW we might want to do this + * before destroying the old framebuffer. + */ + for (i = 0; i < xf86_config->num_crtc; i++) { + xf86CrtcPtr crtc = xf86_config->crtc[i]; + + if (!crtc->enabled) + continue; + + crtc->funcs->set_mode_major(crtc, &crtc->mode, crtc->rotation, crtc->x, crtc->y); + } + + return TRUE; + + /* + * This is the error recovery path. + */ +error_create: + if (!pScreen->ModifyPixmapHeader(rootPixmap, old_width, old_height, -1, -1, -1, NULL)) + FatalError("failed to resize rootPixmap error path\n"); + + pScrn->displayWidth = rootPixmap->devKind / (rootPixmap->drawable.bitsPerPixel / 8); + +error_modify: + pScrn->virtualX = old_width; + pScrn->virtualY = old_height; + + if (ms->create_front_buffer(pScrn) && ms->bind_front_buffer(pScrn)) + return FALSE; + + FatalError("failed to setup old framebuffer\n"); + return FALSE; } static const xf86CrtcConfigFuncsRec crtc_config_funcs = { @@ -333,6 +368,7 @@ drv_pre_init(ScrnInfoPtr pScrn, int flags) EntityInfoPtr pEnt; EntPtr msEnt = NULL; int max_width, max_height; + CustomizerPtr cust; if (pScrn->numEntities != 1) return FALSE; @@ -344,6 +380,9 @@ drv_pre_init(ScrnInfoPtr pScrn, int flags) return TRUE; } + cust = (CustomizerPtr) pScrn->driverPrivate; + pScrn->driverPrivate = NULL; + /* Allocate driverPrivate */ if (!drv_get_rec(pScrn)) return FALSE; @@ -351,6 +390,7 @@ drv_pre_init(ScrnInfoPtr pScrn, int flags) ms = modesettingPTR(pScrn); ms->SaveGeneration = -1; ms->pEnt = pEnt; + ms->cust = cust; pScrn->displayWidth = 640; /* default it */ @@ -423,8 +463,8 @@ drv_pre_init(ScrnInfoPtr pScrn, int flags) xf86CrtcConfigInit(pScrn, &crtc_config_funcs); xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - max_width = 8192; - max_height = 8192; + max_width = 2048; /* A very low default */ + max_height = 2048; /* see screen_init */ xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height); if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) { @@ -607,7 +647,9 @@ drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; modesettingPtr ms = modesettingPTR(pScrn); + unsigned max_width, max_height; VisualPtr visual; + CustomizerPtr cust = ms->cust; if (!drv_init_drm(pScrn)) { FatalError("Could not init DRM"); @@ -624,6 +666,26 @@ drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) return FALSE; } + /* get max width and height */ + { + drmModeResPtr res; + res = drmModeGetResources(ms->fd); + max_width = res->max_width; + max_height = res->max_height; + drmModeFreeResources(res); + } + + if (ms->screen) { + float maxf; + int max; + maxf = ms->screen->get_paramf(ms->screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); + max = (1 << (int)(maxf - 1.0f)); + max_width = max < max_width ? max : max_width; + max_height = max < max_height ? max : max_height; + } + + xf86CrtcSetSizeRange(pScrn, 1, 1, max_width, max_height); + pScrn->pScreen = pScreen; /* HW dependent - FIXME */ @@ -673,7 +735,7 @@ drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) xf86SetBlackWhitePixels(pScreen); ms->accelerate_2d = xf86ReturnOptValBool(ms->Options, OPTION_2D_ACCEL, FALSE); - ms->debug_fallback = xf86ReturnOptValBool(ms->Options, OPTION_DEBUG_FALLBACK, TRUE); + ms->debug_fallback = xf86ReturnOptValBool(ms->Options, OPTION_DEBUG_FALLBACK, ms->accelerate_2d); if (ms->screen) { ms->exa = xorg_exa_init(pScrn, ms->accelerate_2d); @@ -684,6 +746,11 @@ drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) #endif } + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "##################################\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "# Usefull debugging info follows #\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "##################################\n"); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using %s backend\n", + ms->screen ? "Gallium3D" : "libkms"); xf86DrvMsg(pScrn->scrnIndex, X_INFO, "2D Acceleration is %s\n", ms->screen && ms->accelerate_2d ? "enabled" : "disabled"); xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Fallback debugging is %s\n", @@ -694,6 +761,7 @@ drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) #else xf86DrvMsg(pScrn->scrnIndex, X_INFO, "3D Acceleration is disabled\n"); #endif + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "##################################\n"); miInitializeBackingStore(pScreen); xf86SetBackingStore(pScreen); @@ -725,8 +793,8 @@ drv_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) if (serverGeneration == 1) xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); - if (ms->winsys_screen_init) - ms->winsys_screen_init(pScrn); + if (cust && cust->winsys_screen_init) + cust->winsys_screen_init(cust, ms->fd); return drv_enter_vt(scrnIndex, 1); } @@ -759,10 +827,11 @@ drv_leave_vt(int scrnIndex, int flags) ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + CustomizerPtr cust = ms->cust; int o; - if (ms->winsys_leave_vt) - ms->winsys_leave_vt(pScrn); + if (cust && cust->winsys_leave_vt) + cust->winsys_leave_vt(cust); for (o = 0; o < config->num_crtc; o++) { xf86CrtcPtr crtc = config->crtc[o]; @@ -778,6 +847,7 @@ drv_leave_vt(int scrnIndex, int flags) } drmModeRmFB(ms->fd, ms->fb_id); + ms->fb_id = -1; drv_restore_hw_state(pScrn); @@ -796,6 +866,7 @@ drv_enter_vt(int scrnIndex, int flags) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); + CustomizerPtr cust = ms->cust; if (drmSetMaster(ms->fd)) { if (errno == EINVAL) { @@ -826,8 +897,8 @@ drv_enter_vt(int scrnIndex, int flags) if (!xf86SetDesiredModes(pScrn)) return FALSE; - if (ms->winsys_enter_vt) - ms->winsys_enter_vt(pScrn); + if (cust && cust->winsys_enter_vt) + cust->winsys_enter_vt(cust); return TRUE; } @@ -845,13 +916,14 @@ drv_close_screen(int scrnIndex, ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; modesettingPtr ms = modesettingPTR(pScrn); + CustomizerPtr cust = ms->cust; if (pScrn->vtSema) { drv_leave_vt(scrnIndex, 0); } - if (ms->winsys_screen_close) - ms->winsys_screen_close(pScrn); + if (cust && cust->winsys_screen_close) + cust->winsys_screen_close(cust); #ifdef DRI2 if (ms->screen) @@ -900,6 +972,15 @@ static Bool drv_destroy_front_buffer_ga3d(ScrnInfoPtr pScrn) { modesettingPtr ms = modesettingPTR(pScrn); + + if (!ms->root_texture) + return TRUE; + + if (ms->fb_id != -1) { + drmModeRmFB(ms->fd, ms->fb_id); + ms->fb_id = -1; + } + pipe_texture_reference(&ms->root_texture, NULL); return TRUE; } @@ -908,8 +989,9 @@ static Bool drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn) { modesettingPtr ms = modesettingPTR(pScrn); - unsigned handle, stride; struct pipe_texture *tex; + struct winsys_handle whandle; + unsigned fb_id; int ret; ms->noEvict = TRUE; @@ -920,10 +1002,10 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn) if (!tex) return FALSE; - if (!ms->api->local_handle_from_texture(ms->api, ms->screen, - tex, - &stride, - &handle)) + memset(&whandle, 0, sizeof(whandle)); + whandle.type = DRM_API_HANDLE_TYPE_KMS; + + if (!ms->screen->texture_get_handle(ms->screen, tex, &whandle)) goto err_destroy; ret = drmModeAddFB(ms->fd, @@ -931,21 +1013,25 @@ drv_create_front_buffer_ga3d(ScrnInfoPtr pScrn) pScrn->virtualY, pScrn->depth, pScrn->bitsPerPixel, - stride, - handle, - &ms->fb_id); + whandle.stride, + whandle.handle, + &fb_id); if (ret) { - debug_printf("%s: failed to create framebuffer (%i, %s)", + debug_printf("%s: failed to create framebuffer (%i, %s)\n", __func__, ret, strerror(-ret)); goto err_destroy; } + if (!drv_destroy_front_buffer_ga3d(pScrn)) + FatalError("%s: failed to take down old framebuffer\n", __func__); + pScrn->frameX0 = 0; pScrn->frameY0 = 0; drv_adjust_frame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); pipe_texture_reference(&ms->root_texture, tex); pipe_texture_reference(&tex, NULL); + ms->fb_id = fb_id; return TRUE; @@ -993,6 +1079,11 @@ drv_destroy_front_buffer_kms(ScrnInfoPtr pScrn) if (!ms->root_bo) return TRUE; + if (ms->fb_id != -1) { + drmModeRmFB(ms->fd, ms->fb_id); + ms->fb_id = -1; + } + kms_bo_unmap(ms->root_bo); kms_bo_destroy(&ms->root_bo); return TRUE; @@ -1005,6 +1096,7 @@ drv_create_front_buffer_kms(ScrnInfoPtr pScrn) unsigned handle, stride; struct kms_bo *bo; unsigned attr[8]; + unsigned fb_id; int ret; attr[0] = KMS_BO_TYPE; @@ -1035,17 +1127,21 @@ drv_create_front_buffer_kms(ScrnInfoPtr pScrn) pScrn->bitsPerPixel, stride, handle, - &ms->fb_id); + &fb_id); if (ret) { debug_printf("%s: failed to create framebuffer (%i, %s)", __func__, ret, strerror(-ret)); goto err_destroy; } + if (!drv_destroy_front_buffer_kms(pScrn)) + FatalError("%s: could not takedown old bo", __func__); + pScrn->frameX0 = 0; pScrn->frameY0 = 0; drv_adjust_frame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); ms->root_bo = bo; + ms->fb_id = fb_id; return TRUE; @@ -1113,4 +1209,14 @@ static Bool drv_init_front_buffer_functions(ScrnInfoPtr pScrn) return TRUE; } +CustomizerPtr xorg_customizer(ScrnInfoPtr pScrn) +{ + return modesettingPTR(pScrn)->cust; +} + +Bool xorg_has_gallium(ScrnInfoPtr pScrn) +{ + return modesettingPTR(pScrn)->screen != NULL; +} + /* vim: set sw=4 ts=8 sts=4: */ diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c index 665efdc0f03..a7ffe3f4992 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.c +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -118,22 +118,22 @@ exa_get_pipe_format(int depth, enum pipe_format *format, int *bbp, int *picture_ { switch (depth) { case 32: - *format = PIPE_FORMAT_A8R8G8B8_UNORM; + *format = PIPE_FORMAT_B8G8R8A8_UNORM; *picture_format = PICT_a8r8g8b8; assert(*bbp == 32); break; case 24: - *format = PIPE_FORMAT_X8R8G8B8_UNORM; + *format = PIPE_FORMAT_B8G8R8X8_UNORM; *picture_format = PICT_x8r8g8b8; assert(*bbp == 32); break; case 16: - *format = PIPE_FORMAT_R5G6B5_UNORM; + *format = PIPE_FORMAT_B5G6R5_UNORM; *picture_format = PICT_r5g6b5; assert(*bbp == 16); break; case 15: - *format = PIPE_FORMAT_A1R5G5B5_UNORM; + *format = PIPE_FORMAT_B5G5R5A1_UNORM; *picture_format = PICT_x1r5g5b5; assert(*bbp == 16); break; @@ -144,7 +144,7 @@ exa_get_pipe_format(int depth, enum pipe_format *format, int *bbp, int *picture_ break; case 4: case 1: - *format = PIPE_FORMAT_A8R8G8B8_UNORM; /* bad bad bad */ + *format = PIPE_FORMAT_B8G8R8A8_UNORM; /* bad bad bad */ break; default: assert(0); @@ -789,7 +789,7 @@ xorg_exa_set_displayed_usage(PixmapPtr pPixmap) return 0; } - priv->flags |= PIPE_TEXTURE_USAGE_PRIMARY; + priv->flags |= PIPE_TEXTURE_USAGE_SCANOUT; return 0; } @@ -805,7 +805,7 @@ xorg_exa_set_shared_usage(PixmapPtr pPixmap) return 0; } - priv->flags |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET; + priv->flags |= PIPE_TEXTURE_USAGE_SHARED; return 0; } @@ -943,7 +943,7 @@ xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_texture *tex) { struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap); - int mask = PIPE_TEXTURE_USAGE_PRIMARY | PIPE_TEXTURE_USAGE_DISPLAY_TARGET; + int mask = PIPE_TEXTURE_USAGE_SHARED | PIPE_TEXTURE_USAGE_SCANOUT; if (!priv) return FALSE; @@ -976,8 +976,8 @@ xorg_exa_create_root_texture(ScrnInfoPtr pScrn, template.depth0 = 1; template.last_level = 0; template.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET; - template.tex_usage |= PIPE_TEXTURE_USAGE_PRIMARY; - template.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET; + template.tex_usage |= PIPE_TEXTURE_USAGE_SCANOUT; + template.tex_usage |= PIPE_TEXTURE_USAGE_SHARED; return exa->scrn->texture_create(exa->scrn, &template); } diff --git a/src/gallium/state_trackers/xorg/xorg_tracker.h b/src/gallium/state_trackers/xorg/xorg_tracker.h index 58bb60a721d..2f5cc64d9c5 100644 --- a/src/gallium/state_trackers/xorg/xorg_tracker.h +++ b/src/gallium/state_trackers/xorg/xorg_tracker.h @@ -67,6 +67,14 @@ typedef struct #define XORG_NR_FENCES 3 +typedef struct _CustomizerRec +{ + Bool (*winsys_screen_init)(struct _CustomizerRec *cust, int fd); + Bool (*winsys_screen_close)(struct _CustomizerRec *cust); + Bool (*winsys_enter_vt)(struct _CustomizerRec *cust); + Bool (*winsys_leave_vt)(struct _CustomizerRec *cust); +} CustomizerRec, *CustomizerPtr; + typedef struct _modesettingRec { /* drm */ @@ -117,12 +125,7 @@ typedef struct _modesettingRec Bool accelerate_2d; Bool debug_fallback; - /* winsys hocks */ - Bool (*winsys_screen_init)(ScrnInfoPtr pScr); - Bool (*winsys_screen_close)(ScrnInfoPtr pScr); - Bool (*winsys_enter_vt)(ScrnInfoPtr pScr); - Bool (*winsys_leave_vt)(ScrnInfoPtr pScr); - void *winsys_priv; + CustomizerPtr cust; #ifdef DRM_MODE_FEATURE_DIRTYFB DamagePtr damage; @@ -131,6 +134,9 @@ typedef struct _modesettingRec #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) +CustomizerPtr xorg_customizer(ScrnInfoPtr pScrn); + +Bool xorg_has_gallium(ScrnInfoPtr pScrn); /*********************************************************************** * xorg_exa.c diff --git a/src/gallium/state_trackers/xorg/xvmc/surface.c b/src/gallium/state_trackers/xorg/xvmc/surface.c index 0e39a390c69..12d94e0c5ca 100644 --- a/src/gallium/state_trackers/xorg/xvmc/surface.c +++ b/src/gallium/state_trackers/xorg/xvmc/surface.c @@ -101,12 +101,12 @@ CreateOrResizeBackBuffer(struct pipe_video_context *vpipe, unsigned int width, u memset(&template, 0, sizeof(struct pipe_texture)); template.target = PIPE_TEXTURE_2D; /* XXX: Needs to match the drawable's format? */ - template.format = PIPE_FORMAT_X8R8G8B8_UNORM; + template.format = PIPE_FORMAT_B8G8R8X8_UNORM; template.last_level = 0; template.width0 = width; template.height0 = height; template.depth0 = 1; - template.tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET; + template.tex_usage = PIPE_TEXTURE_USAGE_SHARED; tex = vpipe->screen->texture_create(vpipe->screen, &template); if (!tex) diff --git a/src/gallium/winsys/drm/Makefile.egl b/src/gallium/winsys/drm/Makefile.egl index b1f20385502..8363de6e975 100644 --- a/src/gallium/winsys/drm/Makefile.egl +++ b/src/gallium/winsys/drm/Makefile.egl @@ -38,8 +38,7 @@ $(EGL_DISPLAY_LIBS): $(TOP)/$(LIB_DIR)/%.so: %.so define mklib-egl $(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ - $(MKLIB_OPTIONS) $(EGL_DRIVER_OBJECTS) \ - -Wl,--whole-archive $($(1)_ST) -Wl,--no-whole-archive \ + $(MKLIB_OPTIONS) $(EGL_DRIVER_OBJECTS) $($(1)_ST) \ $(EGL_DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $($(1)_LIBS) $(EGL_DRIVER_LIBS) endef diff --git a/src/gallium/winsys/drm/Makefile.template b/src/gallium/winsys/drm/Makefile.template index 960353a73d9..f4cc0def471 100644 --- a/src/gallium/winsys/drm/Makefile.template +++ b/src/gallium/winsys/drm/Makefile.template @@ -19,30 +19,12 @@ COMMON_BM_SOURCES = \ $(TOP)/src/mesa/drivers/dri/common/dri_bufmgr.c \ $(TOP)/src/mesa/drivers/dri/common/dri_drmpool.c - -ifeq ($(WINDOW_SYSTEM),dri) -WINOBJ= -WINLIB= INCLUDES = $(SHARED_INCLUDES) $(EXPAT_INCLUDES) OBJECTS = \ $(C_SOURCES:.c=.o) \ $(ASM_SOURCES:.S=.o) -else -# miniglx -WINOBJ= -WINLIB=-L$(MESA)/src/glx/mini -MINIGLX_INCLUDES = -I$(TOP)/src/glx/mini -INCLUDES = $(MINIGLX_INCLUDES) \ - $(SHARED_INCLUDES) \ - $(PCIACCESS_CFLAGS) - -OBJECTS = $(C_SOURCES:.c=.o) \ - $(MINIGLX_SOURCES:.c=.o) \ - $(ASM_SOURCES:.S=.o) -endif - ### Include directories SHARED_INCLUDES = \ @@ -74,18 +56,19 @@ SHARED_INCLUDES = \ $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ .S.o: - $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ ##### TARGETS ##### default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME) -$(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) $(WINOBJ) Makefile $(TOP)/src/mesa/drivers/dri/Makefile.template +$(LIBNAME): $(OBJECTS) $(MESA_MODULES) $(PIPE_DRIVERS) Makefile \ + $(TOP)/src/mesa/drivers/dri/Makefile.template $(MKLIB) -o $@ -noprefix -linker '$(CC)' -ldflags '$(LDFLAGS)' \ $(OBJECTS) $(PIPE_DRIVERS) \ -Wl,--start-group $(MESA_MODULES) -Wl,--end-group \ - $(WINOBJ) $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) + $(DRI_LIB_DEPS) $(DRIVER_EXTRAS) $(TOP)/$(LIB_DIR)/gallium: mkdir -p $@ diff --git a/src/gallium/winsys/drm/i965/egl/dummy.c b/src/gallium/winsys/drm/i965/egl/dummy.c index 4a1bc28b0b6..3181d0ba7e8 100644 --- a/src/gallium/winsys/drm/i965/egl/dummy.c +++ b/src/gallium/winsys/drm/i965/egl/dummy.c @@ -1 +1,3 @@ -/* mklib expects at least one object file */ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c b/src/gallium/winsys/drm/i965/gem/i965_drm_api.c index a061eef0beb..21e82303f72 100644 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_api.c +++ b/src/gallium/winsys/drm/i965/gem/i965_drm_api.c @@ -37,129 +37,6 @@ i965_libdrm_get_device_id(unsigned int *device_id) fclose(file); } -static struct i965_libdrm_buffer * -i965_libdrm_buffer_from_handle(struct i965_libdrm_winsys *idws, - const char* name, unsigned handle) -{ - struct i965_libdrm_buffer *buf = CALLOC_STRUCT(i965_libdrm_buffer); - uint32_t swizzle = 0; - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (!buf) - return NULL; - pipe_reference_init(&buf->base.reference, 1); - buf->bo = drm_intel_bo_gem_create_from_name(idws->gem, name, handle); - buf->base.size = buf->bo->size; - buf->base.sws = &idws->base; - buf->flinked = TRUE; - buf->flink = handle; - - - if (!buf->bo) - goto err; - - drm_intel_bo_get_tiling(buf->bo, &buf->tiling, &swizzle); - if (buf->tiling != 0) - buf->map_gtt = TRUE; - - return buf; - -err: - FREE(buf); - return NULL; -} - - -/* - * Exported functions - */ - - -static struct pipe_texture * -i965_libdrm_texture_from_shared_handle(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *template, - const char* name, - unsigned pitch, - unsigned handle) -{ - /* XXX: this is silly -- there should be a way to get directly from - * the "drm_api" struct to ourselves, without peering into - * unrelated code: - */ - struct i965_libdrm_winsys *idws = i965_libdrm_winsys(brw_screen(screen)->sws); - struct i965_libdrm_buffer *buffer; - - if (BRW_DUMP) - debug_printf("%s %s pitch %d handle 0x%x\n", __FUNCTION__, - name, pitch, handle); - - buffer = i965_libdrm_buffer_from_handle(idws, name, handle); - if (!buffer) - return NULL; - - return brw_texture_blanket_winsys_buffer(screen, template, pitch, - buffer->tiling, - &buffer->base); -} - - -static boolean -i965_libdrm_shared_handle_from_texture(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *pitch, - unsigned *handle) -{ - struct i965_libdrm_buffer *buf = NULL; - struct brw_winsys_buffer *buffer = NULL; - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (!brw_texture_get_winsys_buffer(texture, &buffer, pitch)) - return FALSE; - - buf = i965_libdrm_buffer(buffer); - if (!buf->flinked) { - if (drm_intel_bo_flink(buf->bo, &buf->flink)) - return FALSE; - buf->flinked = TRUE; - } - - *handle = buf->flink; - - if (BRW_DUMP) - debug_printf(" -> pitch %d handle 0x%x\n", *pitch, *handle); - - return TRUE; -} - -static boolean -i965_libdrm_local_handle_from_texture(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *pitch, - unsigned *handle) -{ - struct brw_winsys_buffer *buffer = NULL; - - if (BRW_DUMP) - debug_printf("%s\n", __FUNCTION__); - - if (!brw_texture_get_winsys_buffer(texture, &buffer, pitch)) - return FALSE; - - *handle = i965_libdrm_buffer(buffer)->bo->handle; - - if (BRW_DUMP) - debug_printf(" -> pitch %d handle 0x%x\n", *pitch, *handle); - - return TRUE; -} - static void i965_libdrm_winsys_destroy(struct brw_winsys_screen *iws) { @@ -225,9 +102,6 @@ struct drm_api i965_libdrm_api = { .name = "i965", .create_screen = i965_libdrm_create_screen, - .texture_from_shared_handle = i965_libdrm_texture_from_shared_handle, - .shared_handle_from_texture = i965_libdrm_shared_handle_from_texture, - .local_handle_from_texture = i965_libdrm_local_handle_from_texture, .destroy = destroy, }; diff --git a/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c b/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c index 07be1df87f0..33a17496b2b 100644 --- a/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c +++ b/src/gallium/winsys/drm/i965/gem/i965_drm_buffer.c @@ -1,4 +1,5 @@ +#include "state_tracker/drm_api.h" #include "i965_drm_winsys.h" #include "util/u_memory.h" #include "util/u_inlines.h" @@ -122,6 +123,78 @@ err: return PIPE_ERROR_OUT_OF_MEMORY; } +static enum pipe_error +i965_libdrm_bo_from_handle(struct brw_winsys_screen *sws, + struct winsys_handle *whandle, + unsigned *stride, + unsigned *tile, + struct brw_winsys_buffer **bo_out) +{ + struct i965_libdrm_winsys *idws = i965_libdrm_winsys(sws); + struct i965_libdrm_buffer *buf = CALLOC_STRUCT(i965_libdrm_buffer); + uint32_t swizzle = 0; + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (!buf) + return PIPE_ERROR_OUT_OF_MEMORY; + + pipe_reference_init(&buf->base.reference, 1); + buf->bo = drm_intel_bo_gem_create_from_name(idws->gem, "FROM_HANDLE", whandle->handle); + buf->base.size = buf->bo->size; + buf->base.sws = &idws->base; + buf->flinked = TRUE; + buf->flink = whandle->handle; + + + if (!buf->bo) + goto err; + + drm_intel_bo_get_tiling(buf->bo, &buf->tiling, &swizzle); + if (buf->tiling != 0) + buf->map_gtt = TRUE; + + *tile = buf->tiling; + *stride = whandle->stride; + + *bo_out = &buf->base; + return PIPE_OK; + +err: + FREE(buf); + return PIPE_ERROR_OUT_OF_MEMORY; +} + +static enum pipe_error +i965_libdrm_bo_get_handle(struct brw_winsys_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride) +{ + struct i965_libdrm_buffer *buf = i965_libdrm_buffer(buffer); + + if (BRW_DUMP) + debug_printf("%s\n", __FUNCTION__); + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + if (drm_intel_bo_flink(buf->bo, &buf->flink)) + return PIPE_ERROR_BAD_INPUT; + buf->flinked = TRUE; + } + + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } else { + assert(!"unknown usage"); + return PIPE_ERROR_BAD_INPUT; + } + + whandle->stride = stride; + return PIPE_OK; +} + static void i965_libdrm_bo_destroy(struct brw_winsys_buffer *buffer) { @@ -415,6 +488,8 @@ void i965_libdrm_winsys_init_buffer_functions(struct i965_libdrm_winsys *idws) { idws->base.bo_alloc = i965_libdrm_bo_alloc; + idws->base.bo_from_handle = i965_libdrm_bo_from_handle; + idws->base.bo_get_handle = i965_libdrm_bo_get_handle; idws->base.bo_destroy = i965_libdrm_bo_destroy; idws->base.bo_emit_reloc = i965_libdrm_bo_emit_reloc; idws->base.bo_exec = i965_libdrm_bo_exec; diff --git a/src/gallium/winsys/drm/intel/egl/dummy.c b/src/gallium/winsys/drm/intel/egl/dummy.c index 4a1bc28b0b6..3181d0ba7e8 100644 --- a/src/gallium/winsys/drm/intel/egl/dummy.c +++ b/src/gallium/winsys/drm/intel/egl/dummy.c @@ -1 +1,3 @@ -/* mklib expects at least one object file */ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_api.c b/src/gallium/winsys/drm/intel/gem/intel_drm_api.c index 377ed255131..e3b980a832b 100644 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_api.c +++ b/src/gallium/winsys/drm/intel/gem/intel_drm_api.c @@ -38,99 +38,6 @@ intel_drm_get_device_id(unsigned int *device_id) fclose(file); } -static struct intel_buffer * -intel_drm_buffer_from_handle(struct intel_drm_winsys *idws, - const char* name, unsigned handle) -{ - struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); - uint32_t tile = 0, swizzle = 0; - - if (!buf) - return NULL; - - buf->magic = 0xDEAD1337; - buf->bo = drm_intel_bo_gem_create_from_name(idws->pools.gem, name, handle); - buf->flinked = TRUE; - buf->flink = handle; - - if (!buf->bo) - goto err; - - drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle); - if (tile != INTEL_TILE_NONE) - buf->map_gtt = TRUE; - - return (struct intel_buffer *)buf; - -err: - FREE(buf); - return NULL; -} - - -/* - * Exported functions - */ - - -static struct pipe_texture * -intel_drm_texture_from_shared_handle(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *templ, - const char* name, - unsigned pitch, - unsigned handle) -{ - struct intel_drm_winsys *idws = intel_drm_winsys(i915_screen(screen)->iws); - struct intel_buffer *buffer; - - buffer = intel_drm_buffer_from_handle(idws, name, handle); - if (!buffer) - return NULL; - - return i915_texture_blanket_intel(screen, templ, pitch, buffer); -} - -static boolean -intel_drm_shared_handle_from_texture(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *pitch, - unsigned *handle) -{ - struct intel_drm_buffer *buf = NULL; - struct intel_buffer *buffer = NULL; - if (!i915_get_texture_buffer_intel(texture, &buffer, pitch)) - return FALSE; - - buf = intel_drm_buffer(buffer); - if (!buf->flinked) { - if (drm_intel_bo_flink(buf->bo, &buf->flink)) - return FALSE; - buf->flinked = TRUE; - } - - *handle = buf->flink; - - return TRUE; -} - -static boolean -intel_drm_local_handle_from_texture(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *pitch, - unsigned *handle) -{ - struct intel_buffer *buffer = NULL; - if (!i915_get_texture_buffer_intel(texture, &buffer, pitch)) - return FALSE; - - *handle = intel_drm_buffer(buffer)->bo->handle; - - return TRUE; -} - static void intel_drm_winsys_destroy(struct intel_winsys *iws) { @@ -192,9 +99,6 @@ struct drm_api intel_drm_api = .name = "i915", .driver_name = "i915", .create_screen = intel_drm_create_screen, - .texture_from_shared_handle = intel_drm_texture_from_shared_handle, - .shared_handle_from_texture = intel_drm_shared_handle_from_texture, - .local_handle_from_texture = intel_drm_local_handle_from_texture, .destroy = destroy, }; diff --git a/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c b/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c index ac4dd6e00e9..cb4f92a3b17 100644 --- a/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c +++ b/src/gallium/winsys/drm/intel/gem/intel_drm_buffer.c @@ -1,4 +1,5 @@ +#include "state_tracker/drm_api.h" #include "intel_drm_winsys.h" #include "util/u_memory.h" @@ -52,6 +53,66 @@ err: return NULL; } +static struct intel_buffer * +intel_drm_buffer_from_handle(struct intel_winsys *iws, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct intel_drm_winsys *idws = intel_drm_winsys(iws); + struct intel_drm_buffer *buf = CALLOC_STRUCT(intel_drm_buffer); + uint32_t tile = 0, swizzle = 0; + + if (!buf) + return NULL; + + buf->magic = 0xDEAD1337; + buf->bo = drm_intel_bo_gem_create_from_name(idws->pools.gem, "gallium3d_from_handle", whandle->handle); + buf->flinked = TRUE; + buf->flink = whandle->handle; + + if (!buf->bo) + goto err; + + drm_intel_bo_get_tiling(buf->bo, &tile, &swizzle); + if (tile != INTEL_TILE_NONE) + buf->map_gtt = TRUE; + + *stride = whandle->stride; + + return (struct intel_buffer *)buf; + +err: + FREE(buf); + return NULL; +} + +static boolean +intel_drm_buffer_get_handle(struct intel_winsys *iws, + struct intel_buffer *buffer, + struct winsys_handle *whandle, + unsigned stride) +{ + struct intel_drm_buffer *buf = intel_drm_buffer(buffer); + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!buf->flinked) { + if (drm_intel_bo_flink(buf->bo, &buf->flink)) + return FALSE; + buf->flinked = TRUE; + } + + whandle->handle = buf->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = buf->bo->handle; + } else { + assert(!"unknown usage"); + return FALSE; + } + + whandle->stride = stride; + return TRUE; +} + static int intel_drm_buffer_set_fence_reg(struct intel_winsys *iws, struct intel_buffer *buffer, @@ -146,6 +207,8 @@ void intel_drm_winsys_init_buffer_functions(struct intel_drm_winsys *idws) { idws->base.buffer_create = intel_drm_buffer_create; + idws->base.buffer_from_handle = intel_drm_buffer_from_handle; + idws->base.buffer_get_handle = intel_drm_buffer_get_handle; idws->base.buffer_set_fence_reg = intel_drm_buffer_set_fence_reg; idws->base.buffer_map = intel_drm_buffer_map; idws->base.buffer_unmap = intel_drm_buffer_unmap; diff --git a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c index c814d986b1d..21517b4bb54 100644 --- a/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c +++ b/src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c @@ -21,9 +21,10 @@ dri_surface_from_handle(struct drm_api *api, struct pipe_screen *pscreen, struct pipe_surface *ps = NULL; struct pipe_texture *pt = NULL; struct pipe_texture tmpl; + struct winsys_handle whandle; memset(&tmpl, 0, sizeof(tmpl)); - tmpl.tex_usage = PIPE_TEXTURE_USAGE_PRIMARY; + tmpl.tex_usage = PIPE_TEXTURE_USAGE_SCANOUT; tmpl.target = PIPE_TEXTURE_2D; tmpl.last_level = 0; tmpl.depth0 = 1; @@ -31,8 +32,11 @@ dri_surface_from_handle(struct drm_api *api, struct pipe_screen *pscreen, tmpl.width0 = width; tmpl.height0 = height; - pt = api->texture_from_shared_handle(api, pscreen, &tmpl, - "front buffer", pitch, handle); + memset(&whandle, 0, sizeof(whandle)); + whandle.stride = pitch; + whandle.handle = handle; + + pt = pscreen->texture_from_handle(pscreen, &tmpl, &whandle); if (!pt) return NULL; @@ -119,9 +123,9 @@ nouveau_drm_create_screen(struct drm_api *api, int fd, enum pipe_format format; if (nvdri->bpp == 16) - format = PIPE_FORMAT_R5G6B5_UNORM; + format = PIPE_FORMAT_B5G6R5_UNORM; else - format = PIPE_FORMAT_A8R8G8B8_UNORM; + format = PIPE_FORMAT_B8G8R8A8_UNORM; nvws->front = dri_surface_from_handle(api, nvws->pscreen, nvdri->front_offset, @@ -142,74 +146,10 @@ nouveau_drm_create_screen(struct drm_api *api, int fd, return nvws->pscreen; } -static struct pipe_texture * -nouveau_drm_pt_from_name(struct drm_api *api, struct pipe_screen *pscreen, - struct pipe_texture *templ, const char *name, - unsigned stride, unsigned handle) -{ - struct nouveau_device *dev = nouveau_screen(pscreen)->device; - struct pipe_texture *pt; - struct pipe_buffer *pb; - int ret; - - pb = CALLOC(1, sizeof(struct pipe_buffer) + sizeof(struct nouveau_bo*)); - if (!pb) - return NULL; - - ret = nouveau_bo_handle_ref(dev, handle, (struct nouveau_bo**)(pb+1)); - if (ret) { - debug_printf("%s: ref name 0x%08x failed with %d\n", - __func__, handle, ret); - FREE(pb); - return NULL; - } - - pipe_reference_init(&pb->reference, 1); - pb->screen = pscreen; - pb->alignment = 0; - pb->usage = PIPE_BUFFER_USAGE_GPU_READ_WRITE | - PIPE_BUFFER_USAGE_CPU_READ_WRITE; - pb->size = nouveau_bo(pb)->size; - pt = pscreen->texture_blanket(pscreen, templ, &stride, pb); - pipe_buffer_reference(&pb, NULL); - return pt; -} - -static boolean -nouveau_drm_name_from_pt(struct drm_api *api, struct pipe_screen *pscreen, - struct pipe_texture *pt, unsigned *stride, - unsigned *handle) -{ - struct nouveau_miptree *mt = nouveau_miptree(pt); - - if (!mt || !mt->bo) - return false; - - return nouveau_bo_handle_get(mt->bo, handle) == 0; -} - -static boolean -nouveau_drm_handle_from_pt(struct drm_api *api, struct pipe_screen *pscreen, - struct pipe_texture *pt, unsigned *stride, - unsigned *handle) -{ - struct nouveau_miptree *mt = nouveau_miptree(pt); - - if (!mt || !mt->bo) - return false; - - *handle = mt->bo->handle; - *stride = util_format_get_stride(mt->base.format, mt->base.width0); - return true; -} - struct drm_api drm_api_hooks = { .name = "nouveau", .driver_name = "nouveau", .create_screen = nouveau_drm_create_screen, - .texture_from_shared_handle = nouveau_drm_pt_from_name, - .shared_handle_from_texture = nouveau_drm_name_from_pt, - .local_handle_from_texture = nouveau_drm_handle_from_pt, }; struct drm_api * diff --git a/src/gallium/winsys/drm/nouveau/egl/dummy.c b/src/gallium/winsys/drm/nouveau/egl/dummy.c index 4a1bc28b0b6..3181d0ba7e8 100644 --- a/src/gallium/winsys/drm/nouveau/egl/dummy.c +++ b/src/gallium/winsys/drm/nouveau/egl/dummy.c @@ -1 +1,3 @@ -/* mklib expects at least one object file */ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/radeon/core/radeon_buffer.c b/src/gallium/winsys/drm/radeon/core/radeon_buffer.c index 5cbf0dd2c54..daa032af6f2 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_buffer.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_buffer.c @@ -31,11 +31,13 @@ */ #include "radeon_buffer.h" +#include "radeon_drm.h" -#include "radeon_bo_gem.h" -#include "r300_context.h" #include "util/u_format.h" #include "util/u_math.h" +#include "util/u_memory.h" + +#include "radeon_bo_gem.h" #include <X11/Xutil.h> struct radeon_vl_context @@ -262,6 +264,75 @@ static int radeon_fence_finish(struct pipe_winsys *ws, return 0; } +/* Create a buffer from a handle. */ +static struct pipe_buffer* radeon_buffer_from_handle(struct radeon_winsys *radeon_ws, + struct pipe_screen *screen, + struct winsys_handle *whandle, + unsigned *stride) +{ + struct radeon_bo_manager* bom = radeon_ws->priv->bom; + struct radeon_pipe_buffer* radeon_buffer; + struct radeon_bo* bo = NULL; + + bo = radeon_bo_open(bom, whandle->handle, 0, 0, 0, 0); + if (bo == NULL) { + return NULL; + } + + radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer); + if (radeon_buffer == NULL) { + radeon_bo_unref(bo); + return NULL; + } + + pipe_reference_init(&radeon_buffer->base.reference, 1); + radeon_buffer->base.screen = screen; + radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL; + radeon_buffer->bo = bo; + + *stride = whandle->stride; + + return &radeon_buffer->base; +} + +static boolean radeon_buffer_get_handle(struct radeon_winsys *radeon_ws, + struct pipe_buffer *buffer, + unsigned stride, + struct winsys_handle *whandle) +{ + int retval, fd; + struct drm_gem_flink flink; + struct radeon_pipe_buffer* radeon_buffer; + + radeon_buffer = (struct radeon_pipe_buffer*)buffer; + + + if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { + if (!radeon_buffer->flinked) { + fd = radeon_ws->priv->fd; + + flink.handle = radeon_buffer->bo->handle; + + retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); + if (retval) { + debug_printf("radeon: DRM_IOCTL_GEM_FLINK failed, error %d\n", + retval); + return FALSE; + } + + radeon_buffer->flink = flink.name; + radeon_buffer->flinked = TRUE; + } + + whandle->handle = radeon_buffer->flink; + } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) { + whandle->handle = ((struct radeon_pipe_buffer*)buffer)->bo->handle; + } + whandle->stride = stride; + + return TRUE; +} + struct radeon_winsys* radeon_pipe_winsys(int fd) { struct radeon_winsys* radeon_ws; @@ -296,6 +367,8 @@ struct radeon_winsys* radeon_pipe_winsys(int fd) radeon_ws->base.get_name = radeon_get_name; radeon_ws->buffer_set_tiling = radeon_buffer_set_tiling; + radeon_ws->buffer_from_handle = radeon_buffer_from_handle; + radeon_ws->buffer_get_handle = radeon_buffer_get_handle; return radeon_ws; } diff --git a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h index f1c8fc2a3b1..f776e2d9008 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_buffer.h +++ b/src/gallium/winsys/drm/radeon/core/radeon_buffer.h @@ -30,21 +30,11 @@ #ifndef RADEON_BUFFER_H #define RADEON_BUFFER_H -#include <stdio.h> - -#include "util/u_simple_screen.h" -#include "pipe/p_defines.h" -#include "util/u_inlines.h" - #include "pipebuffer/pb_buffer.h" -#include "util/u_memory.h" - #include "radeon_bo.h" #include "radeon_cs.h" -#include "radeon_drm.h" - #include "radeon_winsys.h" struct radeon_pipe_buffer { diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm.c b/src/gallium/winsys/drm/radeon/core/radeon_drm.c index 0c0e118ba3a..97edb6a47e3 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm.c @@ -30,6 +30,16 @@ */ #include "radeon_drm.h" +#include "radeon_r300.h" +#include "radeon_buffer.h" + +#include "r300_winsys.h" +#include "trace/tr_drm.h" + +#include "util/u_memory.h" + +#include "xf86drm.h" +#include <sys/ioctl.h> /* Helper function to do the ioctls needed for setup and init. */ static void do_ioctls(int fd, struct radeon_winsys* winsys) @@ -138,124 +148,6 @@ struct pipe_screen* radeon_create_screen(struct drm_api* api, } } - -boolean radeon_buffer_from_texture(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_texture* texture, - struct pipe_buffer** buffer, - unsigned* stride) -{ - /* XXX fix this */ - return r300_get_texture_buffer(screen, texture, buffer, stride); -} - -/* Create a buffer from a handle. */ -/* XXX what's up with name? */ -struct pipe_buffer* radeon_buffer_from_handle(struct drm_api* api, - struct pipe_screen* screen, - const char* name, - unsigned handle) -{ - struct radeon_bo_manager* bom = - ((struct radeon_winsys*)screen->winsys)->priv->bom; - struct radeon_pipe_buffer* radeon_buffer; - struct radeon_bo* bo = NULL; - - bo = radeon_bo_open(bom, handle, 0, 0, 0, 0); - if (bo == NULL) { - return NULL; - } - - radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer); - if (radeon_buffer == NULL) { - radeon_bo_unref(bo); - return NULL; - } - - pipe_reference_init(&radeon_buffer->base.reference, 1); - radeon_buffer->base.screen = screen; - radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL; - radeon_buffer->bo = bo; - return &radeon_buffer->base; -} - -static struct pipe_texture* -radeon_texture_from_shared_handle(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *templ, - const char *name, - unsigned stride, - unsigned handle) -{ - struct pipe_buffer *buffer; - struct pipe_texture *blanket; - - buffer = radeon_buffer_from_handle(api, screen, name, handle); - if (!buffer) { - return NULL; - } - - blanket = screen->texture_blanket(screen, templ, &stride, buffer); - - pipe_buffer_reference(&buffer, NULL); - - return blanket; -} - -static boolean radeon_shared_handle_from_texture(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *stride, - unsigned *handle) -{ - int retval, fd; - struct drm_gem_flink flink; - struct radeon_pipe_buffer* radeon_buffer; - struct pipe_buffer *buffer = NULL; - - if (!radeon_buffer_from_texture(api, screen, texture, &buffer, stride)) { - return FALSE; - } - - radeon_buffer = (struct radeon_pipe_buffer*)buffer; - if (!radeon_buffer->flinked) { - fd = ((struct radeon_winsys*)screen->winsys)->priv->fd; - - flink.handle = radeon_buffer->bo->handle; - - retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); - if (retval) { - debug_printf("radeon: DRM_IOCTL_GEM_FLINK failed, error %d\n", - retval); - return FALSE; - } - - radeon_buffer->flink = flink.name; - radeon_buffer->flinked = TRUE; - } - - *handle = radeon_buffer->flink; - return TRUE; -} - -static boolean radeon_local_handle_from_texture(struct drm_api *api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *stride, - unsigned *handle) -{ - struct pipe_buffer *buffer = NULL; - if (!radeon_buffer_from_texture(api, screen, texture, &buffer, stride)) { - return FALSE; - } - - *handle = ((struct radeon_pipe_buffer*)buffer)->bo->handle; - - pipe_buffer_reference(&buffer, NULL); - - return TRUE; -} - static void radeon_drm_api_destroy(struct drm_api *api) { return; @@ -265,9 +157,6 @@ struct drm_api drm_api_hooks = { .name = "radeon", .driver_name = "radeon", .create_screen = radeon_create_screen, - .texture_from_shared_handle = radeon_texture_from_shared_handle, - .shared_handle_from_texture = radeon_shared_handle_from_texture, - .local_handle_from_texture = radeon_local_handle_from_texture, .destroy = radeon_drm_api_destroy, }; diff --git a/src/gallium/winsys/drm/radeon/core/radeon_drm.h b/src/gallium/winsys/drm/radeon/core/radeon_drm.h index 8d74cbafc2f..78451b6f011 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_drm.h +++ b/src/gallium/winsys/drm/radeon/core/radeon_drm.h @@ -30,50 +30,13 @@ #ifndef RADEON_DRM_H #define RADEON_DRM_H -#include <sys/ioctl.h> - -#include "xf86drm.h" - -#include "pipe/p_screen.h" - -#include "trace/tr_drm.h" -#include "util/u_debug.h" -#include "util/u_memory.h" - #include "state_tracker/drm_api.h" -#include "radeon_buffer.h" -#include "radeon_r300.h" - -/* XXX */ -#include "r300_screen.h" struct pipe_screen* radeon_create_screen(struct drm_api* api, int drmFB, struct drm_create_screen_arg *arg); - -boolean radeon_buffer_from_texture(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_texture* texture, - struct pipe_buffer** buffer, - unsigned* stride); - -struct pipe_buffer* radeon_buffer_from_handle(struct drm_api* api, - struct pipe_screen* screen, - const char* name, - unsigned handle); - -boolean radeon_handle_from_buffer(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_buffer* buffer, - unsigned* handle); - -boolean radeon_global_handle_from_buffer(struct drm_api* api, - struct pipe_screen* screen, - struct pipe_buffer* buffer, - unsigned* handle); - void radeon_destroy_drm_api(struct drm_api* api); /* Guess at whether this chipset should use r300g. diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.c b/src/gallium/winsys/drm/radeon/core/radeon_r300.c index d759beaba13..122bd213543 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.c +++ b/src/gallium/winsys/drm/radeon/core/radeon_r300.c @@ -21,6 +21,9 @@ * USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "radeon_r300.h" +#include "radeon_buffer.h" + +#include "radeon_cs_gem.h" static void radeon_set_flush_cb(struct radeon_winsys *winsys, void (*flush_cb)(void *), diff --git a/src/gallium/winsys/drm/radeon/core/radeon_r300.h b/src/gallium/winsys/drm/radeon/core/radeon_r300.h index cfbdb302661..e655dc32c85 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_r300.h +++ b/src/gallium/winsys/drm/radeon/core/radeon_r300.h @@ -23,16 +23,7 @@ #ifndef RADEON_R300_H #define RADEON_R300_H -/* XXX WTF is this! I shouldn't have to include those first three! FUCK! */ -#include <stdint.h> -#include <stdlib.h> -#include "drm.h" -#include "radeon_drm.h" -#include "radeon_cs_gem.h" - -#include "r300_winsys.h" - -#include "radeon_buffer.h" +#include "radeon_winsys.h" void radeon_setup_winsys(int fd, struct radeon_winsys* winsys); diff --git a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h index 4901080ca7b..37eeb459791 100644 --- a/src/gallium/winsys/drm/radeon/core/radeon_winsys.h +++ b/src/gallium/winsys/drm/radeon/core/radeon_winsys.h @@ -56,6 +56,18 @@ struct radeon_winsys { /* VRAM size. */ uint32_t vram_size; + /* Create a buffer from a winsys handle. */ + struct pipe_buffer *(*buffer_from_handle)(struct radeon_winsys *winsys, + struct pipe_screen *screen, + struct winsys_handle *whandle, + unsigned *stride); + + /* Get the handle from a buffer. */ + boolean (*buffer_get_handle)(struct radeon_winsys *winsys, + struct pipe_buffer *buffer, + unsigned stride, + struct winsys_handle *whandle); + /* Add a pipe_buffer to the list of buffer objects to validate. */ boolean (*add_buffer)(struct radeon_winsys* winsys, struct pipe_buffer* pbuffer, diff --git a/src/gallium/winsys/drm/radeon/dri/Makefile b/src/gallium/winsys/drm/radeon/dri/Makefile index eaa34180321..d75f7dd6da7 100644 --- a/src/gallium/winsys/drm/radeon/dri/Makefile +++ b/src/gallium/winsys/drm/radeon/dri/Makefile @@ -4,8 +4,6 @@ include $(TOP)/configs/current LIBNAME = radeong_dri.so -MINIGLX_SOURCES = - PIPE_DRIVERS = \ $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \ $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \ diff --git a/src/gallium/winsys/drm/radeon/egl/dummy.c b/src/gallium/winsys/drm/radeon/egl/dummy.c index 4a1bc28b0b6..3181d0ba7e8 100644 --- a/src/gallium/winsys/drm/radeon/egl/dummy.c +++ b/src/gallium/winsys/drm/radeon/egl/dummy.c @@ -1 +1,3 @@ -/* mklib expects at least one object file */ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/swrast/egl/dummy.c b/src/gallium/winsys/drm/swrast/egl/dummy.c index 4a1bc28b0b6..3181d0ba7e8 100644 --- a/src/gallium/winsys/drm/swrast/egl/dummy.c +++ b/src/gallium/winsys/drm/swrast/egl/dummy.c @@ -1 +1,3 @@ -/* mklib expects at least one object file */ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c b/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c index 1dcbc419dbb..657544dcb21 100644 --- a/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c +++ b/src/gallium/winsys/drm/vmware/core/vmw_screen_dri.c @@ -44,12 +44,22 @@ #include <stdio.h> +static struct svga_winsys_surface * +vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format); +static boolean +vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle); + static struct dri1_api dri1_api_hooks; static struct dri1_api_version ddx_required = { 0, 1, 0 }; static struct dri1_api_version ddx_compat = { 0, 0, 0 }; static struct dri1_api_version dri_required = { 4, 0, 0 }; static struct dri1_api_version dri_compat = { 4, 0, 0 }; -static struct dri1_api_version drm_required = { 0, 1, 0 }; +static struct dri1_api_version drm_required = { 1, 0, 0 }; static struct dri1_api_version drm_compat = { 1, 0, 0 }; static struct dri1_api_version drm_scanout = { 0, 9, 0 }; @@ -129,7 +139,12 @@ vmw_drm_create_screen(struct drm_api *drm_api, &drm_compat, "use old scanout field (not a error)")) use_old_scanout_flag = TRUE; dri1->api = &dri1_api_hooks; +#if 0 break; +#else + assert(!"No dri 1 support for now\n"); + return NULL; +#endif default: return NULL; } @@ -139,6 +154,10 @@ vmw_drm_create_screen(struct drm_api *drm_api, if (!vws) goto out_no_vws; + /* XXX do this properly */ + vws->base.surface_from_handle = vmw_drm_surface_from_handle; + vws->base.surface_get_handle = vmw_drm_surface_get_handle; + screen = svga_screen_create( &vws->base ); if (!screen) goto out_no_screen; @@ -200,6 +219,7 @@ vmw_dri1_present_locked(struct pipe_context *locked_pipe, const struct drm_clip_rect *bbox, struct pipe_fence_handle **p_fence) { +#if 0 struct svga_winsys_surface *srf = svga_screen_texture_get_winsys_surface(surf->texture); struct vmw_svga_winsys_surface *vsrf = vmw_svga_winsys_surface(srf); @@ -246,21 +266,19 @@ vmw_dri1_present_locked(struct pipe_context *locked_pipe, *p_fence = (visible) ? vmw_pipe_fence(fence_seq) : NULL; vmw_svga_winsys_surface_reference(&vsrf, NULL); +#else + assert(!"No dri 1 support for now\n"); +#endif } -static struct pipe_texture * -vmw_drm_texture_from_handle(struct drm_api *drm_api, - struct pipe_screen *screen, - struct pipe_texture *templat, - const char *name, - unsigned stride, - unsigned handle) +static struct svga_winsys_surface * +vmw_drm_surface_from_handle(struct svga_winsys_screen *sws, + struct winsys_handle *whandle, + SVGA3dSurfaceFormat *format) { struct vmw_svga_winsys_surface *vsrf; struct svga_winsys_surface *ssrf; - struct vmw_winsys_screen *vws = - vmw_winsys_screen(svga_winsys_screen(screen)); - struct pipe_texture *tex; + struct vmw_winsys_screen *vws = vmw_winsys_screen(sws); union drm_vmw_surface_reference_arg arg; struct drm_vmw_surface_arg *req = &arg.req; struct drm_vmw_surface_create_req *rep = &arg.rep; @@ -273,7 +291,7 @@ vmw_drm_texture_from_handle(struct drm_api *drm_api, */ memset(&arg, 0, sizeof(arg)); - req->sid = handle; + req->sid = whandle->handle; ret = drmCommandWriteRead(vws->ioctl.drm_fd, DRM_VMW_REF_SURFACE, &arg, sizeof(arg)); @@ -281,14 +299,14 @@ vmw_drm_texture_from_handle(struct drm_api *drm_api, if (ret) { fprintf(stderr, "Failed referencing shared surface. SID %d.\n" "Error %d (%s).\n", - handle, ret, strerror(-ret)); + whandle->handle, ret, strerror(-ret)); return NULL; } if (rep->mip_levels[0] != 1) { fprintf(stderr, "Incorrect number of mipmap levels on shared surface." " SID %d, levels %d\n", - handle, rep->mip_levels[0]); + whandle->handle, rep->mip_levels[0]); goto out_mip; } @@ -296,7 +314,7 @@ vmw_drm_texture_from_handle(struct drm_api *drm_api, if (rep->mip_levels[i] != 0) { fprintf(stderr, "Incorrect number of faces levels on shared surface." " SID %d, face %d present.\n", - handle, i); + whandle->handle, i); goto out_mip; } } @@ -308,38 +326,32 @@ vmw_drm_texture_from_handle(struct drm_api *drm_api, pipe_reference_init(&vsrf->refcnt, 1); p_atomic_set(&vsrf->validated, 0); vsrf->screen = vws; - vsrf->sid = handle; + vsrf->sid = whandle->handle; ssrf = svga_winsys_surface(vsrf); - tex = svga_screen_texture_wrap_surface(screen, templat, rep->format, ssrf); - if (!tex) - vmw_svga_winsys_surface_reference(&vsrf, NULL); + *format = rep->format; + + return ssrf; - return tex; - out_mip: - vmw_ioctl_surface_destroy(vws, handle); +out_mip: + vmw_ioctl_surface_destroy(vws, whandle->handle); return NULL; } static boolean -vmw_drm_handle_from_texture(struct drm_api *drm_api, - struct pipe_screen *screen, - struct pipe_texture *texture, - unsigned *stride, - unsigned *handle) +vmw_drm_surface_get_handle(struct svga_winsys_screen *sws, + struct svga_winsys_surface *surface, + unsigned stride, + struct winsys_handle *whandle) { - struct svga_winsys_surface *surface = - svga_screen_texture_get_winsys_surface(texture); struct vmw_svga_winsys_surface *vsrf; if (!surface) return FALSE; vsrf = vmw_svga_winsys_surface(surface); - *handle = vsrf->sid; - *stride = util_format_get_nblocksx(texture->format, texture->width0) * - util_format_get_blocksize(texture->format); + whandle->handle = vsrf->sid; + whandle->stride = stride; - vmw_svga_winsys_surface_reference(&vsrf, NULL); return TRUE; } @@ -353,9 +365,6 @@ static struct drm_api vmw_drm_api_hooks = { .name = "vmwgfx", .driver_name = "vmwgfx", .create_screen = vmw_drm_create_screen, - .texture_from_shared_handle = vmw_drm_texture_from_handle, - .shared_handle_from_texture = vmw_drm_handle_from_texture, - .local_handle_from_texture = vmw_drm_handle_from_texture, }; struct drm_api* drm_api_create() diff --git a/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h b/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h index 1457966db81..47914bdb711 100644 --- a/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h +++ b/src/gallium/winsys/drm/vmware/core/vmwgfx_drm.h @@ -260,15 +260,23 @@ union drm_vmw_surface_reference_arg { * to the nearest kernel tick. * @fence_rep: User-space address of a struct drm_vmw_fence_rep cast to an * uint64_t. + * @version: Allows expanding the execbuf ioctl parameters without breaking + * backwards compatibility, since user-space will always tell the kernel + * which version it uses. + * @flags: Execbuf flags. None currently. * * Argument to the DRM_VMW_EXECBUF Ioctl. */ +#define DRM_VMW_EXECBUF_VERSION 0 + struct drm_vmw_execbuf_arg { uint64_t commands; uint32_t command_size; uint32_t throttle_us; uint64_t fence_rep; + uint32_t version; + uint32_t flags; }; /** diff --git a/src/gallium/winsys/drm/vmware/egl/dummy.c b/src/gallium/winsys/drm/vmware/egl/dummy.c index 4a1bc28b0b6..3181d0ba7e8 100644 --- a/src/gallium/winsys/drm/vmware/egl/dummy.c +++ b/src/gallium/winsys/drm/vmware/egl/dummy.c @@ -1 +1,3 @@ -/* mklib expects at least one object file */ +/* A poor man's --whole-archive for EGL drivers */ +void *_eglMain(void *); +void *_eglWholeArchive = (void *) _eglMain; diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h b/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h index 3efe851a4be..ba754b51e47 100644 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h +++ b/src/gallium/winsys/drm/vmware/xorg/vmw_driver.h @@ -40,8 +40,11 @@ struct vmw_dma_buffer; -struct vmw_driver +struct vmw_customizer { + CustomizerRec base; + ScrnInfoPtr pScrn; + int fd; void *cursor_priv; @@ -50,11 +53,10 @@ struct vmw_driver void *video_priv; }; -static INLINE struct vmw_driver * -vmw_driver(ScrnInfoPtr pScrn) +static INLINE struct vmw_customizer * +vmw_customizer(CustomizerPtr cust) { - modesettingPtr ms = modesettingPTR(pScrn); - return ms ? (struct vmw_driver *)ms->winsys_priv : NULL; + return cust ? (struct vmw_customizer *) cust : NULL; } @@ -62,40 +64,40 @@ vmw_driver(ScrnInfoPtr pScrn) * vmw_video.c */ -Bool vmw_video_init(ScrnInfoPtr pScrn, struct vmw_driver *vmw); +Bool vmw_video_init(struct vmw_customizer *vmw); -Bool vmw_video_close(ScrnInfoPtr pScrn, struct vmw_driver *vmw); +Bool vmw_video_close(struct vmw_customizer *vmw); -void vmw_video_stop_all(ScrnInfoPtr pScrn, struct vmw_driver *vmw); +void vmw_video_stop_all(struct vmw_customizer *vmw); /*********************************************************************** * vmw_ioctl.c */ -int vmw_ioctl_cursor_bypass(struct vmw_driver *vmw, int xhot, int yhot); +int vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot); -struct vmw_dma_buffer * vmw_ioctl_buffer_create(struct vmw_driver *vmw, +struct vmw_dma_buffer * vmw_ioctl_buffer_create(struct vmw_customizer *vmw, uint32_t size, unsigned *handle); -void * vmw_ioctl_buffer_map(struct vmw_driver *vmw, +void * vmw_ioctl_buffer_map(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf); -void vmw_ioctl_buffer_unmap(struct vmw_driver *vmw, +void vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf); -void vmw_ioctl_buffer_destroy(struct vmw_driver *vmw, +void vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf); -int vmw_ioctl_supports_streams(struct vmw_driver *vmw); +int vmw_ioctl_supports_streams(struct vmw_customizer *vmw); -int vmw_ioctl_num_streams(struct vmw_driver *vmw, +int vmw_ioctl_num_streams(struct vmw_customizer *vmw, uint32_t *ntot, uint32_t *nfree); -int vmw_ioctl_unref_stream(struct vmw_driver *vmw, uint32_t stream_id); +int vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id); -int vmw_ioctl_claim_stream(struct vmw_driver *vmw, uint32_t *out); +int vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out); #endif diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c b/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c index ab2b5fadc49..521578ab35d 100644 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c +++ b/src/gallium/winsys/drm/vmware/xorg/vmw_ioctl.c @@ -57,7 +57,7 @@ struct vmw_dma_buffer }; static int -vmw_ioctl_get_param(struct vmw_driver *vmw, uint32_t param, uint64_t *out) +vmw_ioctl_get_param(struct vmw_customizer *vmw, uint32_t param, uint64_t *out) { struct drm_vmw_getparam_arg gp_arg; int ret; @@ -75,7 +75,7 @@ vmw_ioctl_get_param(struct vmw_driver *vmw, uint32_t param, uint64_t *out) } int -vmw_ioctl_supports_streams(struct vmw_driver *vmw) +vmw_ioctl_supports_streams(struct vmw_customizer *vmw) { uint64_t value; int ret; @@ -88,7 +88,7 @@ vmw_ioctl_supports_streams(struct vmw_driver *vmw) } int -vmw_ioctl_num_streams(struct vmw_driver *vmw, +vmw_ioctl_num_streams(struct vmw_customizer *vmw, uint32_t *ntot, uint32_t *nfree) { uint64_t v1, v2; @@ -109,7 +109,7 @@ vmw_ioctl_num_streams(struct vmw_driver *vmw, } int -vmw_ioctl_claim_stream(struct vmw_driver *vmw, uint32_t *out) +vmw_ioctl_claim_stream(struct vmw_customizer *vmw, uint32_t *out) { struct drm_vmw_stream_arg s_arg; int ret; @@ -125,7 +125,7 @@ vmw_ioctl_claim_stream(struct vmw_driver *vmw, uint32_t *out) } int -vmw_ioctl_unref_stream(struct vmw_driver *vmw, uint32_t stream_id) +vmw_ioctl_unref_stream(struct vmw_customizer *vmw, uint32_t stream_id) { struct drm_vmw_stream_arg s_arg; int ret; @@ -140,7 +140,7 @@ vmw_ioctl_unref_stream(struct vmw_driver *vmw, uint32_t stream_id) } int -vmw_ioctl_cursor_bypass(struct vmw_driver *vmw, int xhot, int yhot) +vmw_ioctl_cursor_bypass(struct vmw_customizer *vmw, int xhot, int yhot) { struct drm_vmw_cursor_bypass_arg arg; int ret; @@ -157,7 +157,7 @@ vmw_ioctl_cursor_bypass(struct vmw_driver *vmw, int xhot, int yhot) } struct vmw_dma_buffer * -vmw_ioctl_buffer_create(struct vmw_driver *vmw, uint32_t size, unsigned *handle) +vmw_ioctl_buffer_create(struct vmw_customizer *vmw, uint32_t size, unsigned *handle) { struct vmw_dma_buffer *buf; union drm_vmw_alloc_dmabuf_arg arg; @@ -198,7 +198,7 @@ err: } void -vmw_ioctl_buffer_destroy(struct vmw_driver *vmw, struct vmw_dma_buffer *buf) +vmw_ioctl_buffer_destroy(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) { struct drm_vmw_unref_dmabuf_arg arg; @@ -215,7 +215,7 @@ vmw_ioctl_buffer_destroy(struct vmw_driver *vmw, struct vmw_dma_buffer *buf) } void * -vmw_ioctl_buffer_map(struct vmw_driver *vmw, struct vmw_dma_buffer *buf) +vmw_ioctl_buffer_map(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) { void *map; @@ -236,7 +236,7 @@ vmw_ioctl_buffer_map(struct vmw_driver *vmw, struct vmw_dma_buffer *buf) } void -vmw_ioctl_buffer_unmap(struct vmw_driver *vmw, struct vmw_dma_buffer *buf) +vmw_ioctl_buffer_unmap(struct vmw_customizer *vmw, struct vmw_dma_buffer *buf) { --buf->map_count; } diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c b/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c index 7c9757cce95..f43f91e5c0d 100644 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c +++ b/src/gallium/winsys/drm/vmware/xorg/vmw_screen.c @@ -41,7 +41,8 @@ xf86CrtcFuncsRec vmw_screen_crtc_funcs; static void vmw_screen_cursor_load_argb(xf86CrtcPtr crtc, CARD32 *image) { - struct vmw_driver *vmw = modesettingPTR(crtc->scrn)->winsys_priv; + struct vmw_customizer *vmw = + vmw_customizer(xorg_customizer(crtc->scrn)); xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); xf86CrtcFuncsPtr funcs = vmw->cursor_priv; CursorPtr c = config->cursor; @@ -53,8 +54,9 @@ vmw_screen_cursor_load_argb(xf86CrtcPtr crtc, CARD32 *image) } static void -vmw_screen_cursor_init(ScrnInfoPtr pScrn, struct vmw_driver *vmw) +vmw_screen_cursor_init(struct vmw_customizer *vmw) { + ScrnInfoPtr pScrn = vmw->pScrn; xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); int i; @@ -70,9 +72,9 @@ vmw_screen_cursor_init(ScrnInfoPtr pScrn, struct vmw_driver *vmw) } static void -vmw_screen_cursor_close(ScrnInfoPtr pScrn, struct vmw_driver *vmw) +vmw_screen_cursor_close(struct vmw_customizer *vmw) { - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(vmw->pScrn); int i; vmw_ioctl_cursor_bypass(vmw, 0, 0); @@ -82,50 +84,39 @@ vmw_screen_cursor_close(ScrnInfoPtr pScrn, struct vmw_driver *vmw) } static Bool -vmw_screen_init(ScrnInfoPtr pScrn) +vmw_screen_init(CustomizerPtr cust, int fd) { - modesettingPtr ms = modesettingPTR(pScrn); - struct vmw_driver *vmw; - - vmw = xnfcalloc(sizeof(*vmw), 1); - if (!vmw) - return FALSE; + struct vmw_customizer *vmw = vmw_customizer(cust); - vmw->fd = ms->fd; - ms->winsys_priv = vmw; - - vmw_screen_cursor_init(pScrn, vmw); + vmw->fd = fd; + vmw_screen_cursor_init(vmw); /* if gallium is used then we don't need to do anything more. */ - if (ms->screen) + if (xorg_has_gallium(vmw->pScrn)) return TRUE; - vmw_video_init(pScrn, vmw); + vmw_video_init(vmw); return TRUE; } static Bool -vmw_screen_close(ScrnInfoPtr pScrn) +vmw_screen_close(CustomizerPtr cust) { - modesettingPtr ms = modesettingPTR(pScrn); - struct vmw_driver *vmw = vmw_driver(pScrn); + struct vmw_customizer *vmw = vmw_customizer(cust); if (!vmw) return TRUE; - vmw_screen_cursor_close(pScrn, vmw); - - vmw_video_close(pScrn, vmw); + vmw_screen_cursor_close(vmw); - ms->winsys_priv = NULL; - xfree(vmw); + vmw_video_close(vmw); return TRUE; } static Bool -vmw_screen_enter_vt(ScrnInfoPtr pScrn) +vmw_screen_enter_vt(CustomizerPtr cust) { debug_printf("%s: enter\n", __func__); @@ -133,13 +124,13 @@ vmw_screen_enter_vt(ScrnInfoPtr pScrn) } static Bool -vmw_screen_leave_vt(ScrnInfoPtr pScrn) +vmw_screen_leave_vt(CustomizerPtr cust) { - struct vmw_driver *vmw = vmw_driver(pScrn); + struct vmw_customizer *vmw = vmw_customizer(cust); debug_printf("%s: enter\n", __func__); - vmw_video_stop_all(pScrn, vmw); + vmw_video_stop_all(vmw); return TRUE; } @@ -153,18 +144,27 @@ static Bool (*vmw_screen_pre_init_saved)(ScrnInfoPtr pScrn, int flags) = NULL; static Bool vmw_screen_pre_init(ScrnInfoPtr pScrn, int flags) { - modesettingPtr ms; + struct vmw_customizer *vmw; + CustomizerPtr cust; + + vmw = xnfcalloc(1, sizeof(*vmw)); + if (!vmw) + return FALSE; + + cust = &vmw->base; + + cust->winsys_screen_init = vmw_screen_init; + cust->winsys_screen_close = vmw_screen_close; + cust->winsys_enter_vt = vmw_screen_enter_vt; + cust->winsys_leave_vt = vmw_screen_leave_vt; + vmw->pScrn = pScrn; + + pScrn->driverPrivate = cust; pScrn->PreInit = vmw_screen_pre_init_saved; if (!pScrn->PreInit(pScrn, flags)) return FALSE; - ms = modesettingPTR(pScrn); - ms->winsys_screen_init = vmw_screen_init; - ms->winsys_screen_close = vmw_screen_close; - ms->winsys_enter_vt = vmw_screen_enter_vt; - ms->winsys_leave_vt = vmw_screen_leave_vt; - return TRUE; } diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_video.c b/src/gallium/winsys/drm/vmware/xorg/vmw_video.c index ff3b992d078..de28f06a475 100644 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_video.c +++ b/src/gallium/winsys/drm/vmware/xorg/vmw_video.c @@ -226,7 +226,7 @@ static void vmw_xv_query_best_size(ScrnInfoPtr pScrn, Bool motion, /* * Local functions. */ -static XF86VideoAdaptorPtr vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_driver *vmw); +static XF86VideoAdaptorPtr vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw); static int vmw_video_port_init(ScrnInfoPtr pScrn, struct vmw_video_port *port, @@ -243,9 +243,9 @@ static int vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, short height, RegionPtr clipBoxes); static void vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port); -static int vmw_video_buffer_alloc(struct vmw_driver *vmw, int size, +static int vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, struct vmw_video_buffer *out); -static int vmw_video_buffer_free(struct vmw_driver *vmw, +static int vmw_video_buffer_free(struct vmw_customizer *vmw, struct vmw_video_buffer *out); @@ -267,8 +267,9 @@ static int vmw_video_buffer_free(struct vmw_driver *vmw, */ Bool -vmw_video_init(ScrnInfoPtr pScrn, struct vmw_driver *vmw) +vmw_video_init(struct vmw_customizer *vmw) { + ScrnInfoPtr pScrn = vmw->pScrn; ScreenPtr pScreen = pScrn->pScreen; XF86VideoAdaptorPtr *overlayAdaptors, *newAdaptors = NULL; XF86VideoAdaptorPtr newAdaptor = NULL; @@ -345,8 +346,9 @@ vmw_video_init(ScrnInfoPtr pScrn, struct vmw_driver *vmw) */ Bool -vmw_video_close(ScrnInfoPtr pScrn, struct vmw_driver *vmw) +vmw_video_close(struct vmw_customizer *vmw) { + ScrnInfoPtr pScrn = vmw->pScrn; struct vmw_video_private *video; int i; @@ -387,8 +389,9 @@ vmw_video_close(ScrnInfoPtr pScrn, struct vmw_driver *vmw) *----------------------------------------------------------------------------- */ -void vmw_video_stop_all(ScrnInfoPtr pScrn, struct vmw_driver *vmw) +void vmw_video_stop_all(struct vmw_customizer *vmw) { + ScrnInfoPtr pScrn = vmw->pScrn; struct vmw_video_private *video = vmw->video_priv; int i; @@ -421,7 +424,7 @@ void vmw_video_stop_all(ScrnInfoPtr pScrn, struct vmw_driver *vmw) */ static XF86VideoAdaptorPtr -vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_driver *vmw) +vmw_video_init_adaptor(ScrnInfoPtr pScrn, struct vmw_customizer *vmw) { XF86VideoAdaptorPtr adaptor; struct vmw_video_private *video; @@ -515,7 +518,7 @@ vmw_video_port_init(ScrnInfoPtr pScrn, struct vmw_video_port *port, unsigned char *buf, short width, short height, RegionPtr clipBoxes) { - struct vmw_driver *vmw = vmw_driver(pScrn); + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); unsigned short w, h; int i, ret; @@ -583,7 +586,7 @@ vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, unsigned char *buf, short width, short height, RegionPtr clipBoxes) { - struct vmw_driver *vmw = vmw_driver(pScrn); + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); struct drm_vmw_control_stream_arg arg; unsigned short w, h; int size; @@ -675,7 +678,7 @@ vmw_video_port_play(ScrnInfoPtr pScrn, struct vmw_video_port *port, static void vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port) { - struct vmw_driver *vmw = vmw_driver(pScrn); + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); uint32 id, colorKey, flags; Bool isAutoPaintColorkey; int i; @@ -721,7 +724,7 @@ vmw_video_port_cleanup(ScrnInfoPtr pScrn, struct vmw_video_port *port) */ static int -vmw_video_buffer_alloc(struct vmw_driver *vmw, int size, +vmw_video_buffer_alloc(struct vmw_customizer *vmw, int size, struct vmw_video_buffer *out) { out->buf = vmw_ioctl_buffer_create(vmw, size, &out->handle); @@ -764,7 +767,7 @@ vmw_video_buffer_alloc(struct vmw_driver *vmw, int size, */ static int -vmw_video_buffer_free(struct vmw_driver *vmw, +vmw_video_buffer_free(struct vmw_customizer *vmw, struct vmw_video_buffer *out) { if (out->size == 0) @@ -814,7 +817,7 @@ vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, Bool sync, RegionPtr clipBoxes, pointer data, DrawablePtr dst) { - struct vmw_driver *vmw = vmw_driver(pScrn); + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); struct vmw_video_port *port = data; debug_printf("%s: enter (%u, %u) (%ux%u) (%u, %u) (%ux%u) (%ux%u)\n", __func__, @@ -852,7 +855,7 @@ vmw_xv_put_image(ScrnInfoPtr pScrn, short src_x, short src_y, static void vmw_xv_stop_video(ScrnInfoPtr pScrn, pointer data, Bool cleanup) { - struct vmw_driver *vmw = vmw_driver(pScrn); + struct vmw_customizer *vmw = vmw_customizer(xorg_customizer(pScrn)); struct vmw_video_port *port = data; struct drm_vmw_control_stream_arg arg; int ret; diff --git a/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c b/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c index cd273d091fe..87aad25b24f 100644 --- a/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c +++ b/src/gallium/winsys/drm/vmware/xorg/vmw_xorg.c @@ -33,12 +33,50 @@ #include "vmw_hook.h" + +/* + * Defines and modinfo + */ + +#define VMWGFX_DRIVER_NAME "vmwgfx" + +#define VMW_STRING_INNER(s) #s +#define VMW_STRING(str) VMW_STRING_INNER(str) + +#define VMWGFX_VERSION_MAJOR 11 +#define VMWGFX_VERSION_MINOR 0 +#define VMWGFX_VERSION_PATCH 0 +#define VMWGFX_VERSION_STRING_MAJOR VMW_STRING(VMWGFX_VERSION_MAJOR) +#define VMWGFX_VERSION_STRING_MINOR VMW_STRING(VMWGFX_VERSION_MINOR) +#define VMWGFX_VERSION_STRING_PATCH VMW_STRING(VMWGFX_VERSION_PATCH) + +#define VMWGFX_DRIVER_VERSION \ + (VMWGFX_VERSION_MAJOR * 65536 + VMWGFX_VERSION_MINOR * 256 + VMWGFX_VERSION_PATCH) +#define VMWGFX_DRIVER_VERSION_STRING \ + VMWGFX_VERSION_STRING_MAJOR "." VMWGFX_VERSION_STRING_MINOR \ + "." VMWGFX_VERSION_STRING_PATCH + +/* + * Standard four digit version string expected by VMware Tools installer. + * As the driver's version is only {major, minor, patchlevel}, simply append an + * extra zero for the fourth digit. + */ +#ifdef __GNUC__ +_X_EXPORT const char vmwgfx_drv_modinfo[] __attribute__((section(".modinfo"),unused)) = + "version=" VMWGFX_DRIVER_VERSION_STRING ".0"; +#endif + static void vmw_xorg_identify(int flags); _X_EXPORT Bool vmw_xorg_pci_probe(DriverPtr driver, int entity_num, struct pci_device *device, intptr_t match_data); + +/* + * Tables + */ + static const struct pci_id_match vmw_xorg_device_match[] = { {0x15ad, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0}, @@ -55,12 +93,12 @@ static PciChipsets vmw_xorg_pci_devices[] = { }; static XF86ModuleVersionInfo vmw_xorg_version = { - "vmwgfx", + VMWGFX_DRIVER_NAME, MODULEVENDORSTRING, MODINFOSTRING1, MODINFOSTRING2, XORG_VERSION_CURRENT, - 0, 1, 0, /* major, minor, patch */ + VMWGFX_VERSION_MAJOR, VMWGFX_VERSION_MINOR, VMWGFX_VERSION_PATCH, ABI_CLASS_VIDEODRV, ABI_VIDEODRV_VERSION, MOD_CLASS_VIDEODRV, @@ -73,7 +111,7 @@ static XF86ModuleVersionInfo vmw_xorg_version = { _X_EXPORT DriverRec vmwgfx = { 1, - "vmwgfx", + VMWGFX_DRIVER_NAME, vmw_xorg_identify, NULL, xorg_tracker_available_options, @@ -92,6 +130,7 @@ _X_EXPORT XF86ModuleData vmwgfxModuleData = { NULL }; + /* * Xorg driver functions */ diff --git a/src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c b/src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c index e9e5990cf53..a9fa03b8e57 100644 --- a/src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c +++ b/src/gallium/winsys/gdi/gdi_llvmpipe_winsys.c @@ -75,8 +75,8 @@ gdi_llvmpipe_is_displaytarget_format_supported( struct llvmpipe_winsys *ws, enum pipe_format format ) { switch(format) { - case PIPE_FORMAT_X8R8G8B8_UNORM: - case PIPE_FORMAT_A8R8G8B8_UNORM: + case PIPE_FORMAT_B8G8R8X8_UNORM: + case PIPE_FORMAT_B8G8R8A8_UNORM: return TRUE; /* TODO: Support other formats possible with BMPs, as described in diff --git a/src/gallium/winsys/xlib/Makefile b/src/gallium/winsys/xlib/Makefile index 9482e8f9b11..824c666ae30 100644 --- a/src/gallium/winsys/xlib/Makefile +++ b/src/gallium/winsys/xlib/Makefile @@ -50,10 +50,10 @@ LIBS = \ .SUFFIXES : .cpp .c.o: - $(CC) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) $< -o $@ + $(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $< -o $@ .cpp.o: - $(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CXXFLAGS) $< -o $@ + $(CXX) -c $(INCLUDE_DIRS) $(CXXFLAGS) $< -o $@ diff --git a/src/gallium/winsys/xlib/SConscript b/src/gallium/winsys/xlib/SConscript index a4dabb7804c..8c9d318af2b 100644 --- a/src/gallium/winsys/xlib/SConscript +++ b/src/gallium/winsys/xlib/SConscript @@ -14,11 +14,7 @@ if env['dri']: print 'warning: DRI enabled: skipping build of xlib libGL.so' Return() -if 'trace' not in env['drivers']: - print 'warning: trace pipe driver disabled: skipping build of xlib libGL.so' - Return() - -if not set(('softpipe', 'llvmpipe', 'trace')).intersection(env['drivers']): +if not set(('softpipe', 'llvmpipe', 'cell')).intersection(env['drivers']): print 'warning: no supported pipe driver: skipping build of xlib libGL.so' Return() |