1204 Commits

Author SHA1 Message Date
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
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
Bill Hollings
08f14d25e4 Propagate VkImageFormatListCreateInfo from mutable format swapchain to swapchain images. 2020-10-01 17:22:52 -04:00
Chip Davis
d6294a17d6 MVKCmdCopyImage: Only use the multi-layer copy method if available.
It is only available starting in Metal 3.0 (macOS 10.15, iOS/tvOS 13).
2020-10-01 14:51:50 -05:00
Bill Hollings
4dee7c288d MVKImageView remove obsolete test for nil image.
Update What's New document.
2020-10-01 15:23:15 -04:00
Bill Hollings
f0029f823f Use VK_KHR_image_format_list to disable MTLTextureUsagePixelFormatView where possible.
MVKImage track VkImageFormatListCreateInfo::pViewFormats
and validate MVKImageView format against them.
Add MVKImage::getMTLTextureUsage() and move tests for dedicated aliasables,
compressed formats, and minimum image usage into it.
Add MVKMTLFormatDesc::mtlPixelFormatLinear and
MVKPixelFormats::compatibleAsLinearOrSRGB()
to track linear counterparts to each Metal sRGB format.
Don't use MTLTextureUsagePixelFormatView if image will only
allow views that use same format or its sRGB/linear variation.
2020-10-01 14:58:36 -04:00
Chip Davis
23895bd988 MVKCmdCopyImage: Fix another copy-pasto. 2020-09-29 11:17:19 -05:00
Chip Davis
7c001fb666 MVKCmdCopyImage: Fix a copy-pasto.
I know I said I wouldn't have any more, but this fixes a problem with
my change #1064 that could trip Metal's validation layer and/or result in
no data being copied.
2020-09-28 18:35:25 -05:00
Bill Hollings
ec7189b3f7
Merge pull request #1080 from cdavis5e/display-timing-use-after-free
MVKSwapchainImage: Retain image and swapchain until presentation is done.
2020-09-28 13:27:25 -04:00
Bill Hollings
ccd9592d61
Merge pull request #1076 from cdavis5e/mux-switch-swapchain
MVKDevice: Only force a mux switch when a swapchain is created.
2020-09-28 12:59:39 -04:00
Chip Davis
9d21231fc2 MVKSwapchainImage: Retain image and swapchain until presentation is done.
Fixes use-after-free bugs in `VK_GOOGLE_display_timing` support.
2020-09-28 11:28:55 -05:00
Bill Hollings
1831eb9f38
Merge pull request #1079 from cdavis5e/indexed-non-indexed-tess-draw
MVKPipeline: Don't rely on the index buffer to tell apart indexed draws.
2020-09-28 12:02:52 -04:00
Bill Hollings
442f586007
Merge pull request #1078 from cdavis5e/fill-buffer-round-down
MVKCmdFillBuffer: Round size down, not up.
2020-09-28 12:01:18 -04:00
Bill Hollings
3dad0c6a04
Merge pull request #1077 from cdavis5e/end-query-outside-rp
MVKQueryPool: Fix ending a query outside a render pass.
2020-09-28 11:56:32 -04:00
Bill Hollings
cff0b6bc7a
Merge pull request #1075 from cdavis5e/shader-subgroup-extended-types
Advertise the VK_KHR_shader_subgroup_extended_types extension.
2020-09-28 11:54:45 -04:00
Bill Hollings
299a937887
Merge pull request #1073 from cdavis5e/aliasable-dedicated-alloc
Allow multiple images for dedicated allocs of aliasabled images.
2020-09-28 11:50:04 -04:00
Chip Davis
481fe3553d MVKPipeline: Don't rely on the index buffer to tell apart indexed draws.
This was a good heuristic, because the index buffer must be bound for
indexed draws. However, it may also be bound for non-indexed draws--for
example, if an indexed draw were immediately followed by a non-indexed
draw, as happens in some `dEQP-VK.synchronization.*` tests. Therefore,
we can't tell from the presence or absence of the index buffer what kind
of draw we're in. We'll have to keep track of this state in the command
encoder.
2020-09-28 00:43:53 -05:00
Chip Davis
5794503876 MVKCmdFillBuffer: Round size down, not up.
According to the Vulkan spec:

