Vulkan: Split off and implement SwapChain
This commit is contained in:
parent
0887236c81
commit
49588b0b8d
|
@ -310,6 +310,8 @@ if (NXT_ENABLE_VULKAN)
|
||||||
${VULKAN_DIR}/RenderPipelineVk.h
|
${VULKAN_DIR}/RenderPipelineVk.h
|
||||||
${VULKAN_DIR}/ShaderModuleVk.cpp
|
${VULKAN_DIR}/ShaderModuleVk.cpp
|
||||||
${VULKAN_DIR}/ShaderModuleVk.h
|
${VULKAN_DIR}/ShaderModuleVk.h
|
||||||
|
${VULKAN_DIR}/SwapChainVk.cpp
|
||||||
|
${VULKAN_DIR}/SwapChainVk.h
|
||||||
${VULKAN_DIR}/TextureVk.cpp
|
${VULKAN_DIR}/TextureVk.cpp
|
||||||
${VULKAN_DIR}/TextureVk.h
|
${VULKAN_DIR}/TextureVk.h
|
||||||
${VULKAN_DIR}/VulkanBackend.cpp
|
${VULKAN_DIR}/VulkanBackend.cpp
|
||||||
|
|
|
@ -20,5 +20,6 @@
|
||||||
#include "backend/vulkan/RenderPassVk.h"
|
#include "backend/vulkan/RenderPassVk.h"
|
||||||
#include "backend/vulkan/RenderPipelineVk.h"
|
#include "backend/vulkan/RenderPipelineVk.h"
|
||||||
#include "backend/vulkan/ShaderModuleVk.h"
|
#include "backend/vulkan/ShaderModuleVk.h"
|
||||||
|
#include "backend/vulkan/SwapChainVk.h"
|
||||||
#include "backend/vulkan/TextureVk.h"
|
#include "backend/vulkan/TextureVk.h"
|
||||||
#include "backend/vulkan/VulkanBackend.h"
|
#include "backend/vulkan/VulkanBackend.h"
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
// Copyright 2018 The NXT Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "backend/vulkan/SwapChainVk.h"
|
||||||
|
|
||||||
|
#include "backend/vulkan/TextureVk.h"
|
||||||
|
#include "backend/vulkan/VulkanBackend.h"
|
||||||
|
|
||||||
|
namespace backend { namespace vulkan {
|
||||||
|
|
||||||
|
SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) {
|
||||||
|
const auto& im = GetImplementation();
|
||||||
|
nxtWSIContextVulkan wsiContext = {};
|
||||||
|
im.Init(im.userData, &wsiContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
SwapChain::~SwapChain() {
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
|
||||||
|
const auto& im = GetImplementation();
|
||||||
|
nxtSwapChainNextTexture next = {};
|
||||||
|
nxtSwapChainError error = im.GetNextTexture(im.userData, &next);
|
||||||
|
if (error) {
|
||||||
|
GetDevice()->HandleError(error);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkImage nativeTexture = VkImage::CreateFromHandle(next.texture.u64);
|
||||||
|
return new Texture(builder, nativeTexture);
|
||||||
|
}
|
||||||
|
|
||||||
|
}} // namespace backend::vulkan
|
|
@ -0,0 +1,35 @@
|
||||||
|
// Copyright 2018 The NXT Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef BACKEND_VULKAN_SWAPCHAINVK_H_
|
||||||
|
#define BACKEND_VULKAN_SWAPCHAINVK_H_
|
||||||
|
|
||||||
|
#include "backend/SwapChain.h"
|
||||||
|
|
||||||
|
#include "common/vulkan_platform.h"
|
||||||
|
|
||||||
|
namespace backend { namespace vulkan {
|
||||||
|
|
||||||
|
class SwapChain : public SwapChainBase {
|
||||||
|
public:
|
||||||
|
SwapChain(SwapChainBuilder* builder);
|
||||||
|
~SwapChain();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}} // namespace backend::vulkan
|
||||||
|
|
||||||
|
#endif // BACKEND_VULKAN_SWAPCHAINVK_H_
|
|
@ -260,6 +260,10 @@ namespace backend { namespace vulkan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Texture::Texture(TextureBuilder* builder, VkImage nativeImage)
|
||||||
|
: TextureBase(builder), mHandle(nativeImage) {
|
||||||
|
}
|
||||||
|
|
||||||
Texture::~Texture() {
|
Texture::~Texture() {
|
||||||
Device* device = ToBackend(GetDevice());
|
Device* device = ToBackend(GetDevice());
|
||||||
|
|
||||||
|
@ -267,6 +271,7 @@ namespace backend { namespace vulkan {
|
||||||
// after the VkImage is destroyed and this is taken care of by the FencedDeleter.
|
// after the VkImage is destroyed and this is taken care of by the FencedDeleter.
|
||||||
device->GetMemoryAllocator()->Free(&mMemoryAllocation);
|
device->GetMemoryAllocator()->Free(&mMemoryAllocation);
|
||||||
|
|
||||||
|
// If we own the resource, release it.
|
||||||
if (mHandle != VK_NULL_HANDLE) {
|
if (mHandle != VK_NULL_HANDLE) {
|
||||||
device->GetFencedDeleter()->DeleteWhenUnused(mHandle);
|
device->GetFencedDeleter()->DeleteWhenUnused(mHandle);
|
||||||
mHandle = VK_NULL_HANDLE;
|
mHandle = VK_NULL_HANDLE;
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace backend { namespace vulkan {
|
||||||
class Texture : public TextureBase {
|
class Texture : public TextureBase {
|
||||||
public:
|
public:
|
||||||
Texture(TextureBuilder* builder);
|
Texture(TextureBuilder* builder);
|
||||||
|
Texture(TextureBuilder* builder, VkImage nativeImage);
|
||||||
~Texture();
|
~Texture();
|
||||||
|
|
||||||
VkImage GetHandle() const;
|
VkImage GetHandle() const;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "backend/vulkan/RenderPassVk.h"
|
#include "backend/vulkan/RenderPassVk.h"
|
||||||
#include "backend/vulkan/RenderPipelineVk.h"
|
#include "backend/vulkan/RenderPipelineVk.h"
|
||||||
#include "backend/vulkan/ShaderModuleVk.h"
|
#include "backend/vulkan/ShaderModuleVk.h"
|
||||||
|
#include "backend/vulkan/SwapChainVk.h"
|
||||||
#include "backend/vulkan/TextureVk.h"
|
#include "backend/vulkan/TextureVk.h"
|
||||||
#include "common/Platform.h"
|
#include "common/Platform.h"
|
||||||
|
|
||||||
|
@ -603,17 +604,4 @@ namespace backend { namespace vulkan {
|
||||||
device->SubmitPendingCommands();
|
device->SubmitPendingCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SwapChain
|
|
||||||
|
|
||||||
SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) {
|
|
||||||
const auto& im = GetImplementation();
|
|
||||||
im.Init(im.userData, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
SwapChain::~SwapChain() {
|
|
||||||
}
|
|
||||||
|
|
||||||
TextureBase* SwapChain::GetNextTextureImpl(TextureBuilder* builder) {
|
|
||||||
return GetDevice()->CreateTexture(builder);
|
|
||||||
}
|
|
||||||
}} // namespace backend::vulkan
|
}} // namespace backend::vulkan
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "backend/Device.h"
|
#include "backend/Device.h"
|
||||||
#include "backend/Queue.h"
|
#include "backend/Queue.h"
|
||||||
#include "backend/Sampler.h"
|
#include "backend/Sampler.h"
|
||||||
#include "backend/SwapChain.h"
|
|
||||||
#include "backend/ToBackend.h"
|
#include "backend/ToBackend.h"
|
||||||
#include "backend/vulkan/VulkanFunctions.h"
|
#include "backend/vulkan/VulkanFunctions.h"
|
||||||
#include "backend/vulkan/VulkanInfo.h"
|
#include "backend/vulkan/VulkanInfo.h"
|
||||||
|
@ -208,15 +207,6 @@ namespace backend { namespace vulkan {
|
||||||
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
|
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SwapChain : public SwapChainBase {
|
|
||||||
public:
|
|
||||||
SwapChain(SwapChainBuilder* builder);
|
|
||||||
~SwapChain();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
TextureBase* GetNextTextureImpl(TextureBuilder* builder) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
}} // namespace backend::vulkan
|
}} // namespace backend::vulkan
|
||||||
|
|
||||||
#endif // BACKEND_VULKAN_VULKANBACKEND_H_
|
#endif // BACKEND_VULKAN_VULKANBACKEND_H_
|
||||||
|
|
|
@ -59,7 +59,14 @@ class VkNonDispatchableHandle {
|
||||||
return mHandle != 0;
|
return mHandle != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VkNonDispatchableHandle<Tag> CreateFromHandle(uint64_t handle) {
|
||||||
|
return {handle};
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
VkNonDispatchableHandle(uint64_t handle) : mHandle(handle) {
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t mHandle = 0;
|
uint64_t mHandle = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue