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