666 Commits

Author SHA1 Message Date
Bill Hollings
522f3ad0d4 Merge branch 'master' of https://github.com/KhronosGroup/MoltenVK 2019-03-21 07:07:31 -04:00
Chip Davis
06babd1cdb Move feature setting into the macOS-specific block. 2019-03-20 10:31:58 -05:00
Chip Davis
0a44de3889 MVKDevice: Don't enable the shaderStorageImageArrayDynamicIndexing feature on iOS.
iOS does not actually support arrays of writable textures. At all.
2019-03-20 09:59:51 -05:00
Bill Hollings
614ac65933 Add correct function entry point handling.
Add MVKEntryPoint struct to track entry points as
instance vs device, and core vs enabled extensions.
Add stubs for newer VK_KHR_swapchain functions.
Pass CTS dEQP-VK.api.version_check.entry_points.
Update What's New document.
2019-03-19 16:43:04 -04:00
Chip Davis
4468f36bc6 Support the VK_EXT_host_query_reset extension.
This allows clients to reset query pools on the host, instead of with a
GPU command.

This updates Vulkan headers to 1.1.104... but, there's a problem. This
change has not been merged to `master` in the `Vulkan-Headers` repo yet,
because of an issue building the C++ binding headers. Luckily, we only
need the core C header.
2019-03-17 19:59:15 -05:00
Bill Hollings
caba1186e4
Merge branch 'master' into tessellation 2019-03-15 16:11:11 -04:00
Bill Hollings
e13444e305 Allow zero offset and stride combo in VkVertexInputBindingDescription.
Also fix memory overrun if no VB found with same binding as a VA.
2019-03-14 17:50:20 -04:00
Bill Hollings
05b14366da Use autorelease pool for synchronous command buffer submissions also. 2019-03-12 17:36:01 -04:00
Chip Davis
6061614895 Fix case where all attributes are skipped.
If none of the attributes in a buffer is used but still present, then
the offset will be non-zero, leading us to set a non-zero stride for a
vertex buffer that is not used. This is invalid.

Fixes tessellation in Final Fantasy XIV.
2019-03-11 14:19:49 -05:00
Chip Davis
d50e654acd Fix a possible race condition around MVKMTLBufferAllocation.
I don't think a race is actually possible here, but this makes Thread
Sanitizer happy.
2019-03-11 14:19:49 -05:00
Chip Davis
a1be5a37d3 Fix broken indirect non-tessellated draws. 2019-03-11 14:19:49 -05:00
Chip Davis
d7e0167b43 Fix more brokenness. 2019-03-11 14:19:49 -05:00
Chip Davis
1069786f25 Fix a broken change from the last commit. 2019-03-11 14:19:49 -05:00
Chip Davis
34047f83f9 Only compile in tessellation support kernels on Metal 1.2+.
And set the stage-in indirect params on 2.1+. I missed this when I added
setting the stage-in region.
2019-03-11 14:19:49 -05:00
Chip Davis
cb8a678c28 Fix stride of stage input arrays to tessellation shaders.
These should be set to the alignment of the first member of the output
struct. This fixes the `dEQP-VK.tessellation.common_edge.*` tests.
2019-03-11 14:19:49 -05:00
Chip Davis
069ee53ac5 Exclude the PointSize builtin when we're not rendering points.
And fix a silly mistake I made setting up the tess. control stage
pipeline.
2019-03-11 14:19:49 -05:00
Chip Davis
403d52d9fa Correct passing the tessellation level builtins around. 2019-03-11 14:19:49 -05:00
Chip Davis
075792e436 Reverse tessellation windings from SPIR-V.
Because we flip the direction of `y`, we need to reverse the windings.
2019-03-11 14:19:49 -05:00
Chip Davis
bfdf0c4233 Set the stage in region for tess. control invocations.
Otherwise, Metal won't fetch any stage input.
2019-03-11 14:19:49 -05:00
Chip Davis
b78235045c Fix a reversed condition.
I have to stop doing that...
2019-03-11 14:19:49 -05:00
Chip Davis
58dbdcdab4 Make sure there's enough space in the tess ctl output buffer. 2019-03-11 14:19:49 -05:00
Chip Davis
79d434553c Add support for tessellation.
At long last, tessellation comes to MoltenVK! With this change, clients
will now be able to specify tessellation shaders when creating
pipelines, and then draw tessellated patches with them.

