platform/upstream/mesa.git
4 years agov3dv/formats: fix exposing FEATURE_UNIFORM/STORAGE_TEXEL_BUFFER_BIT
Alejandro Piñeiro [Sun, 2 Aug 2020 00:23:16 +0000 (02:23 +0200)]
v3dv/formats: fix exposing FEATURE_UNIFORM/STORAGE_TEXEL_BUFFER_BIT

If the formats are not suitable as texture type, then they can't be
used as texel buffers.

Gets tests like the following one:
   dEQP-VK.image.load_store.without_format.buffer.r32g32b32_sfloat_minalign_uniform

to be properly skipped (instead of Crash on the simulator)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle multisample image clears
Iago Toral Quiroga [Fri, 31 Jul 2020 16:25:06 +0000 (18:25 +0200)]
v3dv: handle multisample image clears

Fixes:
dEQP-VK.pipeline.framebuffer_attachment.*_ms

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle multisample resolves for formats that don't support TLB resolves
Iago Toral Quiroga [Fri, 31 Jul 2020 12:58:42 +0000 (14:58 +0200)]
v3dv: handle multisample resolves for formats that don't support TLB resolves

The TLB multisample resolve feature is only limited to specific format types.
For everything else, including sfloat and integer formats, we need to
fallback to a blit resolve. This needs to be handled both for in-pass
resolves as well as for vkCmdResolveImage.

Because these blits would happen after the tile store operations, we need
to make sure we store the multisampled buffers so we can then read them for
the blit resolve.

Fixes the remaining test failures in:
dEQP-VK.renderpass.suballocation.multisample_resolve.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle multisample resolve of integer formats
Iago Toral Quiroga [Fri, 31 Jul 2020 12:59:09 +0000 (14:59 +0200)]
v3dv: handle multisample resolve of integer formats

The multisample resolve of an integer framebuffer should just take one
of the samples instead of averaging.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix blitting of signed integer formats
Iago Toral Quiroga [Fri, 31 Jul 2020 12:52:58 +0000 (14:52 +0200)]
v3dv: fix blitting of signed integer formats

For these we want to select a signed integer output format
and a signed sampler type.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agonir/glsl: add a glsl_ivec4_type() helper
Iago Toral Quiroga [Fri, 31 Jul 2020 12:50:57 +0000 (14:50 +0200)]
nir/glsl: add a glsl_ivec4_type() helper

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: amend tile size tables with smallest tile sizes available
Iago Toral Quiroga [Fri, 31 Jul 2020 07:26:06 +0000 (09:26 +0200)]
v3dv: amend tile size tables with smallest tile sizes available

We'll need this for some cases involving maximum number of multisampled
color targets.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/device: fix minTexelBufferOffsetAlingment
Alejandro Piñeiro [Thu, 30 Jul 2020 12:35:43 +0000 (14:35 +0200)]
v3dv/device: fix minTexelBufferOffsetAlingment

As we understand that texture accesses should be aligned to the UIF
block size.

Fixes several of the CTS tests under this pattern:
  dEQP-VK.binding_model.shader_access.primary_cmd_buf.uniform_texel_buffer.*.offset_nonzero
  dEQP-VK.binding_model.shader_access.primary_cmd_buf.storage_texel_buffer.*.offset_nonzero

Note: for those tests, using a lower value (64) was enough to get them
working, but again, we understand that the real alignment is the UIF
block size.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: add v3dv_limits file
Alejandro Piñeiro [Thu, 30 Jul 2020 12:32:26 +0000 (14:32 +0200)]
v3dv: add v3dv_limits file

There are several definitions for hw limits on v3dv_image that we want
to share, but v3dv_private was already growing bigger and messier.

So let's move them to a specific header. Note that there is already a
broadcom/common/v3d_limits.h. We are not putting them there because
right now they are only used by the Vulkan driver, but are candidates
to be moved.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/descriptor: support for UNIFORM/STORAGE_TEXEL_BUFFER
Alejandro Piñeiro [Tue, 28 Jul 2020 22:28:28 +0000 (00:28 +0200)]
v3dv/descriptor: support for UNIFORM/STORAGE_TEXEL_BUFFER

This gets passing most uniform/storage_texel buffer tests.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agobroadcom/compiler: handle gl_SampleMask writes in fragment shaders
Iago Toral Quiroga [Thu, 30 Jul 2020 09:29:12 +0000 (11:29 +0200)]
broadcom/compiler: handle gl_SampleMask writes in fragment shaders

We didn't need this until now, since this was included with GLES 3.2,
but we need it for Vulkan.

Eric had already done the plumbing for it though, we just need to
actually emit the mask.

Fixes some tests in:
dEQP-VK.renderpass.suballocation.multisample_resolve.*

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle multisampled image copies with the blit path
Iago Toral Quiroga [Thu, 30 Jul 2020 07:00:07 +0000 (09:00 +0200)]
v3dv: handle multisampled image copies with the blit path

This should be able to handle partial copies of multisampled images.

This change extends our blit shader interface to also handle multisampled
destinations so that if the blit destination is a multisampled image,
the blit will rely on sample rate shading to copy all samples from
the source image (which must have a matching number of samples).

I have not found any tests in CTS that do partial copies of
multisampled images, so I tested this with a full multisampled image
copy, using this test:
dEQP-VK.api.copy_and_blit.core.resolve_image.whole_copy_before_resolving.4_bit

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: add a blit fallback path for vkCmdResolveImage
Iago Toral Quiroga [Wed, 29 Jul 2020 07:49:47 +0000 (09:49 +0200)]
v3dv: add a blit fallback path for vkCmdResolveImage

