-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGBufferFillPass.h
More file actions
138 lines (118 loc) · 5.79 KB
/
GBufferFillPass.h
File metadata and controls
138 lines (118 loc) · 5.79 KB
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
/*
* Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <donut/engine/View.h>
#include <donut/engine/SceneTypes.h>
#include <donut/render/GeometryPasses.h>
#include <memory>
#include <mutex>
namespace donut::engine
{
class ShaderFactory;
class CommonRenderPasses;
class FramebufferFactory;
class MaterialBindingCache;
struct Material;
}
namespace donut::render
{
class GBufferFillPass : public IGeometryPass
{
public:
union PipelineKey
{
struct
{
nvrhi::RasterCullMode cullMode : 2;
bool alphaTested : 1;
bool frontCounterClockwise : 1;
bool reverseDepth : 1;
} bits;
uint32_t value;
static constexpr size_t Count = 1 << 5;
};
class Context : public GeometryPassContext
{
public:
PipelineKey keyTemplate;
Context()
{
keyTemplate.value = 0;
}
};
struct CreateParameters
{
std::shared_ptr<engine::MaterialBindingCache> materialBindings;
bool enableSinglePassCubemap = false;
bool enableDepthWrite = true;
bool enableMotionVectors = false;
bool trackLiveness = true;
uint32_t stencilWriteMask = 0;
uint32_t numConstantBufferVersions = 16;
};
protected:
nvrhi::DeviceHandle m_Device;
nvrhi::InputLayoutHandle m_InputLayout;
nvrhi::ShaderHandle m_VertexShader;
nvrhi::ShaderHandle m_PixelShader;
nvrhi::ShaderHandle m_PixelShaderAlphaTested;
nvrhi::ShaderHandle m_GeometryShader;
nvrhi::BindingLayoutHandle m_ViewBindingLayout;
nvrhi::BufferHandle m_GBufferCB;
nvrhi::BindingSetHandle m_ViewBindings;
engine::ViewType::Enum m_SupportedViewTypes = engine::ViewType::PLANAR;
nvrhi::GraphicsPipelineHandle m_Pipelines[PipelineKey::Count];
std::mutex m_Mutex;
std::shared_ptr<engine::CommonRenderPasses> m_CommonPasses;
std::shared_ptr<engine::MaterialBindingCache> m_MaterialBindings;
bool m_EnableDepthWrite = true;
uint32_t m_StencilWriteMask = 0;
virtual nvrhi::ShaderHandle CreateVertexShader(engine::ShaderFactory& shaderFactory, const CreateParameters& params);
virtual nvrhi::ShaderHandle CreateGeometryShader(engine::ShaderFactory& shaderFactory, const CreateParameters& params);
virtual nvrhi::ShaderHandle CreatePixelShader(engine::ShaderFactory& shaderFactory, const CreateParameters& params, bool alphaTested);
virtual nvrhi::InputLayoutHandle CreateInputLayout(nvrhi::IShader* vertexShader, const CreateParameters& params);
virtual void CreateViewBindings(nvrhi::BindingLayoutHandle& layout, nvrhi::BindingSetHandle& set, const CreateParameters& params);
virtual std::shared_ptr<engine::MaterialBindingCache> CreateMaterialBindingCache(engine::CommonRenderPasses& commonPasses);
virtual nvrhi::GraphicsPipelineHandle CreateGraphicsPipeline(PipelineKey key, nvrhi::IFramebuffer* sampleFramebuffer);
public:
GBufferFillPass(nvrhi::IDevice* device, std::shared_ptr<engine::CommonRenderPasses> commonPasses);
virtual void Init(
engine::ShaderFactory& shaderFactory,
const CreateParameters& params);
void ResetBindingCache() const;
// IGeometryPass implementation
[[nodiscard]] engine::ViewType::Enum GetSupportedViewTypes() const override;
void SetupView(GeometryPassContext& context, nvrhi::ICommandList* commandList, const engine::IView* view, const engine::IView* viewPrev) override;
bool SetupMaterial(GeometryPassContext& context, const engine::Material* material, nvrhi::RasterCullMode cullMode, nvrhi::GraphicsState& state) override;
void SetupInputBuffers(GeometryPassContext& context, const engine::BufferGroup* buffers, nvrhi::GraphicsState& state) override;
void SetPushConstants(GeometryPassContext& context, nvrhi::ICommandList* commandList, nvrhi::GraphicsState& state, nvrhi::DrawArguments& args) override { }
};
class MaterialIDPass : public GBufferFillPass
{
protected:
nvrhi::ShaderHandle CreatePixelShader(engine::ShaderFactory& shaderFactory, const CreateParameters& params, bool alphaTested) override;
void CreateViewBindings(nvrhi::BindingLayoutHandle& layout, nvrhi::BindingSetHandle& set, const CreateParameters& params) override;
public:
using GBufferFillPass::GBufferFillPass;
void SetPushConstants(GeometryPassContext& context, nvrhi::ICommandList* commandList, nvrhi::GraphicsState& state, nvrhi::DrawArguments& args) override;
};
}