summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/draw/draw_vs.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2010-07-29 13:49:21 -0600
committerBrian Paul <[email protected]>2010-07-29 17:25:54 -0600
commitba2cc3b8e6ad161181b67fd2575c6bc768584d23 (patch)
treebdf82dfc3e06fd305e6161575830374a4c6101ab /src/gallium/auxiliary/draw/draw_vs.c
parent8a2933f3663177f32f5ee45bb696463b8549dcbb (diff)
gallium: implement bounds checking for constant buffers
Plumb the constant buffer sizes down into the tgsi interpreter where we can do bounds checking. Optional debug code warns upon out-of-bounds reading. Plus add a few other assertions in the TGSI interpreter.
Diffstat (limited to 'src/gallium/auxiliary/draw/draw_vs.c')
-rw-r--r--src/gallium/auxiliary/draw/draw_vs.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/gallium/auxiliary/draw/draw_vs.c b/src/gallium/auxiliary/draw/draw_vs.c
index 57ea63fc060..fb665b08fff 100644
--- a/src/gallium/auxiliary/draw/draw_vs.c
+++ b/src/gallium/auxiliary/draw/draw_vs.c
@@ -48,18 +48,30 @@
DEBUG_GET_ONCE_BOOL_OPTION(gallium_dump_vs, "GALLIUM_DUMP_VS", FALSE)
+
+/**
+ * Set a vertex shader constant buffer.
+ * \param slot which constant buffer in [0, PIPE_MAX_CONSTANT_BUFFERS-1]
+ * \param constants the mapped buffer
+ * \param size size of buffer in bytes
+ */
void
draw_vs_set_constants(struct draw_context *draw,
unsigned slot,
const void *constants,
unsigned size)
{
- if (((uintptr_t)constants) & 0xf) {
+ const int alignment = 16;
+
+ /* check if buffer is 16-byte aligned */
+ if (((uintptr_t)constants) & (alignment - 1)) {
+ /* if not, copy the constants into a new, 16-byte aligned buffer */
if (size > draw->vs.const_storage_size[slot]) {
if (draw->vs.aligned_constant_storage[slot]) {
align_free((void *)draw->vs.aligned_constant_storage[slot]);
}
- draw->vs.aligned_constant_storage[slot] = align_malloc(size, 16);
+ draw->vs.aligned_constant_storage[slot] =
+ align_malloc(size, alignment);
}
assert(constants);
memcpy((void *)draw->vs.aligned_constant_storage[slot],