Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Fix uniform update tests #28698

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Changes from all commits
Commits
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
98 changes: 68 additions & 30 deletions examples/jsm/renderers/common/UniformsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class UniformsGroup extends UniformBuffer {

this.isUniformsGroup = true;

this._values = null;

// the order of uniforms in this array must match the order of uniforms in the shader

this.uniforms = [];
Expand Down Expand Up @@ -37,6 +39,18 @@ class UniformsGroup extends UniformBuffer {

}

get values() {

if ( this._values === null ) {

this._values = Array.from( this.buffer );

}

return this._values;

}

get buffer() {

let buffer = this._buffer;
Expand Down Expand Up @@ -132,13 +146,15 @@ class UniformsGroup extends UniformBuffer {

let updated = false;

const a = this.buffer;
const a = this.values;
const v = uniform.getValue();
const offset = uniform.offset;

if ( a[ offset ] !== v ) {

a[ offset ] = v;
const b = this.buffer;

b[ offset ] = a[ offset ] = v;
updated = true;

}
Expand All @@ -151,14 +167,16 @@ class UniformsGroup extends UniformBuffer {

let updated = false;

const a = this.buffer;
const a = this.values;
const v = uniform.getValue();
const offset = uniform.offset;

if ( a[ offset + 0 ] !== v.x || a[ offset + 1 ] !== v.y ) {

a[ offset + 0 ] = v.x;
a[ offset + 1 ] = v.y;
const b = this.buffer;

b[ offset + 0 ] = a[ offset + 0 ] = v.x;
b[ offset + 1 ] = a[ offset + 1 ] = v.y;

updated = true;

Expand All @@ -172,15 +190,17 @@ class UniformsGroup extends UniformBuffer {

let updated = false;

const a = this.buffer;
const a = this.values;
const v = uniform.getValue();
const offset = uniform.offset;

if ( a[ offset + 0 ] !== v.x || a[ offset + 1 ] !== v.y || a[ offset + 2 ] !== v.z ) {

a[ offset + 0 ] = v.x;
a[ offset + 1 ] = v.y;
a[ offset + 2 ] = v.z;
const b = this.buffer;

b[ offset + 0 ] = a[ offset + 0 ] = v.x;
b[ offset + 1 ] = a[ offset + 1 ] = v.y;
b[ offset + 2 ] = a[ offset + 2 ] = v.z;

updated = true;

Expand All @@ -194,16 +214,18 @@ class UniformsGroup extends UniformBuffer {

let updated = false;

const a = this.buffer;
const a = this.values;
const v = uniform.getValue();
const offset = uniform.offset;

if ( a[ offset + 0 ] !== v.x || a[ offset + 1 ] !== v.y || a[ offset + 2 ] !== v.z || a[ offset + 4 ] !== v.w ) {

a[ offset + 0 ] = v.x;
a[ offset + 1 ] = v.y;
a[ offset + 2 ] = v.z;
a[ offset + 3 ] = v.w;
const b = this.buffer;

b[ offset + 0 ] = a[ offset + 0 ] = v.x;
b[ offset + 1 ] = a[ offset + 1 ] = v.y;
b[ offset + 2 ] = a[ offset + 2 ] = v.z;
b[ offset + 3 ] = a[ offset + 3 ] = v.w;

updated = true;

Expand All @@ -217,15 +239,17 @@ class UniformsGroup extends UniformBuffer {

let updated = false;

const a = this.buffer;
const a = this.values;
const c = uniform.getValue();
const offset = uniform.offset;

if ( a[ offset + 0 ] !== c.r || a[ offset + 1 ] !== c.g || a[ offset + 2 ] !== c.b ) {

a[ offset + 0 ] = c.r;
a[ offset + 1 ] = c.g;
a[ offset + 2 ] = c.b;
const b = this.buffer;

b[ offset + 0 ] = a[ offset + 0 ] = c.r;
b[ offset + 1 ] = a[ offset + 1 ] = c.g;
b[ offset + 2 ] = a[ offset + 2 ] = c.b;

updated = true;

Expand All @@ -239,23 +263,25 @@ class UniformsGroup extends UniformBuffer {

let updated = false;

const a = this.buffer;
const a = this.values;
const e = uniform.getValue().elements;
const offset = uniform.offset;

if ( a[ offset + 0 ] !== e[ 0 ] || a[ offset + 1 ] !== e[ 1 ] || a[ offset + 2 ] !== e[ 2 ] ||
a[ offset + 4 ] !== e[ 3 ] || a[ offset + 5 ] !== e[ 4 ] || a[ offset + 6 ] !== e[ 5 ] ||
a[ offset + 8 ] !== e[ 6 ] || a[ offset + 9 ] !== e[ 7 ] || a[ offset + 10 ] !== e[ 8 ] ) {

a[ offset + 0 ] = e[ 0 ];
a[ offset + 1 ] = e[ 1 ];
a[ offset + 2 ] = e[ 2 ];
a[ offset + 4 ] = e[ 3 ];
a[ offset + 5 ] = e[ 4 ];
a[ offset + 6 ] = e[ 5 ];
a[ offset + 8 ] = e[ 6 ];
a[ offset + 9 ] = e[ 7 ];
a[ offset + 10 ] = e[ 8 ];
const b = this.buffer;

b[ offset + 0 ] = a[ offset + 0 ] = e[ 0 ];
b[ offset + 1 ] = a[ offset + 1 ] = e[ 1 ];
b[ offset + 2 ] = a[ offset + 2 ] = e[ 2 ];
b[ offset + 4 ] = a[ offset + 4 ] = e[ 3 ];
b[ offset + 5 ] = a[ offset + 5 ] = e[ 4 ];
b[ offset + 6 ] = a[ offset + 6 ] = e[ 5 ];
b[ offset + 8 ] = a[ offset + 8 ] = e[ 6 ];
b[ offset + 9 ] = a[ offset + 9 ] = e[ 7 ];
b[ offset + 10 ] = a[ offset + 10 ] = e[ 8 ];

updated = true;

Expand All @@ -269,13 +295,15 @@ class UniformsGroup extends UniformBuffer {

let updated = false;

const a = this.buffer;
const a = this.values;
const e = uniform.getValue().elements;
const offset = uniform.offset;

if ( arraysEqual( a, e, offset ) === false ) {

a.set( e, offset );
const b = this.buffer;
b.set( e, offset );
setArray( a, e, offset );
updated = true;

}
Expand All @@ -286,6 +314,16 @@ class UniformsGroup extends UniformBuffer {

}

function setArray( a, b, offset ) {

for ( let i = 0, l = b.length; i < l; i ++ ) {

a[ offset + i ] = b[ i ];

}

}

function arraysEqual( a, b, offset ) {

for ( let i = 0, l = b.length; i < l; i ++ ) {
Expand Down