1230 Commits

Author SHA1 Message Date
Chip Davis
387763797d Expose MTLStorageTypeMemoryless for Apple Silicon on Mac. 2020-10-29 12:39:34 -05:00
Chip Davis
d73017f4db MVKDevice: Set properties for Apple Silicon GPUs on macOS. 2020-10-28 19:35:24 -05:00
Chip Davis
2b7f9aee43 Support the VK_KHR_timeline_semaphore extension.
This implementation uses `MTLSharedEvent` where possible, and emulates
it on the host otherwise. Unlike binary semaphores, `MTLSharedEvent`s
map well to timeline semaphores; there should be no problems using them
when they're available.

I'm extremely confident in the `MTLSharedEvent`-based implementation. It
passes nearly all the synchronization tests. I'm less confident in the
emulated implementation.
2020-10-27 18:56:00 -05:00
Bill Hollings
dd08daa478
Merge pull request #1123 from cdavis5e/intel-nv-strictlines
MVKPhysicalDevice: Enable strictLines for Intel and NVIDIA.
2020-10-27 10:20:45 -04:00
Chip Davis
1aad3c3659 MVKPhysicalDevice: Enable strictLines for Intel and NVIDIA.
Both Intel and NV Vulkan drivers enable `strictLines`. My testing shows
in fact that AMD and Apple Silicon exhibit the non-strict-line behavior,
while Intel shows the strict-line behavior.
2020-10-26 17:53:27 -05:00
Chip Davis
9cf3a21b40 MVKCmdBlitImage: Add 0.5 to layer index before interpolating.
This is why the 3D blit tests failed.
2020-10-23 19:05:29 -05:00
Jan Sikorski
e7c49d4e7f MVKPipeline: shorten vertex attribute format's length when stride < size
Metal currently does not support overlapping attribute loads and asserts on
them. Prevent it by shortening format's vector length to fit within the stride,
but print a cautionary message.

