@zephyr3d/device 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"builtinfunc.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -126,7 +126,7 @@ const texStorageCtors = {
126
126
  Object.keys(texStorageCtors).forEach((k)=>{
127
127
  cls.prototype[k] = makeStorageTextureCtor(texStorageCtors[k]);
128
128
  });
129
- cls.prototype['atomic_int'] = function(...args) {
129
+ cls.prototype['atomic_int'] = makeConstructor(function(...args) {
130
130
  if (args.length > 1) {
131
131
  throw new PBParamLengthError('atomic_int');
132
132
  }
@@ -140,8 +140,8 @@ const texStorageCtors = {
140
140
  exp.$ast = new ASTShaderExpConstructor(exp.$typeinfo, []);
141
141
  return exp;
142
142
  }
143
- };
144
- cls.prototype['atomic_uint'] = function(...args) {
143
+ }, typeAtomicI32);
144
+ cls.prototype['atomic_uint'] = makeConstructor(function(...args) {
145
145
  if (args.length > 1) {
146
146
  throw new PBParamLengthError('atomic_uint');
147
147
  }
@@ -161,7 +161,7 @@ const texStorageCtors = {
161
161
  return exp;
162
162
  }
163
163
  return null;
164
- };
164
+ }, typeAtomicU32);
165
165
  } /*
166
166
  ProgramBuilder.prototype.texStorage1D = makeStorageTextureCtor(typeinfo.PBTextureType.TEX_STORAGE_1D);
167
167
  ProgramBuilder.prototype.texStorage2D = makeStorageTextureCtor(typeinfo.PBTextureType.TEX_STORAGE_2D);
@@ -712,14 +712,19 @@ const output_prefix_fs = 'zFSOutput_';
712
712
  name,
713
713
  new ASTDeclareVar(new ASTPrimitive(variable))
714
714
  ];
715
- Object.defineProperty(this._outputScope, name, {
716
- get: function() {
717
- return variable;
718
- },
719
- set: function(v) {
720
- getCurrentProgramBuilder().getCurrentScope().$ast.statements.push(new ASTAssignment(new ASTLValueScalar(variable.$ast), v instanceof PBShaderExp ? v.$ast : v));
721
- }
722
- });
715
+ for (const prop of [
716
+ name,
717
+ String(location)
718
+ ]){
719
+ Object.defineProperty(this._outputScope, prop, {
720
+ get: function() {
721
+ return variable;
722
+ },
723
+ set: function(v) {
724
+ getCurrentProgramBuilder().getCurrentScope().$ast.statements.push(new ASTAssignment(new ASTLValueScalar(variable.$ast), v instanceof PBShaderExp ? v.$ast : v));
725
+ }
726
+ });
727
+ }
723
728
  }
724
729
  /** @internal */ getDefaultSampler(t, comparison) {
725
730
  const u = this._uniforms.findIndex((val)=>val.texture?.exp === t);
@@ -1015,6 +1020,8 @@ const output_prefix_fs = 'zFSOutput_';
1015
1020
  const exp = new PBShaderExp(u.block.exp.$str, u.block.exp.$ast.getType());
1016
1021
  exp.$declareType = u.block.exp.$declareType;
1017
1022
  exp.$isBuffer = u.block.exp.$isBuffer;
1023
+ exp.$bindingSize = u.block.exp.$bindingSize;
1024
+ exp.$readonly = u.block.exp.$readonly;
1018
1025
  uniformList[u.group].push({
1019
1026
  member: exp,
1020
1027
  uniform: i
@@ -1054,11 +1061,13 @@ const output_prefix_fs = 'zFSOutput_';
1054
1061
  const uname = `${nameList[i]}_${k}_${p}`;
1055
1062
  const structName = this.generateStructureName();
1056
1063
  const t = getCurrentProgramBuilder().internalDefineStruct(structName, types[i], ShaderType.Compute, false, ...allLists[p].map((val)=>val.member));
1064
+ const readonly = i > 0 ? allLists[p].findIndex((val)=>!val.member.$readonly) < 0 : true;
1057
1065
  const exp = t();
1058
1066
  if (i === 0) {
1059
- exp.uniformBuffer(Number(k));
1067
+ exp.uniformBuffer(Number(k), p > 0 ? allLists[p][0].member.$bindingSize : 0);
1060
1068
  } else {
1061
- exp.storageBuffer(Number(k));
1069
+ exp.storageBuffer(Number(k), p > 0 ? allLists[p][0].member.$bindingSize : 0);
1070
+ exp.$readonly = readonly;
1062
1071
  }
1063
1072
  globalScope[uname] = exp;
1064
1073
  const index = this._uniforms.findIndex((val)=>val.block?.name === uname);
@@ -1120,6 +1129,8 @@ const output_prefix_fs = 'zFSOutput_';
1120
1129
  const exp = new PBShaderExp(u.block.exp.$str, u.block.exp.$ast.getType());
1121
1130
  exp.$declareType = u.block.exp.$declareType;
1122
1131
  exp.$isBuffer = u.block.exp.$isBuffer;
1132
+ exp.$bindingSize = u.block.exp.$bindingSize;
1133
+ exp.$readonly = u.block.exp.$readonly;
1123
1134
  sharedUniformList[u.group].push({
1124
1135
  member: exp,
1125
1136
  uniform: i
@@ -1132,6 +1143,8 @@ const output_prefix_fs = 'zFSOutput_';
1132
1143
  const exp = new PBShaderExp(u.block.exp.$str, u.block.exp.$ast.getType());
1133
1144
  exp.$declareType = u.block.exp.$declareType;
1134
1145
  exp.$isBuffer = u.block.exp.$isBuffer;
1146
+ exp.$bindingSize = u.block.exp.$bindingSize;
1147
+ exp.$readonly = u.block.exp.$readonly;
1135
1148
  vertexUniformList[u.group].push({
1136
1149
  member: exp,
1137
1150
  uniform: i
@@ -1144,6 +1157,8 @@ const output_prefix_fs = 'zFSOutput_';
1144
1157
  const exp = new PBShaderExp(u.block.exp.$str, u.block.exp.$ast.getType());
1145
1158
  exp.$declareType = u.block.exp.$declareType;
1146
1159
  exp.$isBuffer = u.block.exp.$isBuffer;
1160
+ exp.$bindingSize = u.block.exp.$bindingSize;
1161
+ exp.$readonly = u.block.exp.$readonly;
1147
1162
  fragUniformList[u.group].push({
1148
1163
  member: exp,
1149
1164
  uniform: i
@@ -1206,21 +1221,27 @@ const output_prefix_fs = 'zFSOutput_';
1206
1221
  const uname = `${nameList[j][i]}_${k}_${p}`;
1207
1222
  const structName = this.generateStructureName();
1208
1223
  const t = getCurrentProgramBuilder().internalDefineStruct(structName, layoutList[j], maskList[i], false, ...allLists[p].map((val)=>val.member));
1224
+ const readonly = j > 0 ? allLists[p].findIndex((val)=>!val.member.$readonly) < 0 : true;
1209
1225
  if (maskList[i] & ShaderType.Vertex) {
1210
1226
  const exp = t();
1227
+ if (j > 0 && !readonly) {
1228
+ throw new Error(`Storage buffer in vertex shader must be read-only`);
1229
+ }
1211
1230
  if (j === 0) {
1212
- exp.uniformBuffer(Number(k));
1231
+ exp.uniformBuffer(Number(k), p > 0 ? allLists[p][0].member.$bindingSize : 0);
1213
1232
  } else {
1214
- exp.storageBuffer(Number(k));
1233
+ exp.storageBuffer(Number(k), p > 0 ? allLists[p][0].member.$bindingSize : 0);
1234
+ exp.$readonly = readonly;
1215
1235
  }
1216
1236
  globalScopeVertex[uname] = exp;
1217
1237
  }
1218
1238
  if (maskList[i] & ShaderType.Fragment) {
1219
1239
  const exp = t();
1220
1240
  if (j === 0) {
1221
- exp.uniformBuffer(Number(k));
1241
+ exp.uniformBuffer(Number(k), p > 0 ? allLists[p][0].member.$bindingSize : 0);
1222
1242
  } else {
1223
- exp.storageBuffer(Number(k));
1243
+ exp.storageBuffer(Number(k), p > 0 ? allLists[p][0].member.$bindingSize : 0);
1244
+ exp.$readonly = readonly;
1224
1245
  }
1225
1246
  globalScopeFragmet[uname] = exp;
1226
1247
  }
@@ -1291,6 +1312,12 @@ const output_prefix_fs = 'zFSOutput_';
1291
1312
  }
1292
1313
  /** @internal */ createBindGroupLayouts(label) {
1293
1314
  const layouts = [];
1315
+ const dynamicOffsetIndex = [
1316
+ 0,
1317
+ 0,
1318
+ 0,
1319
+ 0
1320
+ ];
1294
1321
  for (const uniformInfo of this._uniforms){
1295
1322
  let layout = layouts[uniformInfo.group];
1296
1323
  if (!layout) {
@@ -1313,9 +1340,11 @@ const output_prefix_fs = 'zFSOutput_';
1313
1340
  entry.type = uniformInfo.block.exp.$typeinfo.clone(this.getBlockName(uniformInfo.block.name));
1314
1341
  const isStorage = uniformInfo.block.exp.$declareType === DeclareType.DECLARE_TYPE_STORAGE;
1315
1342
  entry.buffer = {
1316
- type: isStorage ? uniformInfo.block.exp.$ast.isWritable() ? 'storage' : 'read-only-storage' : 'uniform',
1317
- hasDynamicOffset: uniformInfo.block.dynamicOffset,
1318
- uniformLayout: entry.type.toBufferLayout(0, entry.type.layout)
1343
+ type: isStorage ? uniformInfo.block.exp.$readonly ? 'read-only-storage' : 'storage' : 'uniform',
1344
+ minBindingSize: uniformInfo.block.bindingSize,
1345
+ hasDynamicOffset: !!uniformInfo.block.bindingSize,
1346
+ uniformLayout: entry.type.toBufferLayout(0, entry.type.layout),
1347
+ dynamicOffsetIndex: !!uniformInfo.block.bindingSize ? dynamicOffsetIndex[uniformInfo.group]++ : -1
1319
1348
  };
1320
1349
  entry.name = uniformInfo.block.name;
1321
1350
  } else if (uniformInfo.texture) {
@@ -1593,7 +1622,7 @@ const output_prefix_fs = 'zFSOutput_';
1593
1622
  } else {
1594
1623
  uniformInfo.block = {
1595
1624
  name: name,
1596
- dynamicOffset: false,
1625
+ bindingSize: variable.$bindingSize,
1597
1626
  exp: variable
1598
1627
  };
1599
1628
  // throw new Error(`unsupported uniform type: ${name}`);
@@ -1768,7 +1797,7 @@ const output_prefix_fs = 'zFSOutput_';
1768
1797
  this[prop] = value;
1769
1798
  return true;
1770
1799
  }
1771
- if (!(this.$_scope instanceof PBGlobalScope) && value instanceof PBShaderExp && (value.isConstructor() || value.$typeinfo.isTextureType() && value.$ast instanceof ASTPrimitive && !value.$ast.name) && value.$declareType === DeclareType.DECLARE_TYPE_UNIFORM) {
1800
+ if (!(this.$_scope instanceof PBGlobalScope) && value instanceof PBShaderExp && (value.isConstructor() || value.$typeinfo.isTextureType() && value.$ast instanceof ASTPrimitive && !value.$ast.name) && (value.$declareType === DeclareType.DECLARE_TYPE_UNIFORM || value.$declareType === DeclareType.DECLARE_TYPE_STORAGE)) {
1772
1801
  // We are setting uniform a uniform, should invoke in the global scope
1773
1802
  this.$g[prop] = value;
1774
1803
  return true;
@@ -1783,6 +1812,8 @@ const output_prefix_fs = 'zFSOutput_';
1783
1812
  if (value instanceof PBShaderExp && !this.$_scope.$parent) {
1784
1813
  exp.$declareType = value.$declareType;
1785
1814
  exp.$isBuffer = value.$isBuffer;
1815
+ exp.$bindingSize = value.$bindingSize;
1816
+ exp.$readonly = value.$readonly;
1786
1817
  exp.$group = value.$group;
1787
1818
  exp.$attrib = value.$attrib;
1788
1819
  exp.$sampleType = value.$sampleType;
@@ -1 +1 @@
1
- {"version":3,"file":"programbuilder.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -408,6 +408,9 @@ var PBTypeClass;
408
408
  /** returns true if this is a primitive type */ isPrimitiveType() {
409
409
  return false;
410
410
  }
411
+ /** Wether this type have atomic members */ haveAtomicMembers() {
412
+ return false;
413
+ }
411
414
  /** returns true if this is a struct type */ isStructType() {
412
415
  return false;
413
416
  }
@@ -828,6 +831,17 @@ var PBTypeClass;
828
831
  /** Get member types of the struct type */ get structMembers() {
829
832
  return this.detail.structMembers;
830
833
  }
834
+ /** Whether this struct has atomic members */ haveAtomicMembers() {
835
+ for (const member of this.structMembers){
836
+ if (member.type.isStructType() && member.type.haveAtomicMembers()) {
837
+ return true;
838
+ } else if (member.type.isArrayType() && member.type.haveAtomicMembers()) {
839
+ return true;
840
+ } else {
841
+ return member.type.isAtomicI32() || member.type.isAtomicU32();
842
+ }
843
+ }
844
+ }
831
845
  /**
832
846
  * Creates a new struct type by extending this type
833
847
  * @param name - Name of the new struct type
@@ -873,17 +887,6 @@ var PBTypeClass;
873
887
  return varName ? `${this.structName} ${varName}` : this.structName;
874
888
  }
875
889
  }
876
- /** @internal */ isWritable() {
877
- for (const member of this.structMembers){
878
- if (member.type.isAtomicI32() || member.type.isAtomicU32()) {
879
- return true;
880
- }
881
- if (member.type.isStructType() && member.type.isWritable()) {
882
- return true;
883
- }
884
- }
885
- return false;
886
- }
887
890
  /** @internal */ getLayoutAlignment(layout) {
888
891
  if (layout === 'packed') {
889
892
  return 1;
@@ -997,6 +1000,13 @@ var PBTypeClass;
997
1000
  /** Get dimension of the array type */ get dimension() {
998
1001
  return this.detail.dimension;
999
1002
  }
1003
+ /** Wether array have atomic members */ haveAtomicMembers() {
1004
+ if (this.elementType.isStructType() || this.elementType.isArrayType()) {
1005
+ return this.elementType.haveAtomicMembers();
1006
+ } else {
1007
+ return this.elementType.isAtomicI32() || this.elementType.isAtomicU32();
1008
+ }
1009
+ }
1000
1010
  /** {@inheritDoc PBTypeInfo.isArrayType} */ isArrayType() {
1001
1011
  return true;
1002
1012
  }
@@ -1087,6 +1097,9 @@ var PBTypeClass;
1087
1097
  this.id = null;
1088
1098
  }
1089
1099
  }
1100
+ /** {@inheritDoc PBTypeInfo.haveAtomicMembers} */ haveAtomicMembers() {
1101
+ return this.pointerType.haveAtomicMembers();
1102
+ }
1090
1103
  /** {@inheritDoc PBTypeInfo.isPointerType} */ isPointerType() {
1091
1104
  return true;
1092
1105
  }
@@ -1121,6 +1134,9 @@ var PBTypeClass;
1121
1134
  constructor(){
1122
1135
  super(PBTypeClass.ATOMIC_I32, null);
1123
1136
  }
1137
+ /** {@inheritDoc PBTypeInfo.isPointerType} */ haveAtomicMembers() {
1138
+ return true;
1139
+ }
1124
1140
  /** @internal */ isAtomicI32() {
1125
1141
  return true;
1126
1142
  }
@@ -1161,6 +1177,9 @@ var PBTypeClass;
1161
1177
  constructor(){
1162
1178
  super(PBTypeClass.ATOMIC_U32, null);
1163
1179
  }
1180
+ /** {@inheritDoc PBTypeInfo.isPointerType} */ haveAtomicMembers() {
1181
+ return true;
1182
+ }
1164
1183
  /** @internal */ isAtomicU32() {
1165
1184
  return true;
1166
1185
  }
@@ -1250,9 +1269,15 @@ var PBTypeClass;
1250
1269
  /** Returns true if this is a readable storage texture type */ get readable() {
1251
1270
  return this.detail.readable;
1252
1271
  }
1272
+ set readable(val) {
1273
+ this.detail.readable = !!val;
1274
+ }
1253
1275
  /** Returns true if this is a writable storage texture type */ get writable() {
1254
1276
  return this.detail.writable;
1255
1277
  }
1278
+ set writable(val) {
1279
+ this.detail.writable = !!val;
1280
+ }
1256
1281
  /** @internal */ isStorable() {
1257
1282
  return true;
1258
1283
  }
@@ -1298,7 +1323,7 @@ var PBTypeClass;
1298
1323
  if (this.isStorageTexture()) {
1299
1324
  const storageTexelFormat = storageTexelFormatMap[this.storageTexelFormat];
1300
1325
  // storage textures currently only support 'write' access control
1301
- const accessMode = 'write'; //this.readable ? (this.writable ? 'read_write' : 'read') : 'write';
1326
+ const accessMode = this.writable ? this.readable ? 'read_write' : 'write' : 'read'; // this.readable ? (this.writable ? 'read_write' : 'read') : 'write';
1302
1327
  typename = `${typename}<${storageTexelFormat}, ${accessMode}>`;
1303
1328
  }
1304
1329
  return varName ? `${varName}: ${typename}` : typename;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/device.js CHANGED
@@ -6,6 +6,7 @@ import { ProgramBuilder } from './builder/programbuilder.js';
6
6
  import { DeviceGPUObjectAddedEvent, DeviceGPUObjectRemovedEvent, DeviceResizeEvent } from './base_types.js';
7
7
  import '@zephyr3d/base';
8
8
  import { DrawText } from './helpers/drawtext.js';
9
+ import { Pool } from './pool.js';
9
10
 
10
11
  /**
11
12
  * Base class for rendering device
@@ -28,6 +29,9 @@ import { DrawText } from './helpers/drawtext.js';
28
29
  _backend;
29
30
  _beginFrameCounter;
30
31
  _programBuilder;
32
+ _pool;
33
+ _temporalFramebuffer;
34
+ _vSync;
31
35
  _stateStack;
32
36
  constructor(cvs, backend){
33
37
  this._backend = backend;
@@ -59,7 +63,8 @@ import { DrawText } from './helpers/drawtext.js';
59
63
  FPS: 0,
60
64
  drawCalls: 0,
61
65
  computeCalls: 0,
62
- nextFrameCall: []
66
+ nextFrameCall: [],
67
+ nextFrameCallNext: []
63
68
  };
64
69
  this._programBuilder = new ProgramBuilder(this);
65
70
  this._cpuTimer = new CPUTimer();
@@ -71,6 +76,9 @@ import { DrawText } from './helpers/drawtext.js';
71
76
  };
72
77
  this._stateStack = [];
73
78
  this._beginFrameCounter = 0;
79
+ this._pool = new Pool(this);
80
+ this._temporalFramebuffer = false;
81
+ this._vSync = true;
74
82
  this._registerEventHandlers();
75
83
  }
76
84
  get backend() {
@@ -91,6 +99,15 @@ import { DrawText } from './helpers/drawtext.js';
91
99
  get type() {
92
100
  return this._backend.typeName();
93
101
  }
102
+ get vSync() {
103
+ return this._vSync;
104
+ }
105
+ set vSync(val) {
106
+ this._vSync = !!val;
107
+ }
108
+ get pool() {
109
+ return this._pool;
110
+ }
94
111
  get runLoopFunction() {
95
112
  return this._runLoopFunc;
96
113
  }
@@ -103,6 +120,31 @@ import { DrawText } from './helpers/drawtext.js';
103
120
  drawText(text, x, y, color) {
104
121
  DrawText.drawText(this, text, color, x, y);
105
122
  }
123
+ setFramebuffer(colorOrRT, depth, sampleCount) {
124
+ let newRT = null;
125
+ let temporal = false;
126
+ if (!Array.isArray(colorOrRT)) {
127
+ newRT = colorOrRT ?? null;
128
+ } else {
129
+ const colorAttachments = colorOrRT.map((val)=>val.texture ?? val);
130
+ newRT = this._pool.createTemporalFramebuffer(false, colorAttachments, depth, sampleCount, true);
131
+ for(let i = 0; i < colorOrRT.length; i++){
132
+ const rt = colorOrRT[i];
133
+ newRT.setColorAttachmentMipLevel(i, rt.texture ? rt.miplevel ?? 0 : 0);
134
+ newRT.setColorAttachmentLayer(i, rt.texture ? rt.face ?? 0 : 0);
135
+ newRT.setColorAttachmentCubeFace(i, rt.texture ? rt.layer ?? 0 : 0);
136
+ }
137
+ temporal = true;
138
+ }
139
+ const currentRT = this.getFramebuffer();
140
+ if (currentRT !== newRT) {
141
+ if (this._temporalFramebuffer) {
142
+ this._pool.releaseFrameBuffer(currentRT);
143
+ }
144
+ this._temporalFramebuffer = temporal;
145
+ this._setFramebuffer(newRT);
146
+ }
147
+ }
106
148
  disposeObject(obj, remove = true) {
107
149
  if (obj) {
108
150
  if (remove) {
@@ -144,6 +186,7 @@ import { DrawText } from './helpers/drawtext.js';
144
186
  this._beginFrameCounter++;
145
187
  this._beginFrameTime = this._cpuTimer.now();
146
188
  this.updateFrameInfo();
189
+ this._pool.autoRelease();
147
190
  return this.onBeginFrame();
148
191
  }
149
192
  endFrame() {
@@ -222,15 +265,13 @@ import { DrawText } from './helpers/drawtext.js';
222
265
  this._frameInfo.nextFrameCall.push(f);
223
266
  }
224
267
  }
225
- cancelNextFrameCall(f) {
226
- const index = this._frameInfo.nextFrameCall.indexOf(f);
227
- if (index >= 0) {
228
- this._frameInfo.nextFrameCall.splice(index, 1);
229
- }
230
- }
231
268
  exitLoop() {
232
- if (this._runningLoop) {
233
- cancelAnimationFrame(this._runningLoop);
269
+ if (this._runningLoop !== null) {
270
+ if (this._runningLoop !== 0) {
271
+ cancelAnimationFrame(this._runningLoop);
272
+ } else {
273
+ this.cancelNextFrame(this._runningLoop);
274
+ }
234
275
  this._runningLoop = null;
235
276
  }
236
277
  }
@@ -246,7 +287,15 @@ import { DrawText } from './helpers/drawtext.js';
246
287
  const that = this;
247
288
  that._runLoopFunc = func;
248
289
  (function entry() {
249
- that._runningLoop = requestAnimationFrame(entry);
290
+ if (that._vSync) {
291
+ that._runningLoop = requestAnimationFrame(entry);
292
+ } else {
293
+ that._runningLoop = that.nextFrame(()=>{
294
+ if (that._runningLoop !== null) {
295
+ entry();
296
+ }
297
+ });
298
+ }
250
299
  if (that.beginFrame()) {
251
300
  that._runLoopFunc(that);
252
301
  that.endFrame();
@@ -407,10 +456,13 @@ import { DrawText } from './helpers/drawtext.js';
407
456
  this._frameInfo.elapsedTimeCPU = cpuTime;
408
457
  }
409
458
  }
410
- for (const f of this._frameInfo.nextFrameCall){
459
+ const tmp = this._frameInfo.nextFrameCall;
460
+ this._frameInfo.nextFrameCall = this._frameInfo.nextFrameCallNext;
461
+ this._frameInfo.nextFrameCallNext = tmp;
462
+ for (const f of this._frameInfo.nextFrameCallNext){
411
463
  f();
412
464
  }
413
- this._frameInfo.nextFrameCall.length = 0;
465
+ this._frameInfo.nextFrameCallNext.length = 0;
414
466
  }
415
467
  getGPUObjectList(obj) {
416
468
  let list = null;
@@ -1 +1 @@
1
- {"version":3,"file":"device.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"device.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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