Skip to content

Commit

Permalink
Merge pull request #850 from billhollings/master
Browse files Browse the repository at this point in the history
Support screen captures.
  • Loading branch information
billhollings authored Apr 2, 2020
2 parents d256991 + 2037b6c commit df11916
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 368 deletions.
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Released 2020/03/30
- Add ability to disable command memory pooling using `MVK_CONFIG_USE_COMMAND_POOLING`
environment variable.
- Fix memory leak when pre-filling `MTLCommandBuffers` using `MVK_CONFIG_PREFILL_METAL_COMMAND_BUFFERS`.
- Broaden conditions for host read sync for image memory barriers on macOS.
- 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.
Expand Down
2 changes: 1 addition & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope
}
}
if (swapchainInfo) {
return (MVKImage*)addResource(new MVKSwapchainImage(this, pCreateInfo, (MVKSwapchain*)swapchainInfo->swapchain));
return createSwapchainImage(pCreateInfo, (MVKSwapchain*)swapchainInfo->swapchain, uint32_t(-1), pAllocator);
}
return (MVKImage*)addResource(new MVKImage(this, pCreateInfo));
}
Expand Down
131 changes: 76 additions & 55 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,82 @@ class MVKImage : public MVKResource {
};


#pragma mark -
#pragma mark MVKSwapchainImage

/** 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;
} MVKSwapchainImageAvailability;

/** Tracks a semaphore and fence for later signaling. */
typedef std::pair<MVKSemaphore*, MVKFence*> MVKSwapchainSignaler;


/** Represents a 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;

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


#pragma mark Metal

/**
* Presents the contained drawable to the OS, releases the Metal drawable and its
* texture back to the Metal layer's pool, and makes the image memory available for new use.
*
* If mtlCmdBuff is not nil, the contained drawable is scheduled for presentation using
* the presentDrawable: method of the command buffer. If mtlCmdBuff is nil, the contained
* drawable is presented immediately using the present method of the drawable.
*/
void presentCAMetalDrawable(id<MTLCommandBuffer> mtlCmdBuff);


#pragma mark Construction

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

~MVKSwapchainImage() override;

protected:
friend MVKSwapchain;

id<MTLTexture> newMTLTexture() override;
id<CAMetalDrawable> getCAMetalDrawable();
void resetMetalDrawable();
MVKSwapchainImageAvailability getAvailability();
void makeAvailable();
void signalWhenAvailable(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;
MVKSwapchainSignaler _preSignaler;
std::mutex _availabilityLock;
};


#pragma mark -
#pragma mark MVKImageView

Expand Down Expand Up @@ -401,58 +477,3 @@ class MVKSampler : public MVKVulkanAPIDeviceObject {
SPIRV_CROSS_NAMESPACE::MSLConstexprSampler _constExprSampler;
bool _requiresConstExprSampler;
};


#pragma mark -
#pragma mark MVKSwapchainImage

/** Represents a 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;

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


#pragma mark Metal

/**
* Presents the contained drawable to the OS, releases the Metal drawable and its
* texture back to the Metal layer's pool, and makes the image memory available for new use.
*
* If mtlCmdBuff is not nil, the contained drawable is scheduled for presentation using
* the presentDrawable: method of the command buffer. If mtlCmdBuff is nil, the contained
* drawable is presented immediately using the present method of the drawable.
*/
void presentCAMetalDrawable(id<MTLCommandBuffer> mtlCmdBuff);


#pragma mark Construction

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

/** Constructs an instance for the specified device and swapchain, without binding to a particular swapchain image index. */
MVKSwapchainImage(MVKDevice* device,
const VkImageCreateInfo* pCreateInfo,
MVKSwapchain* swapchain);

~MVKSwapchainImage() override;

protected:
id<MTLTexture> newMTLTexture() override;
id<CAMetalDrawable> getCAMetalDrawable();
void resetMetalSurface();
void renderWatermark(id<MTLCommandBuffer> mtlCmdBuff);

MVKSwapchain* _swapchain;
uint32_t _swapchainIndex;
};

Loading

0 comments on commit df11916

Please sign in to comment.