dawn_native: define exported functions in their own files.

This adds a new FooBackend.cpp file for each backend that defines
exactly the symbols that are exported by libdawn_native's headers. THis
will allow factoring most of the compilation of dawn_native between the
shared and static library variants.

BUG=dawn:85

Change-Id: I69c808dac2fe5e8bb08356117e3997677787b08a
Reviewed-on: https://dawn-review.googlesource.com/c/3760
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2019-01-09 08:35:16 +00:00 committed by Commit Bot service account
parent 5236eb2057
commit 97d2a71684
13 changed files with 476 additions and 342 deletions

View File

@ -447,6 +447,7 @@ source_set("libdawn_native_sources") {
"src/dawn_native/d3d12/CommandBufferD3D12.h", "src/dawn_native/d3d12/CommandBufferD3D12.h",
"src/dawn_native/d3d12/ComputePipelineD3D12.cpp", "src/dawn_native/d3d12/ComputePipelineD3D12.cpp",
"src/dawn_native/d3d12/ComputePipelineD3D12.h", "src/dawn_native/d3d12/ComputePipelineD3D12.h",
"src/dawn_native/d3d12/D3D12Backend.cpp",
"src/dawn_native/d3d12/DescriptorHeapAllocator.cpp", "src/dawn_native/d3d12/DescriptorHeapAllocator.cpp",
"src/dawn_native/d3d12/DescriptorHeapAllocator.h", "src/dawn_native/d3d12/DescriptorHeapAllocator.h",
"src/dawn_native/d3d12/DeviceD3D12.cpp", "src/dawn_native/d3d12/DeviceD3D12.cpp",
@ -504,6 +505,7 @@ source_set("libdawn_native_sources") {
"src/dawn_native/metal/Forward.h", "src/dawn_native/metal/Forward.h",
"src/dawn_native/metal/InputStateMTL.h", "src/dawn_native/metal/InputStateMTL.h",
"src/dawn_native/metal/InputStateMTL.mm", "src/dawn_native/metal/InputStateMTL.mm",
"src/dawn_native/metal/MetalBackend.mm",
"src/dawn_native/metal/PipelineLayoutMTL.h", "src/dawn_native/metal/PipelineLayoutMTL.h",
"src/dawn_native/metal/PipelineLayoutMTL.mm", "src/dawn_native/metal/PipelineLayoutMTL.mm",
"src/dawn_native/metal/QueueMTL.h", "src/dawn_native/metal/QueueMTL.h",
@ -527,8 +529,9 @@ source_set("libdawn_native_sources") {
if (dawn_enable_null) { if (dawn_enable_null) {
sources += [ sources += [
"src/dawn_native/null/DeviceNull.cpp",
"src/dawn_native/null/DeviceNull.h",
"src/dawn_native/null/NullBackend.cpp", "src/dawn_native/null/NullBackend.cpp",
"src/dawn_native/null/NullBackend.h",
] ]
} }
@ -548,6 +551,7 @@ source_set("libdawn_native_sources") {
"src/dawn_native/opengl/Forward.h", "src/dawn_native/opengl/Forward.h",
"src/dawn_native/opengl/InputStateGL.cpp", "src/dawn_native/opengl/InputStateGL.cpp",
"src/dawn_native/opengl/InputStateGL.h", "src/dawn_native/opengl/InputStateGL.h",
"src/dawn_native/opengl/OpenGLBackend.cpp",
"src/dawn_native/opengl/PersistentPipelineStateGL.cpp", "src/dawn_native/opengl/PersistentPipelineStateGL.cpp",
"src/dawn_native/opengl/PersistentPipelineStateGL.h", "src/dawn_native/opengl/PersistentPipelineStateGL.h",
"src/dawn_native/opengl/PipelineGL.cpp", "src/dawn_native/opengl/PipelineGL.cpp",
@ -617,6 +621,7 @@ source_set("libdawn_native_sources") {
"src/dawn_native/vulkan/TextureVk.h", "src/dawn_native/vulkan/TextureVk.h",
"src/dawn_native/vulkan/UtilsVulkan.cpp", "src/dawn_native/vulkan/UtilsVulkan.cpp",
"src/dawn_native/vulkan/UtilsVulkan.h", "src/dawn_native/vulkan/UtilsVulkan.h",
"src/dawn_native/vulkan/VulkanBackend.cpp",
"src/dawn_native/vulkan/VulkanError.cpp", "src/dawn_native/vulkan/VulkanError.cpp",
"src/dawn_native/vulkan/VulkanError.h", "src/dawn_native/vulkan/VulkanError.h",
"src/dawn_native/vulkan/VulkanFunctions.cpp", "src/dawn_native/vulkan/VulkanFunctions.cpp",

View File

@ -0,0 +1,46 @@
// Copyright 2019 The Dawn 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.
// D3D12Backend.cpp: contains the definition of symbols exported by D3D12Backend.h so that they
// can be compiled twice: once export (shared library), once not exported (static library)
#include "dawn_native/D3D12Backend.h"
#include "common/SwapChainUtils.h"
#include "dawn_native/d3d12/DeviceD3D12.h"
#include "dawn_native/d3d12/NativeSwapChainImplD3D12.h"
namespace dawn_native { namespace d3d12 {
dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device());
}
dawnSwapChainImplementation CreateNativeSwapChainImpl(dawnDevice device, HWND window) {
Device* backendDevice = reinterpret_cast<Device*>(device);
dawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl(backendDevice, window));
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;
return impl;
}
dawnTextureFormat GetNativeSwapChainPreferredFormat(
const dawnSwapChainImplementation* swapChain) {
NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
return static_cast<dawnTextureFormat>(impl->GetPreferredFormat());
}
}} // namespace dawn_native::d3d12

View File

@ -15,9 +15,7 @@
#include "dawn_native/d3d12/DeviceD3D12.h" #include "dawn_native/d3d12/DeviceD3D12.h"
#include "common/Assert.h" #include "common/Assert.h"
#include "common/SwapChainUtils.h"
#include "dawn_native/BackendConnection.h" #include "dawn_native/BackendConnection.h"
#include "dawn_native/D3D12Backend.h"
#include "dawn_native/d3d12/BindGroupD3D12.h" #include "dawn_native/d3d12/BindGroupD3D12.h"
#include "dawn_native/d3d12/BindGroupLayoutD3D12.h" #include "dawn_native/d3d12/BindGroupLayoutD3D12.h"
#include "dawn_native/d3d12/BufferD3D12.h" #include "dawn_native/d3d12/BufferD3D12.h"
@ -26,7 +24,6 @@
#include "dawn_native/d3d12/ComputePipelineD3D12.h" #include "dawn_native/d3d12/ComputePipelineD3D12.h"
#include "dawn_native/d3d12/DescriptorHeapAllocator.h" #include "dawn_native/d3d12/DescriptorHeapAllocator.h"
#include "dawn_native/d3d12/InputStateD3D12.h" #include "dawn_native/d3d12/InputStateD3D12.h"
#include "dawn_native/d3d12/NativeSwapChainImplD3D12.h"
#include "dawn_native/d3d12/PipelineLayoutD3D12.h" #include "dawn_native/d3d12/PipelineLayoutD3D12.h"
#include "dawn_native/d3d12/PlatformFunctions.h" #include "dawn_native/d3d12/PlatformFunctions.h"
#include "dawn_native/d3d12/QueueD3D12.h" #include "dawn_native/d3d12/QueueD3D12.h"
@ -43,26 +40,6 @@
namespace dawn_native { namespace d3d12 { namespace dawn_native { namespace d3d12 {
dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device());
}
dawnSwapChainImplementation CreateNativeSwapChainImpl(dawnDevice device, HWND window) {
Device* backendDevice = reinterpret_cast<Device*>(device);
dawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl(backendDevice, window));
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;
return impl;
}
dawnTextureFormat GetNativeSwapChainPreferredFormat(
const dawnSwapChainImplementation* swapChain) {
NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
return static_cast<dawnTextureFormat>(impl->GetPreferredFormat());
}
void ASSERT_SUCCESS(HRESULT hr) { void ASSERT_SUCCESS(HRESULT hr) {
ASSERT(SUCCEEDED(hr)); ASSERT(SUCCEEDED(hr));
} }

View File

@ -17,7 +17,6 @@
#include "dawn_native/BackendConnection.h" #include "dawn_native/BackendConnection.h"
#include "dawn_native/BindGroup.h" #include "dawn_native/BindGroup.h"
#include "dawn_native/BindGroupLayout.h" #include "dawn_native/BindGroupLayout.h"
#include "dawn_native/MetalBackend.h"
#include "dawn_native/RenderPassDescriptor.h" #include "dawn_native/RenderPassDescriptor.h"
#include "dawn_native/metal/BufferMTL.h" #include "dawn_native/metal/BufferMTL.h"
#include "dawn_native/metal/CommandBufferMTL.h" #include "dawn_native/metal/CommandBufferMTL.h"
@ -122,15 +121,6 @@ namespace dawn_native { namespace metal {
} }
} // anonymous namespace } // anonymous namespace
dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device());
}
id<MTLDevice> GetMetalDevice(dawnDevice cDevice) {
Device* device = reinterpret_cast<Device*>(cDevice);
return device->GetMTLDevice();
}
BackendConnection* Connect(InstanceBase* instance) { BackendConnection* Connect(InstanceBase* instance) {
return nullptr; return nullptr;
} }

