From 11298dd305f6d2104ac11bb656bda71af453eb83 Mon Sep 17 00:00:00 2001 From: Jeroen Trappers Date: Wed, 2 Dec 2026 00:15:44 +0100 Subject: [PATCH 1/4] st/mesa: copy R16G16 images as UINT when R16G16_UNORM cannot be rendered glCopyImageSubData between formats blits through canonical formats, and two-channel 16-bit data takes R16G16_UNORM (for G16R16's sake). A GLES driver need not render or sample R16G16_UNORM: it is not a core GLES format. Without it util_blitter refuses the blit ("ZINK: blit unsupported") and every copy into an RG16UI, RG16I or RG16F image is lost. Copy R16G16 as R16G16_UINT then, which is bit-exact. On an iPhone 6s (Zink on the PowerVR G5P driver): the 51 GLES3.1 copy_image cases of the sample with an RG16 destination pass (5 before); the sample's other 769 non-3D copy_image cases are unchanged. Generated-by: LLM Signed-off-by: Jeroen Trappers --- src/mesa/state_tracker/st_cb_copyimage.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/mesa/state_tracker/st_cb_copyimage.c b/src/mesa/state_tracker/st_cb_copyimage.c index f821ce7932d..86ca9d11403 100644 --- a/src/mesa/state_tracker/st_cb_copyimage.c +++ b/src/mesa/state_tracker/st_cb_copyimage.c @@ -138,6 +138,14 @@ get_canonical_format(struct pipe_screen *screen, break; case 16: + /* UNORM for G16R16's sake, but a driver that cannot both render + * and sample R16G16_UNORM (a GLES driver need not: it is not a + * core format) copies R16G16 bit-exactly as UINT. + */ + if (desc->swizzle[0] == PIPE_SWIZZLE_X && desc->swizzle[1] == PIPE_SWIZZLE_Y && + !screen->is_format_supported(screen, PIPE_FORMAT_R16G16_UNORM, PIPE_TEXTURE_2D, 0, 0, + PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) + return PIPE_FORMAT_R16G16_UINT; RETURN_FOR_SWIZZLE2(X, Y, PIPE_FORMAT_R16G16_UNORM); RETURN_FOR_SWIZZLE2(Y, X, PIPE_FORMAT_G16R16_UNORM); break; From dd0da25ed7543bb3431a5ba6c3e1f0b1303d5925 Mon Sep 17 00:00:00 2001 From: Jeroen Trappers Date: Wed, 2 Dec 2026 07:26:02 +0100 Subject: [PATCH 2/4] st/mesa: at least one integer, colour and depth texture sample get_max_samples_for_formats() counts sample counts from 2, so a driver without multisampled integer formats, or without multisample textures of colour or depth formats, reported GL_MAX_INTEGER_SAMPLES, GL_MAX_COLOR_TEXTURE_SAMPLES or GL_MAX_DEPTH_TEXTURE_SAMPLES as 0. GL's minimum for each is 1 (single-sampled formats count), and ES 3.1 queries each format against it. Report 1 when the driver has multisampling at all. On an iPhone 6s (Zink on the PowerVR G5P driver): 12 more GLES3.1 cases of the sample pass (state_query.internal_format samples, sample_variables). Generated-by: LLM Signed-off-by: Jeroen Trappers --- src/mesa/state_tracker/st_extensions.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index e9a4e1ffc33..c36caa4f3e4 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -1460,6 +1460,15 @@ void st_init_extensions(struct pipe_screen *screen, get_max_samples_for_formats(screen, ARRAY_SIZE(int_formats), int_formats, consts->MaxSamples, PIPE_BIND_SAMPLER_VIEW); + /* GL's minimum is 1: a driver without multisampled integer formats + * still has single-sampled ones (ES 3.1 queries it per format) + */ + if (consts->MaxSamples && !consts->MaxIntegerSamples) + consts->MaxIntegerSamples = 1; + if (consts->MaxSamples && !consts->MaxColorTextureSamples) + consts->MaxColorTextureSamples = 1; + if (consts->MaxSamples && !consts->MaxDepthTextureSamples) + consts->MaxDepthTextureSamples = 1; /* ARB_framebuffer_no_attachments, assume max no. of samples 32 */ consts->MaxFramebufferSamples = From e408be04f52e2a6000c1a5556d1d8758ebbaf6cb Mon Sep 17 00:00:00 2001 From: Jeroen Trappers Date: Tue, 1 Dec 2026 22:15:00 +0100 Subject: [PATCH 3/4] zink: end a command buffer once submit_queue() ended each batch's command buffer inside VRAM_ALLOC_LOOP, which calls vkEndCommandBuffer() again after VK_ERROR_OUT_OF_DEVICE_MEMORY. That error is the recording's own (a draw whose pipeline the driver could not create), so the command buffer is already invalid, and ending it again is invalid usage: the Vulkan runtime asserts in vk_command_buffer_end(). Call it once and keep the error handling. On the iPhone 6s (G5P): draw_buffers_indexed and fragment_out cases with a colour set G5P refuses aborted in that assert; they now fail. Generated-by: LLM Signed-off-by: Jeroen Trappers --- src/gallium/drivers/zink/zink_batch.c | 57 +++++++++++++-------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c index 5be730ebf88..7c2e17276d5 100644 --- a/src/gallium/drivers/zink/zink_batch.c +++ b/src/gallium/drivers/zink/zink_batch.c @@ -821,17 +821,18 @@ submit_queue(void *data, void *gdata, int thread_index) const bool screen_lost = screen->device_lost && keep_promises; bool recorded = !screen_lost; if (recorded && bs->has_work) { - VRAM_ALLOC_LOOP(result, - VKSCR(EndCommandBuffer)(bs->cmdbuf), - if (result != VK_SUCCESS) { - mesa_loge("ZINK: vkEndCommandBuffer failed (%s)", vk_Result_to_str(result)); - recorded = false; - if (!keep_promises) { - bs->is_device_lost = true; - goto end; - } + /* Once, not in VRAM_ALLOC_LOOP: a failed vkEndCommandBuffer leaves the command buffer invalid (the + * error is its recording's, e.g. a pipeline the driver could not create), and ending it again is + * invalid usage that the runtime asserts on. */ + result = VKSCR(EndCommandBuffer)(bs->cmdbuf); + if (result != VK_SUCCESS) { + mesa_loge("ZINK: vkEndCommandBuffer failed (%s)", vk_Result_to_str(result)); + recorded = false; + if (!keep_promises) { + bs->is_device_lost = true; + goto end; } - ); + } } if (recorded && bs->has_reordered_work) { VkMemoryBarrier mb; @@ -846,30 +847,26 @@ submit_queue(void *data, void *gdata, int thread_index) src, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 1, &mb, 0, NULL, 0, NULL); - VRAM_ALLOC_LOOP(result, - VKSCR(EndCommandBuffer)(bs->reordered_cmdbuf), - if (result != VK_SUCCESS) { - mesa_loge("ZINK: vkEndCommandBuffer failed (%s)", vk_Result_to_str(result)); - recorded = false; - if (!keep_promises) { - bs->is_device_lost = true; - goto end; - } + result = VKSCR(EndCommandBuffer)(bs->reordered_cmdbuf); /* once: see above */ + if (result != VK_SUCCESS) { + mesa_loge("ZINK: vkEndCommandBuffer failed (%s)", vk_Result_to_str(result)); + recorded = false; + if (!keep_promises) { + bs->is_device_lost = true; + goto end; } - ); + } } if (recorded && bs->has_unsync) { - VRAM_ALLOC_LOOP(result, - VKSCR(EndCommandBuffer)(bs->unsynchronized_cmdbuf), - if (result != VK_SUCCESS) { - mesa_loge("ZINK: vkEndCommandBuffer failed (%s)", vk_Result_to_str(result)); - recorded = false; - if (!keep_promises) { - bs->is_device_lost = true; - goto end; - } + result = VKSCR(EndCommandBuffer)(bs->unsynchronized_cmdbuf); /* once: see above */ + if (result != VK_SUCCESS) { + mesa_loge("ZINK: vkEndCommandBuffer failed (%s)", vk_Result_to_str(result)); + recorded = false; + if (!keep_promises) { + bs->is_device_lost = true; + goto end; } - ); + } } if (!recorded) { /* the batch that lost the screen reports it (post_submit); later ones only keep their promises */ From fa77e27d37a99ceda654955d66bfa9face533748 Mon Sep 17 00:00:00 2001 From: Jeroen Trappers Date: Tue, 1 Dec 2026 22:26:42 +0100 Subject: [PATCH 4/4] zink: a batch whose recording failed does not lose the context When vkEndCommandBuffer() reports the recording's error (a render or draw the driver refused, on G5P an attachment set it does not render), the batch is submitted without its command buffers so that its semaphores are still signalled, and the context was marked lost. Every later draw of that context then failed: under the CTS, the rest of the test process. Drop that batch's work only. The device is not lost and neither is the context's other work; a real device loss still reports as before. On an iPhone 6s (S8003), the iPhone 6's sample lists: - GLES3 sample: 3278 -> 4247 passes (75.9 % -> 96.7 % of supported); the 1801-2700 slice alone 476 -> 855. - GLES3.1 sample: 1776 -> 2191 passes (61.1 % -> 75.4 %), with the narrow integer colour targets of the commit before. Most of the cases this turns into passes had nothing refused: they ran after a refused case in the same process. Generated-by: LLM Signed-off-by: Jeroen Trappers --- src/gallium/drivers/zink/zink_batch.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/zink/zink_batch.c b/src/gallium/drivers/zink/zink_batch.c index 7c2e17276d5..07a5c26785f 100644 --- a/src/gallium/drivers/zink/zink_batch.c +++ b/src/gallium/drivers/zink/zink_batch.c @@ -869,12 +869,13 @@ submit_queue(void *data, void *gdata, int thread_index) } } if (!recorded) { - /* the batch that lost the screen reports it (post_submit); later ones only keep their promises */ - if (!screen_lost) { - mesa_loge("ZINK: batch %" PRIu64 " dropped: its semaphores are signalled without its command buffers; " - "the context is lost", batch_id); - bs->is_device_lost = true; - } + /* The batch that lost the screen reports it (post_submit); later ones only keep their promises. A batch + * whose recording failed (vkEndCommandBuffer's error: a render or draw the driver refused) is dropped + * without losing the context: its work is missing, the device and the context's other work are not, + * and losing the context would fail everything after it. */ + if (!screen_lost) + mesa_loge("ZINK: batch %" PRIu64 " dropped: its recording failed; its semaphores are signalled " + "without its command buffers", batch_id); si[ZINK_SUBMIT_CMDBUF].commandBufferCount = 0; }