Rise
The Vieneo Province
Loading...
Searching...
No Matches
Device11.h
Go to the documentation of this file.
1#pragma once
2
3#include <d3d11.h>
4#include <dxgi1_4.h>
5#include <wrl/client.h>
6#include <string>
7
8namespace Rendering
9{
10 // Depth is owned by the scene, not copied out of a swap-chain depth buffer.
11 // The SRV exposes the original samples, including stencil-masked edges.
13 {
14 public:
15 HRESULT Create(ID3D11Device* device, UINT width, UINT height, DXGI_SAMPLE_DESC samples);
16 void Reset();
17 ID3D11Texture2D* Texture() const { return texture.Get(); }
18 ID3D11DepthStencilView* WriteView() const { return writable.Get(); }
19 ID3D11DepthStencilView* ReadView() const { return readOnly.Get(); }
20 ID3D11ShaderResourceView* ShaderView() const { return shaderView.Get(); }
21 ID3D11ShaderResourceView* StencilView() const { return stencilView.Get(); }
22 const D3D11_TEXTURE2D_DESC& Description() const { return description; }
23 private:
24 Microsoft::WRL::ComPtr<ID3D11Texture2D> texture;
25 Microsoft::WRL::ComPtr<ID3D11DepthStencilView> writable, readOnly;
26 Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> shaderView, stencilView;
27 D3D11_TEXTURE2D_DESC description{};
28 };
29
31 {
32 D3D_DRIVER_TYPE driver = D3D_DRIVER_TYPE_HARDWARE;
33 bool debugLayer = false;
34 };
35
36 // Immediate-context ownership stays on the render thread. No vendor APIs,
37 // D3DX, DXUT, D3D9 device, or optional debug runtime is required.
39 {
40 public:
41 HRESULT Create(const DeviceOptions11& options = {});
42 HRESULT AttachWindow(HWND window, UINT width, UINT height, UINT requestedSamples);
43 HRESULT Resize(UINT width, UINT height, UINT requestedSamples);
44 HRESULT Present(UINT syncInterval = 1);
45 HRESULT SetFullscreen(bool fullscreen);
46 void Reset();
48 Device11() = default;
49 Device11(const Device11&) = delete;
50 Device11& operator=(const Device11&) = delete;
51
52 // Checks both the color and typeless depth family; quality zero is
53 // available whenever levels>0 and is reproducible across adapters.
54 bool SupportsSamples(UINT count) const;
55 UINT SelectSamples(UINT requested) const;
57 void BindScene();
58 // A cloud composite may sample depth and test stencil at once. Both
59 // depth and stencil writes MUST be disabled in its depth/stencil state.
61 // Call at pass boundaries before changing a resource's role. Covers
62 // every shader stage rather than relying on runtime hazard nulling.
64
65 ID3D11Device* Device() const { return device.Get(); }
66 ID3D11DeviceContext* Context() const { return context.Get(); }
67 IDXGISwapChain1* SwapChain() const { return swapChain.Get(); }
68 ID3D11RenderTargetView* SceneTarget() const { return sceneTarget.Get(); }
69 ID3D11Texture2D* SceneColor() const { return sceneColor.Get(); }
70 const SceneDepth11& Depth() const { return depth; }
71 D3D_FEATURE_LEVEL FeatureLevel() const { return featureLevel; }
72 bool DebugLayerEnabled() const { return debugEnabled; }
73 bool Suspended() const { return suspended; }
74 HRESULT RemovalReason() const;
75 const std::string& Status() const { return status; }
76 const DXGI_ADAPTER_DESC1& Adapter() const { return adapterDescription; }
77
78 private:
79 HRESULT CreateTargets(UINT width, UINT height, UINT samples);
80 HRESULT Fail(const char* stage, HRESULT hr);
81 void ReleaseTargets();
82 Microsoft::WRL::ComPtr<ID3D11Device> device;
83 Microsoft::WRL::ComPtr<ID3D11DeviceContext> context;
84 Microsoft::WRL::ComPtr<IDXGISwapChain1> swapChain;
85 Microsoft::WRL::ComPtr<ID3D11Texture2D> backBuffer, sceneColor;
86 Microsoft::WRL::ComPtr<ID3D11RenderTargetView> sceneTarget;
88 DXGI_ADAPTER_DESC1 adapterDescription{};
89 D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
90 UINT width = 0, height = 0, sampleCount = 0;
91 bool debugEnabled = false, suspended = false;
92 std::string status = "D3D11: not initialized";
93 };
94}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
UINT SelectSamples(UINT requested) const
Definition Device11.cpp:124
ID3D11Texture2D * SceneColor() const
Definition Device11.h:69
Microsoft::WRL::ComPtr< ID3D11RenderTargetView > sceneTarget
Definition Device11.h:86
HRESULT AttachWindow(HWND window, UINT width, UINT height, UINT requestedSamples)
Definition Device11.cpp:142
bool SupportsSamples(UINT count) const
Definition Device11.cpp:112
void UnbindShaderResources()
Definition Device11.cpp:163
ID3D11DeviceContext * Context() const
Definition Device11.h:66
HRESULT Fail(const char *stage, HRESULT hr)
Definition Device11.cpp:73
bool Suspended() const
Definition Device11.h:73
void BindSceneWithReadOnlyDepth()
Definition Device11.cpp:236
ID3D11RenderTargetView * SceneTarget() const
Definition Device11.h:68
D3D_FEATURE_LEVEL FeatureLevel() const
Definition Device11.h:71
std::string status
Definition Device11.h:92
IDXGISwapChain1 * SwapChain() const
Definition Device11.h:67
Device11(const Device11 &)=delete
Microsoft::WRL::ComPtr< ID3D11Texture2D > sceneColor
Definition Device11.h:85
HRESULT CheckCloudFormats() const
Definition Device11.cpp:131
ID3D11Device * Device() const
Definition Device11.h:65
DXGI_ADAPTER_DESC1 adapterDescription
Definition Device11.h:88
Microsoft::WRL::ComPtr< IDXGISwapChain1 > swapChain
Definition Device11.h:84
bool DebugLayerEnabled() const
Definition Device11.h:72
const DXGI_ADAPTER_DESC1 & Adapter() const
Definition Device11.h:76
HRESULT Present(UINT syncInterval=1)
Definition Device11.cpp:243
const std::string & Status() const
Definition Device11.h:75
HRESULT SetFullscreen(bool fullscreen)
Definition Device11.cpp:261
Microsoft::WRL::ComPtr< ID3D11Texture2D > backBuffer
Definition Device11.h:85
HRESULT CreateTargets(UINT width, UINT height, UINT samples)
Definition Device11.cpp:186
D3D_FEATURE_LEVEL featureLevel
Definition Device11.h:89
Microsoft::WRL::ComPtr< ID3D11DeviceContext > context
Definition Device11.h:83
Microsoft::WRL::ComPtr< ID3D11Device > device
Definition Device11.h:82
HRESULT Resize(UINT width, UINT height, UINT requestedSamples)
Definition Device11.cpp:210
HRESULT Create(const DeviceOptions11 &options={})
Definition Device11.cpp:84
HRESULT RemovalReason() const
Definition Device11.cpp:268
Device11 & operator=(const Device11 &)=delete
SceneDepth11 depth
Definition Device11.h:87
const SceneDepth11 & Depth() const
Definition Device11.h:70
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > shaderView
Definition Device11.h:26
ID3D11ShaderResourceView * StencilView() const
Definition Device11.h:21
Microsoft::WRL::ComPtr< ID3D11DepthStencilView > writable
Definition Device11.h:25
D3D11_TEXTURE2D_DESC description
Definition Device11.h:27
ID3D11ShaderResourceView * ShaderView() const
Definition Device11.h:20
ID3D11Texture2D * Texture() const
Definition Device11.h:17
Microsoft::WRL::ComPtr< ID3D11DepthStencilView > readOnly
Definition Device11.h:25
const D3D11_TEXTURE2D_DESC & Description() const
Definition Device11.h:22
Microsoft::WRL::ComPtr< ID3D11Texture2D > texture
Definition Device11.h:24
HRESULT Create(ID3D11Device *device, UINT width, UINT height, DXGI_SAMPLE_DESC samples)
Definition Device11.cpp:20
ID3D11DepthStencilView * ReadView() const
Definition Device11.h:19
Microsoft::WRL::ComPtr< ID3D11ShaderResourceView > stencilView
Definition Device11.h:26
ID3D11DepthStencilView * WriteView() const
Definition Device11.h:18
D3D_DRIVER_TYPE driver
Definition Device11.h:32