Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/util/d3d12_pipeline.h
4222 views
1
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#include "gpu_device.h"
5
6
#include "common/windows_headers.h"
7
8
#include <d3d12.h>
9
#include <vector>
10
#include <wrl/client.h>
11
12
class D3D12Device;
13
14
class D3D12Shader final : public GPUShader
15
{
16
friend D3D12Device;
17
18
public:
19
using Bytecode = std::vector<u8>;
20
21
~D3D12Shader() override;
22
23
ALWAYS_INLINE const Bytecode& GetBytecode() const { return m_bytecode; }
24
ALWAYS_INLINE D3D12_SHADER_BYTECODE GetD3DBytecode() const { return {m_bytecode.data(), m_bytecode.size()}; }
25
ALWAYS_INLINE const u8* GetBytecodeData() const { return m_bytecode.data(); }
26
ALWAYS_INLINE u32 GetBytecodeSize() const { return static_cast<u32>(m_bytecode.size()); }
27
28
#ifdef ENABLE_GPU_OBJECT_NAMES
29
void SetDebugName(std::string_view name) override;
30
#endif
31
32
private:
33
D3D12Shader(GPUShaderStage stage, Bytecode bytecode);
34
35
Bytecode m_bytecode;
36
};
37
38
class D3D12Pipeline final : public GPUPipeline
39
{
40
friend D3D12Device;
41
42
public:
43
~D3D12Pipeline() override;
44
45
ALWAYS_INLINE ID3D12PipelineState* GetPipeline() const { return m_pipeline.Get(); }
46
ALWAYS_INLINE Layout GetLayout() const { return m_layout; }
47
ALWAYS_INLINE D3D12_PRIMITIVE_TOPOLOGY GetTopology() const { return m_topology; }
48
ALWAYS_INLINE u32 GetVertexStride() const { return m_vertex_stride; }
49
ALWAYS_INLINE u32 GetBlendConstants() const { return m_blend_constants; }
50
ALWAYS_INLINE const std::array<float, 4>& GetBlendConstantsF() const { return m_blend_constants_f; }
51
ALWAYS_INLINE bool HasVertexStride() const { return (m_vertex_stride > 0); }
52
53
#ifdef ENABLE_GPU_OBJECT_NAMES
54
void SetDebugName(std::string_view name) override;
55
#endif
56
57
static std::string GetPipelineName(const GraphicsConfig& config);
58
static std::string GetPipelineName(const ComputeConfig& config);
59
60
private:
61
D3D12Pipeline(Microsoft::WRL::ComPtr<ID3D12PipelineState> pipeline, Layout layout, D3D12_PRIMITIVE_TOPOLOGY topology,
62
u32 vertex_stride, u32 blend_constants);
63
64
Microsoft::WRL::ComPtr<ID3D12PipelineState> m_pipeline;
65
Layout m_layout;
66
D3D12_PRIMITIVE_TOPOLOGY m_topology;
67
u32 m_vertex_stride;
68
u32 m_blend_constants;
69
std::array<float, 4> m_blend_constants_f;
70
};
71
72