341 Commits

Author SHA1 Message Date
Chip Davis
e9158463a6 On macOS, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 can only be filtered. 2018-12-11 17:40:21 -06:00
Chip Davis
15b67b4311 On macOS, linear textures cannot be blitted to.
Since they cannot be render targets.

I wonder if we could work around that using a shader.
2018-12-11 17:40:21 -06:00
Chip Davis
35573832dc Give every image format we support the BLIT_SRC feature.
All that is required is that we can either read the format
(`TRANSFER_SRC`) or sample from it (`SAMPLED_IMAGE`). Every image format
that Metal supports supports those two features.

This marks the depth/stencil formats as able to be the source of a
blit. The spec requires in particular that `D16_UNORM` and `D32_SFLOAT`
support that.
2018-12-11 17:40:21 -06:00
Chip Davis
282699d755 Depth formats cannot be used for a VkBufferView.
It is not possible to create a linear texture from a depth/stencil
format. Therefore, we can't support buffer views in these formats.
2018-12-11 17:40:21 -06:00
Chip Davis
a1d8de5da2 Correct supported features of compressed formats.
Compressed formats only support reading and filtering. They also can't
be used to create linear textures, so they can't be used for buffer
views, either.
2018-12-11 17:40:21 -06:00
Chip Davis
5c65330e50 Add some more vertex formats.
Use `MTLVertexFormatChar`, `UChar`, `Short`, `UShort`, and `Half` when
available. Add `MTLVertexFormatUChar4Normalized_BGRA` for
`VK_FORMAT_B8G8R8A8_UNORM`.

These are only available on Metal 2.0 (iOS 11, macOS 10.13) and up, so
this adds what MoltenVK was using before as a fallback, similar to how
some `MTLPixelFormat`s have substitutes.
2018-12-11 17:40:21 -06:00
Bill Hollings
03086fbd86
Merge pull request #388 from cdavis5e/fix-khr-maintenance3
Use MVKDevice::getMVKDevice() to get the real underlying device.
2018-12-11 18:24:27 -05:00
Bill Hollings
5633cc58e3
Merge pull request #387 from cdavis5e/all-unused-attachments-3
MVKGraphicsPipeline: Add dummy attachments even when rasterization is off.
2018-12-11 18:20:42 -05:00
Bill Hollings
aad5ba63a3
Merge pull request #386 from cdavis5e/cmd-transfer-8bit-format
Don't use char/uchar for clearing/copying 8-bit formats.
2018-12-11 18:19:42 -05:00
Bill Hollings
c9475cb464
Merge pull request #384 from cdavis5e/a8b8g8r8-pack32
Support A8B8G8R8_PACK32 formats.
2018-12-11 18:14:48 -05:00
Chip Davis
39afc5d553 Use MVKDevice::getMVKDevice() to get the real underlying device.
Mea culpa.
2018-12-11 15:28:03 -06:00
Chip Davis
cb583fa8e3 MVKGraphicsPipeline: Add dummy attachments even when rasterization is off.
Turns out I was wrong. Metal expects at least one attachment to define
the size of the framebuffer, whether or not rasterization is on.
2018-12-11 15:25:54 -06:00
Chip Davis
569879a10e Don't use char/uchar for clearing/copying 8-bit formats.
Metal doesn't allow using that as a texture's sampled data type or as a
fragment shader's output type.
2018-12-11 15:24:48 -06:00
Chip Davis
b413ec1676 MVKImage: Don't set MTLTextureUsageRenderTarget for non-blittable formats.
Setting that usage bit on a non-renderable format, especially a
compressed one, will cause Metal to crash. (And I mean crash, without
raising an assertion failure.)
2018-12-11 15:23:36 -06:00
Chip Davis
c80c42dedd Support A8B8G8R8_PACK32 formats.
Because they're packed formats, they correspond to
`MTLPixelFormatRGBA8`. In fact, these formats would only be distinct on
a big endian system, and no current Apple hardware is big endian
anymore.
2018-12-11 15:21:30 -06:00
Bill Hollings
0764843898
Merge pull request #383 from cdavis5e/memory-bind-after-map
MVKDeviceMemory: Try creating an MTLBuffer before allocating heap memory.
2018-12-11 16:09:20 -05:00
Bill Hollings
570c67c5dc
Merge pull request #382 from cdavis5e/sparse-props
Explicitly set number of sparse image property/requirement info sets to 0.
2018-12-11 15:50:45 -05:00
Bill Hollings
a98d1a989c
Merge pull request #381 from cdavis5e/asan-build
Build the dylib with -fsanitize=address when asan is enabled.
2018-12-11 15:50:03 -05:00
Bill Hollings
7c03db9e4f
Merge pull request #380 from cdavis5e/debug-dsym-file-2
Fix name of generated dSYM file.
2018-12-11 15:49:09 -05:00
Bill Hollings
c6cca34510
Merge pull request #379 from cdavis5e/2dms-array-image-2
MVKImage: Support image views of 2D multisample array images.
2018-12-11 15:48:17 -05:00
Bill Hollings
15a52437f2
Merge pull request #378 from cdavis5e/pack16-formats
Correct mapping of packed 16-bit formats.
2018-12-11 15:47:05 -05:00
Chip Davis
b64485bf2a MVKDeviceMemory: Try creating an MTLBuffer before allocating heap memory.
If the device memory is subsequently bound to a `VkBuffer` after it has
been mapped, the heap memory will be freed, leaving dangling pointers in
the client. Instead, create an `MTLBuffer` right away--it is *device*
memory after all--and use its memory.

Another option might be to use `-[MTLDevice
newBufferWithBytesNoCopy:length:options:deallocator:]`, but that
requires that the entire allocation come from a single contiguous
virtual memory mapping, a requirement that is not necessarily satisfied
by `malloc(3)` memory.

Fixes #377.
2018-12-10 14:55:49 -06:00
Chip Davis
1d2da75eb5 Explicit set number of sparse image property/requirement info sets to 0.
Since these functions return void, there's no indication of an error
from them.
2018-12-10 14:54:23 -06:00
Chip Davis
aec492cfca Build the dylib with -fsanitize=address when asan is enabled. 2018-12-10 14:53:23 -06:00
Chip Davis
63b291a6c1 Fix name of generated dSYM file. 2018-12-10 14:52:24 -06:00
Chip Davis
8b0ea361f1 MVKImage: Support image views of 2D multisample array images.
A bit that I missed in my initial change to add this.
2018-12-10 14:50:47 -06:00
Chip Davis
46c1081456 Correct mapping of packed 16-bit formats.
Metal always gives the components in little endian order, while Vulkan
always lists them in big endian order. This also brings us more in line
with the spec, which says that the formats
`VK_FORMAT_R5G6B5_UNORM_PACK16` and `VK_FORMAT_A1R5G5B5_UNORM_PACK16`
must be supported.

Fixes #353.
2018-12-10 14:48:22 -06:00
Bill Hollings
5299879d04 Merge branch 'master' of https://github.com/KhronosGroup/MoltenVK 2018-12-08 14:13:50 -05:00
Bill Hollings
f459bf34e3 Retrieve linear image memory alignment requirements from Metal device.
Add mvkMTLPixelFormatLinearTextureAlignment() function.
Add MVKDevice::getVkFormatTexelBufferAlignment() and use for Linear image memory alignment.
For non-linear image memory alignment, use mvkVkFormatBytesPerBlock().
Rename MVKDevice::mtlPixelFormatFromVkFormat() to getMTLPixelFormatFromVkFormat().
2018-12-08 14:09:53 -05:00
Chip Davis
89aaaee0b8 Support the VK_KHR_bind_memory2 extension.
This extension allows multiple device memory objects to be bound in one
call. It also provides extensible versions of the memory binding calls.
It is a prerequisite for both the `VK_KHR_device_group` and
`VK_KHR_sampler_ycbcr_conversion` extensions.

The `VK_IMAGE_CREATE_ALIAS_BIT`, also added in this extension, would be
more interesting if we used `MTLHeap` objects for device memory, since
that would determine whether or not we would make images aliasable.
2018-12-06 11:50:43 -06:00
Chip Davis
528d3daf2a Support the VK_KHR_swapchain_mutable_format extension.
This allows clients to create views of a swapchain image with a
different format, just like a regular image created with the
`VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT` set. This extension also supports
the additional features provided by `VK_KHR_maintenance2` and
`VK_KHR_image_format_list` for swapchain images.

We... admittedly don't do much with any of this. There wasn't really
anything in Metal stopping clients from doing this to begin with. This
change does, however, set the `MUTABLE_FORMAT` and `EXTENDED_USAGE`
image bits on any swapchain created with the new
`VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR`.
2018-12-05 12:15:55 -06:00
Chip Davis
f4295ab3f1 Support the VK_KHR_shader_float16_int8 extension.
Only the `shaderFloat16` feature is supported for now. The `shaderInt8`
feature may require additional work on SPIRV-Cross.

