Skip to content

Commit

Permalink
rename uniformBuffer to Ubo for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital committed Jan 18, 2024
1 parent 2a2726e commit 9fd9c46
Show file tree
Hide file tree
Showing 37 changed files with 206 additions and 211 deletions.
30 changes: 15 additions & 15 deletions scripts/utils/autoGenerateUnsafeEvalFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
UNIFORM_TO_SINGLE_SETTERS
} from '../../src/rendering/renderers/gl/shader/utils/generateUniformsSyncTypes';
import {
uniformBufferSyncFunctionsSTD40,
uniformBufferSyncFunctionsWGSL
} from '../../src/rendering/renderers/shared/shader/utils/uniformBufferSyncFunctions';
uboSyncFunctionsSTD40,
uboSyncFunctionsWGSL
} from '../../src/rendering/renderers/shared/shader/utils/uboSyncFunctions';
import { uniformParsers } from '../../src/rendering/renderers/shared/shader/utils/uniformParsers';

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ function autoGenerateUnsafeEvalFunctions()
// eslint-disable-next-line max-len
out.push(`export type UniformUploadFunction = (name: string, cu: any, cv: any, v: any, ud: any, uv: any, gl: any) => void;`);

out.push('export const UNIFORM_TO_SINGLE_FUNCTIONS:Record<UNIFORM_TYPES|string, UniformUploadFunction> = {');
out.push('export const uniformSingleParserFunctions:Record<UNIFORM_TYPES|string, UniformUploadFunction> = {');
for (const i in UNIFORM_TO_SINGLE_SETTERS)
{
const fn = UNIFORM_TO_SINGLE_SETTERS[i];
Expand All @@ -60,7 +60,7 @@ function autoGenerateUnsafeEvalFunctions()
}
out.push('};\n');

