-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from Themaister/mdi-poc-bringup
Sketch out MDI/Meshlet bindless path.
- Loading branch information
Showing
15 changed files
with
423 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#version 450 | ||
|
||
layout(local_size_x = 32) in; | ||
|
||
struct AABB | ||
{ | ||
vec4 lo, hi; | ||
}; | ||
|
||
layout(set = 0, binding = 0, std430) readonly buffer AABBSSBO | ||
{ | ||
AABB data[]; | ||
} aabb; | ||
|
||
layout(set = 0, binding = 1, std430) readonly buffer Transforms | ||
{ | ||
mat4 data[]; | ||
} transforms; | ||
|
||
layout(set = 0, binding = 2, std430) readonly buffer Tasks | ||
{ | ||
uvec4 data[]; | ||
} task_info; | ||
|
||
struct Draw | ||
{ | ||
uint payload[5]; | ||
}; | ||
|
||
layout(set = 0, binding = 3, std430) readonly buffer InputDraws | ||
{ | ||
Draw data[]; | ||
} input_draws; | ||
|
||
layout(set = 0, binding = 4, std430) writeonly buffer OutputDraws | ||
{ | ||
uint count; | ||
uint padding[256 / 4 - 1]; | ||
Draw data[]; | ||
} output_draws; | ||
|
||
layout(set = 0, binding = 5, std430) writeonly buffer CompactedDraws | ||
{ | ||
uvec2 data[]; | ||
} output_draw_info; | ||
|
||
layout(push_constant, std430) uniform Registers | ||
{ | ||
uint count; | ||
} registers; | ||
|
||
void main() | ||
{ | ||
uvec4 command_payload; | ||
uint task_index = gl_GlobalInvocationID.x; | ||
if (task_index < registers.count) | ||
{ | ||
command_payload = task_info.data[task_index]; | ||
uint offset = command_payload.w & ~31u; | ||
uint count = bitfieldExtract(command_payload.w, 0, 5) + 1; | ||
|
||
uint draw_offset = atomicAdd(output_draws.count, count); | ||
for (uint i = 0; i < count; i++) | ||
{ | ||
output_draws.data[draw_offset + i] = input_draws.data[offset + i]; | ||
output_draw_info.data[draw_offset + i] = command_payload.yz; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
#version 450 | ||
#extension GL_EXT_nonuniform_qualifier : require | ||
|
||
layout(location = 0) in mediump vec3 vNormal; | ||
layout(location = 1) in mediump vec4 vTangent; | ||
layout(location = 2) in vec2 vUV; | ||
layout(location = 3) flat in uint MaterialOffset; | ||
|
||
layout(location = 0) out vec4 FragColor; | ||
layout(location = 0) out vec3 FragColor; | ||
|
||
layout(set = 0, binding = 2) uniform sampler DefaultSampler; | ||
layout(set = 2, binding = 0) uniform texture2D Textures[]; | ||
|
||
void main() | ||
{ | ||
FragColor = vec4(vNormal.xyz * 0.5 + 0.5, 1.0); | ||
vec3 color = texture(sampler2D(Textures[MaterialOffset], DefaultSampler), vUV).rgb; | ||
FragColor = color * (0.01 + clamp(dot(vNormal.xyz, vec3(5, 2, 20)), 0.0, 1.0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
#version 450 | ||
#extension GL_EXT_mesh_shader : require | ||
#extension GL_EXT_nonuniform_qualifier : require | ||
|
||
layout(location = 0) perprimitiveEXT in flat uint vMeshletIndex; | ||
layout(location = 1) in mediump vec3 vNormal; | ||
layout(location = 2) in mediump vec4 vTangent; | ||
layout(location = 3) in vec2 vUV; | ||
layout(location = 0) in mediump vec3 vNormal; | ||
layout(location = 1) in mediump vec4 vTangent; | ||
layout(location = 2) in vec2 vUV; | ||
layout(location = 3) perprimitiveEXT flat in uint MaterialOffset; | ||
|
||
layout(location = 0) out vec4 FragColor; | ||
layout(location = 0) out vec3 FragColor; | ||
|
||
vec3 decode_mesh_color() | ||
{ | ||
uint index = vMeshletIndex * 1991u; | ||
index ^= (index >> 5u); | ||
uint r = bitfieldExtract(index, 0, 2); | ||
uint g = bitfieldExtract(index, 2, 2); | ||
uint b = bitfieldExtract(index, 4, 2); | ||
//return (vec3(r, g, b) + 1.0 / 3.0) / 4.0; | ||
return vec3(1.0); | ||
} | ||
layout(set = 0, binding = 6) uniform sampler DefaultSampler; | ||
layout(set = 2, binding = 0) uniform texture2D Textures[]; | ||
|
||
void main() | ||
{ | ||
FragColor = vec4(decode_mesh_color() * (vNormal.xyz * 0.5 + 0.5), 1.0); | ||
vec3 color = texture(nonuniformEXT(sampler2D(Textures[MaterialOffset], DefaultSampler)), vUV).rgb; | ||
FragColor = color * (0.01 + clamp(dot(vNormal.xyz, vec3(5, 2, 20)), 0.0, 1.0)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#version 450 | ||
#extension GL_EXT_mesh_shader : require | ||
#extension GL_KHR_shader_subgroup_arithmetic : require | ||
#extension GL_KHR_shader_subgroup_ballot : require | ||
layout(local_size_x = 32) in; | ||
|
||
struct TaskInfo | ||
{ | ||
uint aabb_instance; | ||
uint node_instance; | ||
uint node_count_material_index; // Skinning | ||
uint mesh_index_count; | ||
}; | ||
|
||
layout(set = 0, binding = 2, std430) readonly buffer Tasks | ||
{ | ||
TaskInfo data[]; | ||
} task_info; | ||
|
||
layout(push_constant, std430) uniform Registers | ||
{ | ||
uint count; | ||
} registers; | ||
|
||
struct MeshTask | ||
{ | ||
uint meshlet_index; | ||
uint node_instance; | ||
uint node_count_material_index; | ||
}; | ||
|
||
struct Payload | ||
{ | ||
MeshTask meshlet[1024]; | ||
}; | ||
|
||
taskPayloadSharedEXT Payload payload; | ||
|
||
void main() | ||
{ | ||
TaskInfo command_payload; | ||
uint task_index = gl_GlobalInvocationID.x; | ||
uint task_count = 0; | ||
|
||
if (task_index < registers.count) | ||
{ | ||
command_payload = task_info.data[task_index]; | ||
uint mesh_offset = command_payload.mesh_index_count & ~31u; | ||
uint mesh_count = bitfieldExtract(command_payload.mesh_index_count, 0, 5) + 1; | ||
|
||
uint task_offset = subgroupExclusiveAdd(mesh_count); | ||
task_count = subgroupAdd(mesh_count); | ||
|
||
for (uint i = 0; i < mesh_count; i++) | ||
{ | ||
MeshTask meshlet; | ||
meshlet.meshlet_index = mesh_offset + i; | ||
meshlet.node_instance = command_payload.node_instance; | ||
meshlet.node_count_material_index = command_payload.node_count_material_index; | ||
payload.meshlet[task_offset + i] = meshlet; | ||
} | ||
} | ||
|
||
EmitMeshTasksEXT(task_count, 1, 1); | ||
} |
Oops, something went wrong.