Some buffers, particularly those used by tessellation, indirect
multiview, or occlusion queries, are never written or read from the
host. Keeping the relevant data in VRAM should improve performance by
reducing the need for the GPU to make expensive accesses over the PCI
bus.
VRAM is a scarce resource on discrete GPUs, but this is part of why we
marked the buffers volatile.
Derive MVK_APPLE_SILICON from target CPU.
Derive MVK_MACOS_APPLE_SILICON from target CPU and macOS platform.
Derive MVK_XCODE_12 from macOS and iOS SDK versions.
Test for simulator on non-Apple GPU using MVK_OS_SIMULATOR && !MVK_APPLE_SILICON.
MTLDevice retains an internal object web that is used during the creation of
new objects, such as pipeline states, libraries, functions, and samplers.
Simultaneously creating and destroying objects of these types can trigger
race conditions on the internal MTLDevice content.
Wrap the following in @synchronized (mtlDevice) {...}:
- MTLRenderPipelineState creation and destruction
- MTLComputePipelineState creation and destruction
- MTLLibrary creation
- MTLFunction creation and specialization
- MTLSampler creation and destruction
MVKCommandEncoderState has numerous subclasses, and the polymorphic
MVKCommandEncoderState::resetImpl() requires significant maintenance
across these subclasses. It's only use was in disabling depth-stencil state.
Remove MVKCommandEncoderState::reset() and all implementations of resetImpl()
across all MVKCommandEncoderState subclasses.
Remove MVKPipeline::__hasDepthStencilInfo and disable depth-stencil state
automatically via cleared Vulkan struct in MVKPipeline.
Don't reset MVKOcclusionQueryCommandEncoderState::_mtlVisibilityResultOffset
when ending occlusion query, as subsequent queries need different offsets.
Also, remove MVKOcclusionQueryCommandEncoderState::_needsVisibilityResultMTLBuffer,
as it is always set once from MVKCommandBuffer::_needsVisibilityResultMTLBuffer.
When app setting MVKConfiguration it with a partial copy, start with existing.
It is possible for the maximum buffer size to be 4 binary gigabytes or
greater. In that case, the upper 32 bits will be lost, and the value of
the `maxUniformBufferRange` and `maxStorageBufferRange` limits would be
too small or even zero. Clamp it to 4 GiB - 1 in that case, since that
is the maximum value of a 32-bit integer.
For #1240.
Refactor auto GPU capture code to support both device and frame capture.
Add ability to automatically capture first GPU frame by setting
`MVK_CONFIG_AUTO_GPU_CAPTURE_SCOPE` to `2`.
Wrap GPU capture in autorelease pool to handle both cases of capture call
being made in run loop as in an app GUI, or in one-shot app like CTS.
They are not expected to be useful beyond the commands that use them,
but they take up memory nonetheless. This is exactly the use case
purgeability was designed for. Tell the system that it's OK to reclaim
their memory if necessary.
Doing this every time the buffer is used will cause the purgeable state
to be reset from `MTLPurgeableStateEmpty`, in case the system really did
reclaim their memory.
In accordance with Apple's advice, lock the pages for the buffer when
loading it, so the memory isn't pulled out from under us.
Add support for "dedicated" temp buffers, where instead of allocating a
big buffer and carving regions out of it, a unique buffer is returned
for each allocation request. This is necessary for visibility buffers,
because the offset passed to `-[MTLRenderCommandEncoder
setVisibilityResultMode:offset:]` cannot exceed an
implementation-defined value, currently 256k less 8 bytes for Mac family
2 on Catalina and up, and on Apple family 7; and 64k less 8 bytes
otherwise.
According to the Metal Feature Set Tables, only family 2 supports
quad-scope permutation. We've been seeing issues with SIMD-group
functions on family 1 hardware, so for now I'm moving quad-group
permutation to family 2.