Reworking VertexData
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import VertexData;
|
||||
import StaticMeshVertexData;
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 transformMatrix;
|
||||
};
|
||||
|
||||
struct Scene
|
||||
{
|
||||
StructuredBuffer<InstanceData> instances;
|
||||
}
|
||||
|
||||
ParameterBlock<Scene> scene;
|
||||
|
||||
[shader("vertex")]
|
||||
StaticMeshVertexAttributes vertexMain(
|
||||
uint vertexId: SV_VertexID,
|
||||
uint instanceId: SV_InstanceID,
|
||||
){
|
||||
InstanceData inst = scene.instances[instanceId];
|
||||
StaticMeshVertexAttributes attr = vertexData.getAttributes(vertexId, inst.transformMatrix);
|
||||
return attr;
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import Common;
|
||||
import BRDF;
|
||||
import Meshlet;
|
||||
import Scene;
|
||||
import StaticMeshVertexData;
|
||||
|
||||
struct MeshPayload
|
||||
{
|
||||
uint instanceId[MAX_MESHLETS_PER_MESH];
|
||||
uint meshletId[MAX_MESHLETS_PER_MESH];
|
||||
};
|
||||
|
||||
groupshared MeshPayload p;
|
||||
groupshared uint head;
|
||||
groupshared float4x4 localToClip;
|
||||
groupshared Frustum viewFrustum;
|
||||
|
||||
[numthreads(TASK_GROUP_SIZE, 1, 1)]
|
||||
[outputtopology("triangle")]
|
||||
[shader("amplification")]
|
||||
void taskMain(
|
||||
uint threadID: SV_GroupIndex,
|
||||
uint groupID: SV_GroupID
|
||||
){
|
||||
InstanceData instance = scene.instances[groupID];
|
||||
if(threadID == 0)
|
||||
{
|
||||
head = 0;
|
||||
localToClip = mul(viewParams.projectionMatrix, mul(viewParams.viewMatrix, instance.transformMatrix));
|
||||
// Left
|
||||
viewFrustum.sides[0].n = float3(1, 0, 0);
|
||||
viewFrustum.sides[0].d = -1;
|
||||
// Right
|
||||
viewFrustum.sides[1].n = float3(-1, 0, 0);
|
||||
viewFrustum.sides[1].d = 1;
|
||||
// Top
|
||||
viewFrustum.sides[2].n = float3(0, -1, 0);
|
||||
viewFrustum.sides[2].d = 1;
|
||||
// Bottom
|
||||
viewFrustum.sides[1].n = float3(0, 1, 0);
|
||||
viewFrustum.sides[1].d = -1;
|
||||
// Base
|
||||
viewFrustum.basePlane.n = float3(0, 0, 1);
|
||||
viewFrustum.basePlane.d = 0;
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
MeshData mesh = scene.meshData[groupID];
|
||||
for(uint i = threadID; i < MAX_MESHLETS_PER_MESH; i += TASK_GROUP_SIZE)
|
||||
{
|
||||
uint m = mesh.meshletOffset + min(mesh.numMeshlets, i);
|
||||
MeshletDescription meshlet = scene.meshlets.meshletInfos[m];
|
||||
//if(meshlet.boundingBox.insideFrustum(localToClip, viewFrustum))
|
||||
{
|
||||
uint index;
|
||||
InterlockedAdd(head, 1, index);
|
||||
p.meshletId[index] = m;
|
||||
p.instanceId[index] = groupID;
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
DispatchMesh(head, 1, 1, p);
|
||||
}
|
||||
|
||||
groupshared StaticMeshVertexAttributes gs_vertices[MAX_VERTICES];
|
||||
groupshared uint3 gs_indices[MAX_PRIMITIVES];
|
||||
groupshared uint gs_numVertices;
|
||||
groupshared uint gs_numPrimitives;
|
||||
|
||||
struct PrimitiveAttributes
|
||||
{
|
||||
uint cull: SV_CullPrimitive;
|
||||
};
|
||||
|
||||
[numthreads(MESH_GROUP_SIZE, 1, 1)]
|
||||
[outputtopology("triangle")]
|
||||
[shader("mesh")]
|
||||
void meshMain(
|
||||
in uint threadID: SV_GroupIndex,
|
||||
in uint groupID: SV_GroupID,
|
||||
in payload MeshPayload meshPayload,
|
||||
out Vertices<StaticMeshVertexAttributes, MAX_VERTICES> vertices,
|
||||
out Indices<uint3, MAX_PRIMITIVES> indices
|
||||
){
|
||||
InstanceData inst = scene.instances[meshPayload.instanceId[groupID]];
|
||||
MeshletDescription m = meshlets.meshletInfos[meshPayload.meshletId[groupID]];
|
||||
const uint vertexLoops = (MAX_VERTICES + MESH_GROUP_SIZE - 1) / MESH_GROUP_SIZE;
|
||||
for(uint loop = 0; loop < vertexLoops; ++loop)
|
||||
{
|
||||
uint v = threadID + loop * MESH_GROUP_SIZE;
|
||||
v = min(v, m.vertexCount - 1);
|
||||
InterlockedMax(gs_numVertices, v + 1);
|
||||
{
|
||||
int vertexIndex = meshlets.vertexIndices[m.vertexOffset + v];
|
||||
gs_vertices[v] = vertexData.getAttributes(vertexIndex, inst);
|
||||
}
|
||||
}
|
||||
|
||||
const uint primitiveLoops = (MAX_PRIMITIVES + MESH_GROUP_SIZE - 1) / MESH_GROUP_SIZE;
|
||||
for(uint loop = 0; loop < primitiveLoops; ++loop)
|
||||
{
|
||||
uint p = threadID + loop * MESH_GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
InterlockedMax(gs_numPrimitives, p + 1);
|
||||
{
|
||||
uint8_t local_idx0 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||
uint8_t local_idx1 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||
uint8_t local_idx2 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||
uint32_t idx0 = meshlets.vertexIndices[m.vertexOffset + local_idx0];
|
||||
uint32_t idx1 = meshlets.vertexIndices[m.vertexOffset + local_idx1];
|
||||
uint32_t idx2 = meshlets.vertexIndices[m.vertexOffset + local_idx2];
|
||||
gs_indices[p * 3 + 0] = idx0;
|
||||
gs_indices[p * 3 + 1] = idx1;
|
||||
gs_indices[p * 3 + 2] = idx2;
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
SetMeshOutputCounts(gs_numVertices, gs_numPrimitives);
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
uint v = threadID;
|
||||
v = min(v, m.vertexCount - 1);
|
||||
vertices[v] = gs_vertices[v];
|
||||
if(vertexLoops >= 1)
|
||||
{
|
||||
uint v = threadID + MESH_GROUP_SIZE;
|
||||
v = min(v, m.vertexCount - 1);
|
||||
vertices[v] = gs_vertices[v];
|
||||
}
|
||||
|
||||
uint p = threadID;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
indices[p] = gs_indices[p];
|
||||
|
||||
if(primitiveLoops >= 1)
|
||||
{
|
||||
uint p = threadID + MESH_GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
indices[p] = gs_indices[p];
|
||||
}
|
||||
if(primitiveLoops >= 2)
|
||||
{
|
||||
uint p = threadID + 2 * MESH_GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
indices[p] = gs_indices[p];
|
||||
}
|
||||
if(primitiveLoops >= 3)
|
||||
{
|
||||
uint p = threadID + 3 * MESH_GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
indices[p] = gs_indices[p];
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
import Common;
|
||||
import BRDF;
|
||||
import Meshlet;
|
||||
import Scene;
|
||||
import VertexData;
|
||||
import StaticMeshVertexData;
|
||||
|
||||
layout(push_constant)
|
||||
ConstantBuffer<uint> meshId;
|
||||
|
||||
struct MeshShaderPayload
|
||||
{
|
||||
uint instanceId;
|
||||
uint meshletId;
|
||||
};
|
||||
|
||||
struct PrimitiveAttributes
|
||||
{
|
||||
uint cull: SV_CullPrimitive;
|
||||
};
|
||||
|
||||
groupshared StaticMeshVertexAttributes gs_vertices[MAX_VERTICES];
|
||||
groupshared uint3 gs_indices[MAX_PRIMITIVES];
|
||||
groupshared uint gs_numVertices;
|
||||
groupshared uint gs_numPrimitives;
|
||||
|
||||
[numthreads(GROUP_SIZE, 1, 1)]
|
||||
[shader("amplification")]
|
||||
void taskMain(
|
||||
uint3 threadID: SV_GroupIndex,
|
||||
uint3 groupID: SV_GroupID
|
||||
){
|
||||
|
||||
}
|
||||
|
||||
[numthreads(GROUP_SIZE, 1, 1)]
|
||||
[outputtopology("triangle")]
|
||||
[shader("mesh")]
|
||||
void meshMain(
|
||||
uint3 threadID: SV_GroupIndex,
|
||||
uint3 groupID: SV_GroupID,
|
||||
out Vertices<StaticMeshVertexAttributes, MAX_VERTICES> vertices,
|
||||
out Indices<uint3, MAX_PRIMITIVES> indices
|
||||
){
|
||||
MeshShaderPayload p;
|
||||
InstanceData inst = scene.instances[p.instanceId];
|
||||
MeshletDescription m = meshlets.meshletInfos[p.meshletId];
|
||||
const uint vertexLoops = (MAX_VERTICES + GROUP_SIZE - 1) / GROUP_SIZE;
|
||||
for(uint loop = 0; loop < vertexLoops; ++loop)
|
||||
{
|
||||
uint v = threadID.x + loop * GROUP_SIZE;
|
||||
v = min(v, m.vertexCount - 1);
|
||||
InterlockedMax(gs_numVertices, v + 1);
|
||||
{
|
||||
int vertexIndex = meshlets.vertexIndices[m.vertexOffset + v];
|
||||
gs_vertices[v] = vertexData.getAttributes(vertexIndex, inst);
|
||||
}
|
||||
}
|
||||
|
||||
const uint primitiveLoops = (MAX_PRIMITIVES + GROUP_SIZE - 1) / GROUP_SIZE;
|
||||
for(uint loop = 0; loop < primitiveLoops; ++loop)
|
||||
{
|
||||
uint p = threadID.x + loop * GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
InterlockedMax(gs_numPrimitives, p + 1);
|
||||
{
|
||||
uint8_t local_idx0 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||
uint8_t local_idx1 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||
uint8_t local_idx2 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||
uint32_t idx0 = meshlets.vertexIndices[m.vertexOffset + local_idx0];
|
||||
uint32_t idx1 = meshlets.vertexIndices[m.vertexOffset + local_idx1];
|
||||
uint32_t idx2 = meshlets.vertexIndices[m.vertexOffset + local_idx2];
|
||||
gs_indices[p * 3 + 0] = idx0;
|
||||
gs_indices[p * 3 + 1] = idx1;
|
||||
gs_indices[p * 3 + 2] = idx2;
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
SetMeshOutputCounts(gs_numVertices, gs_numPrimitives);
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
for(uint loop = 0; loop < vertexLoops; ++loop)
|
||||
{
|
||||
uint v = threadID.x + loop * GROUP_SIZE;
|
||||
v = min(v, m.vertexCount - 1);
|
||||
vertices[v] = gs_vertices[v];
|
||||
}
|
||||
for(uint loop = 0; loop < primitiveLoops; ++loop)
|
||||
{
|
||||
uint p = threadID.x + loop * GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
indices[p] = gs_indices[p];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import Common;
|
||||
|
||||
struct AABB
|
||||
{
|
||||
float3 min;
|
||||
float3 max;
|
||||
bool insideFrustum(float4x4 transform, Frustum frustum)
|
||||
{
|
||||
float3 corners[8];
|
||||
corners[0] = mul(transform, float4(min.x, min.y, min.z, 1.0f)).xyz;
|
||||
corners[1] = mul(transform, float4(min.x, min.y, max.z, 1.0f)).xyz;
|
||||
corners[2] = mul(transform, float4(min.x, max.y, min.z, 1.0f)).xyz;
|
||||
corners[3] = mul(transform, float4(min.x, max.y, max.z, 1.0f)).xyz;
|
||||
corners[4] = mul(transform, float4(max.x, min.y, min.z, 1.0f)).xyz;
|
||||
corners[5] = mul(transform, float4(max.x, min.y, max.z, 1.0f)).xyz;
|
||||
corners[6] = mul(transform, float4(max.x, max.y, min.z, 1.0f)).xyz;
|
||||
corners[7] = mul(transform, float4(max.x, max.y, max.z, 1.0f)).xyz;
|
||||
for(int i = 0; i < 8; ++i)
|
||||
{
|
||||
if(frustum.pointInside(corners[i]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -9,7 +9,7 @@ struct ViewParameter
|
||||
float4 cameraPos_WS;
|
||||
float2 screenDimensions;
|
||||
}
|
||||
//layout(set = INDEX_VIEW_PARAMS, binding = 0, std430)
|
||||
layout(set = INDEX_VIEW_PARAMS)
|
||||
ParameterBlock<ViewParameter> viewParams;
|
||||
|
||||
|
||||
@@ -31,7 +31,24 @@ struct Plane
|
||||
|
||||
struct Frustum
|
||||
{
|
||||
Plane planes[4];
|
||||
Plane sides[4];
|
||||
Plane basePlane;
|
||||
bool pointInside(float3 point)
|
||||
{
|
||||
if (dot(basePlane.n, point) + basePlane.d < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for(int p = 0; p < 4; ++p)
|
||||
{
|
||||
float result = dot(sides[p].n, point) + sides[p].d;
|
||||
if(result < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Plane computePlane(float3 p0, float3 p1, float3 p2)
|
||||
{
|
||||
|
||||
@@ -8,4 +8,5 @@ interface IMaterial
|
||||
|
||||
};
|
||||
|
||||
layout(set = INDEX_MATERIAL)
|
||||
ParameterBlock<IMaterial> gMaterial;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import AABB;
|
||||
|
||||
struct MeshletDescription
|
||||
{
|
||||
AABB boundingBox;
|
||||
uint32_t vertexCount;
|
||||
uint32_t primitiveCount;
|
||||
uint32_t vertexOffset;
|
||||
@@ -14,8 +17,30 @@ struct MeshletData
|
||||
StructuredBuffer<uint32_t> vertexIndices;
|
||||
};
|
||||
|
||||
struct MeshData
|
||||
{
|
||||
uint numMeshlets;
|
||||
uint meshletOffset;
|
||||
};
|
||||
|
||||
static const uint MAX_VERTICES = 64;
|
||||
static const uint MAX_PRIMITIVES = 126;
|
||||
static const uint GROUP_SIZE = 32;
|
||||
static const uint TASK_GROUP_SIZE = 128;
|
||||
static const uint MESH_GROUP_SIZE = 32;
|
||||
static const uint MAX_MESHLETS_PER_MESH = 512;
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 transformMatrix;
|
||||
};
|
||||
|
||||
struct Scene
|
||||
{
|
||||
StructuredBuffer<InstanceData> instances;
|
||||
StructuredBuffer<MeshData> meshData;
|
||||
StructuredBuffer<MeshletData> meshlets;
|
||||
};
|
||||
|
||||
layout(set = INDEX_SCENE_DATA)
|
||||
ParameterBlock<Scene> scene;
|
||||
|
||||
ParameterBlock<MeshletData> meshlets;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 transformMatrix;
|
||||
};
|
||||
|
||||
struct MeshData
|
||||
{
|
||||
uint numMeshlets;
|
||||
uint meshletOffset;
|
||||
uint numInstances;
|
||||
uint instanceOffset;
|
||||
};
|
||||
|
||||
struct Scene
|
||||
{
|
||||
StructuredBuffer<InstanceData> instances;
|
||||
StructuredBuffer<MeshData> meshData;
|
||||
};
|
||||
|
||||
ParameterBlock<Scene> scene;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import VertexData;
|
||||
import Common;
|
||||
import Scene;
|
||||
|
||||
struct SkinnedMeshVertexAttributes : VertexAttributes
|
||||
{
|
||||
float4 clipPosition: SV_Position;
|
||||
float3 worldPosition: POSITION0;
|
||||
float2 texCoords: TEXCOORD0;
|
||||
float3 normal: NORMAL0;
|
||||
float3 tangent: TANGENT0;
|
||||
float3 biTangent: BITANGENT0;
|
||||
float3 getWorldPosition()
|
||||
{
|
||||
return worldPosition;
|
||||
}
|
||||
float2 getTexCoords()
|
||||
{
|
||||
return texCoords;
|
||||
}
|
||||
float3 getNormal()
|
||||
{
|
||||
return normal;
|
||||
}
|
||||
float3 getTangent()
|
||||
{
|
||||
return tangent;
|
||||
}
|
||||
float3 getBiTangent()
|
||||
{
|
||||
return biTangent;
|
||||
}
|
||||
}
|
||||
|
||||
struct SkinnedMeshVertexData : VertexData
|
||||
{
|
||||
SkinnedMeshVertexAttributes getAttributes(uint index, float4x4 transform)
|
||||
{
|
||||
StaticMeshVertexAttributes attr;
|
||||
float4x4 boneTransform = float4x4(1.0f);
|
||||
for(int i = 0; i < 4; ++i)
|
||||
{
|
||||
boneTransform += bones[boneIndices[i]] * boneWeights[i];
|
||||
}
|
||||
float4 localPos = mul(boneTransform, float4(positions[index], 1));
|
||||
float4 worldPos = mul(transform, localPos);
|
||||
float4 viewPos = mul(viewParams.viewMatrix, worldPos);
|
||||
float4 clipPos = mul(viewParams.projectionMatrix, viewPos);
|
||||
attr.clipPosition = clipPos;
|
||||
attr.worldPosition = worldPos.xyz;
|
||||
attr.texCoords = texCoords[index];
|
||||
attr.normal = normals[index];
|
||||
attr.tangent = tangents[index];
|
||||
attr.biTangent = biTangents[index];
|
||||
return attr;
|
||||
}
|
||||
StructuredBuffer<float3> positions;
|
||||
StructuredBuffer<float2> texCoords;
|
||||
StructuredBuffer<float3> normals;
|
||||
StructuredBuffer<float3> tangents;
|
||||
StructuredBuffer<float3> biTangents;
|
||||
StructuredBuffer<int4> boneIndices;
|
||||
StructuredBuffer<float4> boneWeights;
|
||||
StructuredBuffer<float4x4> bones;
|
||||
}
|
||||
layout(set = INDEX_VERTEX_DATA)
|
||||
ParameterBlock<SkinnedMeshVertexData> vertexData;
|
||||
@@ -34,11 +34,11 @@ struct StaticMeshVertexAttributes : VertexAttributes
|
||||
|
||||
struct StaticMeshVertexData : VertexData
|
||||
{
|
||||
StaticMeshVertexAttributes getAttributes(uint index, InstanceData inst)
|
||||
StaticMeshVertexAttributes getAttributes(uint index, float4x4 transform)
|
||||
{
|
||||
StaticMeshVertexAttributes attr;
|
||||
float4 localPos = float4(positions[index], 1);
|
||||
float4 worldPos = mul(inst.transformMatrix, localPos);
|
||||
float4 worldPos = mul(transform, localPos);
|
||||
float4 viewPos = mul(viewParams.viewMatrix, worldPos);
|
||||
float4 clipPos = mul(viewParams.projectionMatrix, viewPos);
|
||||
attr.clipPosition = clipPos;
|
||||
@@ -55,4 +55,5 @@ struct StaticMeshVertexData : VertexData
|
||||
StructuredBuffer<float3> tangents;
|
||||
StructuredBuffer<float3> biTangents;
|
||||
}
|
||||
layout(set = INDEX_VERTEX_DATA)
|
||||
ParameterBlock<StaticMeshVertexData> vertexData;
|
||||
@@ -11,5 +11,5 @@ interface VertexAttributes
|
||||
|
||||
interface VertexData
|
||||
{
|
||||
VertexAttributes getAttributes(uint index, InstanceData inst);
|
||||
VertexAttributes getAttributes(uint index, float4x4 transform);
|
||||
};
|
||||
+218
-96
@@ -1,22 +1,23 @@
|
||||
#pragma pack_matrix(column_major)
|
||||
#ifdef SLANG_HLSL_ENABLE_NVAPI
|
||||
#include "nvHLSLExtns.h"
|
||||
#endif
|
||||
#pragma warning(disable: 3557)
|
||||
#version 450
|
||||
#extension GL_EXT_mesh_shader : require
|
||||
#extension GL_EXT_shader_8bit_storage : require
|
||||
#extension GL_EXT_shader_explicit_arithmetic_types : require
|
||||
layout(row_major) uniform;
|
||||
layout(row_major) buffer;
|
||||
|
||||
|
||||
#line 1 "lib/Scene.slang"
|
||||
#line 1 0
|
||||
struct InstanceData_0
|
||||
{
|
||||
matrix<float,int(4),int(4)> transformMatrix_0;
|
||||
mat4x4 transformMatrix_0;
|
||||
};
|
||||
|
||||
|
||||
#line 45 "test.slang"
|
||||
StructuredBuffer<InstanceData_0 > scene_instances_0 : register(t0, space3);
|
||||
#line 45 1
|
||||
layout(std430, binding = 0, set = 2) readonly buffer StructuredBuffer_InstanceData_t_0 {
|
||||
InstanceData_0 _data[];
|
||||
} scene_instances_0;
|
||||
|
||||
|
||||
#line 1 "lib/Meshlet.slang"
|
||||
#line 1 2
|
||||
struct MeshletDescription_0
|
||||
{
|
||||
uint vertexCount_0;
|
||||
@@ -26,130 +27,197 @@ struct MeshletDescription_0
|
||||
};
|
||||
|
||||
|
||||
#line 46 "test.slang"
|
||||
StructuredBuffer<MeshletDescription_0 > meshlets_meshletInfos_0 : register(t0, space2);
|
||||
|
||||
|
||||
#line 9 "lib/Meshlet.slang"
|
||||
StructuredBuffer<uint8_t > meshlets_primitiveIndices_0 : register(t1, space2);
|
||||
#line 46 1
|
||||
layout(std430, binding = 0, set = 1) readonly buffer StructuredBuffer_MeshletDescription_t_0 {
|
||||
MeshletDescription_0 _data[];
|
||||
} meshlets_meshletInfos_0;
|
||||
|
||||
#line 9 2
|
||||
layout(std430, binding = 1, set = 1) readonly buffer StructuredBuffer_uint8_t_0 {
|
||||
uint8_t _data[];
|
||||
} meshlets_primitiveIndices_0;
|
||||
|
||||
#line 9
|
||||
StructuredBuffer<uint > meshlets_vertexIndices_0 : register(t2, space2);
|
||||
|
||||
|
||||
#line 35 "lib/StaticMeshVertexData.slang"
|
||||
StructuredBuffer<float3 > vertexData_positions_0 : register(t0, space4);
|
||||
layout(std430, binding = 2, set = 1) readonly buffer StructuredBuffer_uint_t_0 {
|
||||
uint _data[];
|
||||
} meshlets_vertexIndices_0;
|
||||
|
||||
#line 35 3
|
||||
layout(std430, binding = 0, set = 3) readonly buffer StructuredBuffer_float3_t_0 {
|
||||
vec3 _data[];
|
||||
} vertexData_positions_0;
|
||||
|
||||
#line 35
|
||||
StructuredBuffer<float2 > vertexData_texCoords_0 : register(t1, space4);
|
||||
|
||||
layout(std430, binding = 1, set = 3) readonly buffer StructuredBuffer_float2_t_0 {
|
||||
vec2 _data[];
|
||||
} vertexData_texCoords_0;
|
||||
|
||||
#line 35
|
||||
StructuredBuffer<float3 > vertexData_normals_0 : register(t2, space4);
|
||||
|
||||
layout(std430, binding = 2, set = 3) readonly buffer StructuredBuffer_float3_t_1 {
|
||||
vec3 _data[];
|
||||
} vertexData_normals_0;
|
||||
|
||||
#line 35
|
||||
StructuredBuffer<float3 > vertexData_tangents_0 : register(t3, space4);
|
||||
|
||||
layout(std430, binding = 3, set = 3) readonly buffer StructuredBuffer_float3_t_2 {
|
||||
vec3 _data[];
|
||||
} vertexData_tangents_0;
|
||||
|
||||
#line 35
|
||||
StructuredBuffer<float3 > vertexData_biTangents_0 : register(t4, space4);
|
||||
layout(std430, binding = 4, set = 3) readonly buffer StructuredBuffer_float3_t_3 {
|
||||
vec3 _data[];
|
||||
} vertexData_biTangents_0;
|
||||
|
||||
|
||||
#line 5 "lib/Common.slang"
|
||||
#line 5 4
|
||||
struct ViewParameter_0
|
||||
{
|
||||
matrix<float,int(4),int(4)> viewMatrix_0;
|
||||
matrix<float,int(4),int(4)> projectionMatrix_0;
|
||||
float4 cameraPos_WS_0;
|
||||
float2 screenDimensions_0;
|
||||
mat4x4 viewMatrix_0;
|
||||
mat4x4 projectionMatrix_0;
|
||||
vec4 cameraPos_WS_0;
|
||||
vec2 screenDimensions_0;
|
||||
};
|
||||
|
||||
cbuffer viewParams_0 : register(b0, space1)
|
||||
layout(binding = 0)
|
||||
layout(std140) uniform _S1
|
||||
{
|
||||
ViewParameter_0 viewParams_0;
|
||||
}
|
||||
mat4x4 viewMatrix_0;
|
||||
mat4x4 projectionMatrix_0;
|
||||
vec4 cameraPos_WS_0;
|
||||
vec2 screenDimensions_0;
|
||||
}viewParams_0;
|
||||
|
||||
#line 24 "test.slang"
|
||||
static groupshared uint gs_numVertices_0;
|
||||
#line 1267 5
|
||||
out gl_MeshPerVertexEXT
|
||||
{
|
||||
vec4 gl_Position;
|
||||
} gl_MeshVerticesEXT[64];
|
||||
|
||||
|
||||
#line 5 "lib/StaticMeshVertexData.slang"
|
||||
#line 24 1
|
||||
shared uint gs_numVertices_0;
|
||||
|
||||
|
||||
#line 5 3
|
||||
struct StaticMeshVertexAttributes_0
|
||||
{
|
||||
float4 clipPosition_0 : SV_Position;
|
||||
float3 worldPosition_0 : POSITION0;
|
||||
float2 texCoords_0 : TEXCOORD0;
|
||||
float3 normal_0 : NORMAL0;
|
||||
float3 tangent_0 : TANGENT0;
|
||||
float3 biTangent_0 : BITANGENT0;
|
||||
vec4 clipPosition_0;
|
||||
vec3 worldPosition_0;
|
||||
vec2 texCoords_0;
|
||||
vec3 normal_0;
|
||||
vec3 tangent_0;
|
||||
vec3 biTangent_0;
|
||||
};
|
||||
|
||||
|
||||
#line 22 "test.slang"
|
||||
static groupshared StaticMeshVertexAttributes_0 gs_vertices_0[int(64)];
|
||||
#line 22 1
|
||||
shared StaticMeshVertexAttributes_0 gs_vertices_0[64];
|
||||
|
||||
|
||||
#line 37 "lib/StaticMeshVertexData.slang"
|
||||
StaticMeshVertexAttributes_0 StaticMeshVertexData_getAttributes_0(StructuredBuffer<float3 > this_positions_0, StructuredBuffer<float2 > this_texCoords_0, StructuredBuffer<float3 > this_normals_0, StructuredBuffer<float3 > this_tangents_0, StructuredBuffer<float3 > this_biTangents_0, uint index_0, InstanceData_0 inst_0)
|
||||
shared uint gs_numPrimitives_0;
|
||||
|
||||
|
||||
#line 23
|
||||
shared uvec3 gs_indices_0[126];
|
||||
|
||||
|
||||
#line 7910 6
|
||||
layout(location = 0)
|
||||
out vec3 _S2[64];
|
||||
|
||||
|
||||
#line 7910
|
||||
layout(location = 1)
|
||||
out vec2 _S3[64];
|
||||
|
||||
|
||||
#line 7910
|
||||
layout(location = 2)
|
||||
out vec3 _S4[64];
|
||||
|
||||
|
||||
#line 7910
|
||||
layout(location = 3)
|
||||
out vec3 _S5[64];
|
||||
|
||||
|
||||
#line 7910
|
||||
layout(location = 4)
|
||||
out vec3 _S6[64];
|
||||
|
||||
|
||||
#line 7910
|
||||
out uvec3 gl_PrimitiveTriangleIndicesEXT[126];
|
||||
|
||||
|
||||
#line 900 7
|
||||
StaticMeshVertexAttributes_0 StaticMeshVertexData_getAttributes_0(uint _S7, InstanceData_0 _S8)
|
||||
{
|
||||
|
||||
|
||||
float4 worldPos_0 = mul(inst_0.transformMatrix_0, float4(this_positions_0.Load(index_0), 1.0));
|
||||
#line 41 3
|
||||
vec4 worldPos_0 = (((vec4(vertexData_positions_0._data[_S7], 1.0)) * (_S8.transformMatrix_0)));
|
||||
|
||||
#line 39
|
||||
StaticMeshVertexAttributes_0 attr_0;
|
||||
|
||||
#line 44
|
||||
attr_0.clipPosition_0 = mul(viewParams_0.projectionMatrix_0, mul(viewParams_0.viewMatrix_0, worldPos_0));
|
||||
attr_0.clipPosition_0 = ((((((worldPos_0) * (viewParams_0.viewMatrix_0)))) * (viewParams_0.projectionMatrix_0)));
|
||||
attr_0.worldPosition_0 = worldPos_0.xyz;
|
||||
attr_0.texCoords_0 = this_texCoords_0.Load(index_0);
|
||||
attr_0.normal_0 = this_normals_0.Load(index_0);
|
||||
attr_0.tangent_0 = this_tangents_0.Load(index_0);
|
||||
attr_0.biTangent_0 = this_biTangents_0.Load(index_0);
|
||||
attr_0.texCoords_0 = vertexData_texCoords_0._data[_S7];
|
||||
attr_0.normal_0 = vertexData_normals_0._data[_S7];
|
||||
attr_0.tangent_0 = vertexData_tangents_0._data[_S7];
|
||||
attr_0.biTangent_0 = vertexData_biTangents_0._data[_S7];
|
||||
return attr_0;
|
||||
}
|
||||
|
||||
|
||||
#line 25 "test.slang"
|
||||
static groupshared uint gs_numPrimitives_0;
|
||||
|
||||
|
||||
#line 23
|
||||
static groupshared uint3 gs_indices_0[int(126)];
|
||||
|
||||
|
||||
#line 39
|
||||
[shader("mesh")][numthreads(32, 1, 1)]
|
||||
[outputtopology("triangle")]
|
||||
void meshMain(uint threadID_0 : SV_GROUPINDEX, uint3 groupID_0 : SV_GROUPID, vertices out StaticMeshVertexAttributes_0 vertices_0[int(64)], indices out uint3 indices_0[int(126)])
|
||||
#line 39 1
|
||||
layout(local_size_x = 32, local_size_y = 1, local_size_z = 1) in;
|
||||
layout(max_vertices = 64) out;
|
||||
layout(max_primitives = 126) out;
|
||||
layout(triangles) out;
|
||||
void main()
|
||||
{
|
||||
|
||||
|
||||
InstanceData_0 _S1 = scene_instances_0.Load(threadID_0);
|
||||
MeshletDescription_0 _S2 = meshlets_meshletInfos_0.Load(groupID_0.x);
|
||||
InstanceData_0 _S9 = scene_instances_0._data[gl_LocalInvocationIndex];
|
||||
MeshletDescription_0 m_0 = meshlets_meshletInfos_0._data[gl_WorkGroupID.x];
|
||||
|
||||
#line 51
|
||||
uint _S3 = _S2.vertexCount_0 - 1U;
|
||||
uint _S10 = m_0.vertexCount_0 - 1U;
|
||||
|
||||
#line 63
|
||||
uint _S4 = _S2.primitiveCount_0 - 1U;
|
||||
uint _S11 = m_0.primitiveCount_0 - 1U;
|
||||
|
||||
#line 63
|
||||
#line 82
|
||||
uint v_0 = min(gl_LocalInvocationIndex, _S10);
|
||||
|
||||
|
||||
|
||||
uint v_1 = gl_LocalInvocationIndex + 32U;
|
||||
uint v_2 = min(v_1, _S10);
|
||||
|
||||
#line 92
|
||||
uint p_0 = min(gl_LocalInvocationIndex, _S11);
|
||||
|
||||
#line 98
|
||||
uint p_1 = min(v_1, _S11);
|
||||
|
||||
#line 104
|
||||
uint p_2 = min(gl_LocalInvocationIndex + 64U, _S11);
|
||||
|
||||
#line 110
|
||||
uint p_3 = min(gl_LocalInvocationIndex + 96U, _S11);
|
||||
|
||||
#line 110
|
||||
uint loop_0 = 0U;
|
||||
|
||||
#line 63
|
||||
#line 110
|
||||
for(;;)
|
||||
{
|
||||
|
||||
#line 51
|
||||
uint v_0 = min(threadID_0 + loop_0 * 32U, _S3);
|
||||
InterlockedMax(gs_numVertices_0, v_0 + 1U);
|
||||
uint v_3 = min(gl_LocalInvocationIndex + loop_0 * 32U, _S10);
|
||||
atomicMax((gs_numVertices_0), (v_3 + 1U));
|
||||
|
||||
|
||||
gs_vertices_0[v_0] = StaticMeshVertexData_getAttributes_0(vertexData_positions_0, vertexData_texCoords_0, vertexData_normals_0, vertexData_tangents_0, vertexData_biTangents_0, uint(int(meshlets_vertexIndices_0.Load(_S2.vertexOffset_0 + v_0))), _S1);
|
||||
gs_vertices_0[v_3] = StaticMeshVertexData_getAttributes_0(uint(int(meshlets_vertexIndices_0._data[m_0.vertexOffset_0 + v_3])), _S9);
|
||||
|
||||
#line 48
|
||||
uint loop_1 = loop_0 + 1U;
|
||||
@@ -179,21 +247,21 @@ void meshMain(uint threadID_0 : SV_GROUPINDEX, uint3 groupID_0 : SV_GROUPID, ver
|
||||
{
|
||||
|
||||
#line 63
|
||||
uint p_0 = min(threadID_0 + loop_0 * 32U, _S4);
|
||||
InterlockedMax(gs_numPrimitives_0, p_0 + 1U);
|
||||
uint p_4 = min(gl_LocalInvocationIndex + loop_0 * 32U, _S11);
|
||||
atomicMax((gs_numPrimitives_0), (p_4 + 1U));
|
||||
|
||||
uint _S5 = p_0 * 3U;
|
||||
uint _S12 = p_4 * 3U;
|
||||
|
||||
#line 66
|
||||
uint _S6 = _S2.primitiveOffset_0 + _S5;
|
||||
uint _S13 = m_0.primitiveOffset_0 + _S12;
|
||||
|
||||
|
||||
|
||||
uint idx1_0 = meshlets_vertexIndices_0.Load(_S2.vertexOffset_0 + uint(meshlets_primitiveIndices_0.Load(_S6 + 1U)));
|
||||
uint idx2_0 = meshlets_vertexIndices_0.Load(_S2.vertexOffset_0 + uint(meshlets_primitiveIndices_0.Load(_S6 + 2U)));
|
||||
gs_indices_0[_S5] = (uint3)meshlets_vertexIndices_0.Load(_S2.vertexOffset_0 + uint(meshlets_primitiveIndices_0.Load(_S6)));
|
||||
gs_indices_0[_S5 + 1U] = (uint3)idx1_0;
|
||||
gs_indices_0[_S5 + 2U] = (uint3)idx2_0;
|
||||
uint idx1_0 = meshlets_vertexIndices_0._data[m_0.vertexOffset_0 + uint(meshlets_primitiveIndices_0._data[_S13 + 1U])];
|
||||
uint idx2_0 = meshlets_vertexIndices_0._data[m_0.vertexOffset_0 + uint(meshlets_primitiveIndices_0._data[_S13 + 2U])];
|
||||
gs_indices_0[_S12] = uvec3(meshlets_vertexIndices_0._data[m_0.vertexOffset_0 + uint(meshlets_primitiveIndices_0._data[_S13])]);
|
||||
gs_indices_0[_S12 + 1U] = uvec3(idx1_0);
|
||||
gs_indices_0[_S12 + 2U] = uvec3(idx2_0);
|
||||
|
||||
#line 60
|
||||
uint loop_2 = loop_0 + 1U;
|
||||
@@ -216,11 +284,65 @@ void meshMain(uint threadID_0 : SV_GROUPINDEX, uint3 groupID_0 : SV_GROUPID, ver
|
||||
}
|
||||
|
||||
#line 77
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
SetMeshOutputCounts(gs_numVertices_0, gs_numPrimitives_0);
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
vertices_0[threadID_0] = gs_vertices_0[threadID_0];
|
||||
indices_0[threadID_0] = gs_indices_0[threadID_0];
|
||||
barrier();
|
||||
SetMeshOutputsEXT(gs_numVertices_0, gs_numPrimitives_0);
|
||||
barrier();
|
||||
|
||||
|
||||
|
||||
StaticMeshVertexAttributes_0 _S14 = gs_vertices_0[v_0];
|
||||
|
||||
#line 83
|
||||
gl_MeshVerticesEXT[v_0].gl_Position = gs_vertices_0[v_0].clipPosition_0;
|
||||
|
||||
#line 83
|
||||
_S2[v_0] = _S14.worldPosition_0;
|
||||
|
||||
#line 83
|
||||
_S3[v_0] = _S14.texCoords_0;
|
||||
|
||||
#line 83
|
||||
_S4[v_0] = _S14.normal_0;
|
||||
|
||||
#line 83
|
||||
_S5[v_0] = _S14.tangent_0;
|
||||
|
||||
#line 83
|
||||
_S6[v_0] = _S14.biTangent_0;
|
||||
|
||||
#line 88
|
||||
StaticMeshVertexAttributes_0 _S15 = gs_vertices_0[v_2];
|
||||
|
||||
#line 88
|
||||
gl_MeshVerticesEXT[v_2].gl_Position = gs_vertices_0[v_2].clipPosition_0;
|
||||
|
||||
#line 88
|
||||
_S2[v_2] = _S15.worldPosition_0;
|
||||
|
||||
#line 88
|
||||
_S3[v_2] = _S15.texCoords_0;
|
||||
|
||||
#line 88
|
||||
_S4[v_2] = _S15.normal_0;
|
||||
|
||||
#line 88
|
||||
_S5[v_2] = _S15.tangent_0;
|
||||
|
||||
#line 88
|
||||
_S6[v_2] = _S15.biTangent_0;
|
||||
|
||||
#line 93
|
||||
gl_PrimitiveTriangleIndicesEXT[p_0] = gs_indices_0[p_0];
|
||||
|
||||
#line 99
|
||||
gl_PrimitiveTriangleIndicesEXT[p_1] = gs_indices_0[p_1];
|
||||
|
||||
#line 105
|
||||
gl_PrimitiveTriangleIndicesEXT[p_2] = gs_indices_0[p_2];
|
||||
|
||||
#line 111
|
||||
gl_PrimitiveTriangleIndicesEXT[p_3] = gs_indices_0[p_3];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+47
-74
@@ -1,90 +1,63 @@
|
||||
import Common;
|
||||
import BRDF;
|
||||
import Meshlet;
|
||||
import Scene;
|
||||
import VertexData;
|
||||
import StaticMeshVertexData;
|
||||
|
||||
layout(push_constant)
|
||||
ConstantBuffer<uint> meshId;
|
||||
|
||||
struct MeshShaderPayload
|
||||
struct MeshPayload
|
||||
{
|
||||
uint instanceId;
|
||||
uint meshletId;
|
||||
int exponent;
|
||||
};
|
||||
|
||||
struct PrimitiveAttributes
|
||||
{
|
||||
uint cull: SV_CullPrimitive;
|
||||
};
|
||||
groupshared MeshPayload payload;
|
||||
|
||||
groupshared StaticMeshVertexAttributes gs_vertices[MAX_VERTICES];
|
||||
groupshared uint3 gs_indices[MAX_PRIMITIVES];
|
||||
groupshared uint gs_numVertices;
|
||||
groupshared uint gs_numPrimitives;
|
||||
|
||||
[numthreads(GROUP_SIZE, 1, 1)]
|
||||
[shader("amplification")]
|
||||
[numthreads(1, 1, 1)]
|
||||
[outputtopology("triangle")]
|
||||
void taskMain(
|
||||
uint3 threadID: SV_GroupIndex,
|
||||
uint3 groupID: SV_GroupID
|
||||
){
|
||||
|
||||
DispatchMesh(1,1,1,payload);
|
||||
}
|
||||
|
||||
[numthreads(GROUP_SIZE, 1, 1)]
|
||||
|
||||
|
||||
const static float2 positions[3] = {
|
||||
float2(0.0, -0.5),
|
||||
float2(0.5, 0.5),
|
||||
float2(-0.5, 0.5)
|
||||
};
|
||||
|
||||
const static float3 colors[3] = {
|
||||
float3(1.0, 1.0, 0.0),
|
||||
float3(0.0, 1.0, 1.0),
|
||||
float3(1.0, 0.0, 1.0)
|
||||
};
|
||||
struct Vertex
|
||||
{
|
||||
float4 pos : SV_Position;
|
||||
float3 color : Color;
|
||||
int index : Index;
|
||||
int value : Value;
|
||||
};
|
||||
|
||||
const static uint MAX_VERTS = 12;
|
||||
const static uint MAX_PRIMS = 4;
|
||||
|
||||
[outputtopology("triangle")]
|
||||
[shader("mesh")]
|
||||
[numthreads(12, 1, 1)]
|
||||
void meshMain(
|
||||
uint threadID: SV_GroupIndex,
|
||||
uint3 groupID: SV_GroupID,
|
||||
out Vertices<StaticMeshVertexAttributes, MAX_VERTICES> vertices,
|
||||
out Indices<uint3, MAX_PRIMITIVES> indices
|
||||
){
|
||||
InstanceData inst = scene.instances[threadID];
|
||||
MeshletDescription m = meshlets.meshletInfos[groupID.x];
|
||||
const uint vertexLoops = (MAX_VERTICES + GROUP_SIZE - 1) / GROUP_SIZE;
|
||||
for(uint loop = 0; loop < vertexLoops; ++loop)
|
||||
{
|
||||
uint v = threadID + loop * GROUP_SIZE;
|
||||
v = min(v, m.vertexCount - 1);
|
||||
InterlockedMax(gs_numVertices, v + 1);
|
||||
{
|
||||
int vertexIndex = meshlets.vertexIndices[m.vertexOffset + v];
|
||||
gs_vertices[v] = vertexData.getAttributes(vertexIndex, inst);
|
||||
}
|
||||
}
|
||||
in uint tig : SV_GroupIndex,
|
||||
in payload MeshPayload meshPayload,
|
||||
out Vertices<Vertex, MAX_VERTS> verts,
|
||||
out Indices<uint3, MAX_PRIMS> triangles)
|
||||
{
|
||||
const uint numVertices = 12;
|
||||
const uint numPrimitives = 4;
|
||||
SetMeshOutputCounts(numVertices, numPrimitives);
|
||||
|
||||
const uint primitiveLoops = (MAX_PRIMITIVES + GROUP_SIZE - 1) / GROUP_SIZE;
|
||||
for(uint loop = 0; loop < primitiveLoops; ++loop)
|
||||
{
|
||||
uint p = threadID + loop * GROUP_SIZE;
|
||||
p = min(p, m.primitiveCount - 1);
|
||||
InterlockedMax(gs_numPrimitives, p + 1);
|
||||
{
|
||||
uint8_t local_idx0 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||
uint8_t local_idx1 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||
uint8_t local_idx2 = meshlets.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||
uint32_t idx0 = meshlets.vertexIndices[m.vertexOffset + local_idx0];
|
||||
uint32_t idx1 = meshlets.vertexIndices[m.vertexOffset + local_idx1];
|
||||
uint32_t idx2 = meshlets.vertexIndices[m.vertexOffset + local_idx2];
|
||||
gs_indices[p * 3 + 0] = idx0;
|
||||
gs_indices[p * 3 + 1] = idx1;
|
||||
gs_indices[p * 3 + 2] = idx2;
|
||||
}
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
SetMeshOutputCounts(gs_numVertices, gs_numPrimitives);
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
for(uint loop1 = 0; loop1 < vertexLoops; ++loop1)
|
||||
{
|
||||
uint v = threadID + loop1 * GROUP_SIZE;
|
||||
vertices[v] = gs_vertices[v];
|
||||
}
|
||||
for(uint loop2 = 0; loop2 < primitiveLoops; ++loop2)
|
||||
{
|
||||
uint p = threadID + loop2 * GROUP_SIZE;
|
||||
indices[p] = gs_indices[p];
|
||||
}
|
||||
if(tig < numVertices)
|
||||
{
|
||||
const int tri = tig / 3;
|
||||
verts[tig] = {float4(positions[tig % 3], 0, 1), colors[tig % 3], tri, int(pow(tri, meshPayload.exponent))};
|
||||
}
|
||||
|
||||
if(tig < numPrimitives)
|
||||
triangles[tig] = tig * 3 + uint3(0,1,2);
|
||||
}
|
||||
Reference in New Issue
Block a user