Render graph integration and resource management refactor
Introduces a full-featured render graph system with pass culling, resource aliasing, and automatic barrier generation. Refactors resource and barrier APIs, improves error handling, and unifies result types. Renderer and render passes now use the new graph-based workflow. Updates shader includes, adds a blit shader, and improves HLSL parsing. Removes dynamic descriptor heaps in favor of persistent ones. Project file now includes the render graph module. Lays the foundation for advanced rendering features and improved memory efficiency.
This commit is contained in:
74
Ghost.Graphics/Shaders/Blit.gsdef
Normal file
74
Ghost.Graphics/Shaders/Blit.gsdef
Normal file
@@ -0,0 +1,74 @@
|
||||
shader "Hidden/Blit"
|
||||
{
|
||||
properties
|
||||
{
|
||||
tex2d mainTex = { white };
|
||||
sampler sampler_mainTex;
|
||||
}
|
||||
|
||||
pass "Blit"
|
||||
{
|
||||
pipeline
|
||||
{
|
||||
ztest = always;
|
||||
zwrite = off;
|
||||
cull = off;
|
||||
blend = opaque;
|
||||
color_mask = all;
|
||||
}
|
||||
|
||||
includes
|
||||
{
|
||||
"F:/csharp/GhostEngine/Ghost.Graphics/Shaders/Includes/Common.hlsl";
|
||||
"F:/csharp/GhostEngine/Ghost.Graphics/Shaders/Includes/Color.hlsl";
|
||||
"F:/csharp/GhostEngine/Ghost.Graphics/Shaders/Includes/Properties.hlsl";
|
||||
}
|
||||
|
||||
hlsl
|
||||
{
|
||||
struct PSInput
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float4 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
[MESH_SHADER_THREADS(4)]
|
||||
[OUTPUT_TRIANGLE_TOPOLOGY]
|
||||
void MSMain(
|
||||
uint gtid : SV_GroupThreadID,
|
||||
out vertices PSInput verts[4],
|
||||
out indices uint3 tris[2]
|
||||
)
|
||||
{
|
||||
SetMeshOutputCounts(4, 2);
|
||||
|
||||
float2 uv = float2(gtid & 1, (gtid >> 1) & 1);
|
||||
|
||||
verts[gtid].position = float4(uv * 2.0 - 1.0, 0.0, 1.0);
|
||||
// verts[gtid].position.y *= -1.0;
|
||||
verts[gtid].uv = float4(uv, 0.0, 0.0);
|
||||
|
||||
if (gtid == 0)
|
||||
{
|
||||
tris[0] = uint3(0, 1, 2); // First triangle
|
||||
tris[1] = uint3(1, 3, 2); // Second triangle
|
||||
}
|
||||
}
|
||||
|
||||
float4 PSMain(PSInput input) : SV_TARGET
|
||||
{
|
||||
PerMaterialData perMaterialData = LoadData<PerMaterialData>(g_PushConstantData.perMaterialBuffer, 0);
|
||||
|
||||
float2 uv = input.uv.xy;
|
||||
float4 color = SAMPLE_TEXTURE2D(perMaterialData.mainTex, perMaterialData.sampler_mainTex, uv);
|
||||
#ifdef LINEAR_COLORSPACE
|
||||
color = LinearToSRGB(color);
|
||||
#endif
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
mesh "hlsl_block" : "MSMain";
|
||||
pixel "hlsl_block" : "PSMain";
|
||||
}
|
||||
}
|
||||
12
Ghost.Graphics/Shaders/Includes/Color.hlsl
Normal file
12
Ghost.Graphics/Shaders/Includes/Color.hlsl
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef GHOST_COLOR_HLSL
|
||||
#define GHOST_COLOR_HLSL
|
||||
|
||||
float4 LinearToSRGB(float4 color)
|
||||
{
|
||||
float3 srgb;
|
||||
srgb = saturate(color.rgb);
|
||||
srgb = pow(srgb, 1.0 / 2.2);
|
||||
return float4(srgb, color.a);
|
||||
}
|
||||
|
||||
#endif // GHOST_COLOR_HLSL
|
||||
97
Ghost.Graphics/Shaders/Includes/Common.hlsl
Normal file
97
Ghost.Graphics/Shaders/Includes/Common.hlsl
Normal file
@@ -0,0 +1,97 @@
|
||||
#ifndef BUILTIN_COMMON_HLSL
|
||||
#define BUILTIN_COMMON_HLSL
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
float4 position;
|
||||
float4 normal;
|
||||
float4 tangent;
|
||||
float4 uv;
|
||||
float4 color;
|
||||
};
|
||||
|
||||
// Resource descriptor heap definitions
|
||||
|
||||
#define GLOBAL_TEXTURE2D_HEAP ResourceDescriptorHeap
|
||||
#define GLOBAL_TEXTURE3D_HEAP ResourceDescriptorHeap
|
||||
#define GLOBAL_TEXTURECUBE_HEAP ResourceDescriptorHeap
|
||||
#define GLOBAL_TEXTURE2D_ARRAY_HEAP ResourceDescriptorHeap
|
||||
#define GLOBAL_TEXTURECUBE_ARRAY_HEAP ResourceDescriptorHeap
|
||||
#define GLOBAL_BUFFER_HEAP ResourceDescriptorHeap
|
||||
#define GLOBAL_SAMPLER_HEAP SamplerDescriptorHeap
|
||||
|
||||
// Bindless resource type definitions
|
||||
|
||||
#define TEXTURE2D uint
|
||||
#define TEXTURE3D uint
|
||||
#define TEXTURECUBE uint
|
||||
#define TEXTURE2D_ARRAY uint
|
||||
#define TEXTURECUBE_ARRAY uint
|
||||
|
||||
#define SAMPLER uint
|
||||
|
||||
#define STRUCT_BUFFER uint
|
||||
#define BYTE_ADDRESS_BUFFER uint
|
||||
|
||||
|
||||
// Texture and sampler access macros
|
||||
|
||||
#define GET_TEXTURE2D(id) GLOBAL_TEXTURE2D_HEAP[id]
|
||||
#define GET_TEXTURE2D_ARRAY(id) GLOBAL_TEXTURE2D_ARRAY_HEAP[id]
|
||||
#define GET_TEXTURE3D(id) GLOBAL_TEXTURE3D_HEAP[id]
|
||||
#define GET_TEXTURECUBE(id) GLOBAL_TEXTURECUBE_HEAP[id]
|
||||
#define GET_TEXTURECUBE_ARRAY(id) GLOBAL_TEXTURECUBE_ARRAY_HEAP[id]
|
||||
#define GET_BUFFER(id) GLOBAL_BUFFER_HEAP[id]
|
||||
#define GET_SAMPLER(id) GLOBAL_SAMPLER_HEAP[id]
|
||||
|
||||
#define SAMPLE_TEXTURE2D(texId, sampId, uv) SampleTexture2D(texId, sampId, uv)
|
||||
#define SAMPLE_TEXTURE2D_LEVEL(texId, sampId, uv, level) SampleTexture2DLevel(texId, sampId, uv, level)
|
||||
#define SAMPLE_TEXTURE2D_ARRAY(texId, sampId, uvw) SampleTextureArray(texId, sampId, uvw)
|
||||
|
||||
|
||||
#define MESH_SHADER_THREADS(x) NumThreads(x, 1, 1)
|
||||
#define OUTPUT_TRIANGLE_TOPOLOGY OutputTopology("triangle")
|
||||
#define OUTPUT_LINE_TOPOLOGY OutputTopology("line")
|
||||
|
||||
|
||||
static inline float4 SampleTexture2D(uint texId, uint sampId, float2 uv)
|
||||
{
|
||||
Texture2D tex = GET_TEXTURE2D(texId);
|
||||
SamplerState samp = GET_SAMPLER(sampId);
|
||||
return tex.Sample(samp, uv);
|
||||
}
|
||||
|
||||
static inline float4 SampleTexture2DLevel(uint texId, uint sampId, float2 uv, float level)
|
||||
{
|
||||
Texture2D tex = GET_TEXTURE2D(texId);
|
||||
SamplerState samp = GET_SAMPLER(sampId);
|
||||
return tex.SampleLevel(samp, uv, level);
|
||||
}
|
||||
|
||||
static inline float4 SampleTextureArray(uint texId, uint sampId, float3 uvw)
|
||||
{
|
||||
Texture2DArray tex = GET_TEXTURE2D_ARRAY(texId);
|
||||
SamplerState samp = GET_SAMPLER(sampId);
|
||||
return tex.Sample(samp, uvw);
|
||||
}
|
||||
|
||||
static inline Vertex LoadVertexData(uint vertexID, uint groupID, BYTE_ADDRESS_BUFFER vertexBuffer, BYTE_ADDRESS_BUFFER indexBuffer)
|
||||
{
|
||||
ByteAddressBuffer vertices = GET_BUFFER(vertexBuffer);
|
||||
ByteAddressBuffer indices = GET_BUFFER(indexBuffer);
|
||||
|
||||
// Compute the triangle’s vertex indices
|
||||
uint indexOffset = (groupID * 3 + vertexID) * 4; // uint32 index
|
||||
uint vertexIndex = indices.Load(indexOffset);
|
||||
|
||||
return vertices.Load<Vertex>(vertexIndex * sizeof(Vertex));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline T LoadData(BYTE_ADDRESS_BUFFER buffer, uint index)
|
||||
{
|
||||
ByteAddressBuffer buf = GET_BUFFER(buffer);
|
||||
return buf.Load<T>(index * sizeof(T));
|
||||
}
|
||||
|
||||
#endif // BUILTIN_COMMON_HLSL
|
||||
36
Ghost.Graphics/Shaders/Includes/Properties.hlsl
Normal file
36
Ghost.Graphics/Shaders/Includes/Properties.hlsl
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef BUILTIN_PROPERTIES_HLSL
|
||||
#define BUILTIN_PROPERTIES_HLSL
|
||||
|
||||
#include "F:/csharp/GhostEngine/Ghost.Graphics/Shaders/Includes/Common.hlsl"
|
||||
|
||||
struct PushConstantData
|
||||
{
|
||||
BYTE_ADDRESS_BUFFER globalBuffer;
|
||||
BYTE_ADDRESS_BUFFER perViewBuffer;
|
||||
BYTE_ADDRESS_BUFFER perObjectBuffer;
|
||||
BYTE_ADDRESS_BUFFER perMaterialBuffer;
|
||||
};
|
||||
|
||||
struct PerViewData
|
||||
{
|
||||
float4x4 viewMatrix;
|
||||
float4x4 projectionMatrix;
|
||||
float3 cameraPosition;
|
||||
float nearClip;
|
||||
float3 cameraDirection;
|
||||
float farClip;
|
||||
float4 screenSize; // xy: size, zw: 1/size
|
||||
};
|
||||
|
||||
struct PerObjectData
|
||||
{
|
||||
float4x4 localToWorld;
|
||||
float3 worldBoundsMin;
|
||||
BYTE_ADDRESS_BUFFER vertexBuffer;
|
||||
float3 worldBoundsMax;
|
||||
BYTE_ADDRESS_BUFFER indexBuffer;
|
||||
};
|
||||
|
||||
PushConstantData g_PushConstantData : register(b0);
|
||||
|
||||
#endif // BUILTIN_PROPERTIES_HLSL
|
||||
Reference in New Issue
Block a user