> If `VK_WHOLE_SIZE` is used and the remaining size of the buffer is not
> a multiple of 4, then the nearest **smaller** multiple is used.
> [emphasis added]

Therefore, we should round down when calculating the number of words to
write.
2020-09-26 01:20:57 -05:00
Chip Davis
bbe45e4a8a MVKQueryPool: Fix ending a query outside a render pass.
I missed this when I fixed occlusion queries begun outside a render
pass.
2020-09-25 15:24:50 -05:00
Chip Davis
ee59948ed8 MVKDevice: Only force a mux switch when a swapchain is created.
We only want the window server to use the high-performance GPU if we
will use it to present to the display. If we won't use it to present, we
can save some battery life by not using the display. I had hoped this
would help window server stability in case something goes horribly
wrong while using the GPU, but my experience has sadly not borne this
out.

My testing shows that the device returned by
`MTLCreateSystemDefaultDevice()` is exactly equal (i.e. has the same
pointer value) to one of the devices returned by `MTLCopyAllDevices()`,
so we should see no problems from doing this at swapchain create time
instead of device create time.
2020-09-25 15:16:01 -05:00
Chip Davis
0a7d2af989 Advertise the VK_KHR_shader_subgroup_extended_types extension.
I anticipated this, and I tried to design the support in SPIRV-Cross so
that this would just work. And they do... well, they work as well as
32-bit types currently do, which is to say, there's plenty of room for
improvement.
2020-09-25 15:13:12 -05:00
Chip Davis
9321b5553f Allow multiple images for dedicated allocs of aliasable images.
Believe it or not, this is valid usage. If an image is aliasable and it
has a dedicated alloc, it is valid for multiple images to bind to the
dedicated memory. Some tests actually try this--for example, the
`dEQP-VK.device_group.afr_dedicated` test.
2020-09-25 15:11:36 -05:00
Chip Davis
f1cbac1629 MVKPipeline: Use arrayed textures for layered subpass input.
Normally, we would have to check the framebuffer, but we don't know its
contents until draw time. To avoid yet another situation where we must
compile multiple pipelines, I've used a simple heuristic: if the vertex
pipeline writes to `BuiltInLayer`, this is likely for a layered
framebuffer, and we should use `texture_2darray` for subpass input.
Hopefully this is good enough for all intents and purposes. If not, then
we really will have to wait until draw time. And God help us if someone
try to do this with a 3D texture!
2020-09-25 10:30:42 -05:00
Bill Hollings
655b15a609
Merge pull request #1072 from cdavis5e/subgroup-size-vendor
MVKPhysicalDevice: Get the vendor ID before setting the subgroup size.
2020-09-25 10:52:21 -04:00
Bill Hollings
4e6930d9d9
Merge pull request #1069 from cdavis5e/2d-attachment-view
MVKImageView: Use a 2D non-arrayed view for 2D non-arrayed attachments.
2020-09-25 10:19:50 -04:00
Chip Davis
ce0c107317 MVKPhysicalDevice: Get the vendor ID before setting the subgroup size.
At this point in device initialization, the device properties have not
yet been initialized. Unfortunately, this includes the vendor ID, on
which the maximum SIMD-group size depends. Initialize that property so
we can use it to set the subgroup size correctly.
2020-09-24 21:58:40 -05:00
Chip Davis
832213b0e3 MVKImageView: Use a 2D non-arrayed view for 2D non-arrayed attachments.
If a shader uses an input attachment and doesn't do layered rendering,
but the image view is of type `MTLTextureType2DArray`, Metal's
validation layer will complain about the texture type mismatching what
the shader expects. This change makes the texture types line up.
2020-09-24 19:56:01 -05:00
Bill Hollings
6588ac8fd5
Merge pull request #1071 from cdavis5e/render-area-size-min
Ensure there is at least one pixel in the render area.
2020-09-24 17:50:09 -04:00