1649 Commits

Author SHA1 Message Date
Bill Hollings
577ec9a447 Rename references to ShaderConverterContext to ShaderConversionConfig
to align better with name of SPIRVToMSLConversionConfiguration structure.
2021-05-04 16:24:41 -04:00
Bill Hollings
91c5f58f7a Add class mixins for reference counting and configuration results.
Separate reference counting from MVKVulkanAPIObject into a new
MVKReferenceCountingMixin class, so reference counting can
potentially be used in other areas of the class hierarchy.
Replace MVKConfigurableObject with MVKConfigurableMixin for the same reason.
Remove some inline definitions as unnecessary in the files being revised here.
2021-05-04 15:26:28 -04:00
Bill Hollings
5b1f38fbb9 Miscellaneous non-functional maintainability updates.
Rename kMVKShaderStageMax to kMVKShaderStageCount
to clarify it's common use in array sizing and for loops.
Change mvkConfig() to return reference instead of pointer
to improve syntactic sugar to use . instead of ->.
Update MoltenVK version to 1.1.4.
Update What's New document.
2021-05-03 18:56:30 -04:00
Bill Hollings
2eba556084
Merge pull request #1345 from billhollings/xc-125
Support Xcode 12.5
2021-05-03 15:04:58 -04:00
Bill Hollings
f2eb8e60c8 Further fixes to Xcode 12.5 support.
Indicate that MacCatalyst does not support BC compression.
2021-05-03 13:49:41 -04:00
StarbucksDave
fea0eddcee
Update MVKDescriptor.mm
Fix space (from web commit).
2021-05-03 10:04:23 +02:00
StarbucksDave
1d480dbe63
Use SPIRV_CROSS_NAMESPACE define in MVKDescriptor.mm
I believe SPIRV_CROSS_NAMESPACE_OVERRIDE should be replaced by SPIRV_CROSS_NAMESPACE defined in SPIRV-Cross spirv_common.hpp. This ensures that SPIRV_CROSS_NAMESPACE_OVERRIDE usage in MVK is optional.
2021-05-03 09:57:12 +02:00
Bill Hollings
5fd821bb5d
Merge pull request #1344 from kleinerm/googledisplaytiming
Compliance fixes for VK_GOOGLE_display_timing extension implementation.
2021-05-01 16:19:58 -04:00
Bill Hollings
6614ef2005
Merge pull request #1342 from kleinerm/iosurfacewithoutobjc
Expose vkGetIOSurfaceMVK() / vkUseIOSurfaceMVK() also under non-ObjC.
2021-05-01 16:13:06 -04:00
Bill Hollings
4a76e5a904 Further fixes to Xcode 12.5 support.
Fix macro logic in mvkSupportsBCTextureCompression() for iOS & tvOS platforms.
2021-05-01 15:35:19 -04:00
Bill Hollings
0bfd127428 Further fixes to Xcode 12.5 support.
Test for [MTLDevice supportsBCTextureCompression] only when using Xcode 12 and above.
Use Xcode 12.5 in GitHub Actions CI.
Fix typos in comments.
2021-05-01 15:21:57 -04:00
Bill Hollings
434b95e829 Fix build error when querying MTLDevice support for BC compression.
This build error seems to have been exposed in Xcode 12.5.
Add mvkSupportsBCTextureCompression() to manage use of
[MTLDevice supportsBCTextureCompression] to query for
MTLDevice support for BC compression across all platforms.
2021-05-01 14:00:17 -04:00
Bill Hollings
1655f3b455 Add tag names to anonymous structs. 2021-04-30 20:49:01 -04:00
Bill Hollings
c0e5f88bf5 Support Xcode 12.5 build settings. 2021-04-30 19:41:54 -04:00
kleinerm
ffed2a26b2 Make vkGetPastPresentationTimingGOOGLE() queuing behavior spec compliant.
Citing section 33.8 "Display Timing Queries", the description of
VK_GOOGLE_display_timing's vkGetPastPresentationTimingGOOGLE()
the spec states that "The results for a given swapchain and presentID are
only returned once from vkGetPastPresentationTimingGOOGLE."