View File

@ -0,0 +1,33 @@
// Copyright 2019 The Dawn 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.
// MetalBackend.cpp: contains the definition of symbols exported by MetalBackend.h so that they
// can be compiled twice: once export (shared library), once not exported (static library)
#include "dawn_native/MetalBackend.h"
#include "dawn_native/metal/DeviceMTL.h"
namespace dawn_native { namespace metal {
dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device());
}
id<MTLDevice> GetMetalDevice(dawnDevice cDevice) {
Device* device = reinterpret_cast<Device*>(cDevice);
return device->GetMTLDevice();
}
}} // namespace dawn_native::metal

View File

@ -0,0 +1,283 @@
// Copyright 2017 The Dawn 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 "dawn_native/null/DeviceNull.h"
#include "dawn_native/BackendConnection.h"
#include "dawn_native/Commands.h"
#include <spirv-cross/spirv_cross.hpp>
namespace dawn_native { namespace null {
// Implementation of pre-Device objects: the null adapter, null backend connection and Connect()
class Adapter : public AdapterBase {
public:
Adapter(InstanceBase* instance) : AdapterBase(instance, BackendType::Null) {
}
virtual ~Adapter() = default;
private:
ResultOrError<DeviceBase*> CreateDeviceImpl() override {
return {new Device};
}
};
class Backend : public BackendConnection {
public:
Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::Null) {
}
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override {
// There is always a single Null adapter because it is purely CPU based and doesn't
// depend on the system.
std::vector<std::unique_ptr<AdapterBase>> adapters;
adapters.push_back(std::make_unique<Adapter>(GetInstance()));
return adapters;
}
};
BackendConnection* Connect(InstanceBase* instance) {
return new Backend(instance);
}
// Device
Device::Device() {
InitFakePCIInfo();
}
Device::~Device() {
}
ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) {
return new BindGroup(this, descriptor);
}
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor);
}
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
return new Buffer(this, descriptor);
}
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
return new CommandBuffer(builder);
}
ResultOrError<ComputePipelineBase*> Device::CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return new ComputePipeline(this, descriptor);
}
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
return new InputState(builder);
}
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor);
}
ResultOrError<QueueBase*> Device::CreateQueueImpl() {
return new Queue(this);
}
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) {
return new RenderPassDescriptor(builder);
}
ResultOrError<RenderPipelineBase*> Device::CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) {
return new RenderPipeline(this, descriptor);
}
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor) {
auto module = new ShaderModule(this, descriptor);
spirv_cross::Compiler compiler(descriptor->code, descriptor->codeSize);
module->ExtractSpirvInfo(compiler);
return module;
}
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
return new SwapChain(builder);
}
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return new Texture(this, descriptor);
}
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return new TextureView(texture, descriptor);
}
void Device::InitFakePCIInfo() {
mPCIInfo.name = "Null backend";
}
const dawn_native::PCIInfo& Device::GetPCIInfo() const {
return mPCIInfo;
}
Serial Device::GetCompletedCommandSerial() const {
return mCompletedSerial;
}
Serial Device::GetLastSubmittedCommandSerial() const {
return mLastSubmittedSerial;
}
void Device::TickImpl() {
SubmitPendingOperations();
}
void Device::AddPendingOperation(std::unique_ptr<PendingOperation> operation) {
mPendingOperations.emplace_back(std::move(operation));
}
void Device::SubmitPendingOperations() {
for (auto& operation : mPendingOperations) {
operation->Execute();
}
mPendingOperations.clear();
mCompletedSerial = mLastSubmittedSerial;
mLastSubmittedSerial++;
}
// Buffer
struct BufferMapReadOperation : PendingOperation {
virtual void Execute() {
buffer->MapReadOperationCompleted(serial, ptr, isWrite);
}
Ref<Buffer> buffer;
void* ptr;
uint32_t serial;
bool isWrite;
};
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
: BufferBase(device, descriptor) {
if (GetUsage() & (dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::MapRead |
dawn::BufferUsageBit::MapWrite)) {
mBackingData = std::unique_ptr<char[]>(new char[GetSize()]);
}
}
Buffer::~Buffer() {
}
void Buffer::MapReadOperationCompleted(uint32_t serial, void* ptr, bool isWrite) {
if (isWrite) {
CallMapWriteCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr);
} else {
CallMapReadCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr);
}
}
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) {
ASSERT(start + count <= GetSize());
ASSERT(mBackingData);
memcpy(mBackingData.get() + start, data, count);
}
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
MapAsyncImplCommon(serial, start, count, false);
}
void Buffer::MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
MapAsyncImplCommon(serial, start, count, true);
}
void Buffer::MapAsyncImplCommon(uint32_t serial, uint32_t start, uint32_t count, bool isWrite) {
ASSERT(start + count <= GetSize());
ASSERT(mBackingData);
auto operation = new BufferMapReadOperation;
operation->buffer = this;
operation->ptr = mBackingData.get() + start;
operation->serial = serial;
operation->isWrite = isWrite;
ToBackend(GetDevice())->AddPendingOperation(std::unique_ptr<PendingOperation>(operation));
}
void Buffer::UnmapImpl() {
}
// CommandBuffer
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
: CommandBufferBase(builder), mCommands(builder->AcquireCommands()) {
}
CommandBuffer::~CommandBuffer() {
FreeCommands(&mCommands);
}
// Queue
Queue::Queue(Device* device) : QueueBase(device) {
}
Queue::~Queue() {
}
void Queue::SubmitImpl(uint32_t, CommandBufferBase* const*) {
ToBackend(GetDevice())->SubmitPendingOperations();
}
// SwapChain
SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) {
const auto& im = GetImplementation();
im.Init(im.userData, nullptr);
}
SwapChain::~SwapChain() {
}
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
return GetDevice()->CreateTexture(descriptor);
}
void SwapChain::OnBeforePresent(TextureBase*) {
}
// NativeSwapChainImpl
void NativeSwapChainImpl::Init(WSIContext* context) {
}
dawnSwapChainError NativeSwapChainImpl::Configure(dawnTextureFormat format,
dawnTextureUsageBit,
uint32_t width,
uint32_t height) {
return DAWN_SWAP_CHAIN_NO_ERROR;
}
dawnSwapChainError NativeSwapChainImpl::GetNextTexture(dawnSwapChainNextTexture* nextTexture) {
return DAWN_SWAP_CHAIN_NO_ERROR;
}
dawnSwapChainError NativeSwapChainImpl::Present() {
return DAWN_SWAP_CHAIN_NO_ERROR;
}
dawn::TextureFormat NativeSwapChainImpl::GetPreferredFormat() const {
return dawn::TextureFormat::R8G8B8A8Unorm;
}
}} // namespace dawn_native::null