Unfortunately, there seem to be a few gotchas with tessellation in
Metal. For one thing, tessellation pipelines in Metal are structured
very differently from Vulkan. There is no tessellation control or even
vertex stage. Instead, the tessellation evaluation shader takes the
place of the vertex function as a "post-tessellation vertex function."
The tessellation levels are supplied in a buffer to the tessellator,
which you are expected to populate. The most common way to do this is by
running a compute shader. MoltenVK thus runs the vertex shader and
tessellation control shader by themselves; a single `VkPipeline` object
then requires at least *three* `MTLPipelineState` objects.

But wait, there's more! The tessellation-control-as-compute stage uses
Metal's support for vertex-style stage input to a compute shader. But,
this support requires one to declare indexing *ahead of time*, when the
pipeline state is created. So a single `VkPipeline` object could have as
many as *five* `MTLPipelineState` objects.

Further, if there are more output than input control points for the
tessellation control stage, then later invocations may end up fetching
the wrong attributes! To get around this, this change uses index buffers
to ensure that all tessellation control shaders see the correct input.
Unfortunately, in the indexed draw case, this means that the incoming
index buffer needs to be munged.

Instancing is another pain point here. In Vulkan, as in OpenGL and
Direct3D, instancing is done in the vertex shader; but in Metal, it is
done at the tessellation evaluation stage. For this reason, only the
vertex stage of a tessellated draw supports instancing. Additional
memory is required to hold data for the extra vertices generated by
instancing. This also requires still more munging of index buffers for
indexed draws.

Indirect draws are even more painful. Because the number of vertices and
instances is unknown, storage for the maximum possible number of
vertices must be allocated. This change imposes a totally arbitrary
limit of 131072 vertices from a single draw, including all vertices
generated by instancing. On a Mac, this requires about 194-256 MB of
VRAM for all the temporary buffers.

There are some possible optimizations here. If we could prove that the
vertex shader's output doesn't depend on the instance ID, either
directly or through a per-instance attribute, then we could avoid
running the vertex and tess. control stages per instance, and take
advantage of Metal's support for tess. eval instancing. If we could
also prove that the vertex shader simply passes instance attributes
through (similarly with the tess. control shader), we could do this for
many more instanced draws as well. It should also be possible to cache
the output from the tess. control stage; if the draw comes up again, we
can then skip the vertex and tess. control stages entirely!

Fixes #56 and #501.
2019-03-11 14:19:49 -05:00
Bill Hollings
3b1e53002e Increase shader float constant accuracy beyond 6 digits of precision. 2019-03-06 08:58:27 -05:00
Bill Hollings
0984b11bc0 Set MSL version for shader compiling from Metal feature set.
Add MVKPhysicalDeviceMetalFeatures::mslVersionEnum and set from Metal feature sets.
Derive MVKPhysicalDeviceMetalFeatures:: mslVersion from mslVersionEnum.
MVKDevice::getMTLCompileOptions() sets MTLCompileOptions::languageVersion
from MVKPhysicalDeviceMetalFeatures::mslVersionEnum.
MVKAssert logs error even when assertions disabled.
Update VK_MVK_MOLTENVK_SPEC_VERSION to 18.
2019-02-25 18:11:47 -05:00
Bill Hollings
5e0f624b34
Merge pull request #505 from cdavis5e/no-storage-image-ms
Disable the shaderStageImageMultisample feature.
2019-02-19 02:12:33 -05:00
Chip Davis
b98b47501d Disable the shaderStageImageMultisample feature.
While Metal *does* allow read access to multisampled textures, it does
*not* allow write access. In Vulkan, storage images are always writable.
Therefore, we can't fully support this feature.
2019-02-18 21:44:34 -06:00
Bill Hollings
6f2dc4bdcb Add static and dynamic libraries to MoltenVKShaderConverter project.
Refactor build scripts.
Update paths to MoltenVKGLSLToSPIRVConverter framework in demos.
Fix rare build race condition on MoltenVKShaderConverter link to MoltenVK.
2019-02-18 22:19:37 +00:00
Chip Davis
e81bd4b25d Turn on shaderInt8.
Now that SPIRV-Cross is updated to support it, we can safely advertise
this.

