1062 Commits

Author SHA1 Message Date
Bill Hollings
a6deef8df9 Use MVKSmallVector in command encoder states.
MVKResourcesCommandEncoderState functions use MVKArrayRef to pass fixed content,
and template functions to pass various dynamic vector types.
2020-05-22 18:39:43 -04:00
Bill Hollings
2e91df7b21 Use MVKSmallVector for pipeline stages.
Remove getStages() from MVKPipeline and MVKComputePipeline,
as it applies only to graphics pipelines.
2020-05-22 11:49:14 -04:00
danginsburg
20bf6d8b8e Check @available for MTLDrawable addPresentedHandler/presentedTime. See if it fixes CI failure. 2020-05-21 15:23:54 -04:00
danginsburg
d9da5c746e Fix compile warning and forgetting to use a constant in previous change 2020-05-21 14:13:20 -04:00
danginsburg
027b66ef5c Add support for VK_GOOGLE_display_timing. Some notes:
* vkGetRefreshCycleDurationGOOGLE is implemented for iOS using UIScreen maximumFramesPerSecond.  I did not implement it for macOS (just hard-coded to 60).  It looks like doing it will require using CGDisplayModeGetRefreshRate
* vkGetPastPresentationTimingGOOGLE fills in the actualPresentationTime, but Metal does not provide the earlierPresentTime or the presentMargin as far as I can tell so earliestPresentTime is set to actualPresentTime and presentMargin is zero.
* Tested mostly on iOS - confirmed with Metal System Trace that desiredPresentTime works properly aligning the presentation correctly with vsync.
2020-05-21 12:00:50 -04:00
Bill Hollings
67dd89b66a Use MVKSmallVector in all MVKCommand subclasses to reduce memory footprints of
commands, and pass MVKArrayRef between MVKCommand subclasses and encoder states.
2020-05-19 17:34:26 -04:00
Bill Hollings
94e392cb37 Add MVKSmallVector as a more memory efficient substitute of MVKVector.
Replicate MVKVector.h and MVKVectorAllocator.h into MVKSmallVector.h and
MVKSmallVectorAllocator.h, and collapse class hierarchies.
Add MVKArrayRef struct to allow the contents of MVKSmallVector and MVKVector
to be passed between functions consistently.
Add contents() function to MVKVector to return MVKArrayRef.
2020-05-19 17:24:01 -04:00
Bill Hollings
e8c231eb45
Merge pull request #878 from billhollings/master
Reduce memory requirements for commands.
2020-05-13 22:03:24 -04:00
Bill Hollings
d8b3578604 MVKCmdCopyImage and MVKCmdBlitImage remove MVKCommandUse member variable.
MVKCmdCopyImage and MVKCmdBlitImage move passing MVKCommandUse
from setContent() to second encode() function.
MVKCmdPipelineBarrier reorder member variables.
2020-05-13 21:22:09 -04:00
Bill Hollings
ac1889534c Reduce memory requirements in MVKCmdTransfer.h/mm.
MVKCmdCopyImage, MVKCmdBlitImage, MVKCmdResolveImage generate derivative
arrays inline during encoding instead of holding as member variables.
Separate MVKCmdBlitImage from MVKCmdCopyImage and derive from MVKCommand instead.
2020-05-13 20:43:26 -04:00
Bill Hollings
5f1ea16808 Reduce memory requirements for vkCmdClearAttachments().
MVKCmdClearAttachments create vertices array inline.
Add MVKCmdClearAttachments subclasses MVKCmdClearSingleAttachment
and MVKCmdClearMultiAttachments.
2020-05-12 20:25:43 -04:00
Bill Hollings
85798f1259 Reduce memory requirements for commands in MVKCmdTransfer.h/mm.
Convert to template classes MVKCmdCopyImage, MVKCmdBlitImage, MVKCmdResolveImage,
MVKCmdCopyBuffer, MVKCmdBufferImageCopy, MVKCmdClearAttachments, MVKCmdClearImage.
Add MVKAddCmdFrom3Thresholds and MVK_CMD_TYPE_POOLS_FROM_3_THRESHOLDS()
macros to support 3 template thresholds.
Add MVKCmdClearImage subclasses MVKCmdClearColorImage and MVKCmdClearDepthStencilImage.
MVKCmdClearAttachments consolidate clear value arrays.
Reorder member variables in commands to avoid internal memory gaps.
Set enum MVKCommandUse type to uint8_t.
2020-05-12 17:32:19 -04:00
Jan Sikorski
46a63afa84 Fix logic in MVKBuffer::getMTLBufferOffset() 2020-05-12 17:29:00 +02:00
Jan Sikorski
3542439cca Mark compute state trackers as dirty when destroying mtlComputeEncoder 2020-05-12 17:28:52 +02:00
Bill Hollings
8f34c5af93 Reduce memory requirements for MVKCmdPushConstants and MVKCmdPushDescriptorSet.
MVKCmdPushConstants convert to a template class based on push constant size.
MVKCmdPushDescriptorSet reduce count of pre-allocated VkWriteDescriptorSets,
in recognition that numerous dynamic allocations necessarily happen anyway.
Cleanup member variable order in commands to avoid internal memory gaps.
2020-05-11 20:52:26 -04:00
Bill Hollings
4ba93c16a5 Reduce memory requirements for vkCmdBindDescriptorSets.
Split MVKCmdBindDescriptorSetsStatic into separate subclasses,
depending on use of dynamic offsets, and make them template classes
based on descriptor set count.
2020-05-11 18:01:40 -04:00
Bill Hollings
7e692f76c2 Reduce memory requirements for MVKCmdBindPipeline.
Split MVKCmdBindPipeline into separate graphics and compute subclasses
to remove need to hold bind point.
2020-05-11 10:46:59 -04:00
Bill Hollings
fe9a5f7fe6 Reduce memory requirements for event commands.
Convert MVKCmdWaitEvents to template class based on number of events.
Add separate MVKCmdSetEvent and MVKCmdResetEvent classes.
2020-05-10 15:59:29 -04:00
Bill Hollings
d0564c16af Reduce memory requirements for vkCmdPipelineBarrier().
Add MVKPipelineBarrier struct to consolidate barrier specs, reduce
memory use in each, and standardize barrier info into one collection.
MVKCmdPipelineBarrier uses templated collection sizes.
Add mvkPrintSizeOf() macro to simplify printing type sizes.
2020-05-09 10:24:45 -04:00
Bill Hollings
d443b131e0 Reduce memory requirements for resource bindings.
Use uint16_t instead of uint32_t for Metal resource indexes in binding structures.
MVKIndexMTLBufferBinding::mtlIndexType track MTLIndexType as uint8_t.
2020-05-08 11:34:11 -04:00
Jan Sikorski
effa0c2ae3 Malloc redoBuff in reportMessage to prevent stack overflow 2020-05-08 11:08:25 +02:00
Bill Hollings
40d0427d31 Reduce memory requirements for commands in MVKCmdDraw.h/mm.
Convert MVKCmdBindVertexBuffers to template class.
Add MVKAddCmdFromTwoThresholds() macro in vulkan.mm.
Add MVK_CMD_TYPE_POOLS_FROM_TWO_THRESHOLDS() macro in MVKCommandTypePools.def.
Add second threshold to MVKCmdBeginRenderPass.
2020-05-08 00:51:35 -04:00
Bill Hollings
8813aff12c Reduce memory requirements for commands in MVKCmdRenderPass.h/mm.
MVKCmdBeginRenderPass don't hold VkRenderPassBeginInfo.
Convert MVKCmdBeginRenderPass and MVKCmdExecuteCommands to template classes.
MVKCommandBuffer::recordBeginRenderPass() pass MVKLoadStoreOverrideMixin
instead of MVKCmdBeginRenderPass.
MVKCommandBuffer::recordEndRenderPass() pass nothing.
Add MVKAddCmdFromThreshold() macro in vulkan.mm.
Add MVK_CMD_TYPE_POOLS_FROM_THRESHOLD() macro in MVKCommandTypePools.def.
2020-05-07 15:51:15 -04:00
Bill Hollings
7452c9316f Remove requirement for dedicated memory for external MTLBuffers. 2020-05-07 11:56:54 -04:00
Bill Hollings
1a1c1250b4 Remove abortive returns from calls in vulkan.mm to allow tracing to complete.
Move null tests on destroy calls from vulkan.mm to MVKDevice and MVKInstance.
Don't bother testing for null when spec says a param must not be null.
Invert remaining null tests so they don't abort.
2020-05-07 11:12:54 -04:00
Alexander Meißner
3da5ecf628 Adds support for VK_KHR_sampler_ycbcr_conversion formats and sampler.
However, the binding of descriptors for
multi-planar / disjoint images is still missing.
2020-05-07 16:02:10 +02:00
Bill Hollings
9c033ec92c Cleanup MVKResource::bindDeviceMemory2() calls.
Remove MVKResource::bindDeviceMemory2() and MVKBindDeviceMemoryInfo struct.
Add separate MVKBuffer::bindDeviceMemory2() and MVKImage::bindDeviceMemory2()
functions with distinct params, and delegate to MVKResource::bindDeviceMemory().
2020-05-06 21:01:11 -04:00
Bill Hollings
d343fed52e Add support for VK_KHR_external_memory extension.
Functions and functionality supported, but don't currently do anything
until Metal-friendly enumerations added to VkExternalMemoryHandleTypeFlagBits.
Updated What's New document.
2020-05-06 19:43:21 -04:00
Bill Hollings
2b3cf6f395 Standardize design pattern for enumerations of Vulkan struct pNext chains.
Consistently use for-loops, VkBaseInStructure and VkBaseOutStructure.
Remove redundant MVKVkAPIStructHeader structure.
Remove unnecessary null tests on incoming Vulkan struct pointers.
2020-05-06 11:15:50 -04:00
Bill Hollings
efde388cbd Add support for VK_KHR_external_memory_capabilities extension.
Capability functions and functionality supported, but don't currently do anything
until Metal-friendly enumerations added to VkExternalMemoryHandleTypeFlagBits.
Rename MVKPhysicalDevice::getPhysicalDeviceMemoryProperties() to
getMemoryProperties() for consistency.
Updated What's New document.
2020-05-05 18:12:17 -04:00
Bill Hollings
2b5eb3e9f6 Shorten Vulkan extension declarations for brevity and clarity.
Shorten instance/device extension declarations for brevity.
Reformat platform extension tests for brevity and clarity.
2020-05-04 13:38:16 -04:00
Bill Hollings
445d30e41f Reduce common memory requirements of MVKCmdSetViewport and MVKCmdSetScissor.
To allow these classes to contain reasonably-sized pre-allocated vectors,
make MVKCmdSetViewport & MVKCmdSetScissor template classes based on quantities.
Create two concrete implementations of each for 1 and 16 viewports or scissors.
vkCmdSetViewport() and vkCmdSetScissor() choose which concrete template class
implementation to use based on the number of viewports or scissors, respectively.
Update auto-generation of getTypePool() to support template classes when needed.
2020-04-24 22:14:05 -04:00
Bill Hollings
30c8ebb2f2 Automatically generate MVKCommand::getTypePool() implementations
for MVKCommand subclasses using MVKCommandTypePools.def file.
2020-04-24 14:13:58 -04:00
Bill Hollings
6ce5b00a1e MVKCommandPool uses def file to define and manage command type pool member variables. 2020-04-24 12:20:53 -04:00
Bill Hollings
471ba9bb39 Rename most MVKPixelFormats member functions to eliminate naming redundancy.
Many of the names of the MVKPixelFormats member functions where inherited from
function names in mvk_datatypes.h, which is a C API, therefore must have unique
function names, and uses parameter types as part of the names to distinguish.

