Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinyork committed Apr 19, 2024
2 parents d3c0b5b + c953888 commit adc46a4
Show file tree
Hide file tree
Showing 142 changed files with 4,919 additions and 2,323 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/backend-webgl",
"comment": "",
"type": "none"
}
],
"packageName": "@zephyr3d/backend-webgl"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/backend-webgl",
"comment": "implement render bundle",
"type": "patch"
}
],
"packageName": "@zephyr3d/backend-webgl"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/backend-webgpu",
"comment": "Add render bundle support",
"type": "patch"
}
],
"packageName": "@zephyr3d/backend-webgpu"
}
10 changes: 10 additions & 0 deletions common/changes/@zephyr3d/base/develop_2024-04-19-17-44.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/base",
"comment": "",
"type": "none"
}
],
"packageName": "@zephyr3d/base"
}
10 changes: 10 additions & 0 deletions common/changes/@zephyr3d/device/develop_2024-03-25-11-16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/device",
"comment": "Implement uniform buffer with dynamic offset",
"type": "patch"
}
],
"packageName": "@zephyr3d/device"
}
10 changes: 10 additions & 0 deletions common/changes/@zephyr3d/device/develop_2024-04-19-17-44.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/device",
"comment": "Add render bundle support",
"type": "patch"
}
],
"packageName": "@zephyr3d/device"
}
10 changes: 10 additions & 0 deletions common/changes/@zephyr3d/imgui/develop_2024-04-19-17-44.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/imgui",
"comment": "",
"type": "none"
}
],
"packageName": "@zephyr3d/imgui"
}
10 changes: 10 additions & 0 deletions common/changes/@zephyr3d/scene/develop_2024-03-25-11-16.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/scene",
"comment": "Improve rendering performance for geometry instancing",
"type": "patch"
}
],
"packageName": "@zephyr3d/scene"
}
10 changes: 10 additions & 0 deletions common/changes/@zephyr3d/scene/develop_2024-04-19-17-44.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@zephyr3d/scene",
"comment": "Add support for command buffer reuse optimization",
"type": "minor"
}
],
"packageName": "@zephyr3d/scene"
}
20 changes: 10 additions & 10 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"dependencies": {
"@types/colors": "^1.2.1",
"@types/diff": "^5.0.2",
"@webgpu/types": "^0.1.31",
"@webgpu/types": "^0.1.40",
"colors": "^1.4.0",
"diff": "^5.0.0",
"@zephyr3d/base": "workspace:^0.1.3",
Expand Down
18 changes: 12 additions & 6 deletions examples/src/instancecube/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Matrix4x4, Quaternion, Vector4 } from '@zephyr3d/base';
import { backendWebGL1, backendWebGL2 } from '@zephyr3d/backend-webgl';
import { backendWebGPU } from '@zephyr3d/backend-webgpu';
import type { DeviceBackend } from '@zephyr3d/device';
import type { DeviceBackend, RenderBundle } from '@zephyr3d/device';
import { DrawText } from '@zephyr3d/device';

