Skip to content

Commit 1a0afaa

Browse files
Release (#171)
* Fix 165 (#169) * fix: throw error message from naga #165 * chore: commit changeset * fix: remove new URL * chore(release): bump version (#170) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 15bfcbb commit 1a0afaa

23 files changed

+485
-450
lines changed

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
],
99
"typescript.tsdk": "node_modules/typescript/lib",
1010
"editor.codeActionsOnSave": {
11-
"source.fixAll.eslint": true
11+
"source.fixAll.eslint": "explicit"
1212
},
13-
"svg.preview.background": "dark-transparent"
13+
"svg.preview.background": "dark-transparent",
14+
"rust-analyzer.linkedProjects": ["./rust/Cargo.toml"]
1415
}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @antv/g-device-api
22

3+
## 1.6.6
4+
5+
### Patch Changes
6+
7+
- 5cfa31c: Display more granular error message when compiling wgsl with naga.
8+
39
## 1.6.5
410

511
### Patch Changes

examples/demos/3d-atomic-rasterizer.ts

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -82,85 +82,85 @@ struct Custom {
8282
8383
struct Camera
8484
{
85-
pos: float3,
86-
cam: float3x3,
87-
fov: float,
88-
size: float2
85+
pos: vec3f,
86+
cam: mat3x3<f32>,
87+
fov: f32,
88+
size: vec2f
8989
}
9090
9191
var<private> camera : Camera;
92-
var<private> state : uint4;
92+
var<private> state : vec4u;
9393
94-
fn pcg4d(a: uint4) -> uint4
94+
fn pcg4d(a: vec4u) -> vec4u
9595
{
9696
var v = a * 1664525u + 1013904223u;
9797
v.x += v.y*v.w; v.y += v.z*v.x; v.z += v.x*v.y; v.w += v.y*v.z;
98-
v = v ^ ( v >> uint4(16u) );
98+
v = v ^ ( v >> vec4u(16u) );
9999
v.x += v.y*v.w; v.y += v.z*v.x; v.z += v.x*v.y; v.w += v.y*v.z;
100100
return v;
101101
}
102102
103-
fn rand4() -> float4
103+
fn rand4() -> vec4f
104104
{
105105
state = pcg4d(state);
106-
return float4(state)/float(0xffffffffu);
106+
return vec4f(state)/f32(0xffffffffu);
107107
}
108108
109-
fn nrand4(sigma: float, mean: float4) -> float4
109+
fn nrand4(sigma: f32, mean: vec4f) -> vec4f
110110
{
111111
let Z = rand4();
112112
return mean + sigma * sqrt(-2.0 * log(Z.xxyy)) *
113-
float4(cos(TWO_PI * Z.z),sin(TWO_PI * Z.z),cos(TWO_PI * Z.w),sin(TWO_PI * Z.w));
113+
vec4f(cos(TWO_PI * Z.z),sin(TWO_PI * Z.z),cos(TWO_PI * Z.w),sin(TWO_PI * Z.w));
114114
}
115115
116-
fn GetCameraMatrix(ang: float2) -> float3x3
116+
fn GetCameraMatrix(ang: vec2f) -> mat3x3<f32>
117117
{
118-
let x_dir = float3(cos(ang.x)*sin(ang.y), cos(ang.y), sin(ang.x)*sin(ang.y));
119-
let y_dir = normalize(cross(x_dir, float3(0.0,1.0,0.0)));
118+
let x_dir = vec3f(cos(ang.x)*sin(ang.y), cos(ang.y), sin(ang.x)*sin(ang.y));
119+
let y_dir = normalize(cross(x_dir, vec3f(0.0,1.0,0.0)));
120120
let z_dir = normalize(cross(y_dir, x_dir));
121-
return float3x3(-x_dir, y_dir, z_dir);
121+
return mat3x3<f32>(-x_dir, y_dir, z_dir);
122122
}
123123
124-
fn SetCamera(ang: float2, fov: float)
124+
fn SetCamera(ang: vec2f, fov: f32)
125125
{
126126
camera.fov = fov;
127127
camera.cam = GetCameraMatrix(ang);
128-
camera.pos = - (camera.cam*float3(3.0*custom.Radius+0.5,0.0,0.0));
129-
camera.size = float2(textureDimensions(screen));
128+
camera.pos = - (camera.cam*vec3f(3.0*custom.Radius+0.5,0.0,0.0));
129+
camera.size = vec2f(textureDimensions(screen));
130130
}
131131
132132
//project to clip space
133-
fn Project(cam: Camera, p: float3) -> float3
133+
fn Project(cam: Camera, p: vec3f) -> vec3f
134134
{
135135
let td = distance(cam.pos, p);
136136
let dir = (p - cam.pos)/td;
137137
let screen = dir*cam.cam;
138-
return float3(screen.yz*cam.size.y/(cam.fov*screen.x) + 0.5*cam.size,screen.x*td);
138+
return vec3f(screen.yz*cam.size.y/(cam.fov*screen.x) + 0.5*cam.size,screen.x*td);
139139
}
140140
141141
@compute @workgroup_size(16, 16)
142-
fn Clear(@builtin(global_invocation_id) id: uint3) {
143-
let screen_size = int2(textureDimensions(screen));
144-
let idx0 = int(id.x) + int(screen_size.x * int(id.y));
142+
fn Clear(@builtin(global_invocation_id) id: vec3u) {
143+
let screen_size = vec2i(textureDimensions(screen));
144+
let idx0 = i32(id.x) + i32(screen_size.x * i32(id.y));
145145
146146
atomicStore(&atomic_storage[idx0*4+0], 0);
147147
atomicStore(&atomic_storage[idx0*4+1], 0);
148148
atomicStore(&atomic_storage[idx0*4+2], 0);
149149
atomicStore(&atomic_storage[idx0*4+3], 0);
150150
}
151151
152-
fn Pack(a: uint, b: uint) -> int
152+
fn Pack(a: u32, b: u32) -> i32
153153
{
154-
return int(a + (b << (31u - DEPTH_BITS)));
154+
return i32(a + (b << (31u - DEPTH_BITS)));
155155
}
156156
157-
fn Unpack(a: int) -> float
157+
fn Unpack(a: i32) -> f32
158158
{
159-
let mask = (1 << (DEPTH_BITS - 1u)) - 1;
160-
return float(a & mask)/256.0;
159+
let mask = i32(1u << (DEPTH_BITS - 1u)) - 1i;
160+
return f32(a & mask)/256.0;
161161
}
162162
163-
fn ClosestPoint(color: float3, depth: float, index: int)
163+
fn ClosestPoint(color: vec3f, depth: f32, index: i32)
164164
{
165165
let inverseDepth = 1.0/depth;
166166
let scaledDepth = (inverseDepth - 1.0/DEPTH_MAX)/(1.0/DEPTH_MIN - 1.0/DEPTH_MAX);
@@ -170,28 +170,28 @@ struct Custom {
170170
return;
171171
}
172172
173-
let uintDepth = uint(scaledDepth*float((1u << DEPTH_BITS) - 1u));
174-
let uintColor = uint3(color * 256.0);
173+
let uintDepth = u32(scaledDepth*f32((1u << DEPTH_BITS) - 1u));
174+
let uintColor = vec3u(color * 256.0);
175175
176176
atomicMax(&atomic_storage[index*4+0], Pack(uintColor.x, uintDepth));
177177
atomicMax(&atomic_storage[index*4+1], Pack(uintColor.y, uintDepth));
178178
atomicMax(&atomic_storage[index*4+2], Pack(uintColor.z, uintDepth));
179179
}
180180
181-
fn AdditiveBlend(color: float3, depth: float, index: int)
181+
fn AdditiveBlend(color: vec3f, depth: f32, index: i32)
182182
{
183183
let scaledColor = 256.0 * color/depth;
184184
185-
atomicAdd(&atomic_storage[index*4+0], int(scaledColor.x));
186-
atomicAdd(&atomic_storage[index*4+1], int(scaledColor.y));
187-
atomicAdd(&atomic_storage[index*4+2], int(scaledColor.z));
185+
atomicAdd(&atomic_storage[index*4+0], i32(scaledColor.x));
186+
atomicAdd(&atomic_storage[index*4+1], i32(scaledColor.y));
187+
atomicAdd(&atomic_storage[index*4+2], i32(scaledColor.z));
188188
}
189189
190-
fn RasterizePoint(pos: float3, color: float3)
190+
fn RasterizePoint(pos: vec3f, color: vec3f)
191191
{
192-
let screen_size = int2(camera.size);
192+
let screen_size = vec2i(camera.size);
193193
let projectedPos = Project(camera, pos);
194-
let screenCoord = int2(projectedPos.xy);
194+
let screenCoord = vec2i(projectedPos.xy);
195195
196196
//outside of our view
197197
if(screenCoord.x < 0 || screenCoord.x >= screen_size.x ||
@@ -213,75 +213,75 @@ struct Custom {
213213
}
214214
215215
@compute @workgroup_size(16, 16)
216-
fn Rasterize(@builtin(global_invocation_id) id: uint3) {
216+
fn Rasterize(@builtin(global_invocation_id) id: vec3u) {
217217
// Viewport resolution (in pixels)
218-
let screen_size = int2(textureDimensions(screen));
219-
let screen_size_f = float2(screen_size);
218+
let screen_size = vec2i(textureDimensions(screen));
219+
let screen_size_f = vec2f(screen_size);
220220
221-
// let ang = float2(mouse.pos.xy)*float2(-TWO_PI, PI)/screen_size_f + float2(0.4, 0.4);
222-
let ang = float2(0.0, 0.0)*float2(-TWO_PI, PI)/screen_size_f + float2(0.4, 0.4);
221+
// let ang = vec2f(mouse.pos.xy)*vec2f(-TWO_PI, PI)/screen_size_f + vec2f(0.4, 0.4);
222+
let ang = vec2f(0.0, 0.0)*vec2f(-TWO_PI, PI)/screen_size_f + vec2f(0.4, 0.4);
223223
224224
SetCamera(ang, FOV);
225225
226226
//RNG state
227-
state = uint4(id.x, id.y, id.z, 0u*time.frame);
227+
state = vec4u(id.x, id.y, id.z, 0u*time.frame);
228228
229-
for(var i: i32 = 0; i < int(custom.Samples*MaxSamples + 1.0); i++)
229+
for(var i: i32 = 0; i < i32(custom.Samples*MaxSamples + 1.0); i++)
230230
{
231-
let rand = nrand4(1.0, float4(0.0));
231+
let rand = nrand4(1.0, vec4f(0.0));
232232
var pos = 0.2*rand.xyz;
233-
let col = float3(0.5 + 0.5*sin(10.0*pos));
233+
let col = vec3f(0.5 + 0.5*sin(10.0*pos));
234234
235235
let sec = 5.0+custom.Speed*time.elapsed;
236236
//move points along sines
237-
pos += sin(float3(2.0,1.0,1.5)*sec)*0.1*sin(30.0*custom.Sinea*pos);
238-
pos += sin(float3(2.0,1.0,1.5)*sec)*0.02*sin(30.0*custom.Sineb*pos.zxy);
237+
pos += sin(vec3f(2.0,1.0,1.5)*sec)*0.1*sin(30.0*custom.Sinea*pos);
238+
pos += sin(vec3f(2.0,1.0,1.5)*sec)*0.02*sin(30.0*custom.Sineb*pos.zxy);
239239
240240
RasterizePoint(pos, col);
241241
}
242242
}
243243
244-
fn Sample(pos: int2) -> float3
244+
fn Sample(pos: vec2i) -> vec3f
245245
{
246-
let screen_size = int2(textureDimensions(screen));
246+
let screen_size = vec2i(textureDimensions(screen));
247247
let idx = pos.x + screen_size.x * pos.y;
248248
249-
var color: float3;
249+
var color: vec3f;
250250
if(custom.Mode < 0.5)
251251
{
252-
let x = float(atomicLoad(&atomic_storage[idx*4+0]))/(256.0);
253-
let y = float(atomicLoad(&atomic_storage[idx*4+1]))/(256.0);
254-
let z = float(atomicLoad(&atomic_storage[idx*4+2]))/(256.0);
252+
let x = f32(atomicLoad(&atomic_storage[idx*4+0]))/(256.0);
253+
let y = f32(atomicLoad(&atomic_storage[idx*4+1]))/(256.0);
254+
let z = f32(atomicLoad(&atomic_storage[idx*4+2]))/(256.0);
255255
256-
color = tanh(0.1*float3(x,y,z)/(custom.Samples*MaxSamples + 1.0));
256+
color = tanh(0.1*vec3f(x,y,z)/(custom.Samples*MaxSamples + 1.0));
257257
}
258258
else
259259
{
260260
let x = Unpack(atomicLoad(&atomic_storage[idx*4+0]));
261261
let y = Unpack(atomicLoad(&atomic_storage[idx*4+1]));
262262
let z = Unpack(atomicLoad(&atomic_storage[idx*4+2]));
263263
264-
color = float3(x,y,z);
264+
color = vec3f(x,y,z);
265265
}
266266
267267
return abs(color);
268268
}
269269
270270
@compute @workgroup_size(16, 16)
271-
fn main_image(@builtin(global_invocation_id) id: uint3)
271+
fn main_image(@builtin(global_invocation_id) id: vec3u)
272272
{
273-
let screen_size = uint2(textureDimensions(screen));
273+
let screen_size = vec2u(textureDimensions(screen));
274274
275275
// Prevent overdraw for workgroups on the edge of the viewport
276276
if (id.x >= screen_size.x || id.y >= screen_size.y) { return; }
277277
278278
// Pixel coordinates (centre of pixel, origin at bottom left)
279-
// let fragCoord = float2(float(id.x) + .5, float(id.y) + .5);
279+
// let fragCoord = vec2f(f32(id.x) + .5, f32(id.y) + .5);
280280
281-
let color = float4(Sample(int2(id.xy)),1.0);
281+
let color = vec4f(Sample(vec2i(id.xy)),1.0);
282282
283283
// Output to screen (linear colour space)
284-
textureStore(screen, int2(id.xy), color);
284+
textureStore(screen, vec2i(id.xy), color);
285285
}
286286
`;
287287

0 commit comments

Comments
 (0)