if (context == null) throw new Error('WebGL 2 is required')
gl = context
+ const MAX_VIEWPORT_DIMS = gl.getParameter(gl.MAX_VIEWPORT_DIMS) ?? [0x1000, 0x1000]
LOG: logger.log('NanoPow WebGL createCanvas', 'requested size', size)
- LOG: logger.log('NanoPow WebGL createCanvas', 'MAX_VIEWPORT_DIMS', ...gl.getParameter(gl.MAX_VIEWPORT_DIMS))
- size = Math.min(size, ...gl.getParameter(gl.MAX_VIEWPORT_DIMS))
+ LOG: logger.log('NanoPow WebGL createCanvas', 'MAX_VIEWPORT_DIMS', MAX_VIEWPORT_DIMS)
+ size = Math.min(size, ...MAX_VIEWPORT_DIMS)
size = Math.floor(size / 0x100) * 0x100
canvas.height = canvas.width = size
LOG: logger.log('NanoPow WebGL createCanvas', 'canvas size', canvas.height, canvas.width)
<head>
<link rel="icon" href="data:,">
<script type="module">
+ try {
let NanoPow, stats
try {
({ NanoPow, stats } = await import('../dist/main.min.js'))
const glSize = (canvas => {
const gl = canvas.getContext('webgl2')
- canvas.height = gl.getParameter(gl.MAX_VIEWPORT_DIMS)[0]
- canvas.width = gl.getParameter(gl.MAX_VIEWPORT_DIMS)[1]
+ const MAX_VIEWPORT_DIMS = gl.getParameter(gl.MAX_VIEWPORT_DIMS)
+ canvas.height = MAX_VIEWPORT_DIMS[0]
+ canvas.width = MAX_VIEWPORT_DIMS[1]
return Math.min(gl.drawingBufferHeight, gl.drawingBufferWidth)
})(new OffscreenCanvas(0, 0))
}
}
- export async function run (size, difficulty, effort, api, isOutputShown, isDebug, isSelfCheck) {
+ async function run (size, difficulty, effort, api, isOutputShown, isDebug, isSelfCheck) {
// Generate once on load to compile shaders and initialize buffers
await NanoPow.work_generate(random(), { api, difficulty: 0 })
const type = api
console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold')
}
- export async function score (runs, size, difficulty, effort, api) {
+ async function score (runs, size, difficulty, effort, api) {
console.log(`%cNanoPow ${api}`, 'color:green', `Calculate truncated harmonic mean of the truncated arithmetic rate across ${runs} runs of ${size} samples.`)
const rates = []
for (let i = 0; i < runs; i++) {
.then(() => event.target.disabled = false)
}
+ document.getElementById('api_webgpu').disabled = navigator?.gpu == null
+ document.getElementById('api_webgl').selected = navigator?.gpu == null
document.getElementById('btnStartTest').addEventListener('click', startTest)
document.getElementById('btnStartScore').addEventListener('click', startScore)
document.getElementById('effort').value = Math.max(1, Math.floor(navigator.hardwareConcurrency) / 2)
+ } catch (err) {
+ console.error(err)
+ }
</script>
<style>
body{background:black;color:white;}a{color:darkcyan;}input[type=number]{width:5em;}input[type=checkbox]{margin-right:2em;}
<span>
<label for="api">API</label>
<select id="api">
- <option>WebGPU</option>
- <option>WebGL</option>
+ <option id="api_webgpu">WebGPU</option>
+ <option id="api_webgl">WebGL</option>
<option>WASM</option>
<option>CPU</option>
</select>