summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/draw/draw_llvm.h
diff options
context:
space:
mode:
authorZack Rusin <zackr@vmware.com>2013-12-18 19:16:07 -0500
committerZack Rusin <zackr@vmware.com>2014-01-16 16:33:57 -0500
commit93b953d139112bea1c9c64a3de462cbb52c544fd (patch)
treeffb9b2c3867a9b396c361645aab66f3786cb5d37 /src/gallium/auxiliary/draw/draw_llvm.h
parentdd687fb8d090f08d09ac5e350a92f38ded837788 (diff)
downloadmesa-93b953d139112bea1c9c64a3de462cbb52c544fd.tar.gz
llvmpipe: do constant buffer bounds checking in shaders
It's possible to bind a smaller buffer as a constant buffer, than what the shader actually uses/requires. This could cause nasty crashes. This patch adds the architecture to pass the maximum allowable constant buffer index to the jit to let it make sure that the constant buffer indices are always within bounds. The behavior follows the d3d10 spec, which says the overflow should always return all zeros, and overflow is only defined as access beyond the size of the currently bound buffer. Accesses beyond the declared shader constant register size are not considered an overflow and expected to return garbage but consistent garbage (we follow the behavior which some wlk tests expect which is to return the actual values from the bound buffer). Signed-off-by: Zack Rusin <zackr@vmware.com> Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Diffstat (limited to 'src/gallium/auxiliary/draw/draw_llvm.h')
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.h32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index 1d238a2a9c2..2e465b2239c 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -123,6 +123,7 @@ enum {
struct draw_jit_context
{
const float *vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
+ int num_vs_constants[LP_MAX_TGSI_CONST_BUFFERS];
float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
float *viewport;
@@ -131,17 +132,21 @@ struct draw_jit_context
};
enum {
- DRAW_JIT_CTX_CONSTANTS = 0,
- DRAW_JIT_CTX_PLANES = 1,
- DRAW_JIT_CTX_VIEWPORT = 2,
- DRAW_JIT_CTX_TEXTURES = 3,
- DRAW_JIT_CTX_SAMPLERS = 4,
+ DRAW_JIT_CTX_CONSTANTS = 0,
+ DRAW_JIT_CTX_NUM_CONSTANTS = 1,
+ DRAW_JIT_CTX_PLANES = 2,
+ DRAW_JIT_CTX_VIEWPORT = 3,
+ DRAW_JIT_CTX_TEXTURES = 4,
+ DRAW_JIT_CTX_SAMPLERS = 5,
DRAW_JIT_CTX_NUM_FIELDS
};
#define draw_jit_context_vs_constants(_gallivm, _ptr) \
lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_CONSTANTS, "vs_constants")
+#define draw_jit_context_num_vs_constants(_gallivm, _ptr) \
+ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_NUM_CONSTANTS, "num_vs_constants")
+
#define draw_jit_context_planes(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, DRAW_JIT_CTX_PLANES, "planes")
@@ -200,6 +205,7 @@ enum {
struct draw_gs_jit_context
{
const float *constants[LP_MAX_TGSI_CONST_BUFFERS];
+ int num_constants[LP_MAX_TGSI_CONST_BUFFERS];
float (*planes) [DRAW_TOTAL_CLIP_PLANES][4];
float *viewport;
@@ -215,23 +221,27 @@ struct draw_gs_jit_context
enum {
DRAW_GS_JIT_CTX_CONSTANTS = 0,
- DRAW_GS_JIT_CTX_PLANES = 1,
- DRAW_GS_JIT_CTX_VIEWPORT = 2,
+ DRAW_GS_JIT_CTX_NUM_CONSTANTS = 1,
+ DRAW_GS_JIT_CTX_PLANES = 2,
+ DRAW_GS_JIT_CTX_VIEWPORT = 3,
/* Textures and samples are reserved for DRAW_JIT_CTX_TEXTURES
* and DRAW_JIT_CTX_SAMPLERS, because they both need
* to be at exactly the same locations as they are in the
* VS ctx structure for sampling to work. */
DRAW_GS_JIT_CTX_TEXTURES = DRAW_JIT_CTX_TEXTURES,
DRAW_GS_JIT_CTX_SAMPLERS = DRAW_JIT_CTX_SAMPLERS,
- DRAW_GS_JIT_CTX_PRIM_LENGTHS = 5,
- DRAW_GS_JIT_CTX_EMITTED_VERTICES = 6,
- DRAW_GS_JIT_CTX_EMITTED_PRIMS = 7,
- DRAW_GS_JIT_CTX_NUM_FIELDS = 8
+ DRAW_GS_JIT_CTX_PRIM_LENGTHS = 6,
+ DRAW_GS_JIT_CTX_EMITTED_VERTICES = 7,
+ DRAW_GS_JIT_CTX_EMITTED_PRIMS = 8,
+ DRAW_GS_JIT_CTX_NUM_FIELDS = 9
};
#define draw_gs_jit_context_constants(_gallivm, _ptr) \
lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_CONSTANTS, "constants")
+#define draw_gs_jit_context_num_constants(_gallivm, _ptr) \
+ lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_GS_JIT_CTX_NUM_CONSTANTS, "num_constants")
+
#define draw_gs_jit_context_planes(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, DRAW_GS_JIT_CTX_PLANES, "planes")