Use push constants for fixed object data, some minor code cleanup
This commit is contained in:
parent
fbc3526c58
commit
e04c084312
9 changed files with 80 additions and 128 deletions
|
|
@ -11,25 +11,24 @@ struct Node
|
|||
uint next;
|
||||
};
|
||||
|
||||
layout (set = 0, binding = 1) uniform ObjectUBO
|
||||
{
|
||||
mat4 model;
|
||||
vec4 color;
|
||||
} objectUBO;
|
||||
|
||||
layout (set = 0, binding = 2) buffer GeometrySBO
|
||||
layout (set = 0, binding = 1) buffer GeometrySBO
|
||||
{
|
||||
uint count;
|
||||
uint maxNodeCount;
|
||||
};
|
||||
|
||||
layout (set = 0, binding = 3, r32ui) uniform uimage2D headIndexImage;
|
||||
layout (set = 0, binding = 2, r32ui) uniform uimage2D headIndexImage;
|
||||
|
||||
layout (set = 0, binding = 4) buffer LinkedListSBO
|
||||
layout (set = 0, binding = 3) buffer LinkedListSBO
|
||||
{
|
||||
Node nodes[];
|
||||
};
|
||||
|
||||
layout(push_constant) uniform PushConsts {
|
||||
mat4 model;
|
||||
vec4 color;
|
||||
} pushConsts;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Increase the node count
|
||||
|
|
@ -42,7 +41,7 @@ void main()
|
|||
uint prevHeadIdx = imageAtomicExchange(headIndexImage, ivec2(gl_FragCoord.xy), nodeIdx);
|
||||
|
||||
// Store node data
|
||||
nodes[nodeIdx].color = objectUBO.color;
|
||||
nodes[nodeIdx].color = pushConsts.color;
|
||||
nodes[nodeIdx].depth = gl_FragCoord.z;
|
||||
nodes[nodeIdx].next = prevHeadIdx;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -8,14 +8,13 @@ layout (set = 0, binding = 0) uniform RenderPassUBO
|
|||
mat4 view;
|
||||
} renderPassUBO;
|
||||
|
||||
layout (set = 0, binding = 1) uniform ObjectUBO
|
||||
{
|
||||
mat4 model;
|
||||
layout(push_constant) uniform PushConsts {
|
||||
mat4 model;
|
||||
vec4 color;
|
||||
} objectUBO;
|
||||
} pushConsts;
|
||||
|
||||
void main()
|
||||
{
|
||||
mat4 PVM = renderPassUBO.projection * renderPassUBO.view * objectUBO.model;
|
||||
mat4 PVM = renderPassUBO.projection * renderPassUBO.view * pushConsts.model;
|
||||
gl_Position = PVM * vec4(inPos, 1.0);
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -14,25 +14,23 @@ struct Node
|
|||
uint next;
|
||||
};
|
||||
|
||||
struct ObjectUBO
|
||||
{
|
||||
float4x4 model;
|
||||
float4 color;
|
||||
};
|
||||
|
||||
cbuffer ubo : register(b1) { ObjectUBO objectUBO; }
|
||||
|
||||
struct GeometrySBO
|
||||
{
|
||||
uint count;
|
||||
uint maxNodeCount;
|
||||
};
|
||||
// Binding 0 : Position storage buffer
|
||||
RWStructuredBuffer<GeometrySBO> geometrySBO : register(u2);
|
||||
RWStructuredBuffer<GeometrySBO> geometrySBO : register(u1);
|
||||
|
||||
RWTexture2D<uint> headIndexImage : register(u3);
|
||||
RWTexture2D<uint> headIndexImage : register(u2);
|
||||
|
||||
RWStructuredBuffer<Node> nodes : register(u4);
|
||||
RWStructuredBuffer<Node> nodes : register(u3);
|
||||
|
||||
struct PushConsts {
|
||||
float4x4 model;
|
||||
float4 color;
|
||||
};
|
||||
[[vk::push_constant]] PushConsts pushConsts;
|
||||
|
||||
[earlydepthstencil]
|
||||
void main(VSOutput input)
|
||||
|
|
@ -49,7 +47,7 @@ void main(VSOutput input)
|
|||
InterlockedExchange(headIndexImage[uint2(input.Pos.xy)], nodeIdx, prevHeadIdx);
|
||||
|
||||
// Store node data
|
||||
nodes[nodeIdx].color = objectUBO.color;
|
||||
nodes[nodeIdx].color = pushConsts.color;
|
||||
nodes[nodeIdx].depth = input.Pos.z;
|
||||
nodes[nodeIdx].next = prevHeadIdx;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -13,13 +13,11 @@ struct RenderPassUBO
|
|||
|
||||
cbuffer renderPassUBO : register(b0) { RenderPassUBO renderPassUBO; }
|
||||
|
||||
struct ObjectUBO
|
||||
{
|
||||
float4x4 model;
|
||||
float4 color;
|
||||
struct PushConsts {
|
||||
float4x4 model;
|
||||
float4 color;
|
||||
};
|
||||
|
||||
cbuffer objectUBO : register(b1) { ObjectUBO objectUBO; }
|
||||
[[vk::push_constant]] PushConsts pushConsts;
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
|
|
@ -29,6 +27,6 @@ struct VSOutput
|
|||
VSOutput main(VSInput input)
|
||||
{
|
||||
VSOutput output = (VSOutput)0;
|
||||
output.Pos = mul(renderPassUBO.projection, mul(renderPassUBO.view, mul(objectUBO.model, input.Pos)));
|
||||
output.Pos = mul(renderPassUBO.projection, mul(renderPassUBO.view, mul(pushConsts.model, input.Pos)));
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue