mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
add D3D12Binding with swap chain
This commit is contained in:
@@ -20,17 +20,74 @@ namespace d3d12 {
|
||||
nxtProcTable GetNonValidatingProcs();
|
||||
nxtProcTable GetValidatingProcs();
|
||||
|
||||
void Init(nxtProcTable* procs, nxtDevice* device) {
|
||||
void Init(ComPtr<ID3D12Device> d3d12Device, nxtProcTable* procs, nxtDevice* device) {
|
||||
*device = nullptr;
|
||||
*procs = GetValidatingProcs();
|
||||
*device = reinterpret_cast<nxtDevice>(new Device(d3d12Device));
|
||||
}
|
||||
|
||||
Device::Device() {
|
||||
ComPtr<ID3D12CommandQueue> GetCommandQueue(nxtDevice device) {
|
||||
Device* backendDevice = reinterpret_cast<Device*>(device);
|
||||
return backendDevice->GetCommandQueue();
|
||||
}
|
||||
|
||||
void SetNextRenderTarget(nxtDevice device, ComPtr<ID3D12Resource> renderTargetResource, D3D12_CPU_DESCRIPTOR_HANDLE renderTargetDescriptor) {
|
||||
Device* backendDevice = reinterpret_cast<Device*>(device);
|
||||
backendDevice->SetNextRenderTarget(renderTargetResource, renderTargetDescriptor);
|
||||
}
|
||||
|
||||
void ASSERT_SUCCESS(HRESULT hr) {
|
||||
ASSERT(SUCCEEDED(hr));
|
||||
}
|
||||
|
||||
Device::Device(ComPtr<ID3D12Device> d3d12Device) : d3d12Device(d3d12Device) {
|
||||
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
||||
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
||||
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
||||
ASSERT_SUCCESS(d3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&commandQueue)));
|
||||
|
||||
// Create an empty root signature.
|
||||
D3D12_ROOT_SIGNATURE_DESC rootSignatureDescriptor;
|
||||
rootSignatureDescriptor.NumParameters = 0;
|
||||
rootSignatureDescriptor.pParameters = nullptr;
|
||||
rootSignatureDescriptor.NumStaticSamplers = 0;
|
||||
rootSignatureDescriptor.pStaticSamplers = nullptr;
|
||||
rootSignatureDescriptor.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
|
||||
|
||||
ComPtr<ID3DBlob> signature;
|
||||
ComPtr<ID3DBlob> error;
|
||||
ASSERT_SUCCESS(D3D12SerializeRootSignature(&rootSignatureDescriptor, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
|
||||
ASSERT_SUCCESS(d3d12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature)));
|
||||
}
|
||||
|
||||
Device::~Device() {
|
||||
}
|
||||
|
||||
ComPtr<ID3D12Device> Device::GetD3D12Device() {
|
||||
return d3d12Device;
|
||||
}
|
||||
|
||||
ComPtr<ID3D12RootSignature> Device::GetRootSignature() {
|
||||
return rootSignature;
|
||||
}
|
||||
|
||||
ComPtr<ID3D12CommandQueue> Device::GetCommandQueue() {
|
||||
return commandQueue;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D12Resource> Device::GetNextRenderTarget() {
|
||||
return renderTargetResource;
|
||||
}
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE Device::GetNextRenderTargetDescriptor() {
|
||||
return renderTargetDescriptor;
|
||||
}
|
||||
|
||||
void Device::SetNextRenderTarget(ComPtr<ID3D12Resource> renderTargetResource, D3D12_CPU_DESCRIPTOR_HANDLE renderTargetDescriptor) {
|
||||
this->renderTargetResource = renderTargetResource;
|
||||
this->renderTargetDescriptor = renderTargetDescriptor;
|
||||
}
|
||||
|
||||
BindGroupBase* Device::CreateBindGroup(BindGroupBuilder* builder) {
|
||||
return new BindGroup(this, builder);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#include "common/Texture.h"
|
||||
#include "common/ToBackend.h"
|
||||
|
||||
#include "d3d12_platform.h"
|
||||
|
||||
namespace backend {
|
||||
namespace d3d12 {
|
||||
|
||||
@@ -78,10 +80,12 @@ namespace d3d12 {
|
||||
return ToBackendBase<D3D12BackendTraits>(common);
|
||||
}
|
||||
|
||||
void ASSERT_SUCCESS(HRESULT hr);
|
||||
|
||||
// Definition of backend types
|
||||
class Device : public DeviceBase {
|
||||
public:
|
||||
Device();
|
||||
Device(Microsoft::WRL::ComPtr<ID3D12Device> d3d12Device);
|
||||
~Device();
|
||||
|
||||
BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) override;
|
||||
@@ -101,9 +105,24 @@ namespace d3d12 {
|
||||
TextureBase* CreateTexture(TextureBuilder* builder) override;
|
||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device();
|
||||
Microsoft::WRL::ComPtr<ID3D12RootSignature> GetRootSignature();
|
||||
Microsoft::WRL::ComPtr<ID3D12CommandQueue> GetCommandQueue();
|
||||
Microsoft::WRL::ComPtr<ID3D12Resource> GetNextRenderTarget();
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE GetNextRenderTargetDescriptor();
|
||||
|
||||
void SetNextRenderTarget(Microsoft::WRL::ComPtr<ID3D12Resource> renderTargetResource, D3D12_CPU_DESCRIPTOR_HANDLE renderTargetDescriptor);
|
||||
|
||||
// NXT API
|
||||
void Reference();
|
||||
void Release();
|
||||
|
||||
private:
|
||||
Microsoft::WRL::ComPtr<ID3D12Device> d3d12Device;
|
||||
Microsoft::WRL::ComPtr<ID3D12CommandQueue> commandQueue;
|
||||
Microsoft::WRL::ComPtr<ID3D12RootSignature> rootSignature;
|
||||
Microsoft::WRL::ComPtr<ID3D12Resource> renderTargetResource;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE renderTargetDescriptor;
|
||||
};
|
||||
|
||||
|
||||
|
||||
24
src/backend/d3d12/d3d12_platform.h
Normal file
24
src/backend/d3d12/d3d12_platform.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// 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_D3D12_D3D12_H_
|
||||
#define BACKEND_D3D12_D3D12_H_
|
||||
|
||||
#include <wrl.h>
|
||||
#include <d3d12.h>
|
||||
#include <dxgi1_4.h>
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
#endif // BACKEND_D3D12_D3D12_H_
|
||||
Reference in New Issue
Block a user