-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial refactor to how bind groups can be used with non-persistent U…
…Bs (#6341) * Initial refactor to how bind groups can be used with non-persistent UBs * types fix * reverted a small thing --------- Co-authored-by: Martin Valigursky <[email protected]>
- Loading branch information
1 parent
9b9285f
commit 95ddb6c
Showing
8 changed files
with
127 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { DebugHelper } from '../../core/debug.js'; | ||
import { BindGroupFormat, BindUniformBufferFormat } from './bind-group-format.js'; | ||
import { BindGroup } from './bind-group.js'; | ||
import { SHADERSTAGE_FRAGMENT, SHADERSTAGE_VERTEX, UNIFORM_BUFFER_DEFAULT_SLOT_NAME } from './constants.js'; | ||
|
||
/** | ||
* A base class representing a single per platform buffer. | ||
* | ||
* @ignore | ||
*/ | ||
class DynamicBuffer { | ||
/** @type {import('./graphics-device.js').GraphicsDevice} */ | ||
device; | ||
|
||
/** | ||
* A cache of bind groups for each uniform buffer size, which is used to avoid creating a new | ||
* bind group for each uniform buffer. | ||
* | ||
* @type {Map<number, BindGroup>} | ||
*/ | ||
bindGroupCache = new Map(); | ||
|
||
constructor(device) { | ||
this.device = device; | ||
|
||
// format of the bind group | ||
this.bindGroupFormat = new BindGroupFormat(this.device, [ | ||
new BindUniformBufferFormat(UNIFORM_BUFFER_DEFAULT_SLOT_NAME, SHADERSTAGE_VERTEX | SHADERSTAGE_FRAGMENT) | ||
]); | ||
} | ||
|
||
getBindGroup(ub) { | ||
const ubSize = ub.format.byteSize; | ||
let bindGroup = this.bindGroupCache.get(ubSize); | ||
if (!bindGroup) { | ||
|
||
// bind group | ||
// we pass ub to it, but internally only its size is used | ||
bindGroup = new BindGroup(this.device, this.bindGroupFormat, ub); | ||
DebugHelper.setName(bindGroup, `DynamicBuffer-BindGroup_${bindGroup.id}-${ubSize}`); | ||
bindGroup.update(); | ||
|
||
this.bindGroupCache.set(ubSize, bindGroup); | ||
} | ||
|
||
return bindGroup; | ||
} | ||
} | ||
|
||
export { DynamicBuffer }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters