diff --git a/external/slang b/external/slang index f94b2f7..4547125 160000 --- a/external/slang +++ b/external/slang @@ -1 +1 @@ -Subproject commit f94b2f7a328a898c5e3dc1389d08e0b7ce6e092e +Subproject commit 4547125ce945140dc10542e9606b225dd06159b8 diff --git a/res/shaders/StaticMeshBasePass.spirv b/res/shaders/StaticMeshBasePass.spirv index 000a04f..db4c9b0 100644 --- a/res/shaders/StaticMeshBasePass.spirv +++ b/res/shaders/StaticMeshBasePass.spirv @@ -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 transformMatrix_0; + mat4x4 transformMatrix_0; }; -#line 46 "./StaticMeshBasePass.slang" -StructuredBuffer scene_instances_0 : register(t0, space3); +#line 46 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,45 +27,55 @@ struct MeshletDescription_0 }; -#line 47 "./StaticMeshBasePass.slang" -StructuredBuffer meshlets_meshletInfos_0 : register(t0, space2); - - -#line 9 "lib/Meshlet.slang" -StructuredBuffer meshlets_primitiveIndices_0 : register(t1, space2); +#line 47 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 meshlets_vertexIndices_0 : register(t2, space2); - - -#line 24 "lib/StaticMeshVertexData.slang" -StructuredBuffer vertexData_positions_0 : register(t0, space4); +layout(std430, binding = 2, set = 1) readonly buffer StructuredBuffer_uint_t_0 { + uint _data[]; +} meshlets_vertexIndices_0; +#line 24 3 +layout(std430, binding = 0, set = 3) readonly buffer StructuredBuffer_float4_t_0 { + vec4 _data[]; +} vertexData_positions_0; #line 24 -StructuredBuffer vertexData_texCoords_0 : register(t1, space4); - +layout(std430, binding = 1, set = 3) readonly buffer StructuredBuffer_float2_t_0 { + vec2 _data[]; +} vertexData_texCoords_0; #line 24 -StructuredBuffer vertexData_normals_0 : register(t2, space4); +layout(std430, binding = 2, set = 3) readonly buffer StructuredBuffer_float3_t_0 { + vec3 _data[]; +} vertexData_normals_0; - -#line 5 "lib/Common.slang" +#line 5 4 struct ViewParameter_0 { - matrix viewMatrix_0; - matrix 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 "./StaticMeshBasePass.slang" +#line 24 1 uint gs_numVertices_0_init() { @@ -72,37 +83,22 @@ uint gs_numVertices_0_init() #line 24 return 0U; } -static groupshared uint gs_numVertices_0 = gs_numVertices_0_init(); +shared uint gs_numVertices_0 = gs_numVertices_0_init(); -#line 5 "lib/StaticMeshVertexData.slang" +#line 5 3 struct StaticMeshVertexAttributes_0 { - float4 position_0 : SV_Position; - float2 texCoords_0 : TEXCOORD0; - float3 normal_0 : NORMAL0; + vec4 position_0; + vec2 texCoords_0; + vec3 normal_0; }; -#line 22 "./StaticMeshBasePass.slang" -static groupshared StaticMeshVertexAttributes_0 gs_vertices_0[int(64)]; +#line 22 1 +shared StaticMeshVertexAttributes_0 gs_vertices_0[64]; -#line 26 "lib/StaticMeshVertexData.slang" -StaticMeshVertexAttributes_0 StaticMeshVertexData_getAttributes_0(StructuredBuffer this_positions_0, StructuredBuffer this_texCoords_0, StructuredBuffer this_normals_0, uint index_0, InstanceData_0 inst_0) -{ - StaticMeshVertexAttributes_0 attr_0; - - - - attr_0.position_0 = mul(viewParams_0.projectionMatrix_0, mul(viewParams_0.viewMatrix_0, mul(inst_0.transformMatrix_0, this_positions_0.Load(index_0)))); - attr_0.texCoords_0 = this_texCoords_0.Load(index_0); - attr_0.normal_0 = this_normals_0.Load(index_0); - return attr_0; -} - - -#line 25 "./StaticMeshBasePass.slang" uint gs_numPrimitives_0_init() { @@ -110,11 +106,11 @@ uint gs_numPrimitives_0_init() #line 25 return 0U; } -static groupshared uint gs_numPrimitives_0 = gs_numPrimitives_0_init(); +shared uint gs_numPrimitives_0 = gs_numPrimitives_0_init(); #line 23 -static groupshared uint3 gs_indices_0[int(126)]; +shared uvec3 gs_indices_0[126]; #line 11 @@ -125,26 +121,44 @@ struct MeshShaderPayload_0 }; -#line 39 -[shader("mesh")][numthreads(32, 1, 1)] -[outputtopology("triangle")] -void meshMain(uint3 threadID_0 : SV_GROUPINDEX, uint3 groupID_0 : SV_GROUPID, vertices vertices out StaticMeshVertexAttributes_0 vertices_0[int(64)], indices indices out uint3 indices_0[int(126)]) +#line 20 3 +StaticMeshVertexAttributes_0 StaticMeshVertexData_getAttributes_0(uint _S2, InstanceData_0 _S3) +{ + +#line 28 + StaticMeshVertexAttributes_0 attr_0; + + + + attr_0.position_0 = (((((((((vertexData_positions_0._data[_S2]) * (_S3.transformMatrix_0)))) * (viewParams_0.viewMatrix_0)))) * (viewParams_0.projectionMatrix_0))); + attr_0.texCoords_0 = vertexData_texCoords_0._data[_S2]; + attr_0.normal_0 = vertexData_normals_0._data[_S2]; + return attr_0; +} + + +#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() { #line 39 MeshShaderPayload_0 p_0; #line 46 - InstanceData_0 _S1 = scene_instances_0.Load(p_0.instanceId_0); - MeshletDescription_0 _S2 = meshlets_meshletInfos_0.Load(p_0.meshletId_0); + InstanceData_0 _S4 = scene_instances_0._data[p_0.instanceId_0]; + MeshletDescription_0 _S5 = meshlets_meshletInfos_0._data[p_0.meshletId_0]; - uint _S3 = threadID_0.x; - uint _S4 = _S2.vertexCount_0 - 1U; + uint _S6 = uvec3(gl_LocalInvocationIndex).x; + uint _S7 = _S5.vertexCount_0 - 1U; #line 64 - uint _S5 = _S2.primitiveCount_0 - 1U; + uint _S8 = _S5.primitiveCount_0 - 1U; #line 64 uint loop_0 = 0U; @@ -154,11 +168,11 @@ void meshMain(uint3 threadID_0 : SV_GROUPINDEX, uint3 groupID_0 : SV_GROUPID, ve { #line 52 - uint v_0 = min(_S3 + loop_0 * 32U, _S4); - InterlockedMax(gs_numVertices_0, v_0 + 1U); + uint v_0 = min(_S6 + loop_0 * 32U, _S7); + atomicMax((gs_numVertices_0), (v_0 + 1U)); - gs_vertices_0[v_0] = StaticMeshVertexData_getAttributes_0(vertexData_positions_0, vertexData_texCoords_0, vertexData_normals_0, uint(int(meshlets_vertexIndices_0.Load(_S2.vertexOffset_0 + v_0))), _S1); + gs_vertices_0[v_0] = StaticMeshVertexData_getAttributes_0(uint(int(meshlets_vertexIndices_0._data[_S5.vertexOffset_0 + v_0])), _S4); #line 49 uint loop_1 = loop_0 + 1U; @@ -188,21 +202,21 @@ void meshMain(uint3 threadID_0 : SV_GROUPINDEX, uint3 groupID_0 : SV_GROUPID, ve { #line 64 - uint p_1 = min(_S3 + loop_0 * 32U, _S5); - InterlockedMax(gs_numPrimitives_0, p_1 + 1U); + uint p_1 = min(_S6 + loop_0 * 32U, _S8); + atomicMax((gs_numPrimitives_0), (p_1 + 1U)); - uint _S6 = p_1 * 3U; + uint _S9 = p_1 * 3U; #line 67 - uint _S7 = _S2.primitiveOffset_0 + _S6; + uint _S10 = _S5.primitiveOffset_0 + _S9; - uint idx1_0 = meshlets_vertexIndices_0.Load(_S2.vertexOffset_0 + uint(meshlets_primitiveIndices_0.Load(_S7 + 1U))); - uint idx2_0 = meshlets_vertexIndices_0.Load(_S2.vertexOffset_0 + uint(meshlets_primitiveIndices_0.Load(_S7 + 2U))); - gs_indices_0[_S6] = (uint3)meshlets_vertexIndices_0.Load(_S2.vertexOffset_0 + uint(meshlets_primitiveIndices_0.Load(_S7))); - gs_indices_0[_S6 + 1U] = (uint3)idx1_0; - gs_indices_0[_S6 + 2U] = (uint3)idx2_0; + uint idx1_0 = meshlets_vertexIndices_0._data[_S5.vertexOffset_0 + uint(meshlets_primitiveIndices_0._data[_S10 + 1U])]; + uint idx2_0 = meshlets_vertexIndices_0._data[_S5.vertexOffset_0 + uint(meshlets_primitiveIndices_0._data[_S10 + 2U])]; + gs_indices_0[_S9] = uvec3(meshlets_vertexIndices_0._data[_S5.vertexOffset_0 + uint(meshlets_primitiveIndices_0._data[_S10])]); + gs_indices_0[_S9 + 1U] = uvec3(idx1_0); + gs_indices_0[_S9 + 2U] = uvec3(idx2_0); #line 61 uint loop_2 = loop_0 + 1U; @@ -225,9 +239,9 @@ void meshMain(uint3 threadID_0 : SV_GROUPINDEX, uint3 groupID_0 : SV_GROUPID, ve } #line 78 - GroupMemoryBarrierWithGroupSync(); - SetMeshOutputCounts(gs_numVertices_0, gs_numPrimitives_0); - GroupMemoryBarrierWithGroupSync(); + barrier(); + SetMeshOutputsEXT(gs_numVertices_0, gs_numPrimitives_0); + barrier(); #line 93 return; diff --git a/res/shaders/slang-glslang.dll b/res/shaders/slang-glslang.dll index 6fe2ce8..54cd2da 100644 Binary files a/res/shaders/slang-glslang.dll and b/res/shaders/slang-glslang.dll differ diff --git a/res/shaders/slang-llvm.dll b/res/shaders/slang-llvm.dll index 1ba54b9..ed17c5e 100644 Binary files a/res/shaders/slang-llvm.dll and b/res/shaders/slang-llvm.dll differ diff --git a/res/shaders/slang-stdlib.bin b/res/shaders/slang-stdlib.bin index 3e77e10..82f8b09 100644 Binary files a/res/shaders/slang-stdlib.bin and b/res/shaders/slang-stdlib.bin differ diff --git a/res/shaders/slang.dll b/res/shaders/slang.dll index a42910e..8a5cc7a 100644 Binary files a/res/shaders/slang.dll and b/res/shaders/slang.dll differ diff --git a/res/shaders/slangc.exe b/res/shaders/slangc.exe index 7a7f8c2..025824b 100755 Binary files a/res/shaders/slangc.exe and b/res/shaders/slangc.exe differ diff --git a/src/Engine/Graphics/IndexBufferTopologyData.cpp b/src/Engine/Graphics/IndexBufferTopologyData.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Engine/Graphics/IndexBufferTopologyData.h b/src/Engine/Graphics/IndexBufferTopologyData.h new file mode 100644 index 0000000..5212bc5 --- /dev/null +++ b/src/Engine/Graphics/IndexBufferTopologyData.h @@ -0,0 +1,12 @@ +#pragma once +#include "TopologyData.h" + +namespace Seele +{ +class IndexBufferTopologyData +{ +public: +private: + Gfx::PIndexBuffer indices; +}; +} // namespace Seele \ No newline at end of file diff --git a/src/Engine/Graphics/Mesh.h b/src/Engine/Graphics/Mesh.h index c298e99..9df58ff 100644 --- a/src/Engine/Graphics/Mesh.h +++ b/src/Engine/Graphics/Mesh.h @@ -4,14 +4,15 @@ namespace Seele { -DECLARE_REF(MeshletBuffer) +DECLARE_REF(TopologyData) +DECLARE_REF(VertexData) class Mesh { public: - Mesh(PMeshletBuffer meshlets); + Mesh(); ~Mesh(); - PMeshletBuffer meshlets; + PTopologyData meshlets; PVertexData vertexData; PMaterialAsset referencedMaterial; private: diff --git a/src/Engine/Graphics/MeshletTopologyData.cpp b/src/Engine/Graphics/MeshletTopologyData.cpp new file mode 100644 index 0000000..0aa7441 --- /dev/null +++ b/src/Engine/Graphics/MeshletTopologyData.cpp @@ -0,0 +1 @@ +#include "MeshletTopologyData.h" \ No newline at end of file diff --git a/src/Engine/Graphics/MeshletTopologyData.h b/src/Engine/Graphics/MeshletTopologyData.h new file mode 100644 index 0000000..8b3a79e --- /dev/null +++ b/src/Engine/Graphics/MeshletTopologyData.h @@ -0,0 +1,11 @@ +#pragma once +#include "TopologyData.h" + +namespace Seele +{ +class MeshletTopologyData : public TopologyData +{ +public: +private: +}; +} \ No newline at end of file diff --git a/src/Engine/Graphics/TopologyData.cpp b/src/Engine/Graphics/TopologyData.cpp new file mode 100644 index 0000000..4f0704d --- /dev/null +++ b/src/Engine/Graphics/TopologyData.cpp @@ -0,0 +1 @@ +#include "TopologyData.h" \ No newline at end of file diff --git a/src/Engine/Graphics/TopologyData.h b/src/Engine/Graphics/TopologyData.h new file mode 100644 index 0000000..8803ada --- /dev/null +++ b/src/Engine/Graphics/TopologyData.h @@ -0,0 +1,11 @@ +#pragma once +#include "GraphicsResources.h" + +namespace Seele +{ +class TopologyData +{ +public: +private: +}; +} // namespace Seele \ No newline at end of file