Fixes #372.
2019-02-11 12:41:10 -06:00
Bill Hollings
e0b75dbc2c Fix crash from use of MTLDevice registryID on early OS versions.
Add mvkGetRegistryID() function to check OS support for registry ID.
Rename build setting MVK_FORCE_LOW_POWER_GPU to MVK_CONFIG_FORCE_LOW_POWER_GPU
and make it an env var / build setting combo.
Rename env var MVK_LOG_LEVEL to MVK_CONFIG_LOG_LEVEL.
Rename MVKLogging.mm to MVKLogging.cpp.
2019-02-11 10:49:58 -05:00
Bill Hollings
d83d934150 Update to latest version of SPIRV-Cross.
Track version of spvAux buffer struct in SPRIV-Cross and
fail build if different than version expected by MoltenVK.
Update MoltenVK version to 1.0.33.
Update What's New document.
2019-02-08 21:31:14 -05:00
Bill Hollings
94404ae0da
Merge pull request #489 from cdavis5e/quiesce-swizzle-log
Only warn on non-default swizzles when fullImageViewSwizzle is off.
2019-02-07 16:35:34 -05:00
Chip Davis
1652f6d719 Don't warn at all on pipelines with full swizzling support.
This could happen, for example, if image views with a non-default
swizzle are used with shaders that don't sample those images. In this
case, MoltenVK will warn, because the pipeline said not to set up the
aux buffer.
2019-02-06 13:17:50 -06:00
Chip Davis
f1c5c79365 Only warn on non-default swizzles when fullImageViewSwizzle is off.
Otherwise, the log will be spammed with hundreds of useless messages
that the `IDENTITY` swizzle is not supported.
2019-02-05 13:56:45 -06:00
Bill Hollings
8e02a5d2f3 Add GPU device ID for iOS A12 SoC. 2019-02-04 10:15:03 -05:00
Chip Davis
8307a66f80 Use the device's registryID property to locate it in IOKit.
This should be better behaved with systems that have more than one GPU
and aren't e.g. MacBooks with graphics switching.
2019-01-31 19:34:01 -06:00
Bill Hollings
e4c196c3b6
Merge pull request #484 from cdavis5e/memory-budget
Support the VK_EXT_memory_budget extension.
2019-01-31 16:12:07 -06:00
Chip Davis
3df6d2d00f Support the VK_EXT_memory_budget extension.
This requires macOS 10.13 or iOS 11, for the `currentAllocatedSize`
property of `MTLDevice`. Ideally, we'd check for that method instead of
keying on the version.
2019-01-31 12:10:57 -06:00
Bill Hollings
216e86de19 Allow logging level to be controlled via runtime environment variable. 2019-01-29 21:10:31 -05:00
Bill Hollings
18a31fb3dd vkSetMTLTextureMVK() function retains texture object. 2019-01-28 17:09:57 -05:00
Bill Hollings
e703705a9a
Merge pull request #479 from cdavis5e/yet-more-features
MVKDevice: Correct some more features and limits.
2019-01-28 16:06:18 -06:00
Chip Davis
34c7f6c09c MVKDevice: Correct some more features and limits.
Actually turn on the `layeredRendering` feature for A12 on iOS. This
should actually allow clients to take advantage of that on A12 devices.

