This repository has been archived by the owner on Mar 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRenderer.h
165 lines (140 loc) · 4.38 KB
/
Renderer.h
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
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
// Developed by Minigraph
//
// Author: James Stanard
//
#pragma once
#include "../Core/GpuBuffer.h"
#include "../Core/VectorMath.h"
#include "../Core/Camera.h"
#include "../Core/CommandContext.h"
#include "../Core/UploadBuffer.h"
#include "../Core/TextureManager.h"
#include <cstdint>
#include <vector>
#include "VRS.h"
#include <d3d12.h>
class GraphicsPSO;
class RootSignature;
class DescriptorHeap;
class ShadowCamera;
class ShadowBuffer;
struct GlobalConstants;
struct Mesh;
struct Joint;
namespace Renderer
{
extern BoolVar SeparateZPass;
using namespace Math;
extern std::vector<GraphicsPSO> sm_PSOs;
extern RootSignature m_RootSig;
extern DescriptorHeap s_TextureHeap;
extern DescriptorHeap s_SamplerHeap;
extern DescriptorHandle m_CommonTextures;
#ifdef QUERY_PSINVOCATIONS
extern ID3D12QueryHeap* m_queryHeap;
extern ID3D12Resource* m_queryResult;
extern D3D12_QUERY_DATA_PIPELINE_STATISTICS PipelineStatistics;
#endif
enum RootBindings
{
kMeshConstants,
kMaterialConstants,
kMaterialSRVs,
kMaterialSamplers,
kCommonSRVs,
kCommonCBV,
kSkinMatrices,
kNumRootBindings
};
void Initialize(void);
void LoadPipelineStatistics();
void ReadPipelineStatistics();
void Shutdown(void);
uint8_t GetPSO(uint16_t psoFlags);
void SetIBLTextures(TextureRef diffuseIBL, TextureRef specularIBL);
void SetIBLBias(float LODBias);
void UpdateGlobalDescriptors(void);
void DrawSkybox( GraphicsContext& gfxContext, const Camera& camera, const D3D12_VIEWPORT& viewport, const D3D12_RECT& scissor );
class MeshSorter
{
public:
enum BatchType { kDefault, kShadows };
enum DrawPass { kZPass, kOpaque, kTransparent, kNumPasses };
MeshSorter(BatchType type)
{
m_BatchType = type;
m_Camera = nullptr;
m_Viewport = {};
m_Scissor = {};
m_NumRTVs = 0;
m_DSV = nullptr;
m_SortObjects.clear();
m_SortKeys.clear();
std::memset(m_PassCounts, 0, sizeof(m_PassCounts));
m_CurrentPass = kZPass;
m_CurrentDraw = 0;
}
void SetCamera( const BaseCamera& camera ) { m_Camera = &camera; }
void SetViewport( const D3D12_VIEWPORT& viewport ) { m_Viewport = viewport; }
void SetScissor( const D3D12_RECT& scissor ) { m_Scissor = scissor; }
void AddRenderTarget( ColorBuffer& RTV )
{
ASSERT(m_NumRTVs < 8);
m_RTV[m_NumRTVs++] = &RTV;
}
void SetDepthStencilTarget( DepthBuffer& DSV ) { m_DSV = &DSV; }
const Frustum& GetWorldFrustum() const { return m_Camera->GetWorldSpaceFrustum(); }
const Frustum& GetViewFrustum() const { return m_Camera->GetViewSpaceFrustum(); }
const Matrix4& GetViewMatrix() const { return m_Camera->GetViewMatrix(); }
void AddMesh( const Mesh& mesh, float distance,
D3D12_GPU_VIRTUAL_ADDRESS meshCBV,
D3D12_GPU_VIRTUAL_ADDRESS materialCBV,
D3D12_GPU_VIRTUAL_ADDRESS bufferPtr,
const Joint* skeleton = nullptr);
void Sort();
void RenderMeshes(DrawPass pass, GraphicsContext& context, GlobalConstants& globals);
private:
struct SortKey
{
union
{
uint64_t value;
struct
{
uint64_t objectIdx : 16;
uint64_t psoIdx : 12;
uint64_t key : 32;
uint64_t passID : 4;
};
};
};
struct SortObject
{
const Mesh* mesh;
const Joint* skeleton;
D3D12_GPU_VIRTUAL_ADDRESS meshCBV;
D3D12_GPU_VIRTUAL_ADDRESS materialCBV;
D3D12_GPU_VIRTUAL_ADDRESS bufferPtr;
};
std::vector<SortObject> m_SortObjects;
std::vector<uint64_t> m_SortKeys;
BatchType m_BatchType;
uint32_t m_PassCounts[kNumPasses];
DrawPass m_CurrentPass;
uint32_t m_CurrentDraw;
const BaseCamera* m_Camera;
D3D12_VIEWPORT m_Viewport;
D3D12_RECT m_Scissor;
uint32_t m_NumRTVs;
ColorBuffer* m_RTV[8];
DepthBuffer* m_DSV;
};
} // namespace Renderer