Bit of shader refactoring

This commit is contained in:
Dynamitos
2023-11-26 12:47:48 +01:00
parent 52c7fce931
commit 2ad7eae60b
6 changed files with 18 additions and 33 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ layout(set=5)
ParameterBlock<LightCullingData> pLightCullingData;
[shader("pixel")]
float4 fragmentMain(in FragmentParameter params : PARAMETER) : SV_Target
float4 fragmentMain(in FragmentParameter params) : SV_Target
{
MaterialParameter materialParams = params.getMaterialParameter();
LightingParameter lightingParams = params.getLightingParameter();
+2 -11
View File
@@ -3,21 +3,12 @@ import VertexData;
import MaterialParameter;
import Scene;
struct VertexShaderOutput
{
FragmentParameter parameter : PARAMETER;
float4 clipPos: SV_Position;
}
[shader("vertex")]
VertexShaderOutput vertexMain(
FragmentParameter vertexMain(
uint vertexId: SV_VertexID,
uint instanceId: SV_InstanceID,
){
InstanceData inst = pScene.instances[instanceId];
VertexAttributes attr = pVertexData.getAttributes(vertexId, inst.transformMatrix);
VertexShaderOutput output;
output.parameter = attr.getParameter(inst.transformMatrix);
output.clipPos = output.parameter.position_CS;
return output;
return attr.getParameter(inst.transformMatrix);
}
+5 -10
View File
@@ -76,8 +76,7 @@ struct PrimitiveAttributes
struct MeshOutput
{
FragmentParameter parameter : PARAMETER;
float4 position_CS : SV_Position;
FragmentParameter parameter;
};
[numthreads(MESH_GROUP_SIZE, 1, 1)]
@@ -94,10 +93,9 @@ void meshMain(
MeshData md = pScene.meshData[meshPayload.instanceId[groupID]];
MeshletDescription m = pScene.meshletInfos[meshPayload.meshletId[groupID]];
const uint vertexLoops = (MAX_VERTICES + MESH_GROUP_SIZE - 1) / MESH_GROUP_SIZE;
for(uint loop = 0; loop < vertexLoops; ++loop)
for(uint i = threadID; i < MAX_VERTICES; i += MESH_GROUP_SIZE)
{
uint v = threadID + loop * MESH_GROUP_SIZE;
v = min(v, m.vertexCount - 1);
uint v = min(i, m.vertexCount - 1);
InterlockedMax(gs_numVertices, v + 1);
{
int vertexIndex = pScene.vertexIndices[m.vertexOffset + v];
@@ -106,10 +104,9 @@ void meshMain(
}
GroupMemoryBarrierWithGroupSync();
const uint primitiveLoops = (MAX_PRIMITIVES + MESH_GROUP_SIZE - 1) / MESH_GROUP_SIZE;
for(uint loop = 0; loop < primitiveLoops; ++loop)
for(uint i = threadID; i < MAX_PRIMITIVES; i += MESH_GROUP_SIZE)
{
uint p = threadID + loop * MESH_GROUP_SIZE;
p = min(p, m.primitiveCount - 1);
uint p = min(i, m.primitiveCount - 1);
InterlockedMax(gs_numPrimitives, p + 1);
{
uint32_t local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
@@ -128,14 +125,12 @@ void meshMain(
v = min(v, m.vertexCount - 1);
FragmentParameter parameter = gs_vertices[v].getParameter(inst.transformMatrix);
vertices[v].parameter = parameter;
vertices[v].position_CS = parameter.position_CS;
if(vertexLoops >= 1)
{
uint v = threadID + MESH_GROUP_SIZE;
v = min(v, m.vertexCount - 1);
FragmentParameter parameter = gs_vertices[v].getParameter(inst.transformMatrix);
vertices[v].parameter = parameter;
vertices[v].position_CS = parameter.position_CS;
}
uint p = threadID;
+4 -4
View File
@@ -2,10 +2,10 @@ import Common;
struct MaterialParameter
{
float3 position_TS : POSITION0;
float3 position_WS : POSITION1;
float2 texCoords : TEXCOORDS0;
float3 vertexColor : COLOR0;
float3 position_TS;
float3 position_WS;
float2 texCoords;
float3 vertexColor;
};
// data used by light environment
+5 -3
View File
@@ -11,9 +11,11 @@ struct MeshletDescription
struct MeshData
{
uint numMeshlets;
uint meshletOffset;
uint indicesOffset;
uint numMeshlets;
uint meshletOffset;
uint firstIndex;
uint numIndices;
uint indicesOffset;
};
static const uint MAX_VERTICES = 64;
+1 -4
View File
@@ -468,10 +468,7 @@ CommandPool::CommandPool(PGraphics graphics, PQueue queue)
CommandPool::~CommandPool()
{
for (auto& command : allocatedBuffers)
{
command->waitForCommand();
}
vkDeviceWaitIdle(graphics->getDevice());
allocatedRenderCommands.clear();
allocatedComputeCommands.clear();
allocatedBuffers.clear();