(async function () {
Expand Down Expand Up @@ -106,6 +106,7 @@ import { DrawText } from '@zephyr3d/device';
// create bind group
const bindGroup = device.createBindGroup(program.bindGroupLayouts[0]);

let renderBundle: RenderBundle = null;
// start render loop
device.runLoop((device) => {
const t = device.frameInfo.elapsedOverall * 0.002;
Expand All @@ -117,11 +118,16 @@ import { DrawText } from '@zephyr3d/device';
);

device.clearFrameBuffer(new Vector4(0, 0, 0.5, 1), 1, 0);
device.setProgram(program);
device.setVertexLayout(vertexLayout);
device.setBindGroup(0, bindGroup);
device.drawInstanced('triangle-list', 0, 36, 16);

if (!renderBundle) {
device.beginCapture();
device.setProgram(program);
device.setVertexLayout(vertexLayout);
device.setBindGroup(0, bindGroup);
device.drawInstanced('triangle-list', 0, 36, 16);
renderBundle = device.endCapture();
} else {
device.executeRenderBundle(renderBundle);
}
DrawText.drawText(device, `Device: ${device.type}`, '#ffffff', 30, 30);
DrawText.drawText(device, `FPS: ${device.frameInfo.FPS.toFixed(2)}`, '#ffff00', 30, 50);
});
Expand Down
5 changes: 5 additions & 0 deletions libs/backend-webgl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@
"@zephyr3d/device": "workspace:^0.2.1"
},
"dependencies": {
<<<<<<< HEAD
"@types/node": "^18.13.0",
"@webgpu/types": "^0.1.31"
=======
"@webgpu/types": "^0.1.40",
"@types/node": "^18.13.0"
>>>>>>> develop
}
}
5 changes: 4 additions & 1 deletion libs/backend-webgl/src/basetexture_webgl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export abstract class WebGLBaseTexture extends WebGLGPUObject<WebGLTexture> {
destroy(): void {
if (this._object) {
this._device.context.deleteTexture(this._object);
this._device.invalidateBindingTextures();
this._object = null;
this._device.updateVideoMemoryCost(-this._memCost);
this._memCost = 0;
Expand Down Expand Up @@ -191,6 +192,7 @@ export abstract class WebGLBaseTexture extends WebGLGPUObject<WebGLTexture> {
const obj = this._object;
this._device.runNextFrame(() => {
this._device.context.deleteTexture(obj);
this._device.invalidateBindingTextures();
});
this._object = null;
}
Expand All @@ -203,7 +205,8 @@ export abstract class WebGLBaseTexture extends WebGLGPUObject<WebGLTexture> {
if (!this._device.isContextLost()) {
this._object = this._device.context.createTexture();
const gl = this._device.context;
gl.bindTexture(textureTargetMap[this._target], this._object);
this._device.bindTexture(textureTargetMap[this._target], 0, this);
//gl.bindTexture(textureTargetMap[this._target], this._object);
const params = (this.getTextureCaps() as WebGLTextureCaps).getTextureFormatInfo(this._format);
if (isWebGL2(gl) && !this.isTextureVideo()) {
if (!this.isTexture3D() && !this.isTexture2DArray()) {
Expand Down
37 changes: 29 additions & 8 deletions libs/backend-webgl/src/bindgroup_webgl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,41 @@ import type { WebGLGPUProgram } from './gpuprogram_webgl';
import type { WebGLTextureSampler } from './sampler_webgl';
import type { TypedArray } from '@zephyr3d/base';
import type { WebGLDevice } from './device_webgl';
import type { WebGLGPUBuffer } from './buffer_webgl';
import { WebGLGPUBuffer } from './buffer_webgl';

export class WebGLBindGroup extends WebGLGPUObject<unknown> implements BindGroup {
private _layout: BindGroupLayout;
private _dynamicOffsets: number[];
private _resources: Record<string, WebGLGPUBuffer | [WebGLBaseTexture, WebGLTextureSampler]>;
constructor(device: WebGLDevice, layout: BindGroupLayout) {
super(device);
this._device = device;
this._layout = layout;
this._dynamicOffsets = null;
this._resources = {};
this._object = {};
for (const entry of this._layout.entries) {
if (entry.buffer && entry.buffer.hasDynamicOffset) {
if (!this._dynamicOffsets) {
this._dynamicOffsets = [];
}
this._dynamicOffsets[entry.buffer.dynamicOffsetIndex] = 0;
}
}
}
getGPUId(): string {
return String(this._uid);
}
getLayout(): BindGroupLayout {
return this._layout;
}
getBuffer(name: string): GPUDataBuffer {
return this._getBuffer(name, true);
}
setBuffer(name: string, buffer: GPUDataBuffer) {
getDynamicOffsets(): number[] {
return this._dynamicOffsets;
}
setBuffer(name: string, buffer: GPUDataBuffer, offset?: number, bindOffset?: number, bindSize?: number) {
const bindName = this._layout.nameMap?.[name] ?? name;
for (const entry of this._layout.entries) {
if (entry.name === bindName) {
Expand All @@ -46,6 +62,9 @@ export class WebGLBindGroup extends WebGLGPUObject<unknown> implements BindGroup
} else if (buffer !== this._resources[entry.name]) {
this._resources[entry.name] = buffer as WebGLGPUBuffer;
}
if (entry.buffer.hasDynamicOffset) {
this._dynamicOffsets[entry.buffer.dynamicOffsetIndex] = offset ?? 0;
}
}
return;
}
Expand Down Expand Up @@ -122,20 +141,22 @@ export class WebGLBindGroup extends WebGLGPUObject<unknown> implements BindGroup
}
apply(program: WebGLGPUProgram, offsets?: Iterable<number>) {
const webgl2 = this._device.isWebGL2;
let dynamicOffsetIndex = 0;
const dynamicOffsets = offsets ?? this.getDynamicOffsets();
for (let i = 0; i < this._layout.entries.length; i++) {
const entry = this._layout.entries[i];
const res = this._resources[entry.name];
if (res instanceof WebGLStructuredBuffer) {
if (res instanceof WebGLGPUBuffer) {
if (webgl2) {
if (entry.buffer.hasDynamicOffset) {
const offset = offsets?.[dynamicOffsetIndex] || 0;
dynamicOffsetIndex++;
program.setBlock((entry.type as PBStructTypeInfo).structName, res, offset);
program.setBlock(
(entry.type as PBStructTypeInfo).structName,
res,
dynamicOffsets[entry.buffer.dynamicOffsetIndex]
);
} else {
program.setBlock((entry.type as PBStructTypeInfo).structName, res, 0);
}
} else {
} else if (res instanceof WebGLStructuredBuffer) {
program.setUniform(entry.name, res.getUniformData().uniforms);
}
} else if (Array.isArray(res)) {
Expand Down
4 changes: 4 additions & 0 deletions libs/backend-webgl/src/capabilities_webgl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,13 @@ export class WebGLShaderCaps implements ShaderCaps {
supportHighPrecisionInt: boolean;
maxUniformBufferSize: number;
uniformBufferOffsetAlignment: number;
maxStorageBufferSize: number;
storageBufferOffsetAlignment: number;
constructor(gl: WebGLContext) {
this._extFragDepth = null;
this._extStandardDerivatives = null;
this.maxStorageBufferSize = 0;
this.storageBufferOffsetAlignment = 0;
if (isWebGL2(gl)) {
this.supportFragmentDepth = true;
this.supportStandardDerivatives = true;
Expand Down
Loading

0 comments on commit adc46a4

Please sign in to comment.