In other words, every VkPastPresentationTimingGOOGLE timing record
stored in the internal queue must get removed from the internal queue,
once it was returned to the calling client application via a successfull
call to vkGetPastPresentationTimingGOOGLE().

The current implementation does not remove delivered entries from the
queue. Instead it keeps the last kMaxPresentationHistory (== 60) records,
so the internal queue grows to its maximum fill level and never empties.
Successive calls to vkGetPastPresentationTimingGOOGLE() deliver the same
records repeatedly, confusing applications which are written according to
spec.

This commit changes the queueing behavior to properly remove items from
the queue, so that it operates in a FIFO fashion and only retains items which
have not been fetched yet, up to kMaxPresentationHistory, after which the
oldest items get discarded.

Tested on macOS 10.15.7 with AMD for different intervals between calling
vkGetPastPresentationTimingGOOGLE() and different input values for
pPresentationTimingCount, to make sure it behaves properly for cases like
1 item in queue at query time, queue half full at query time, queue completely
full, queue "overflowing" - ie. items are properly discarded in FIFO order, and
for fetching 1 item at a time, multiple items (partially emptying the queue in
each iteration) or all items (emptying the queue in one go).
2021-04-29 06:07:57 +02:00
kleinerm
136a5cbd4a Fix behaviour of vkGetPastPresentationTimingGOOGLE().
On return, *pPresentationTimingCount was not assigned the actual number
of timing records written, as the spec requires. Fix this.

If pPresentationTimingCount was smaller than the number of available
records, the function still returned VK_SUCCESS instead of VK_INCOMPLETE,
as the spec requires. Fix this.
2021-04-29 06:04:24 +02:00
Bill Hollings
8f94b820a8 Change documentation references to macOS 10.16 to macOS 11.0. 2021-04-27 12:53:02 -04:00
kleinerm
14bbf3453d Expose vkGetIOSurfaceMVK() / vkUseIOSurfaceMVK() also under non-ObjC.
Those functions are also usable from standard C, no need for the caller
to be compiled as Objective-C. Move their definition outside the __OBJC__
guards.
2021-04-27 17:15:30 +02:00
Bill Hollings
404aa3e8cd Metal argument buffers code review fixes.
Use `[MTLDevice maxArgumentBufferSamplerCount]` to determine maximum sampler counts.
When checking `[MTLDevice argumentBuffersSupport]` tiers, compare
using `>=` to automatically handle evolution of this value in future.
Remove suspect use of early breaks in
MVKDescriptorSetLayoutBinding::initMetalResourceIndexOffsets().
Revert to using void* when padding for buffers in shader desc set structs.
Fix several typos.
2021-04-27 10:09:16 -04:00
Bill Hollings
852610735d Merge branch master into branch argument-buffers. 2021-04-26 17:51:52 -04:00
Bill Hollings
8969e4d4a4 Update dependency libraries to match Vulkan SDK 1.2.176, and update What's New document. 2021-04-26 16:38:23 -04:00
Bill Hollings
fd7d7dabf8 MVKBitArray updates reuse pointer for data if
under 64 bits, and remove inline declarations.
2021-04-23 20:23:06 -04:00
Bill Hollings
dde1e55149 Fix memory corruption caused in tessellation pipeline
by introduction of Metal argument buffer support.

Add copy assignment operator to MVKMTLFunction, plus other objects that have
notable copy constructors: MVKBitArray, MVKShaderLibrary, MVKVulkanAPIObject.

There are still some classes that have destructors without copy and
copy assign overrides, but these are higher level classes that should
not be subject to copy or assignment by value.

Note to self: Respect the Rule of Three!
2021-04-23 14:52:55 -04:00
Bill Hollings
90daa3c388 MVKComputePipeline ensure init for Metal arg buffer support before creating MTLFunction. 2021-04-20 19:22:12 -04:00
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
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
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
55a2fe6467 Remove private flag from MVKCommandEncoder::copyToTempMTLBufferAllocation().
MVKMTLBufferAllocationPool subclass from MVKDeviceTrackingMixin.
MVKDeviceObjectPool subclass from MVKDeviceTrackingMixin.
2021-03-22 07:51:07 -04:00