2022-12-28 19:49:18 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
2024-01-13 21:40:13 +00:00
|
|
|
Copyright (C) 2022-2024 Gian 'myT' Schellenbaum
|
2022-12-28 19:49:18 +00:00
|
|
|
|
|
|
|
This file is part of Challenge Quake 3 (CNQ3).
|
|
|
|
|
|
|
|
Challenge Quake 3 is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
Challenge Quake 3 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Challenge Quake 3. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
// Gameplay Rendering Pipeline - private declarations
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
2024-01-13 21:40:13 +00:00
|
|
|
#include "srp_local.h"
|
2022-12-28 19:49:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
#pragma pack(push, 4)
|
|
|
|
|
|
|
|
struct WorldVertexRC
|
|
|
|
{
|
|
|
|
float modelViewMatrix[16];
|
|
|
|
float projectionMatrix[16];
|
|
|
|
float clipPlane[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WorldPixelRC
|
|
|
|
{
|
2023-06-18 00:42:59 +00:00
|
|
|
// general
|
2023-09-16 23:56:35 +00:00
|
|
|
uint32_t stageIndices[8]; // sampler: 16 - texture: 16
|
2022-12-28 19:49:18 +00:00
|
|
|
float greyscale;
|
2023-06-18 00:42:59 +00:00
|
|
|
|
|
|
|
// r_shaderTrace - dynamically enabled
|
2023-09-16 23:56:35 +00:00
|
|
|
uint32_t shaderTrace; // shader index: 14 - frame index: 2 - enable: 1
|
|
|
|
uint16_t centerPixelX;
|
|
|
|
uint16_t centerPixelY;
|
|
|
|
|
|
|
|
// r_depthFade - statically enabled
|
|
|
|
uint16_t hFadeDistance;
|
|
|
|
uint16_t hFadeOffset;
|
|
|
|
uint32_t depthFadeColorTex; // texture index: 12 - color bias: 4 - color scale: 4
|
2023-06-18 00:42:59 +00:00
|
|
|
|
|
|
|
// r_dither - statically enabled
|
2023-09-16 23:56:35 +00:00
|
|
|
uint16_t hFrameSeed;
|
|
|
|
uint16_t hNoiseScale;
|
|
|
|
uint16_t hInvGamma;
|
|
|
|
uint16_t hInvBrightness;
|
2022-12-28 19:49:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
struct VertexBuffers : BufferBase
|
|
|
|
{
|
|
|
|
enum BaseId
|
|
|
|
{
|
|
|
|
BasePosition,
|
|
|
|
BaseNormal,
|
|
|
|
BaseCount
|
|
|
|
};
|
|
|
|
|
|
|
|
enum StageId
|
|
|
|
{
|
|
|
|
StageTexCoords,
|
|
|
|
StageColors,
|
|
|
|
StageCount
|
|
|
|
};
|
|
|
|
|
2024-01-13 21:40:13 +00:00
|
|
|
void Create(const char* name, MemoryUsage::Id memoryUsage, uint32_t vertexCount);
|
|
|
|
void BeginUpload();
|
|
|
|
void EndUpload();
|
|
|
|
void Upload(uint32_t firstStage, uint32_t stageCount);
|
2022-12-28 19:49:18 +00:00
|
|
|
|
|
|
|
static const uint32_t BufferCount = BaseCount + StageCount * MAX_SHADER_STAGES;
|
|
|
|
HBuffer buffers[BufferCount] = {};
|
|
|
|
uint32_t strides[BufferCount] = {};
|
|
|
|
uint8_t* mapped[BufferCount] = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GeometryBuffers
|
|
|
|
{
|
|
|
|
void Rewind()
|
|
|
|
{
|
|
|
|
vertexBuffers.Rewind();
|
|
|
|
indexBuffer.Rewind();
|
|
|
|
}
|
|
|
|
|
|
|
|
VertexBuffers vertexBuffers;
|
|
|
|
IndexBuffer indexBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StaticGeometryChunk
|
|
|
|
{
|
|
|
|
uint32_t vertexCount;
|
|
|
|
uint32_t indexCount;
|
|
|
|
uint32_t firstGPUVertex;
|
|
|
|
uint32_t firstGPUIndex;
|
|
|
|
uint32_t firstCPUIndex;
|
|
|
|
};
|
|
|
|
|
2023-09-10 16:45:55 +00:00
|
|
|
struct BatchType
|
|
|
|
{
|
|
|
|
enum Id
|
|
|
|
{
|
|
|
|
Standard,
|
|
|
|
DynamicLight,
|
2023-09-16 23:56:35 +00:00
|
|
|
DepthFade,
|
2023-09-10 16:45:55 +00:00
|
|
|
Count
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-12-28 19:49:18 +00:00
|
|
|
struct World
|
|
|
|
{
|
|
|
|
void Init();
|
|
|
|
void BeginFrame();
|
2023-06-18 00:42:59 +00:00
|
|
|
void EndFrame();
|
2022-12-28 19:49:18 +00:00
|
|
|
void Begin();
|
|
|
|
void End();
|
2023-07-01 22:23:02 +00:00
|
|
|
void DrawPrePass(const drawSceneViewCommand_t& cmd);
|
2023-09-10 16:45:55 +00:00
|
|
|
void BeginBatch(const shader_t* shader, bool hasStaticGeo, BatchType::Id batchType);
|
2022-12-28 19:49:18 +00:00
|
|
|
void EndBatch();
|
|
|
|
void EndSkyBatch();
|
|
|
|
void RestartBatch();
|
|
|
|
void DrawGUI();
|
|
|
|
void ProcessWorld(world_t& world);
|
|
|
|
void DrawSceneView(const drawSceneViewCommand_t& cmd);
|
|
|
|
void BindVertexBuffers(bool staticGeo, uint32_t firstStage, uint32_t stageCount);
|
|
|
|
void BindIndexBuffer(bool staticGeo);
|
|
|
|
void DrawFog();
|
2023-09-10 16:45:55 +00:00
|
|
|
void DrawLitSurfaces(dlight_t* dl, bool opaque);
|
|
|
|
void DrawDynamicLights(bool opaque);
|
2022-12-28 19:49:18 +00:00
|
|
|
void DrawSkyBox();
|
|
|
|
void DrawClouds();
|
|
|
|
|
|
|
|
typedef uint32_t Index;
|
|
|
|
const IndexType::Id indexType = IndexType::UInt32;
|
|
|
|
|
|
|
|
HTexture depthTexture;
|
|
|
|
uint32_t depthTextureIndex;
|
|
|
|
|
|
|
|
float clipPlane[4];
|
|
|
|
|
|
|
|
struct BufferFamily
|
|
|
|
{
|
|
|
|
enum Id
|
|
|
|
{
|
|
|
|
Invalid,
|
|
|
|
PrePass,
|
|
|
|
Static,
|
|
|
|
Dynamic
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Z pre-pass
|
|
|
|
HRootSignature zppRootSignature;
|
|
|
|
HDescriptorTable zppDescriptorTable;
|
2023-07-01 22:23:02 +00:00
|
|
|
HPipeline zppPipeline;
|
2022-12-28 19:49:18 +00:00
|
|
|
GeometryBuffer zppVertexBuffer;
|
|
|
|
|
|
|
|
// shared
|
|
|
|
BufferFamily::Id boundVertexBuffers;
|
|
|
|
BufferFamily::Id boundIndexBuffer;
|
|
|
|
uint32_t boundStaticVertexBuffersFirst;
|
|
|
|
uint32_t boundStaticVertexBuffersCount;
|
|
|
|
HPipeline batchPSO;
|
2023-09-10 16:45:55 +00:00
|
|
|
BatchType::Id batchType;
|
2022-12-28 19:49:18 +00:00
|
|
|
bool batchHasStaticGeo;
|
|
|
|
int psoChangeCount;
|
|
|
|
bool batchDepthHack;
|
|
|
|
bool batchOldDepthHack;
|
2023-08-03 00:38:29 +00:00
|
|
|
ShadingRate::Id batchShadingRate;
|
|
|
|
ShadingRate::Id batchOldShadingRate;
|
2022-12-28 19:49:18 +00:00
|
|
|
|
|
|
|
// dynamic
|
|
|
|
GeometryBuffers dynBuffers[FrameCount];
|
|
|
|
|
|
|
|
// static
|
|
|
|
GeometryBuffers statBuffers;
|
2023-06-18 00:44:31 +00:00
|
|
|
StaticGeometryChunk statChunks[32768];
|
2022-12-28 19:49:18 +00:00
|
|
|
uint32_t statChunkCount;
|
|
|
|
uint32_t statIndices[1 << 20];
|
|
|
|
uint32_t statIndexCount;
|
|
|
|
|
|
|
|
// fog
|
|
|
|
HRootSignature fogRootSignature;
|
|
|
|
HDescriptorTable fogDescriptorTable;
|
|
|
|
HPipeline fogOutsidePipeline;
|
|
|
|
HPipeline fogInsidePipeline;
|
|
|
|
HBuffer boxVertexBuffer;
|
|
|
|
HBuffer boxIndexBuffer;
|
2023-06-18 00:42:59 +00:00
|
|
|
|
2023-09-10 16:45:55 +00:00
|
|
|
// dynamic lights
|
|
|
|
HRootSignature dlRootSignature;
|
|
|
|
HPipeline dlPipelines[CT_COUNT * 2 * 2]; // { cull type, polygon offset, depth test }
|
|
|
|
bool dlOpaque;
|
|
|
|
float dlIntensity; // 1 for most surfaces, but can be scaled down for liquids etc.
|
|
|
|
bool dlDepthTestEqual;
|
|
|
|
// quick explanation on why dlOpaque is useful in the first place:
|
|
|
|
// - opaque surfaces can have a diffuse texture whose alpha isn't 255 everywhere
|
|
|
|
// - when that happens and we multiply the color by the the alpha (DL uses additive blending),
|
|
|
|
// we get "light holes" in opaque surfaces, which is not what we want
|
2022-12-28 19:49:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
|
|
|
|
struct PSODesc
|
|
|
|
{
|
|
|
|
cullType_t cullType;
|
|
|
|
bool polygonOffset;
|
|
|
|
bool clampDepth;
|
2023-09-16 23:56:35 +00:00
|
|
|
bool depthFade;
|
2022-12-28 19:49:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
struct CachedPSO
|
|
|
|
{
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
// lets us know which Q3 shader
|
|
|
|
// triggered the creation of this PSO
|
|
|
|
char name[MAX_QPATH];
|
|
|
|
#endif
|
|
|
|
PSODesc desc;
|
|
|
|
uint32_t stageStateBits[MAX_SHADER_STAGES];
|
|
|
|
uint32_t stageCount;
|
|
|
|
HPipeline pipeline;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PostProcess
|
|
|
|
{
|
|
|
|
void Init();
|
2023-11-18 03:13:21 +00:00
|
|
|
void Draw(const char* renderPassName, HTexture renderTarget);
|
2022-12-28 19:49:18 +00:00
|
|
|
void ToneMap();
|
2023-11-18 03:13:21 +00:00
|
|
|
void InverseToneMap(int colorFormat);
|
2022-12-28 19:49:18 +00:00
|
|
|
void SetToneMapInput(HTexture toneMapInput);
|
|
|
|
void SetInverseToneMapInput(HTexture inverseToneMapInput);
|
|
|
|
|
2024-01-13 21:40:13 +00:00
|
|
|
private:
|
2022-12-28 19:49:18 +00:00
|
|
|
HPipeline toneMapPipeline;
|
|
|
|
HRootSignature toneMapRootSignature;
|
|
|
|
HDescriptorTable toneMapDescriptorTable;
|
|
|
|
|
2023-11-18 03:13:21 +00:00
|
|
|
HPipeline inverseToneMapPipelines[RTCF_COUNT];
|
2022-12-28 19:49:18 +00:00
|
|
|
HRootSignature inverseToneMapRootSignature;
|
|
|
|
HDescriptorTable inverseToneMapDescriptorTable;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SMAA
|
|
|
|
{
|
|
|
|
void Init();
|
|
|
|
void Update();
|
|
|
|
void Draw(const viewParms_t& parms);
|
|
|
|
|
|
|
|
// matches r_smaa
|
|
|
|
struct Mode
|
|
|
|
{
|
|
|
|
enum Id
|
|
|
|
{
|
|
|
|
Disabled,
|
|
|
|
Low,
|
|
|
|
Medium,
|
|
|
|
High,
|
|
|
|
Ultra,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-13 21:40:13 +00:00
|
|
|
private:
|
2022-12-28 19:49:18 +00:00
|
|
|
// fixed
|
|
|
|
HTexture areaTexture;
|
|
|
|
HTexture searchTexture;
|
|
|
|
HRootSignature rootSignature;
|
|
|
|
HDescriptorTable descriptorTable;
|
|
|
|
|
|
|
|
// depends on render target resolution
|
|
|
|
HTexture edgeTexture;
|
|
|
|
HTexture blendTexture;
|
|
|
|
HTexture stencilTexture;
|
|
|
|
HTexture inputTexture; // tone mapped
|
|
|
|
HTexture outputTexture; // tone mapped
|
|
|
|
|
|
|
|
// depends on selected preset/mode
|
|
|
|
// SMAA has 3 passes:
|
|
|
|
// 1. edge detection
|
|
|
|
// 2. blend weight computation
|
|
|
|
// 3. neighborhood blending
|
|
|
|
HPipeline firstPassPipeline;
|
|
|
|
HPipeline secondPassPipeline;
|
|
|
|
HPipeline thirdPassPipeline;
|
|
|
|
|
|
|
|
Mode::Id mode = Mode::Disabled;
|
|
|
|
int width = -1;
|
|
|
|
int height = -1;
|
|
|
|
bool fixedLoaded = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GRP : IRenderPipeline
|
|
|
|
{
|
|
|
|
void Init() override;
|
|
|
|
void ShutDown(bool fullShutDown) override;
|
|
|
|
void CreateTexture(image_t* image, int mipCount, int width, int height) override;
|
|
|
|
void UpoadTextureAndGenerateMipMaps(image_t* image, const byte* data) override;
|
|
|
|
void BeginTextureUpload(MappedTexture& mappedTexture, image_t* image) override;
|
|
|
|
void EndTextureUpload() override;
|
|
|
|
void ProcessWorld(world_t& world) override;
|
|
|
|
void ProcessModel(model_t& model) override;
|
|
|
|
void ProcessShader(shader_t& shader) override;
|
|
|
|
|
2023-11-23 18:59:39 +00:00
|
|
|
void ExecuteRenderCommands(const byte* data, bool readbackRequested) override;
|
2022-12-28 19:49:18 +00:00
|
|
|
void TessellationOverflow() override { world.RestartBatch(); }
|
|
|
|
void DrawSkyBox() override { world.DrawSkyBox(); }
|
|
|
|
void DrawClouds() override { world.DrawClouds(); }
|
|
|
|
void ReadPixels(int w, int h, int alignment, colorSpace_t colorSpace, void* out) override;
|
|
|
|
|
2024-01-13 21:40:13 +00:00
|
|
|
uint32_t GetSamplerDescriptorIndexFromBaseIndex(uint32_t baseIndex) override { return baseIndex; }
|
|
|
|
|
2022-12-28 19:49:18 +00:00
|
|
|
void BeginFrame();
|
|
|
|
void EndFrame();
|
|
|
|
|
|
|
|
uint32_t RegisterTexture(HTexture htexture);
|
|
|
|
|
|
|
|
uint32_t CreatePSO(CachedPSO& cache, const char* name);
|
|
|
|
|
2023-11-18 03:17:11 +00:00
|
|
|
void UpdateReadbackTexture();
|
|
|
|
|
2022-12-28 19:49:18 +00:00
|
|
|
UI ui;
|
|
|
|
World world;
|
|
|
|
MipMapGenerator mipMapGen;
|
|
|
|
ImGUI imgui;
|
|
|
|
PostProcess post;
|
|
|
|
SMAA smaa;
|
2023-11-29 01:57:28 +00:00
|
|
|
Nuklear nuklear;
|
2022-12-28 19:49:18 +00:00
|
|
|
float frameSeed;
|
2023-11-18 03:17:11 +00:00
|
|
|
bool updateReadbackTexture;
|
2022-12-28 19:49:18 +00:00
|
|
|
|
|
|
|
HTexture renderTarget;
|
|
|
|
TextureFormat::Id renderTargetFormat;
|
2023-11-18 03:17:11 +00:00
|
|
|
HTexture readbackRenderTarget;
|
2022-12-28 19:49:18 +00:00
|
|
|
RootSignatureDesc rootSignatureDesc;
|
|
|
|
HRootSignature rootSignature;
|
|
|
|
HDescriptorTable descriptorTable;
|
|
|
|
uint32_t textureIndex;
|
2024-01-13 21:40:13 +00:00
|
|
|
HSampler samplers[BASE_SAMPLER_COUNT]; // all base samplers
|
2022-12-28 19:49:18 +00:00
|
|
|
|
|
|
|
CachedPSO psos[1024];
|
|
|
|
uint32_t psoCount;
|
|
|
|
HRootSignature uberRootSignature;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern GRP grp;
|