This fallback is required when we have to do partial resolves. It
works the same way as other blit fallbacks for copy operations: it
will bind the source image as a source texture and blit the selected
region to the destination image.

The difference in this case is that the source image is multisampled
and the blit shader needs to fetch and average individual samples for
each texel.

This gets us to pass all the remaining test cases in
dEQP-VK.api.copy_and_blit.core.resolve_image.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: setup texture shader state correctly for multisampled images
Iago Toral Quiroga [Wed, 29 Jul 2020 07:49:08 +0000 (09:49 +0200)]
v3dv: setup texture shader state correctly for multisampled images

Fixes multisampled cases in:
dEQP-VK.pipeline.multisample.sampled_image.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle multisampled image copies in the TLB path
Iago Toral Quiroga [Tue, 28 Jul 2020 08:33:17 +0000 (10:33 +0200)]
v3dv: handle multisampled image copies in the TLB path

vkCmdCopyImage can be used to copy multisampled images. We can
easily support that on the TLB path, which copies full images.

For partial copies we will need to amend our blit shader path
to support multisampling resolve.

Fixes:
dEQP-VK.api.copy_and_blit.core.resolve_image.whole_copy_before_resolving.4_bit

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: implement vkCmdResolveImage for whole images
Iago Toral Quiroga [Tue, 28 Jul 2020 08:50:01 +0000 (10:50 +0200)]
v3dv: implement vkCmdResolveImage for whole images

For partial resolves we will need a shader blit & resolve fallback.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: implement subpass multisample rendering and resolve
Iago Toral Quiroga [Tue, 28 Jul 2020 06:53:19 +0000 (08:53 +0200)]
v3dv: implement subpass multisample rendering and resolve

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: process VkPipelineMultisampleStateCreateInfo properly
Iago Toral Quiroga [Fri, 24 Jul 2020 08:42:43 +0000 (10:42 +0200)]
v3dv: process VkPipelineMultisampleStateCreateInfo properly

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: consider MSAA when computing frame tiling
Iago Toral Quiroga [Fri, 24 Jul 2020 08:33:16 +0000 (10:33 +0200)]
v3dv: consider MSAA when computing frame tiling

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: handle properly OUT_OF_HOST_MEMORY error when allocating p_stage
Alejandro Piñeiro [Sun, 26 Jul 2020 23:51:36 +0000 (01:51 +0200)]
v3dv/pipeline: handle properly OUT_OF_HOST_MEMORY error when allocating p_stage

So far we were just assuming that it would work (so we could try to
access a NULL pointer), and not freeing it properly.

Fixing that was somewhat messy due pipeline_compile_graphics using a
temporary array and then update the internal pipeline stages. As we
are here we just removed the array and simplified
pipeline_compile_graphics code.

Fixes following tests:
  dEQP-VK.api.object_management.alloc_callback_fail.graphics_pipeline
  dEQP-VK.api.object_management.alloc_callback_fail_multiple.graphics_pipeline

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: pre-generate more that one shader variant
Alejandro Piñeiro [Sat, 25 Jul 2020 10:44:22 +0000 (12:44 +0200)]
v3dv/pipeline: pre-generate more that one shader variant

