1104 Commits

Author SHA1 Message Date
Chip Davis
278a7208ca MVKImage: Handle VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT.
Only set `MTLTextureUsagePixelFormatView` if this bit is set. This
should reduce the usage of this bit, which disables lossless compression
on Apple GPUs, in many cases.

We continue to set it anyway for `VK_IMAGE_USAGE_TRANSFER_SRC_BIT`; this
is because we create those texture views on the application's behalf, to
implement `vkCopyImage()` where the source and destination formats do
not agree. We also continue to set it for depth/stencil formats; Metal
requires it in order to use only the stencil aspect in a view.
2020-09-21 16:01:36 -05:00
Bill Hollings
cadc011c67
Merge pull request #1050 from cdavis5e/image-extended-usage
MVKImage: Handle VK_IMAGE_CREATE_EXTENDED_USAGE_BIT.
2020-09-21 16:43:22 -04:00
Chip Davis
3a97b1b810
Merge pull request #1049 from cdavis5e/mac-linear-images-ios-fix
Fix iOS build again.
2020-09-21 14:27:11 -05:00
Chip Davis
f5897fcc0c MVKImage: Handle VK_IMAGE_CREATE_EXTENDED_USAGE_BIT.
If this bit is set, add `MTLTextureUsage` bits for features supported by
all possible view formats, not just the image format. Happily, Metal's
API validator layer is OK with this.

This is needed for the mutable format tests, which use this bit with a
format that doesn't support writing, then casts the image to a format
which does.
2020-09-21 13:53:24 -05:00
Chip Davis
7b0f08ea1f Fix iOS build again.
Only do the managed-storage check on Mac.
2020-09-21 13:50:44 -05:00
Bill Hollings
1423930408
Merge pull request #1048 from cdavis5e/depth-stencil-resolve
Support the VK_KHR_depth_stencil_resolve extension.
2020-09-21 14:49:21 -04:00
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
Chip Davis
1f1726647e MVKImage: Fix broken getMemoryRequirements2().
We were looking in the wrong chain for the
`VkImagePlaneMemoryRequirementsInfo` struct. We were also failing to
call through to the `MVKImageMemoryBinding` to get dedicated
requirements, which broke dedicated memory.

Clearly, I failed to properly review the patch which refactored
`MVKImage` for `VK_KHR_sampler_ycbcr_conversion`.
2020-09-21 12:57:15 -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