From c65a76db85492f2a80ece3f3214236357e8c66ca Mon Sep 17 00:00:00 2001 From: Paulo Zanoni Date: Tue, 9 Jul 2024 12:56:16 -0700 Subject: [PATCH] anv/trtt: don't just crash when we can't find device->trtt.queue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Please refer to the big comment this patch introduces. Reviewed-by: José Roberto de Souza Signed-off-by: Paulo Zanoni Part-of: --- src/intel/vulkan/anv_sparse.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/intel/vulkan/anv_sparse.c b/src/intel/vulkan/anv_sparse.c index c899a1f2b16..de31331b5a3 100644 --- a/src/intel/vulkan/anv_sparse.c +++ b/src/intel/vulkan/anv_sparse.c @@ -624,8 +624,34 @@ anv_sparse_bind_trtt(struct anv_device *device, VkResult result; /* TR-TT submission needs a queue even when the API entry point doesn't - * give one, such as resource creation. */ - assert(trtt->queue != NULL); + * provide one, such as resource creation. We pick this queue from the user + * created queues at init_device_state() under anv_CreateDevice. + * + * It is technically possible for the user to create sparse resources even + * when they don't have a sparse queue: they won't be able to bind the + * resource but they should still be able to use the resource and rely on + * its unbound behavior. We haven't spotted any real world application or + * even test suite that exercises this behavior. + * + * For now let's just print an error message and return, which means that + * resource creation will succeed but the behavior will be undefined if the + * resource is used, which goes against our claim that we support the + * sparseResidencyNonResidentStrict property. + * + * TODO: be fully spec-compliant here. Maybe have a device-internal queue + * independent of the application's queues for the TR-TT operations. + */ + if (!trtt->queue) { + static bool warned = false; + if (unlikely(!warned)) { + fprintf(stderr, "FIXME: application has created a sparse resource " + "but no queues capable of binding sparse resources were " + "created. Using these resources will result in undefined " + "behavior.\n"); + warned = true; + } + return VK_SUCCESS; + } if (!sparse_submit->queue) sparse_submit->queue = trtt->queue;