Mesa (master): zink: heap-allocate samplers objects
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Oct 31 14:40:00 UTC 2019
Module: Mesa
Branch: master
Commit: 5ea787950f6e7feb0f9f3a146ae0d626bad19b63
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=5ea787950f6e7feb0f9f3a146ae0d626bad19b63
Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date: Tue Oct 29 10:07:53 2019 +0100
zink: heap-allocate samplers objects
VkSampler is 64-bit even on 32-bit systems, so casting it to a pointer
is a bad idea there. So let's heap-allocate the sampler-object instead.
Signed-off-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/2017
Reviewed-by: Witold Baryluk <witold.baryluk at gmail.com>
Tested-by: Witold Baryluk <witold.baryluk at gmail.com>
---
src/gallium/drivers/zink/zink_context.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 9219d019811..219605d90a3 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -162,11 +162,15 @@ zink_create_sampler_state(struct pipe_context *pctx,
sci.anisotropyEnable = VK_TRUE;
}
- VkSampler sampler;
- VkResult err = vkCreateSampler(screen->dev, &sci, NULL, &sampler);
- if (err != VK_SUCCESS)
+ VkSampler *sampler = CALLOC(1, sizeof(VkSampler));
+ if (!sampler)
return NULL;
+ if (vkCreateSampler(screen->dev, &sci, NULL, sampler) != VK_SUCCESS) {
+ FREE(sampler);
+ return NULL;
+ }
+
return sampler;
}
@@ -178,8 +182,10 @@ zink_bind_sampler_states(struct pipe_context *pctx,
void **samplers)
{
struct zink_context *ctx = zink_context(pctx);
- for (unsigned i = 0; i < num_samplers; ++i)
- ctx->samplers[shader][start_slot + i] = (VkSampler)samplers[i];
+ for (unsigned i = 0; i < num_samplers; ++i) {
+ VkSampler *sampler = samplers[i];
+ ctx->samplers[shader][start_slot + i] = sampler ? *sampler : VK_NULL_HANDLE;
+ }
ctx->num_samplers[shader] = start_slot + num_samplers;
}
@@ -188,8 +194,9 @@ zink_delete_sampler_state(struct pipe_context *pctx,
void *sampler_state)
{
struct zink_batch *batch = zink_curr_batch(zink_context(pctx));
- util_dynarray_append(&batch->zombie_samplers,
- VkSampler, sampler_state);
+ util_dynarray_append(&batch->zombie_samplers, VkSampler,
+ *(VkSampler *)sampler_state);
+ FREE(sampler_state);
}
More information about the mesa-commit
mailing list