Skip to content

Commit

Permalink
namespace attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon7925 committed Dec 20, 2024
1 parent e5015cf commit 1dfd800
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
10 changes: 5 additions & 5 deletions demos/gsplat2d-diff.slang
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ static const float ADAM_EPSILON = 1e-8;
// initializing & binding these buffers.
//

[RAND(BLOB_BUFFER_SIZE)]
[playground::RAND(BLOB_BUFFER_SIZE)]
RWStructuredBuffer<float> blobsBuffer;

[ZEROS(BLOB_BUFFER_SIZE)]
[playground::ZEROS(BLOB_BUFFER_SIZE)]
RWStructuredBuffer<Atomic<uint>> derivBuffer;

[ZEROS(BLOB_BUFFER_SIZE)]
[playground::ZEROS(BLOB_BUFFER_SIZE)]
RWStructuredBuffer<float> adamFirstMoment;

[ZEROS(BLOB_BUFFER_SIZE)]
[playground::ZEROS(BLOB_BUFFER_SIZE)]
RWStructuredBuffer<float> adamSecondMoment;

[URL("static/jeep.jpg")]
[playground::URL("static/jeep.jpg")]
Texture2D<float4> targetTexture;

// ----- Shared memory declarations --------
Expand Down
2 changes: 1 addition & 1 deletion demos/gsplat2d.slang
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import playground;

[RAND(131072)]
[playground::RAND(131072)]
RWStructuredBuffer<float> randBuffer;

#define GAUSSIANS_PER_BLOCK 256
Expand Down
2 changes: 1 addition & 1 deletion demos/image-from-url.slang
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import playground;

[URL("static/jeep.jpg")]
[playground::URL("static/jeep.jpg")]
Texture2D<float4> myImage;

float4 imageMain(uint2 dispatchThreadID, int2 screenSize)
Expand Down
2 changes: 1 addition & 1 deletion demos/multiple-kernels.slang
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import playground;

[RAND(131072)]
[playground::RAND(131072)]
RWStructuredBuffer<float> buf;

// Fills buffer with a sine wave
Expand Down
2 changes: 1 addition & 1 deletion image_demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const imageDemoCode =
`
import playground;
[URL("static/jeep.jpg")]
[playground::URL("static/jeep.jpg")]
Texture2D<float4> myImage;
float4 imageMain(uint2 dispatchThreadID, int2 screenSize)
{
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ <h4>Shader Commands</h4>
<p>
WebGPU shaders in browser can use certain commands to specify how they will run.

<li><code>[ZEROS(512)]</code></li>
<li><code>[playground::ZEROS(512)]</code></li>
Initialize a float buffer with zeros of the provided size.
<li><code>[BLACK(512, 512)]</code></li>
<li><code>[playground::BLACK(512, 512)]</code></li>
Initialize a float texture with zeros of the provided size.
<li><code>[URL("https://example.com/image.png")]</code></li>
<li><code>[playground::URL("https://example.com/image.png")]</code></li>
Initialize a texture with image from URL.
<li><code>[RAND(1000)]</code></li>
<li><code>[playground::RAND(1000)]</code></li>
Initialize a float buffer with uniform random floats between 0 and 1.
<li><code>//! CALL(fn-name, SIZE_OF(<resource-name>))</code></li>
Dispatch a compute pass with the given function name and using the resource size to determine the work-group size.
Expand Down
8 changes: 4 additions & 4 deletions playgroundShader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,26 @@ public void printf<each T>(String format, expand each T values) where T : IPrint
}
[__AttributeUsage(_AttributeTargets.Var)]
public struct ZEROSAttribute
public struct playground_ZEROSAttribute
{
int count;
};
[__AttributeUsage(_AttributeTargets.Var)]
public struct BLACKAttribute
public struct playground_BLACKAttribute
{
int width;
int height;
};
[__AttributeUsage(_AttributeTargets.Var)]
public struct URLAttribute
public struct playground_URLAttribute
{
string url;
};
[__AttributeUsage(_AttributeTargets.Var)]
public struct RANDAttribute
public struct playground_RANDAttribute
{
int count;
};
Expand Down
20 changes: 12 additions & 8 deletions util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ function reinterpretUint32AsFloat(uint32: number) {
*
* | Attribute | Result
* | :--------------------------------------- | :-
* | `[ZEROS(512)]` | Initialize a buffer with zeros of the provided size.
* | `[BLACK(512, 512)]` | Initialize a texture with black of the provided size.
* | `[URL("https://example.com/image.png")]` | Initialize a texture with image from URL
* | `[RAND(1000)]` | Initialize a float buffer with uniform random floats between 0 and 1.
* | `[playground::ZEROS(512)]` | Initialize a buffer with zeros of the provided size.
* | `[playground::BLACK(512, 512)]` | Initialize a texture with black of the provided size.
* | `[playground::URL("https://example.com/image.png")]` | Initialize a texture with image from URL
* | `[playground::RAND(1000)]` | Initialize a float buffer with uniform random floats between 0 and 1.
*/
export function getCommandsFromAttributes(reflection: ReflectionJSON): { resourceName: string; parsedCommand: ParsedCommand; }[] {
let commands: { resourceName: string, parsedCommand: ParsedCommand }[] = []
Expand All @@ -59,18 +59,22 @@ export function getCommandsFromAttributes(reflection: ReflectionJSON): { resourc
if (parameter.userAttribs == undefined) continue;
for (let attribute of parameter.userAttribs) {
let command: ParsedCommand | null = null;
if (attribute.name == "ZEROS" || attribute.name == "RAND") {

if(!attribute.name.startsWith("playground_")) continue;

let playground_attribute_name = attribute.name.slice(11)
if (playground_attribute_name == "ZEROS" || playground_attribute_name == "RAND") {
command = {
type: attribute.name,
type: playground_attribute_name,
count: attribute.arguments[0] as number,
}
} else if (attribute.name == "BLACK") {
} else if (playground_attribute_name == "BLACK") {
command = {
type: "BLACK",
width: attribute.arguments[0] as number,
height: attribute.arguments[1] as number,
}
} else if (attribute.name == "URL") {
} else if (playground_attribute_name == "URL") {
command = {
type: "URL",
url: attribute.arguments[0] as string,
Expand Down

0 comments on commit 1dfd800

Please sign in to comment.