out.push('export const UNIFORM_TO_ARRAY_FUNCTIONS:Record<UNIFORM_TYPES|string, UniformUploadFunction> = {');
out.push('export const uniformArrayParserFunctions:Record<UNIFORM_TYPES|string, UniformUploadFunction> = {');
for (const i in UNIFORM_TO_ARRAY_SETTERS)
{
const fn = UNIFORM_TO_ARRAY_SETTERS[i];
Expand All @@ -70,7 +70,7 @@ function autoGenerateUnsafeEvalFunctions()
out.push('};\n');

// now add the uniform parsers..
out.push('export const uniformParsersFunctions:UniformUploadFunction[] = [');
out.push('export const uniformParserFunctions:UniformUploadFunction[] = [');
for (const i in uniformParsers)
{
const fn = uniformParsers[i].uniform;
Expand All @@ -92,7 +92,7 @@ function autoGenerateUboUnsafeEvalFunctions()
const out: string[] = [header];

// eslint-disable-next-line max-len
out.push(`export type UniformBufferUploadFunction = (name:string, data:Float32Array, offset:number, uv:any, v:any) => void;`);
out.push(`export type UboUploadFunction = (name:string, data:Float32Array, offset:number, uv:any, v:any) => void;`);

function convertToFunction(body: string)
{
Expand All @@ -103,7 +103,7 @@ function autoGenerateUboUnsafeEvalFunctions()
}

// now add the uniform parsers..
out.push('export const uniformBufferParsersFunctions:UniformBufferUploadFunction[] = [');
out.push('export const uboParserFunctions:UboUploadFunction[] = [');
for (const i in uniformParsers)
{
const fn = uniformParsers[i].uboWgsl ?? uniformParsers[i].ubo;
Expand All @@ -115,21 +115,21 @@ function autoGenerateUboUnsafeEvalFunctions()
// and the basic uploads

// now add the uniform parsers..
out.push('export const uniformBufferFunctionsWGSL:Record<UNIFORM_TYPES|string, UniformBufferUploadFunction> = {');
for (const i in uniformBufferSyncFunctionsWGSL)
out.push('export const uboSingleFunctionsWGSL:Record<UNIFORM_TYPES|string, UboUploadFunction> = {');
for (const i in uboSyncFunctionsWGSL)
{
const fn = uniformBufferSyncFunctionsWGSL[i as keyof typeof uniformBufferSyncFunctionsWGSL];
const fn = uboSyncFunctionsWGSL[i as keyof typeof uboSyncFunctionsWGSL];

out.push(`'${i}': ${convertToFunction(fn)},`);
}

out.push('};');

// now add the uniform parsers..
out.push('export const uniformBufferSyncFunctionsSTD40:Record<UNIFORM_TYPES|string, UniformBufferUploadFunction> = {');
for (const i in uniformBufferSyncFunctionsSTD40)
out.push('export const uboSingleFunctionsSTD40:Record<UNIFORM_TYPES|string, UboUploadFunction> = {');
for (const i in uboSyncFunctionsSTD40)
{
const fn = uniformBufferSyncFunctionsSTD40[i as keyof typeof uniformBufferSyncFunctionsSTD40];
const fn = uboSyncFunctionsSTD40[i as keyof typeof uboSyncFunctionsSTD40];

out.push(`'${i}': ${convertToFunction(fn)},`);
}
Expand All @@ -138,7 +138,7 @@ function autoGenerateUboUnsafeEvalFunctions()

const final = out.join('\n');

const path = 'src/unsafe-eval/uniformBufferSyncFunctions.ts';
const path = 'src/unsafe-eval/uboSyncFunctions.ts';

writeFileSync(path, final, 'utf8');
}
Expand Down
2 changes: 1 addition & 1 deletion src/filters/FilterSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export class FilterSystem implements System
if ((renderer as WebGPURenderer).renderPipes.uniformBatch)
{
const batchUniforms = (renderer as WebGPURenderer).renderPipes.uniformBatch
.getUniformBufferResource(this._filterGlobalUniforms);
.getUboResource(this._filterGlobalUniforms);

this._globalFilterBindGroup.setResource(batchUniforms, 0);
}
Expand Down
25 changes: 25 additions & 0 deletions src/rendering/renderers/gl/GlUboSystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ExtensionType } from '../../../extensions/Extensions';
import { UboSystem } from '../shared/shader/UboSystem';
import { createUboElementsSTD40 } from './shader/utils/createUboElementsSTD40_';
import { createUboSyncFunctionSTD40 } from './shader/utils/createUboSyncSTD40';

/**
* System plugin to the renderer to manage uniform buffers. But with an WGSL adaptor.
* @memberof rendering
*/
export class GlUboSystem extends UboSystem
{
/** @ignore */
public static extension = {
type: [ExtensionType.WebGLSystem],
name: 'ubo',
} as const;

constructor()
{
super({
createUboElements: createUboElementsSTD40,
generateUboSync: createUboSyncFunctionSTD40,
});
}
}
25 changes: 0 additions & 25 deletions src/rendering/renderers/gl/GlUniformBufferSystem.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/rendering/renderers/gl/WebGLRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { GlColorMaskSystem } from './GlColorMaskSystem';
import { GlEncoderSystem } from './GlEncoderSystem';
import { GlRenderTargetSystem } from './GlRenderTargetSystem';
import { GlStencilSystem } from './GlStencilSystem';
import { GlUniformBufferSystem } from './GlUniformBufferSystem';
import { GlUboSystem } from './GlUboSystem';
import { GlShaderSystem } from './shader/GlShaderSystem';
import { GlUniformGroupSystem } from './shader/GlUniformGroupSystem';
import { GlStateSystem } from './state/GlStateSystem';
Expand All @@ -27,7 +27,7 @@ import type { GlRenderingContext } from './context/GlRenderingContext';

const DefaultWebGLSystems = [
...SharedSystems,
GlUniformBufferSystem,
GlUboSystem,
GlBackBufferSystem,
GlContextSystem,
GlBufferSystem,
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/renderers/gl/shader/GlShaderSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class GlShaderSystem

if (isBufferResource)
{
this._renderer.uniformBuffer.updateUniformGroup(uniformGroup as UniformGroup);
this._renderer.ubo.updateUniformGroup(uniformGroup as UniformGroup);
}

bufferSystem.updateBuffer(uniformGroup.buffer);
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/renderers/gl/shader/program/generateProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GlProgramData } from '../GlProgramData';
import { compileShader } from './compileShader';
import { defaultValue } from './defaultValue';
import { extractAttributesFromGlProgram } from './extractAttributesFromGlProgram';
import { getUniformBufferData } from './getUniformBufferData';
import { getUboData } from './getUboData';
import { getUniformData } from './getUniformData';
import { logProgramError } from './logProgramError';

Expand Down Expand Up @@ -58,7 +58,7 @@ export function generateProgram(gl: GlRenderingContext, program: GlProgram): GlP

program._attributeData = extractAttributesFromGlProgram(webGLProgram, gl);
program._uniformData = getUniformData(webGLProgram, gl);
program._uniformBlockData = getUniformBufferData(webGLProgram, gl);
program._uniformBlockData = getUboData(webGLProgram, gl);

gl.deleteShader(glVertShader);
gl.deleteShader(glFragShader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { GlUniformBlockData } from '../GlProgram';
* @param gl - the WebGL context
* @returns {object} the uniform data for this program
*/
export function getUniformBufferData(program: WebGLProgram, gl: WebGL2RenderingContext): Record<string, GlUniformBlockData>
export function getUboData(program: WebGLProgram, gl: WebGL2RenderingContext): Record<string, GlUniformBlockData>
{
// if uniform buffer data is not supported, early out
if (!gl.ACTIVE_UNIFORM_BLOCKS) return {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UBOElement, UniformBufferLayout, UniformData } from '../../../shared/shader/types';
import type { UboElement, UboLayout, UniformData } from '../../../shared/shader/types';

export const WGSL_TO_STD40_SIZE: Record<string, number> = {
f32: 4,
Expand Down Expand Up @@ -31,9 +31,9 @@ export const WGSL_TO_STD40_SIZE: Record<string, number> = {
// mat4: 16 * 4,
};

export function createUBOElementsSTD40(uniformData: UniformData[]): UniformBufferLayout
export function createUboElementsSTD40(uniformData: UniformData[]): UboLayout
{
const uboElements: UBOElement[] = uniformData.map((data: UniformData) =>
const uboElements: UboElement[] = uniformData.map((data: UniformData) =>
({
data,
offset: 0,
Expand Down
19 changes: 19 additions & 0 deletions src/rendering/renderers/gl/shader/utils/createUboSyncSTD40.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable quote-props */

import { createUboSyncFunction } from '../../../shared/shader/utils/createUboSyncFunction_';
import { uboSyncFunctionsSTD40 } from '../../../shared/shader/utils/uboSyncFunctions';
import { generateArraySyncSTD40 } from './generateArraySyncSTD40';

import type { UboElement, UniformsSyncCallback } from '../../../shared/shader/types';

export function createUboSyncFunctionSTD40(
uboElements: UboElement[],
): UniformsSyncCallback
{
return createUboSyncFunction(
uboElements,
'uboStd40',
generateArraySyncSTD40,
uboSyncFunctionsSTD40,
);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WGSL_TO_STD40_SIZE } from './createUBOElementsSTD40';
import { WGSL_TO_STD40_SIZE } from './createUboElementsSTD40_';

import type { UBOElement } from '../../../shared/shader/types';
import type { UboElement } from '../../../shared/shader/types';

/**
* This generates a function that will sync an array to the uniform buffer
Expand All @@ -9,7 +9,7 @@ import type { UBOElement } from '../../../shared/shader/types';
* @param offsetToAdd - the offset to append at the start of the code
* @returns - the generated code
*/
export function generateArraySyncSTD40(uboElement: UBOElement, offsetToAdd: number): string
export function generateArraySyncSTD40(uboElement: UboElement, offsetToAdd: number): string
{
const rowSize = Math.max(WGSL_TO_STD40_SIZE[uboElement.data.type] / 16, 1);
const elementSize = (uboElement.data.value as Array<number>).length / uboElement.data.size;// size / rowSize;
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/renderers/gpu/BindGroupSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class BindGroupSystem implements System
{
const uniformGroup = resource as UniformGroup;

renderer.uniformBuffer.updateUniformGroup(uniformGroup as UniformGroup);
renderer.ubo.updateUniformGroup(uniformGroup as UniformGroup);

const buffer = uniformGroup.buffer;

Expand Down
2 changes: 1 addition & 1 deletion src/rendering/renderers/gpu/GpuEncoderSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class GpuEncoderSystem implements System

if ((resource as UniformGroup).isUniformGroup)
{
this._renderer.uniformBuffer.updateUniformGroup(resource as UniformGroup);
this._renderer.ubo.updateUniformGroup(resource as UniformGroup);
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/rendering/renderers/gpu/GpuUboSystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ExtensionType } from '../../../extensions/Extensions';
import { UboSystem } from '../shared/shader/UboSystem';
import { createUboElementsWGSL } from './shader/utils/createUboElementsWGSL_';
import { createUboSyncFunctionWGSL } from './shader/utils/createUboSyncFunctionWGSL';

/**
* System plugin to the renderer to manage uniform buffers. With a WGSL twist!
* @memberof rendering
*/
export class GpuUboSystem extends UboSystem
{
/** @ignore */
public static extension = {
type: [ExtensionType.WebGPUSystem],
name: 'ubo',
} as const;

constructor()
{
super({
createUboElements: createUboElementsWGSL,
generateUboSync: createUboSyncFunctionWGSL,
});
}
}
14 changes: 7 additions & 7 deletions src/rendering/renderers/gpu/GpuUniformBatchPipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ExtensionType } from '../../../extensions/Extensions';
import { Buffer } from '../shared/buffer/Buffer';
import { BufferResource } from '../shared/buffer/BufferResource';
import { BufferUsage } from '../shared/buffer/const';
import { UniformBufferBatch } from './buffer/UniformBufferBatch';
import { UboBatch } from './buffer/UboBatch';
import { BindGroup } from './shader/BindGroup';

import type { UniformGroup } from '../shared/shader/UniformGroup';
Expand All @@ -25,7 +25,7 @@ export class GpuUniformBatchPipe
private _renderer: WebGPURenderer;

private _bindGroupHash: Record<number, BindGroup> = Object.create(null);
private readonly _batchBuffer: UniformBufferBatch;
private readonly _batchBuffer: UboBatch;

// number of buffers..
private _buffers: Buffer[] = [];
Expand All @@ -37,7 +37,7 @@ export class GpuUniformBatchPipe
{
this._renderer = renderer;

this._batchBuffer = new UniformBufferBatch({ minUniformOffsetAlignment });
this._batchBuffer = new UboBatch({ minUniformOffsetAlignment });

const totalBuffers = (256 / minUniformOffsetAlignment);

Expand Down Expand Up @@ -78,22 +78,22 @@ export class GpuUniformBatchPipe
return this._bindGroupHash[group.uid];
}

this._renderer.uniformBuffer.ensureUniformGroup(group);
this._renderer.ubo.ensureUniformGroup(group);

const data = group.buffer.data as Float32Array;

const offset = this._batchBuffer.addEmptyGroup(data.length);

this._renderer.uniformBuffer.syncUniformGroup(group, this._batchBuffer.data, offset / 4);
this._renderer.ubo.syncUniformGroup(group, this._batchBuffer.data, offset / 4);

this._bindGroupHash[group.uid] = this._getBindGroup(offset / minUniformOffsetAlignment);

return this._bindGroupHash[group.uid];
}

public getUniformBufferResource(group: UniformGroup<any>): BufferResource
public getUboResource(group: UniformGroup<any>): BufferResource
{
this._renderer.uniformBuffer.updateUniformGroup(group);
this._renderer.ubo.updateUniformGroup(group);

const data = group.buffer.data as Float32Array;

Expand Down
Loading

0 comments on commit 9fd9c46

Please sign in to comment.