Add slang shader for mesh shader sample
This commit is contained in:
parent
5484d51bae
commit
33cab712ca
2 changed files with 82 additions and 0 deletions
|
|
@ -48,6 +48,10 @@ def getShaderStages(filename):
|
|||
stages.append("callable")
|
||||
if '[shader("compute")]' in filecontent:
|
||||
stages.append("compute")
|
||||
if '[shader("amplification")]' in filecontent:
|
||||
stages.append("amplification")
|
||||
if '[shader("mesh")]' in filecontent:
|
||||
stages.append("mesh")
|
||||
f.close()
|
||||
return stages
|
||||
|
||||
|
|
@ -58,6 +62,9 @@ print("Found slang compiler at %s", compiler_path)
|
|||
compile_single_sample = ""
|
||||
if args.sample != None:
|
||||
compile_single_sample = args.sample
|
||||
if (not os.path.isdir(compile_single_sample)):
|
||||
print("ERROR: No directory found with name %s" % compile_single_sample)
|
||||
exit(-1)
|
||||
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
dir_path = dir_path.replace('\\', '/')
|
||||
|
|
@ -91,6 +98,10 @@ for root, dirs, files in os.walk(dir_path):
|
|||
output_ext = ".rcall"
|
||||
case "compute":
|
||||
output_ext = ".comp"
|
||||
case "mesh":
|
||||
output_ext = ".mesh"
|
||||
case "amplification":
|
||||
output_ext = ".task"
|
||||
output_file = input_file + output_ext + ".spv"
|
||||
output_file = output_file.replace(".slang", "")
|
||||
res = subprocess.call("%s %s -profile spirv_1_4 -matrix-layout-column-major -target spirv -o %s -entry %s -stage %s -warnings-disable 39001" % (compiler_path, input_file, output_file, entry_point, stage), shell=True)
|
||||
|
|
|
|||
71
shaders/slang/meshshader/meshshader.slang
Normal file
71
shaders/slang/meshshader/meshshader.slang
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* Copyright (c) 2025, Sascha Willems
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
float4 position : SV_Position;
|
||||
float4 color;
|
||||
};
|
||||
|
||||
struct UBO
|
||||
{
|
||||
float4x4 projection;
|
||||
float4x4 model;
|
||||
float4x4 view;
|
||||
};
|
||||
ConstantBuffer<UBO> ubo;
|
||||
|
||||
static const float4 positions[3] = {
|
||||
float4( 0.0, -1.0, 0.0, 1.0),
|
||||
float4(-1.0, 1.0, 0.0, 1.0),
|
||||
float4( 1.0, 1.0, 0.0, 1.0)
|
||||
};
|
||||
|
||||
static const float4 colors[3] = {
|
||||
float4(0.0, 1.0, 0.0, 1.0),
|
||||
float4(0.0, 0.0, 1.0, 1.0),
|
||||
float4(1.0, 0.0, 0.0, 1.0)
|
||||
};
|
||||
|
||||
struct DummyPayLoad
|
||||
{
|
||||
uint dummyData;
|
||||
};
|
||||
|
||||
// We don't use pay loads in this sample, but the fn call requires one
|
||||
groupshared DummyPayLoad dummyPayLoad;
|
||||
|
||||
[shader("amplification")]
|
||||
[numthreads(1, 1, 1)]
|
||||
void amplificationMain()
|
||||
{
|
||||
DispatchMesh(3, 1, 1, dummyPayLoad);
|
||||
}
|
||||
|
||||
[shader("mesh")]
|
||||
[outputtopology("triangle")]
|
||||
[numthreads(1, 1, 1)]
|
||||
void meshMain(out indices uint3 triangles[1], out vertices VertexOutput vertices[3], uint3 DispatchThreadID : SV_DispatchThreadID)
|
||||
{
|
||||
float4x4 mvp = mul(ubo.projection, mul(ubo.view, ubo.model));
|
||||
|
||||
float4 offset = float4(0.0, 0.0, float(DispatchThreadID.x), 0.0);
|
||||
|
||||
SetMeshOutputCounts(3, 1);
|
||||
for (uint i = 0; i < 3; i++) {
|
||||
vertices[i].position = mul(mvp, positions[i] + offset);
|
||||
vertices[i].color = colors[i];
|
||||
}
|
||||
|
||||
SetMeshOutputCounts(3, 1);
|
||||
triangles[0] = uint3(0, 1, 2);
|
||||
}
|
||||
|
||||
[shader("fragment")]
|
||||
float4 fragmentMain(VertexOutput input)
|
||||
{
|
||||
return input.color;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue