Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/util/d3d11_pipeline.h
4223 views
1
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#pragma once
5
6
#include "gpu_device.h"
7
8
#include "common/windows_headers.h"
9
10
#include <d3d11_1.h>
11
#include <dxgi1_5.h>
12
#include <string>
13
#include <string_view>
14
#include <vector>
15
#include <wrl/client.h>
16
17
class D3D11Device;
18
19
class D3D11Shader final : public GPUShader
20
{
21
friend D3D11Device;
22
23
public:
24
~D3D11Shader() override;
25
26
ID3D11VertexShader* GetVertexShader() const;
27
ID3D11PixelShader* GetPixelShader() const;
28
ID3D11GeometryShader* GetGeometryShader() const;
29
ID3D11ComputeShader* GetComputeShader() const;
30
31
ALWAYS_INLINE const std::vector<u8>& GetBytecode() const { return m_bytecode; }
32
33
#ifdef ENABLE_GPU_OBJECT_NAMES
34
void SetDebugName(std::string_view name) override;
35
#endif
36
37
private:
38
D3D11Shader(GPUShaderStage stage, Microsoft::WRL::ComPtr<ID3D11DeviceChild> shader, std::vector<u8> bytecode);
39
40
Microsoft::WRL::ComPtr<ID3D11DeviceChild> m_shader;
41
std::vector<u8> m_bytecode; // only for VS
42
};
43
44
class D3D11Pipeline final : public GPUPipeline
45
{
46
friend D3D11Device;
47
48
template<typename T>
49
using ComPtr = Microsoft::WRL::ComPtr<T>;
50
51
public:
52
~D3D11Pipeline() override;
53
54
#ifdef ENABLE_GPU_OBJECT_NAMES
55
void SetDebugName(std::string_view name) override;
56
#endif
57
58
ALWAYS_INLINE bool IsComputePipeline() const { return !m_vs; }
59
ALWAYS_INLINE ID3D11RasterizerState* GetRasterizerState() const { return m_rs.Get(); }
60
ALWAYS_INLINE ID3D11DepthStencilState* GetDepthStencilState() const { return m_ds.Get(); }
61
ALWAYS_INLINE ID3D11BlendState* GetBlendState() const { return m_bs.Get(); }
62
ALWAYS_INLINE ID3D11InputLayout* GetInputLayout() const { return m_il.Get(); }
63
ALWAYS_INLINE ID3D11VertexShader* GetVertexShader() const { return m_vs.Get(); }
64
ALWAYS_INLINE ID3D11GeometryShader* GetGeometryShader() const { return m_gs.Get(); }
65
ALWAYS_INLINE ID3D11PixelShader* GetPixelShader() const { return static_cast<ID3D11PixelShader*>(m_ps_or_cs.Get()); }
66
ALWAYS_INLINE ID3D11ComputeShader* GetComputeShader() const
67
{
68
return static_cast<ID3D11ComputeShader*>(m_ps_or_cs.Get());
69
}
70
ALWAYS_INLINE D3D11_PRIMITIVE_TOPOLOGY GetPrimitiveTopology() const { return m_topology; }
71
ALWAYS_INLINE u32 GetVertexStride() const { return m_vertex_stride; }
72
ALWAYS_INLINE u32 GetBlendFactor() const { return m_blend_factor; }
73
ALWAYS_INLINE const std::array<float, 4>& GetBlendFactorFloat() const { return m_blend_factor_float; }
74
75
private:
76
D3D11Pipeline(ComPtr<ID3D11RasterizerState> rs, ComPtr<ID3D11DepthStencilState> ds, ComPtr<ID3D11BlendState> bs,
77
ComPtr<ID3D11InputLayout> il, ComPtr<ID3D11VertexShader> vs, ComPtr<ID3D11GeometryShader> gs,
78
ComPtr<ID3D11DeviceChild> ps_or_cs, D3D11_PRIMITIVE_TOPOLOGY topology, u32 vertex_stride,
79
u32 blend_factor);
80
81
ComPtr<ID3D11RasterizerState> m_rs;
82
ComPtr<ID3D11DepthStencilState> m_ds;
83
ComPtr<ID3D11BlendState> m_bs;
84
ComPtr<ID3D11InputLayout> m_il;
85
ComPtr<ID3D11VertexShader> m_vs;
86
ComPtr<ID3D11GeometryShader> m_gs;
87
ComPtr<ID3D11DeviceChild> m_ps_or_cs;
88
D3D11_PRIMITIVE_TOPOLOGY m_topology;
89
u32 m_vertex_stride;
90
u32 m_blend_factor;
91
std::array<float, 4> m_blend_factor_float;
92
};
93
94