Generate a single ProcTable instead of one per backend.

This required putting Queue::Submit on QueueBase which is something we
would want to do anyway, and removes the need for Queue::ValidateSubmit
being called in the ProcTable.

This removes the need for all the "GeneratedCodeIncludes" files and
leads to a bunch of simplifications in BindGroup as well as the
dawn_native CMakeLists.txt.

Finally this was done in order to simplify the writing of BUILD.gn
files.
This commit is contained in:
Corentin Wallez
2018-08-01 15:12:10 +02:00
committed by Corentin Wallez
parent 1ac25e850a
commit fe253f135b
27 changed files with 119 additions and 337 deletions

View File

@@ -25,7 +25,6 @@
#include <array>
#include <bitset>
#include <type_traits>
namespace dawn_native {
@@ -55,25 +54,8 @@ namespace dawn_native {
void SetLayout(BindGroupLayoutBase* layout);
void SetUsage(dawn::BindGroupUsage usage);
template <typename T>
void SetBufferViews(uint32_t start, uint32_t count, T* const* bufferViews) {
static_assert(std::is_base_of<BufferViewBase, T>::value, "");
SetBufferViews(start, count, reinterpret_cast<BufferViewBase* const*>(bufferViews));
}
void SetBufferViews(uint32_t start, uint32_t count, BufferViewBase* const* bufferViews);
template <typename T>
void SetSamplers(uint32_t start, uint32_t count, T* const* samplers) {
static_assert(std::is_base_of<SamplerBase, T>::value, "");
SetSamplers(start, count, reinterpret_cast<SamplerBase* const*>(samplers));
}
void SetSamplers(uint32_t start, uint32_t count, SamplerBase* const* samplers);
template <typename T>
void SetTextureViews(uint32_t start, uint32_t count, T* const* textureViews) {
static_assert(std::is_base_of<TextureViewBase, T>::value, "");
SetTextureViews(start, count, reinterpret_cast<TextureViewBase* const*>(textureViews));
}
void SetTextureViews(uint32_t start, uint32_t count, TextureViewBase* const* textureViews);
private:

View File

@@ -30,21 +30,8 @@ Generate(
-T dawn_native_utils
)
function(GenerateProcTable backend)
Generate(
LIB_NAME ${backend}_autogen
LIB_TYPE STATIC
FOLDER "dawn_native"
PRINT_NAME "${backend} backend autogenerated files"
COMMAND_LINE_ARGS
${GENERATOR_COMMON_ARGS}
-T ${backend}
)
target_link_libraries(${backend}_autogen dawn_native_utils_autogen)
endfunction()
set(DAWN_NATIVE_SOURCES)
set(DAWN_NATIVE_DEPS dawn_common spirv_cross)
set(DAWN_NATIVE_DEPS dawn_common spirv_cross dawn_native_utils_autogen)
set(DAWN_NATIVE_INCLUDE_DIRS ${SPIRV_CROSS_INCLUDE_DIR})
################################################################################
@@ -52,10 +39,7 @@ set(DAWN_NATIVE_INCLUDE_DIRS ${SPIRV_CROSS_INCLUDE_DIR})
################################################################################
if (DAWN_ENABLE_OPENGL)
GenerateProcTable(opengl)
target_link_libraries(opengl_autogen glad)
list(APPEND DAWN_NATIVE_DEPS opengl_autogen glad)
list(APPEND DAWN_NATIVE_DEPS glad)
list(APPEND DAWN_NATIVE_INCLUDE_DIRS ${GLAD_INCLUDE_DIR})
list(APPEND DAWN_NATIVE_SOURCES
${OPENGL_DIR}/BlendStateGL.cpp
@@ -100,9 +84,6 @@ endif()
################################################################################
if (DAWN_ENABLE_NULL)
GenerateProcTable(null)
list(APPEND DAWN_NATIVE_DEPS null_autogen)
list(APPEND DAWN_NATIVE_SOURCES
${NULL_DIR}/NullBackend.cpp
${NULL_DIR}/NullBackend.h
@@ -115,8 +96,7 @@ endif()
################################################################################
if (DAWN_ENABLE_METAL)
GenerateProcTable(metal)
list(APPEND DAWN_NATIVE_DEPS metal_autogen "-framework Metal" "-framework Cocoa")
list(APPEND DAWN_NATIVE_DEPS "-framework Metal" "-framework Cocoa")
list(APPEND DAWN_NATIVE_SOURCES
${METAL_DIR}/BlendStateMTL.mm
@@ -159,8 +139,6 @@ endif()
################################################################################
if (DAWN_ENABLE_D3D12)
GenerateProcTable(d3d12)
# WIN10_SDK_PATH will be something like C:\Program Files (x86)\Windows Kits\10
get_filename_component(WIN10_SDK_PATH "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v10.0;InstallationFolder]" ABSOLUTE CACHE)
@@ -216,9 +194,8 @@ if (DAWN_ENABLE_D3D12)
list(APPEND D3D12_LIBRARIES ${DXGUID_LIBRARY})
endif()
list(APPEND DAWN_NATIVE_DEPS d3d12_autogen ${D3D12_LIBRARIES})
target_include_directories(d3d12_autogen SYSTEM PUBLIC ${D3D12_INCLUDE_DIR} ${DXGI_INCLUDE_DIR})
list(APPEND DAWN_NATIVE_DEPS ${D3D12_LIBRARIES})
list(APPEND DAWN_NATIVE_INCLUDE_DIRS ${D3D12_INCLUDE_DIR} ${DXGI_INCLUDE_DIR})
list(APPEND DAWN_NATIVE_SOURCES
${D3D12_DIR}/d3d12_platform.h
${D3D12_DIR}/BindGroupD3D12.cpp
@@ -277,10 +254,7 @@ endif()
################################################################################
if (DAWN_ENABLE_VULKAN)
GenerateProcTable(vulkan)
list(APPEND DAWN_NATIVE_DEPS vulkan_autogen)
target_include_directories(vulkan_autogen PUBLIC ${VULKAN_HEADERS_INCLUDE_DIR})
list(APPEND DAWN_NATIVE_INCLUDE_DIRS ${VULKAN_HEADERS_INCLUDE_DIR})
list(APPEND DAWN_NATIVE_SOURCES
${VULKAN_DIR}/BindGroupVk.cpp
${VULKAN_DIR}/BindGroupVk.h

View File

@@ -28,8 +28,15 @@ namespace dawn_native {
return mDevice;
}
MaybeError QueueBase::ValidateSubmitCommand(CommandBufferBase*) {
// TODO(cwallez@chromium.org): Validate resources referenced by command buffers can be used
void QueueBase::Submit(uint32_t numCommands, CommandBufferBase* const* commands) {
if (mDevice->ConsumedError(ValidateSubmit(numCommands, commands))) {
return;
}
SubmitImpl(numCommands, commands);
}
MaybeError QueueBase::ValidateSubmit(uint32_t, CommandBufferBase* const*) {
return {};
}

View File

@@ -30,19 +30,13 @@ namespace dawn_native {
DeviceBase* GetDevice();
template <typename T>
MaybeError ValidateSubmit(uint32_t numCommands, T* const* commands) {
static_assert(std::is_base_of<CommandBufferBase, T>::value,
"invalid command buffer type");
for (uint32_t i = 0; i < numCommands; ++i) {
DAWN_TRY(ValidateSubmitCommand(commands[i]));
}
return {};
}
// Dawn API
void Submit(uint32_t numCommands, CommandBufferBase* const* commands);
private:
MaybeError ValidateSubmitCommand(CommandBufferBase* command);
virtual void SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) = 0;
MaybeError ValidateSubmit(uint32_t numCommands, CommandBufferBase* const* commands);
DeviceBase* mDevice;
};

View File

@@ -39,14 +39,15 @@
#include "dawn_native/d3d12/SwapChainD3D12.h"
#include "dawn_native/d3d12/TextureD3D12.h"
namespace dawn_native { namespace d3d12 {
namespace dawn_native {
dawnProcTable GetProcs();
} // namespace dawn_native
dawnProcTable GetNonValidatingProcs();
dawnProcTable GetValidatingProcs();
namespace dawn_native { namespace d3d12 {
void Init(dawnProcTable* procs, dawnDevice* device) {
*device = nullptr;
*procs = GetValidatingProcs();
*procs = GetProcs();
*device = reinterpret_cast<dawnDevice>(new Device());
}

View File

@@ -1,31 +0,0 @@
// 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/d3d12/BindGroupD3D12.h"
#include "dawn_native/d3d12/BindGroupLayoutD3D12.h"
#include "dawn_native/d3d12/BlendStateD3D12.h"
#include "dawn_native/d3d12/BufferD3D12.h"
#include "dawn_native/d3d12/CommandBufferD3D12.h"
#include "dawn_native/d3d12/ComputePipelineD3D12.h"
#include "dawn_native/d3d12/DepthStencilStateD3D12.h"
#include "dawn_native/d3d12/DeviceD3D12.h"
#include "dawn_native/d3d12/InputStateD3D12.h"
#include "dawn_native/d3d12/PipelineLayoutD3D12.h"
#include "dawn_native/d3d12/QueueD3D12.h"
#include "dawn_native/d3d12/RenderPassDescriptorD3D12.h"
#include "dawn_native/d3d12/RenderPipelineD3D12.h"
#include "dawn_native/d3d12/SamplerD3D12.h"
#include "dawn_native/d3d12/ShaderModuleD3D12.h"
#include "dawn_native/d3d12/SwapChainD3D12.h"
#include "dawn_native/d3d12/TextureD3D12.h"

View File

@@ -22,14 +22,14 @@ namespace dawn_native { namespace d3d12 {
Queue::Queue(Device* device) : QueueBase(device) {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {
void Queue::SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) {
Device* device = ToBackend(GetDevice());
device->Tick();
device->OpenCommandList(&mCommandList);
for (uint32_t i = 0; i < numCommands; ++i) {
commands[i]->RecordCommands(mCommandList);
ToBackend(commands[i])->RecordCommands(mCommandList);
}
ASSERT_SUCCESS(mCommandList->Close());

View File

@@ -28,10 +28,9 @@ namespace dawn_native { namespace d3d12 {
public:
Queue(Device* device);
// Dawn API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
private:
void SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) override;
ComPtr<ID3D12GraphicsCommandList> mCommandList;
};

View File

@@ -35,14 +35,16 @@
#include <unistd.h>
namespace dawn_native {
dawnProcTable GetProcs();
} // namespace dawn_native
namespace dawn_native { namespace metal {
dawnProcTable GetNonValidatingProcs();
dawnProcTable GetValidatingProcs();
void Init(id<MTLDevice> metalDevice, dawnProcTable* procs, dawnDevice* device) {
*device = nullptr;
*procs = GetValidatingProcs();
*procs = GetProcs();
*device = reinterpret_cast<dawnDevice>(new Device(metalDevice));
}

View File

@@ -1,31 +0,0 @@
// 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/BindGroup.h"
#include "dawn_native/BindGroupLayout.h"
#include "dawn_native/RenderPassDescriptor.h"
#include "dawn_native/metal/BlendStateMTL.h"
#include "dawn_native/metal/BufferMTL.h"
#include "dawn_native/metal/CommandBufferMTL.h"
#include "dawn_native/metal/ComputePipelineMTL.h"
#include "dawn_native/metal/DepthStencilStateMTL.h"
#include "dawn_native/metal/DeviceMTL.h"
#include "dawn_native/metal/InputStateMTL.h"
#include "dawn_native/metal/PipelineLayoutMTL.h"
#include "dawn_native/metal/QueueMTL.h"
#include "dawn_native/metal/RenderPipelineMTL.h"
#include "dawn_native/metal/SamplerMTL.h"
#include "dawn_native/metal/ShaderModuleMTL.h"
#include "dawn_native/metal/SwapChainMTL.h"
#include "dawn_native/metal/TextureMTL.h"

View File

@@ -26,8 +26,8 @@ namespace dawn_native { namespace metal {
public:
Queue(Device* device);
// Dawn API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
private:
void SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) override;
};
}} // namespace dawn_native::metal

View File

@@ -22,13 +22,13 @@ namespace dawn_native { namespace metal {
Queue::Queue(Device* device) : QueueBase(device) {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {
void Queue::SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) {
Device* device = ToBackend(GetDevice());
device->Tick();
id<MTLCommandBuffer> commandBuffer = device->GetPendingCommandBuffer();
for (uint32_t i = 0; i < numCommands; ++i) {
commands[i]->FillCommands(commandBuffer);
ToBackend(commands[i])->FillCommands(commandBuffer);
}
device->SubmitPendingCommandBuffer();

View File

@@ -1,15 +0,0 @@
// 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/NullBackend.h"

View File

@@ -19,13 +19,14 @@
#include <spirv-cross/spirv_cross.hpp>
namespace dawn_native {
dawnProcTable GetProcs();
} // namespace dawn_native
namespace dawn_native { namespace null {
dawnProcTable GetNonValidatingProcs();
dawnProcTable GetValidatingProcs();
void Init(dawnProcTable* procs, dawnDevice* device) {
*procs = GetValidatingProcs();
*procs = GetProcs();
*device = reinterpret_cast<dawnDevice>(new Device);
}
@@ -189,7 +190,7 @@ namespace dawn_native { namespace null {
Queue::~Queue() {
}
void Queue::Submit(uint32_t, CommandBuffer* const*) {
void Queue::SubmitImpl(uint32_t, CommandBufferBase* const*) {
auto operations = ToBackend(GetDevice())->AcquirePendingOperations();
for (auto& operation : operations) {

View File

@@ -159,8 +159,8 @@ namespace dawn_native { namespace null {
Queue(Device* device);
~Queue();
// Dawn API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
private:
void SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) override;
};
class SwapChain : public SwapChainBase {

View File

@@ -32,16 +32,18 @@
#include "dawn_native/opengl/SwapChainGL.h"
#include "dawn_native/opengl/TextureGL.h"
namespace dawn_native {
dawnProcTable GetProcs();
} // namespace dawn_native
namespace dawn_native { namespace opengl {
dawnProcTable GetNonValidatingProcs();
dawnProcTable GetValidatingProcs();
void Init(void* (*getProc)(const char*), dawnProcTable* procs, dawnDevice* device) {
*device = nullptr;
gladLoadGLLoader(reinterpret_cast<GLADloadproc>(getProc));
*procs = GetValidatingProcs();
*procs = GetProcs();
*device = reinterpret_cast<dawnDevice>(new Device);
glEnable(GL_DEPTH_TEST);

View File

@@ -1,32 +0,0 @@
// 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/BindGroup.h"
#include "dawn_native/BindGroupLayout.h"
#include "dawn_native/RenderPassDescriptor.h"
#include "dawn_native/opengl/BlendStateGL.h"
#include "dawn_native/opengl/BufferGL.h"
#include "dawn_native/opengl/CommandBufferGL.h"
#include "dawn_native/opengl/ComputePipelineGL.h"
#include "dawn_native/opengl/DepthStencilStateGL.h"
#include "dawn_native/opengl/DeviceGL.h"
#include "dawn_native/opengl/InputStateGL.h"
#include "dawn_native/opengl/PersistentPipelineStateGL.h"
#include "dawn_native/opengl/PipelineLayoutGL.h"
#include "dawn_native/opengl/QueueGL.h"
#include "dawn_native/opengl/RenderPipelineGL.h"
#include "dawn_native/opengl/SamplerGL.h"
#include "dawn_native/opengl/ShaderModuleGL.h"
#include "dawn_native/opengl/SwapChainGL.h"
#include "dawn_native/opengl/TextureGL.h"

View File

@@ -22,9 +22,9 @@ namespace dawn_native { namespace opengl {
Queue::Queue(Device* device) : QueueBase(device) {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {
void Queue::SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) {
for (uint32_t i = 0; i < numCommands; ++i) {
commands[i]->Execute();
ToBackend(commands[i])->Execute();
}
}

View File

@@ -26,8 +26,8 @@ namespace dawn_native { namespace opengl {
public:
Queue(Device* device);
// Dawn API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
private:
void SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) override;
};
}} // namespace dawn_native::opengl

View File

@@ -51,15 +51,16 @@ const char kVulkanLibName[] = "vulkan-1.dll";
# error "Unimplemented Vulkan backend platform"
#endif
namespace dawn_native { namespace vulkan {
namespace dawn_native {
dawnProcTable GetProcs();
} // namespace dawn_native
dawnProcTable GetNonValidatingProcs();
dawnProcTable GetValidatingProcs();
namespace dawn_native { namespace vulkan {
void Init(dawnProcTable* procs,
dawnDevice* device,
const std::vector<const char*>& requiredInstanceExtensions) {
*procs = GetValidatingProcs();
*procs = GetProcs();
*device = reinterpret_cast<dawnDevice>(new Device(requiredInstanceExtensions));
}

View File

@@ -1,31 +0,0 @@
// 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/vulkan/BindGroupLayoutVk.h"
#include "dawn_native/vulkan/BindGroupVk.h"
#include "dawn_native/vulkan/BlendStateVk.h"
#include "dawn_native/vulkan/BufferVk.h"
#include "dawn_native/vulkan/CommandBufferVk.h"
#include "dawn_native/vulkan/ComputePipelineVk.h"
#include "dawn_native/vulkan/DepthStencilStateVk.h"
#include "dawn_native/vulkan/DeviceVk.h"
#include "dawn_native/vulkan/InputStateVk.h"
#include "dawn_native/vulkan/PipelineLayoutVk.h"
#include "dawn_native/vulkan/QueueVk.h"
#include "dawn_native/vulkan/RenderPassDescriptorVk.h"
#include "dawn_native/vulkan/RenderPipelineVk.h"
#include "dawn_native/vulkan/SamplerVk.h"
#include "dawn_native/vulkan/ShaderModuleVk.h"
#include "dawn_native/vulkan/SwapChainVk.h"
#include "dawn_native/vulkan/TextureVk.h"

View File

@@ -25,12 +25,12 @@ namespace dawn_native { namespace vulkan {
Queue::~Queue() {
}
void Queue::Submit(uint32_t numCommands, CommandBuffer* const* commands) {
void Queue::SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) {
Device* device = ToBackend(GetDevice());
VkCommandBuffer commandBuffer = device->GetPendingCommandBuffer();
for (uint32_t i = 0; i < numCommands; ++i) {
commands[i]->RecordCommands(commandBuffer);
ToBackend(commands[i])->RecordCommands(commandBuffer);
}
device->SubmitPendingCommands();

View File

@@ -27,8 +27,8 @@ namespace dawn_native { namespace vulkan {
Queue(Device* device);
~Queue();
// Dawn API
void Submit(uint32_t numCommands, CommandBuffer* const* commands);
private:
void SubmitImpl(uint32_t numCommands, CommandBufferBase* const* commands) override;
};
}} // namespace dawn_native::vulkan