it works now???
This commit is contained in:
@@ -9,6 +9,6 @@ FragmentParameter vertexMain(
|
|||||||
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);
|
||||||
return attr.getParameter(inst.transformMatrix);
|
return attr.getParameter(inst.transformMatrix);
|
||||||
}
|
}
|
||||||
@@ -64,21 +64,11 @@ void taskMain(
|
|||||||
DispatchMesh(head, 1, 1, p);
|
DispatchMesh(head, 1, 1, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
groupshared VertexAttributes gs_vertices[MAX_VERTICES];
|
|
||||||
groupshared uint3 gs_indices[MAX_PRIMITIVES];
|
|
||||||
groupshared uint gs_numVertices;
|
|
||||||
groupshared uint gs_numPrimitives;
|
|
||||||
|
|
||||||
struct PrimitiveAttributes
|
struct PrimitiveAttributes
|
||||||
{
|
{
|
||||||
uint cull: SV_CullPrimitive;
|
uint cull: SV_CullPrimitive;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MeshOutput
|
|
||||||
{
|
|
||||||
FragmentParameter parameter;
|
|
||||||
};
|
|
||||||
|
|
||||||
[numthreads(MESH_GROUP_SIZE, 1, 1)]
|
[numthreads(MESH_GROUP_SIZE, 1, 1)]
|
||||||
[outputtopology("triangle")]
|
[outputtopology("triangle")]
|
||||||
[shader("mesh")]
|
[shader("mesh")]
|
||||||
@@ -86,73 +76,50 @@ void meshMain(
|
|||||||
in uint threadID: SV_GroupIndex,
|
in uint threadID: SV_GroupIndex,
|
||||||
in uint groupID: SV_GroupID,
|
in uint groupID: SV_GroupID,
|
||||||
in payload MeshPayload meshPayload,
|
in payload MeshPayload meshPayload,
|
||||||
out Vertices<MeshOutput, MAX_VERTICES> vertices,
|
out Vertices<FragmentParameter, MAX_VERTICES> vertices,
|
||||||
out Indices<uint3, MAX_PRIMITIVES> indices
|
out Indices<uint3, MAX_PRIMITIVES> indices
|
||||||
){
|
){
|
||||||
InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]];
|
InstanceData inst = pScene.instances[meshPayload.instanceId[groupID]];
|
||||||
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;
|
SetMeshOutputCounts(m.vertexCount, m.primitiveCount);
|
||||||
for(uint i = threadID; i < MAX_VERTICES; i += MESH_GROUP_SIZE)
|
|
||||||
|
uint p = min(threadID, m.primitiveCount - 1);
|
||||||
|
{
|
||||||
|
uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||||
|
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||||
|
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||||
|
indices[p] = uint3(local_idx0, local_idx1, local_idx2);
|
||||||
|
}
|
||||||
|
p = min(threadID + 32, m.primitiveCount - 1);
|
||||||
|
{
|
||||||
|
uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||||
|
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||||
|
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||||
|
indices[p] = uint3(local_idx0, local_idx1, local_idx2);
|
||||||
|
}
|
||||||
|
p = min(threadID + 64, m.primitiveCount - 1);
|
||||||
|
{
|
||||||
|
uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||||
|
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||||
|
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||||
|
indices[p] = uint3(local_idx0, local_idx1, local_idx2);
|
||||||
|
}
|
||||||
|
p = min(threadID + 96, m.primitiveCount - 1);
|
||||||
|
{
|
||||||
|
uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||||
|
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||||
|
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||||
|
indices[p] = uint3(local_idx0, local_idx1, local_idx2);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupMemoryBarrierWithGroupSync();
|
||||||
|
for(uint i = threadID; i < MAX_VERTICES; i+=MESH_GROUP_SIZE)
|
||||||
{
|
{
|
||||||
uint v = min(i, m.vertexCount - 1);
|
uint v = min(i, m.vertexCount - 1);
|
||||||
InterlockedMax(gs_numVertices, v + 1);
|
|
||||||
{
|
{
|
||||||
int vertexIndex = pScene.vertexIndices[m.vertexOffset + v];
|
int vertexIndex = pScene.vertexIndices[m.vertexOffset + v];
|
||||||
gs_vertices[v] = pVertexData.getAttributes(md.indicesOffset + vertexIndex, inst.transformMatrix);
|
vertices[v] = pVertexData.getAttributes(md.indicesOffset + vertexIndex).getParameter(inst.transformMatrix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GroupMemoryBarrierWithGroupSync();
|
|
||||||
const uint primitiveLoops = (MAX_PRIMITIVES + MESH_GROUP_SIZE - 1) / MESH_GROUP_SIZE;
|
|
||||||
for(uint i = threadID; i < MAX_PRIMITIVES; i += MESH_GROUP_SIZE)
|
|
||||||
{
|
|
||||||
uint p = min(i, m.primitiveCount - 1);
|
|
||||||
InterlockedMax(gs_numPrimitives, p + 1);
|
|
||||||
{
|
|
||||||
uint32_t local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
|
||||||
uint32_t local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
|
||||||
uint32_t local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
|
||||||
gs_indices[p].x = local_idx0;
|
|
||||||
gs_indices[p].y = local_idx1;
|
|
||||||
gs_indices[p].z = local_idx2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GroupMemoryBarrierWithGroupSync();
|
|
||||||
SetMeshOutputCounts(gs_numVertices, gs_numPrimitives);
|
|
||||||
GroupMemoryBarrierWithGroupSync();
|
|
||||||
|
|
||||||
uint v = threadID;
|
|
||||||
v = min(v, m.vertexCount - 1);
|
|
||||||
FragmentParameter parameter = gs_vertices[v].getParameter(inst.transformMatrix);
|
|
||||||
vertices[v].parameter = parameter;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint p = threadID;
|
|
||||||
p = min(p, m.primitiveCount - 1);
|
|
||||||
indices[p] = gs_indices[p];
|
|
||||||
|
|
||||||
if(primitiveLoops >= 1)
|
|
||||||
{
|
|
||||||
p += MESH_GROUP_SIZE;
|
|
||||||
p = min(p, m.primitiveCount - 1);
|
|
||||||
indices[p] = gs_indices[p];
|
|
||||||
}
|
|
||||||
if(primitiveLoops >= 2)
|
|
||||||
{
|
|
||||||
p += MESH_GROUP_SIZE;
|
|
||||||
p = min(p, m.primitiveCount - 1);
|
|
||||||
indices[p] = gs_indices[p];
|
|
||||||
}
|
|
||||||
if(primitiveLoops >= 3)
|
|
||||||
{
|
|
||||||
p += MESH_GROUP_SIZE;
|
|
||||||
p = min(p, m.primitiveCount - 1);
|
|
||||||
indices[p] = gs_indices[p];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -51,28 +51,31 @@ struct FragmentParameter
|
|||||||
// data retrieved from VertexData
|
// data retrieved from VertexData
|
||||||
struct VertexAttributes
|
struct VertexAttributes
|
||||||
{
|
{
|
||||||
|
float3 position_MS;
|
||||||
float3 normal_MS;
|
float3 normal_MS;
|
||||||
float3 tangent_MS;
|
float3 tangent_MS;
|
||||||
float3 biTangent_MS;
|
float3 biTangent_MS;
|
||||||
float3 position_WS;
|
|
||||||
float4 position_CS;
|
|
||||||
float2 texCoords;
|
float2 texCoords;
|
||||||
float3 vertexColor;
|
float3 vertexColor;
|
||||||
FragmentParameter getParameter(float4x4 transformMatrix)
|
FragmentParameter getParameter(float4x4 transformMatrix)
|
||||||
{
|
{
|
||||||
|
float4 modelPos = float4(position_MS, 1);
|
||||||
|
float4 worldPos = mul(transformMatrix, modelPos);
|
||||||
|
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
|
||||||
|
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
|
||||||
float3 tangent_WS = mul(transformMatrix, float4(normalize(tangent_MS), 0)).xyz;
|
float3 tangent_WS = mul(transformMatrix, float4(normalize(tangent_MS), 0)).xyz;
|
||||||
float3 biTangent_WS = mul(transformMatrix, float4(normalize(biTangent_MS), 0)).xyz;
|
float3 biTangent_WS = mul(transformMatrix, float4(normalize(biTangent_MS), 0)).xyz;
|
||||||
float3 normal_WS = mul(transformMatrix, float4(normalize(normal_MS), 0)).xyz;
|
float3 normal_WS = mul(transformMatrix, float4(normalize(normal_MS), 0)).xyz;
|
||||||
// Transforms from world space into tangent space
|
// Transforms from world space into tangent space
|
||||||
float3x3 tbn = transpose(float3x3(tangent_WS, biTangent_WS, normal_WS));
|
float3x3 tbn = transpose(float3x3(tangent_WS, biTangent_WS, normal_WS));
|
||||||
FragmentParameter result;
|
FragmentParameter result;
|
||||||
result.position_TS = mul(tbn, position_WS);
|
result.position_TS = mul(tbn, worldPos.xyz);
|
||||||
result.viewDir_TS = mul(tbn, pViewParams.cameraPos_WS.xyz - position_WS);
|
result.viewDir_TS = mul(tbn, pViewParams.cameraPos_WS.xyz - worldPos.xyz);
|
||||||
result.normal_WS = normal_WS;
|
result.normal_WS = normal_WS;
|
||||||
result.tangent_WS = tangent_WS;
|
result.tangent_WS = tangent_WS;
|
||||||
result.biTangent_WS = biTangent_WS;
|
result.biTangent_WS = biTangent_WS;
|
||||||
result.position_WS = position_WS;
|
result.position_WS = worldPos.xyz;
|
||||||
result.position_CS = position_CS;
|
result.position_CS = clipPos;
|
||||||
result.texCoords = texCoords;
|
result.texCoords = texCoords;
|
||||||
result.vertexColor = vertexColor;
|
result.vertexColor = vertexColor;
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -4,18 +4,13 @@ import MaterialParameter;
|
|||||||
|
|
||||||
struct StaticMeshVertexData : IVertexData
|
struct StaticMeshVertexData : IVertexData
|
||||||
{
|
{
|
||||||
VertexAttributes getAttributes(uint index, float4x4 transform)
|
VertexAttributes getAttributes(uint index)
|
||||||
{
|
{
|
||||||
VertexAttributes attributes;
|
VertexAttributes attributes;
|
||||||
float4 modelPos = float4(positions[3 * index + 0], positions[3 * index + 1], positions[3 * index + 2], 1);
|
attributes.position_MS = float3(positions[3 * index + 0], positions[3 * index + 1], positions[3 * index + 2]);
|
||||||
float4 worldPos = mul(transform, modelPos);
|
|
||||||
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
|
|
||||||
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
|
|
||||||
attributes.normal_MS = float3(normals[3 * index + 0], normals[3 * index + 1], normals[3 * index + 2]);
|
attributes.normal_MS = float3(normals[3 * index + 0], normals[3 * index + 1], normals[3 * index + 2]);
|
||||||
attributes.tangent_MS = float3(tangents[3 * index + 0], tangents[3 * index + 1], tangents[3 * index + 2]);
|
attributes.tangent_MS = float3(tangents[3 * index + 0], tangents[3 * index + 1], tangents[3 * index + 2]);
|
||||||
attributes.biTangent_MS = float3(biTangents[3 * index + 0], biTangents[3 * index + 1], biTangents[3 * index + 2]);
|
attributes.biTangent_MS = float3(biTangents[3 * index + 0], biTangents[3 * index + 1], biTangents[3 * index + 2]);
|
||||||
attributes.position_WS = worldPos.xyz;
|
|
||||||
attributes.position_CS = clipPos;
|
|
||||||
attributes.texCoords = float2(texCoords[2 * index + 0], texCoords[2 * index + 1]);
|
attributes.texCoords = float2(texCoords[2 * index + 0], texCoords[2 * index + 1]);
|
||||||
attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]);
|
attributes.vertexColor = float3(color[3 * index + 0], color[3 * index + 1], color[3 * index + 2]);
|
||||||
return attributes;
|
return attributes;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import MaterialParameter;
|
|||||||
|
|
||||||
interface IVertexData
|
interface IVertexData
|
||||||
{
|
{
|
||||||
VertexAttributes getAttributes(uint index, float4x4 transform);
|
VertexAttributes getAttributes(uint index);
|
||||||
};
|
};
|
||||||
layout(set = 1)
|
layout(set = 1)
|
||||||
ParameterBlock<IVertexData> pVertexData;
|
ParameterBlock<IVertexData> pVertexData;
|
||||||
@@ -399,7 +399,7 @@ void Graphics::pickPhysicalDevice()
|
|||||||
{
|
{
|
||||||
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
if (std::strcmp(VK_EXT_MESH_SHADER_EXTENSION_NAME, extensionProps[i].extensionName) == 0)
|
||||||
{
|
{
|
||||||
//meshShadingEnabled = true;
|
meshShadingEnabled = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,8 +55,12 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
|||||||
slang::TargetDesc vulkan;
|
slang::TargetDesc vulkan;
|
||||||
vulkan.profile = globalSession->findProfile("sm_6_6");
|
vulkan.profile = globalSession->findProfile("sm_6_6");
|
||||||
vulkan.format = SLANG_SPIRV;
|
vulkan.format = SLANG_SPIRV;
|
||||||
sessionDesc.targetCount = 1;
|
slang::TargetDesc glsl;
|
||||||
sessionDesc.targets = &vulkan;
|
glsl.profile = globalSession->findProfile("sm_6_6");
|
||||||
|
glsl.format = SLANG_GLSL;
|
||||||
|
slang::TargetDesc targets[2] = { vulkan, glsl };
|
||||||
|
sessionDesc.targetCount = 2;
|
||||||
|
sessionDesc.targets = targets;
|
||||||
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
|
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
|
||||||
sessionDesc.searchPaths = searchPaths.data();
|
sessionDesc.searchPaths = searchPaths.data();
|
||||||
sessionDesc.searchPathCount = searchPaths.size();
|
sessionDesc.searchPathCount = searchPaths.size();
|
||||||
@@ -132,4 +136,15 @@ void Shader::create(const ShaderCreateInfo& createInfo)
|
|||||||
|
|
||||||
hash = CRC::Calculate(entryPointName.data(), entryPointName.size(), CRC::CRC_32());
|
hash = CRC::Calculate(entryPointName.data(), entryPointName.size(), CRC::CRC_32());
|
||||||
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash);
|
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash);
|
||||||
|
|
||||||
|
specializedComponent->getEntryPointCode(
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
kernelBlob.writeRef(),
|
||||||
|
diagnostics.writeRef()
|
||||||
|
);
|
||||||
|
CHECK_DIAGNOSTICS();
|
||||||
|
std::ofstream shaderStream(createInfo.name + createInfo.entryPoint + ".glsl");
|
||||||
|
shaderStream << (char*)kernelBlob->getBufferPointer();
|
||||||
|
shaderStream.close();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user