An example of affected program is Kingdom Come: Deliverance, which sets
attribute format to RGBA32 in IA and binding stride to 12, while the shader
input is just a float3.
2020-10-22 18:37:41 +02:00
Jan Sikorski
9ee50b526a MVKPixelFormats: Add getName() for MTLVertexFormat 2020-10-22 18:37:41 +02:00
Bill Hollings
a71267797d Upgrade to Xcode 12.2 build settings. 2020-10-21 23:01:33 -04:00
Chip Davis
b052600404 MVKImage: Always set the depth plane when rendering to a 3D image.
Even if we used a texture view. We can't constrain the depth planes in a
3D texture using a texture view, so we need to set the render depth
plane in that case.
2020-10-21 18:04:20 -05:00
Bill Hollings
59ab58484a
Merge pull request #1117 from billhollings/master
Allow binding descriptor set using layout different than it was created with.
2020-10-21 18:06:42 -04:00
Bill Hollings
eb81f2b5be Streamline binding access in MVKDescriptorSetLayout.
Use temporary MVKSmallVector of bindings to sort dynamic offset indices.
Use getDescriptor() where in read/write functions.
2020-10-21 15:34:10 -04:00
Chip Davis
b3f828afcd MVKImageView: Always ignore transfer usages.
Transfer commands don't use image views. The transfer usages, then,
shouldn't figure into whether it's valid to use a view a particular way.
2020-10-21 10:12:45 -05:00
Bill Hollings
0738e5471b MVKDescriptorSetLayout speed up lookup of descriptor index. 2020-10-20 21:56:31 -04:00
Bill Hollings
cd9e2b0437 Allow binding descriptor set using layout different than it was created with.
Bind descriptors based on binding number within pipeline layout, not order within
layout, and descriptor set looks up descriptor using binding layout it was created with.
2020-10-20 17:24:17 -04:00
Bill Hollings
35d4e5d2d5
Merge pull request #1115 from cdavis5e/align-plane-heap-offsets
MVKImage: Make sure plane heap offsets are properly aligned.
2020-10-19 17:06:22 -04:00
Bill Hollings
90f069e86f
Merge pull request #1114 from cdavis5e/max-point-size
MVKPhysicalDevice: Reduce maximum point size to 64.
2020-10-19 15:29:59 -04:00
Chip Davis
5e832634ca MVKImage: Make sure plane heap offsets are properly aligned.
If the texture is not properly aligned, creation will fail. Make sure
we ask for enough memory to hold all planes with alignment, or a plane
could wind up beyond the bounds of the heap.
2020-10-19 14:11:05 -05:00
Bill Hollings
9290f4e3a5
Merge pull request #1113 from cdavis5e/linear-image-mtlheap
MVKImage: Always use texel buffers for linear images in MTLHeaps.
2020-10-19 15:05:20 -04:00
Chip Davis
aeb0ec2b7c MVKPhysicalDevice: Reduce maximum point size to 64.
The Metal Feature Set Tables lied. The maximum point size supported by a
device varies; values higher than the true maximum are clamped. For
example, my AMD Radeon Pro 460 clamps point sizes above 64, and my Intel
HD Graphics 530 clamps them above 256. 64 is the minimum maximum
mandated by Vulkan, so that's what we'll report.
2020-10-19 13:54:30 -05:00
Chip Davis
be0f67d79d MVKImage: Always use texel buffers for linear images in MTLHeaps.
This is particularly important if the resource will be aliased with
another resource; the memory in this case must have a linear layout.
2020-10-18 22:08:35 -05:00
Chip Davis
f0ba184c41 MVKPhysicalDevice: Correct max descriptor set resources.
The minimum number of samplers is the lesser of 96 or *n* times the
per-stage maximum, where *n* is the number of stages supported. So we
need to account for compute shaders as well as graphics pipeline
shaders.
2020-10-18 22:06:22 -05:00
Bill Hollings
af331a393f
Merge pull request #1111 from cdavis5e/capture-scope-refcount-kluge
MVKGPUCapture: Make sure the MTLCaptureScope has only one reference.
2020-10-18 15:30:52 -04:00
Bill Hollings
343a55c91a
Merge pull request #1110 from cdavis5e/cull-mode-both
MVKPipeline: Also disable rasterization if culling both sides.
2020-10-18 15:17:30 -04:00
Chip Davis
c719a4f48d MVKGPUCapture: Make sure the MTLCaptureScope has only one reference.
For some reason, when we create the `MTLCaptureScope` with capture
enabled, in addition to the reference from object creation, Metal
retains the object for no apparent reason in the base `MTLCaptureScope`
initializer. This causes us to leak the capture scope--and with it, the
queue. Let's hope Apple isn't doing anything with that extra reference.
2020-10-16 17:53:01 -05:00
Chip Davis
167fdb3821 MVKPipeline: Also disable rasterization if culling both sides.
But only if we're drawing triangles. The cull mode only applies to
triangles.

In this case, make sure we don't try to add a fragment shader.
2020-10-16 17:51:01 -05:00
Chip Davis
337362b045 MVKPhysicalDevice: Correct fragment input component limit.
Starting in iOS/tvOS 13, Apple family 4 and up support 124 fragment
input components, matching macOS. Reduce Mac max to 124 to prevent Metal
from complaining when using more than 124 components.

Tessellation control shaders must support at least 120 per-patch output
components, so make sure the limit is that value.
2020-10-16 17:49:40 -05:00
Bill Hollings
86c80008c2
Merge pull request #1104 from cdavis5e/atomic-image-address
MVKPipeline: Fix calculation of atomic image buffer addresses.
2020-10-16 18:07:54 -04:00
Chip Davis
da0872b047 MVKPipeline: Fix calculation of atomic image buffer addresses.
Align the row address using the linear texture alignment for an
`R32Uint` texture.