In order to reduce the number of shader builds after pipeline creation
(that ideally shouldn't happen) we pre-generate two shader variants at
pipeline creation time. In addition to the default one, that set the
return size for all texture to 16 bit, we build another variant
setting the return size for all textures to 32-bit. cmd buffer selects
the latter if any of the textures requires 32bit.

So we are using an all 16-bit return size or an all 32-bit return size
variants. This could be slightly improved by pre-generating return
size combinations if the texture number is below a threshold. But that
would require more space, and bigger pipeline creation time, so would
need to be evaluated.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: when looking for a variant, check first current variant
Alejandro Piñeiro [Fri, 24 Jul 2020 22:11:51 +0000 (00:11 +0200)]
v3dv/pipeline: when looking for a variant, check first current variant

So far, when checking for a variant fulfilling a specific v3d key, we
were checking the caches, and if that failed, we compiled a new
variant, and update the current variant.

But we could check first if the current variant fullfils that. This
was not really problematic so far, as checking on the caches was fast,
but now that we could be without any kind of shader cache using
V3DV_ENABLE_PIPELINE_CACHE, it is far better to check first current
variant.

Without this vkQuake3 at 720p drops to 1fps when disabling the cache.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: remove custom variant cache
Alejandro Piñeiro [Fri, 24 Jul 2020 13:47:23 +0000 (15:47 +0200)]
v3dv/pipeline: remove custom variant cache

Now that we have a default pipeline cache, we can rely on it. This
allows to remove some code, and avoid the need to have a cache per
each pipeline stage.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline_cache: add default pipeline cache
Alejandro Piñeiro [Wed, 22 Jul 2020 00:08:06 +0000 (02:08 +0200)]
v3dv/pipeline_cache: add default pipeline cache

That it would be used as fallback. Three advantages:

  * Having a cache for user operations even if the user doesn't
    provide it.

  * Having a cache for internal operations. v3dv_meta_copy creates
    pipelines for some copy path, so it is interesting to have them
    cached.

  * Testing: so now the pipeline cache is tested by more CTS tests.

As any other pipeline cache, it can be disabled with the
V3DV_ENABLE_PIPELINE_CACHE. It was suggested that would make sense to
have a specific envvar for the default pipeline cache, but for now
just one envvar is enough.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: provide a shader_sha1 to private ShaderModules
Alejandro Piñeiro [Thu, 23 Jul 2020 09:18:11 +0000 (11:18 +0200)]
v3dv/pipeline: provide a shader_sha1 to private ShaderModules

So far for private pipelines we were creating dummy shader modules
where we directly provided the nir shader. But for the pipeline cache
we were using the SPIR-V to generate part of the cache key sha1.

The main use case for private pipelines are meta_copy/clear. Those nir
shaders depend on parameters like the format etc, so we use directly
the serialized form of the NIR shader to generate the sha1.

The other case are the no-op fragment shader that we need to provide
if no fragment shader is defined by the user. For that case we can
just use the default shader name, as the no-op shader is always the
same.

This is required as we plan to add a default pipeline cache, that
would include our private shaders too.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline_cache: MergePipelineCaches implementation
Alejandro Piñeiro [Tue, 21 Jul 2020 22:51:19 +0000 (00:51 +0200)]
v3dv/pipeline_cache: MergePipelineCaches implementation

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline_cache: support to serialize/deserialize cached NIRs
Alejandro Piñeiro [Tue, 21 Jul 2020 21:26:26 +0000 (23:26 +0200)]
v3dv/pipeline_cache: support to serialize/deserialize cached NIRs

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline_cache: cache v3dv_shader_variants
Alejandro Piñeiro [Thu, 16 Jul 2020 10:41:11 +0000 (12:41 +0200)]
v3dv/pipeline_cache: cache v3dv_shader_variants

This also includes being able to serialize them as part of
GetPipelineCacheData and to deserialize it as part of
CreatePipelineCache.

So now we can also upload the assembly of the variant as part of the
PipelineCache creation.

Note that from all this the tricky part was the prog_data
serialization. v3d_compile allocates and fill a new prog_data, with
rzalloc. Among other things because it also allocates internally the
uniform list. So we needed to replicate that when deserializating the
prog_data. Ideally we would like to avoid that, and allocate as much
resources as possible using vk_alloc, but that would mean a somewhat
deep change on the v3d_compiler, that we want to avoid as much
possible for now.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: add basic ref counting support for variants
Alejandro Piñeiro [Sat, 18 Jul 2020 00:40:00 +0000 (02:40 +0200)]
v3dv/pipeline: add basic ref counting support for variants

As soon as we start to cache variants on pipeline caches, the same
variant could be used by different pipelines and pipeline caches.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline_cache: cache nir shaders
Alejandro Piñeiro [Tue, 7 Jul 2020 13:56:44 +0000 (15:56 +0200)]
v3dv/pipeline_cache: cache nir shaders

Heavily based on anv nir caching. One of the bigger difference is that
we don't create the nir shader using a ralloc_context local to the
main compile graphics method. On anv, after compiling the shader, they
discard the nir shader. We need it as we could need it to build shader
variants later.

As anv, we introduce a environment variable to disable the cache:
  V3DV_ENABLE_PIPELINE_CACHE

By default is enabled. The main purpose for this envvar is debugging,
in order to provide a easy way to discard a bug on the cache.

It is pending to serialize/deserialize the NIR shaders as part of
GetPipelineCacheData and PipelineCacheCreate. We also plan is to cache
too shader variants. We would do that on following patches.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline_cache: bare basic support for pipeline cache
Alejandro Piñeiro [Sat, 4 Jul 2020 11:10:49 +0000 (13:10 +0200)]
v3dv/pipeline_cache: bare basic support for pipeline cache

And this means providing a proper cache object, and being able to
load/retrieve a cache data with a proper header. Not really caching
anything yet. That would be tackle on following patches.

Note that this no-op cache got all the specific pipeline_cache and
pipeline.cache tests passing on the rpi4.

The following tests are still crashing when using the simulator:
 dEQP-VK.synchronization.internally_synchronized_objects.pipeline_cache_compute
 dEQP-VK.synchronization.internally_synchronized_objects.pipeline_cache_graphics

But those are an issue of synchronization tests on the simulator, and
not related with the pipeline cache itself. In general synchronization
tests should be tested on the rpi4.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/device: proper pipeline cache uuid
Alejandro Piñeiro [Sat, 4 Jul 2020 11:09:58 +0000 (13:09 +0200)]
v3dv/device: proper pipeline cache uuid

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/device: get proper device ID under simulator
Alejandro Piñeiro [Tue, 7 Jul 2020 10:23:12 +0000 (12:23 +0200)]
v3dv/device: get proper device ID under simulator

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/device: add vendorID/deviceID get helpers
Alejandro Piñeiro [Fri, 3 Jul 2020 23:32:11 +0000 (01:32 +0200)]
v3dv/device: add vendorID/deviceID get helpers

As we would need them for the pipeline cache header.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix dynamic state after meta operation
Iago Toral Quiroga [Thu, 23 Jul 2020 10:45:41 +0000 (12:45 +0200)]
v3dv: fix dynamic state after meta operation

We should always save state on a push before starting a meta operation,
even if we don't have a pipeline, since dynamic state can be set at any
time directly on the command buffer. Similarly, we should always restore
it if the pop after the meta operation signals that it has written any
state, not only if we have a graphics pipeline to restore.

Fixes a rendering artifact in VkQuake.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: enable fillModeNonSolid
Iago Toral Quiroga [Wed, 22 Jul 2020 08:12:51 +0000 (10:12 +0200)]
v3dv: enable fillModeNonSolid

This, together with the shaderClipDistance changes, gets vkQuake3
to run without hacks.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: enable shaderClipDistance
Iago Toral Quiroga [Tue, 21 Jul 2020 08:29:21 +0000 (10:29 +0200)]
v3dv: enable shaderClipDistance

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: add a fast path for vkCmdClearAttachments
Iago Toral Quiroga [Thu, 16 Jul 2020 10:34:30 +0000 (12:34 +0200)]
v3dv: add a fast path for vkCmdClearAttachments

Since vkCmdClearAttachments executes inside a render pass, we would
benefit from converting it to a draw within the current subpass job to
improve batching and avoid expensive tile load/store operations.

This can dramatically improve performance for applications using this
command, however, we can only use this if we are clearing the base
layers of framebuffer attachments, since otherwise we would need to
use layered rendering, which we don't support yet.

This improves vkQuake3 performance dramatically (almost 100%
performance improvement at 1080p), which calls this twice per frame.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: only clear depth/stencil attachments if any aspect needs clearing
Iago Toral Quiroga [Fri, 17 Jul 2020 08:30:35 +0000 (10:30 +0200)]
v3dv: only clear depth/stencil attachments if any aspect needs clearing

When we can't perform the clears using the TLB and fallback to
vkCmdClearAttachments make sure we only emit the clear if any of
the depth/stencil aspects actually needs it.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: emit new shader state if viewport is dirty
Iago Toral Quiroga [Fri, 17 Jul 2020 10:28:46 +0000 (12:28 +0200)]
v3dv: emit new shader state if viewport is dirty

If we have a dirty viewport then we need to re-emit our uniforms
to update QUNIFORM_VIEWPORT_*.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: only care about barriers between GPU jobs
Iago Toral Quiroga [Thu, 16 Jul 2020 07:25:18 +0000 (09:25 +0200)]
v3dv: only care about barriers between GPU jobs

We don't need to do anything special for host/gpu synchronization.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: avoid prime blit path when presenting WSI images
Iago Toral Quiroga [Wed, 15 Jul 2020 07:31:39 +0000 (09:31 +0200)]
v3dv: avoid prime blit path when presenting WSI images

This allows us to present WSI images directly rather than going through
a blit path, improving performance.

This improves vkQuake performance at 1080p by 10-20%.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: only use per-buffer clear bit for cases were we are already storing
Iago Toral Quiroga [Tue, 14 Jul 2020 09:29:12 +0000 (11:29 +0200)]
v3dv: only use per-buffer clear bit for cases were we are already storing

This bit is helpful if we already need to store the buffer, but otherwise
we should not emit the store only to get the clear, we can use the global
clear packet for that and save us an expensive tile buffer store operation.

Also, we have not been using the per-buffer clear bit for depth/stencil
stores since "v3dv: fix depth/stencil clears on hardware", so we should
never been considering clearing needs to flag stores.

This improves vkQuake performance somewhere between 5%-15% by allowing
us to skip the store of the depth attachment.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: ignore stencil load operation if attachment format doesn't have stencil
Iago Toral Quiroga [Fri, 10 Jul 2020 07:50:57 +0000 (09:50 +0200)]
v3dv: ignore stencil load operation if attachment format doesn't have stencil

This gets vkQuake to render correctly, which creates render passes with
stencil load operations even when the depth/stencil attachment format
doesn't have a stencil aspect. While this is a bit weird, it seems to
be allowed by the spec:

   "If the format has depth and/or stencil components, loadOp and storeOp
    apply only to the depth data, while stencilLoadOp and stencilStoreOp
    define how the stencil data is handled."

In our case we were not ignoring it and this was causing that we emitted a
Z buffer load that seemed to clobber the Z clear, preventing all draw calls
from passing the depth test.

While we are at it, also change the depth/stencil store operation (which
was already handling this scenario correctly) to use the format of the
render pass attachment description rather than the underlying image
format.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: use a binning sync for CL jobs waiting on a semaphore
Iago Toral Quiroga [Thu, 9 Jul 2020 06:47:59 +0000 (08:47 +0200)]
v3dv: use a binning sync for CL jobs waiting on a semaphore

If we have a semaphore wait the job cannot be started before the semaphore
has been signaled, so we need to wait before starting the binning stage.

Fixes CTS failures in:
dEQP-VK.synchronization.op.single_queue.binary_semaphore.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: improve pipeline barrier handling
Iago Toral Quiroga [Wed, 8 Jul 2020 07:56:44 +0000 (09:56 +0200)]
v3dv: improve pipeline barrier handling

So far we have been getting away with finishing the current job in the
presence of a pipeline barrier and relying on the RCL serialization,
but of course this is not always enough.

This patch  addresses synchronization across different GPU units
(i.e. draw indirect after compute), as well as cases where we need to
sync before binning.

Fixes CTS failures in:
dEQP-VK.synchronization.op.single_queue.barrier.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: don't support sRGB buffer formats
Iago Toral Quiroga [Tue, 7 Jul 2020 11:10:44 +0000 (13:10 +0200)]
v3dv: don't support sRGB buffer formats

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle VK_FORMAT_B8G8R8A8_UNORM vertex attributes
Iago Toral Quiroga [Mon, 6 Jul 2020 09:44:00 +0000 (11:44 +0200)]
v3dv: handle VK_FORMAT_B8G8R8A8_UNORM vertex attributes

This is the only mandatory vertex attribute format that requires a
swizzle.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3d/compiler: support swapping R/B channels in vertex attributes.
Iago Toral Quiroga [Tue, 7 Jul 2020 09:10:57 +0000 (11:10 +0200)]
v3d/compiler: support swapping R/B channels in vertex attributes.

We will need this in Vulkan to support vertex format
VK_FORMAT_B8G8R8A8_UNORM.  The hardware doesn't allow to swizzle
vertex attribute components, so we need to do it in the shader.

v2:
 - Use nir_intrinsic_io_semantics() to retrieve the location instead
   of looping through the shader input variables (Eric).
 - Assert that we only have one component (Eric).

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com> (v1)
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: make sure we emit vertex attributes in location order
Iago Toral Quiroga [Tue, 7 Jul 2020 06:22:31 +0000 (08:22 +0200)]
v3dv: make sure we emit vertex attributes in location order

The order in which we emit the attributes is relevant, since
GL_SHADER_STATE_ATTRIBUTE_RECORD packets don't include an explicit
attribute index. This means that we need to emit them in driver
location order, since the compiler uses that location to compute
attribute offsets in the VPM.

Fixes ~1300 CTS tests in:
dEQP-VK.pipeline.vertex_input.multiple_attributes.out_of_order.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/device: handle primary nodes for newer kernels
n00b7 [Fri, 3 Jul 2020 08:46:51 +0000 (10:46 +0200)]
v3dv/device: handle primary nodes for newer kernels

For kernels rpi-5.X.y it changed from brcm,bcm2835-vc4 to
brcm,bcm2711-vc5, so let's just check for both strings.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix color border clamping with specific formats
Iago Toral Quiroga [Fri, 3 Jul 2020 08:06:28 +0000 (10:06 +0200)]
v3dv: fix color border clamping with specific formats

For some reason, CTS expects E5B9G9R9 and B10G11R11 with
transparent black border clamping produce alpha 1 instead of 0.

Since border color takes precedence over the texture state swizzle,
the only way to fix this is to lower the texture swizzle in the shader
to set alpha to 1.

Fixes:
dEQP-VK.pipeline.sampler.view_type.*b10g11r11*clamp_to_border_transparent_black
dEQP-VK.pipeline.sampler.view_type.*e5b9g9r9*.clamp_to_border_transparent_black

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix regressions for cubemap array load/store
Iago Toral Quiroga [Thu, 2 Jul 2020 10:43:42 +0000 (12:43 +0200)]
v3dv: fix regressions for cubemap array load/store

It seems that we only want to set the texture state's depth to the
number of 2D layers divided by 6 when sampling, not wen doing
load/store.

This means that we need to generate two different states and choose
the one to use depending on the descriptor.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: use swizzle X001 with D/S formats
Iago Toral Quiroga [Thu, 2 Jul 2020 08:56:05 +0000 (10:56 +0200)]
v3dv: use swizzle X001 with D/S formats

This matches Vulkan CTS expectations.

Fixes (for D/S formats):
dEQP-VK.pipeline.sampler.view_type.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/image: fix TEXTURE_SHADER_STATE depth for cube arrays
Alejandro Piñeiro [Wed, 1 Jul 2020 15:03:28 +0000 (17:03 +0200)]
v3dv/image: fix TEXTURE_SHADER_STATE depth for cube arrays

For these we want to divide the number of layers by 6.

Fixes:
dEQP-VK.pipeline.image_view.view_type.cube_array.*
dEQP-VK.pipeline.image.suballocation.sampling_type.combined.view_type.cube_array.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle unnormalized coordinates in samplers
Iago Toral Quiroga [Wed, 1 Jul 2020 12:21:09 +0000 (14:21 +0200)]
v3dv: handle unnormalized coordinates in samplers

In OpenGL, unnormalized coordinates are implicit based on the sampler
type (rectangle textures), so the compiler can set the flag when needed.
In Vulkan, however, this is configured explicitly in the sampler object,
so the compiler won't set it and we need to do it manually when we are
writing the P1 uniform.

Fixes:
dEQP-VK.pipeline.sampler.exact_sampling.*.unnormalized_coords

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix blit_shader() to honor the region's aspect mask
Iago Toral Quiroga [Wed, 1 Jul 2020 09:05:28 +0000 (11:05 +0200)]
v3dv: fix blit_shader() to honor the region's aspect mask

When translating combined depth/stencil blits to compatible color blits we
should look at the requested region aspects to decide the color
mask to apply.

Fixes:
dEQP-VK.api.copy_and_blit.*.buffer_to_depthstencil.buffer_offset_d24_unorm_s8_uint_D
dEQP-VK.api.copy_and_blit.*.buffer_to_depthstencil.buffer_offset_d24_unorm_s8_uint_SD
dEQP-VK.api.copy_and_blit.*.buffer_to_depthstencil.buffer_offset_d24_unorm_s8_uint_S_D

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix srcSubresource description for image to buffer blits
Iago Toral Quiroga [Tue, 30 Jun 2020 11:19:01 +0000 (13:19 +0200)]
v3dv: fix srcSubresource description for image to buffer blits

We are emitting a loop copying layer by layer here.

Fixes:
dEQP-VK.pipeline.render_to_image.core.*.huge.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix textureSize() for cube arrays
Iago Toral Quiroga [Tue, 30 Jun 2020 08:44:43 +0000 (10:44 +0200)]
v3dv: fix textureSize() for cube arrays

For these we want to divide the number of layers by 6.

Fixes:
dEQP-VK.glsl.texture_functions.query.texturesize.*samplercubearray*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix vkCmdCopyBuffer unaligned TLB access
Iago Toral Quiroga [Tue, 30 Jun 2020 08:07:12 +0000 (10:07 +0200)]
v3dv: fix vkCmdCopyBuffer unaligned TLB access

We need to make sure that our tile load/store operations are aligned
to the selected item size for the copy.

Fixes simulator assert in VkQuake.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle draw after barrier
Iago Toral Quiroga [Mon, 29 Jun 2020 10:39:53 +0000 (12:39 +0200)]
v3dv: handle draw after barrier

Currently, we end the current job whenever the user emits a
pipeline barrier, but we then expect to have a valid job when
we emit a draw call.

If by the time we have to emit a draw call we don't have a valid
job, we need to create one by resuming execution of the current
subpass.

Fixes some tests in:
dEQP-VK.renderpass.suballocation.attachment_allocation.input_output.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: improve handling of too large image sizes
Iago Toral Quiroga [Mon, 29 Jun 2020 09:56:48 +0000 (11:56 +0200)]
v3dv: improve handling of too large image sizes

Instead of asserting that users don't try to create images that
would require 4GB+ of memory, error out with the corresponding
OOM error when the user tries to actually allocate the memory
for the image.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: add workaround for GFXH-1602
Iago Toral Quiroga [Mon, 29 Jun 2020 09:17:19 +0000 (11:17 +0200)]
v3dv: add workaround for GFXH-1602

The first attribute must be active if using builtins.

This fixes a lot of simulator crashes for vertex input CTS tests.
It should be noted that some of these tests still fail after this
fix though, so there may be some other bug.

Fixes crashes in:
dEQP-VK.pipeline.vertex_input.multiple_attributes.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix GFXH-930 workaround
Iago Toral Quiroga [Mon, 29 Jun 2020 09:15:25 +0000 (11:15 +0200)]
v3dv: fix GFXH-930 workaround

We want to check if the coordinate shader is reading attributes, not
the vertex shader.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/device: expose support for image cube array
Alejandro Piñeiro [Sun, 28 Jun 2020 00:08:16 +0000 (02:08 +0200)]
v3dv/device: expose support for image cube array

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agonir: include texture query lod as one of the ops that requires a sampler
Alejandro Piñeiro [Mon, 29 Jun 2020 09:17:32 +0000 (11:17 +0200)]
nir: include texture query lod as one of the ops that requires a sampler

In practice we found that we need this for v3d (specifically for cube
map arrays, as they don't support the default value for wrap_i, so a
sampler object is needed to override that value).

It is worth to note that the main reason behind this auxiliar method
was to identify those cases that we didn't have a sampler object
available for Vulkan. So far, we found that we have a sampler object
coming from nir always for that operation.

Fixes cube map array tests like the following:
dEQP-VK.glsl.texture_functions.query.texturequerylod.usamplercubearray_fragment

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/uniforms: support for some QUNIFORM_IMAGE_XXX
Alejandro Piñeiro [Wed, 24 Jun 2020 09:36:58 +0000 (11:36 +0200)]
v3dv/uniforms: support for some QUNIFORM_IMAGE_XXX

As we are using the descriptor sets to access to the specific
v3dv_image_view, we can just reuse the existing methods for the
textures.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: lower_image_deref
Alejandro Piñeiro [Tue, 23 Jun 2020 23:55:20 +0000 (01:55 +0200)]
v3dv/pipeline: lower_image_deref

This is really similar to the existing lower_tex_src_to_offset, but
for now we prefer to keep them independent, just in case we start to
found specific image use-cases as we advance fixing CTS tests.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/descriptors: support for DESCRIPTOR_TYPE_STORAGE_IMAGE
Alejandro Piñeiro [Tue, 23 Jun 2020 14:37:02 +0000 (16:37 +0200)]
v3dv/descriptors: support for DESCRIPTOR_TYPE_STORAGE_IMAGE

From the descriptor pov is mostly another image without sampler, so
for example, on the descriptor pool bo we only store the texture
shader state.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: implement support for shader spilling
Iago Toral Quiroga [Fri, 26 Jun 2020 10:45:09 +0000 (12:45 +0200)]
v3dv: implement support for shader spilling

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: lower frexp
Iago Toral Quiroga [Thu, 25 Jun 2020 08:49:13 +0000 (10:49 +0200)]
v3dv: lower frexp

Fixes:
dEQP-VK.glsl.builtin.precision.frexp.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: lower unpack_{u,s}norm_2x16
Iago Toral Quiroga [Thu, 25 Jun 2020 08:28:07 +0000 (10:28 +0200)]
v3dv: lower unpack_{u,s}norm_2x16

The hardware doesn't have unorm/snorm packing variants and we were
already lowering the packing versions of these.

Fixes:
dEQP-VK.glsl.builtin.function.pack_unpack.unpacksnorm2x16_compute
dEQP-VK.glsl.builtin.function.pack_unpack.unpackunorm2x16_compute

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: don't reset descriptor state after a meta operation
Iago Toral Quiroga [Thu, 25 Jun 2020 07:30:04 +0000 (09:30 +0200)]
v3dv: don't reset descriptor state after a meta operation

If the meta operation did not change descriptor state then we should keep it,
not reset it.

Fixes:
dEQP-VK.fragment_operations.early_fragment.early_fragment_tests_stencil
dEQP-VK.fragment_operations.early_fragment.no_early_fragment_tests_stencil

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle empty set layouts
Iago Toral Quiroga [Thu, 25 Jun 2020 06:54:34 +0000 (08:54 +0200)]
v3dv: handle empty set layouts

Fixes:
dEQP-VK.api.object_management.max_concurrent.descriptor_set_layout_empty
dEQP-VK.api.object_management.single_alloc_callbacks.descriptor_set_layout_empty

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: initial support for input attachments
Alejandro Piñeiro [Tue, 23 Jun 2020 13:47:53 +0000 (15:47 +0200)]
v3dv: initial support for input attachments

We are treating them as a special case of texture, so the commit is
mostly about integrating them with the existing
SAMPLER/SAMPLER_IMAGE/COMBINED_IMAGE_SAMPLER infrastructure.

This commit doesn't use in any special way the render pass
information, including the dependencies, so it is possible that we
would need to do something else. But this commit gets several CTS
tests, and two Sascha Willem Vulkan demos, so let's start with this
commit and handle any other use case for following commits.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: set load_layer_id to zero
Alejandro Piñeiro [Fri, 8 May 2020 23:06:12 +0000 (01:06 +0200)]
v3dv/pipeline: set load_layer_id to zero

We don't support layered rendering so let's lower the intrinsic to
zero for now. Based on turnip commit 99a4f7c ("turnip: set
load_layer_id to zero")

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/pipeline: iterate used textures using the combined index map
Alejandro Piñeiro [Mon, 22 Jun 2020 15:20:24 +0000 (17:20 +0200)]
v3dv/pipeline: iterate used textures using the combined index map

So far we were using nir->data.num_textures to fill the default values
for the textures used on the shader, and set the value for the number
of textures used.

But nir->data.num_textures doesn't take into account input
attachments, even after nir_lower_input_attachments. Although that
could make sense from a general pov, in our case we are treating input
attachments mostly as textures.

This commit count the number of textures interating through the
pipeline combined index map, as it includes both. This also makes the
populate of the shader key for default values more similar to the one
done at cmd_buffer with real values.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3d/tex: avoid to ask back for a sampler state if not needed
Alejandro Piñeiro [Mon, 22 Jun 2020 23:52:48 +0000 (01:52 +0200)]
v3d/tex: avoid to ask back for a sampler state if not needed

So far we were not asking the driver for the sampler state if we could
just use the default P1 values. But even if we need to fill P1 (for
example to fill up the output type of the format), if the texture
operation doesn't need a sampler, we can let that field as NULL (so
default values) and avoid calling back the driver for a sampler.

This is not mandatory for OpenGL (as we always have a sampler object),
although still a good to have. For Vulkan this is needed, as we don't
have a sampler object in that case.

v2: reword comment (Eric)

Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: pipeline initialization fixes for disabled rasterization
Iago Toral Quiroga [Tue, 23 Jun 2020 10:46:49 +0000 (12:46 +0200)]
v3dv: pipeline initialization fixes for disabled rasterization

When rasterization is disabled there are a number of CreateInfo
structs that should be ignored. We were managing this correctly
for some cases, but not all of them. Specifically, viewport state
must be ignored and we weren't doing that.

Fixes:
dEQP-VK.api.descriptor_set.descriptor_set_layout_lifetime.graphics

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: don't free BOs from imported memory objects
Iago Toral Quiroga [Tue, 23 Jun 2020 11:36:15 +0000 (13:36 +0200)]
v3dv: don't free BOs from imported memory objects

Only free the underlying BO when the exported memory object is freed
to avoid multiple frees of the same memory.

The only exception is winsys BOs where we import a BO created in the
display device into the render device. In this case, we only have one
memory object referencing the BO and we want to destroy it with that
memory object.

Fixes:
dEQP-VK.api.external.memory.dma_buf.*
dEQP-VK.api.external.memory.opaque_fd.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: assert that our framebuffers are single sampled
Iago Toral Quiroga [Tue, 23 Jun 2020 10:11:30 +0000 (12:11 +0200)]
v3dv: assert that our framebuffers are single sampled

This makes it easier to track CTS test fails related to multisampling,
which we don't support yet.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: return a proper error for too large buffer allocations
Iago Toral Quiroga [Tue, 23 Jun 2020 09:32:04 +0000 (11:32 +0200)]
v3dv: return a proper error for too large buffer allocations

Fixes: dEQP-VK.api.buffer.basic.size_max_uint64
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: implement indirect compute dispatch
Iago Toral Quiroga [Fri, 19 Jun 2020 09:56:20 +0000 (11:56 +0200)]
v3dv: implement indirect compute dispatch

The hardware can't do this, so we need to record a CPU job that will
map the indirect buffer at queue submission time, read the dispatch
parameters and then submit a regular dispatch.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: always emit index buffer state for new jobs
Iago Toral Quiroga [Fri, 19 Jun 2020 11:42:21 +0000 (13:42 +0200)]
v3dv: always emit index buffer state for new jobs

New jobs need to re-emit all state. Typically, this is achieved
by resetting all dirty state flags when we start a new job, but
for index buffers we were not using a dirty bit because we always
emit them immediately. This patch adds the bit and only tries
to skip index buffer state if the bit is not dirty, which will
ensure that we will always emit it for new jobs.

This fixes a regression in the shadowmapping demo from Sascha Willems
introduced with "v3dv: try harder to skip emission of redundant state".

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle unsized arrays in SSBOs
Iago Toral Quiroga [Fri, 19 Jun 2020 07:52:53 +0000 (09:52 +0200)]
v3dv: handle unsized arrays in SSBOs

CTS coverage for this was hiding behind compute shaders so
we didn't notice this was not working properly until now.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: implement compute dispatch
Iago Toral Quiroga [Thu, 18 Jun 2020 11:53:51 +0000 (13:53 +0200)]
v3dv: implement compute dispatch

for now this only implements regular dispatches, not indirect.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: handle separate binding points for compute and graphics
Iago Toral Quiroga [Thu, 18 Jun 2020 10:14:58 +0000 (12:14 +0200)]
v3dv: handle separate binding points for compute and graphics

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: support compute pipelines
Iago Toral Quiroga [Thu, 18 Jun 2020 09:06:00 +0000 (11:06 +0200)]
v3dv: support compute pipelines

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/bo: add dump stats info
Alejandro Piñeiro [Thu, 18 Jun 2020 08:59:57 +0000 (10:59 +0200)]
v3dv/bo: add dump stats info

Focused specially on the cache, how many BOs and how much bo_size is
store on the cache, freed bos, bos moved to cache etc.

Initially not configured with V3D_DEBUG (like v3d) to avoid a runtime
check on most of v3dv_bo functions.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/bo: add a maximum size for the bo_cache and a envvar to configure it
Alejandro Piñeiro [Tue, 16 Jun 2020 23:41:13 +0000 (01:41 +0200)]
v3dv/bo: add a maximum size for the bo_cache and a envvar to configure it

V3DV_MAX_BO_CACHE_SIZE can be used to configure it.

So one way to disable the bo cache is setting V3DV_MAX_BO_CACHE_SIZE
to zero. This would still run all the bo_cache size checks, but having
another envvar just to ensure that anything related to the cache is
used seemed like an overkill.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv/bo: adding a BO cache
Alejandro Piñeiro [Fri, 5 Jun 2020 10:21:54 +0000 (12:21 +0200)]
v3dv/bo: adding a BO cache

Heavily based on the already existing for the v3d OpenGL driver, but
without references, and with some extra OOM checks (Vulkan CTS has
several OOM tests).

With this commit v3dv_bo_alloc and v3dv_bo_free became frontends to
the bo_cache. The former tries to get a BO from the cache if possible,
and the latter stores the BO on the cache if possible. The former also
adds a new parameter to point if the BO to allocate is private.

As v3d we are only caching private BOs, those created by the driver
for internal use (like CLs, tile_alloc, etc). They are the ones with
the highest change of being reused (for example, CL BOs are always
4KB, so they can always be reused). User-created BOs can have any
size, including some very large ones for buffers and images, which
makes them far less likely to be reused and would add a lot of memory
pressure if we decided to cache them.

In any case, in practice, we found that we could get a performance
improvement by caching also user-created BOs, but that would need more
care and an analysis to decide which ones makes sense. Would also
require to change how the cached BOs are stored by size. Right now
there are an array of list_head, that doesn't work well with big
BOs. If done, that would be handled on a separate commit.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: always map full BOs
Iago Toral Quiroga [Wed, 17 Jun 2020 10:15:42 +0000 (12:15 +0200)]
v3dv: always map full BOs

Both the API user and the driver may attempt to map a BO, possibly
only partially and using different ranges. This is a problem because
we only have a single map per BO. Fix this by making sure that when
a BO is mapped, we always map its entire range. This way if a BO
has been mapped before, we know that map is still valid no matter the
region we need to access now.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: try to use TFU path when creating tiled images from linear buffers
Iago Toral Quiroga [Tue, 16 Jun 2020 07:47:23 +0000 (09:47 +0200)]
v3dv: try to use TFU path when creating tiled images from linear buffers

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: add a CPU path for buffer to image copies
Iago Toral Quiroga [Mon, 15 Jun 2020 14:44:49 +0000 (16:44 +0200)]
v3dv: add a CPU path for buffer to image copies

The blit shader path for buffer to image copies is pretty bad,
since it needs to produce a tiled image from the linear buffer
prior to emitting the blit copy.

This patch adds a new preferential path where we implement the
copy using the CPU, similar to what the GL driver does for
texture uploads. This makes vkQuake2 at least 4x faster when
dynamic lights are enabled (which triggers dynamic texture
updates).

We also tested a GPU path where we use a shader that takes the
linear buffer as a UBO and copies directly from it. This also
shows a clear performance gain, but still worse than the CPU
implementation.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: add a TFU path for buffer to image copies
Iago Toral Quiroga [Mon, 15 Jun 2020 08:49:11 +0000 (10:49 +0200)]
v3dv: add a TFU path for buffer to image copies

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: try harder to skip emission of redundant state
Iago Toral Quiroga [Thu, 11 Jun 2020 09:59:24 +0000 (11:59 +0200)]
v3dv: try harder to skip emission of redundant state

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: actually enable early Z
Iago Toral Quiroga [Thu, 11 Jun 2020 06:32:26 +0000 (08:32 +0200)]
v3dv: actually enable early Z

We had done all the plumbing for this but EZ can be disabled in 3 places
and we were never setting the enable bit in the configuration bits packet.

Also, configuration bits must not enable EZ if this has been disabled in
the RCL for the whole frame, which we do if we don't have a depth
attachment at all.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix release build warnings
Iago Toral Quiroga [Wed, 10 Jun 2020 10:12:21 +0000 (12:12 +0200)]
v3dv: fix release build warnings

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: fix a few cases where we were ignoring suballocated buffers
Iago Toral Quiroga [Tue, 9 Jun 2020 10:06:50 +0000 (12:06 +0200)]
v3dv: fix a few cases where we were ignoring suballocated buffers

This gets VkQuake2 to render correctly.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

4 years agov3dv: regen BO lists for CLs inside cloned jobs
Iago Toral Quiroga [Tue, 9 Jun 2020 12:31:40 +0000 (14:31 +0200)]
v3dv: regen BO lists for CLs inside cloned jobs

Otherwise cloned BO lists point to the original list objects and not
the cloned ones, and that will confuse anything that tries to iterate over
them, such as list_length(), leading to infinite loops.

Fixes (in debug mode):
dEQP-VK.api.command_buffers.render_pass_continue

In that test we clone a full CL job from a secondary, and without this,
the BO lists in its CL lists will point to the bo_list field in the
original job, leading to an infinite loop as we assert the expected size
of these lists at queue submit time in handle_cl_job.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>