Turn on the `variableMultisampleRate` and `inheritedQueries` features.
`variableMultisampleRate` means that pipelines with no attachments may
have different sample counts. Since no-attachment pipelines are
emulated, we don't have that limitation anyway. If and when Metal gains
real support for no-attachment pipelines, we may have to revisit this.

`inheritedQueries` means that queries may apply to secondary command
buffers as well as primary commands. Secondary command buffers are also
emulated, and should by virtue of being inlined into the primary's
`MTLCommandBuffer` inherit any query-related state.

Use the `maxBufferLength` property of `MTLDevice` when available to get
the true maximum buffer size. (This is one of the "secret" properties in
earlier versions of Metal. It finally became a public, supported API in
Metal 2.1.)

Limit the number of dual-source blending color attachments to 1. This is
a documented limitation of Metal 1.2. I don't know if Metal 2 or 2.1
have lifted this restriction.

Indicate that this implementation uses the standard sample locations.
For Metal, these are actually documented in "Using Programmable Sample
Positions," which discusses setting custom sample locations. The default
sample locations given there are all consistent with the standard
locations documented in the Vulkan spec.
2019-01-28 14:12:28 -06:00
Bill Hollings
64ca492696 Advertise VkPhysicalDevicePortabilitySubsetFeaturesEXTX::standardImageViews
enabled if MVKConfiguration::fullImageViewSwizzle enabled.
2019-01-28 13:55:43 -05:00
Chip Davis
cedaed7d7e Advertise support for the separateStencilMaskRef portability feature.
Why was this turned off? Pretty sure Metal supports this.
2019-01-27 23:01:08 -06:00
Bill Hollings
e5a890775b Add support for VK_EXTX_portability_subset extension.
Add KhronosGroup/Vulkan-Portability as external dependency repo.
Add ExternalRevisions/Vulkan-Portability_repo_revision.
Add vk_extx_portability_subset.h header file to mvk_vulkan.h.
MVKImageView allow constructor with no image or device.
Add mvkVkComponentMappingsMatch() & mvkVkComponentSwizzlesMatch() functions.
Cleanup some local var init warnings.
2019-01-27 19:52:59 -05:00
Bill Hollings
100848304d Minor leftover cleanup from MVKVector. 2019-01-23 20:29:04 -06:00
Bill Hollings
01e7da2a50
Merge pull request #460 from aerofly/master
Missing functions for MVKVector
2019-01-23 20:00:25 -05:00
Chip Davis
69dabceaf1 MVKDevice: Correct returned values from getImageFormatProperties().
According to the Vulkan spec:

> `sampleCounts` will be set to `VK_SAMPLE_COUNT_1_BIT` if at least one
> of the following conditions is true:
>
> * `tiling` is `VK_IMAGE_TILING_LINEAR` [we already handled this]
> * `type` is not `VK_IMAGE_TYPE_2D`
> * `flags` contains `VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT`
> * Neither the `VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT` nor the
>   `VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT` flag in
>   `VkFormatProperties::optimalTilingFeatures` returned by
>   `vkGetPhysicalDeviceFormatProperties` is set

Use the maximum cube dimensions for cube-compatible images. It makes no
difference in practice, since the maximum dimensions of a cube and a 2D
image are the same on all platforms and devices, but this seems more
correct to me.
2019-01-22 19:05:11 -06:00
Bill Hollings
ab59655a72
Merge pull request #466 from cdavis5e/no-atomic-image
Stop advertising atomic image support.
2019-01-22 12:29:38 -08:00
Bill Hollings
663e56f8c9
Merge pull request #465 from cdavis5e/more-features-ios
Support some more features on iOS.
2019-01-22 11:52:59 -08:00
Chip Davis
ee0c59cd9f Stop advertising atomic image support.
We don't support this on any format--not even `VK_FORMAT_R32_UINT`,
which is the only format the spec requires support for. I'm still
waiting for Apple to add support for this to Metal. Until then, stop
telling applications they can use this.
2019-01-22 13:38:11 -06:00