View File

@ -12,10 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef DAWNNATIVE_NULL_NULLBACKEND_H_ #ifndef DAWNNATIVE_NULL_DEVICENULL_H_
#define DAWNNATIVE_NULL_NULLBACKEND_H_ #define DAWNNATIVE_NULL_DEVICENULL_H_
#include "dawn_native/dawn_platform.h"
#include "dawn_native/BindGroup.h" #include "dawn_native/BindGroup.h"
#include "dawn_native/BindGroupLayout.h" #include "dawn_native/BindGroupLayout.h"
@ -33,6 +31,7 @@
#include "dawn_native/SwapChain.h" #include "dawn_native/SwapChain.h"
#include "dawn_native/Texture.h" #include "dawn_native/Texture.h"
#include "dawn_native/ToBackend.h" #include "dawn_native/ToBackend.h"
#include "dawn_native/dawn_platform.h"
namespace dawn_native { namespace null { namespace dawn_native { namespace null {
@ -176,6 +175,19 @@ namespace dawn_native { namespace null {
void OnBeforePresent(TextureBase*) override; void OnBeforePresent(TextureBase*) override;
}; };
class NativeSwapChainImpl {
public:
using WSIContext = struct {};
void Init(WSIContext* context);
dawnSwapChainError Configure(dawnTextureFormat format,
dawnTextureUsageBit,
uint32_t width,
uint32_t height);
dawnSwapChainError GetNextTexture(dawnSwapChainNextTexture* nextTexture);
dawnSwapChainError Present();
dawn::TextureFormat GetPreferredFormat() const;
};
}} // namespace dawn_native::null }} // namespace dawn_native::null
#endif // DAWNNATIVE_NULL_NULLBACKEND_H_ #endif // DAWNNATIVE_NULL_DEVICENULL_H_

View File

@ -1,4 +1,4 @@
// Copyright 2017 The Dawn Authors // Copyright 2019 The Dawn Authors
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -12,281 +12,21 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "dawn_native/null/NullBackend.h" // NullBackend.cpp: contains the definition of symbols exported by NullBackend.h so that they
// can be compiled twice: once export (shared library), once not exported (static library)
#include "common/SwapChainUtils.h"
#include "dawn_native/BackendConnection.h"
#include "dawn_native/Commands.h"
#include "dawn_native/NullBackend.h" #include "dawn_native/NullBackend.h"
#include <spirv-cross/spirv_cross.hpp> #include "common/SwapChainUtils.h"
#include "dawn_native/null/DeviceNull.h"
namespace dawn_native { namespace null { namespace dawn_native { namespace null {
// Implementation of pre-Device objects: the null adapter, null backend connection and Connect()
class Adapter : public AdapterBase {
public:
Adapter(InstanceBase* instance) : AdapterBase(instance, BackendType::Null) {
}
virtual ~Adapter() = default;
private:
ResultOrError<DeviceBase*> CreateDeviceImpl() override {
return {new Device};
}
};
class Backend : public BackendConnection {
public:
Backend(InstanceBase* instance) : BackendConnection(instance, BackendType::Null) {
}
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override {
// There is always a single Null adapter because it is purely CPU based and doesn't
// depend on the system.
std::vector<std::unique_ptr<AdapterBase>> adapters;
adapters.push_back(std::make_unique<Adapter>(GetInstance()));
return adapters;
}
};
dawnDevice CreateDevice() { dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device); return reinterpret_cast<dawnDevice>(new Device);
} }
BackendConnection* Connect(InstanceBase* instance) { dawnSwapChainImplementation CreateNativeSwapChainImpl() {
return new Backend(instance);
}
// Device
Device::Device() {
InitFakePCIInfo();
}
Device::~Device() {
}
ResultOrError<BindGroupBase*> Device::CreateBindGroupImpl(
const BindGroupDescriptor* descriptor) {
return new BindGroup(this, descriptor);
}
ResultOrError<BindGroupLayoutBase*> Device::CreateBindGroupLayoutImpl(
const BindGroupLayoutDescriptor* descriptor) {
return new BindGroupLayout(this, descriptor);
}
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
return new Buffer(this, descriptor);
}
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
return new CommandBuffer(builder);
}
ResultOrError<ComputePipelineBase*> Device::CreateComputePipelineImpl(
const ComputePipelineDescriptor* descriptor) {
return new ComputePipeline(this, descriptor);
}
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
return new InputState(builder);
}
ResultOrError<PipelineLayoutBase*> Device::CreatePipelineLayoutImpl(
const PipelineLayoutDescriptor* descriptor) {
return new PipelineLayout(this, descriptor);
}
ResultOrError<QueueBase*> Device::CreateQueueImpl() {
return new Queue(this);
}
RenderPassDescriptorBase* Device::CreateRenderPassDescriptor(
RenderPassDescriptorBuilder* builder) {
return new RenderPassDescriptor(builder);
}
ResultOrError<RenderPipelineBase*> Device::CreateRenderPipelineImpl(
const RenderPipelineDescriptor* descriptor) {
return new RenderPipeline(this, descriptor);
}
ResultOrError<SamplerBase*> Device::CreateSamplerImpl(const SamplerDescriptor* descriptor) {
return new Sampler(this, descriptor);
}
ResultOrError<ShaderModuleBase*> Device::CreateShaderModuleImpl(
const ShaderModuleDescriptor* descriptor) {
auto module = new ShaderModule(this, descriptor);
spirv_cross::Compiler compiler(descriptor->code, descriptor->codeSize);
module->ExtractSpirvInfo(compiler);
return module;
}
SwapChainBase* Device::CreateSwapChain(SwapChainBuilder* builder) {
return new SwapChain(builder);
}
ResultOrError<TextureBase*> Device::CreateTextureImpl(const TextureDescriptor* descriptor) {
return new Texture(this, descriptor);
}
ResultOrError<TextureViewBase*> Device::CreateTextureViewImpl(
TextureBase* texture,
const TextureViewDescriptor* descriptor) {
return new TextureView(texture, descriptor);
}
void Device::InitFakePCIInfo() {
mPCIInfo.name = "Null backend";
}
const dawn_native::PCIInfo& Device::GetPCIInfo() const {
return mPCIInfo;
}
Serial Device::GetCompletedCommandSerial() const {
return mCompletedSerial;
}
Serial Device::GetLastSubmittedCommandSerial() const {
return mLastSubmittedSerial;
}
void Device::TickImpl() {
SubmitPendingOperations();
}
void Device::AddPendingOperation(std::unique_ptr<PendingOperation> operation) {
mPendingOperations.emplace_back(std::move(operation));
}
void Device::SubmitPendingOperations() {
for (auto& operation : mPendingOperations) {
operation->Execute();
}
mPendingOperations.clear();
mCompletedSerial = mLastSubmittedSerial;
mLastSubmittedSerial++;
}
// Buffer
struct BufferMapReadOperation : PendingOperation {
virtual void Execute() {
buffer->MapReadOperationCompleted(serial, ptr, isWrite);
}
Ref<Buffer> buffer;
void* ptr;
uint32_t serial;
bool isWrite;
};
Buffer::Buffer(Device* device, const BufferDescriptor* descriptor)
: BufferBase(device, descriptor) {
if (GetUsage() & (dawn::BufferUsageBit::TransferDst | dawn::BufferUsageBit::MapRead |
dawn::BufferUsageBit::MapWrite)) {
mBackingData = std::unique_ptr<char[]>(new char[GetSize()]);
}
}
Buffer::~Buffer() {
}
void Buffer::MapReadOperationCompleted(uint32_t serial, void* ptr, bool isWrite) {
if (isWrite) {
CallMapWriteCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr);
} else {
CallMapReadCallback(serial, DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS, ptr);
}
}
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint8_t* data) {
ASSERT(start + count <= GetSize());
ASSERT(mBackingData);
memcpy(mBackingData.get() + start, data, count);
}
void Buffer::MapReadAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
MapAsyncImplCommon(serial, start, count, false);
}
void Buffer::MapWriteAsyncImpl(uint32_t serial, uint32_t start, uint32_t count) {
MapAsyncImplCommon(serial, start, count, true);
}
void Buffer::MapAsyncImplCommon(uint32_t serial, uint32_t start, uint32_t count, bool isWrite) {
ASSERT(start + count <= GetSize());
ASSERT(mBackingData);
auto operation = new BufferMapReadOperation;
operation->buffer = this;
operation->ptr = mBackingData.get() + start;
operation->serial = serial;
operation->isWrite = isWrite;
ToBackend(GetDevice())->AddPendingOperation(std::unique_ptr<PendingOperation>(operation));
}
void Buffer::UnmapImpl() {
}
// CommandBuffer
CommandBuffer::CommandBuffer(CommandBufferBuilder* builder)
: CommandBufferBase(builder), mCommands(builder->AcquireCommands()) {
}
CommandBuffer::~CommandBuffer() {
FreeCommands(&mCommands);
}
// Queue
Queue::Queue(Device* device) : QueueBase(device) {
}
Queue::~Queue() {
}
void Queue::SubmitImpl(uint32_t, CommandBufferBase* const*) {
ToBackend(GetDevice())->SubmitPendingOperations();
}
// SwapChain
SwapChain::SwapChain(SwapChainBuilder* builder) : SwapChainBase(builder) {
const auto& im = GetImplementation();
im.Init(im.userData, nullptr);
}
SwapChain::~SwapChain() {
}
TextureBase* SwapChain::GetNextTextureImpl(const TextureDescriptor* descriptor) {
return GetDevice()->CreateTexture(descriptor);
}
void SwapChain::OnBeforePresent(TextureBase*) {
}
// CreateNativeSwapChainImpl
class NativeSwapChainImpl {
public:
using WSIContext = struct {};
void Init(WSIContext* context) {
}
dawnSwapChainError Configure(dawnTextureFormat format,
dawnTextureUsageBit,
uint32_t width,
uint32_t height) {
return DAWN_SWAP_CHAIN_NO_ERROR;
}
dawnSwapChainError GetNextTexture(dawnSwapChainNextTexture* nextTexture) {
return DAWN_SWAP_CHAIN_NO_ERROR;
}
dawnSwapChainError Present() {
return DAWN_SWAP_CHAIN_NO_ERROR;
}
dawn::TextureFormat GetPreferredFormat() const {
return dawn::TextureFormat::R8G8B8A8Unorm;
}
};
DAWN_NATIVE_EXPORT dawnSwapChainImplementation CreateNativeSwapChainImpl() {
dawnSwapChainImplementation impl; dawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl()); impl = CreateSwapChainImplementation(new NativeSwapChainImpl());
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT; impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;