Since MVKPixelFormats is a C++ class, we can do away with that and make use
of function overloading to simplify the function names.

I forgot to to this when creating MVKPixelFormats in the first place.
2020-04-23 14:45:35 -04:00
Bill Hollings
432a63545e MVKPixelFormats add all iOS feat set caps for R23Uint and R23Sint. 2020-04-23 13:51:53 -04:00
Bill Hollings
8502d516e3 Merge branch 'master' of https://github.com/KhronosGroup/MoltenVK 2020-04-22 22:55:45 -04:00
Bill Hollings
e8b0ef879a MVKPixelFormats enables atomic capabilities only when applicable.
Start with no Vulkan atomic feature bits and add VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT
and VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT if Metal format supports it.
Currently only applies to formats MTLPixelFormatR32Uint and MTLPixelFormatR32Sint.
Enable for linear tiling only. Previously optimal was enabled too.
Add kMVKMTLFmtCapsAtomic.
Add kMVKVkFormatFeatureFlagsTexAtomic.
Add kMVKVkFormatFeatureFlagsBufAtomic.
2020-04-22 22:54:51 -04:00
Chip Davis
9260f5bfd5 MVKDevice: Support capturing GPU traces to a file.
Use MVK_CONFIG_AUTO_GPU_CAPTURE_OUTPUT_FILE to set the destination file.
This is useful for capturing traces where the program in question cannot
be run under Xcode's control; the captured trace can then be inspected
later with Xcode.

