summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/llvmpipe
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2019-12-30 09:59:28 +1000
committerMarge Bot <eric+marge@anholt.net>2020-07-23 00:04:49 +0000
commit12c06a0deb632728f76ceb480e86151b8f96100e (patch)
tree07e412b3250df2a0310ae28727b32f705633c55a /src/gallium/drivers/llvmpipe
parentf0c3a258003ea8655bc05a0a0febf93ffb1a0736 (diff)
llvmpipe/draw: handle constant buffer limits and robustness (v1.1)
TGSI expect vec4 of constants for it's current code paths, and when doing indirect accesses it does the comparison on vec4 indexes, however NIR does the indexing on packed float indexes. This also align the compute path with the other shaders, and should improve robustness (at least under Vulkan) Fixes: KHR-NoContext.gl43.robust_buffer_access_behavior.uniform_buffer v1.1: rename variable to something more meaningful (Roland) Reviewed-by: Roland Scheidegger <sroland@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5971>
Diffstat (limited to 'src/gallium/drivers/llvmpipe')
-rw-r--r--src/gallium/drivers/llvmpipe/lp_context.c4
-rw-r--r--src/gallium/drivers/llvmpipe/lp_screen.h6
-rw-r--r--src/gallium/drivers/llvmpipe/lp_setup.c4
-rw-r--r--src/gallium/drivers/llvmpipe/lp_state_cs.c12
4 files changed, 18 insertions, 8 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_context.c b/src/gallium/drivers/llvmpipe/lp_context.c
index 58073f3a7f6..05dc33ef4e2 100644
--- a/src/gallium/drivers/llvmpipe/lp_context.c
+++ b/src/gallium/drivers/llvmpipe/lp_context.c
@@ -47,6 +47,7 @@
#include "lp_query.h"
#include "lp_setup.h"
#include "lp_screen.h"
+
/* This is only safe if there's just one concurrent context */
#ifdef EMBEDDED_DEVICE
#define USE_GLOBAL_LLVM_CONTEXT
@@ -222,6 +223,9 @@ llvmpipe_create_context(struct pipe_screen *screen, void *priv,
llvmpipe_screen(screen),
lp_draw_disk_cache_find_shader,
lp_draw_disk_cache_insert_shader);
+
+ draw_set_constant_buffer_stride(llvmpipe->draw, lp_get_constant_buffer_stride(screen));
+
/* FIXME: devise alternative to draw_texture_samplers */
llvmpipe->setup = lp_setup_create( &llvmpipe->pipe,
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.h b/src/gallium/drivers/llvmpipe/lp_screen.h
index 88f87f9dcbd..6b3798e4d7a 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.h
+++ b/src/gallium/drivers/llvmpipe/lp_screen.h
@@ -82,6 +82,10 @@ llvmpipe_screen( struct pipe_screen *pipe )
return (struct llvmpipe_screen *)pipe;
}
-
+static inline unsigned lp_get_constant_buffer_stride(struct pipe_screen *_screen)
+{
+ struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
+ return screen->use_tgsi ? (sizeof(float) * 4) : sizeof(float);
+}
#endif /* LP_SCREEN_H */
diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c
index a3e2a7ed7e4..550062ffcfc 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup.c
@@ -1201,7 +1201,7 @@ try_update_scene_state( struct lp_setup_context *setup )
current_data = (ubyte *) setup->constants[i].current.user_buffer;
}
- if (current_data) {
+ if (current_data && current_size >= sizeof(float)) {
current_data += setup->constants[i].current.buffer_offset;
/* TODO: copy only the actually used constants? */
@@ -1235,7 +1235,7 @@ try_update_scene_state( struct lp_setup_context *setup )
}
num_constants =
- DIV_ROUND_UP(setup->constants[i].stored_size, (sizeof(float) * 4));
+ DIV_ROUND_UP(setup->constants[i].stored_size, lp_get_constant_buffer_stride(scene->pipe->screen));
setup->fs.current.jit_context.num_constants[i] = num_constants;
setup->dirty |= LP_SETUP_NEW_FS;
}
diff --git a/src/gallium/drivers/llvmpipe/lp_state_cs.c b/src/gallium/drivers/llvmpipe/lp_state_cs.c
index dcdd9b36240..be6d648cd53 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_cs.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_cs.c
@@ -1161,7 +1161,7 @@ update_csctx_consts(struct llvmpipe_context *llvmpipe)
for (i = 0; i < ARRAY_SIZE(csctx->constants); ++i) {
struct pipe_resource *buffer = csctx->constants[i].current.buffer;
const ubyte *current_data = NULL;
-
+ unsigned current_size = csctx->constants[i].current.buffer_size;
if (buffer) {
/* resource buffer */
current_data = (ubyte *) llvmpipe_resource_data(buffer);
@@ -1171,13 +1171,15 @@ update_csctx_consts(struct llvmpipe_context *llvmpipe)
current_data = (ubyte *) csctx->constants[i].current.user_buffer;
}
- if (current_data) {
+ if (current_data && current_size >= sizeof(float)) {
current_data += csctx->constants[i].current.buffer_offset;
-
csctx->cs.current.jit_context.constants[i] = (const float *)current_data;
- csctx->cs.current.jit_context.num_constants[i] = csctx->constants[i].current.buffer_size;
+ csctx->cs.current.jit_context.num_constants[i] =
+ DIV_ROUND_UP(csctx->constants[i].current.buffer_size,
+ lp_get_constant_buffer_stride(llvmpipe->pipe.screen));
} else {
- csctx->cs.current.jit_context.constants[i] = NULL;
+ static const float fake_const_buf[4];
+ csctx->cs.current.jit_context.constants[i] = fake_const_buf;
csctx->cs.current.jit_context.num_constants[i] = 0;
}
}