2230 Commits

Author SHA1 Message Date
Bill Hollings
f35922507a With Metal argument buffers, track descriptor bindings used by
pipelines and only encode bindings that are in use for each stage.

Add SPIRVToMSLConversionConfiguration::isResourceUsed() and
remove SPIRVToMSLConversionResults::isDescriptorSetUsed().
MVKBitArray add copy constructor and allow queries beyond range.
2021-04-19 22:05:06 -04:00
Bill Hollings
ca89d258c9 No longer extract MTLTextureType from SPIR-V Cross to create MTLArgumentEncoders.
MVKDescriptorSetLayoutBinding no longer uses MTLTextureType to create
MTLArgumentEncoder, which is not needed for descriptor set argument encoding.
Remove obsolete MSLResourceBinding::outMTLTextureType and
SPIRVToMSLConversionConfiguration::getMTLTextureType().
2021-04-19 13:31:19 -04:00
Bill Hollings
4f0367130d Metal argument buffers support options for one MTLArgumentEncoder per descriptor set,
or one MTLArgumentEncoder per combination of pipeline-stage/descriptor set.

Add MVKPhysicalDeviceMetalFeatures::descriptorSetArgumentBuffers,
and MVKDeviceTrackingMixin::isUsingDescriptorSetMetalArgumentBuffers()
and isUsingPipelineStageMetalArgumentBuffers() to track this.
Create a separate MTLArgumentEncoder for each shader stage from
MTLFunction instead of MTLDevice, and track per-stage in MVKPipeline.
Add MVKMTLArgumentEncoder to track MTLArgumentEncoders in pipelines and desc set layouts.
Add SPIRVToMSLConversionResults::activeDescriptorSets to get desc sets used by a shader.
In SPIRV-Cross make padded Metal argument buffer descriptors
for buffers a pointer to float instead of pointer to void.
Update to latest version of SPIRV-Cross to use arg buffer padding feature.
Enable argument buffer support only when one MTLArgumentEncoder per
descriptor set can be used (macOS 10.16 and later or Intel GPU's).
2021-04-19 12:36:29 -04:00
Bill Hollings
2be819a364 When using Metal argument buffers, include all
descriptor bindings in all stages of shading compilation.
2021-04-17 15:25:56 -04:00
Bill Hollings
fc3bc1b635 Merge branch master into branch argument-buffers. 2021-04-13 14:13:31 -04:00
Bill Hollings
897e375bbb
Merge pull request #1331 from billhollings/resume-device
Add MVKConfiguration::resumeLostDevice and MVK_CONFIG_RESUME_LOST_DEVICE env var.
2021-04-13 13:41:33 -04:00
Bill Hollings
e9ca34a7aa Fix typo in description of MVK_CONFIG_RESUME_LOST_DEVICE. 2021-04-13 06:27:44 -04:00
Bill Hollings
260548172a Add MVKConfiguration::resumeLostDevice and MVK_CONFIG_RESUME_LOST_DEVICE env var,
to allow VkDevice to resume after non-fatal VK_ERROR_DEVICE_LOST error.

When running CTS, when one test triggers a VK_ERROR_DEVICE_LOST error condition,
CTS does not create a new VkDevice for subsequent tests, which causes all subsequent
tests to fail. This creates an incredible amount of results noise, and makes it
difficult to determine accurate test failure numbers. This is particularly problematic
because VK_ERROR_DEVICE_LOST may be triggered sporadically by internal Metal issues,
often making it not traceable to a consistent failure of a particular CTS test.
2021-04-12 18:20:16 -04:00
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