Skip to content

Commit 05f8f6f

Browse files
committed
Snap piet-gpu-hal, add readme.
This snaps to the latest piet-gpu-hal, which fixes some bugs. Also make the buffer read-write (even though it's only readonly) to work around limitations in DX12 resource binding. Add a README.
1 parent 8650660 commit 05f8f6f

File tree

9 files changed

+49
-7
lines changed

9 files changed

+49
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The second subdirectory is a simple GUI application that runs a compute shader a
1818

1919
Recommended activity: find an existing shadertoy that implements some interesting algorithm or visual effect, and port it to run in a compute shader. Is there some limitation of the original that could be improved by compute capabilities?
2020

21+
A great place to find shaders to adapt is [The Book of Shaders].
22+
2123
## A note on the choice of runtime
2224

2325
Your compute shader code cannot run on its own, but rather needs a *runtime* to connect to the GPU, set up resources such as buffers and compiled shader code, and manage the submission of that work to the GPU. There is, as of this writing, no standard runtime for such things, but I hope that will change in time.
@@ -66,3 +68,4 @@ Licensed under either of
6668
[Cg]: https://www.khronos.org/opengl/wiki/Cg
6769
[rust-gpu]: https://github.com/EmbarkStudios/rust-gpu
6870
[IREE]: https://google.github.io/iree/
71+
[The Book of Shaders]: https://thebookofshaders.com/

piet-compute-toy/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

piet-compute-toy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ edition = "2018"
99

1010
[dependencies]
1111
winit = "0.25"
12-
piet-gpu-hal = { git = "https://github.com/linebender/piet-gpu", rev = "bae185" }
12+
piet-gpu-hal = { git = "https://github.com/linebender/piet-gpu", rev = "074fafa" }

piet-compute-toy/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Compute shader toy based on piet-gpu
2+
3+
To run it without changing the shaders, just do `cargo run`.
4+
5+
To change the shaders, you will need to recompile those. You need [ninja] and spirv tools (glslangValidator and spirv-cross) in your path. The easiest way to get those is to install the [Vulkan SDK]. Then, to recompile the shaders, do:
6+
7+
```shell
8+
(cd shader && ninja) && cargo run
9+
```
10+
11+
This version is based on piet-gpu-hal, which is the runtime for [piet-gpu]. It's still very new so there are limitations and things that don't work yet. If you run into something, please file an issue!
12+
13+
[Vulkan SDK]: https://www.lunarg.com/vulkan-sdk/
14+
[ninja]: https://ninja-build.org/
15+
[piet-gpu]: https://github.com/linebender/piet-gpu

piet-compute-toy/shader/build.ninja

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ rule glsl
99
command = $glslang_validator -V -o $out $in
1010

1111
rule hlsl
12-
command = $spirv_cross --hlsl $in --output $out
12+
command = $spirv_cross --hlsl --shader-model 50 $in --output $out
1313

1414
rule msl
1515
command = $spirv_cross --msl $in --output $out
1616

1717
build gen/shader.spv: glsl shader.comp
18-
# TODO: fix "Separate image and samplers not supported in legacy HLSL" error
19-
#build gen/shader.hlsl: hlsl gen/shader.spv
18+
build gen/shader.hlsl: hlsl gen/shader.spv
2019
build gen/shader.msl: msl gen/shader.spv
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
static const uint3 gl_WorkGroupSize = uint3(16u, 16u, 1u);
2+
3+
RWByteAddressBuffer _24 : register(u0);
4+
RWTexture2D<unorm float4> image : register(u1);
5+
6+
static uint3 gl_GlobalInvocationID;
7+
struct SPIRV_Cross_Input
8+
{
9+
uint3 gl_GlobalInvocationID : SV_DispatchThreadID;
10+
};
11+
12+
void comp_main()
13+
{
14+
uint2 xy = gl_GlobalInvocationID.xy;
15+
float2 fragCoord = (float2(gl_GlobalInvocationID.xy) / float2(float(_24.Load(0)), float(_24.Load(4)))) - 0.5f.xx;
16+
float4 fragColor = float4(fragCoord.x + 0.5f, fragCoord.y + 0.5f, 0.5f + (0.5f * sin(asfloat(_24.Load(8)))), 1.0f);
17+
image[int2(xy)] = fragColor;
18+
}
19+
20+
[numthreads(16, 16, 1)]
21+
void main(SPIRV_Cross_Input stage_input)
22+
{
23+
gl_GlobalInvocationID = stage_input.gl_GlobalInvocationID;
24+
comp_main();
25+
}

piet-compute-toy/shader/gen/shader.msl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct Params
1212

1313
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(16u, 16u, 1u);
1414

15-
kernel void main0(const device Params& _24 [[buffer(0)]], texture2d<float, access::write> image [[texture(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
15+
kernel void main0(device Params& _24 [[buffer(0)]], texture2d<float, access::write> image [[texture(0)]], uint3 gl_GlobalInvocationID [[thread_position_in_grid]])
1616
{
1717
uint2 xy = gl_GlobalInvocationID.xy;
1818
float2 fragCoord = (float2(gl_GlobalInvocationID.xy) / float2(float(_24.width), float(_24.height))) - float2(0.5);
-48 Bytes
Binary file not shown.

piet-compute-toy/shader/shader.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#version 450
2121
layout(local_size_x = 16, local_size_y = 16) in;
2222

23-
layout(set = 0, binding = 0) readonly restrict buffer Params {
23+
layout(set = 0, binding = 0) restrict buffer Params {
2424
uint width;
2525
uint height;
2626
float iTime;

0 commit comments

Comments
 (0)