2222 Commits

Author SHA1 Message Date
Bill Hollings
60df8d45a7 Fix resource usage updates during tessellation when using Metal argument buffers.
Pass stage when encoding resource usage.
During compute encoding of tessellation stage, track
graphics resources usage, but encode onto compute encoder.
2021-04-10 16:53:51 -04:00
Bill Hollings
0e2439c3e8 Metal argument buffers handle descriptor bindings with zero descriptor count.
If descriptor count is zero, don't add MTLArgumentDescriptor to
MTLArgumentEncoder, and don't populate resources into shader converter.
Don't update command encoder resource usage if resource is nil.
2021-04-10 09:16:29 -04:00
Bill Hollings
1ba6065490 Metal argument buffers support storage image and texel buffers. 2021-04-09 20:24:51 -04:00
Bill Hollings
a7ffa3cfd7 Metal argument buffers support immutable samplers. 2021-04-09 16:50:54 -04:00
Bill Hollings
2405606c1e If descriptor set binding does not change the descriptor set that
is bound (rebinds the same descriptor set), don't mark descriptor
resource usage tracking for Metal argument buffers as dirty.
2021-04-09 14:11:35 -04:00
Bill Hollings
52854bb76f Metal argument buffers support dynamic buffer offsets.
Move dynamic offsets from the Metal argument buffer to an implicit shader buffer.
Add SPIRVToMSLConversionConfiguration::dynamicBufferDescriptors to track dynamic
buffer descriptors, and add SPIRVToMSLConversionResults::needsDynamicOffsetBuffer
to indicate shader needs an implicit buffer to track these dynamic offsets.
Add MVKShaderStageResourceBinding::dynamicOffsetBufferIndex to track a
descriptor's index into the implicit dynamic offsets buffer.
MVKPipelineLayout change how per-descriptor set offsets are calculated and tracked
when using Metal argument buffers, so that resource indexes do not accumulate
across descriptor sets, but dynamic offset buffer indexes do accumulate.
MVKPipelineLayout rearrange order of implicit buffer indexes to give more commonly used
implicit buffers lower indexes to help reduce risk of exhausting discrete buffer bindings.
2021-04-09 12:06:57 -04:00
Bill Hollings
a868ccc563 Don't encode storage image MTLBuffer to Metal argument buffer
if storage image has no underlying MTLBuffer.

MVKResourcesCommandEncoderState::encodeMetalArgumentBuffer()
if runtime array retrieve descriptor count from descriptor set.
2021-04-07 18:21:27 -04:00
Bill Hollings
d23725626a Always use MTLResourceStorageModeShared for Metal argument buffers
to ensure writes to argument buffers propagate on discrete GPUs.
2021-04-07 16:09:25 -04:00
Bill Hollings
3d010dba67 Fix issue where Metal argument buffer resource
usage not tracked accurately across shader stages.

Remove tracking of descriptor usage in MVKPipeline.
Don't bind argument buffer to command encoder if descriptor set unused by shader stage.
MVKDescriptor::encodeToMetalArgumentBuffer() remove unused shader stage argument.
Remove SPIRVToMSLConversionConfiguration::isResourceUsed().
2021-04-07 14:52:33 -04:00
Bill Hollings
c20b8f4010 Fixes to Metal argument buffer indexing and offset alignment calculations.
MVKPipelineLayout don't track descriptor set resource index offsets when
using Metal argument buffers.
Fix alignment calc of space available for next descriptor set.
Bind Metal argument buffer to command encoder when its content is updated
during command encoding, and only if shader uses that descriptor set.
Use MTLResourceStorageModeManaged for Metal argument buffer if available.
2021-04-06 19:49:08 -04:00
Bill Hollings
8145aa2707 Align shader descriptor set definitions with Metal argument buffer definitions.
Support SPIRV-Cross CompilerMSL::Options::pad_argument_buffer_resources and
MSLResourceBinding::base_type.
Consolidate mvkPopulateShaderConverterContext() and set
MSLResourceBinding::base_type from VkDescriptorType.
Add MVKDescriptorSetLayout::initForMetalArgumentBufferUse() to measure size of Metal
argument buffer needed for descriptor set by creating a ephemeral MTLArgumentEncoder
from the descriptor bindings and measuring its length.
MVKDescriptorPool::initMetalArgumentBuffer() measure size of a single MTLBuffer
to use for all descriptor sets in the pool.
MVKDescriptorPool use VkDescriptorPoolInlineUniformBlockCreateInfoEXT to determine
descriptor count for VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT.
Set max size of temporary inline block buffer allocations from
MVKDevice::_pMetalFeatures->dynamicMTLBufferSize.
Set MTLSamplerDescriptor::supportArgumentBuffers property when appropriate.
2021-04-05 13:23:53 -04:00
Bill Hollings
4920362f43 Fixes to argument buffers during initial testing.
Use specific resource indices of MVKShaderStageResourceBinding
when assigning indices to argument buffer elements.
MVKShaderStageResourceBinding expand elements to uint32_t
to support larger numbers of resource arguments.
Fix calculation of descriptor set Metal argument buffer size requirements.
Streamline MVKResourcesCommandEncoderState::encodeToMetalArgumentBuffer(),
and add fix for GPU capturing of Metal arg buffers for Xcode 12.
Update MSLResourceBinding::outMTLTextureType and outIsUsedByShader from shader
only if resource binding is for the correct shader stage, to allow outIsUsedByShader
to be carried across multiple-stage shader compilations.
Remove MVKDescriptorSet::populateMetalArgumentBufferBinding().
Remove MVKSamplerDescriptorMixin::getMetalArgumentBufferSamplerIndexOffset().
Add MVKCommandEncoderState::getDevice().
2021-03-31 14:56:38 -04:00
Bill Hollings
8a68bbd94f Merge branch 'master' of https://github.com/billhollings/MoltenVK into argument-buffers 2021-03-30 10:01:48 -04:00
Bill Hollings
36a5a6e654 Fix time and space inefficiencies caused by missed
shader cache lookup hits in MVKShaderLibraryCache.

Rename MSLResourceBinding::mtlTextureType, MSLResourceBinding::isUsedByShader, and
MSLShaderInput::isUsedByShader to add a prefix out*, to clarify that those variables
are output from the conversion process, instead of input to the conversion process.
Don't use MSLResourceBinding::outMTLTextureType when looking up cached shaders.
2021-03-30 09:53:07 -04:00
Bill Hollings
0db803bc3c
Merge pull request #1325 from billhollings/swapchain-leak
Fix memory leak where swapchains and images were not destroyed due to a retention loop.
2021-03-26 17:59:04 -04:00
Bill Hollings
d4844490f4 Fix memory leak where swapchains and images were not destroyed due to a retention loop.
Add Cube app iOS device rotation support, to test swapchain destruction on iOS.
2021-03-26 17:45:16 -04:00
Bill Hollings
aa89f845a9 Update Metal argument buffer resource usage in Metal command encoder.
MVKPipeline track descriptors used by shaders.
Update resources as dirty at start of Metal render pass or compute encoder.
Add MVKCommandEncoder::beginMetalComputeEncoding() to mark a new Metal compute encoder.
MVKResourcesCommandEncoderState track resource usage that needs to be encoded.
Add MVKResourcesCommandEncoderState::encodeArgumentBufferResourceUsage().
Add MVKCommandEncoderState::beginMetalComputeEncoding() to mark compute
state dirty when a MTLComputeEncoder is created.
Add SPIRVToMSLConversionConfiguration::isResourceUsed().
MVKBitArray add ability to retain contents when resizing, and clear bit during getBit().
Add MVKBitArray getBit() option to clear bit.
2021-03-26 13:16:16 -04:00
Bill Hollings
6dfe48bc23 Write descriptors to Metal argument buffers.
Pass VkPipelineBindPoint during descriptor set binding, and hold bound
descriptor sets and dynamic offsets in MVKResourcesCommandEncoderState.
Add MVKDescriptor::encodeToMetalArgumentBuffer() to write descriptor to arg buffer.
MVKInlineUniformBlockDescriptor use temp MTLBuffer, available through
MVKDescriptorPool, so it can be written to arg buffer.
Write to arg buffer during MVKResourcesCommandEncoderState encoding, for update-after-bind.
Add MVKBitArray::enumerateEnabledBits() to perform operations on enabled bits.
During beta period, disable MVKConfiguration::useMetalArgumentBuffers/
MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS by default.
2021-03-24 13:05:32 -04:00
Bill Hollings
9b3de66d32 Merge branch 'master' of https://github.com/billhollings/MoltenVK into argument-buffers 2021-03-22 15:03:26 -04:00
Bill Hollings
79ba1d8e1e
Merge pull request #1323 from billhollings/tmp-buff-alloc
Enhancements and fixes to temporary MTLBuffer allocation.
2021-03-22 15:01:24 -04:00
Bill Hollings
55a2fe6467 Remove private flag from MVKCommandEncoder::copyToTempMTLBufferAllocation().
MVKMTLBufferAllocationPool subclass from MVKDeviceTrackingMixin.
MVKDeviceObjectPool subclass from MVKDeviceTrackingMixin.
2021-03-22 07:51:07 -04:00
Bill Hollings
ef1990306d Enhancements and fixes to temporary MTLBuffer allocation.
Check allocations are larger than MTLBuffer alignment to avoid Metal errors.
Align returning safely with allocating safely, and change callers to use
MVKMTLBufferAllocation::returnToPool() globally, to ensure this match.
Fix use of const on returnToPool();
Move MVKCommandEncoder::copyToTempMTLBufferAllocation()
and support setting private and dedicated flags.
Align constructor parameter order on MVKMTLBufferAllocationPool
with that of MVKMTLBufferAllocator.
Move subclass overrides of MVKObjectPool::newObject() to protected access.
2021-03-21 21:53:16 -04:00
Bill Hollings
7c50cc4f37 Calculate resource indexes for Metal argument buffers.
Add MVKShaderStageResourceBinding::resourceIndex to accumulate unique index across
all resource types, and refactor calculation of indices to accommodate this value.
Create SVOT in descriptors for Metal arg buffer indices.
Remove  MVKDescriptorSetLayoutBinding::_metalArgumentBufferIndex
and use MVKShaderStageResourceBinding::resourceIndex instead.
Refactor calculation of MVKDescriptorSetLayout::_metalArgumentBufferSize.
2021-03-19 16:15:12 -04:00
Bill Hollings
14c649853f Construct MTLArgumentEncoders for pipelines.
MVKPipeline tracks a MTLArgumentEncoder for each descriptor set in the pipeline layout,
created from MTLArgumentDescriptors that are populated by MVKDescriptorSetLayoutBindings
in each MVKDescriptorSetLayout.
2021-03-18 18:10:29 -04:00
Bill Hollings
751d864964 Descriptor set Metal argument buffer.
MVKDescriptorPool create single MVKBuffer to use as Metal argument buffer
shared between associated descriptor sets.
MVKDescriptorSetLayout track space required within Metal argument buffer.
MVKDescriptorSet track offset into shared Metal argument buffer, and find
and assign a slice for each descriptor set as it is allocated.
MVKDescriptorSetLayoutBinding track index into argument buffer.
2021-03-18 15:50:56 -04:00
Bill Hollings
0a8f9995c9 Device and shader framework framework changes to support Metal argument buffers.
Add MVKPhysicalDeviceMetalFeatures::argumentBuffers.
Add MVKConfiguration::useMetalArgumentBuffers and
MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS env var.
MVKPhysicalDevice and MVKDeviceTrackingMixin add isUsingMetalArgumentBuffers().
Populate VkPhysicalDeviceDescriptorIndexingPropertiesEXT with larger Tier2
limits when supported.
Populate pipelineCacheUUID with feature flag if Metal arg buffers are used.
SPIRVToMSLConversionConfiguration add content to extract shader texture types
and mark discrete descriptor sets.
2021-03-18 13:29:10 -04:00
Bill Hollings
16654b9341
Merge pull request #1322 from billhollings/several-frwk-changes
Several underlying non-functional changes towards Metal argument buffer support.
2021-03-17 23:13:17 -04:00
Bill Hollings
9542a5cc54 Several underlying non-functional changes towards Metal argument buffer support.
Move tracking descriptor index to MVKDescriptorSetLayoutBinding from MVKDescriptorSetLayout.
Refactor MVKDescriptorSet::write() to be more DRY.
Grow and shrink MVKDescriptorSet memory consumption during allocate and free.
MVKPhysicalDevice refactor layout of pipelineCacheUUID to remove redundancy in MoltenVK
revision and allow tracking of enabled features that affect pipeline cache content.
MVKBitArray support resizing and simplify setBit() functionality.
2021-03-17 19:21:35 -04:00
Bill Hollings
e7a5a8f427
Merge pull request #1320 from billhollings/rename-config
Rename mvkGetMVKConfiguration() to mvkConfig() for brevity.
2021-03-17 11:14:42 -04:00
Bill Hollings
f8280bca89 Rename mvkGetMVKConfiguration() to mvkConfig() for brevity. 2021-03-17 09:45:13 -04:00
Bill Hollings
55e1b1b29b
Merge pull request #1319 from billhollings/texel-buff-align
Fix advertising single-texel alignment capability for texel buffers.
2021-03-15 18:54:35 -04:00
Bill Hollings
d24414592c
Merge pull request #1317 from billhollings/pool-desc-sets
Descriptor pooling enhancements
2021-03-15 18:32:45 -04:00
Bill Hollings
e276f1a261 Fix advertising single-texel alignment capability for texel buffers.
The test for single-texel capability used a mod calculation to compare the linear
alignment requirement reported by Metal to the texel size. Instead, it should use an
inequality comparison, to check if the alignment requirement is LTE the texel size.
2021-03-15 18:29:11 -04:00
Bill Hollings
2ef21c65bf Preallocate a pool of descriptors by default.
Enable MVKConfiguration::preallocateDescriptors and
MVK_CONFIG_PREALLOCATE_DESCRIPTORS by default.
Rename MVKDescriptorTypePreallocation to MVKDescriptorTypePool.
2021-03-15 16:27:39 -04:00
Bill Hollings
6cba6a851b MVKDescriptorPool optimize reseting descriptor pool.
Don't free individual pooled descriptors during a pool reset.
Don't mark availability of individual descriptor sets during a pool reset.
Add MVKDescriptorPool::_hasPooledDescriptors as SVOT to track if descriptors
are pooled, and is set from outside constructor to ensure all internal
descriptor pools are constructed with the same SVOT.
MVKDescriptorPool::allocateDescriptorSet() ensure correct result returned.
2021-03-15 15:52:40 -04:00
Bill Hollings
4371ef4d2b MVKDescriptorPool pools its descriptor sets. 2021-03-15 11:33:14 -04:00
Bill Hollings
392957df72
Merge pull request #1312 from billhollings/optimize-descriptor-sizes
MVKDescriptor subclasses: Reduce redundant and unused content.
2021-03-13 16:01:21 -05:00
Bill Hollings
88fcb30090 Revert to using MVKBufferDescriptor::_buffRange, and populating
MVKMTLBufferBinding::size to specify the length of shader runtime arrays.
2021-03-13 14:03:47 -05:00
Bill Hollings
a2be769e5f MVKDescriptor subclasses: Reduce unused content.
Don't populate MVKMTLBufferBinding::size unless using mtlBytes and isInline.
Remove MVKBufferDescriptor::_buffRange.
Remove MVKImageDescriptor::_imageLayout.
Remove MVKCmdBufferImageCopy::_imageLayout.
2021-03-12 22:12:22 -05:00
Bill Hollings
068ce2ee8e MVKDescriptor subclasses: Simplify interface and reduce redundant content.
Remove MVKDescriptor::setLayout() and pass MVKDescriptorSetLayoutBinding
to MVKDescriptor::bind(), write(), and read().
Remove MVKSamplerDescriptorMixin::_hasDynamicSampler.
Remove MVKInlineUniformBlockDescriptor::_length.
2021-03-12 20:10:51 -05:00
Bill Hollings
85ef62d043
Merge pull request #1310 from billhollings/prealloc-descriptors-refactor
Refactor preallocated descriptor handling.
2021-03-12 09:25:03 -05:00
Bill Hollings
984a74fffd Refactor preallocated descriptor handling.
Add MVKBitArray class.
Consolidate MVKPreallocatedDescriptors into MVKDescriptorPool
and remove MVKPreallocatedDescriptors.
2021-03-12 09:11:58 -05:00
Bill Hollings
20b5067ee5
Merge pull request #1309 from billhollings/fix-memoryless-load-store
In a renderpass, don't load or store memoryless attachments.
2021-03-11 14:11:42 -05:00
Bill Hollings
9c13e46c47 In a renderpass, don't load or store memoryless attachments.
For memoryless attachments, setting renderpass load and store
actions to "load" and "store" triggers Metal validation errors.
Refactor determination of renderpass MTLLoadAction and MTLStoreAction.
For memoryless attachments, replace load with don't care,
and store with resolve or don't care.
2021-03-11 12:22:47 -05:00
Bill Hollings
a0d20fe498
Merge pull request #1305 from billhollings/fix-physdvc-fmts
Several surface format and colorspace fixes.
2021-03-10 20:17:32 -05:00
Bill Hollings
4d452fdca6 Always explicitly set CAMetalLayer colorspace and wantsExtendedDynamicRangeContent.
Don't assume the incoming CAMetalLayer has default (no-op) values for colorspace and
wantsExtendedDynamicRangeContent properties, since they could have been set externally.
Ensure the Vulkan app has control over both of these properties.
vkCreateSwapchainKHR() returns VK_ERROR_FORMAT_NOT_SUPPORTED for unsupported colorspaces.
2021-03-10 19:59:11 -05:00
Bill Hollings
cd8a0e149e Restore support for HDR10 colorspace.
Restore support for VK_COLOR_SPACE_HDR10_HLG_EXT and VK_COLOR_SPACE_HDR10_ST2084_EXT
under Xcode12 that was removed due to App Store conflicts using older enum values.
2021-03-10 19:05:01 -05:00
Bill Hollings
8112d85103 Fix MVKPhysicalDevice::getSurfaceFormats() returning VK_FORMAT_UNDEFINED.
Fix MVKPhysicalDevice::getSurfaceFormats() returning VK_FORMAT_UNDEFINED
in available surface formats when a Metal surface format is available that
doesn't map to a defined Vulkan format (eg. MTLPixelFormatBGRA10_XR).
2021-03-10 18:30:11 -05:00
Bill Hollings
6665a6a436
Merge pull request #1300 from billhollings/cfg-enums
Create enums for remaining MVKConfiguration enumerated values.
2021-03-10 10:36:19 -05:00
Bill Hollings
cfc2556c31 Fix use of VkFlags in MVKConfiguration enumerated values.
MVKConfigLogLevel, MVKConfigTraceVulkanCalls, and MVKConfigAutoGPUCaptureScope
do not need to be VkFlags, since they aren't bitwise flags.

MVK_SET_FROM_ENV_OR_BUILD_INT32 supports setting enumerated values.
2021-03-10 09:26:59 -05:00