Pull in the SPIRV-Cross changes needed to make this work.
2020-10-16 10:26:20 -05:00
Chip Davis
92de8f0137 MVKSamplerYcbcrConversion: Always make sure there is one plane.
Otherwise, SPIRV-Cross would generate no texture variable for the
image-sampler.
2020-10-14 13:58:03 -05:00
Bill Hollings
cbf745d7c7
Merge pull request #1099 from cdavis5e/queue-capture-scope
MVKQueue: Only create one GPUCaptureScope per queue.
2020-10-13 22:36:30 -04:00
Chip Davis
91a836c8ba MVKQueue: Only create one GPUCaptureScope per queue.
The `MTLCaptureManager`--at least, the one in the capture layer--uniques
capture scopes created for queues. The two scopes we created--for
command buffer submission and surface presentation, respectively--wound
up referring to the same scope. So don't even bother creating a second
one. Use one scope for everything on the queue.

Since there's no need for the 'purpose' parameter anymore, remove it.

Honestly, I think this is a shame. It's useful to be able to create
distinct scopes for command buffer submission and swapchain
presentation. I've filed FB8791712 to get Apple to let us create
multiple scopes for a single queue. Unfortunately, until that's
resolved, because the objects are uniqued, this will interfere with a
forthcoming workaround for a retain bug in Metal relating to capture
scopes.
2020-10-12 11:02:41 -05:00
Chip Davis
c90c276250 MVKDevice: Increase minimum OS for shared-storage textures.
In #1093 it was reported that `MTLStorageModeShared` textures don't
actually work on 10.15.5, but do work on 10.15.7. I've increased the
minimum to 10.15.6 for now. If someone else reports that it doesn't work
on 10.15.6 either, I'll bump it to 10.15.7.
2020-10-12 11:00:43 -05:00
Bill Hollings
78ff57c0fe Adjust order of structs and functions of VK_EXT_private_data
extension relative to other extensions.

Also adjust a couple of other similar and outstanding orderings.
2020-10-11 13:54:20 -04:00
Bill Hollings
b71fe94558 Add support for VK_EXT_private_data extension.
Moved to a new model for creation: create and potentially destroy the object
within MVKDevice::create..., to hide it from vulkan.mm where all other object
creation errors are handled. We could move to this slowly over time.

Passes all 49 private data CTS tests.
2020-10-10 17:15:07 -04:00
Bill Hollings
7d6f68869c
Merge pull request #1096 from cdavis5e/depth-stencil-blits
MVKCmdBlitImage: Support depth/stencil blits with inversion and scaling.
2020-10-08 15:34:36 -04:00
Chip Davis
956794969c MVKCmdBlitImage: Support depth/stencil blits with inversion and scaling.
Prior to this, we weren't even setting the `BLIT_DST` bit for
depth/stencil formats. Conforming apps would thus never pass DS images
at all to `vkCmdBlitImage()`. It is now possible to do that, and even
get scaling and inversion to boot.

Stencil blits require the use of stencil feedback. If this feature isn't
available, both stencil and packed depth/stencil formats have their
`BLIT_SRC` and `BLIT_DST` features turned off, to prevent apps from
attempting to blit the stencil aspect.

