Commit Graph

129828 Commits

Author SHA1 Message Date
Iago Toral Quiroga f41857eb48 v3d/compiler: implement nir_intrinsic_load_base_instance
Vulkan lowers gl_InstanceIndex to load_base_instance +
load_instance_id, so we need to implement loading the base instance in
the compiler.

The base instance is set by the BASE_VERTEX_BASE_INSTANCE command
right before the instanced draw call and it is included in the VPM
payload together with the InstanceID and VertexID if this is requested
by the shader record.

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>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro ee917d2b78 v3dv/descriptor_set: combine texture and sampler indices
OpenGL doesn't have the concept of individual texture and sampler, so
texture and sampler indexes have the same value. v3d compiler uses
this assumption, so for example, the texture info at the v3d key
include values that you need to use the texture format and the sampler
to fill (like the return_size).

One option would be to adapt the v3d compiler to handle both, but then
we would need to adapt to the lowerings it uses, like nir_lower_tex,
that also take the same assumption.

We deal with this on the Vulkan driver, by reassigning the texture and
sampler index to a combined one. We add a hash table to map the
combined texture idx and sampler idx to this combined idx, and a
simple array to the opposite map. On the driver we work with the
separate indices to fill up the data, while the v3d compiler works
with the combined one.

As mentioned, this is needed to properly fill up the texture return
size, so as we are here, we fix that. This gets tests like the
following working:

dEQP-VK.glsl.texture_gather.basic.2d.depth32f.base_level.level_2

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +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
Iago Toral Quiroga 1b80bac236 v3dv: handle partial clears of just one aspect of combined DS targets
For these we can still use a compatible color format, but we need to mask
out the color components matching the aspect that is preserved.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga b31ea83b80 v3dv: simplify partial clearing code
Alaways work with the render pass attachment index and avoid using
the subpass render target index completely. This makes things easier.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 360adff215 v3dv: fix incorrect attachment reference
We were using the subpass render target index to index into the framebuffer,
which is not correct, since the framebuffer is defined for the render pass.
We should use the attachment index instead.

Fixes:
dEQP-VK.renderpass.suballocation.attachment_allocation.roll.{40,48}

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 03a150c8ab v3dv: fix incorrect attachment reference
We were using the subpass render target index to index into the framebuffer,
which is not correct, since the framebuffer is defined for the render pass.
We should use the attachment index instead, which we were already computing
but that we were not actually using for indexing by mistake.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 93fd897c28 v3dv: compute tile granularity for each subpass
We must update our check for whether the render area is tile-aligned for
each subpass, since the hardware will update tile sizes for each RCL.

Fixes:
dEQP-VK.renderpass.suballocation.attachment_allocation.roll.8

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga f7059e4603 v3dv: set render area for partial clears to match clear rect
While this was already being achieved by the scissort rect set on the
pipeline, we still want to limit the render area to we reduce the tile
coverage of the pass as much as possible and avoid unnecessar
tile load and store operations.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga ad64add4f5 v3dv: create a v3dv_cmd_buffer_subpass_resume helper
This is the same as the subpass start version, only that it won't
emit subpass clears. This is necessary when resuming a subpass
from a partial clear to make sure we don't try to clear subpass
attachments again.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga debdea6cb5 v3dv: push/pop more state during meta operations
Since a meta partial clear starts a new render pass, we need to store
all state that can be changed with vkCmdBeginRenderPass.

Also, since the meta clear pipeline sets dynamic state, we also
have to restore that.

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
Iago Toral Quiroga 53de8892f4 v3dv: assert on subpasses that use input or resolve attachments
We don't support these yet, so we might as well assert early.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 79b07b85b6 v3dv: handle stencil load/store operations
We were using the ones defined for the depth aspect.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 7e96f9b219 v3dv: restrict render pass clears to the render area
The problem with this is that TLB clears always clear and store full
tiles, so if our render area is not perfectly aligned to tile boundaries
we end up clearing all pixels in tiles that are only partially covered.

In this scenario we have to avoid using TLB clears and instead fallback
to clearing by rendering a scissored quad in the clear color, like we do
for partial clears in vkCmdClearAttachments.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga ad0a68df11 v3dv: use the TLB to clear attachments even if we have an active scissor
According to the Vulkan spec, vkCmdClearAttachments ignores bound pipeline
state, which includes scissort and viewport.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 4db55731d4 v3dv: don't always assert that we have an active job
There are some scenario where this won't happen and don't imply a bug.
For example, if we find a pipeline barrier, we will finish the current
job automatically and won't start a new one. There may be other
scenarios where we may want to do the same.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga c9b87e9213 v3dv: fix v3dv_GetRenderAreaGranularity to account for attachment bpp
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 22d6326449 v3dv: check the render area against the clip window
And flag dirty scissor state if the render area is constraining the
current clip window, so that we emit a new clip window with the next
draw call.

Also, remove the early emission of a clip window for the render area
if we didn't have any scissor state. TLB clears ignore the clip
window, so this was doing nothing for us.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga e5642a36a0 v3dv: store the clip window in the command buffer state
We will need this so we can match a render area for a new render pass
against the current clip rect and decide if we need to make adjustments.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga d6d8bfbb4a v3dv: implement proper caching for partial clear pipelines
So far we have been caching the first pipeline we produced and always
reusing that, which is obviously incorrect.

This change implements a proper cache and also takes care of releasing
the cached resources when the device is destroyed.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga c09c8c0ef3 v3dv: implement partial depth/stencil attachment clears
This is achieved by bounding the depth/stencil attachment as a color
attachment with a compatible format and emitting a color clear instead.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 7a39e5e902 v3dv: implement partial color attachment clears
This is achieved by rendering a quad in the clear color for each layer
of each attachment being cleared. Right now we emit each clear in a
separate job with a single attachment framebuffer, but in the future
we may be able to extend the solution to using multiple render targets
and clear multiple attachments with a single job.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga 152a64185b v3dv: improve asserts for VkPipelineColorBlendStateCreateInfo handling
According to the Vulkan 1.0 spec:

  "attachmentCount is the number of VkPipelineColorBlendAttachmentState
   elements in pAttachments. This value must equal the colorAttachmentCount
   for the subpass in which this pipeline is used."

so let's assert exactly that.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Iago Toral Quiroga c6dca4c529 v3dv: allow to create shader modules from NIR
This will come in handy when the driver needs to generate its own shaders,
such as for partial clears.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro f47d0829cb v3dv/pipeline: fix adding texture/samplers array elements to texture/sampler map
For arrays we are adding one entry on the map per array element. This
makes getting back the descriptor for each array element easier, as
for example, for ubo arrays, each array element can be bound to a
different descriptor buffer.

For samplers arrays this would also make sense.

Fixes crashes on tests like:
dEQP-VK.binding_model.shader_access.primary_cmd_buf.combined_image_sampler_mutable.fragment.descriptor_array.2d

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
Alejandro Piñeiro f76dad8f89 v3dv/pipeline: add support for shader variants
So far, we were doing the compilation to qpu when the pipeline was
created (as part of vkCreateGraphicsPipeline).

But this would not be correct when some specific descriptors are
involved, like textures. For that case some nir lowerings depend on
the texture format, and that info is not available until the specific
descriptors are bound to the command buffer. In the same way, the same
command buffer with a given pipeline could get their descriptor bound
again.

So it would be needed to support compilation variants of the same
shader. So finally, the v3d_key would work as keys, as the variants
would be tracked with a hash table.

This commit introduces the new structures for that. What we were
building as the final qpu shader would become the initial default
variant for the pipeline. We are also saving the keys used at that
point, to avoid needing to fully regenerate them when a new variant is
created. Not just for performance, but also to avoid needing to track
the graphics pipeline create info structure.

The code to handle updating the current variant would be done on
following commits.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro b6d4148b92 v3dv/uniforms: filling up QUNIFORM_TMU_CONFIG_P0/P1
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro 272f0d9cfb v3dv/descriptor_set: added support for samplers
This include SAMPLER, COMBINED_IMAGE_SAMPLER and SAMPLED_IMAGE
descriptors.

In order to support them we do the pre-packing of TEXTURE_SHADER_STATE
and SAMPLER_STATE when Images and Samplers (respectively) are
created. Those packets doesn't need to be tweaked later, so we upload
them to an bo.

A possible improvement of this would be that the descriptor pool
manages a bo for all descriptors, that suballocate for each descriptor
allocated. This is what other drivers do (and as far as I understand,
one of the reasons of having a descriptor pool).

Immutable samplers are not supported, will be handled on a following
patch.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro 34910532fd v3dv/pipeline: sampler lowering
Add a pass to lower "uniform sampler2d" and others to their
texture/sampler idx.

This commit basically imports the same lowering from turnip.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:29 +00:00
Alejandro Piñeiro 522f7110a1 v3dv/pipeline: unify local allocator name
Sometimes called alloc some other pAllocator. Choosing the later for
consistency.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Alejandro Piñeiro 477b142480 v3dv/uniforms: cleaning up, moving udpate ubo/ssbo uniforms to a function
The code to handle ubo/ssbo has become too big, and made the switch
hard to read. Moved to their own function.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Alejandro Piñeiro f2d16529d1 v3dv/cmd_buffer: push constants not using descriptor anymore
v3dv_descriptor is going to be expanded with more data, so it doesn't
make sense anymore to handle a fake descriptor for the push
constants. Introducing a new struct, that is just a pair
bo/offset. Initially named v3dv_resource, as it could be the base to
reuse bos for different resources (like assembly bo)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga ca186f7291 v3dv: fix a1r5g5b5 format
We were configuring the TLB to use ABGR1555, but that doesn't really
give us what we want. There were two issues:

  * We were using the wrong Texture Data Format and Output Image
    Format. In fact those we need to use were not included on the
    packet file.

  * Even using the correct one, we need to do a RB swap to match the
    semantics of the Vulkan format.

This patch fixes both issues. As we are here we keep the formats we
were already used, that would provide support for r5g5b5a1.

So this patch makes tests like the following going from skip to pass:
dEQP-VK.texture.filtering.2d.formats.r5g5b5a1_unorm.nearest

And the following test from fail to pass:
dEQP-VK.texture.filtering.2d.formats.a1r5g5b5_unorm.nearest

Note that the R5G5B5A1_UNORM_PACK16 is not mandatory, but as we
already made the effort to understand them and get them working let's
just keep it on the list

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga 45e86d8a07 v3dv: don't emit the subpass RCL for jobs that have emitted their own
This fixes multi-layer vkCmdClearAttachments CTS tests. The underlying
problem here is that even though this command runs inside a render pass,
it is implemented as a separate job that emits its own RCL to program
render target color clears, so we should not emit the subpass RCL for it.

Fixes 250+ CTS tests (all but a1r5g5b5) in:
dEQP-VK.api.image_clearing.core.clear_color_attachment.cube_layers.*
dEQP-VK.api.image_clearing.core.clear_color_attachment.multiple_layers.*
dEQP-VK.api.image_clearing.core.clear_depth_stencil_attachment.multiple_layers.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga 32d261fad4 v3dv: fix job subpass index for vkCmdClearAttachments jobs
We had changed the interface for job starts so they take the subpass index
rather than a boolean indicating whether the job starts a new subpas, but we
forgot to update this accordingly.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga 010589a699 v3dv: fix clearing of 3D images
We were not considering that the depth of the image is minified according
to its miplevel. For some reason this only seemed to show up for tiled
images.

Fixes (except a1r5g5b5 format):
dEQP-VK.api.image_clearing.core.clear_color_image.3d.optimal.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga 3faa7db053 v3dv: fix incorrect image slice selection
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga 7de80fad74 v3dv: use compatible TLB formats if possible during copies and clears
If a format is not supported by the TLB, we can still use the TLB path
if we setup the render target using a compatible format. The only caveat
is that for clears we need to pack the clear value using the original
format of the underlying image, not the compatible format.

With this change we get to use the TLB path successfully for all supported
image formats (except a1r5g5b5, at least for now) so long as the region starts
at (0,0), and we only need to consider fallback paths for partial copies
and clears, not because of the format.

This gets us to pass a few extra hundreds of tests in:
dEQP-VK.api.image_clearing.core.clear_color_image.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga cfc0e15b9b v3dv: make sure we only expose transfer features for formats we can use
We were already doing this, but this makes it more explicit.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga 19841fd550 v3dv: check support for transfer usage flags
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga 9e7403d791 v3dv: improve assert handling for fallback paths on meta copy/clear operations
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga d471c47c79 v3dv: assert on vkCreateComputePipelines
So we can quickly identify tests that crash because they use compute shaders

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga df2bb5b01b v3dv: disable depth/stencil testing if we don't have a depth/stencil attachment
Also, remove obsolete FIXME.

Fixes:
dEQP-VK.fragment_operations.early_fragment.early_fragment_tests_stencil_no_attachment

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga e86f381ea1 v3dv: drop incorrect assertion on number of clear values at render pass begin
There can be more clear values than attachments, we should just ignore them
in that case.

Fixes some tests in:
dEQP-VK.fragment_operations.*

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga a81e63a302 v3dv: use perp end caps rasterization mode for lines
This is required to pass line rasterization tests in CTS while exposing
at least 4 bits of subpixel precision, which is the minimum required
by the spec. We are currently exposing 6 bits, however, if we select
diamond exit instead of perp end caps rasterization, then even if we
lower subpixel precision bits to 4 bits, we'd still fail one of the tests.

Fixes:
dEQP-VK.rasterization.flatshading.line_strip
dEQP-VK.rasterization.flatshading.lines
dEQP-VK.rasterization.interpolation.basic.line_strip
dEQP-VK.rasterization.interpolation.basic.lines
dEQP-VK.rasterization.interpolation.projected.line_strip
dEQP-VK.rasterization.interpolation.projected.lines

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Iago Toral Quiroga 69ce1f4fd4 v3dv: only emit config bits and varyings packets if needed
These should be emitted only if we have a new pipeline.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
2020-10-13 21:21:28 +00:00
Alejandro Piñeiro e903075335 v3dv/cmd_bufffer: rename and split emit_graphics_pipeline
The name suggests that this method emits the full graphics pipeline,
but that is not the case (ie: scissor is emitted at a different
point).

Right now that method is mostly emitting the gl_shader state plus some
other packets. So we just renamed it to emit_gl_shader_state, and move
the other packet emission to new emission methods.

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