Commit Graph

55 Commits

Author SHA1 Message Date
Konstantin Seurer 9104dafb6f vulkan,nir: Refactor ycbcr conversion state into a struct
This will be useful for RADV since it hashes the state.

v3dv changes:
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20731>
2023-02-06 18:36:29 +00:00
Thomas H.P. Andersen a8caf451cb v3dv: use common code for descriptor update template
Use the common code and structs for this. Depends on !14780

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18625>
2023-01-22 11:20:29 +00:00
Ella Stanforth 18319a236c v3dv: add support for multi-planar formats, enable YCbCr
Original patches wrote by Ella Stanforth.

Alejandro Piñeiro main changes (skipping the small fixes/typos):
  * Reduced the list of supported formats to
    VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM and
    VK_FORMAT_G8_B8R8_2PLANE_420_UNORM, that are the two only
    mandatory by the spec.
  * Fix format features exposed with YCbCr:
    * Disallow some features not supported with YCbCr (like blitting)
    * Disallow storage image support. Not clear if really useful. Even
      if there are CTS tests, there is an ongoing discussion about the
      possibility to remove them.
    * Expose VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT, that is
      mandatory for the formats supported.
    * Not expose VK_FORMAT_FEATURE_2_MIDPOINT_CHROMA_SAMPLES_BIT. Some
      CTS tests are failing right now, and it is not mandatory. Likely
      to be revisit later.
    * We are keeping VK_FORMAT_FEATURE_2_DISJOINT_BIT and
      VK_FORMAT_FEATURE_2_MIDPOINT_CHROMA_SAMPLES_BIT. Even if they
      are optional, it is working with the two formats that we are
      exposing. Likely that will need to be refined if we start to
      expose more formats.
  * create_image_view: don't use hardcoded 0x70, but instead doing an
    explicit bit or of VK_IMAGE_ASPECT_PLANE_0/1/2_BIT
  * image_format_plane_features: keep how supported aspects and
    separate stencil check is done. Even if the change introduced was
    correct (not sure about that though), that change is unrelated to
    this work
  * write_image_descriptor: add additional checks for descriptor type,
    to compute properly the offset.
  * Cosmetic changes (don't use // for comments, capital letters, etc)
  * Main changes coming from the review:
     * Not use image aliases. All the info is already on the image
       planes, and some points of the code were confusing as it was
       using always a hardcoded plane 0.
     * Squashed the two original main patches. YCbCr conversion was
       leaking on the multi-planar support, as some support needed
       info coming from the ycbcr structs.
     * Not expose the extension on Android, and explicitly assert that
       we expect plane_count to be 1 always.
  * For a full list of review changes  see MR#19950

Signed-off-by: Ella Stanforth <estanforth@igalia.com>
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19950>
2023-01-16 14:10:21 +00:00
Iago Toral Quiroga 07c7d846e5 v3dv: drop layout refs for all allocated sets from a pool on destroy / reset
In 7f6ecb8667 we added reference counting for descriptor set layouts,
however, we didn't realize that pools created without the flag
VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT don't free individual
descriptors and can only be reset or destroyed. Since we only drop
references when individual descriptor sets were destroyed, we would
leak set layouts referenced from descriptor sets allocated from these
pools.

Fix that by keeping a list of all allocated descriptor sets (no matter
whether VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT is present or
not) and then traversing the list dropping the references on pool resets
and destroys.

Fixes: 7f6ecb8667 ('v3dv: add reference counting for descriptor set layouts')
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19337>
2022-10-27 11:35:29 +00:00
Iago Toral Quiroga 14dab6b10c v3dv: ref/unref pipeline layout objects
Since KHR_maintenance4 it is possible to destroy pipeline layouts
immediately after creating pipelines.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18246>
2022-08-30 11:10:14 +00:00
Iago Toral Quiroga 425f8aa7a4 v3dv: add a helper to destoy pipeline layouts
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18246>
2022-08-30 11:10:14 +00:00
Iago Toral Quiroga d2d2fdf934 v3dv: remove assert that poolSizeCount must be larger than 0
From the Vulkan spec:

   "If poolSizeCount is not 0, pPoolSizes must be a valid pointer to an
    array of poolSizeCount valid VkDescriptorPoolSize structures"

So 0 is actually allowed and there is a CTS to check it is handled gracefully.

Fixes:
dEQP-VK.api.descriptor_pool.zero_pool_size_count

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17648>
2022-07-20 10:33:57 +00:00
Eric Engestrom 9db1af8757 v3dv: use updated tokens from vk.xml
Signed-off-by: Eric Engestrom <eric@igalia.com>
Acked-by: Iago Toral Quiroga <itoral@igalia.com>
Acked-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17342>
2022-07-12 15:53:11 +00:00
Iago Toral Quiroga 7b91b39ba5 v3dv: fix pool descriptor count for inline uniform buffers
Fixes VK_ERROR_OUT_OF_POOL_MEMORY in the inlineuniformblocks
sample from Sascha Willems.

Fixes: ea3223e7a4 ('v3dv: implement VK_EXT_inline_uniform_block')
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17311>
2022-07-01 11:12:39 +00:00
Alejandro Piñeiro 1ed2b5e253 v3dv/pipeline: include pipeline layout on the pipeline sha1
Fixes failures on tests like this when the on-disk-cache is enabled:
dEQP-VK.binding_model.descriptor_copy.compute.uniform_buffer_0

We only found them when running full CTS runs. What happens is that we
got a hit from the on-disk shader cache, for several tests using the
same shaders. But some tests seems to be using a uniform buffer, and
others a inline buffer. Right now inline buffers leads to some changes
on the final nir shader, and generated assembly, compared with uniform
buffers. So we got a wrong shader. Fortunately we only got an assert
instead of weird behaviour.

With this commit we include the pipeline layout on the pipeline sha1,
so those two cases would get different sha1. FWIW, this is what other
drivers are already doing.

Surprisingly that didn't cause a problem before.

Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16313>
2022-05-04 09:21:20 +00:00
Iago Toral Quiroga 7f6ecb8667 v3dv: add reference counting for descriptor set layouts
The spec states that descriptor set layouts can be destroyed almost
at any time:

   "VkDescriptorSetLayout objects may be accessed by commands that
    operate on descriptor sets allocated using that layout, and those
    descriptor sets must not be updated with vkUpdateDescriptorSets
    after the descriptor set layout has been destroyed. Otherwise,
    descriptor set layouts can be destroyed any time they are not in
    use by an API command."

Based on a similar fix for RADV.

Gitlab: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5893
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15634>
2022-03-29 11:28:39 +00:00
Iago Toral Quiroga ca861bd6f4 v3dv: drop unnecessary memset
We are already zeroing when we allocate the descriptor set layout
memory with vk_object_zalloc.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15634>
2022-03-29 11:28:39 +00:00
Iago Toral Quiroga 591eed30b2 v3dv: fix sampler array addressing in v3dv_descriptor_set_layout
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15634>
2022-03-29 11:28:39 +00:00
Iago Toral Quiroga ea3223e7a4 v3dv: implement VK_EXT_inline_uniform_block
Inline uniform blocks store their contents in pool memory rather
than a separate buffer, and are intended to provide a way in which
some platforms may provide more efficient access to the uniform
data, similar to push constants but with more flexible size
constraints.

We implement these in a similar way as push constants: for constant
access we copy the data in the uniform stream (using the new
QUNIFORM_UNIFORM_UBO_*) enums to identify the inline buffer from
which we need to copy and for indirect access we fallback to
regular UBO access.

Because at NIR level there is no distinction between inline and
regular UBOs and the compiler isn't aware of Vulkan descriptor
sets, we use the UBO index on UBO load intrinsics to identify
inline UBOs, just like we do for push constants. Particularly,
we reserve indices 1..MAX_INLINE_UNIFORM_BUFFERS for this,
however, unlike push constants, inline buffers are accessed
through descriptor sets, and therefore we need to make sure
they are located in the first slots of the UBO descriptor map.
This means we store them in the first MAX_INLINE_UNIFORM_BUFFERS
slots of the map, with regular UBOs always coming after these
slots.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15575>
2022-03-28 10:44:13 +00:00
Jose Maria Casanova Crespo 90f966e05f v3dv/v3d: Fix copyright holder to Raspberry Pi Ltd
Acked-by: Iago Toral Quiroga <itoral@igalia.com>
Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15057>
2022-02-18 11:50:07 +01:00
Alejandro Piñeiro 5d04b76c09 v3dv: remove unused v3dv_descriptor_map_get_texture_format
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14635>
2022-01-21 13:24:18 +00:00
Jason Ekstrand bab0530f07 v3dv: Switch to the new vk_error helpers
Also, change every vk_error to use the closest object instead of
fetching all the way back to the instance.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13045>
2021-10-07 20:51:36 +00:00
Iago Toral Quiroga 0496a39b1f v3dv: make v3dv_image_view derive from vk_image_view
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12668>
2021-09-02 05:53:39 +00:00
Iago Toral Quiroga 0df9112692 v3dv: add API entry points for sampler Ycbcr conversions
While this feature is optional in Vulkan 1.1 and we don't currently
expose it, the CTS still requires that the entry points exist.

From the Vulkan 1.1 spec:

   "If the VK_KHR_sampler_ycbcr_conversion extension is not supported,
    support for the samplerYcbcrConversion feature is optional."
   (...)
   "samplerYcbcrConversion specifies whether the implementation supports
    sampler YCBCR conversion. If samplerYcbcrConversion is VK_FALSE,
    sampler YCBCR conversion is not supported, and samplers using sampler
    YCBCR conversion must not be used."

Fixes (with Vulkan 1.1 exposed):
dEQP-VK.api.version_check.entry_points

Reviewed-by: Juan A. Suarez <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12338>
2021-08-12 10:20:54 +00:00
Alejandro Piñeiro 2e40f13f9a v3dv: don't use cl_packet_length for prepacked data
cl_packet_length depends on the specific hw generation packets, so it
is can't be included directly by main header.

The straight forward solution would be to allocate them dynamically,
based on the current generation. That ended to be complex and
messy. Also, even if that change between hw versions, it will not
change significantly.

So we just add some definition with the size of the packets we
prepack. We just need to be careful that this needs to be the maximum
value considering all the versions supported.

Note that on Opengl v3d does something similar, using hardcoded
values, but without a define, neither a runtime check.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11310>
2021-06-22 11:34:06 +02:00
Alejandro Piñeiro 1bea0d76b8 v3dv: split v3dv_descriptor hw version dependant to a new source file.
As part of this, we get rid of the v3dv_xxx_descriptor structs to
v3dv_descriptor. The main reason is that in order to support several
versions, we would need to define them several times. Also, they were
somewhat an overkill even before, as their main advantage was getting
the offset for each data on the combined case. That functionality is
replaced with some new helpers.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11310>
2021-06-22 11:34:06 +02:00
Iago Toral Quiroga 4886773fc0 v3dv: implement VK_KHR_descriptor_update_template
Relevant tests:
dEQP-VK.binding_model.*.with_template.*

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11213>
2021-06-07 11:10:49 +00:00
Iago Toral Quiroga a48cb7534d v3dv: refactor descriptor updates
Make helper functions for all descriptor types and have them handle
all of the descriptor update so we can reuse them later to implement
template updates.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11213>
2021-06-07 11:10:49 +00:00
Georg Lehmann 9d66a2d986 v3dv: use VKAPI_ATTR and VKAPI_CALL.
Closes #4852

Signed-off-by: Georg Lehmann <dadschoorse@gmail.com>
Tested-by: Roman Stratiienko <r.stratiienko@gmail.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11062>
2021-05-31 17:08:27 +00:00
Iago Toral Quiroga 6a847cbe1d v3dv: implement VK_KHR_maintenance3
We don't have any special restrictions associated with the number
of descriptors in a set other than maybe not exceeding what we can
put in a single memory allocation, so in practice, applications will
be limited by the per-stage contraints defined by other Vulkan limits.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10970>
2021-05-26 07:18:19 +00:00
Alejandro Piñeiro 1e0a69afa7 vulkan: track number of bindings instead of max binding for CreateDescriptorSetLayout
As that handles better, and more clear, the case of bindingCount being
zero. For the case of Anvil and Turnip, this avoids allocating a
non-needed binding when bindingCount is zero.

Inspired on radv, that was what it was doing so far.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4526

Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Hyunjun Ko <zzoon@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9905>
2021-04-05 20:17:53 +00:00
Bas Nieuwenhuizen 83c92a48b7 vulkan: Fix descriptor set creation with zero bindings.
MAX2(count * struct size, 1) results in 1 for count=0, not the size of a struct.

Since this MAX only seems to exist so we can keep using NULL for error reporting,
just refactor to return a VkResult.

Fixes: ad241b15a9 ("vk: consolidate dynamic descriptor binding sorting")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4522
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Acked-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9880>
2021-03-29 23:32:50 +00:00
Mike Blumenkrantz ad241b15a9 vk: consolidate dynamic descriptor binding sorting
this code was duplicated across several drivers

Reviewed-by: Adam Jackson <ajax@redhat.com>
turnip changes Reviewed-by: Hyunjun Ko <zzoon@igalia.com>

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9480>
2021-03-22 16:51:55 +00:00
Alejandro Piñeiro c373b24369 v3dv/descriptor_set: don't free individual set if not allowed
If we have a host_memory_base pointer it means that we are handling
the pool memory as a whole, so each set is a sub-slice of the memory
pool. In this case we can't just free the individual set. In other
words, VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT is not set.

Note tha at that point we were able to sub-allocate an set, and we are
failing to sub-allocate the pool bo for the descripto bo. So
technically we could try to return that set to the pool (so undo the
change on host_memory_ptr before), that I assume was my intention when
(wrongly) calling vk_free there. But in practice, at that point we are
already on a out of descriptor pool situation, so in the end it
doesn't even matter.

This fixes a double free crash with the UE4 VehicleGame demo.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9640>
2021-03-17 10:05:07 +00:00
Alejandro Piñeiro 319153365b v3dv/descriptor: assert CrateDescriptorPool receives valid count values
Although I assume that this should be caught by the validation layers,
recently while triaging the following tests:
dEQP-VK.ycbcr.query.*r8g8b8a8_unorm*

We found that they were setting a descriptorCount of zero, because it
was not handling correctly the differences between Vulkan 1.0 and
Vulkan 1.1.

So let's just assert, just in case it happens again, as that would
make the bugfixing far easier.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8614>
2021-01-21 17:06:51 +00:00
Iago Toral Quiroga a46547671b v3dv: only update uniforms for dirty descriptors if stage has descriptors
If we have dirty descriptor set state we have to update our uniform
data to reference the new resources such as addresses for textures
or UBOs. This is known to have a high CPU cost, so we want to limit
this as much as we can.

It is a common rendering pattern in applications to render many objects
using the same pipeline, but modifying the descriptor sets bound to update
textures, UBOs, etc. In this scenario, we would be incurring in unnecessary
uniform stream updates for stages that don't access descriptor sets at all.

This change makes it so we track which shader stages in a pipeline
use descriptor set state and skips updating uniform streams for them
when dirty descriptor set state is the only reason requiring us to
generate new uniform streams for a draw call.

v2: reuse shader stage information from the pipeline set layouts
    to track shader stages that use descriptor state.

Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8555>
2021-01-19 08:07:57 +00:00
Iago Toral Quiroga 4f7d4871a6 v3dv: don't log out of pool memory errors for internal driver pools
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7848>
2020-12-01 12:10:11 +00:00
Alejandro Piñeiro 30b6fbc496 v3dv: use the common base object type and struct
Used as reference Hyujun's commit
5d3fdbc52b, that does the same for
turnip.

This commit also replaces in several cases alloc for zalloc, and adds
checks on more Destroy methods if the object to be free is NULL or
not. Most of them were needed to avoid crashes/weird behaviour due
trying to use un-initialized data. Note that now that vk_object_free
iterates over a array, making it more against un-initialized or just
NULL data.

Additionally, using zalloc we can also remove some memset to 0. In
fact we needed to remove them, as if not, they would override the
vk_object_base object to 0 (the alternative would me doing a memset
computing a pointer offset, but that's is not needed as we can just
use zalloc).

v2:
   * Call memset(0) on reused descriptor sets when calling
     ResetDescriptorPool, not when reallocating them (Iago)
   * Add null check when calling DestroyImageView (detected by a full CTS run)

v3: Fixed rebase conflicts after last meta copy/clear changes

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7627>
2020-11-17 23:55:14 +00:00
Vinson Lee f0c8645cb9 v3dv: Remove unsigned comparison to zero.
index is of type uint32_t.

Fix defects reported by Coverity Scan.

Macro compares unsigned to 0 (NO_EFFECT)
unsigned_compare: This greater-than-or-equal-to-zero comparison of
an unsigned value is always true. index >= 0U.

Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7518>
2020-11-13 16:54:09 -08:00
Vinson Lee 8eb246d7f6 v3dv: Remove unsigned comparison to zero.
index is of type uint32_t.

Fix defect reported by Coverity Scan.

Macro compares unsigned to 0 (NO_EFFECT)
unsigned_compare: This greater-than-or-equal-to-zero comparison of
an unsigned value is always true. index >= 0U.

Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7153>
2020-10-16 15:25:37 -07:00
Alejandro Piñeiro 5de282b50a v3dv/descriptor: remove v3dv_descriptor_map_get_image_view
Now that we added support for texel_buffers, on all the cases that we
were checking for a image_view we end checking for a image_view or
buffer_view, so we stopped to use it. Remove it as it become
superfluous.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:32 +00:00
Alejandro Piñeiro 81b713e341 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>
2020-10-13 21:21:32 +00:00
Iago Toral Quiroga f156c5dc4d 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>
2020-10-13 21:21:31 +00:00
Alejandro Piñeiro 407411036c 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>
2020-10-13 21:21:31 +00:00
Iago Toral Quiroga 4b9e3bbf48 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>
2020-10-13 21:21:31 +00:00
Alejandro Piñeiro 9833a5ae70 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>
2020-10-13 21:21:31 +00:00
Iago Toral Quiroga 2f1c15116f 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>
2020-10-13 21:21:31 +00:00
Alejandro Piñeiro 2adea940f1 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>
2020-10-13 21:21:31 +00:00
Alejandro Piñeiro 9a894849d5 v3dv/descriptor: use descriptor pool bo for image/samplers
This allows us to remove some individual bos for the image and
sampler, used to store the SAMPLER_STATE and TEXTURE_SHADER_STATE. Now
they are prepacked on static memory as part of the vulkan object
struct.

This commit introduces small descriptor structs, used to define what
the bo subregion would contain. It is used mostly to compute offsets
to that specific data, and define the size needed. Having said so, it
would be possible to replace them with some kind of flag (like anv) or
just compute the offset based on the context.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:30 +00:00
Alejandro Piñeiro 18553b50f9 v3dv/descriptor: add general bo on descriptor pool
So far we were saving all the descriptor info on the host memory. With
this commit we do the equivalent that other mesa vulkan drivers (Anvil
and Turnip) and create a bo on the descriptor pool that would be
suballocated for each descriptor.

This would allow to clean up individual bos from some vulkan objects,
reducing device memory fragmentation, and allowing to avoid to alloc
bos for that info. After all, pre-allocating needed memory is one of
the purposes of the descriptor pool.

This commit introduces all the infrastructure, but doesn't use it for
any descriptor yet, as if no descriptor needed data uploaded to a bo.

The idea to decide which info goes to the descriptor pool bo is info
that we would need to upload to a bo in any case, as it is referenced
as an address by any packet.

We could be more aggressive with that general rule, but that would be
enough for now. If in the future we support
VK_EXT_descriptor_indexing, we probably would need to store more info,
as under that extension, descriptors can be updated after being bound.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:30 +00:00
Alejandro Piñeiro 03f5fae88f v3dv/cmd_buffer: move variant checking to CmdDraw
In order to properly check (and possibly compile) shader variants we
need a pipeline and a compatible descriptor set. So far we were trying
to do that check as early as possible, so we were trying to do it at
CmdBindPipeline or CmdBindDescriptorSets, and a combination of dirty
flags. This showed to not cover all the corners cases, and made the
code complex, as needed to handle cases where the descriptors were not
yet available, and return early. The latter also meant that we were
running several checks that failed in the middle.

This commit moves the variant check to CmdDraw, when we should have a
pipeline and compatible descriptor sets, and simplifies and makes more
strict the existing code.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:30 +00:00
Alejandro Piñeiro 9d8b1b01c3 v3dv/descriptor: move descriptor_map_get_sampler, add and use get_image_view
First one as we plan to use get_sampler on more places, second one
just to get cleaner code.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro dedff7446a v3dv/descriptor_set: support for immutable samplers
They are bound at the set layout, and cannot be changed. From
VkDescriptorSetLayoutBinding spec:

   "pImmutableSamplers affects initialization of samplers. If
   descriptorType specifies a VK_DESCRIPTOR_TYPE_SAMPLER or
   VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER type descriptor, then
   pImmutableSamplers can be used to initialize a set of immutable
   samplers. Immutable samplers are permanently bound into the set
   layout and must not be changed; updating a
   VK_DESCRIPTOR_TYPE_SAMPLER descriptor with immutable samplers is
   not allowed and updates to a
   VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptor with immutable
   samplers does not modify the samplers (the image views are updated,
   but the sampler updates are ignored)"

We stored them as part of the set layout. It also means that when we
need the sampler (like for texture operations) we can't just ask for a
descriptor, as it would not have the sampler. A new method is created.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro 6e39565e59 v3dv/cmd_buffer: allow return in the middle of variant update if needed
Right now shader variant update on the cmd_buffer is based on populate
a new key using the descriptor bounds, assuming that we would get one
final descriptor for any usage on the shader. But if the descriptors
are being bound with more that one call to CmdBindDescriptorSet, that
would not be true, as the first calls would not bind all the
descriptors. Right now this was raising an assert.

Now we allow that as possible, and for the case of checking variants,
we just stop it, and we don't clean up the SHADER_VARIANT flag.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro 07addb4183 v3dv/cmd_buffer: update shader variants at CmdBindDescriptorSets/CmdBindPipeline
Specially after CmdBindDescriptorSets, it is likely that we would need
a new shader variant, like for example if sampler descriptor sets are
bound.

At that moment a new v3d key is populated, using as base the one used
at pipeline creation, so only cmd_buffer depending values are changed.

Then a new variant is requested. Note that internally it is handled
with a cache, so no new compilation will be done if not needed.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00