Update Vulkan-Headers to 1.1.95 to pull in the definitions for this new
extension.
2018-12-05 10:32:30 -06:00
Chip Davis
faa455cec6 Support the VK_KHR_8bit_storage extension.
This isn't part of Vulkan 1.1, but it will almost certainly be part of
Vulkan 1.2. (Or whatever the new version is.)
2018-12-05 09:50:32 -06:00
Bill Hollings
5a93d80de0
Merge pull request #367 from cdavis5e/16-bit-storage
Support the VK_KHR_16bit_storage extension.
2018-12-05 05:24:23 +01:00
Bill Hollings
b4a8f2672c
Merge pull request #364 from cdavis5e/force-signedness
Force signedness of shader vertex attributes to match the host.
2018-12-05 05:20:22 +01:00
Bill Hollings
85ba42a0a7
Merge pull request #366 from cdavis5e/debug-dsym-file
In debug configurations, create a dSYM bundle for libMoltenVK.dylib.
2018-12-04 22:27:58 +01:00
Bill Hollings
23b3837d1e
Merge pull request #365 from cdavis5e/lock-set-texture
MVKImage: Take lock when setting the MTLTexture manually.
2018-12-04 22:26:51 +01:00
Bill Hollings
1aec2cf5e9
Merge pull request #363 from cdavis5e/2dms-array-image
Add support for 2D multisample array textures.
2018-12-04 22:11:05 +01:00
Chip Davis
9e1a466669 Support the VK_KHR_16bit_storage extension.
This extension allows shaders to use 16-bit types in buffers, push
constants, and shader inputs and outputs. One step closer to Vulkan 1.1.
2018-12-04 15:11:04 -06:00
Bill Hollings
44cf6c3bf1
Merge pull request #362 from cdavis5e/relaxed-block-layout
Advertise the VK_KHR_relaxed_block_layout extension.
2018-12-04 22:08:51 +01:00
Bill Hollings
1b99ba03ab
Merge pull request #361 from cdavis5e/khr-maintenance3
Support the VK_KHR_maintenance3 extension.
2018-12-04 22:07:16 +01:00
Chip Davis
18fa43994f Force signedness of shader vertex attributes to match the host.
Based on a patch by Stefan Dösinger.

Metal cannot do signedness conversion on vertex attributes, and for good
reason. Putting a `uint4` into an `int4`, or a `char4` into a `uint4`,
would lose those values that are outside the range of the target type.
But putting a `uchar4` into a `short4` or an `int4`, or a `ushort4` into
an `int4`, should work. In that case, force the signedness in the shader
to match the declared type of the host.

Update SPIRV-Cross to pull in the corresponding change. Bump MoltenVK
version.
2018-12-04 15:04:10 -06:00
Chip Davis
3ac51e46bf In debug configurations, create a dSYM bundle for libMoltenVK.dylib. 2018-12-04 13:29:02 -06:00
Stefan Dösinger
fe09f01cbe MVKImage: Take lock when setting the MTLTexture manually. 2018-12-04 13:26:11 -06:00
Chip Davis
f9e78313ba Correct format types of 8/16-bit integer formats.
They were using `Int32`/`UInt32`, which is fine I guess, but wasteful in
the blit/clear shaders. This will be more important later, when I work
around a bug in Metal.
2018-12-04 13:17:27 -06:00
Chip Davis
374741a989 Add support for 2D multisample array textures.
Requires Metal 2.1 on Mac. Not supported at all on iOS.

I'm split as to whether or not to have
`mvkMTLTextureTypeFromVkImageType()` return
`MTLTextureType2DMultisampleArray`.
2018-12-04 13:13:49 -06:00
Chip Davis
2b929c36ae Advertise the VK_KHR_relaxed_block_layout extension.
The recent updates to SPIRV-Cross should enable us to support this.
2018-12-04 13:12:16 -06:00
Chip Davis
08f9da1157 Support the VK_KHR_maintenance3 extension.
This is necessary to support the `VK_EXT_descriptor_indexing` extension.
It's also one step closer to Vulkan 1.1.
2018-12-04 13:10:02 -06:00
Chip Davis
bdbe5c71f8 Advertise the VK_KHR_storage_buffer_storage_class extension.
SPIRV-Cross already handles this. This extension was promoted to core in
Vulkan 1.1, and is a requirement for multiple other extensions, some of
which were also promoted to core in 1.1.
2018-12-04 13:07:51 -06:00
Bill Hollings
231e39bd7f Optimize MVKFenceSitter.
Remove internal MVKFenceSitter locks and collections.
Support inline wait only, and iterate static fence array externally.
Remove MVKSemaphoreImpl::reserveImpl().
2018-11-27 15:15:09 -05:00