Skip to content

Commit

Permalink
Merge pull request #852 from billhollings/master
Browse files Browse the repository at this point in the history
Various fixes resulting from testing for SDK release.
  • Loading branch information
billhollings authored Apr 6, 2020
2 parents 2352ae1 + a644c98 commit 1a25de5
Show file tree
Hide file tree
Showing 14 changed files with 265 additions and 161 deletions.
3 changes: 0 additions & 3 deletions Demos/Demos.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ as a system library instead.
<a name="lunarg-vulkan-samples-api"></a>
### *API-Samples*

This *Xcode* project actually contains a large number of modular demos, with each demo
> **_Note:_** The `Vulkan-Samples API-Samples` have recently changed to use a different build
process that involves converting GLSL to SPIR-V via scripts. This upgrade has not yet been
integrated into the *Xcode*-based build environment used to build these demos here.
As a result, the `API-Samples` demos have been disabled here until this can be corrected.

This *Xcode* project contains a large number of modular demos, with each demo
demonstrating a particular *Vulkan* feature, or suite of calls.

This demo can be found in the `LunarG-VulkanSamples/API-Samples` folder, and in the
Expand All @@ -77,7 +82,7 @@ To specify which of the many modular demos to run, open the `Samples.h` in the `
project in the *Xcode Project Navigator* in the `Demos.xcworkspace` *Xcode* workspace, and
follow the instructions in the comments within that file.

> **Note:** For simplicity, the `API-Samples` demos are bare-bones. Each of the `API-Samples`
> **_Note:_** For simplicity, the `API-Samples` demos are bare-bones. Each of the `API-Samples`
> demos renders a single frame during app startup, and then leaves the rendered image static.
> There is no display loop or motion in any of these demos.
> **This is normal for these demos, and the demo has not "hung" or "crashed" when this occurs.**
Expand All @@ -91,7 +96,7 @@ The `API-Samples` demo is a simple example of installing **MoltenVK** as a *stat
<a name="lunarg-vulkan-samples-hologram"></a>
### *Hologram*

> **Note:** In order to build the `Hologram` demo, you must have *Python3* installed
> **_Note:_** In order to build the `Hologram` demo, you must have *Python3* installed
> on your build computer.
This is a sophisticated particle demo that populates command buffers from multiple threads.
Expand Down
2 changes: 2 additions & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ Released 2020/04/05
- Fix issue causing screen captures from swapchain image to deadlock.
- Fix memory estimates for iOS 13+.
- Broaden conditions for host read sync for image memory barriers on macOS.
- Fix issue of reseting `CAMetalDrawable` and `MTLTexture` of peer swapchain images.
- Fix the `make install` build command to overwrite the existing framework in the system
framework library, and update `README.md` to clarify the instructions for using `make install`.
- Update the `README.md` and `MoltenVK_Runtime_UserGuide.md` documents to clarify that
**MoltenVK** is not a fully-compliant implementation of *Vulkan*.
- Support Xcode 11.4.
- Disable `API-Samples` demos and document in `Demos/README.md`.
- Update dependency libraries to match *Vulkan SDK 1.2.135*.
- Update to latest SPIRV-Cross version:
- MSL: Support inline uniform blocks in argument buffers.
Expand Down
4 changes: 2 additions & 2 deletions MoltenVK/MoltenVK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,6 @@
A94FB7841C7DFB4800632CA3 /* MVKDevice.mm */,
A94FB7851C7DFB4800632CA3 /* MVKDeviceMemory.h */,
A94FB7861C7DFB4800632CA3 /* MVKDeviceMemory.mm */,
A9653FB724129C84005999D7 /* MVKPixelFormats.h */,
A9653FB924129C84005999D7 /* MVKPixelFormats.mm */,
A94FB7871C7DFB4800632CA3 /* MVKFramebuffer.h */,
A94FB7881C7DFB4800632CA3 /* MVKFramebuffer.mm */,
A94FB7891C7DFB4800632CA3 /* MVKImage.h */,
Expand All @@ -513,6 +511,8 @@
A94FB78C1C7DFB4800632CA3 /* MVKInstance.mm */,
A94FB78D1C7DFB4800632CA3 /* MVKPipeline.h */,
A94FB78E1C7DFB4800632CA3 /* MVKPipeline.mm */,
A9653FB724129C84005999D7 /* MVKPixelFormats.h */,
A9653FB924129C84005999D7 /* MVKPixelFormats.mm */,
A94FB78F1C7DFB4800632CA3 /* MVKQueryPool.h */,
A94FB7901C7DFB4800632CA3 /* MVKQueryPool.mm */,
A94FB7911C7DFB4800632CA3 /* MVKQueue.h */,
Expand Down
12 changes: 12 additions & 0 deletions MoltenVK/MoltenVK/API/vk_mvk_moltenvk.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ typedef unsigned long MTLLanguageVersion;
* a command is executed. This is a classic time-space trade off. When command pooling is
* active, the memory in the pool can be cleared via a call to the vkTrimCommandPoolKHR()
* command. This setting is enabled by default, and MoltenVK will pool command memory.
*
* 9. The MVK_CONFIG_USE_MTLHEAP runtime environment variable or MoltenVK compile-time build
* setting controls whether MoltenVK should use MTLHeaps for allocating textures and buffers
* from device memory. If this environment variable is enabled, and placement MTLHeaps are
* available on the platform, MoltenVK will allocate a placement MTLHeap for each VkDeviceMemory
* instance, and allocate textures and buffers from that placement heap. If this environment
* variable is disabled, MoltenVK will allocate textures and buffers from general device memory.
* Apple recommends that MTLHeaps should only be used for specific requirements such as aliasing
* or hazard tracking, and MoltenVK testing has shown that allocating multiple textures of
* different types or usages from one MTLHeap can occassionally cause corruption issues under
* certain circumstances. Because of this, this setting is disabled by default, and MoltenVK
* will allocate texures and buffers from general device memory.
*/
typedef struct {

Expand Down
14 changes: 7 additions & 7 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MVKResource;
class MVKBuffer;
class MVKBufferView;
class MVKImage;
class MVKSwapchainImage;
class MVKPresentableSwapchainImage;
class MVKImageView;
class MVKSwapchain;
class MVKDeviceMemory;
Expand Down Expand Up @@ -450,12 +450,12 @@ class MVKDevice : public MVKDispatchableVulkanAPIObject {
void destroySwapchain(MVKSwapchain* mvkSwpChn,
const VkAllocationCallbacks* pAllocator);

MVKSwapchainImage* createSwapchainImage(const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex,
const VkAllocationCallbacks* pAllocator);
void destroySwapchainImage(MVKSwapchainImage* mvkImg,
const VkAllocationCallbacks* pAllocator);
MVKPresentableSwapchainImage* createPresentableSwapchainImage(const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex,
const VkAllocationCallbacks* pAllocator);
void destroyPresentableSwapchainImage(MVKPresentableSwapchainImage* mvkImg,
const VkAllocationCallbacks* pAllocator);

MVKFence* createFence(const VkFenceCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator);
Expand Down
38 changes: 22 additions & 16 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,15 @@

// Initializes the Metal-specific physical device features of this instance.
void MVKPhysicalDevice::initMetalFeatures() {
mvkClear(&_metalFeatures); // Start with everything cleared

# ifndef MVK_CONFIG_USE_MTLHEAP
# define MVK_CONFIG_USE_MTLHEAP 0
# endif
bool useMTLHeaps;
MVK_SET_FROM_ENV_OR_BUILD_BOOL(useMTLHeaps, MVK_CONFIG_USE_MTLHEAP);

// Start with all Metal features cleared
mvkClear(&_metalFeatures);

_metalFeatures.maxPerStageBufferCount = 31;
_metalFeatures.maxMTLBufferSize = (256 * MEBI);
Expand Down Expand Up @@ -848,7 +856,7 @@

if ( mvkOSVersionIsAtLeast(13.0) ) {
_metalFeatures.mslVersionEnum = MTLLanguageVersion2_2;
_metalFeatures.placementHeaps = true;
_metalFeatures.placementHeaps = useMTLHeaps;
if (supportsMTLGPUFamily(Apple4)) {
_metalFeatures.nativeTextureSwizzle = true;
}
Expand Down Expand Up @@ -904,7 +912,7 @@
_metalFeatures.native3DCompressedTextures = true;
if (supportsMTLGPUFamily(Mac2)) {
_metalFeatures.nativeTextureSwizzle = true;
_metalFeatures.placementHeaps = true;
_metalFeatures.placementHeaps = useMTLHeaps;
}
}

Expand Down Expand Up @@ -957,7 +965,6 @@
break;
#endif
}

}

// Initializes the physical device features of this instance.
Expand Down Expand Up @@ -2131,7 +2138,7 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}
}
if (swapchainInfo) {
return createSwapchainImage(pCreateInfo, (MVKSwapchain*)swapchainInfo->swapchain, uint32_t(-1), pAllocator);
return (MVKImage*)addResource(new MVKPeerSwapchainImage(this, pCreateInfo, (MVKSwapchain*)swapchainInfo->swapchain, uint32_t(-1)));
}
return (MVKImage*)addResource(new MVKImage(this, pCreateInfo));
}
Expand Down Expand Up @@ -2162,15 +2169,15 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
mvkSwpChn->destroy();
}

MVKSwapchainImage* MVKDevice::createSwapchainImage(const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex,
const VkAllocationCallbacks* pAllocator) {
return (MVKSwapchainImage*)addResource(new MVKSwapchainImage(this, pCreateInfo, swapchain, swapchainIndex));
MVKPresentableSwapchainImage* MVKDevice::createPresentableSwapchainImage(const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex,
const VkAllocationCallbacks* pAllocator) {
return (MVKPresentableSwapchainImage*)addResource(new MVKPresentableSwapchainImage(this, pCreateInfo, swapchain, swapchainIndex));
}

void MVKDevice::destroySwapchainImage(MVKSwapchainImage* mvkImg,
const VkAllocationCallbacks* pAllocator) {
void MVKDevice::destroyPresentableSwapchainImage(MVKPresentableSwapchainImage* mvkImg,
const VkAllocationCallbacks* pAllocator) {
removeResource(mvkImg);
mvkImg->destroy();
}
Expand Down Expand Up @@ -2656,10 +2663,9 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}
MVKLogInfo("Using %s for Vulkan semaphores.", _useMTLFenceForSemaphores ? "MTLFence" : (_useMTLEventForSemaphores ? "MTLEvent" : "emulation"));

#ifndef MVK_CONFIG_USE_COMMAND_POOLING
# define MVK_CONFIG_USE_COMMAND_POOLING 1
#endif
_useCommandPooling = MVK_CONFIG_USE_COMMAND_POOLING;
# ifndef MVK_CONFIG_USE_COMMAND_POOLING
# define MVK_CONFIG_USE_COMMAND_POOLING 1
# endif
MVK_SET_FROM_ENV_OR_BUILD_BOOL(_useCommandPooling, MVK_CONFIG_USE_COMMAND_POOLING);

#if MVK_MACOS
Expand Down
100 changes: 75 additions & 25 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class MVKImage : public MVKResource {
#pragma mark Metal

/** Returns the Metal texture underlying this image. */
id<MTLTexture> getMTLTexture();
virtual id<MTLTexture> getMTLTexture();

/** Returns a Metal texture that interprets the pixels in the specified format. */
id<MTLTexture> getMTLTexture(MTLPixelFormat mtlPixFmt);
Expand Down Expand Up @@ -235,9 +235,9 @@ class MVKImage : public MVKResource {
bool validateUseTexelBuffer();
void initSubresources(const VkImageCreateInfo* pCreateInfo);
void initSubresourceLayout(MVKImageSubresource& imgSubRez);
virtual id<MTLTexture> newMTLTexture();
void resetMTLTexture();
void resetIOSurface();
id<MTLTexture> newMTLTexture();
void releaseMTLTexture();
void releaseIOSurface();
MTLTextureDescriptor* newMTLTextureDescriptor();
void updateMTLTextureContent(MVKImageSubresource& subresource, VkDeviceSize offset, VkDeviceSize size);
void getMTLTextureContent(MVKImageSubresource& subresource, VkDeviceSize offset, VkDeviceSize size);
Expand Down Expand Up @@ -274,10 +274,44 @@ class MVKImage : public MVKResource {
#pragma mark -
#pragma mark MVKSwapchainImage

/** Abstract class of Vulkan image used as a rendering destination within a swapchain. */
class MVKSwapchainImage : public MVKImage {

public:

/** Binds this resource to the specified offset within the specified memory allocation. */
VkResult bindDeviceMemory(MVKDeviceMemory* mvkMem, VkDeviceSize memOffset) override;

#pragma mark Metal

/** Returns the Metal texture used by the CAMetalDrawable underlying this image. */
id<MTLTexture> getMTLTexture() override;


#pragma mark Construction

/** Constructs an instance for the specified device and swapchain. */
MVKSwapchainImage(MVKDevice* device,
const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex);

protected:
friend class MVKPeerSwapchainImage;

virtual id<CAMetalDrawable> getCAMetalDrawable() = 0;

MVKSwapchain* _swapchain;
uint32_t _swapchainIndex;
};


#pragma mark -
#pragma mark MVKPresentableSwapchainImage

/** Indicates the relative availability of each image in the swapchain. */
typedef struct MVKSwapchainImageAvailability {
uint64_t acquisitionID; /**< When this image was last made available, relative to the other images in the swapchain. Smaller value is earlier. */
uint32_t waitCount; /**< The number of semaphores already waiting for this image. */
bool isAvailable; /**< Indicates whether this image is currently available. */

bool operator< (const MVKSwapchainImageAvailability& rhs) const;
Expand All @@ -287,18 +321,11 @@ typedef struct MVKSwapchainImageAvailability {
typedef std::pair<MVKSemaphore*, MVKFence*> MVKSwapchainSignaler;


/** Represents a Vulkan image used as a rendering destination within a swapchain. */
class MVKSwapchainImage : public MVKImage {
/** Represents a Vulkan swapchain image that can be submitted to the presentation engine. */
class MVKPresentableSwapchainImage : public MVKSwapchainImage {

public:

/** Binds this resource to the specified offset within the specified memory allocation. */
VkResult bindDeviceMemory(MVKDeviceMemory* mvkMem, VkDeviceSize memOffset) override;

/** Binds this resource according to the specified bind information. */
VkResult bindDeviceMemory2(const void* pBindInfo) override;


#pragma mark Metal

/**
Expand All @@ -315,30 +342,27 @@ class MVKSwapchainImage : public MVKImage {
#pragma mark Construction

/** Constructs an instance for the specified device and swapchain. */
MVKSwapchainImage(MVKDevice* device,
const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex);
MVKPresentableSwapchainImage(MVKDevice* device,
const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex);

~MVKSwapchainImage() override;
~MVKPresentableSwapchainImage() override;

protected:
friend MVKSwapchain;

id<MTLTexture> newMTLTexture() override;
id<CAMetalDrawable> getCAMetalDrawable();
void resetMetalDrawable();
id<CAMetalDrawable> getCAMetalDrawable() override;
void releaseMetalDrawable();
MVKSwapchainImageAvailability getAvailability();
void makeAvailable();
void signalWhenAvailable(MVKSemaphore* semaphore, MVKFence* fence);
void acquireAndSignalWhenAvailable(MVKSemaphore* semaphore, MVKFence* fence);
void signal(MVKSwapchainSignaler& signaler, id<MTLCommandBuffer> mtlCmdBuff);
void signalPresentationSemaphore(id<MTLCommandBuffer> mtlCmdBuff);
static void markAsTracked(MVKSwapchainSignaler& signaler);
static void unmarkAsTracked(MVKSwapchainSignaler& signaler);
void renderWatermark(id<MTLCommandBuffer> mtlCmdBuff);

MVKSwapchain* _swapchain;
uint32_t _swapchainIndex;
id<CAMetalDrawable> _mtlDrawable;
MVKSwapchainImageAvailability _availability;
MVKVectorInline<MVKSwapchainSignaler, 1> _availabilitySignalers;
Expand All @@ -347,6 +371,32 @@ class MVKSwapchainImage : public MVKImage {
};


#pragma mark -
#pragma mark MVKPeerSwapchainImage

/** Represents a Vulkan swapchain image that can be associated as a peer to a swapchain image. */
class MVKPeerSwapchainImage : public MVKSwapchainImage {

public:

/** Binds this resource according to the specified bind information. */
VkResult bindDeviceMemory2(const void* pBindInfo) override;


#pragma mark Construction

/** Constructs an instance for the specified device and swapchain. */
MVKPeerSwapchainImage(MVKDevice* device,
const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain,
uint32_t swapchainIndex);

protected:
id<CAMetalDrawable> getCAMetalDrawable() override;

};


#pragma mark -
#pragma mark MVKImageView

Expand Down
Loading

0 comments on commit 1a25de5

Please sign in to comment.