mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
add D3D12Binding with swap chain
This commit is contained in:
@@ -156,7 +156,58 @@ if (WIN32)
|
||||
${GENERATOR_COMMON_ARGS}
|
||||
-T 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)
|
||||
|
||||
# TEMP_WIN10_SDK_VERSION will be something like ${CMAKE_CURRENT_SOURCE_DIR}\10.0.14393 or ${CMAKE_CURRENT_SOURCE_DIR}\10.0.14393.0
|
||||
get_filename_component(TEMP_WIN10_SDK_VERSION "[HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\Microsoft SDKs\\Windows\\v10.0;ProductVersion]" ABSOLUTE CACHE)
|
||||
|
||||
# strip off ${CMAKE_CURRENT_SOURCE_DIR} to get just the version number
|
||||
get_filename_component(WIN10_SDK_VERSION ${TEMP_WIN10_SDK_VERSION} NAME)
|
||||
# WIN10_SDK_VERSION will be something like 10.0.14393 or 10.0.14393.0; we need the one that matches the directory name.
|
||||
if (IS_DIRECTORY "${WIN10_SDK_PATH}/Include/${WIN10_SDK_VERSION}.0")
|
||||
set(WIN10_SDK_VERSION "${WIN10_SDK_VERSION}.0")
|
||||
endif()
|
||||
|
||||
# Find the d3d12 and dxgi include path, it will typically look something like this.
|
||||
# C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\um\d3d12.h
|
||||
# C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\shared\dxgi1_4.h
|
||||
find_path(D3D12_INCLUDE_DIR # Set variable D3D12_INCLUDE_DIR
|
||||
d3d12.h # Find a path with d3d12.h
|
||||
HINTS "${WIN10_SDK_PATH}/Include/${WIN10_SDK_VERSION}/um"
|
||||
DOC "path to WIN10 SDK header files"
|
||||
HINTS
|
||||
)
|
||||
|
||||
find_path(DXGI_INCLUDE_DIR # Set variable DXGI_INCLUDE_DIR
|
||||
dxgi1_4.h # Find a path with dxgi1_4.h
|
||||
HINTS "${WIN10_SDK_PATH}/Include/${WIN10_SDK_VERSION}/shared"
|
||||
DOC "path to WIN10 SDK header files"
|
||||
HINTS
|
||||
)
|
||||
|
||||
if (CMAKE_GENERATOR MATCHES "Visual Studio.*ARM" )
|
||||
set(WIN10_SDK_LIB_PATH ${WIN10_SDK_PATH}/Lib/${WIN10_SDK_VERSION}/um/arm)
|
||||
elseif (CMAKE_GENERATOR MATCHES "Visual Studio.*ARM64" )
|
||||
set(WIN10_SDK_LIB_PATH ${WIN10_SDK_PATH}/Lib/${WIN10_SDK_VERSION}/um/arm64)
|
||||
elseif (CMAKE_GENERATOR MATCHES "Visual Studio.*Win64" )
|
||||
set(WIN10_SDK_LIB_PATH ${WIN10_SDK_PATH}/Lib/${WIN10_SDK_VERSION}/um/x64)
|
||||
else()
|
||||
set(WIN10_SDK_LIB_PATH ${WIN10_SDK_PATH}/Lib/${WIN10_SDK_VERSION}/um/x86)
|
||||
endif()
|
||||
|
||||
find_library(D3D12_LIBRARY NAMES d3d12.lib HINTS ${WIN10_SDK_LIB_PATH})
|
||||
find_library(DXGI_LIBRARY NAMES dxgi.lib HINTS ${WIN10_SDK_LIB_PATH})
|
||||
find_library(D3DCOMPILER_LIBRARY NAMES d3dcompiler.lib HINTS ${WIN10_SDK_LIB_PATH})
|
||||
|
||||
set(D3D12_LIBRARIES
|
||||
${D3D12_LIBRARY}
|
||||
${DXGI_LIBRARY}
|
||||
${D3DCOMPILER_LIBRARY}
|
||||
)
|
||||
|
||||
target_link_libraries(d3d12_autogen glfw nxtcpp ${D3D12_LIBRARIES})
|
||||
target_include_directories(d3d12_autogen SYSTEM PRIVATE ${D3D12_INCLUDE_DIR} ${DXGI_INCLUDE_DIR})
|
||||
target_include_directories(d3d12_autogen PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(d3d12_autogen PUBLIC ${GENERATED_DIR})
|
||||
SetCXX14(d3d12_autogen)
|
||||
|
||||
@@ -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