Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/webgpu' into webgpu
  • Loading branch information
lukeplowden committed Jun 16, 2025
commit 186f42349ce6c306766a8b0a84eaf3a2035585ec
4 changes: 4 additions & 0 deletions src/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,10 @@ class Shader {
return;
}

const data = this._renderer._mapUniformData
? this._renderer._mapUniformData(uniform, rawData)
: rawData;

if (uniform.isArray) {
if (
uniform._cachedData &&
Expand Down
15 changes: 9 additions & 6 deletions src/webgpu/p5.RendererWebGPU.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Shader } from '../webgl/p5.Shader';
import * as constants from '../core/constants';
import { colorVertexShader, colorFragmentShader } from './shaders/color';
import { lineVertexShader, lineFragmentShader} from './shaders/line';
import { materialVertexShader, materialFragmentShader } from './shaders/material';

class RendererWebGPU extends Renderer3D {
constructor(pInst, w, h, isMainCanvas, elt) {
Expand Down Expand Up @@ -245,10 +246,14 @@ class RendererWebGPU extends Renderer3D {
}

_finalizeShader(shader) {
const uniformSize = Object.values(shader.uniforms)
.filter(u => !u.isSampler)
.reduce((sum, u) => sum + u.alignedBytes, 0);
shader._uniformData = new Float32Array(uniformSize / 4);
const rawSize = Math.max(
0,
...Object.values(shader.uniforms).map(u => u.offsetEnd)
);
const alignedSize = Math.ceil(rawSize / 16) * 16;
shader._uniformData = new Float32Array(alignedSize / 4);
shader._uniformDataView = new DataView(shader._uniformData.buffer);

shader._uniformBuffer = this.device.createBuffer({
size: alignedSize,
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
Expand Down Expand Up @@ -648,8 +653,6 @@ class RendererWebGPU extends Renderer3D {
//////////////////////////////////////////////

_packUniforms(shader) {
let offset = 0;
let i = 0;
for (const name in shader.uniforms) {
const uniform = shader.uniforms[name];
if (uniform.isSampler) continue;
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.