There's only a couple of failing tests, involving a 1D stencil blit
(really a 2D stencil with height 1). For some reason, the fragments
produced during a scaled blit get spread out over the rendering surface.
I think this is a bug in Metal; we can't do anything about it.
2020-10-07 19:28:13 -05:00
Chip Davis
51b743b095 MVKPixelFormats: Add 0.5 ULP to clear values for normalized formats.
I've noticed that in some tests, the clear values seem to be off by
about one ULP, and the tests subsequently fail. This should cause Metal
to round up instead of down and fix those tests.
2020-10-07 19:26:57 -05:00
Bill Hollings
14b0a47251 MVKPhysicalDevice remove need to call initGPUInfoProperties() twice.
Move setting of limits from MVKPhysicalDevice::initProperties() into separate
initLimits() function. Call initProperties() before initMetalFeatures() and
initLimits() after initMetalFeatures().
2020-10-07 12:33:45 -04:00
Bill Hollings
7a259ca375 Fix potential drawable present race conditions.
Retrieve MTLDrawable when requested, not in MTLCommandBuffer scheduled
handler, in case a different drawable is established by then.
Call timed present after adding presented handler, to avoid race
condition if presentation happens before handler is added.
2020-10-06 12:45:15 -04:00
Bill Hollings
3f5c2b17af Fix MoltenShaderConverter tvOS build to support tvOS 9.0.
Move deployment target build settings from targets to projects.
Move several other target build settings from targets to projects.
2020-10-06 11:40:45 -04:00
Bill Hollings
0e72c06e68 Update Xcode build settings check to Xcode 12.0. 2020-10-05 22:46:51 -04:00
Bill Hollings
38c4921b69
Merge pull request #1090 from billhollings/drawable-present
Move Metal drawable presentation from MTLCommandBuffer to MTLDrawable.
2020-10-05 17:33:45 -04:00
Bill Hollings
3b9c48ed7d
Merge pull request #1089 from gnoliyil/planecount
MVKImage: Check plane count in IOSurface only if it has chroma subsampling
2020-10-03 16:26:27 -04:00
Bill Hollings
1b4c045707 Move Metal drawable presentation from MTLCommandBuffer to MTLDrawable.
Update MVKPresentableSwapchainImage::presentCAMetalDrawable() to create a
MTLCommandBuffer scheduled-handler and present the MTLDrawable from there.

According to Apple, it is more performant to call MTLDrawable present from within a
MTLCommandBuffer scheduled-handler than it is to call MTLCommandBuffer presentDrawable:.

Pass presentation timing info as a struct to simplify calls.
2020-10-03 16:11:25 -04:00
Yilong Li
695ad5be9f MVKImage: Check plane count in IOSurface only if it has chroma subsampling.
useIOSurface() sets the plane information in IOSurface only if
the image format has chroma subsampling. And when we import an
IOSurface, we should only check count of planes when the format
has chroma subsampling.

This resolves a crash in the following case to let two VkImages
share the same IOSurface:

```
VkImage image1, image2;

// the format in |info| is a non-chroma-subsampling format,
// e.g. R8G8B8A8_UNORM.
vkCreateImage(info, &image1);
vkCreateImage(info, &image2);

IOSurfaceRef ioSurface;
vkUseIOSurfaceMVK(image1, nil);
vkGetIOSurfaceMVK(image1, &ioSurface);
vkUseIOSurfaceMVK(image2, ioSurface);
```
2020-10-02 17:40:43 -07:00
Yilong Li
c9e727ea27 MVKImagePlane: Reset _mtlTexture after releasing.
For an MVKImage, when we call vkUseIOSurfaceMVK(),
the MTLTexture of each plane will be released but not
reset. And later when we destroy the MVKImage, the
destructor of MVKImagePlane calls releaseMTLTexture()
again, which will cause a crash because of double releasing
of an object.

To solve this we need to reset _mtlTexture to nil after
it is successfully released.
2020-10-02 17:23:56 -07:00
Bill Hollings
766e05b70c
Merge pull request #1087 from billhollings/usage-pixfmt-view
Use VK_KHR_image_format_list to disable MTLTextureUsagePixelFormatView where possible.
2020-10-02 14:28:16 -04:00
Bill Hollings
78c58cc026 Add validation policy for MoltenVK development to README.md document.
Remove unnecessary image view format validation.
2020-10-02 12:22:32 -04:00
Bill Hollings
0673e63b18 MVKImage avoid texel buffer for atomics if view format list
exists and does not include either R32_UINT or R32_SINT format.
2020-10-02 10:24:29 -04:00