487 Commits

Author SHA1 Message Date
Bill Hollings
0ce9fccd17
Merge pull request #559 from cdavis5e/rtarray-a12-fix
Actually set the renderTargetArrayLength property on iOS 12.
2019-04-01 21:56:18 -04:00
Chip Davis
9736aace54 Detect surface loss in the swapchain on iOS as well. 2019-04-01 16:43:13 -05:00
Chip Davis
d24ddb1831 Add missing braces. 2019-04-01 16:28:27 -05:00
Chip Davis
77ddaff4d4 Actually set the renderTargetArrayLength property on iOS 12.
Fixes #558.
2019-04-01 13:42:35 -05:00
Chip Davis
b8f22700d5 Handle surface loss.
Sometimes, the `CAMetalLayer` backing a view can be replaced--for
example, when the window is moved to another screen, or the style bits
on the window are changed. In that case, we must allow the client the
opportunity to recreate the surface and swapchain.

Layer-backed views always set themselves as the layer's delegate; we use
this fact to Key-Value Observe the view's `layer` property.

Other alternatives considered:

* Registering for `NSViewGlobalFrameDidChange` notifications. Aside from
  only working on macOS, this doesn't actually catch every case where we
  want to report a lost surface. I'm not even sure it works at all for
  Metal.
* Holding a reference to the view, and checking when its layer property
  has changed.
* Holding a weak reference to the layer; that way, the reference will
  become `nil` when the layer is replaced. But this requires ARC.
2019-04-01 13:11:01 -05:00
danginsburg
7199c2570b Fix https://github.com/KhronosGroup/MoltenVK/issues/553 by making the Metal renderpass descriptor width/height clamped to the renderArea including the offset, not just the extent. 2019-03-29 14:32:27 -04:00
Hans-Kristian Arntzen
38edfdb3de Override namespace for SPIRV-Cross.
Some projects also link against SPIRV-Cross statically, and in order to
avoid ABI conflicts, we should use a private namespace for the
SPIRV-Cross dependency to avoid bugs. See SPIRV-Cross issue #902 for
more information. The new namespace is MVK_spirv_cross, and the code
now makes use of the SPIRV_CROSS_NAMESPACE macro rather than spirv_cross.
2019-03-29 11:34:55 +01:00
Bill Hollings
9536538035
Merge pull request #547 from HansKristian-Work/vkcmdfillbuffer-offset-crash
Fix wrong offset for vkCmdFillBuffer on VK_WHOLE_SIZE.
2019-03-27 22:46:55 -04:00
Bill Hollings
29f32a3e4c
Merge pull request #545 from cdavis5e/fix-private-buffer-views
Set options properly on a buffer view's MTLTextureDescriptor.
2019-03-27 22:44:57 -04:00
Chip Davis
354dc32fb9 Set options properly on a buffer view's MTLTextureDescriptor.
The resource options must match between an `MTLBuffer` and any linear
texture created from it. Further, to be writable, the
`MTLTextureDescriptor` should have the `MTLTextureUsageShaderWrite` bit
set.

Fixes #542.
2019-03-27 13:56:42 -05:00
Hans-Kristian Arntzen
bfd4d182cd Fix wrong offset for vkCmdFillBuffer on VK_WHOLE_SIZE.
A double offset would be applied, causing the word count to wrap around
and trigger an assertion and GPU lockup.
2019-03-27 19:56:35 +01:00
Bill Hollings
32137e6da9 Fixed crash within MVKPushConstantsCommandEncoderState when accessing absent
graphics pipeline during a compute stage.

MVKPushConstantsCommandEncoderState test for tessellation only during graphics stages.
Guard against possible missing graphics pipeline even during graphics stages.
2019-03-27 12:40:58 -04:00
Bill Hollings
f31a56a93c Support null device in MVKBaseDeviceObject and MVKDispatchableDeviceObject instances. 2019-03-26 16:49:23 -04:00
Bill Hollings
b3240794fc Fix PVRTC texture content loading via memory mapping.
MoltenVK_Runtime_UserGuide.md: Add limitation explanation
about loading PVRTC using host-visible memory only.
Update What's New document.
2019-03-26 13:31:26 -04:00
Bill Hollings
e4d96f6fa2 Support Xcode 10.2. 2019-03-26 11:50:39 -04:00
Bill Hollings
91f78b6bea Add support for tracking device features enabled during vkCreateDevice().
Enable device features based on content of pCreateDeviceInfo.
Validate requested features are available and return  if not.
Support returning error from vkCreateDevice(), vkFlushMappedMemoryRanges()
and vkInvalidateMappedMemoryRanges().
Update What's New Document.
2019-03-25 19:58:36 -04:00
Bill Hollings
cc2dd1cc21 Clean up sparse binding functions.
Remove "unimplemented" error reporting from sparse binding functions.
As per Vulkan spec, sparse binding query functions simply return zero responses.
vkQueueBindSparse() returns VK_ERROR_FEATURE_NOT_PRESENT error.
2019-03-25 11:48:48 -04:00
Bill Hollings
0ac1edbac0 Project build enhancements, and MoltenVKShaderConverter
tool now validates converted MSL with a test compilation.

Project build scripts now build dylib and framework in separate build directories
to enable MoltenVKShaderConverter to link to static library instead of dynamic library.
Final Package structure remains the same.
In Debug build, copy dylib dSYM files to Package.
Package/Latest directory now links relative to local Debug or Release directory.
Add install option to Makefile.
MoltenVKShaderConverter tool now validates converted MSL with a test compilation.
Clean up various MSL conversion and compilation error logging.
MVKCommandResourceFactory wrap Metal library compile with autorelease pool.
Build ExternalDependencies with same symbol hiding as MoltenVK to suppress visibility warnings.
Update What's New document.
2019-03-22 19:36:21 -04:00
Chip Davis
316429225a Fix updating push constants for tessellation shaders.
Missed this when I was initially implementing this.
2019-03-22 12:57:09 -05:00
Chip Davis
4b0d84e576 vkCmdBlitImage: Remove check for invalid behavior.
According to the Vulkan spec:

> * If either of `srcImage` or `dstImage` was created with a
>   depth/stencil format, the other **must** have exactly the same format

So this should not happen in well-behaved clients.
2019-03-21 15:45:08 -05:00
Bill Hollings
bdaf306233 Update VK_KHR_swapchain and VK_KHR_get_surface_capabilities2 extensions.
Add support for VK_KHR_get_surface_capabilities2 extension.
Implement newer VK_KHR_swapchain extension functions.
Fix when the following functions return VK_INCOMPLETE:
    vkGetPhysicalDeviceSurfaceFormatsKHR()
    vkGetSwapchainImagesKHR()
    vkEnumeratePhysicalDevices()
    vkEnumerateInstanceLayerProperties()
    vkGetPhysicalDeviceQueueFamilyProperties()
CTS: Pass supported *.macos.surface.* and *.macos.swapchain.* tests.
Update What's New document.
2019-03-21 08:53:18 -04:00
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