aboutsummaryrefslogtreecommitdiff
path: root/src/d3d11/context_d3d11.h
blob: 82a693164863229687cabd8313605bc67d71623e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// This code contains NVIDIA Confidential Information and is disclosed 
// under the Mutual Non-Disclosure Agreement. 
// 
// Notice 
// ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES 
// NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 
// THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT, 
// MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. 
// 
// NVIDIA Corporation assumes no responsibility for the consequences of use of such 
// information or for any infringement of patents or other rights of third parties that may 
// result from its use. No license is granted by implication or otherwise under any patent 
// or patent rights of NVIDIA Corporation. No third party distribution is allowed unless 
// expressly authorized by NVIDIA.  Details are subject to change without notice. 
// This code supersedes and replaces all information previously supplied. 
// NVIDIA Corporation products are not authorized for use as critical 
// components in life support devices or systems without express written approval of 
// NVIDIA Corporation. 
// 
// Copyright (c) 2003 - 2016 NVIDIA Corporation. All rights reserved.
//
// NVIDIA Corporation and its licensors retain all intellectual property and proprietary
// rights in and to this software and related documentation and any modifications thereto.
// Any use, reproduction, disclosure or distribution of this software and related
// documentation without an express license agreement from NVIDIA Corporation is
// strictly prohibited.
//

#ifndef CONTEXT_D3D11_H
#define CONTEXT_D3D11_H
////////////////////////////////////////////////////////////////////////////////
#include <Nv/VolumetricLighting/NvVolumetricLighting.h>

#include <vector> // TODO: remove this dependency
#include "context_common.h"
/*==============================================================================
   Forward Declarations
==============================================================================*/
// D3D11 Types
struct ID3D11VertexShader;
struct ID3D11HullShader;
struct ID3D11DomainShader;
struct ID3D11GeometryShader;
struct ID3D11PixelShader;
struct ID3D11ComputeShader;
struct ID3D11RasterizerState;
struct ID3D11SamplerState;
struct ID3D11DepthStencilState;
struct ID3D11BlendState;
struct ID3D11InputLayout;
struct ID3D11Buffer;

// Helper Types
class Texture2D;
class RenderTarget;
class DepthTarget;
template <class T> class ConstantBuffer;

////////////////////////////////////////////////////////////////////////////////
namespace Nv { namespace VolumetricLighting {
////////////////////////////////////////////////////////////////////////////////

class ContextImp_D3D11 : public ContextImp_Common
{
public:
    // Creates the context and resources
    static Status Create(ContextImp_D3D11 ** out_ctx, const PlatformDesc * pPlatformDesc, const ContextDesc * pContextDesc);

	// Clean up the context on delete
	virtual ~ContextImp_D3D11();

protected:
	// BeginAccumulation
    Status BeginAccumulation_Start(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc);
	Status BeginAccumulation_UpdateMediumLUT(PlatformRenderCtx renderCtx);
	Status BeginAccumulation_CopyDepth(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth);
	Status BeginAccumulation_End(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, ViewerDesc const* pViewerDesc, MediumDesc const* pMediumDesc);

	// RenderVolume
    Status RenderVolume_Start(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc);
	Status RenderVolume_DoVolume_Directional(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc);
	Status RenderVolume_DoVolume_Spotlight(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc);
    Status RenderVolume_DoVolume_Omni(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc);
	Status RenderVolume_End(PlatformRenderCtx renderCtx, PlatformShaderResource shadowMap, ShadowMapDesc const* pShadowMapDesc, LightDesc const* pLightDesc, VolumeDesc const* pVolumeDesc);

	// EndAccumulation
	Status EndAccumulation_Imp(PlatformRenderCtx renderCtx);

