Slang shaders for buffer device address example
This commit is contained in:
parent
bc3c41e89a
commit
880b48485f
3 changed files with 68 additions and 1 deletions
20
shaders/slang/bufferdeviceaddress/cube.frag.slang
Normal file
20
shaders/slang/bufferdeviceaddress/cube.frag.slang
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
[[vk::binding(0, 0)]]
|
||||||
|
Sampler2D samplerColorMap;
|
||||||
|
|
||||||
|
struct VSInput
|
||||||
|
{
|
||||||
|
[[vk::location(1)]] float3 Color;
|
||||||
|
[[vk::location(2)]] float2 UV;
|
||||||
|
};
|
||||||
|
|
||||||
|
[shader("fragment")]
|
||||||
|
float4 main(VSInput input)
|
||||||
|
{
|
||||||
|
return samplerColorMap.Sample(input.UV) * float4(input.Color, 1.0);
|
||||||
|
}
|
||||||
47
shaders/slang/bufferdeviceaddress/cube.vert.slang
Normal file
47
shaders/slang/bufferdeviceaddress/cube.vert.slang
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* Copyright (c) 2025, Sascha Willems
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct VSInput
|
||||||
|
{
|
||||||
|
[[vk::location(0)]] float3 Pos;
|
||||||
|
[[vk::location(1)]] float3 Normal;
|
||||||
|
[[vk::location(2)]] float2 UV;
|
||||||
|
[[vk::location(3)]] float3 Color;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MatrixReference {
|
||||||
|
float4x4 matrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PushConsts {
|
||||||
|
// Pointer to the buffer with the scene's MVP matrix
|
||||||
|
ConstBufferPointer<MatrixReference> sceneDataReference;
|
||||||
|
// Pointer to the buffer for the data for each model
|
||||||
|
ConstBufferPointer<MatrixReference> modelDataReference;
|
||||||
|
};
|
||||||
|
[[vk::push_constant]] PushConsts pushConstants;
|
||||||
|
|
||||||
|
struct VSOutput
|
||||||
|
{
|
||||||
|
float4 Pos : SV_POSITION;
|
||||||
|
[[vk::location(0)]] float3 Normal;
|
||||||
|
[[vk::location(1)]] float3 Color;
|
||||||
|
[[vk::location(2)]] float2 UV;
|
||||||
|
};
|
||||||
|
|
||||||
|
[shader("vertex")]
|
||||||
|
VSOutput main(VSInput input)
|
||||||
|
{
|
||||||
|
MatrixReference sceneData = pushConstants.sceneDataReference.get();
|
||||||
|
MatrixReference modelData = pushConstants.modelDataReference.get();
|
||||||
|
|
||||||
|
VSOutput output;
|
||||||
|
output.Normal = input.Normal;
|
||||||
|
output.Color = input.Color;
|
||||||
|
output.UV = input.UV;
|
||||||
|
output.Pos = mul(sceneData.matrix, mul(modelData.matrix, float4(input.Pos.xyz, 1.0)));
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
@ -41,6 +41,6 @@ for root, dirs, files in os.walk(dir_path):
|
||||||
input_file = os.path.join(root, file)
|
input_file = os.path.join(root, file)
|
||||||
output_file = input_file + ".spv"
|
output_file = input_file + ".spv"
|
||||||
output_file = output_file.replace(".slang", "")
|
output_file = output_file.replace(".slang", "")
|
||||||
res = subprocess.call("%s %s -profile spirv_1_4 -target spirv -o %s -entry %s" % (compiler_path, input_file, output_file, "main"), shell=True)
|
res = subprocess.call("%s %s -profile spirv_1_4 -matrix-layout-column-major -target spirv -o %s -entry %s" % (compiler_path, input_file, output_file, "main"), shell=True)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
sys.exit(res)
|
sys.exit(res)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue