TextureVk: Make a Create function for swapchain textures.

This aligns this constructor to be used via Create like the other
vulkan::Texture constructors.

Bug: dawn:269
Change-Id: Ib85874bf24bfe49b644b4faa63c9248c540811c8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/20882
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Corentin Wallez 2020-05-05 08:33:35 +00:00 committed by Commit Bot service account
parent 07328ba0bb
commit 3874434bf1
3 changed files with 22 additions and 8 deletions

View File

@ -49,7 +49,8 @@ namespace dawn_native { namespace vulkan {
VkImage nativeTexture = VkImage nativeTexture =
VkImage::CreateFromHandle(reinterpret_cast<::VkImage>(next.texture.u64)); VkImage::CreateFromHandle(reinterpret_cast<::VkImage>(next.texture.u64));
return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture); return Texture::CreateForSwapChain(ToBackend(GetDevice()), descriptor, nativeTexture)
.Detach();
} }
MaybeError SwapChain::OnBeforePresent(TextureBase* texture) { MaybeError SwapChain::OnBeforePresent(TextureBase* texture) {

View File

@ -432,6 +432,16 @@ namespace dawn_native { namespace vulkan {
return texture.Detach(); return texture.Detach();
} }
// static
Ref<Texture> Texture::CreateForSwapChain(Device* device,
const TextureDescriptor* descriptor,
VkImage nativeImage) {
Ref<Texture> texture =
AcquireRef(new Texture(device, descriptor, TextureState::OwnedExternal));
texture->InitializeForSwapChain(nativeImage);
return std::move(texture);
}
MaybeError Texture::InitializeAsInternalTexture() { MaybeError Texture::InitializeAsInternalTexture() {
Device* device = ToBackend(GetDevice()); Device* device = ToBackend(GetDevice());
@ -491,11 +501,6 @@ namespace dawn_native { namespace vulkan {
return {}; return {};
} }
// With this constructor, the lifetime of the resource is externally managed.
Texture::Texture(Device* device, const TextureDescriptor* descriptor, VkImage nativeImage)
: TextureBase(device, descriptor, TextureState::OwnedExternal), mHandle(nativeImage) {
}
// Internally managed, but imported from external handle // Internally managed, but imported from external handle
MaybeError Texture::InitializeFromExternal(const ExternalImageDescriptor* descriptor, MaybeError Texture::InitializeFromExternal(const ExternalImageDescriptor* descriptor,
external_memory::Service* externalMemoryService) { external_memory::Service* externalMemoryService) {
@ -529,6 +534,10 @@ namespace dawn_native { namespace vulkan {
return {}; return {};
} }
void Texture::InitializeForSwapChain(VkImage nativeImage) {
mHandle = nativeImage;
}
MaybeError Texture::BindExternalMemory(const ExternalImageDescriptor* descriptor, MaybeError Texture::BindExternalMemory(const ExternalImageDescriptor* descriptor,
VkSemaphore signalSemaphore, VkSemaphore signalSemaphore,
VkDeviceMemory externalMemoryAllocation, VkDeviceMemory externalMemoryAllocation,

View File

@ -52,7 +52,10 @@ namespace dawn_native { namespace vulkan {
const TextureDescriptor* textureDescriptor, const TextureDescriptor* textureDescriptor,
external_memory::Service* externalMemoryService); external_memory::Service* externalMemoryService);
Texture(Device* device, const TextureDescriptor* descriptor, VkImage nativeImage); // Creates a texture that wraps a swapchain-allocated VkImage.
static Ref<Texture> CreateForSwapChain(Device* device,
const TextureDescriptor* descriptor,
VkImage nativeImage);
VkImage GetHandle() const; VkImage GetHandle() const;
VkImageAspectFlags GetVkAspectMask() const; VkImageAspectFlags GetVkAspectMask() const;
@ -79,10 +82,11 @@ namespace dawn_native { namespace vulkan {
private: private:
~Texture() override; ~Texture() override;
using TextureBase::TextureBase; using TextureBase::TextureBase;
MaybeError InitializeAsInternalTexture();
MaybeError InitializeAsInternalTexture();
MaybeError InitializeFromExternal(const ExternalImageDescriptor* descriptor, MaybeError InitializeFromExternal(const ExternalImageDescriptor* descriptor,
external_memory::Service* externalMemoryService); external_memory::Service* externalMemoryService);
void InitializeForSwapChain(VkImage nativeImage);
void DestroyImpl() override; void DestroyImpl() override;
MaybeError ClearTexture(CommandRecordingContext* recordingContext, MaybeError ClearTexture(CommandRecordingContext* recordingContext,