	// ApplyLighting
    Status ApplyLighting_Start(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc);
	Status ApplyLighting_Resolve(PlatformRenderCtx renderCtx, PostprocessDesc const* pPostprocessDesc);
	Status ApplyLighting_TemporalFilter(PlatformRenderCtx renderCtx, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc);
	Status ApplyLighting_Composite(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc);
	Status ApplyLighting_End(PlatformRenderCtx renderCtx, PlatformRenderTarget sceneTarget, PlatformShaderResource sceneDepth, PostprocessDesc const* pPostprocessDesc);

private:
	// Private default constructor
	// Should never be called
	ContextImp_D3D11() {};

	// Initializing Destructor
	// Setup all code that can't fail
	ContextImp_D3D11(const ContextDesc * pContextDesc);

    // Called by Create internally
    Status CreateResources(ID3D11Device * device);

    // Do a fullscreen pass with the bound pixel-shader
    Status DrawFullscreen(ID3D11DeviceContext * dxCtx);

    Status DrawFrustumGrid(ID3D11DeviceContext * dxCtx, uint32_t resolution);
    Status DrawFrustumBase(ID3D11DeviceContext * dxCtx, uint32_t resolution);
    Status DrawFrustumCap(ID3D11DeviceContext * dxCtx, uint32_t resolution);
    Status DrawOmniVolume(ID3D11DeviceContext * dxCtx, uint32_t resolution);

	struct
	{
		ID3D11PixelShader ** Apply_PS;
        ID3D11ComputeShader ** ComputeLightLUT_CS;
		ID3D11PixelShader ** ComputePhaseLookup_PS;
		ID3D11PixelShader ** Debug_PS;
		ID3D11PixelShader ** DownsampleDepth_PS;
		ID3D11VertexShader ** Quad_VS;
		ID3D11VertexShader ** RenderVolume_VS;
		ID3D11HullShader ** RenderVolume_HS;
		ID3D11DomainShader ** RenderVolume_DS;
		ID3D11PixelShader ** RenderVolume_PS;
		ID3D11PixelShader ** Resolve_PS;
		ID3D11PixelShader ** TemporalFilter_PS;
	} shaders;

    ConstantBuffer<PerContextCB> * pPerContextCB;
    ConstantBuffer<PerFrameCB> * pPerFrameCB;
    ConstantBuffer<PerVolumeCB> * pPerVolumeCB;
    ConstantBuffer<PerApplyCB> * pPerApplyCB;

	DepthTarget * pDepth_;
    RenderTarget * pPhaseLUT_;
	RenderTarget * pLightLUT_P_[2];
    RenderTarget * pLightLUT_S1_[2];
    RenderTarget * pLightLUT_S2_[2];
	RenderTarget * pAccumulation_;
	RenderTarget * pResolvedAccumulation_;
	RenderTarget * pResolvedDepth_;
	RenderTarget * pFilteredAccumulation_[2];
	RenderTarget * pFilteredDepth_[2];

    RenderTarget * pAccumulatedOutput_;

    struct
    {
        struct
        {
            ID3D11RasterizerState * cull_none;
            ID3D11RasterizerState * cull_front;
            ID3D11RasterizerState * wireframe;
        } rs;

        struct
        {
            ID3D11SamplerState * point;
            ID3D11SamplerState * linear;
        } ss;

        struct  
        {
            ID3D11DepthStencilState * no_depth;
            ID3D11DepthStencilState * write_only_depth;
            ID3D11DepthStencilState * read_only_depth;
            ID3D11DepthStencilState * render_volume;
            ID3D11DepthStencilState * render_volume_boundary;
            ID3D11DepthStencilState * remove_volume_base;
            ID3D11DepthStencilState * render_volume_cap;
            ID3D11DepthStencilState * finish_volume;
        } ds;

        struct
        {
            ID3D11BlendState * no_color;
            ID3D11BlendState * no_blending;
            ID3D11BlendState * additive;
            ID3D11BlendState * additive_modulate;
            ID3D11BlendState * debug_blend;
        } bs;
    } states;
};

////////////////////////////////////////////////////////////////////////////////
}; /*namespace VolumetricLighting*/ }; /*namespace Nv*/
////////////////////////////////////////////////////////////////////////////////
#endif // CONTEXT_D3D11_H