mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-15 08:06:19 +00:00
Move vulkan_platform.h to common/
This file changes the non-dispatchable Vulkan handle types. We want to use some of these handles in utils/VulkanSwapChain.cpp so it needs to have access to it. The file could include backend/vulkan/vulkan_platform.h but it seems a bit cleaner to move the header in common/ instead with a warning if the Vulkan backend isn't enabled.
This commit is contained in:
committed by
Corentin Wallez
parent
cc407ae787
commit
c0f5ca1f5a
@@ -288,7 +288,6 @@ if (NXT_ENABLE_VULKAN)
|
||||
target_include_directories(vulkan_autogen PUBLIC ${SRC_DIR})
|
||||
|
||||
list(APPEND BACKEND_SOURCES
|
||||
${VULKAN_DIR}/vulkan_platform.h
|
||||
${VULKAN_DIR}/BufferUploader.cpp
|
||||
${VULKAN_DIR}/BufferUploader.h
|
||||
${VULKAN_DIR}/BufferVk.cpp
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_VULKAN_BUFFERUPLOADER_H_
|
||||
#define BACKEND_VULKAN_BUFFERUPLOADER_H_
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/SerialQueue.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
#include "backend/Buffer.h"
|
||||
|
||||
#include "backend/vulkan/MemoryAllocator.h"
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/SerialQueue.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "backend/CommandBuffer.h"
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_VULKAN_FENCEDDELETER_H_
|
||||
#define BACKEND_VULKAN_FENCEDDELETER_H_
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/SerialQueue.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "backend/Framebuffer.h"
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "backend/InputState.h"
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
#ifndef BACKEND_VULKAN_MEMORYALLOCATOR_H_
|
||||
#define BACKEND_VULKAN_MEMORYALLOCATOR_H_
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/SerialQueue.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "backend/PipelineLayout.h"
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "backend/RenderPass.h"
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "backend/RenderPipeline.h"
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "backend/ShaderModule.h"
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "backend/Texture.h"
|
||||
|
||||
#include "backend/vulkan/MemoryAllocator.h"
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
namespace backend { namespace vulkan {
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#ifndef BACKEND_VULKAN_VULKANFUNCTIONS_H_
|
||||
#define BACKEND_VULKAN_VULKANFUNCTIONS_H_
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
class DynamicLib;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#ifndef BACKEND_VULKAN_VULKANINFO_H_
|
||||
#define BACKEND_VULKAN_VULKANINFO_H_
|
||||
|
||||
#include "backend/vulkan/vulkan_platform.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
// Copyright 2017 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_VULKANPLATFORM_H_
|
||||
#define BACKEND_VULKAN_VULKANPLATFORM_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
// vulkan.h defines non-dispatchable handles to opaque pointers on 64bit architectures and uint64_t
|
||||
// on 32bit architectures. This causes a problem in 32bit where the handles cannot be used to
|
||||
// distinguish between overloads of the same function.
|
||||
// Change the definition of non-dispatchable handles to be opaque structures containing a uint64_t
|
||||
// and overload the comparison operators between themselves and VK_NULL_HANDLE (which will be
|
||||
// redefined to be nullptr). This keeps the type-safety of having the handles be different types
|
||||
// (like vulkan.h on 64 bit) but makes sure the types are different on 32 bit architectures.
|
||||
|
||||
// Simple handle types that supports "nullptr_t" as a 0 value.
|
||||
template <typename Tag>
|
||||
class VkNonDispatchableHandle {
|
||||
public:
|
||||
// Default constructor and assigning of VK_NULL_HANDLE
|
||||
VkNonDispatchableHandle() = default;
|
||||
VkNonDispatchableHandle(std::nullptr_t) : mHandle(0) {
|
||||
}
|
||||
|
||||
// Use default copy constructor/assignment
|
||||
VkNonDispatchableHandle(const VkNonDispatchableHandle<Tag>& other) = default;
|
||||
VkNonDispatchableHandle& operator=(const VkNonDispatchableHandle<Tag>&) = default;
|
||||
|
||||
// Comparisons between handles
|
||||
bool operator==(VkNonDispatchableHandle<Tag> other) {
|
||||
return mHandle == other.mHandle;
|
||||
}
|
||||
bool operator!=(VkNonDispatchableHandle<Tag> other) {
|
||||
return mHandle != other.mHandle;
|
||||
}
|
||||
|
||||
// Comparisons between handles and VK_NULL_HANDLE
|
||||
bool operator==(std::nullptr_t) {
|
||||
return mHandle == 0;
|
||||
}
|
||||
bool operator!=(std::nullptr_t) {
|
||||
return mHandle != 0;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t mHandle = 0;
|
||||
};
|
||||
|
||||
# define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) \
|
||||
struct VkTag##object; \
|
||||
using object = VkNonDispatchableHandle<VkTag##object>; \
|
||||
static_assert(sizeof(object) == sizeof(uint64_t), ""); \
|
||||
static_assert(alignof(object) == alignof(uint64_t), "");
|
||||
|
||||
# include <vulkan/vulkan.h>
|
||||
|
||||
// VK_NULL_HANDLE is defined to 0 but we don't want our handle type to compare to arbitrary
|
||||
// integers. Redefine VK_NULL_HANDLE to nullptr that has its own type.
|
||||
# undef VK_NULL_HANDLE
|
||||
# define VK_NULL_HANDLE nullptr
|
||||
|
||||
#endif // BACKEND_VULKAN_VULKANPLATFORM_H_
|
||||
Reference in New Issue
Block a user