Skip to content

Commit

Permalink
Add unit tests for DiligentGraphics#75 (close DiligentGraphics#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailGorobets committed Dec 18, 2021
1 parent 074de5c commit 4503641
Show file tree
Hide file tree
Showing 13 changed files with 537 additions and 0 deletions.
1 change: 1 addition & 0 deletions Tests/DiligentToolsTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PRIVATE
Diligent-TextureLoader
Diligent-Common
Diligent-GraphicsEngine
Diligent-RenderStateNotationParser
LibPng
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"Shaders": [
{
"Desc": {
"Name": "GeometryOpaque-VS",
"ShaderType": "VERTEX"
},
"SourceLanguage": "HLSL",
"FilePath": "GeometryOpaque.hlsl",
"EntryPoint": "VSMain",
"UseCombinedTextureSamplers": true
},
{
"Desc": {
"Name": "GeometryOpaque-PS",
"ShaderType": "PIXEL"
},
"SourceLanguage": "HLSL",
"FilePath": "GeometryOpaque.hlsl",
"EntryPoint": "PSMain",
"UseCombinedTextureSamplers": true
}
],
"Pipeleines": [
{
"GraphicsPipeline": {
"DepthStencilDesc": {
"DepthEnable": true,
"DepthWriteEnable": true,
"DepthFunc": "LESS"
},
"RasterizerDesc": {
"FillMode": "SOLID",
"CullMode": "BACK",
"FrontCounterClockwise": true,
"DepthClipEnable": true
},
"SmplDesc": {
"Count": 4,
"Quality": 0
},
"NumRenderTargets": 1,
"RTVFormats": {
"0": "RGBA8_UNORM_SRGB"
},
"DSVFormat": "D32_FLOAT",
"PrimitiveTopology": "TRIANGLE_LIST"

},
"PSODesc": {
"Name": "GeometryOpaque",
"PipelineType": "GRAPHICS"
},
"pVS": "GeometryOpaque-VS",
"pPS": "GeometryOpaque-PS"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"Shaders": [
{
"Desc": {
"Name": "GeometryResolve-CS",
"ShaderType": "COMPUTE"
},
"SourceLanguage": "HLSL",
"FilePath": "GeometryResolve.hlsl",
"EntryPoint": "CSMain",
"UseCombinedTextureSamplers": true
}
],
"Pipeleines": [
{
"PSODesc": {
"Name": "GeometryResolve",
"PipelineType": "COMPUTE",
"ResourceLayout": {
"Variables": [
{ "ShaderStages": "COMPUTE", "Name": "TextureColor", "Type": "DYNAMIC" },
{ "ShaderStages": "COMPUTE", "Name": "TextureHead", "Type": "DYNAMIC" },
{ "ShaderStages": "COMPUTE", "Name": "BufferLinkedList", "Type": "DYNAMIC" }
]
}
},
"pCS": "GeometryResolve-CS"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"Shaders": [
{
"Desc": {
"Name": "GeometryTransparent-VS",
"ShaderType": "VERTEX"
},
"SourceLanguage": "HLSL",
"FilePath": "GeometryTransparent.hlsl",
"EntryPoint": "VSMain",
"UseCombinedTextureSamplers": true
},
{
"Desc": {
"Name": "GeometryTransparent-PS",
"ShaderType": "PIXEL"
},
"SourceLanguage": "HLSL",
"FilePath": "GeometryTransparent.hlsl",
"EntryPoint": "PSMain",
"UseCombinedTextureSamplers": true
}
],
"Pipeleines": [
{
"GraphicsPipeline": {
"DepthStencilDesc": {
"DepthEnable": true,
"DepthWriteEnable": false,
"DepthFunc": "LESS"
},
"RasterizerDesc": {
"FillMode": "SOLID",
"CullMode": "NONE",
"FrontCounterClockwise": true,
"DepthClipEnable": true
},
"SmplDesc": {
"Count": 4,
"Quality": 0
},
"NumRenderTargets": 0,
"DSVFormat": "D32_FLOAT",
"PrimitiveTopology": "TRIANGLE_LIST"

},
"PSODesc": {
"Name": "GeometryTransparent",
"PipelineType": "GRAPHICS",
"ResourceLayout": {
"DefaultVariableMergeStages": "PIXEL",
"Variables": [
{ "ShaderStages": [ "PIXEL" ], "Name": "TextureHead", "Type": "DYNAMIC" },
{ "ShaderStages": [ "PIXEL" ], "Name": "BufferLinkedList", "Type": "DYNAMIC" },
{ "ShaderStages": [ "PIXEL" ], "Name": "BufferLinkedListCounter", "Type": "DYNAMIC" }
]
}
},
"pVS": "GeometryTransparent-VS",
"pPS": "GeometryTransparent-PS"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"Shaders": [
{
"Desc": {
"Name": "BlitTexture-VS",
"ShaderType": "VERTEX"
},
"SourceLanguage": "HLSL",
"FilePath": "GraphicsPrimitives.hlsl",
"EntryPoint": "VSBlitTexture",
"UseCombinedTextureSamplers": true
},
{
"Desc": {
"Name": "BlitTexture-PS",
"ShaderType": "PIXEL"
},
"SourceLanguage": "HLSL",
"FilePath": "GraphicsPrimitives.hlsl",
"EntryPoint": "PSBlitTexture",
"UseCombinedTextureSamplers": true
},
{
"Desc": {
"Name": "ClearUnorderedAccessViewUint-CS",
"ShaderType": "COMPUTE"
},
"SourceLanguage": "HLSL",
"FilePath": "GraphicsPrimitives.hlsl",
"EntryPoint": "CSClearUnorderedAccessViewUint",
"UseCombinedTextureSamplers": true
},
{
"Desc": {
"Name": "ClearBufferCounter-CS",
"ShaderType": "COMPUTE"
},
"SourceLanguage": "HLSL",
"FilePath": "GraphicsPrimitives.hlsl",
"EntryPoint": "CSClearBufferCounter",
"UseCombinedTextureSamplers": true
}
],
"Pipeleines": [
{
"GraphicsPipeline": {
"DepthStencilDesc": {
"DepthEnable": false
},
"RasterizerDesc": {
"FillMode": "SOLID",
"CullMode": "NONE"
},
"NumRenderTargets": 1,
"RTVFormats": {
"0": "RGBA8_UNORM_SRGB"
},
"PrimitiveTopology": "TRIANGLE_LIST"

},
"PSODesc": {
"Name": "BlitTexture",
"PipelineType": "GRAPHICS",
"ResourceLayout": {
"Variables": [
{ "ShaderStages": "PIXEL", "Name": "TextureSRV", "Type": "DYNAMIC" }
],
"ImmutableSamplers": [
{ "SamplerOrTextureName": "TextureSRV", "ShaderStages": "PIXEL", "Desc": { "MinFilter" : "POINT", "MagFilter": "POINT", "MipFilter": "POINT" } }
]
}
},
"pVS": "BlitTexture-VS",
"pPS": "BlitTexture-PS"
},
{
"PSODesc": {
"Name": "ClearUnorderedAccessViewUint",
"PipelineType": "COMPUTE",
"ResourceLayout": {
"DefaultVariableMergeStages": "COMPUTE",
"Variables": [
{ "ShaderStages": [ "COMPUTE" ], "Name": "TextureUAV", "Type": "DYNAMIC" }
]
}
},
"pCS": "ClearUnorderedAccessViewUint-CS"
},
{
"PSODesc": {
"Name": "ClearBufferCounter",
"PipelineType": "COMPUTE",
"ResourceLayout": {
"DefaultVariableMergeStages": "COMPUTE",
"Variables": [
{ "ShaderStages": [ "COMPUTE" ], "Name": "BufferUAV", "Type": "DYNAMIC" }
]
}
},
"pCS": "ClearBufferCounter-CS"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Imports": [
"GeometryOpaque.drsn",
"GeometryResolve.drsn",
"GeometryTransparent.drsn",
"GraphicsPrimitives.drsn"
]
}
27 changes: 27 additions & 0 deletions Tests/DiligentToolsTest/assets/Shaders/Common.hlsli
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#define TEXTURE_UINT_CLEAR 0xFFFFFFFF
#define BUFFER_UINT_CLEAR 0

struct ListNode {
uint Next;
uint Color;
uint Depth;
uint Coverage;
};

struct ListSubNode {
float Depth;
uint Color;
};

uint PackColor(float4 color) {
return (uint(color.r * 255) << 24) | (uint(color.g * 255) << 16) | (uint(color.b * 255) << 8) | uint(color.a * 255);
}

float4 UnpackColor(uint color) {
float4 result;
result.r = float((color >> 24) & 0x000000FF) / 255.0f;
result.g = float((color >> 16) & 0x000000FF) / 255.0f;
result.b = float((color >> 8) & 0x000000FF) / 255.0f;
result.a = float((color >> 0) & 0x000000FF) / 255.0f;
return saturate(result);
}
15 changes: 15 additions & 0 deletions Tests/DiligentToolsTest/assets/Shaders/GeometryOpaque.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Common.hlsli"

void VSMain(uint vertexID: SV_VertexID, uint instanceID: SV_InstanceID, out float4 position: SV_Position, out float4 color: TEXCOORD) {
float2 vertexPositions[] = { float2(-0.5, -0.5), float2(+0.5, -0.5), float2(+0.0, +0.5) };

float4 vertexColors[] = { float4(1.0, 0.0, 0.0, 1.0), float4(0.0, 1.0, 0.0, 1.0), float4(0.0, 0.0, 1.0, 1.0) };
float2 instancePositionOffsets[] = { float2(.0, 0.0), float2(0.5, 0.5), float2(-0.5, -0.5), float2(-0.5, 0.5), float2(0.5, -0.5) };

color = vertexColors[vertexID];
position = float4(vertexPositions[vertexID] + instancePositionOffsets[instanceID], 0.8, 1.0f);
}

float4 PSMain(float4 position : SV_Position, float4 color : TEXCOORD) : SV_Target {
return float4(color);
}
56 changes: 56 additions & 0 deletions Tests/DiligentToolsTest/assets/Shaders/GeometryResolve.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

#include "Common.hlsli"

#define FRAGMENT_COUNT 4
#define MSAA_SAMPLE_COUNT 4

RWTexture2D<unorm float4> TextureColor;
Texture2D<uint> TextureHead;
StructuredBuffer<ListNode> BufferLinkedList;

[numthreads(8, 8, 1)]
void CSMain(uint3 id: SV_DispatchThreadID) {

float4 backBuffer = TextureColor[id.xy];
float4 resolveBuffer = float4(0.0, 0.0, 0.0, 0.0f);

uint nodeHead = TextureHead[id.xy];
if (nodeHead == TEXTURE_UINT_CLEAR)
return;

ListSubNode nodes[FRAGMENT_COUNT];
for (uint sampleIdx = 0; sampleIdx < MSAA_SAMPLE_COUNT; sampleIdx++) {

uint count = 0;
uint nodeIdx = nodeHead;

while (nodeIdx != TEXTURE_UINT_CLEAR && count < FRAGMENT_COUNT) {
ListNode node = BufferLinkedList[nodeIdx];
if (node.Coverage & (1 << sampleIdx)) {
nodes[count].Depth = asfloat(node.Depth);
nodes[count].Color = node.Color;
count++;
}
nodeIdx = node.Next;
}

for (uint i = 1; i < count; i++) {
ListSubNode t = nodes[i];
uint j = i;
while (j > 0 && (nodes[j - 1].Depth < t.Depth)) {
nodes[j] = nodes[j - 1];
j--;
}
nodes[j] = t;
}

float4 dstPixelColor = backBuffer;
for (uint index = 0; index < count; index++) {
float4 srcPixelColor = UnpackColor(nodes[index].Color);
dstPixelColor = lerp(dstPixelColor, srcPixelColor, srcPixelColor.a);
}
resolveBuffer += dstPixelColor;
}
TextureColor[id.xy] = resolveBuffer / MSAA_SAMPLE_COUNT;
}

Loading

0 comments on commit 4503641

Please sign in to comment.