-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
328 additions
and
215 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,67 @@ | ||
import { AppBase } from 'playcanvas'; | ||
|
||
class DummyWebGPU { | ||
constructor(app: AppBase) { | ||
if (app.graphicsDevice.isWebGPU) { | ||
console.log('WebGPU is already created, skipping dummy WebGPU creation'); | ||
return; | ||
} | ||
|
||
if (!navigator.gpu) { | ||
console.log('WebGPU is not supported, skipping dummy WebGPU creation'); | ||
return; | ||
} | ||
|
||
// Create a new canvas for WebGPU with a smaller size | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = 20; | ||
canvas.height = 20; | ||
canvas.style.position = 'absolute'; | ||
canvas.style.top = '20px'; | ||
canvas.style.left = '20px'; | ||
document.body.appendChild(canvas); | ||
|
||
(async () => { | ||
const adapter = await navigator.gpu.requestAdapter(); | ||
const device = await adapter.requestDevice(); | ||
|
||
console.log('Created WebGPU device used for profiling'); | ||
|
||
// Create a WebGPU context for the new canvas | ||
const context = canvas.getContext('webgpu') as any; | ||
|
||
// Configure the WebGPU context | ||
context.configure({ device, format: 'bgra8unorm' }); | ||
|
||
// Hook into the 'frameend' event | ||
app.on('frameend', () => { | ||
// Clear the WebGPU surface to red after WebGL rendering | ||
|
||
// Get the current texture to render to | ||
const textureView = context.getCurrentTexture().createView(); | ||
|
||
// Create a command encoder | ||
const commandEncoder = device.createCommandEncoder(); | ||
|
||
// Create a render pass descriptor with a red background | ||
const renderPassDescriptor = { | ||
colorAttachments: [{ | ||
view: textureView, | ||
clearValue: { r: 1.0, g: 0.0, b: 0.0, a: 1.0 }, // Red background | ||
loadOp: 'clear', | ||
storeOp: 'store' | ||
}] | ||
}; | ||
|
||
// render pass | ||
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor); | ||
passEncoder.end(); | ||
|
||
// Submit the commands to the GPU | ||
device.queue.submit([commandEncoder.finish()]); | ||
}); | ||
})(); | ||
} | ||
} | ||
|
||
export { DummyWebGPU }; |
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