Skip to content

Commit

Permalink
chore(webgpu): Partial WGSL texture/sampler support
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Aug 31, 2024
1 parent c836c09 commit fcc9095
Show file tree
Hide file tree
Showing 67 changed files with 628 additions and 331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"require": "./dist/index.cjs"
},
"dependencies": {
"@luma.gl/constants": "9.1.0-alpha.17"
"@luma.gl/constants": "9.1.0-alpha.19"
}
}
24 changes: 12 additions & 12 deletions docs/api-guide/gpu/gpu-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@ WGSL vertex shader
struct Uniforms {
modelViewProjectionMatrix : mat4x4<f32>;
};
[[binding(0), group(0)]] var<uniform> uniforms : Uniforms; // BINDING 0
@binding(0), @group(0) var<uniform> uniforms : Uniforms; // BINDING 0

struct VertexOutput {
[[builtin(position)]] Position : vec4<f32>;
[[location(0)]] fragUV : vec2<f32>;
[[location(1)]] fragPosition: vec4<f32>;
@builtin(position) Position : vec4<f32>;
@location(0) fragUV : vec2<f32>;
@location(1) fragPosition: vec4<f32>;
};

[[stage(vertex)]]
fn main([[location(0)]] position : vec4<f32>,
[[location(1)]] uv : vec2<f32>) -> VertexOutput {
@stage(vertex)
fn main(@location(0) position : vec4<f32>,
@location(1) uv : vec2<f32>) -> VertexOutput {
var output : VertexOutput;
output.Position = uniforms.modelViewProjectionMatrix * position;
output.fragUV = uv;
Expand All @@ -165,12 +165,12 @@ fn main([[location(0)]] position : vec4<f32>,
WGSL Fragment Shader
```rust
[[group(0), binding(1)]] var mySampler: sampler; // BINDING 1
[[group(0), binding(2)]] var myTexture: texture_2d<f32>; // BINDING 2
@group(0), binding(1) var mySampler: sampler; // BINDING 1
@group(0), binding(2) var myTexture: texture_2d<f32>; // BINDING 2

[[stage(fragment)]]
fn main([[location(0)]] fragUV: vec2<f32>,
[[location(1)]] fragPosition: vec4<f32>) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn main(@location(0) fragUV: vec2<f32>,
@location(1) fragPosition: vec4<f32>) -> [[location(0)]] vec4<f32> {
return textureSample(myTexture, mySampler, fragUV) * fragPosition;
}
```
24 changes: 12 additions & 12 deletions docs/api-reference/core/bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ WGSL vertex shader
struct Uniforms {
modelViewProjectionMatrix : mat4x4<f32>;
};
[[binding(0), group(0)]] var<uniform> uniforms : Uniforms; // BINDING 0
@binding(0), @group(0) var<uniform> uniforms : Uniforms; // BINDING 0

struct VertexOutput {
[[builtin(position)]] Position : vec4<f32>;
[[location(0)]] fragUV : vec2<f32>;
[[location(1)]] fragPosition: vec4<f32>;
@builtin(position) Position : vec4<f32>;
@location(0) fragUV : vec2<f32>;
@location(1) fragPosition: vec4<f32>;
};

[[stage(vertex)]]
fn main([[location(0)]] position : vec4<f32>,
[[location(1)]] uv : vec2<f32>) -> VertexOutput {
@stage(vertex)
fn main(@location(0) position : vec4<f32>,
@location(1) uv : vec2<f32>) -> VertexOutput {
var output : VertexOutput;
output.Position = uniforms.modelViewProjectionMatrix * position;
output.fragUV = uv;
Expand All @@ -137,12 +137,12 @@ fn main([[location(0)]] position : vec4<f32>,
WGSL FRAGMENT SHADER

```rust
[[group(0), binding(1)]] var mySampler: sampler; // BINDING 1
[[group(0), binding(2)]] var myTexture: texture_2d<f32>; // BINDING 2
@group(0), @binding(1) var mySampler: sampler; // BINDING 1
@group(0), @binding(2) var myTexture: texture_2d<f32>; // BINDING 2

[[stage(fragment)]]
fn main([[location(0)]] fragUV: vec2<f32>,
[[location(1)]] fragPosition: vec4<f32>) -> [[location(0)]] vec4<f32> {
@stage(fragment)
fn main(@location(0) fragUV: vec2<f32>,
@location(1) fragPosition: vec4<f32>) -> @location(0) vec4<f32> {
return textureSample(myTexture, mySampler, fragUV) * fragPosition;
}
```
8 changes: 4 additions & 4 deletions docs/tutorials/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ Open the file `package.json` (created when we initialized npm), and add the foll
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
},
"devDependencies": {
"typescript": "^5.5.0",
Expand All @@ -129,8 +129,8 @@ The full contents of the `package.json` should be the following (dependency vers
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
},
"devDependencies": {
"typescript": "^5.5.0",
Expand Down
1 change: 0 additions & 1 deletion examples/api/animation/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate {
.translate(cube.translation)
.rotateXYZ([rotationX, rotationY, rotationZ]);

cube.model.setUniforms({});
cube.uniformStore.setUniforms({
app: {
uModel: modelMatrix
Expand Down
8 changes: 4 additions & 4 deletions examples/api/animation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions examples/api/cubemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/constants": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/webgpu": "9.1.0-alpha.17",
"@luma.gl/constants": "9.1.0-alpha.19",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@luma.gl/webgpu": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions examples/api/texture-3d/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/webgpu": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@luma.gl/webgpu": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions examples/showcase/instancing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/webgpu": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@luma.gl/webgpu": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase/persistence/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
}
@fragment
fn fragmentMain(inputs: FragmentInputs) -> [[location(0)]] vec4<f32> {
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
let attenuation = 1.0;
if (sphere.lighting) {
light = normalize(vec3(1,1,2));
Expand Down
10 changes: 5 additions & 5 deletions examples/showcase/persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/webgpu": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@luma.gl/webgpu": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase/postprocessing/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import {webgpuAdapter} from '@luma.gl/webgpu';
import {makeAnimationLoop} from '@luma.gl/engine';
import AnimationLoopTemplate from './app.ts';
const animationLoop = makeAnimationLoop(AnimationLoopTemplate, {adapters: [/* webgpuAdapter, */ webgl2Adapter]});
const animationLoop = makeAnimationLoop(AnimationLoopTemplate, {adapters: [webgpuAdapter, webgl2Adapter]});
animationLoop.start();
</script>
<body>
Expand Down
12 changes: 6 additions & 6 deletions examples/showcase/postprocessing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"dependencies": {
"@loaders.gl/core": "^4.2.0",
"@loaders.gl/gltf": "^4.2.0",
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/gltf": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/webgpu": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/gltf": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@luma.gl/webgpu": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
11 changes: 7 additions & 4 deletions examples/tutorials/hello-cube/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ struct Uniforms {
modelViewProjectionMatrix : mat4x4<f32>,
};
@binding(0) @group(0) var<uniform> app : Uniforms;
@group(0) @binding(0) var<uniform> app : Uniforms;
// @group(0) @binding(1) var uTexture : texture_2d<f32>;
// @group(0) @binding(2) var uTextureSampler : sampler;
struct VertexInputs {
// CUBE GEOMETRY
Expand All @@ -48,6 +50,7 @@ fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
@fragment
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
return inputs.fragPosition;
// return textureSample(uTexture, uTextureSampler, inputs.fragUV);
}
`;

Expand Down Expand Up @@ -125,9 +128,9 @@ export default class AppAnimationLoopTemplate extends AnimationLoopTemplate {
data: loadImageBitmap('vis-logo.png'),
mipmaps: true,
sampler: device.createSampler({
minFilter: 'linear',
magFilter: 'linear',
mipmapFilter: 'linear'
minFilter: 'nearest',
magFilter: 'nearest',
mipmapFilter: 'nearest'
})
});

Expand Down
8 changes: 4 additions & 4 deletions examples/tutorials/hello-cube/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
16 changes: 6 additions & 10 deletions examples/tutorials/hello-cube/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {defineConfig} from 'vite';
import {readdirSync} from 'fs';

const alias = {
'@luma.gl/constants': `${__dirname}/../../../modules/constants/src`,
'@luma.gl/core': `${__dirname}/../../../modules/core/src`,
'@luma.gl/engine': `${__dirname}/../../../modules/engine/src`,
'@luma.gl/experimental': `${__dirname}/../../../modules/experimental/src`,
'@luma.gl/webgl-legacy': `${__dirname}/../../../modules/gltf/src`,
'@luma.gl/shadertools': `${__dirname}/../../../modules/shadertools/src`,
'@luma.gl/test-utils': `${__dirname}/../../../modules/test-utils/src`,
'@luma.gl/webgl': `${__dirname}/../../../modules/webgl/src`
};
const MODULES_DIR = `${__dirname}/../../../modules`;
const modules = readdirSync(MODULES_DIR);
const alias = Object.fromEntries(
modules.map(module => [`@luma.gl/${module}`, `${MODULES_DIR}/${module}/src`])
);

// https://vitejs.dev/config/
export default defineConfig({
Expand Down
12 changes: 6 additions & 6 deletions examples/tutorials/hello-gltf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"dependencies": {
"@loaders.gl/core": "^4.2.0",
"@loaders.gl/gltf": "^4.2.0",
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/gltf": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/webgpu": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/gltf": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@luma.gl/webgpu": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions examples/tutorials/hello-instanced-cubes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17",
"@luma.gl/webgpu": "9.1.0-alpha.17",
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19",
"@luma.gl/webgpu": "9.1.0-alpha.19",
"@math.gl/core": "4.1.0-alpha.3"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions examples/tutorials/hello-instancing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"serve": "vite preview"
},
"dependencies": {
"@luma.gl/core": "9.1.0-alpha.17",
"@luma.gl/engine": "9.1.0-alpha.17",
"@luma.gl/shadertools": "9.1.0-alpha.17",
"@luma.gl/webgl": "9.1.0-alpha.17"
"@luma.gl/core": "9.1.0-alpha.19",
"@luma.gl/engine": "9.1.0-alpha.19",
"@luma.gl/shadertools": "9.1.0-alpha.19",
"@luma.gl/webgl": "9.1.0-alpha.19"
},
"devDependencies": {
"typescript": "^5.5.0",
Expand Down
Loading

0 comments on commit fcc9095

Please sign in to comment.