This new feature requires Metal 3.0 (macOS 10.15, iOS 13).
2020-04-22 18:38:08 -05:00
Bill Hollings
11bd75d521 MVKPixelFormats consolidate setting VkFormatProperties. 2020-04-22 17:29:11 -04:00
Bill Hollings
5d9cad350d In MVKCommand subclasses, replace holding Metal structs with Vulkan equivalents. 2020-04-22 14:35:37 -04:00
Bill Hollings
14a606854b Merge branch 'master' of https://github.com/KhronosGroup/MoltenVK 2020-04-22 13:43:01 -04:00
Bill Hollings
4a62300a1c
Merge pull request #863 from cdavis5e/image-atomics
MVKDescriptor: Pass buffers to shaders that do atomic image accesses.
2020-04-22 13:34:20 -04:00
Chip Davis
15e3dc041c MVKDescriptor: Pass buffers to shaders that do atomic image accesses.
Special thanks to Epic Games for contributing the underlying support to
SPIRV-Cross.

Metal does not support atomic image accesses, but we can work around
that. For buffer views, and for linear image views, we can pass the
underlying buffer to the shader and do atomic accesses on that. For now,
we only support this for `VK_FORMAT_R32_UINT` and `VK_FORMAT_R32_SINT`,
as required by the Vulkan standard; it should theoretically be possible
to extend this to any format where the size of a pixel is 32 bits. Metal
does not yet support 16-bit or 8-bit atomic access, so those formats are
out for now.

Unfortunately, we cannot yet support this for optimal-tiled images, even
though Vulkan requires it. These images do not have a buffer backing
them. Possible alternatives and their downsides:

* Pass a buffer, probably the buffer backing the device memory, for
  these images. But this would defeat the purpose of atomic access--the
  buffer and image would not be consistent until afterward when their
  contents were sync'd. Using a heap with aliased resources would
  eliminate this problem... but, optimal tiling.
* Lie and create a linear image for a format supporting atomic image
  access. But that only works for 1D and 2D images with one array slice
  and one mip level. Also, this would likely hurt performance, because
  the GPU can no longer rely on optimal layout.
2020-04-22 11:13:00 -05:00
Bill Hollings
04865936c9 Reduce memory via just-in-time conversion to Metal viewports and scissors.
Metal viewports and scissors are twice the size of the Vulkan equivalents,
and internal caches are preallocated for 16 of each to avoid dynamic allocations.
Hold the Vulkan viewports and scissors, and convert just before sending them to Metal.
MVKCommandEncoder::clipToRenderArea() use VkRect2D instead of MTLScissorRect.
2020-04-20 22:35:11 -04:00
Bill Hollings
5d9dd08353 Fix issue in setting depth bias introduced during recent MVKCommand redesign. 2020-04-19 16:31:38 -04:00
Bill Hollings
e4be6b836c Simplify MVKCommand and MVKCommandTypePool instantiation.
MVKCommand constructor not longer take MVKCommandTypePool.
Remove MVKCommand::returnToPool().
MVKCommandTypePool no longer track MVKCommandPool.
Remove MVKCommand.mm.
2020-04-18 22:52:40 -04:00
Bill Hollings
33dbc761c7 Remove MVKCommand::_pool iVar.
Pass MVKCommandPool to MVKCommand::returnToPool() function.
Add pure virtual MVKCommand::getTypePool() to reference correct
type pool in MVKCommandPool for a subclass instance.
Add MVKFuncionOverride_getTypePool() macro template to define
MVKCommand::getTypePool() overrides in subclasses.
Rename MVKCommandPool::_cmdPushSetWithTemplatePool to
_cmdPushDescriptorSetWithTemplatePool for consistency
with macro template support.
2020-04-17 22:47:12 -04:00
Bill Hollings
b7c6f73c04 MVKCommand remove functions that access device and command pool.
MVKCommand subclasses access device and command pool through
MVKCommandEncoder and MVKCommandBuffer.
2020-04-17 14:32:25 -04:00
Bill Hollings
4ef21a2589 Remove MVKCommand from MVKConfigurableObject superclass.
MVKCommand subclass setContent() return VkResult
instead of calling setConfigurationResult().
MVKAddCmd() macro tests return error and doesn't add command to MVKCommandBuffer.
Remove MVKCommand::canEncode().
2020-04-16 18:07:42 -04:00