diff options
Diffstat (limited to 'mesalib/src/gallium')
-rw-r--r-- | mesalib/src/gallium/auxiliary/hud/hud_context.c | 3 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_blitter.c | 124 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_blitter.h | 2 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_cpu_detect.c | 5 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_format.h | 28 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_math.h | 3 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_resource.h | 20 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_simple_list.h | 1 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_simple_shaders.c | 21 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_simple_shaders.h | 7 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_surface.c | 240 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_surface.h | 7 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_transfer.c | 1 | ||||
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_vbuf.c | 3 |
14 files changed, 244 insertions, 221 deletions
diff --git a/mesalib/src/gallium/auxiliary/hud/hud_context.c b/mesalib/src/gallium/auxiliary/hud/hud_context.c index de032b6ba..cbd00a961 100644 --- a/mesalib/src/gallium/auxiliary/hud/hud_context.c +++ b/mesalib/src/gallium/auxiliary/hud/hud_context.c @@ -959,7 +959,8 @@ hud_create(struct pipe_context *pipe, struct cso_context *cso) hud->fs_color = util_make_fragment_passthrough_shader(pipe, TGSI_SEMANTIC_COLOR, - TGSI_INTERPOLATE_CONSTANT); + TGSI_INTERPOLATE_CONSTANT, + TRUE); { /* Read a texture and do .xxxx swizzling. */ diff --git a/mesalib/src/gallium/auxiliary/util/u_blitter.c b/mesalib/src/gallium/auxiliary/util/u_blitter.c index 8c871fdf9..e9ac170f7 100644 --- a/mesalib/src/gallium/auxiliary/util/u_blitter.c +++ b/mesalib/src/gallium/auxiliary/util/u_blitter.c @@ -67,9 +67,9 @@ struct blitter_context_priv void *vs_pos_only; /**< Vertex shader which passes pos to the output.*/ /* Fragment shaders. */ - /* The shader at index i outputs color to color buffers 0,1,...,i-1. */ - void *fs_col[PIPE_MAX_COLOR_BUFS+1]; - void *fs_col_int[PIPE_MAX_COLOR_BUFS+1]; + void *fs_empty; + void *fs_write_one_cbuf; + void *fs_write_all_cbufs; /* FS which outputs a color from a texture, where the index is PIPE_TEXTURE_* to be sampled. */ @@ -98,8 +98,6 @@ struct blitter_context_priv /* Vertex elements states. */ void *velem_state; - void *velem_uint_state; - void *velem_sint_state; void *velem_state_readbuf[4]; /**< X, XY, XYZ, XYZW */ /* Sampler state. */ @@ -119,7 +117,6 @@ struct blitter_context_priv unsigned dst_height; boolean has_geometry_shader; - boolean vertex_has_integers; boolean has_stream_out; boolean has_stencil_export; boolean has_texture_multisample; @@ -171,9 +168,6 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) ctx->has_geometry_shader = pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0; - ctx->vertex_has_integers = - pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_VERTEX, - PIPE_SHADER_CAP_INTEGERS); ctx->has_stream_out = pipe->screen->get_param(pipe->screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS) != 0; @@ -265,26 +259,6 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) } ctx->velem_state = pipe->create_vertex_elements_state(pipe, 2, &velem[0]); - if (ctx->vertex_has_integers) { - memset(&velem[0], 0, sizeof(velem[0]) * 2); - velem[0].src_offset = 0; - velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - velem[0].vertex_buffer_index = ctx->base.vb_slot; - velem[1].src_offset = 4 * sizeof(float); - velem[1].src_format = PIPE_FORMAT_R32G32B32A32_SINT; - velem[1].vertex_buffer_index = ctx->base.vb_slot; - ctx->velem_sint_state = pipe->create_vertex_elements_state(pipe, 2, &velem[0]); - - memset(&velem[0], 0, sizeof(velem[0]) * 2); - velem[0].src_offset = 0; - velem[0].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - velem[0].vertex_buffer_index = ctx->base.vb_slot; - velem[1].src_offset = 4 * sizeof(float); - velem[1].src_format = PIPE_FORMAT_R32G32B32A32_UINT; - velem[1].vertex_buffer_index = ctx->base.vb_slot; - ctx->velem_uint_state = pipe->create_vertex_elements_state(pipe, 2, &velem[0]); - } - if (ctx->has_stream_out) { static enum pipe_format formats[4] = { PIPE_FORMAT_R32_UINT, @@ -301,7 +275,16 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe) } } - /* fragment shaders are created on-demand */ + /* Fragment shaders are created on-demand, except these. + * The interpolation must be constant for integer texture clearing to work. + */ + ctx->fs_empty = util_make_empty_fragment_shader(pipe); + ctx->fs_write_one_cbuf = + util_make_fragment_passthrough_shader(pipe, TGSI_SEMANTIC_GENERIC, + TGSI_INTERPOLATE_CONSTANT, FALSE); + ctx->fs_write_all_cbufs = + util_make_fragment_passthrough_shader(pipe, TGSI_SEMANTIC_GENERIC, + TGSI_INTERPOLATE_CONSTANT, TRUE); /* vertex shaders */ { @@ -359,10 +342,6 @@ void util_blitter_destroy(struct blitter_context *blitter) if (ctx->vs_pos_only) pipe->delete_vs_state(pipe, ctx->vs_pos_only); pipe->delete_vertex_elements_state(pipe, ctx->velem_state); - if (ctx->vertex_has_integers) { - pipe->delete_vertex_elements_state(pipe, ctx->velem_sint_state); - pipe->delete_vertex_elements_state(pipe, ctx->velem_uint_state); - } for (i = 0; i < 4; i++) { if (ctx->velem_state_readbuf[i]) { pipe->delete_vertex_elements_state(pipe, ctx->velem_state_readbuf[i]); @@ -379,13 +358,9 @@ void util_blitter_destroy(struct blitter_context *blitter) if (ctx->fs_texfetch_stencil[i]) ctx->delete_fs_state(pipe, ctx->fs_texfetch_stencil[i]); } - - for (i = 0; i <= PIPE_MAX_COLOR_BUFS; i++) { - if (ctx->fs_col[i]) - ctx->delete_fs_state(pipe, ctx->fs_col[i]); - if (ctx->fs_col_int[i]) - ctx->delete_fs_state(pipe, ctx->fs_col_int[i]); - } + ctx->delete_fs_state(pipe, ctx->fs_empty); + ctx->delete_fs_state(pipe, ctx->fs_write_one_cbuf); + ctx->delete_fs_state(pipe, ctx->fs_write_all_cbufs); pipe->delete_sampler_state(pipe, ctx->sampler_state_rect_linear); pipe->delete_sampler_state(pipe, ctx->sampler_state_rect); @@ -732,30 +707,6 @@ static void blitter_set_dst_dimensions(struct blitter_context_priv *ctx, ctx->dst_height = height; } -static void *blitter_get_fs_col(struct blitter_context_priv *ctx, - unsigned num_cbufs, boolean int_format) -{ - struct pipe_context *pipe = ctx->base.pipe; - - assert(num_cbufs <= PIPE_MAX_COLOR_BUFS); - - if (int_format) { - if (!ctx->fs_col_int[num_cbufs]) - ctx->fs_col_int[num_cbufs] = - util_make_fragment_cloneinput_shader(pipe, num_cbufs, - TGSI_SEMANTIC_GENERIC, - TGSI_INTERPOLATE_CONSTANT); - return ctx->fs_col_int[num_cbufs]; - } else { - if (!ctx->fs_col[num_cbufs]) - ctx->fs_col[num_cbufs] = - util_make_fragment_cloneinput_shader(pipe, num_cbufs, - TGSI_SEMANTIC_GENERIC, - TGSI_INTERPOLATE_LINEAR); - return ctx->fs_col[num_cbufs]; - } -} - static void *blitter_get_fs_texfetch_col(struct blitter_context_priv *ctx, enum pipe_texture_target target, unsigned nr_samples) @@ -910,22 +861,15 @@ void util_blitter_cache_all_shaders(struct blitter_context *blitter) { struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; struct pipe_screen *screen = blitter->pipe->screen; - unsigned num_cbufs, i, target, max_samples; + unsigned i, target, max_samples; boolean has_arraytex, has_cubearraytex; - num_cbufs = MAX2(screen->get_param(screen, - PIPE_CAP_MAX_RENDER_TARGETS), 1); max_samples = ctx->has_texture_multisample ? 2 : 1; has_arraytex = screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS) != 0; has_cubearraytex = screen->get_param(screen, PIPE_CAP_CUBE_MAP_ARRAY) != 0; - for (i = 0; i < num_cbufs; i++) { - blitter_get_fs_col(ctx, i, FALSE); - blitter_get_fs_col(ctx, i, TRUE); - } - /* It only matters if i <= 1 or > 1. */ for (i = 1; i <= max_samples; i++) { for (target = PIPE_TEXTURE_1D; target < PIPE_MAX_TEXTURE_TYPES; target++) { @@ -1007,9 +951,7 @@ void util_blitter_draw_rectangle(struct blitter_context *blitter, static void util_blitter_clear_custom(struct blitter_context *blitter, unsigned width, unsigned height, - unsigned num_cbufs, unsigned clear_buffers, - enum pipe_format cbuf_format, const union pipe_color_union *color, double depth, unsigned stencil, void *custom_blend, void *custom_dsa) @@ -1017,8 +959,6 @@ static void util_blitter_clear_custom(struct blitter_context *blitter, struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; struct pipe_context *pipe = ctx->base.pipe; struct pipe_stencil_ref sr = { { 0 } }; - boolean int_format = util_format_is_pure_integer(cbuf_format); - assert(num_cbufs <= PIPE_MAX_COLOR_BUFS); blitter_set_running_flag(ctx); blitter_check_saved_vertex_states(ctx); @@ -1049,14 +989,8 @@ static void util_blitter_clear_custom(struct blitter_context *blitter, sr.ref_value[0] = stencil & 0xff; pipe->set_stencil_ref(pipe, &sr); - if (util_format_is_pure_sint(cbuf_format)) { - pipe->bind_vertex_elements_state(pipe, ctx->velem_sint_state); - } else if (util_format_is_pure_uint(cbuf_format)) { - pipe->bind_vertex_elements_state(pipe, ctx->velem_uint_state); - } else { - pipe->bind_vertex_elements_state(pipe, ctx->velem_state); - } - ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, num_cbufs, int_format)); + pipe->bind_vertex_elements_state(pipe, ctx->velem_state); + ctx->bind_fs_state(pipe, ctx->fs_write_all_cbufs); pipe->set_sample_mask(pipe, ~0); blitter_set_common_draw_rect_state(ctx, FALSE); @@ -1072,14 +1006,12 @@ static void util_blitter_clear_custom(struct blitter_context *blitter, void util_blitter_clear(struct blitter_context *blitter, unsigned width, unsigned height, - unsigned num_cbufs, unsigned clear_buffers, - enum pipe_format cbuf_format, const union pipe_color_union *color, double depth, unsigned stencil) { - util_blitter_clear_custom(blitter, width, height, num_cbufs, - clear_buffers, cbuf_format, color, depth, stencil, + util_blitter_clear_custom(blitter, width, height, + clear_buffers, color, depth, stencil, NULL, NULL); } @@ -1088,8 +1020,8 @@ void util_blitter_custom_clear_depth(struct blitter_context *blitter, double depth, void *custom_dsa) { static const union pipe_color_union color; - util_blitter_clear_custom(blitter, width, height, 0, - 0, PIPE_FORMAT_NONE, &color, depth, 0, NULL, custom_dsa); + util_blitter_clear_custom(blitter, width, height, 0, &color, depth, 0, + NULL, custom_dsa); } void util_blitter_default_dst_texture(struct pipe_surface *dst_templ, @@ -1559,7 +1491,7 @@ void util_blitter_clear_render_target(struct blitter_context *blitter, /* bind states */ pipe->bind_blend_state(pipe, ctx->blend[PIPE_MASK_RGBA]); pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); - ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE)); + ctx->bind_fs_state(pipe, ctx->fs_write_one_cbuf); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); /* set a framebuffer state */ @@ -1627,7 +1559,7 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter, /* hmm that should be illegal probably, or make it a no-op somewhere */ pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); - ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0, FALSE)); + ctx->bind_fs_state(pipe, ctx->fs_empty); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); /* set a framebuffer state */ @@ -1678,7 +1610,7 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter, pipe->bind_blend_state(pipe, cbsurf ? ctx->blend[PIPE_MASK_RGBA] : ctx->blend[0]); pipe->bind_depth_stencil_alpha_state(pipe, dsa_stage); - ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0, FALSE)); + ctx->bind_fs_state(pipe, ctx->fs_empty); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); /* set a framebuffer state */ @@ -1855,7 +1787,7 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter, pipe->bind_blend_state(pipe, custom_blend); pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); - ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE)); + ctx->bind_fs_state(pipe, ctx->fs_write_one_cbuf); pipe->set_sample_mask(pipe, sample_mask); memset(&surf_tmpl, 0, sizeof(surf_tmpl)); @@ -1918,7 +1850,7 @@ void util_blitter_custom_color(struct blitter_context *blitter, pipe->bind_blend_state(pipe, custom_blend ? custom_blend : ctx->blend[PIPE_MASK_RGBA]); pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil); - ctx->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1, FALSE)); + ctx->bind_fs_state(pipe, ctx->fs_write_one_cbuf); pipe->bind_vertex_elements_state(pipe, ctx->velem_state); pipe->set_sample_mask(pipe, (1ull << MAX2(1, dstsurf->texture->nr_samples)) - 1); diff --git a/mesalib/src/gallium/auxiliary/util/u_blitter.h b/mesalib/src/gallium/auxiliary/util/u_blitter.h index 19015844e..e52d5acc9 100644 --- a/mesalib/src/gallium/auxiliary/util/u_blitter.h +++ b/mesalib/src/gallium/auxiliary/util/u_blitter.h @@ -183,9 +183,7 @@ void util_blitter_draw_rectangle(struct blitter_context *blitter, */ void util_blitter_clear(struct blitter_context *blitter, unsigned width, unsigned height, - unsigned num_cbufs, unsigned clear_buffers, - enum pipe_format cbuf_format, const union pipe_color_union *color, double depth, unsigned stencil); diff --git a/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c b/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c index 7e6df9df1..763b5cc22 100644 --- a/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c +++ b/mesalib/src/gallium/auxiliary/util/u_cpu_detect.c @@ -250,6 +250,11 @@ util_cpu_detect(void) util_cpu_caps.nr_cpus = 1; #endif + /* Make the fallback cacheline size nonzero so that it can be + * safely passed to align(). + */ + util_cpu_caps.cacheline = sizeof(void *); + #if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) if (has_cpuid()) { uint32_t regs[4]; diff --git a/mesalib/src/gallium/auxiliary/util/u_format.h b/mesalib/src/gallium/auxiliary/util/u_format.h index e4b9c365c..4cace6ad1 100644 --- a/mesalib/src/gallium/auxiliary/util/u_format.h +++ b/mesalib/src/gallium/auxiliary/util/u_format.h @@ -31,6 +31,7 @@ #include "pipe/p_format.h" +#include "pipe/p_defines.h" #include "util/u_debug.h" union pipe_color_union; @@ -520,6 +521,33 @@ util_format_is_depth_and_stencil(enum pipe_format format) util_format_has_stencil(desc); } +/** + * Return whether this is an RGBA, Z, S, or combined ZS format. + * Useful for initializing pipe_blit_info::mask. + */ +static INLINE unsigned +util_format_get_mask(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + if (!desc) + return 0; + + if (util_format_has_depth(desc)) { + if (util_format_has_stencil(desc)) { + return PIPE_MASK_ZS; + } else { + return PIPE_MASK_Z; + } + } else { + if (util_format_has_stencil(desc)) { + return PIPE_MASK_S; + } else { + return PIPE_MASK_RGBA; + } + } +} /** * Give the RGBA colormask of the channels that can be represented in this diff --git a/mesalib/src/gallium/auxiliary/util/u_math.h b/mesalib/src/gallium/auxiliary/util/u_math.h index 607fbecb0..64d16cbe7 100644 --- a/mesalib/src/gallium/auxiliary/util/u_math.h +++ b/mesalib/src/gallium/auxiliary/util/u_math.h @@ -540,14 +540,13 @@ ubyte_to_float(ubyte ub) static INLINE ubyte float_to_ubyte(float f) { - const int ieee_0996 = 0x3f7f0000; /* 0.996 or so */ union fi tmp; tmp.f = f; if (tmp.i < 0) { return (ubyte) 0; } - else if (tmp.i >= ieee_0996) { + else if (tmp.i >= 0x3f800000 /* 1.0f */) { return (ubyte) 255; } else { diff --git a/mesalib/src/gallium/auxiliary/util/u_resource.h b/mesalib/src/gallium/auxiliary/util/u_resource.h index 977e0136b..a5e091fd6 100644 --- a/mesalib/src/gallium/auxiliary/util/u_resource.h +++ b/mesalib/src/gallium/auxiliary/util/u_resource.h @@ -26,9 +26,27 @@ #ifndef U_RESOURCE_H #define U_RESOURCE_H -struct pipe_resource; +#include "pipe/p_state.h" unsigned util_resource_size(const struct pipe_resource *res); +/** + * Return true if the resource is an array texture. + * + * Note that this function returns true for single-layered array textures. + */ +static INLINE boolean +util_resource_is_array_texture(const struct pipe_resource *res) +{ + switch (res->target) { + case PIPE_TEXTURE_1D_ARRAY: + case PIPE_TEXTURE_2D_ARRAY: + case PIPE_TEXTURE_CUBE_ARRAY: + return TRUE; + default: + return FALSE; + } +} + #endif diff --git a/mesalib/src/gallium/auxiliary/util/u_simple_list.h b/mesalib/src/gallium/auxiliary/util/u_simple_list.h index 7a47c1a78..3f7def5fc 100644 --- a/mesalib/src/gallium/auxiliary/util/u_simple_list.h +++ b/mesalib/src/gallium/auxiliary/util/u_simple_list.h @@ -11,7 +11,6 @@ /* * Mesa 3-D graphics library - * Version: 3.5 * * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. * diff --git a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c index c53c2d024..c93d75469 100644 --- a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c +++ b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.c @@ -322,11 +322,12 @@ util_make_fragment_tex_shader_writestencil(struct pipe_context *pipe, void * util_make_fragment_passthrough_shader(struct pipe_context *pipe, int input_semantic, - int input_interpolate) + int input_interpolate, + boolean write_all_cbufs) { static const char shader_templ[] = "FRAG\n" - "PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1\n" + "%s" "DCL IN[0], %s[0], %s\n" "DCL OUT[0], COLOR[0]\n" @@ -337,7 +338,9 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe, struct tgsi_token tokens[1000]; struct pipe_shader_state state = {tokens}; - sprintf(text, shader_templ, tgsi_semantic_names[input_semantic], + sprintf(text, shader_templ, + write_all_cbufs ? "PROPERTY FS_COLOR0_WRITES_ALL_CBUFS 1\n" : "", + tgsi_semantic_names[input_semantic], tgsi_interpolate_names[input_interpolate]); if (!tgsi_text_translate(text, tokens, Elements(tokens))) { @@ -352,6 +355,18 @@ util_make_fragment_passthrough_shader(struct pipe_context *pipe, } +void * +util_make_empty_fragment_shader(struct pipe_context *pipe) +{ + struct ureg_program *ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); + if (ureg == NULL) + return NULL; + + ureg_END(ureg); + return ureg_create_shader_and_destroy(ureg, pipe); +} + + /** * Make a fragment shader that copies the input color to N output colors. */ diff --git a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.h b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.h index 22b9cee4d..016664d1b 100644 --- a/mesalib/src/gallium/auxiliary/util/u_simple_shaders.h +++ b/mesalib/src/gallium/auxiliary/util/u_simple_shaders.h @@ -89,7 +89,12 @@ util_make_fragment_tex_shader_writestencil(struct pipe_context *pipe, extern void * util_make_fragment_passthrough_shader(struct pipe_context *pipe, int input_semantic, - int input_interpolate); + int input_interpolate, + boolean write_all_cbufs); + + +extern void * +util_make_empty_fragment_shader(struct pipe_context *pipe); extern void * diff --git a/mesalib/src/gallium/auxiliary/util/u_surface.c b/mesalib/src/gallium/auxiliary/util/u_surface.c index 5c3a655d6..07997d2ad 100644 --- a/mesalib/src/gallium/auxiliary/util/u_surface.c +++ b/mesalib/src/gallium/auxiliary/util/u_surface.c @@ -214,6 +214,30 @@ util_fill_rect(ubyte * dst, } +void +util_fill_box(ubyte * dst, + enum pipe_format format, + unsigned stride, + unsigned layer_stride, + unsigned x, + unsigned y, + unsigned z, + unsigned width, + unsigned height, + unsigned depth, + union util_color *uc) +{ + unsigned layer; + dst += z * layer_stride; + for (layer = z; layer < depth; layer++) { + util_fill_rect(dst, format, + stride, + x, y, width, height, uc); + dst += layer_stride; + } +} + + /** * Fallback function for pipe->resource_copy_region(). * Note: (X,Y)=(0,0) is always the upper-left corner. @@ -307,6 +331,7 @@ no_src_map: * cpp > 4 looks like a gross hack at best... * Plus can't use these transfer fallbacks when clearing * multisampled surfaces for instance. + * Clears all bound layers. */ void util_clear_render_target(struct pipe_context *pipe, @@ -316,8 +341,9 @@ util_clear_render_target(struct pipe_context *pipe, unsigned width, unsigned height) { struct pipe_transfer *dst_trans; - void *dst_map; + ubyte *dst_map; union util_color uc; + unsigned max_layer; assert(dst->texture); if (!dst->texture) @@ -332,6 +358,7 @@ util_clear_render_target(struct pipe_context *pipe, unsigned pixstride = util_format_get_blocksize(dst->format); dx = (dst->u.buf.first_element + dstx) * pixstride; w = width * pixstride; + max_layer = 0; dst_map = pipe_transfer_map(pipe, dst->texture, 0, 0, @@ -340,14 +367,13 @@ util_clear_render_target(struct pipe_context *pipe, &dst_trans); } else { - /* XXX: should handle multiple layers */ - dst_map = pipe_transfer_map(pipe, - dst->texture, - dst->u.tex.level, - dst->u.tex.first_layer, - PIPE_TRANSFER_WRITE, - dstx, dsty, width, height, &dst_trans); - + max_layer = dst->u.tex.last_layer - dst->u.tex.first_layer; + dst_map = pipe_transfer_map_3d(pipe, + dst->texture, + dst->u.tex.level, + PIPE_TRANSFER_WRITE, + dstx, dsty, dst->u.tex.first_layer, + width, height, max_layer + 1, &dst_trans); } assert(dst_map); @@ -373,9 +399,10 @@ util_clear_render_target(struct pipe_context *pipe, else { util_pack_color(color->f, dst->format, &uc); } - util_fill_rect(dst_map, dst->format, - dst_trans->stride, - 0, 0, width, height, &uc); + + util_fill_box(dst_map, dst->format, + dst_trans->stride, dst_trans->layer_stride, + 0, 0, 0, width, height, max_layer + 1, &uc); pipe->transfer_unmap(pipe, dst_trans); } @@ -386,6 +413,7 @@ util_clear_render_target(struct pipe_context *pipe, * sw fallback doesn't look terribly useful here. * Plus can't use these transfer fallbacks when clearing * multisampled surfaces for instance. + * Clears all bound layers. */ void util_clear_depth_stencil(struct pipe_context *pipe, @@ -400,6 +428,7 @@ util_clear_depth_stencil(struct pipe_context *pipe, struct pipe_transfer *dst_trans; ubyte *dst_map; boolean need_rmw = FALSE; + unsigned max_layer, layer; if ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) && ((clear_flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) && @@ -409,102 +438,109 @@ util_clear_depth_stencil(struct pipe_context *pipe, assert(dst->texture); if (!dst->texture) return; - dst_map = pipe_transfer_map(pipe, - dst->texture, - dst->u.tex.level, - dst->u.tex.first_layer, - (need_rmw ? PIPE_TRANSFER_READ_WRITE : - PIPE_TRANSFER_WRITE), - dstx, dsty, width, height, &dst_trans); + + max_layer = dst->u.tex.last_layer - dst->u.tex.first_layer; + dst_map = pipe_transfer_map_3d(pipe, + dst->texture, + dst->u.tex.level, + (need_rmw ? PIPE_TRANSFER_READ_WRITE : + PIPE_TRANSFER_WRITE), + dstx, dsty, dst->u.tex.first_layer, + width, height, max_layer + 1, &dst_trans); assert(dst_map); if (dst_map) { unsigned dst_stride = dst_trans->stride; - uint64_t zstencil = util_pack64_z_stencil(format, - depth, stencil); + uint64_t zstencil = util_pack64_z_stencil(format, depth, stencil); + ubyte *dst_layer = dst_map; unsigned i, j; assert(dst_trans->stride > 0); - switch (util_format_get_blocksize(format)) { - case 1: - assert(format == PIPE_FORMAT_S8_UINT); - if(dst_stride == width) - memset(dst_map, (uint8_t) zstencil, height * width); - else { - for (i = 0; i < height; i++) { - memset(dst_map, (uint8_t) zstencil, width); - dst_map += dst_stride; - } - } - break; - case 2: - assert(format == PIPE_FORMAT_Z16_UNORM); - for (i = 0; i < height; i++) { - uint16_t *row = (uint16_t *)dst_map; - for (j = 0; j < width; j++) - *row++ = (uint16_t) zstencil; - dst_map += dst_stride; + for (layer = 0; layer <= max_layer; layer++) { + dst_map = dst_layer; + + switch (util_format_get_blocksize(format)) { + case 1: + assert(format == PIPE_FORMAT_S8_UINT); + if(dst_stride == width) + memset(dst_map, (uint8_t) zstencil, height * width); + else { + for (i = 0; i < height; i++) { + memset(dst_map, (uint8_t) zstencil, width); + dst_map += dst_stride; + } } - break; - case 4: - if (!need_rmw) { + break; + case 2: + assert(format == PIPE_FORMAT_Z16_UNORM); for (i = 0; i < height; i++) { - uint32_t *row = (uint32_t *)dst_map; + uint16_t *row = (uint16_t *)dst_map; for (j = 0; j < width; j++) - *row++ = (uint32_t) zstencil; + *row++ = (uint16_t) zstencil; dst_map += dst_stride; + } + break; + case 4: + if (!need_rmw) { + for (i = 0; i < height; i++) { + uint32_t *row = (uint32_t *)dst_map; + for (j = 0; j < width; j++) + *row++ = (uint32_t) zstencil; + dst_map += dst_stride; + } } - } - else { - uint32_t dst_mask; - if (format == PIPE_FORMAT_Z24_UNORM_S8_UINT) - dst_mask = 0x00ffffff; else { - assert(format == PIPE_FORMAT_S8_UINT_Z24_UNORM); - dst_mask = 0xffffff00; - } - if (clear_flags & PIPE_CLEAR_DEPTH) - dst_mask = ~dst_mask; - for (i = 0; i < height; i++) { - uint32_t *row = (uint32_t *)dst_map; - for (j = 0; j < width; j++) { - uint32_t tmp = *row & dst_mask; - *row++ = tmp | ((uint32_t) zstencil & ~dst_mask); + uint32_t dst_mask; + if (format == PIPE_FORMAT_Z24_UNORM_S8_UINT) + dst_mask = 0x00ffffff; + else { + assert(format == PIPE_FORMAT_S8_UINT_Z24_UNORM); + dst_mask = 0xffffff00; + } + if (clear_flags & PIPE_CLEAR_DEPTH) + dst_mask = ~dst_mask; + for (i = 0; i < height; i++) { + uint32_t *row = (uint32_t *)dst_map; + for (j = 0; j < width; j++) { + uint32_t tmp = *row & dst_mask; + *row++ = tmp | ((uint32_t) zstencil & ~dst_mask); + } + dst_map += dst_stride; } - dst_map += dst_stride; } - } - break; - case 8: - if (!need_rmw) { - for (i = 0; i < height; i++) { - uint64_t *row = (uint64_t *)dst_map; - for (j = 0; j < width; j++) - *row++ = zstencil; - dst_map += dst_stride; + break; + case 8: + if (!need_rmw) { + for (i = 0; i < height; i++) { + uint64_t *row = (uint64_t *)dst_map; + for (j = 0; j < width; j++) + *row++ = zstencil; + dst_map += dst_stride; + } } - } - else { - uint64_t src_mask; - - if (clear_flags & PIPE_CLEAR_DEPTH) - src_mask = 0x00000000ffffffffull; - else - src_mask = 0x000000ff00000000ull; - - for (i = 0; i < height; i++) { - uint64_t *row = (uint64_t *)dst_map; - for (j = 0; j < width; j++) { - uint64_t tmp = *row & ~src_mask; - *row++ = tmp | (zstencil & src_mask); + else { + uint64_t src_mask; + + if (clear_flags & PIPE_CLEAR_DEPTH) + src_mask = 0x00000000ffffffffull; + else + src_mask = 0x000000ff00000000ull; + + for (i = 0; i < height; i++) { + uint64_t *row = (uint64_t *)dst_map; + for (j = 0; j < width; j++) { + uint64_t tmp = *row & ~src_mask; + *row++ = tmp | (zstencil & src_mask); + } + dst_map += dst_stride; } - dst_map += dst_stride; } + break; + default: + assert(0); + break; } - break; - default: - assert(0); - break; + dst_layer += dst_trans->layer_stride; } pipe->transfer_unmap(pipe, dst_trans); @@ -512,30 +548,6 @@ util_clear_depth_stencil(struct pipe_context *pipe, } -/* Return whether this is an RGBA, Z, S, or combined ZS format. - */ -static unsigned -get_format_mask(enum pipe_format format) -{ - const struct util_format_description *desc = util_format_description(format); - - assert(desc); - - if (util_format_has_depth(desc)) { - if (util_format_has_stencil(desc)) { - return PIPE_MASK_ZS; - } else { - return PIPE_MASK_Z; - } - } else { - if (util_format_has_stencil(desc)) { - return PIPE_MASK_S; - } else { - return PIPE_MASK_RGBA; - } - } -} - /* Return if the box is totally inside the resource. */ static boolean @@ -618,7 +630,7 @@ boolean util_try_blit_via_copy_region(struct pipe_context *ctx, const struct pipe_blit_info *blit) { - unsigned mask = get_format_mask(blit->dst.format); + unsigned mask = util_format_get_mask(blit->dst.format); /* No format conversions. */ if (blit->src.resource->format != blit->src.format || diff --git a/mesalib/src/gallium/auxiliary/util/u_surface.h b/mesalib/src/gallium/auxiliary/util/u_surface.h index d6184acbd..bfd8f40d1 100644 --- a/mesalib/src/gallium/auxiliary/util/u_surface.h +++ b/mesalib/src/gallium/auxiliary/util/u_surface.h @@ -65,6 +65,13 @@ util_fill_rect(ubyte * dst, enum pipe_format format, unsigned dst_stride, unsigned dst_x, unsigned dst_y, unsigned width, unsigned height, union util_color *uc); +extern void +util_fill_box(ubyte * dst, enum pipe_format format, + unsigned stride, unsigned layer_stride, + unsigned x, unsigned y, unsigned z, + unsigned width, unsigned height, unsigned depth, + union util_color *uc); + extern void util_resource_copy_region(struct pipe_context *pipe, diff --git a/mesalib/src/gallium/auxiliary/util/u_transfer.c b/mesalib/src/gallium/auxiliary/util/u_transfer.c index 56e059bfd..7804f2a82 100644 --- a/mesalib/src/gallium/auxiliary/util/u_transfer.c +++ b/mesalib/src/gallium/auxiliary/util/u_transfer.c @@ -25,6 +25,7 @@ void u_default_transfer_inline_write( struct pipe_context *pipe, usage |= PIPE_TRANSFER_WRITE; /* transfer_inline_write implicitly discards the rewritten buffer range */ + /* XXX this looks very broken for non-buffer resources having more than one dim. */ if (box->x == 0 && box->width == resource->width0) { usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE; } else { diff --git a/mesalib/src/gallium/auxiliary/util/u_vbuf.c b/mesalib/src/gallium/auxiliary/util/u_vbuf.c index 244b04d2a..5936f74a0 100644 --- a/mesalib/src/gallium/auxiliary/util/u_vbuf.c +++ b/mesalib/src/gallium/auxiliary/util/u_vbuf.c @@ -307,6 +307,9 @@ void u_vbuf_destroy(struct u_vbuf *mgr) unsigned num_vb = screen->get_shader_param(screen, PIPE_SHADER_VERTEX, PIPE_SHADER_CAP_MAX_INPUTS); + mgr->pipe->set_index_buffer(mgr->pipe, NULL); + pipe_resource_reference(&mgr->index_buffer.buffer, NULL); + mgr->pipe->set_vertex_buffers(mgr->pipe, 0, num_vb, NULL); for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { |