1097 Commits

Author SHA1 Message Date
Chip Davis
20217d0bf6 Support the VK_KHR_depth_stencil_resolve extension.
I've turned on the `Resolve` cap for stencil-only formats, even though
no version of the Metal Feature Set tables lists them as supporting
multisample resolve. Obviously, if they couldn't be resolve
destinations, the stencil-resolve filter that was introduced in Metal
2.1 wouldn't work. I don't know if the platforms and feature sets where
I've turned the bit on is accurate, though. Wider testing is needed.

Because Apple families 1 and 2 don't support depth/stencil resolve at
all, I've disabled the extension for those families. Since sample-zero
resolution is a required feature of Vulkan 1.2, this means we won't be
able to support 1.2 on those devices. If there's demand, we could
possibly have a compute pass which does sample-zero resolution.
2020-09-21 13:05:38 -05:00
Bill Hollings
a59a26816e
Merge pull request #1043 from cdavis5e/mac-linear-images
Support linear images and buffer views in shared memory on macOS 10.15.5+.
2020-09-21 13:41:31 -04:00
Chip Davis
e4dbb8044a Support linear images and buffer views in shared memory on macOS 10.15.5+.
Apple assured me that, starting in 10.15.5, linear textures and texture
buffers can be created from buffers with `Shared` storage. I have tested
this and can confirm that it works at least on Big Sur, and probably on
Catalina as well.
2020-09-21 12:13:13 -05:00
Bill Hollings
bfabb5f827
Merge pull request #1045 from cdavis5e/indirect-tess-draw-fix
MVKPipeline: Don't skip setting the vertex stage pipeline.
2020-09-21 12:57:11 -04:00
Bill Hollings
5cbd809d12
Merge pull request #1044 from cdavis5e/no-compressed-linear
MVKImage: Reject attempts to create compressed linear images.
2020-09-21 12:54:44 -04:00
Bill Hollings
76828818ce Add support for VK_KHR_portability_subset extension.
Remove support for VK_EXTX_portability_subset extension.
2020-09-21 11:33:29 -04:00
Chip Davis
fa7515ed08 MVKPipeline: Don't skip setting the vertex stage pipeline.
In an indirect draw, we wouldn't set the pipeline for the vertex stage
to the command encoder, because we had already switched encoders. This
caused havoc down the line, as we wound up running the "convert indirect
buffers" pipeline again, which smashed memory randomly--possibly causing
the GPU to crash, and bringing down the `WindowServer` with it!

Why is it so easy to bring down the `WindowServer` like this?
2020-09-20 23:27:55 -05:00
Chip Davis
ff25d46992 MVKImage: Reject attempts to create compressed linear images.
This doesn't sit well with Metal, which will immediately abort the
program on the attempt.
2020-09-20 22:43:39 -05:00
Chip Davis
69255e8122 MVKGraphicsPipeline: Fix applying divisors to instanced vertex attributes.
Use the Vulkan binding index to check that the binding is used.
Previously, we were erroneously using the Metal binding index. This
allows vertex binding divisor info to actually be used, and fixes some
tests in the CTS.

Fixes #1041.
2020-09-17 15:51:22 -05:00
Chip Davis
e768649c31 Fix iOS/tvOS build. 2020-09-16 13:33:18 -05:00
Bill Hollings
a8eff24d00
Merge pull request #1039 from cdavis5e/no-variable-ms-rate
Disable the variableMultisampleRate feature for now.
2020-09-16 12:12:38 -04:00
Bill Hollings
a0bdca1ec8
Merge pull request #1038 from cdavis5e/fail-tri-fan-pipelines
MVKGraphicsPipeline: Fail triangle fan pipelines.
2020-09-16 12:02:50 -04:00
Chip Davis
68c8146729 Disable the variableMultisampleRate feature for now.
We actually can't support this. Metal's validation layer complains if
a pipeline has a different raster sample count from that of the
framebuffer, even in the no-attachment case. This means that the
`defaultRasterSampleCount` property must be set correctly if Metal
supports no-attachment rendering, and the sample count of the dummy
texture must be set properly otherwise.
2020-09-16 01:09:33 -05:00
Chip Davis
049fa3840d MVKGraphicsPipeline: Fail triangle fan pipelines.
Otherwise, when we try to draw with them, Metal's validation layer will
complain that the primitive type and primitive topology don't match.
2020-09-16 01:08:25 -05:00
Chip Davis
9f675b2e9d MVKCmdClearImage: Support clears of 3D images.
For these, we must use the `depthPlane` property to set the layer to
clear, and we must iterate over the image's depth, since the layer count
will be 1 in this case.
2020-09-16 01:07:20 -05:00
Bill Hollings
67d4b335be
Merge pull request #1036 from cdavis5e/ignore-sampler-address-w
MVKSampler: Ignore addressModeW with unnormalized coordinates.
2020-09-15 16:35:58 -04:00
Bill Hollings
afa536c8ea
Merge pull request #1035 from cdavis5e/3d-blits
MVKCmdBlitImage: Support blits with non-2D images.
2020-09-15 16:23:31 -04:00
Bill Hollings
5a9b8c8936
Merge pull request #1031 from cdavis5e/retain-descriptor-sets
MVKCmdBindDescriptorSets: Retain given objects.
2020-09-15 16:18:48 -04:00
Chip Davis
9c28064760 MVKSampler: Ignore addressModeW with unnormalized coordinates.
Some tests intentionally pass an invalid address mode here when
unnormalized coordinates are in use, ostensibly to test that it is
ignored. Metal's validation layer, however, complains if you set
`rAddressMode` to an invalid value, even if `normalizedCoordinates` is
`false`. To avoid this, don't set the `rAddressMode`, since it can't be
used with unnormalized coordinates anyway.
2020-09-15 13:13:32 -05:00
Chip Davis
3e1e029569 MVKCmdBlitImage: Support blits with non-2D images.
This is needed to get us past the 3D blit tests that were recently added
to the CTS. It *almost* passes all these new tests; the 3D format tests
fail for some reason.
2020-09-15 13:10:09 -05:00
Chip Davis
30113fc123 Retain pipeline layouts in bind/push descriptor commands.
Fixes a use-after-free bug when the pipeline layout is destroyed after
recording--e.g. in the
`dEQP-VK.api.pipeline_layout.lifetime.destroy_after_end` test.
2020-09-15 13:07:16 -05:00
Bill Hollings
a2734c3166
Merge pull request #1034 from cdavis5e/sampler-desc-autorelease
MVKSampler: Wrap MTLSamplerState creation in an autorelease pool.
2020-09-15 13:36:48 -04:00
Bill Hollings
7abb9f552a
Merge pull request #1033 from cdavis5e/3d-2d-copies
MVKCmdCopyImage: Support copies between 3D and 2D images.
2020-09-15 13:35:44 -04:00
Chip Davis
ef55ef6927 MVKSampler: Wrap MTLSamplerState creation in an autorelease pool.
Or the `MTLSamplerDescriptor` could be leaked.
2020-09-14 19:30:33 -05:00
Chip Davis
fa862c46a3 MVKCmdCopyImage: Support copies between 3D and 2D images.
This can be done by copying between each slice of the 2D image and each
plane of the 3D image individually.

This was actually quite simple to implement. I don't know why I punted
on this.
2020-09-14 19:28:09 -05:00
Chip Davis
86a1fbdb8f Destroy/free objects when configuration fails.
Prior to this, we were leaking objects after failing to configure them.
The sole exception was `VkDescriptorSet`; failed descriptor sets are
automatically returned to the pool. Now all objects are destroyed or
freed when creation fails.
2020-09-14 19:25:54 -05:00
Chip Davis
544a4a88ef MVKCmdClearColorImage: Clear linear images on Mac with a shader.
Linear textures on Mac family GPUs aren't renderable, so we cannot use
a `Clear`/`Store` `MTLRenderPass` to clear them. Instead, use a compute
shader to clear them.

I haven't expanded this to all color images, because the
`MTLTextureUsageShaderWrite` usage disables lossless compression on
Apple GPUs, but `RenderTarget` usage does not. Also, multisample
textures do not yet support writing.
2020-09-14 12:37:17 -05:00
Chip Davis
a299ee6601 MVKCmdResolveImage: Fix resolving sub-regions.
When doing multisample resolution in Metal, the dimensions of the MSAA
RT and the resolve destination must be the same. Therefore, if the
resolve region does not cover the entire destination, we must use a
temporary transfer image. This fixes a validation error in the differing
image size tests from the CTS
(`dEQP-VK.api.copy_and_blit.*.resolve_image.diff_image_size.*`).

Because the temporary transfer image has the same dimensions as the
destination and is intended to be resolved to it, copies from the source
should use the destination's parameters for the temp image. That way,
the regions show up in the correct place in the destination. This fixes
the remaining resolve tests.

Don't do expansion blits if the resolve region covers the entire
destination. This should reduce the amount of needless work we do in
that case.
2020-09-14 11:28:18 -05:00
Bill Hollings
b7b1435d8b Support Xcode 11.7. 2020-09-11 11:35:44 -04:00
Bill Hollings
e9c4b4813b Cleanup Vulkan 1.1 info.
Update remaining documents to reference Vulkan 1.1 instead of 1.0.
Per Vulkan 1.1 spec, remove now-obsolete MVKInstance code
that emits error if app requests higher Vulkan version.
Upgrade MoltenVK version to 1.1.0.
2020-09-11 11:16:34 -04:00
Chip Davis
260f9393d7 Support the VK_KHR_create_renderpass2 extension.
This will be needed for two other Vulkan 1.2 extensions,
`VK_KHR_depth_stencil_resolve` and
`VK_KHR_separate_depth_stencil_layouts`.

Most of this is just changing MVKRenderPass to store everything
internally in `RenderPass2` format. I also added some basic handling for
a few things I left out from earlier changes, input attachment aspect
masks and dependency view offsets. The former won't become important
until Metal supports depth/stencil framebuffer fetch. The latter won't
be needed until we start using untracked resources, and therefore need
to insert explicit fences and/or barriers between subpasses. We don't
need either right now, but I've handled them regardless.
2020-09-10 19:09:05 -05:00
Bill Hollings
3fccd4bcbf Fix Metal validation error when occlusion query and
renderpass are in separate Vulkan command buffers.
2020-09-10 16:41:03 -04:00
Jan Sikorski
8eeae75dc6 MVKCmdCopyImage: adjust destination extent when it's compressed 2020-09-10 14:48:39 +02:00
Bill Hollings
f7a592850b
Merge pull request #1014 from js6i/master
Store action validation warnings
2020-09-09 12:48:20 -04:00
Jan Sikorski
6cbfba085d Prevent accidental setColorStoreAction for non-color attachments 2020-09-09 10:16:36 +02:00
Chip Davis
93ee0300a9 MVKCommandEncoder: Set store override actions before finalizing draw state.
Otherwise, they could be left unset when we switch to compute in order
to set up the state for the draw call.
2020-09-08 18:52:38 -05:00
Bill Hollings
8260f44762
Merge pull request #1017 from cdavis5e/merge-pipeline-cache-owner-fix
MVKShaderLibraryCache: Fix owner of merged MVKShaderLibraries.
2020-09-08 16:54:13 -04:00
Bill Hollings
79a15b1776
Merge pull request #1016 from cdavis5e/free-descriptor-sets
MVKDescriptorPool: Only free descriptor sets it knows about.
2020-09-08 16:37:45 -04:00
Chip Davis
28b5f8c37e MVKShaderLibraryCache: Fix owner of merged MVKShaderLibraries.
When a pipeline cache were merged into another pipeline cache, we would
create new `MVKShaderLibrary` objects for each one contained in the
source. The objects would be exact copies of the originals... including
their owner, which could be destroyed after the pipeline caches were
merged. Fix the owner in the new objects to prevent a dangling
reference.
2020-09-08 13:35:02 -05:00
Chip Davis
8a30aeadbe MVKDescriptorPool: Only free descriptor sets it knows about.
Fixes a crash in `dEQP-VK.api.null_handle.free_descriptor_sets`.
2020-09-08 13:33:46 -05:00
Chip Davis
0cf2bfd1d2 Implement the vkEnumerateInstanceVersion() function.
We're Vulkan 1.1 now!
2020-09-08 13:22:17 -05:00
Chip Davis
a775263888 Implement the vkGetDeviceQueue2() function.
This function was introduced with protected memory. Since we don't
support that, right now it does nothing that `vkGetDeviceQueue()` did
not already do. Despite that, I've added a method to `MVKDevice`,
because this is an extensible function analogous to e.g.
`vkGetPhysicalDeviceFeatures2()`.
2020-09-08 13:22:17 -05:00
Chip Davis
78963db6cc Export core names of Vulkan 1.1 calls promoted from extensions.
The functions are now defined under their core names. To avoid code
bloat, I've defined the suffixed names as aliases of the core names.
Both symbols will be globally defined with the same value, and in the
dylib both will be exported.

Fix the default API version when none is given. Zero is the same as
`VK_API_VERSION_1_0`. Prior to this, we were overwriting it with zero if
no app info were given, or if it were zero in the app info. It wasn't
important before, but now that we gate API availability on maximum
Vulkan version, we need to make sure it's a valid version.
2020-09-08 13:22:17 -05:00
Chip Davis
16db5bfe63 MVKDevice: Fill in protected memory info structs.
We can't support this feature on top of Metal with the API available to
us, but we have to fill in the structures for Vulkan 1.1.
2020-09-08 13:22:17 -05:00
Chip Davis
742a2f2951 MVKDevice: Fill in feature struct for VK_KHR_shader_draw_parameters.
It's actually from Vulkan 1.1, but we'll soon support that.
2020-09-08 13:22:17 -05:00
Chip Davis
09bcd534d9 Add basic support for VK_KHR_external_semaphore{,_capabilities}.
Also a non-functional base for future extensions. We can't implement it
anyway until all remaining bugs in `MTLEvent`-based semaphores are
fixed.

This is the last of the extensions that was promoted to core for Vulkan
1.1. We're almost there!
2020-09-05 21:05:54 -05:00
Bill Hollings
697e8627cf
Merge pull request #1009 from cdavis5e/external-fence
Add basic support for VK_KHR_external_fence{,_capabilities}.
2020-09-05 21:58:24 -04:00
Chip Davis
0d4b087f3d MVKCommandBuffer: Fix a crash on starting a query outside a render pass.
This was introduced by #1006.

Fixes #1007.
2020-09-04 22:30:10 -05:00
Chip Davis
e6424654e3 Add basic support for VK_KHR_external_fence{,_capabilities}.
Like with `VK_KHR_device_group` and `VK_KHR_external_memory`, this just
adds the groundwork needed to support future extensions; it provides no
actual support for external fences.

We should be able to easily support `VK_KHR_external_fence_fd`, by using
a POSIX semaphore. Since the fence FDs produced by that extension are
opaque, only supporting `close(2)` and `dup(2)`, we shouldn't have to
worry about portable programs poking the FD in weird ways. Hopefully.

Other types of external fences we might support include GCD semaphores
(`dispatch_semaphore_t`) and Mach semaphores (`semaphore_t`). I really
think we want support for GCD semaphores, because that's the most likely
object we're going to see passed between processes on Darwin given GCD's
built-in support for XPC.

I have deliberately omitted mention of these extensions from the user
guide. `VK_KHR_external_memory` was not mentioned in there, presumably
because no actual external memory types are actually supported.

Also, add missing `vkGetInstanceProcAddr()` entry for
`vkGetPhysicalDeviceExternalBufferPropertiesKHR()`. We have the
function, and we export the extension's name string. We might as well
make it available via `vkGetInstanceProcAddr()`.
2020-09-04 13:16:54 -05:00
Chip Davis
34930eaf5b Support the VK_KHR_multiview extension.
Originally, Metal did not support this directly, and still largely
doesn't on GPUs other than Apple family 6. Therefore, this
implementation uses vertex instancing to draw the needed views. To
support the Vulkan requirement that only the layers for the enabled
views are loaded and stored in a multiview render pass, this
implementation uses multiple Metal render passes for multiple "clumps"
of enabled views.

For indirect draws, as with tessellation, we must adjust the draw
parameters at execution time to account for the extra views, so we need
to use deferred store actions here. Without them, tracking the state
becomes too involved.

If the implementation doesn't support either layered rendering or
deferred store actions, multiview render passes are instead unrolled and
rendered one view at a time. This will enable us to support the
extension even on older devices and OSes, but at the cost of additional
command buffer memory and (possibly) worse performance.

Eventually, we should consider using vertex amplification to accelerate
this, particularly since indirect multiview draws are terrible and
currently require a compute pass to adjust the instance count. Also,
instanced drawing in itself is terrible due to its subpar performance.
But, since vertex amplification on family 6 only supports two views,
when `VK_KHR_multiview` mandates a minimum of 6, we'll still need to use
instancing to support more than two views.

I have tested this extensively against the CTS. I'm very confident in
its correctness. The only failing tests are
`dEQP-VK.multiview.queries.*`, due to our inadequate implementation of
timestamp queries; and `dEQP-VK.multiview.depth.*`, due to what I assume
is a bug in the way Metal handles arrayed packed depth/stencil textures,
and which may only be a problem on Mojave. I need to test this on
Catalina and Big Sur.

Update SPIRV-Cross to pull in some fixes necessary for this to work.

Fixes #347.
2020-09-03 17:14:46 -05:00