From 1dfd800f3b2786976c17aaeadaf4d88ea41a381c Mon Sep 17 00:00:00 2001 From: Devon7925 Date: Fri, 20 Dec 2024 14:40:06 -0700 Subject: [PATCH] namespace attributes --- demos/gsplat2d-diff.slang | 10 +++++----- demos/gsplat2d.slang | 2 +- demos/image-from-url.slang | 2 +- demos/multiple-kernels.slang | 2 +- image_demo.ts | 2 +- index.html | 8 ++++---- playgroundShader.ts | 8 ++++---- util.ts | 20 ++++++++++++-------- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/demos/gsplat2d-diff.slang b/demos/gsplat2d-diff.slang index be0392e..f81cefe 100644 --- a/demos/gsplat2d-diff.slang +++ b/demos/gsplat2d-diff.slang @@ -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 blobsBuffer; -[ZEROS(BLOB_BUFFER_SIZE)] +[playground::ZEROS(BLOB_BUFFER_SIZE)] RWStructuredBuffer> derivBuffer; -[ZEROS(BLOB_BUFFER_SIZE)] +[playground::ZEROS(BLOB_BUFFER_SIZE)] RWStructuredBuffer adamFirstMoment; -[ZEROS(BLOB_BUFFER_SIZE)] +[playground::ZEROS(BLOB_BUFFER_SIZE)] RWStructuredBuffer adamSecondMoment; -[URL("static/jeep.jpg")] +[playground::URL("static/jeep.jpg")] Texture2D targetTexture; // ----- Shared memory declarations -------- diff --git a/demos/gsplat2d.slang b/demos/gsplat2d.slang index 2076e75..296e82e 100644 --- a/demos/gsplat2d.slang +++ b/demos/gsplat2d.slang @@ -1,6 +1,6 @@ import playground; -[RAND(131072)] +[playground::RAND(131072)] RWStructuredBuffer randBuffer; #define GAUSSIANS_PER_BLOCK 256 diff --git a/demos/image-from-url.slang b/demos/image-from-url.slang index a339648..ec91c55 100644 --- a/demos/image-from-url.slang +++ b/demos/image-from-url.slang @@ -2,7 +2,7 @@ import playground; -[URL("static/jeep.jpg")] +[playground::URL("static/jeep.jpg")] Texture2D myImage; float4 imageMain(uint2 dispatchThreadID, int2 screenSize) diff --git a/demos/multiple-kernels.slang b/demos/multiple-kernels.slang index 2cc7f1c..0bedfe4 100644 --- a/demos/multiple-kernels.slang +++ b/demos/multiple-kernels.slang @@ -1,6 +1,6 @@ import playground; -[RAND(131072)] +[playground::RAND(131072)] RWStructuredBuffer buf; // Fills buffer with a sine wave diff --git a/image_demo.ts b/image_demo.ts index 3e33811..9c30b23 100644 --- a/image_demo.ts +++ b/image_demo.ts @@ -2,7 +2,7 @@ const imageDemoCode = ` import playground; -[URL("static/jeep.jpg")] +[playground::URL("static/jeep.jpg")] Texture2D myImage; float4 imageMain(uint2 dispatchThreadID, int2 screenSize) { diff --git a/index.html b/index.html index f59c900..5018f8a 100644 --- a/index.html +++ b/index.html @@ -228,13 +228,13 @@

Shader Commands

WebGPU shaders in browser can use certain commands to specify how they will run. -

  • [ZEROS(512)]
  • +
  • [playground::ZEROS(512)]
  • Initialize a float buffer with zeros of the provided size. -
  • [BLACK(512, 512)]
  • +
  • [playground::BLACK(512, 512)]
  • Initialize a float texture with zeros of the provided size. -
  • [URL("https://example.com/image.png")]
  • +
  • [playground::URL("https://example.com/image.png")]
  • Initialize a texture with image from URL. -
  • [RAND(1000)]
  • +
  • [playground::RAND(1000)]
  • Initialize a float buffer with uniform random floats between 0 and 1.
  • //! CALL(fn-name, SIZE_OF())
  • Dispatch a compute pass with the given function name and using the resource size to determine the work-group size. diff --git a/playgroundShader.ts b/playgroundShader.ts index 38639a1..67f1967 100644 --- a/playgroundShader.ts +++ b/playgroundShader.ts @@ -105,26 +105,26 @@ public void printf(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; }; diff --git a/util.ts b/util.ts index aee5dbd..f2f08e9 100644 --- a/util.ts +++ b/util.ts @@ -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 }[] = [] @@ -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,