aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-11-21 08:06:12 +0100
committermarha <marha@users.sourceforge.net>2011-11-21 08:06:12 +0100
commit45710577f374972946a8eb37833a9c94e5a299bf (patch)
tree83862aa10e13033fe715c36f673f6e82c5434934 /mesalib/src
parent1037d56ca89d503cfd62830a90e934a2806ad804 (diff)
downloadvcxsrv-45710577f374972946a8eb37833a9c94e5a299bf.tar.gz
vcxsrv-45710577f374972946a8eb37833a9c94e5a299bf.tar.bz2
vcxsrv-45710577f374972946a8eb37833a9c94e5a299bf.zip
xserver xkeyboard-config mesa git update 21 nov 2011
Diffstat (limited to 'mesalib/src')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.c290
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.h9
-rw-r--r--mesalib/src/glsl/ir_clone.cpp1
-rw-r--r--mesalib/src/glsl/linker.cpp52
-rw-r--r--mesalib/src/mesa/main/fbobject.c10
-rw-r--r--mesalib/src/mesa/main/mtypes.h3
-rw-r--r--mesalib/src/mesa/main/readpix.c49
-rw-r--r--mesalib/src/mesa/main/texgetimage.c9
-rw-r--r--mesalib/src/mesa/main/teximage.c9
-rw-r--r--mesalib/src/mesa/main/teximage.h10
-rw-r--r--mesalib/src/mesa/program/ir_to_mesa.cpp29
-rw-r--r--mesalib/src/mesa/state_tracker/st_draw.c246
-rw-r--r--mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp23
13 files changed, 515 insertions, 225 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.c b/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.c
index ca4f795f0..7e36018a0 100644
--- a/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.c
+++ b/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.c
@@ -50,21 +50,39 @@ struct u_vbuf_elements {
* - src_format != native_format, as discussed above.
* - src_offset % 4 != 0 (if the caps don't allow such an offset). */
boolean incompatible_layout;
+ /* Per-element flags. */
+ boolean incompatible_layout_elem[PIPE_MAX_ATTRIBS];
};
struct u_vbuf_priv {
struct u_vbuf_mgr b;
struct pipe_context *pipe;
-
struct translate_cache *translate_cache;
- unsigned translate_vb_slot;
+ /* Whether there is any user buffer. */
+ boolean any_user_vbs;
+
+ /* Vertex element state bound by the state tracker. */
+ void *saved_ve;
+ /* and its associated helper structure for this module. */
struct u_vbuf_elements *ve;
- void *saved_ve, *fallback_ve;
+
+ /* Vertex elements used for the translate fallback. */
+ struct pipe_vertex_element fallback_velems[PIPE_MAX_ATTRIBS];
+ /* If non-NULL, this is a vertex element state used for the translate
+ * fallback and therefore used for rendering too. */
+ void *fallback_ve;
+ /* The vertex buffer slot index where translated vertices have been
+ * stored in. */
+ unsigned translate_vb_slot;
+ /* When binding the fallback vertex element state, we don't want to
+ * change saved_ve and ve. This is set to TRUE in such cases. */
boolean ve_binding_lock;
- boolean any_user_vbs;
+ /* Whether there is a buffer with a non-native layout. */
boolean incompatible_vb_layout;
+ /* Per-buffer flags. */
+ boolean incompatible_vb[PIPE_MAX_ATTRIBS];
};
static void u_vbuf_init_format_caps(struct u_vbuf_priv *mgr)
@@ -107,6 +125,7 @@ u_vbuf_create(struct pipe_context *pipe,
mgr->pipe = pipe;
mgr->translate_cache = translate_cache_create();
+ mgr->translate_vb_slot = ~0;
mgr->b.uploader = u_upload_create(pipe, upload_buffer_size,
upload_buffer_alignment,
@@ -151,27 +170,21 @@ u_vbuf_translate_begin(struct u_vbuf_priv *mgr,
struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {0};
struct pipe_resource *out_buffer = NULL;
unsigned i, num_verts, out_offset;
- struct pipe_vertex_element new_velems[PIPE_MAX_ATTRIBS];
boolean upload_flushed = FALSE;
memset(&key, 0, sizeof(key));
memset(tr_elem_index, 0xff, sizeof(tr_elem_index));
/* Initialize the translate key, i.e. the recipe how vertices should be
- * translated. */
+ * translated. */
memset(&key, 0, sizeof key);
for (i = 0; i < mgr->ve->count; i++) {
- struct pipe_vertex_buffer *vb =
- &mgr->b.vertex_buffer[mgr->ve->ve[i].vertex_buffer_index];
enum pipe_format output_format = mgr->ve->native_format[i];
unsigned output_format_size = mgr->ve->native_format_size[i];
/* Check for support. */
- if (mgr->ve->ve[i].src_format == mgr->ve->native_format[i] &&
- (mgr->b.caps.fetch_dword_unaligned ||
- (vb->buffer_offset % 4 == 0 &&
- vb->stride % 4 == 0 &&
- mgr->ve->ve[i].src_offset % 4 == 0))) {
+ if (!mgr->ve->incompatible_layout_elem[i] &&
+ !mgr->incompatible_vb[mgr->ve->ve[i].vertex_buffer_index]) {
continue;
}
@@ -274,19 +287,19 @@ u_vbuf_translate_begin(struct u_vbuf_priv *mgr,
for (i = 0; i < mgr->ve->count; i++) {
if (tr_elem_index[i] < key.nr_elements) {
te = &key.element[tr_elem_index[i]];
- new_velems[i].instance_divisor = mgr->ve->ve[i].instance_divisor;
- new_velems[i].src_format = te->output_format;
- new_velems[i].src_offset = te->output_offset;
- new_velems[i].vertex_buffer_index = mgr->translate_vb_slot;
+ mgr->fallback_velems[i].instance_divisor = mgr->ve->ve[i].instance_divisor;
+ mgr->fallback_velems[i].src_format = te->output_format;
+ mgr->fallback_velems[i].src_offset = te->output_offset;
+ mgr->fallback_velems[i].vertex_buffer_index = mgr->translate_vb_slot;
} else {
- memcpy(&new_velems[i], &mgr->ve->ve[i],
+ memcpy(&mgr->fallback_velems[i], &mgr->ve->ve[i],
sizeof(struct pipe_vertex_element));
}
}
mgr->fallback_ve =
mgr->pipe->create_vertex_elements_state(mgr->pipe, mgr->ve->count,
- new_velems);
+ mgr->fallback_velems);
/* Preserve saved_ve. */
mgr->ve_binding_lock = TRUE;
@@ -312,6 +325,7 @@ static void u_vbuf_translate_end(struct u_vbuf_priv *mgr)
/* Delete the now-unused VBO. */
pipe_resource_reference(&mgr->b.real_vertex_buffer[mgr->translate_vb_slot].buffer,
NULL);
+ mgr->translate_vb_slot = ~0;
mgr->b.nr_real_vertex_buffers = mgr->b.nr_vertex_buffers;
}
@@ -406,10 +420,12 @@ u_vbuf_create_vertex_elements(struct u_vbuf_mgr *mgrb,
ve->native_format_size[i] =
util_format_get_blocksize(ve->native_format[i]);
- ve->incompatible_layout =
- ve->incompatible_layout ||
+ ve->incompatible_layout_elem[i] =
ve->ve[i].src_format != ve->native_format[i] ||
(!mgr->b.caps.fetch_dword_unaligned && ve->ve[i].src_offset % 4 != 0);
+ ve->incompatible_layout =
+ ve->incompatible_layout ||
+ ve->incompatible_layout_elem[i];
}
/* Align the formats to the size of DWORD if needed. */
@@ -453,6 +469,7 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgrb,
mgr->any_user_vbs = FALSE;
mgr->incompatible_vb_layout = FALSE;
+ memset(mgr->incompatible_vb, 0, sizeof(mgr->incompatible_vb));
if (!mgr->b.caps.fetch_dword_unaligned) {
/* Check if the strides and offsets are aligned to the size of DWORD. */
@@ -461,7 +478,7 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgrb,
if (bufs[i].stride % 4 != 0 ||
bufs[i].buffer_offset % 4 != 0) {
mgr->incompatible_vb_layout = TRUE;
- break;
+ mgr->incompatible_vb[i] = TRUE;
}
}
}
@@ -503,6 +520,19 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgrb,
mgr->b.nr_real_vertex_buffers = count;
}
+void u_vbuf_set_index_buffer(struct u_vbuf_mgr *mgr,
+ const struct pipe_index_buffer *ib)
+{
+ if (ib && ib->buffer) {
+ assert(ib->offset % ib->index_size == 0);
+ pipe_resource_reference(&mgr->index_buffer.buffer, ib->buffer);
+ mgr->index_buffer.offset = ib->offset;
+ mgr->index_buffer.index_size = ib->index_size;
+ } else {
+ pipe_resource_reference(&mgr->index_buffer.buffer, NULL);
+ }
+}
+
static void
u_vbuf_upload_buffers(struct u_vbuf_priv *mgr,
int min_index, int max_index,
@@ -512,16 +542,23 @@ u_vbuf_upload_buffers(struct u_vbuf_priv *mgr,
unsigned count = max_index + 1 - min_index;
unsigned nr_velems = mgr->ve->count;
unsigned nr_vbufs = mgr->b.nr_vertex_buffers;
+ struct pipe_vertex_element *velems =
+ mgr->fallback_ve ? mgr->fallback_velems : mgr->ve->ve;
unsigned start_offset[PIPE_MAX_ATTRIBS];
unsigned end_offset[PIPE_MAX_ATTRIBS] = {0};
/* Determine how much data needs to be uploaded. */
for (i = 0; i < nr_velems; i++) {
- struct pipe_vertex_element *velem = &mgr->ve->ve[i];
+ struct pipe_vertex_element *velem = &velems[i];
unsigned index = velem->vertex_buffer_index;
struct pipe_vertex_buffer *vb = &mgr->b.vertex_buffer[index];
unsigned instance_div, first, size;
+ /* Skip the buffer generated by translate. */
+ if (index == mgr->translate_vb_slot) {
+ continue;
+ }
+
assert(vb->buffer);
if (!u_vbuf_resource(vb->buffer)->user_ptr) {
@@ -580,43 +617,182 @@ u_vbuf_upload_buffers(struct u_vbuf_priv *mgr,
}
}
-static void u_vbuf_compute_max_index(struct u_vbuf_priv *mgr)
+unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf_mgr *mgrb)
{
+ struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb;
unsigned i, nr = mgr->ve->count;
-
- mgr->b.max_index = ~0;
+ struct pipe_vertex_element *velems =
+ mgr->fallback_ve ? mgr->fallback_velems : mgr->ve->ve;
+ unsigned result = ~0;
for (i = 0; i < nr; i++) {
struct pipe_vertex_buffer *vb =
- &mgr->b.vertex_buffer[mgr->ve->ve[i].vertex_buffer_index];
- unsigned max_index, src_size, unused;
+ &mgr->b.real_vertex_buffer[velems[i].vertex_buffer_index];
+ unsigned size, max_count, value;
+ /* We're not interested in constant and per-instance attribs. */
if (!vb->buffer ||
!vb->stride ||
- u_vbuf_resource(vb->buffer)->user_ptr ||
- mgr->ve->ve[i].instance_divisor) {
+ velems[i].instance_divisor) {
continue;
}
- src_size = mgr->ve->ve[i].src_offset + mgr->ve->src_format_size[i];
+ size = vb->buffer->width0;
- /* If src_offset is greater than stride (which means it's a buffer
- * offset rather than a vertex offset)... */
- if (src_size >= vb->stride) {
- unused = 0;
- } else {
- /* How many bytes is unused after the last vertex.
- * width0 may be "count*stride - unused" and we have to compensate
- * for that when dividing by stride. */
- unused = vb->stride - src_size;
+ /* Subtract buffer_offset. */
+ value = vb->buffer_offset;
+ if (value >= size) {
+ return 0;
+ }
+ size -= value;
+
+ /* Subtract src_offset. */
+ value = velems[i].src_offset;
+ if (value >= size) {
+ return 0;
+ }
+ size -= value;
+
+ /* Subtract format_size. */
+ value = mgr->ve->native_format_size[i];
+ if (value >= size) {
+ return 0;
+ }
+ size -= value;
+
+ /* Compute the max count. */
+ max_count = 1 + size / vb->stride;
+ result = MIN2(result, max_count);
+ }
+ return result;
+}
+
+static boolean u_vbuf_need_minmax_index(struct u_vbuf_priv *mgr)
+{
+ unsigned i, nr = mgr->ve->count;
+
+ for (i = 0; i < nr; i++) {
+ struct pipe_vertex_buffer *vb;
+ unsigned index;
+
+ /* Per-instance attribs don't need min/max_index. */
+ if (mgr->ve->ve[i].instance_divisor) {
+ continue;
+ }
+
+ index = mgr->ve->ve[i].vertex_buffer_index;
+ vb = &mgr->b.vertex_buffer[index];
+
+ /* Constant attribs don't need min/max_index. */
+ if (!vb->stride) {
+ continue;
}
- /* Compute the maximum index for this vertex element. */
- max_index =
- (vb->buffer->width0 - vb->buffer_offset + (unsigned)unused) /
- vb->stride - 1;
+ /* Per-vertex attribs need min/max_index. */
+ if (u_vbuf_resource(vb->buffer)->user_ptr ||
+ mgr->ve->incompatible_layout_elem[i] ||
+ mgr->incompatible_vb[index]) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static void u_vbuf_get_minmax_index(struct pipe_context *pipe,
+ struct pipe_index_buffer *ib,
+ const struct pipe_draw_info *info,
+ int *out_min_index,
+ int *out_max_index)
+{
+ struct pipe_transfer *transfer = NULL;
+ const void *indices;
+ unsigned i;
+ unsigned restart_index = info->restart_index;
+
+ if (u_vbuf_resource(ib->buffer)->user_ptr) {
+ indices = u_vbuf_resource(ib->buffer)->user_ptr +
+ ib->offset + info->start * ib->index_size;
+ } else {
+ indices = pipe_buffer_map_range(pipe, ib->buffer,
+ ib->offset + info->start * ib->index_size,
+ info->count * ib->index_size,
+ PIPE_TRANSFER_READ, &transfer);
+ }
+
+ switch (ib->index_size) {
+ case 4: {
+ const unsigned *ui_indices = (const unsigned*)indices;
+ unsigned max_ui = 0;
+ unsigned min_ui = ~0U;
+ if (info->primitive_restart) {
+ for (i = 0; i < info->count; i++) {
+ if (ui_indices[i] != restart_index) {
+ if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
+ if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < info->count; i++) {
+ if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
+ if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
+ }
+ }
+ *out_min_index = min_ui;
+ *out_max_index = max_ui;
+ break;
+ }
+ case 2: {
+ const unsigned short *us_indices = (const unsigned short*)indices;
+ unsigned max_us = 0;
+ unsigned min_us = ~0U;
+ if (info->primitive_restart) {
+ for (i = 0; i < info->count; i++) {
+ if (us_indices[i] != restart_index) {
+ if (us_indices[i] > max_us) max_us = us_indices[i];
+ if (us_indices[i] < min_us) min_us = us_indices[i];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < info->count; i++) {
+ if (us_indices[i] > max_us) max_us = us_indices[i];
+ if (us_indices[i] < min_us) min_us = us_indices[i];
+ }
+ }
+ *out_min_index = min_us;
+ *out_max_index = max_us;
+ break;
+ }
+ case 1: {
+ const unsigned char *ub_indices = (const unsigned char*)indices;
+ unsigned max_ub = 0;
+ unsigned min_ub = ~0U;
+ if (info->primitive_restart) {
+ for (i = 0; i < info->count; i++) {
+ if (ub_indices[i] != restart_index) {
+ if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
+ if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
+ }
+ }
+ }
+ else {
+ for (i = 0; i < info->count; i++) {
+ if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
+ if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
+ }
+ }
+ *out_min_index = min_ub;
+ *out_max_index = max_ub;
+ break;
+ }
+ default:
+ assert(0);
+ }
- mgr->b.max_index = MIN2(mgr->b.max_index, max_index);
+ if (transfer) {
+ pipe_buffer_unmap(pipe, transfer);
}
}
@@ -627,17 +803,25 @@ u_vbuf_draw_begin(struct u_vbuf_mgr *mgrb,
struct u_vbuf_priv *mgr = (struct u_vbuf_priv*)mgrb;
int min_index, max_index;
- u_vbuf_compute_max_index(mgr);
+ if (!mgr->incompatible_vb_layout &&
+ !mgr->ve->incompatible_layout &&
+ !mgr->any_user_vbs) {
+ return 0;
+ }
if (info->indexed) {
- min_index = info->min_index;
- if (info->max_index == ~0) {
- max_index = mgr->b.max_index;
+ if (info->max_index != ~0) {
+ min_index = info->min_index + info->index_bias;
+ max_index = info->max_index + info->index_bias;
+ } else if (u_vbuf_need_minmax_index(mgr)) {
+ u_vbuf_get_minmax_index(mgr->pipe, &mgr->b.index_buffer, info,
+ &min_index, &max_index);
+ min_index += info->index_bias;
+ max_index += info->index_bias;
} else {
- max_index = MIN2(info->max_index, mgr->b.max_index);
+ min_index = 0;
+ max_index = 0;
}
- min_index += info->index_bias;
- max_index += info->index_bias;
} else {
min_index = info->start;
max_index = info->start + info->count - 1;
@@ -652,7 +836,7 @@ u_vbuf_draw_begin(struct u_vbuf_mgr *mgrb,
if (mgr->any_user_vbs) {
u_vbuf_upload_buffers(mgr, min_index, max_index, info->instance_count);
}
- return mgr->any_user_vbs || mgr->fallback_ve ? U_VBUF_BUFFERS_UPDATED : 0;
+ return U_VBUF_BUFFERS_UPDATED;
}
void u_vbuf_draw_end(struct u_vbuf_mgr *mgrb)
diff --git a/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.h b/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.h
index d854e4449..42ca0ac35 100644
--- a/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.h
+++ b/mesalib/src/gallium/auxiliary/util/u_vbuf_mgr.h
@@ -67,8 +67,8 @@ struct u_vbuf_mgr {
struct pipe_vertex_buffer real_vertex_buffer[PIPE_MAX_ATTRIBS];
int nr_real_vertex_buffers;
- /* Precomputed max_index for hardware vertex buffers. */
- unsigned max_index;
+ /* The index buffer. */
+ struct pipe_index_buffer index_buffer;
/* This uploader can optionally be used by the driver.
*
@@ -126,9 +126,14 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgr,
unsigned count,
const struct pipe_vertex_buffer *bufs);
+void u_vbuf_set_index_buffer(struct u_vbuf_mgr *mgr,
+ const struct pipe_index_buffer *ib);
+
enum u_vbuf_return_flags u_vbuf_draw_begin(struct u_vbuf_mgr *mgr,
const struct pipe_draw_info *info);
+unsigned u_vbuf_draw_max_vertex_count(struct u_vbuf_mgr *mgr);
+
void u_vbuf_draw_end(struct u_vbuf_mgr *mgr);
diff --git a/mesalib/src/glsl/ir_clone.cpp b/mesalib/src/glsl/ir_clone.cpp
index e8ac9fbe4..c63615c7e 100644
--- a/mesalib/src/glsl/ir_clone.cpp
+++ b/mesalib/src/glsl/ir_clone.cpp
@@ -51,6 +51,7 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
var->pixel_center_integer = this->pixel_center_integer;
var->explicit_location = this->explicit_location;
var->has_initializer = this->has_initializer;
+ var->depth_layout = this->depth_layout;
var->num_state_slots = this->num_state_slots;
if (this->state_slots) {
diff --git a/mesalib/src/glsl/linker.cpp b/mesalib/src/glsl/linker.cpp
index 0ec773d6c..35270881a 100644
--- a/mesalib/src/glsl/linker.cpp
+++ b/mesalib/src/glsl/linker.cpp
@@ -1876,6 +1876,57 @@ store_tfeedback_info(struct gl_context *ctx, struct gl_shader_program *prog,
}
/**
+ * Store the gl_FragDepth layout in the gl_shader_program struct.
+ */
+static void
+store_fragdepth_layout(struct gl_shader_program *prog)
+{
+ if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) {
+ return;
+ }
+
+ struct exec_list *ir = prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->ir;
+
+ /* We don't look up the gl_FragDepth symbol directly because if
+ * gl_FragDepth is not used in the shader, it's removed from the IR.
+ * However, the symbol won't be removed from the symbol table.
+ *
+ * We're only interested in the cases where the variable is NOT removed
+ * from the IR.
+ */
+ foreach_list(node, ir) {
+ ir_variable *const var = ((ir_instruction *) node)->as_variable();
+
+ if (var == NULL || var->mode != ir_var_out) {
+ continue;
+ }
+
+ if (strcmp(var->name, "gl_FragDepth") == 0) {
+ switch (var->depth_layout) {
+ case ir_depth_layout_none:
+ prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_NONE;
+ return;
+ case ir_depth_layout_any:
+ prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_ANY;
+ return;
+ case ir_depth_layout_greater:
+ prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_GREATER;
+ return;
+ case ir_depth_layout_less:
+ prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_LESS;
+ return;
+ case ir_depth_layout_unchanged:
+ prog->FragDepthLayout = FRAG_DEPTH_LAYOUT_UNCHANGED;
+ return;
+ default:
+ assert(0);
+ return;
+ }
+ }
+ }
+}
+
+/**
* Validate the resources used by a program versus the implementation limits
*/
static bool
@@ -2177,6 +2228,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
update_array_sizes(prog);
link_assign_uniform_locations(prog);
+ store_fragdepth_layout(prog);
if (!check_resources(ctx, prog))
goto done;
diff --git a/mesalib/src/mesa/main/fbobject.c b/mesalib/src/mesa/main/fbobject.c
index f8b148cee..5b329f5c3 100644
--- a/mesalib/src/mesa/main/fbobject.c
+++ b/mesalib/src/mesa/main/fbobject.c
@@ -78,14 +78,6 @@ static struct gl_renderbuffer DummyRenderbuffer;
static struct gl_framebuffer IncompleteFramebuffer;
-static inline GLboolean
-is_cube_face(GLenum target)
-{
- return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
-}
-
-
/**
* Is the given FBO a user-created FBO?
*/
@@ -2008,7 +2000,7 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
}
else {
err = (texObj->Target == GL_TEXTURE_CUBE_MAP)
- ? !is_cube_face(textarget)
+ ? !_mesa_is_cube_face(textarget)
: (texObj->Target != textarget);
}
}
diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h
index 285ec0783..b3427dac1 100644
--- a/mesalib/src/mesa/main/mtypes.h
+++ b/mesalib/src/mesa/main/mtypes.h
@@ -2218,6 +2218,9 @@ struct gl_shader_program
/** Post-link transform feedback info. */
struct gl_transform_feedback_info LinkedTransformFeedback;
+ /** Post-link gl_FragDepth layout for ARB_conservative_depth. */
+ enum gl_frag_depth_layout FragDepthLayout;
+
/** Geometry shader state - copied into gl_geometry_program at link time */
struct {
GLint VerticesOut;
diff --git a/mesalib/src/mesa/main/readpix.c b/mesalib/src/mesa/main/readpix.c
index 86b87534d..8048a7286 100644
--- a/mesalib/src/mesa/main/readpix.c
+++ b/mesalib/src/mesa/main/readpix.c
@@ -70,6 +70,11 @@ fast_read_depth_pixels( struct gl_context *ctx,
ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
&map, &stride);
+ if (!map) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return GL_TRUE; /* don't bother trying the slow path */
+ }
+
dstStride = _mesa_image_row_stride(packing, width, GL_DEPTH_COMPONENT, type);
dst = (GLubyte *) _mesa_image_address2d(packing, pixels, width, height,
GL_DEPTH_COMPONENT, type, 0, 0);
@@ -126,6 +131,10 @@ read_depth_pixels( struct gl_context *ctx,
ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
&map, &stride);
+ if (!map) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return;
+ }
/* General case (slower) */
for (j = 0; j < height; j++, y++) {
@@ -165,6 +174,10 @@ read_stencil_pixels( struct gl_context *ctx,
ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
&map, &stride);
+ if (!map) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return;
+ }
/* process image row by row */
for (j = 0; j < height; j++) {
@@ -211,6 +224,10 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
&map, &stride);
+ if (!map) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return GL_TRUE; /* don't bother trying the slow path */
+ }
texelBytes = _mesa_get_format_bytes(rb->Format);
for (j = 0; j < height; j++) {
@@ -224,7 +241,7 @@ fast_read_rgba_pixels_memcpy( struct gl_context *ctx,
return GL_TRUE;
}
-static GLboolean
+static void
slow_read_rgba_pixels( struct gl_context *ctx,
GLint x, GLint y,
GLsizei width, GLsizei height,
@@ -248,6 +265,10 @@ slow_read_rgba_pixels( struct gl_context *ctx,
ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
&map, &stride);
+ if (!map) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return;
+ }
for (j = 0; j < height; j++) {
if (_mesa_is_integer_format(format)) {
@@ -263,8 +284,6 @@ slow_read_rgba_pixels( struct gl_context *ctx,
}
ctx->Driver.UnmapRenderbuffer(ctx, rb);
-
- return GL_TRUE;
}
/*
@@ -327,6 +346,10 @@ fast_read_depth_stencil_pixels(struct gl_context *ctx,
ctx->Driver.MapRenderbuffer(ctx, rb, x, y, width, height, GL_MAP_READ_BIT,
&map, &stride);
+ if (!map) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return GL_TRUE; /* don't bother trying the slow path */
+ }
for (i = 0; i < height; i++) {
_mesa_unpack_uint_24_8_depth_stencil_row(rb->Format, width,
@@ -363,8 +386,18 @@ fast_read_depth_stencil_pixels_separate(struct gl_context *ctx,
ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height,
GL_MAP_READ_BIT, &depthMap, &depthStride);
+ if (!depthMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return GL_TRUE; /* don't bother trying the slow path */
+ }
+
ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height,
GL_MAP_READ_BIT, &stencilMap, &stencilStride);
+ if (!stencilMap) {
+ ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return GL_TRUE; /* don't bother trying the slow path */
+ }
for (j = 0; j < height; j++) {
GLubyte stencilVals[MAX_WIDTH];
@@ -407,10 +440,20 @@ slow_read_depth_stencil_pixels_separate(struct gl_context *ctx,
*/
ctx->Driver.MapRenderbuffer(ctx, depthRb, x, y, width, height,
GL_MAP_READ_BIT, &depthMap, &depthStride);
+ if (!depthMap) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return;
+ }
+
if (stencilRb != depthRb) {
ctx->Driver.MapRenderbuffer(ctx, stencilRb, x, y, width, height,
GL_MAP_READ_BIT, &stencilMap,
&stencilStride);
+ if (!stencilMap) {
+ ctx->Driver.UnmapRenderbuffer(ctx, depthRb);
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glReadPixels");
+ return;
+ }
}
else {
stencilMap = depthMap;
diff --git a/mesalib/src/mesa/main/texgetimage.c b/mesalib/src/mesa/main/texgetimage.c
index 31d49f2d8..06506594d 100644
--- a/mesalib/src/mesa/main/texgetimage.c
+++ b/mesalib/src/mesa/main/texgetimage.c
@@ -386,11 +386,10 @@ get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type,
* so we don't have to worry about those.
* XXX more format combinations could be supported here.
*/
- if ((target == GL_TEXTURE_1D ||
- target == GL_TEXTURE_2D ||
- target == GL_TEXTURE_RECTANGLE ||
- (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) {
+ if (target == GL_TEXTURE_1D ||
+ target == GL_TEXTURE_2D ||
+ target == GL_TEXTURE_RECTANGLE ||
+ _mesa_is_cube_face(target)) {
if ((texImage->TexFormat == MESA_FORMAT_ARGB8888 ||
texImage->TexFormat == MESA_FORMAT_SARGB8) &&
format == GL_BGRA &&
diff --git a/mesalib/src/mesa/main/teximage.c b/mesalib/src/mesa/main/teximage.c
index a84d6873d..c8ea4329f 100644
--- a/mesalib/src/mesa/main/teximage.c
+++ b/mesalib/src/mesa/main/teximage.c
@@ -522,8 +522,7 @@ _mesa_base_tex_format( struct gl_context *ctx, GLint internalFormat )
GLuint
_mesa_tex_target_to_face(GLenum target)
{
- if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB)
+ if (_mesa_is_cube_face(target))
return (GLuint) target - (GLuint) GL_TEXTURE_CUBE_MAP_POSITIVE_X;
else
return 0;
@@ -3094,8 +3093,7 @@ compressed_texture_error_check(struct gl_context *ctx, GLint dimensions,
}
/* For cube map, width must equal height */
- if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB && width != height) {
+ if (_mesa_is_cube_face(target) && width != height) {
*reason = "width != height";
return GL_INVALID_VALUE;
}
@@ -3183,8 +3181,7 @@ compressed_subtexture_error_check(struct gl_context *ctx, GLint dimensions,
return GL_INVALID_ENUM; /*target*/
maxLevels = ctx->Const.MaxCubeTextureLevels;
}
- else if (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
- target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB) {
+ else if (_mesa_is_cube_face(target)) {
if (!ctx->Extensions.ARB_texture_cube_map)
return GL_INVALID_ENUM; /*target*/
maxLevels = ctx->Const.MaxCubeTextureLevels;
diff --git a/mesalib/src/mesa/main/teximage.h b/mesalib/src/mesa/main/teximage.h
index fd315bea3..9cc7d5a54 100644
--- a/mesalib/src/mesa/main/teximage.h
+++ b/mesalib/src/mesa/main/teximage.h
@@ -36,6 +36,16 @@
#include "formats.h"
+/** Is the given value one of the 6 cube faces? */
+static inline GLboolean
+_mesa_is_cube_face(GLenum target)
+{
+ return (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB &&
+ target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB);
+}
+
+
+
/** \name Internal functions */
/*@{*/
diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp
index 5cee83778..5a68fc51d 100644
--- a/mesalib/src/mesa/program/ir_to_mesa.cpp
+++ b/mesalib/src/mesa/program/ir_to_mesa.cpp
@@ -685,29 +685,6 @@ ir_to_mesa_visitor::visit(ir_variable *ir)
fp->OriginUpperLeft = ir->origin_upper_left;
fp->PixelCenterInteger = ir->pixel_center_integer;
-
- } else if (strcmp(ir->name, "gl_FragDepth") == 0) {
- struct gl_fragment_program *fp = (struct gl_fragment_program *)this->prog;
- switch (ir->depth_layout) {
- case ir_depth_layout_none:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_NONE;
- break;
- case ir_depth_layout_any:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_ANY;
- break;
- case ir_depth_layout_greater:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_GREATER;
- break;
- case ir_depth_layout_less:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_LESS;
- break;
- case ir_depth_layout_unchanged:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_UNCHANGED;
- break;
- default:
- assert(0);
- break;
- }
}
if (ir->mode == ir_var_uniform && strncmp(ir->name, "gl_", 3) == 0) {
@@ -3222,6 +3199,12 @@ get_mesa_program(struct gl_context *ctx,
do_set_program_inouts(shader->ir, prog, shader->Type == GL_FRAGMENT_SHADER);
count_resources(prog);
+ /* Set the gl_FragDepth layout. */
+ if (target == GL_FRAGMENT_PROGRAM_ARB) {
+ struct gl_fragment_program *fp = (struct gl_fragment_program *)prog;
+ fp->FragDepthLayout = shader_program->FragDepthLayout;
+ }
+
_mesa_reference_program(ctx, &shader->Program, prog);
if ((ctx->Shader.Flags & GLSL_NO_OPT) == 0) {
diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c
index cb518e1af..05a71d35c 100644
--- a/mesalib/src/mesa/state_tracker/st_draw.c
+++ b/mesalib/src/mesa/state_tracker/st_draw.c
@@ -648,45 +648,108 @@ check_uniforms(struct gl_context *ctx)
}
}
-/** Helper code for primitive restart fallback */
-#define DO_DRAW(pipe, cur_start, cur_count) \
- do { \
- info.start = cur_start; \
- info.count = cur_count; \
- if (u_trim_pipe_prim(info.mode, &info.count)) { \
- if (transfer) \
- pipe_buffer_unmap(pipe, transfer); \
- pipe->draw_vbo(pipe, &info); \
- if (transfer) { \
- ptr = pipe_buffer_map(pipe, ibuffer->buffer, PIPE_TRANSFER_READ, &transfer); \
- assert(ptr != NULL); \
- ptr = ADD_POINTERS(ptr, ibuffer->offset); \
- } \
- } \
- } while(0)
-
-/** More helper code for primitive restart fallback */
-#define PRIM_RESTART_LOOP(elements) \
- do { \
- for (i = start; i < end; i++) { \
- if (elements[i] == info.restart_index) { \
- if (cur_count > 0) { \
- /* draw elts up to prev pos */ \
- DO_DRAW(pipe, cur_start, cur_count); \
- } \
- /* begin new prim at next elt */ \
- cur_start = i + 1; \
- cur_count = 0; \
- } \
- else { \
- cur_count++; \
+
+/*
+ * Notes on primitive restart:
+ * The code below is used when the gallium driver does not support primitive
+ * restart itself. We map the index buffer, find the restart indexes, unmap
+ * the index buffer then draw the sub-primitives delineated by the restarts.
+ * A couple possible optimizations:
+ * 1. Save the list of sub-primitive (start, count) values in a list attached
+ * to the index buffer for re-use in subsequent draws. The list would be
+ * invalidated when the contents of the buffer changed.
+ * 2. If drawing triangle strips or quad strips, create a new index buffer
+ * that uses duplicated vertices to render the disjoint strips as one
+ * long strip. We'd have to be careful to avoid using too much memory
+ * for this.
+ * Finally, some apps might perform better if they don't use primitive restart
+ * at all rather than this fallback path. Set MESA_EXTENSION_OVERRIDE to
+ * "-GL_NV_primitive_restart" to test that.
+ */
+
+
+struct sub_primitive
+{
+ unsigned start, count;
+};
+
+
+/**
+ * Scan the elements array to find restart indexes. Return a list
+ * of primitive (start,count) pairs to indicate how to draw the sub-
+ * primitives delineated by the restart index.
+ */
+static struct sub_primitive *
+find_sub_primitives(const void *elements, unsigned element_size,
+ unsigned start, unsigned end, unsigned restart_index,
+ unsigned *num_sub_prims)
+{
+ const unsigned max_prims = end - start;
+ struct sub_primitive *sub_prims;
+ unsigned i, cur_start, cur_count, num;
+
+ sub_prims = (struct sub_primitive *)
+ malloc(max_prims * sizeof(struct sub_primitive));
+
+ if (!sub_prims) {
+ *num_sub_prims = 0;
+ return NULL;
+ }
+
+ cur_start = start;
+ cur_count = 0;
+ num = 0;
+
+#define SCAN_ELEMENTS(TYPE) \
+ for (i = start; i < end; i++) { \
+ if (((const TYPE *) elements)[i] == restart_index) { \
+ if (cur_count > 0) { \
+ assert(num < max_prims); \
+ sub_prims[num].start = cur_start; \
+ sub_prims[num].count = cur_count; \
+ num++; \
} \
+ cur_start = i + 1; \
+ cur_count = 0; \
} \
- if (cur_count > 0) { \
- DO_DRAW(pipe, cur_start, cur_count); \
+ else { \
+ cur_count++; \
} \
- } while (0)
+ } \
+ if (cur_count > 0) { \
+ assert(num < max_prims); \
+ sub_prims[num].start = cur_start; \
+ sub_prims[num].count = cur_count; \
+ num++; \
+ }
+
+ switch (element_size) {
+ case 1:
+ SCAN_ELEMENTS(ubyte);
+ break;
+ case 2:
+ SCAN_ELEMENTS(ushort);
+ break;
+ case 4:
+ SCAN_ELEMENTS(uint);
+ break;
+ default:
+ assert(0 && "bad index_size in find_sub_primitives()");
+ }
+
+#undef SCAN_ELEMENTS
+
+ *num_sub_prims = num;
+
+ return sub_prims;
+}
+
+/**
+ * For gallium drivers that don't support the primitive restart
+ * feature, handle it here by breaking up the indexed primitive into
+ * sub-primitives.
+ */
static void
handle_fallback_primitive_restart(struct pipe_context *pipe,
const struct _mesa_index_buffer *ib,
@@ -695,78 +758,61 @@ handle_fallback_primitive_restart(struct pipe_context *pipe,
{
const unsigned start = orig_info->start;
const unsigned count = orig_info->count;
- const unsigned end = start + count;
struct pipe_draw_info info = *orig_info;
struct pipe_transfer *transfer = NULL;
- unsigned instance, i, cur_start, cur_count;
- const void *ptr;
+ unsigned instance, i;
+ const void *ptr = NULL;
+ struct sub_primitive *sub_prims;
+ unsigned num_sub_prims;
- info.primitive_restart = FALSE;
-
- if (!info.indexed) {
- /* Splitting the draw arrays call is handled by the VBO module */
- if (u_trim_pipe_prim(info.mode, &info.count))
- pipe->draw_vbo(pipe, &info);
+ assert(info.indexed);
+ assert(ibuffer->buffer);
+ assert(ib);
+ if (!ibuffer->buffer || !ib)
return;
- }
- /* info.indexed == TRUE */
- assert(ibuffer);
- assert(ibuffer->buffer);
+ info.primitive_restart = FALSE;
+ info.instance_count = 1;
- if (ib) {
- struct gl_buffer_object *bufobj = ib->obj;
- if (bufobj && bufobj->Name) {
- ptr = NULL;
- }
- else {
- ptr = ib->ptr;
- }
- } else {
- ptr = NULL;
+ if (ib->obj && _mesa_is_bufferobj(ib->obj)) {
+ ptr = pipe_buffer_map_range(pipe, ibuffer->buffer,
+ start * ibuffer->index_size, /* start */
+ count * ibuffer->index_size, /* length */
+ PIPE_TRANSFER_READ, &transfer);
+ }
+ else {
+ ptr = ib->ptr;
}
if (!ptr)
- ptr = pipe_buffer_map(pipe, ibuffer->buffer, PIPE_TRANSFER_READ, &transfer);
+ return;
- if (!ptr)
- return;
ptr = ADD_POINTERS(ptr, ibuffer->offset);
- /* Need to loop over instances as well to preserve draw order */
+ sub_prims = find_sub_primitives(ptr, ibuffer->index_size,
+ 0, count, orig_info->restart_index,
+ &num_sub_prims);
+
+ if (transfer)
+ pipe_buffer_unmap(pipe, transfer);
+
+ /* Now draw the sub primitives.
+ * Need to loop over instances as well to preserve draw order.
+ */
for (instance = 0; instance < orig_info->instance_count; instance++) {
info.start_instance = instance + orig_info->start_instance;
- info.instance_count = 1;
- cur_start = start;
- cur_count = 0;
-
- switch (ibuffer->index_size) {
- case 1:
- {
- const ubyte *elt_ub = (const ubyte *)ptr;
- PRIM_RESTART_LOOP(elt_ub);
- }
- break;
- case 2:
- {
- const ushort *elt_us = (const ushort *)ptr;
- PRIM_RESTART_LOOP(elt_us);
- }
- break;
- case 4:
- {
- const uint *elt_ui = (const uint *)ptr;
- PRIM_RESTART_LOOP(elt_ui);
+ for (i = 0; i < num_sub_prims; i++) {
+ info.start = sub_prims[i].start;
+ info.count = sub_prims[i].count;
+ if (u_trim_pipe_prim(info.mode, &info.count)) {
+ pipe->draw_vbo(pipe, &info);
}
- break;
- default:
- assert(0 && "bad index_size in handle_fallback_primitive_restart()");
}
}
- if (transfer)
- pipe_buffer_unmap(pipe, transfer);
+ if (sub_prims)
+ free(sub_prims);
}
@@ -978,10 +1024,13 @@ st_draw_vbo(struct gl_context *ctx,
info.min_index = min_index;
info.max_index = max_index;
}
- }
- info.primitive_restart = ctx->Array.PrimitiveRestart;
- info.restart_index = ctx->Array.RestartIndex;
+ /* The VBO module handles restart for the non-indexed GLDrawArrays
+ * so we only set these fields for indexed drawing:
+ */
+ info.primitive_restart = ctx->Array.PrimitiveRestart;
+ info.restart_index = ctx->Array.RestartIndex;
+ }
/* do actual drawing */
for (i = 0; i < nr_prims; i++) {
@@ -996,19 +1045,14 @@ st_draw_vbo(struct gl_context *ctx,
}
if (info.primitive_restart) {
- /*
- * Handle primitive restart for drivers that doesn't support it.
- *
- * The VBO module handles restart inside of draw_arrays for us,
- * but we should still remove the primitive_restart flag on the
- * info struct, the fallback function does this for us. Just
- * remove the flag for all drivers in this case as well.
- */
- if (st->sw_primitive_restart || !info.indexed)
+ if (st->sw_primitive_restart) {
+ /* Handle primitive restart for drivers that doesn't support it */
handle_fallback_primitive_restart(pipe, ib, &ibuffer, &info);
- else
+ }
+ else {
/* don't trim, restarts might be inside index list */
pipe->draw_vbo(pipe, &info);
+ }
}
else if (u_trim_pipe_prim(info.mode, &info.count))
pipe->draw_vbo(pipe, &info);
diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 0bf6766f7..929c7af01 100644
--- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -1017,29 +1017,6 @@ glsl_to_tgsi_visitor::visit(ir_variable *ir)
fp->OriginUpperLeft = ir->origin_upper_left;
fp->PixelCenterInteger = ir->pixel_center_integer;
-
- } else if (strcmp(ir->name, "gl_FragDepth") == 0) {
- struct gl_fragment_program *fp = (struct gl_fragment_program *)this->prog;
- switch (ir->depth_layout) {
- case ir_depth_layout_none:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_NONE;
- break;
- case ir_depth_layout_any:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_ANY;
- break;
- case ir_depth_layout_greater:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_GREATER;
- break;
- case ir_depth_layout_less:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_LESS;
- break;
- case ir_depth_layout_unchanged:
- fp->FragDepthLayout = FRAG_DEPTH_LAYOUT_UNCHANGED;
- break;
- default:
- assert(0);
- break;
- }
}
if (ir->mode == ir_var_uniform && strncmp(ir->name, "gl_", 3) == 0) {