View File

@ -19,12 +19,6 @@
namespace dawn_native { namespace opengl { namespace dawn_native { namespace opengl {
// Implementation of OpenGLBackend.h
AdapterDiscoveryOptions::AdapterDiscoveryOptions()
: AdapterDiscoveryOptionsBase(BackendType::OpenGL) {
}
// The OpenGL backend's Adapter. // The OpenGL backend's Adapter.
class Adapter : public AdapterBase { class Adapter : public AdapterBase {

View File

@ -17,7 +17,6 @@
#include "dawn_native/BackendConnection.h" #include "dawn_native/BackendConnection.h"
#include "dawn_native/BindGroup.h" #include "dawn_native/BindGroup.h"
#include "dawn_native/BindGroupLayout.h" #include "dawn_native/BindGroupLayout.h"
#include "dawn_native/OpenGLBackend.h"
#include "dawn_native/RenderPassDescriptor.h" #include "dawn_native/RenderPassDescriptor.h"
#include "dawn_native/opengl/BufferGL.h" #include "dawn_native/opengl/BufferGL.h"
#include "dawn_native/opengl/CommandBufferGL.h" #include "dawn_native/opengl/CommandBufferGL.h"

View File

@ -0,0 +1,28 @@
// Copyright 2019 The Dawn 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.
// OpenGLBackend.cpp: contains the definition of symbols exported by OpenGLBackend.h so that they
// can be compiled twice: once export (shared library), once not exported (static library)
#include "dawn_native/OpenGLBackend.h"
#include "dawn_native/opengl/DeviceGL.h"
namespace dawn_native { namespace opengl {
AdapterDiscoveryOptions::AdapterDiscoveryOptions()
: AdapterDiscoveryOptionsBase(BackendType::OpenGL) {
}
}} // namespace dawn_native::opengl

View File

@ -15,11 +15,9 @@
#include "dawn_native/vulkan/DeviceVk.h" #include "dawn_native/vulkan/DeviceVk.h"
#include "common/Platform.h" #include "common/Platform.h"
#include "common/SwapChainUtils.h"
#include "dawn_native/BackendConnection.h" #include "dawn_native/BackendConnection.h"
#include "dawn_native/Commands.h" #include "dawn_native/Commands.h"
#include "dawn_native/ErrorData.h" #include "dawn_native/ErrorData.h"
#include "dawn_native/VulkanBackend.h"
#include "dawn_native/vulkan/BindGroupLayoutVk.h" #include "dawn_native/vulkan/BindGroupLayoutVk.h"
#include "dawn_native/vulkan/BindGroupVk.h" #include "dawn_native/vulkan/BindGroupVk.h"
#include "dawn_native/vulkan/BufferUploader.h" #include "dawn_native/vulkan/BufferUploader.h"
@ -28,7 +26,6 @@
#include "dawn_native/vulkan/ComputePipelineVk.h" #include "dawn_native/vulkan/ComputePipelineVk.h"
#include "dawn_native/vulkan/FencedDeleter.h" #include "dawn_native/vulkan/FencedDeleter.h"
#include "dawn_native/vulkan/InputStateVk.h" #include "dawn_native/vulkan/InputStateVk.h"
#include "dawn_native/vulkan/NativeSwapChainImplVk.h"
#include "dawn_native/vulkan/PipelineLayoutVk.h" #include "dawn_native/vulkan/PipelineLayoutVk.h"
#include "dawn_native/vulkan/QueueVk.h" #include "dawn_native/vulkan/QueueVk.h"
#include "dawn_native/vulkan/RenderPassCache.h" #include "dawn_native/vulkan/RenderPassCache.h"
@ -54,33 +51,6 @@ const char kVulkanLibName[] = "vulkan-1.dll";
namespace dawn_native { namespace vulkan { namespace dawn_native { namespace vulkan {
dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device());
}
VkInstance GetInstance(dawnDevice device) {
Device* backendDevice = reinterpret_cast<Device*>(device);
return backendDevice->GetInstance();
}
DAWN_NATIVE_EXPORT dawnSwapChainImplementation
CreateNativeSwapChainImpl(dawnDevice device, VkSurfaceKHRNative surfaceNative) {
Device* backendDevice = reinterpret_cast<Device*>(device);
VkSurfaceKHR surface = VkSurfaceKHR::CreateFromHandle(surfaceNative);
dawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl(backendDevice, surface));
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;
return impl;
}
dawnTextureFormat GetNativeSwapChainPreferredFormat(
const dawnSwapChainImplementation* swapChain) {
NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
return static_cast<dawnTextureFormat>(impl->GetPreferredFormat());
}
BackendConnection* Connect(InstanceBase* instance) { BackendConnection* Connect(InstanceBase* instance) {
return nullptr; return nullptr;
} }

View File

@ -0,0 +1,57 @@
// Copyright 2019 The Dawn 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.
// VulkanBackend.cpp: contains the definition of symbols exported by VulkanBackend.h so that they
// can be compiled twice: once export (shared library), once not exported (static library)
// Include vulkan_platform.h before VulkanBackend.h includes vulkan.h so that we use our version
// of the non-dispatchable handles.
#include "common/vulkan_platform.h"
#include "dawn_native/VulkanBackend.h"
#include "common/SwapChainUtils.h"
#include "dawn_native/vulkan/DeviceVk.h"
#include "dawn_native/vulkan/NativeSwapChainImplVk.h"
namespace dawn_native { namespace vulkan {
dawnDevice CreateDevice() {
return reinterpret_cast<dawnDevice>(new Device());
}
VkInstance GetInstance(dawnDevice device) {
Device* backendDevice = reinterpret_cast<Device*>(device);
return backendDevice->GetInstance();
}
DAWN_NATIVE_EXPORT dawnSwapChainImplementation
CreateNativeSwapChainImpl(dawnDevice device, VkSurfaceKHRNative surfaceNative) {
Device* backendDevice = reinterpret_cast<Device*>(device);
VkSurfaceKHR surface = VkSurfaceKHR::CreateFromHandle(surfaceNative);
dawnSwapChainImplementation impl;
impl = CreateSwapChainImplementation(new NativeSwapChainImpl(backendDevice, surface));
impl.textureUsage = DAWN_TEXTURE_USAGE_BIT_PRESENT;
return impl;
}
dawnTextureFormat GetNativeSwapChainPreferredFormat(
const dawnSwapChainImplementation* swapChain) {
NativeSwapChainImpl* impl = reinterpret_cast<NativeSwapChainImpl*>(swapChain->userData);
return static_cast<dawnTextureFormat>(impl->GetPreferredFormat());
}
}} // namespace dawn_native::vulkan