-
Notifications
You must be signed in to change notification settings - Fork 131
Add D3D12 GPU backend. #1437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add D3D12 GPU backend. #1437
Changes from all commits
856a955
737f459
94bcae2
b3dc420
07c9456
c6527ae
04953f8
1b4baf0
5b58a9a
705be43
387d36c
3792ca3
cef4184
3fbcdcc
7249946
a4f0a9b
5a92d17
e762ac9
d5a32f7
e86b75b
fef9781
d42a391
2e953bb
1f41413
508bf52
288017c
e1038dc
711ae9b
c4c205c
550a757
8019cf4
0f42381
d9bc637
4196821
6017691
ca8d0b6
2990e3a
d6bba62
f29a771
2c98ae8
811538d
748de81
65a826e
59ff859
5e70c07
15c2f50
1b4abe2
b9a1ba6
b3b30a9
736d205
57f2901
59c1408
db31bb9
2980c4a
e71ba93
8b145e0
7da907c
31c89d0
4b3cc37
748c856
79d5f7a
721b4b6
74ba7d6
def43d2
6d93b44
f3c8e07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // Tencent is pleased to support the open source community by making tgfx available. | ||
| // | ||
| // Copyright (C) 2026 Tencent. All rights reserved. | ||
| // | ||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
| // in compliance with the License. You may obtain a copy of the License at | ||
| // | ||
| // https://opensource.org/licenses/BSD-3-Clause | ||
| // | ||
| // 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. | ||
| // | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "tgfx/gpu/Device.h" | ||
|
|
||
| namespace tgfx { | ||
|
|
||
| /** | ||
| * The D3D12 interface for drawing graphics. | ||
| */ | ||
| class D3D12Device : public Device { | ||
| public: | ||
| /** | ||
| * Creates a new D3D12Device using the default hardware adapter. Returns nullptr if D3D12 is not | ||
| * available. | ||
| */ | ||
| static std::shared_ptr<D3D12Device> Make(); | ||
|
|
||
| /** | ||
| * Creates a new D3D12Device backed by the WARP software rasterizer. WARP is a CPU-based D3D12 | ||
| * implementation that ships with Windows; it is functionally complete (feature level 12_1) but | ||
| * orders of magnitude slower than a real GPU. Intended for headless CI runners and other | ||
| * environments without a usable hardware adapter — do not rely on it for performance work. | ||
| * Returns nullptr if WARP is unavailable on the current system. | ||
| */ | ||
| static std::shared_ptr<D3D12Device> MakeWarp(); | ||
|
|
||
| /** | ||
| * Creates a new D3D12Device from an existing ID3D12Device. The device parameter is a pointer to | ||
| * an ID3D12Device object. Returns nullptr if the device is invalid. | ||
| */ | ||
| static std::shared_ptr<D3D12Device> MakeFrom(void* device); | ||
|
|
||
| ~D3D12Device() override; | ||
|
|
||
| /** | ||
| * Returns the underlying ID3D12Device as a raw pointer. | ||
| */ | ||
| void* d3d12Device() const; | ||
|
|
||
| protected: | ||
| bool onLockContext() override; | ||
| void onUnlockContext() override; | ||
|
|
||
| private: | ||
| explicit D3D12Device(std::unique_ptr<class D3D12GPU> gpu); | ||
| }; | ||
|
|
||
| } // namespace tgfx | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // Tencent is pleased to support the open source community by making tgfx available. | ||
| // | ||
| // Copyright (C) 2026 Tencent. All rights reserved. | ||
| // | ||
| // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
| // in compliance with the License. You may obtain a copy of the License at | ||
| // | ||
| // https://opensource.org/licenses/BSD-3-Clause | ||
| // | ||
| // 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. | ||
| // | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <type_traits> | ||
|
|
||
| namespace tgfx { | ||
| /** | ||
| * Types for interacting with D3D12 textures created externally to TGFX. | ||
| */ | ||
| struct D3D12TextureInfo { | ||
| /** | ||
| * Pointer to an ID3D12Resource object representing a texture. | ||
| */ | ||
| const void* resource = nullptr; | ||
|
|
||
| /** | ||
| * The pixel format of this texture (DXGI_FORMAT value). | ||
| */ | ||
| unsigned format = 0; // DXGI_FORMAT_UNKNOWN | ||
| }; | ||
|
|
||
| /** | ||
| * Types for interacting with D3D12 synchronization objects created externally to TGFX. | ||
| */ | ||
| struct D3D12SyncInfo { | ||
| /** | ||
| * Pointer to an ID3D12Fence object. | ||
| */ | ||
| const void* fence = nullptr; | ||
|
|
||
| /** | ||
| * The signal value for the fence. | ||
| */ | ||
| uint64_t value = 0; | ||
| }; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 【P14 中】缺少与 证据: static_assert(std::is_trivially_copyable_v<VulkanImageInfo>);
static_assert(std::is_trivially_copyable_v<VulkanSyncInfo>);
static_assert(std::is_standard_layout_v<VulkanImageInfo>);
static_assert(std::is_standard_layout_v<VulkanSyncInfo>);本文件没有等价校验。 影响:未来若有人为 建议:在文件结尾加四条: static_assert(std::is_trivially_copyable_v<D3D12TextureInfo>);
static_assert(std::is_trivially_copyable_v<D3D12SyncInfo>);
static_assert(std::is_standard_layout_v<D3D12TextureInfo>);
static_assert(std::is_standard_layout_v<D3D12SyncInfo>);
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
|
||
| static_assert(std::is_trivially_copyable_v<D3D12TextureInfo>); | ||
| static_assert(std::is_trivially_copyable_v<D3D12SyncInfo>); | ||
| static_assert(std::is_standard_layout_v<D3D12TextureInfo>); | ||
| static_assert(std::is_standard_layout_v<D3D12SyncInfo>); | ||
|
|
||
| } // namespace tgfx | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释未说明
device参数的具体类型(ID3D12Device*)和所有权语义。调用者不清楚:1)void*实际指向何种类型;2)tgfx 是否对该对象调用 AddRef,以及何时/是否调用 Release。建议补全,例如:@param device A pointer to an existing ID3D12Device. The caller retains ownership; tgfx internally calls QueryInterface (AddRef) and releases its own reference when the D3D12Device is destroyed.