mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 15:16:16 +00:00
Create a Null backend.
This will be useful to run validation unittests without using the GPU.
This commit is contained in:
committed by
Corentin Wallez
parent
68df8b0a3a
commit
79a62bf6e3
@@ -14,6 +14,7 @@
|
||||
|
||||
set(COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common)
|
||||
set(METAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/metal)
|
||||
set(NULL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/null)
|
||||
set(OPENGL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/opengl)
|
||||
set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
|
||||
@@ -94,6 +95,26 @@ list(APPEND BACKEND_SOURCES
|
||||
${OPENGL_DIR}/TextureGL.h
|
||||
)
|
||||
|
||||
# Null backend
|
||||
Generate(
|
||||
LIB_NAME null_autogen
|
||||
LIB_TYPE STATIC
|
||||
PRINT_NAME "Null backend autogenerated files"
|
||||
COMMAND_LINE_ARGS
|
||||
${GENERATOR_COMMON_ARGS}
|
||||
-T null
|
||||
)
|
||||
target_link_libraries(null_autogen nxtcpp)
|
||||
target_include_directories(null_autogen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(null_autogen PUBLIC ${GENERATED_DIR})
|
||||
SetCXX14(null_autogen)
|
||||
SetPIC(null_autogen)
|
||||
|
||||
list(APPEND BACKEND_SOURCES
|
||||
${NULL_DIR}/NullBackend.cpp
|
||||
${NULL_DIR}/NullBackend.h
|
||||
)
|
||||
|
||||
# Metal Backend
|
||||
|
||||
if (APPLE)
|
||||
@@ -118,7 +139,7 @@ if (APPLE)
|
||||
endif()
|
||||
|
||||
add_library(nxt_backend SHARED ${BACKEND_SOURCES})
|
||||
target_link_libraries(nxt_backend opengl_autogen glfw glad spirv-cross)
|
||||
target_link_libraries(nxt_backend opengl_autogen null_autogen glfw glad spirv-cross)
|
||||
if (APPLE)
|
||||
target_link_libraries(nxt_backend metal_autogen)
|
||||
endif()
|
||||
|
||||
15
src/backend/null/GeneratedCodeIncludes.h
Normal file
15
src/backend/null/GeneratedCodeIncludes.h
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
#include "NullBackend.h"
|
||||
120
src/backend/null/NullBackend.cpp
Normal file
120
src/backend/null/NullBackend.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
// 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.
|
||||
|
||||
#include "NullBackend.h"
|
||||
|
||||
#include <spirv-cross/spirv_cross.hpp>
|
||||
|
||||
namespace backend {
|
||||
namespace null {
|
||||
|
||||
nxtProcTable GetNonValidatingProcs();
|
||||
nxtProcTable GetValidatingProcs();
|
||||
|
||||
void Init(nxtProcTable* procs, nxtDevice* device) {
|
||||
*procs = GetValidatingProcs();
|
||||
*device = reinterpret_cast<nxtDevice>(new Device);
|
||||
}
|
||||
|
||||
// Device
|
||||
|
||||
Device::Device() {
|
||||
}
|
||||
|
||||
Device::~Device() {
|
||||
}
|
||||
|
||||
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
|
||||
return new BindGroupBase(builder);
|
||||
}
|
||||
BindGroupLayoutBase* Device::CreateBindGroupLayout(BindGroupLayoutBuilder* builder) {
|
||||
return new BindGroupLayoutBase(builder);
|
||||
}
|
||||
BufferBase* Device::CreateBuffer(BufferBuilder* builder) {
|
||||
return new Buffer(builder);
|
||||
}
|
||||
BufferViewBase* Device::CreateBufferView(BufferViewBuilder* builder) {
|
||||
return new BufferViewBase(builder);
|
||||
}
|
||||
CommandBufferBase* Device::CreateCommandBuffer(CommandBufferBuilder* builder) {
|
||||
return new CommandBufferBase(builder);
|
||||
}
|
||||
InputStateBase* Device::CreateInputState(InputStateBuilder* builder) {
|
||||
return new InputStateBase(builder);
|
||||
}
|
||||
FramebufferBase* Device::CreateFramebuffer(FramebufferBuilder* builder) {
|
||||
return new FramebufferBase(builder);
|
||||
}
|
||||
PipelineBase* Device::CreatePipeline(PipelineBuilder* builder) {
|
||||
return new PipelineBase(builder);
|
||||
}
|
||||
PipelineLayoutBase* Device::CreatePipelineLayout(PipelineLayoutBuilder* builder) {
|
||||
return new PipelineLayoutBase(builder);
|
||||
}
|
||||
QueueBase* Device::CreateQueue(QueueBuilder* builder) {
|
||||
return new Queue(builder);
|
||||
}
|
||||
RenderPassBase* Device::CreateRenderPass(RenderPassBuilder* builder) {
|
||||
return new RenderPassBase(builder);
|
||||
}
|
||||
SamplerBase* Device::CreateSampler(SamplerBuilder* builder) {
|
||||
return new SamplerBase(builder);
|
||||
}
|
||||
ShaderModuleBase* Device::CreateShaderModule(ShaderModuleBuilder* builder) {
|
||||
auto module = new ShaderModuleBase(builder);
|
||||
|
||||
spirv_cross::Compiler compiler(builder->AcquireSpirv());
|
||||
module->ExtractSpirvInfo(compiler);
|
||||
|
||||
return module;
|
||||
}
|
||||
TextureBase* Device::CreateTexture(TextureBuilder* builder) {
|
||||
return new TextureBase(builder);
|
||||
}
|
||||
TextureViewBase* Device::CreateTextureView(TextureViewBuilder* builder) {
|
||||
return new TextureViewBase(builder);
|
||||
}
|
||||
|
||||
void Device::Reference() {
|
||||
}
|
||||
|
||||
void Device::Release() {
|
||||
}
|
||||
|
||||
// Buffer
|
||||
|
||||
Buffer::Buffer(BufferBuilder* builder)
|
||||
: BufferBase(builder) {
|
||||
}
|
||||
|
||||
Buffer::~Buffer() {
|
||||
}
|
||||
|
||||
void Buffer::SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) {
|
||||
}
|
||||
|
||||
// Queue
|
||||
|
||||
Queue::Queue(QueueBuilder* builder)
|
||||
: QueueBase(builder) {
|
||||
}
|
||||
|
||||
Queue::~Queue() {
|
||||
}
|
||||
|
||||
void Queue::Submit(uint32_t numCommands, CommandBuffer* const * commands) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
125
src/backend/null/NullBackend.h
Normal file
125
src/backend/null/NullBackend.h
Normal file
@@ -0,0 +1,125 @@
|
||||
// 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_NULL_NULLBACKEND_H_
|
||||
#define BACKEND_NULL_NULLBACKEND_H_
|
||||
|
||||
#include "nxt/nxtcpp.h"
|
||||
|
||||
#include "common/Buffer.h"
|
||||
#include "common/BindGroup.h"
|
||||
#include "common/BindGroupLayout.h"
|
||||
#include "common/Device.h"
|
||||
#include "common/CommandBuffer.h"
|
||||
#include "common/InputState.h"
|
||||
#include "common/Framebuffer.h"
|
||||
#include "common/Pipeline.h"
|
||||
#include "common/PipelineLayout.h"
|
||||
#include "common/Queue.h"
|
||||
#include "common/RenderPass.h"
|
||||
#include "common/Sampler.h"
|
||||
#include "common/ShaderModule.h"
|
||||
#include "common/Texture.h"
|
||||
#include "common/ToBackend.h"
|
||||
|
||||
namespace backend {
|
||||
namespace null {
|
||||
|
||||
using BindGroup = BindGroupBase;
|
||||
using BindGroupLayout = BindGroupLayoutBase;
|
||||
class Buffer;
|
||||
using BufferView = BufferViewBase;
|
||||
using CommandBuffer = CommandBufferBase;
|
||||
using InputState = InputStateBase;
|
||||
using Framebuffer = FramebufferBase;
|
||||
using Pipeline = PipelineBase;
|
||||
using PipelineLayout = PipelineLayoutBase;
|
||||
class Queue;
|
||||
using RenderPass = RenderPassBase;
|
||||
using Sampler = SamplerBase;
|
||||
using ShaderModule = ShaderModuleBase;
|
||||
using Texture = TextureBase;
|
||||
using TextureView = TextureViewBase;
|
||||
|
||||
struct NullBackendTraits {
|
||||
using BindGroupType = BindGroup;
|
||||
using BindGroupLayoutType = BindGroupLayout;
|
||||
using BufferType = Buffer;
|
||||
using BufferViewType = BufferView;
|
||||
using CommandBufferType = CommandBuffer;
|
||||
using InputStateType = InputState;
|
||||
using FramebufferType = Framebuffer;
|
||||
using PipelineType = Pipeline;
|
||||
using PipelineLayoutType = PipelineLayout;
|
||||
using QueueType = Queue;
|
||||
using RenderPassType = RenderPass;
|
||||
using SamplerType = Sampler;
|
||||
using ShaderModuleType = ShaderModule;
|
||||
using TextureType = Texture;
|
||||
using TextureViewType = TextureView;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
auto ToBackend(T&& common) -> decltype(ToBackendBase<NullBackendTraits>(common)) {
|
||||
return ToBackendBase<NullBackendTraits>(common);
|
||||
}
|
||||
|
||||
class Device : public DeviceBase {
|
||||
public:
|
||||
Device();
|
||||
~Device();
|
||||
|
||||
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
|
||||
BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* builder) override;
|
||||
BufferBase* CreateBuffer(BufferBuilder* builder) override;
|
||||
BufferViewBase* CreateBufferView(BufferViewBuilder* builder) override;
|
||||
CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override;
|
||||
InputStateBase* CreateInputState(InputStateBuilder* builder) override;
|
||||
FramebufferBase* CreateFramebuffer(FramebufferBuilder* builder) override;
|
||||
PipelineBase* CreatePipeline(PipelineBuilder* builder) override;
|
||||
PipelineLayoutBase* CreatePipelineLayout(PipelineLayoutBuilder* builder) override;
|
||||
QueueBase* CreateQueue(QueueBuilder* builder) override;
|
||||
RenderPassBase* CreateRenderPass(RenderPassBuilder* builder) override;
|
||||
SamplerBase* CreateSampler(SamplerBuilder* builder) override;
|
||||
ShaderModuleBase* CreateShaderModule(ShaderModuleBuilder* builder) override;
|
||||
TextureBase* CreateTexture(TextureBuilder* builder) override;
|
||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||
|
||||
// NXT API
|
||||
void Reference();
|
||||
void Release();
|
||||
};
|
||||
|
||||
class Buffer : public BufferBase {
|
||||
public:
|
||||
Buffer(BufferBuilder* builder);
|
||||
~Buffer();
|
||||
|
||||
private:
|
||||
void SetSubDataImpl(uint32_t start, uint32_t count, const uint32_t* data) override;
|
||||
};
|
||||
|
||||
class Queue : public QueueBase {
|
||||
public:
|
||||
Queue(QueueBuilder* builder);
|
||||
~Queue();
|
||||
|
||||
// NXT API
|
||||
void Submit(uint32_t numCommands, CommandBuffer* const * commands);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // BACKEND_NULL_NULLBACKEND_H_
|
||||
Reference in New Issue
Block a user