WebKit Bugzilla
Attachment 371375 Details for
Bug 198163
: [WHLSL] Implement array references
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Test
file.html (text/html), 4.26 KB, created by
Myles C. Maxfield
on 2019-06-04 21:41:41 PDT
(
hide
)
Description:
Test
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-06-04 21:41:41 PDT
Size:
4.26 KB
patch
obsolete
><!DOCTYPE html> ><html> ><head> ></head> ><body> ><canvas id="canvas" width="400" height="400"></canvas> ><script> >const shaderSource = ` >vertex float4 vertexShader(constant float4[] buffer : register(b0), uint id : SV_VertexID) : SV_Position { > return buffer[id]; >} > >fragment float4 fragmentShader(float4 position : SV_Position) : SV_Target 0 { > return float4(1.0, 1.0, 1.0, 1.0); >} >`; >async function start() { > const adapter = await navigator.gpu.requestAdapter(); > const device = await adapter.requestDevice(); > > const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true}); > const vertexStage = {module: shaderModule, entryPoint: "vertexShader"}; > const fragmentStage = {module: shaderModule, entryPoint: "fragmentShader"}; > const primitiveTopology = "triangle-strip"; > const rasterizationState = {frontFace: "cw", cullMode: "none"}; > const alphaBlend = {}; > const colorBlend = {}; > const colorStates = [{format: "rgba8unorm", alphaBlend, colorBlend, writeMask: 15}]; // GPUColorWriteBits.ALL > const depthStencilState = null; > > const vertexInput = {vertexBuffers: []}; > > const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "uniform-buffer"}]}; > const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor); > const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]}; > const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor); > > const renderPipelineDescriptor = {vertexStage, fragmentStage, primitiveTopology, rasterizationState, colorStates, depthStencilState, vertexInput, sampleCount: 1, layout: pipelineLayout}; > const renderPipeline = device.createRenderPipeline(renderPipelineDescriptor); > > const resourceBufferDescriptor = {size: 4 * 4 * Float32Array.BYTES_PER_ELEMENT, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.MAP_WRITE}; > const resourceBuffer = device.createBuffer(resourceBufferDescriptor); > const resourceBufferArrayBuffer = await resourceBuffer.mapWriteAsync(); > const resourceBufferFloat32Array = new Float32Array(resourceBufferArrayBuffer); > resourceBufferFloat32Array[0] = -0.5; > resourceBufferFloat32Array[1] = -0.5; > resourceBufferFloat32Array[2] = 1.0; > resourceBufferFloat32Array[3] = 1; > resourceBufferFloat32Array[4] = -0.5; > resourceBufferFloat32Array[5] = 0.5; > resourceBufferFloat32Array[6] = 1.0; > resourceBufferFloat32Array[7] = 1; > resourceBufferFloat32Array[8] = 0.5; > resourceBufferFloat32Array[9] = -0.5; > resourceBufferFloat32Array[10] = 1.0; > resourceBufferFloat32Array[11] = 1; > resourceBufferFloat32Array[12] = 0.5; > resourceBufferFloat32Array[13] = 0.5; > resourceBufferFloat32Array[14] = 1.0; > resourceBufferFloat32Array[15] = 1; > resourceBuffer.unmap(); > > const bufferBinding = {buffer: resourceBuffer, size: 4}; > const bindGroupBinding = {binding: 0, resource: bufferBinding}; > const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]}; > const bindGroup = device.createBindGroup(bindGroupDescriptor); > > const canvas = document.getElementById("canvas"); > const context = canvas.getContext("gpu"); > const swapChainDescriptor = {device, format: "bgra8unorm"}; > const swapChain = context.configureSwapChain(swapChainDescriptor); > const outputTexture = swapChain.getCurrentTexture(); > const outputTextureView = outputTexture.createDefaultView(); > > const commandEncoder = device.createCommandEncoder(); // {} > const red = {r: 0, g: 0, b: 1, a: 1}; > const colorAttachments = [{attachment: outputTextureView, resolveTarget: null, loadOp: "clear", storeOp: "store", clearColor: red}]; > const depthStencilAttachment = null; > const renderPassDescriptor = {colorAttachments, depthStencilAttachment}; > const renderPassEncoder = commandEncoder.beginRenderPass(renderPassDescriptor); > renderPassEncoder.setPipeline(renderPipeline); > renderPassEncoder.setBindGroup(0, bindGroup); > renderPassEncoder.draw(4, 1, 0, 0); > renderPassEncoder.endPass(); > const commandBuffer = commandEncoder.finish(); > device.getQueue().submit([commandBuffer]); > > if (window.testRunner) > testRunner.notifyDone(); >} >if (window.testRunner) > testRunner.waitUntilDone(); >window.addEventListener("load", start); ></script> ></body> ></html>
<!DOCTYPE html> <html> <head> </head> <body> <canvas id="canvas" width="400" height="400"></canvas> <script> const shaderSource = ` vertex float4 vertexShader(constant float4[] buffer : register(b0), uint id : SV_VertexID) : SV_Position { return buffer[id]; } fragment float4 fragmentShader(float4 position : SV_Position) : SV_Target 0 { return float4(1.0, 1.0, 1.0, 1.0); } `; async function start() { const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice(); const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true}); const vertexStage = {module: shaderModule, entryPoint: "vertexShader"}; const fragmentStage = {module: shaderModule, entryPoint: "fragmentShader"}; const primitiveTopology = "triangle-strip"; const rasterizationState = {frontFace: "cw", cullMode: "none"}; const alphaBlend = {}; const colorBlend = {}; const colorStates = [{format: "rgba8unorm", alphaBlend, colorBlend, writeMask: 15}]; // GPUColorWriteBits.ALL const depthStencilState = null; const vertexInput = {vertexBuffers: []}; const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "uniform-buffer"}]}; const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor); const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]}; const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor); const renderPipelineDescriptor = {vertexStage, fragmentStage, primitiveTopology, rasterizationState, colorStates, depthStencilState, vertexInput, sampleCount: 1, layout: pipelineLayout}; const renderPipeline = device.createRenderPipeline(renderPipelineDescriptor); const resourceBufferDescriptor = {size: 4 * 4 * Float32Array.BYTES_PER_ELEMENT, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.MAP_WRITE}; const resourceBuffer = device.createBuffer(resourceBufferDescriptor); const resourceBufferArrayBuffer = await resourceBuffer.mapWriteAsync(); const resourceBufferFloat32Array = new Float32Array(resourceBufferArrayBuffer); resourceBufferFloat32Array[0] = -0.5; resourceBufferFloat32Array[1] = -0.5; resourceBufferFloat32Array[2] = 1.0; resourceBufferFloat32Array[3] = 1; resourceBufferFloat32Array[4] = -0.5; resourceBufferFloat32Array[5] = 0.5; resourceBufferFloat32Array[6] = 1.0; resourceBufferFloat32Array[7] = 1; resourceBufferFloat32Array[8] = 0.5; resourceBufferFloat32Array[9] = -0.5; resourceBufferFloat32Array[10] = 1.0; resourceBufferFloat32Array[11] = 1; resourceBufferFloat32Array[12] = 0.5; resourceBufferFloat32Array[13] = 0.5; resourceBufferFloat32Array[14] = 1.0; resourceBufferFloat32Array[15] = 1; resourceBuffer.unmap(); const bufferBinding = {buffer: resourceBuffer, size: 4}; const bindGroupBinding = {binding: 0, resource: bufferBinding}; const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]}; const bindGroup = device.createBindGroup(bindGroupDescriptor); const canvas = document.getElementById("canvas"); const context = canvas.getContext("gpu"); const swapChainDescriptor = {device, format: "bgra8unorm"}; const swapChain = context.configureSwapChain(swapChainDescriptor); const outputTexture = swapChain.getCurrentTexture(); const outputTextureView = outputTexture.createDefaultView(); const commandEncoder = device.createCommandEncoder(); // {} const red = {r: 0, g: 0, b: 1, a: 1}; const colorAttachments = [{attachment: outputTextureView, resolveTarget: null, loadOp: "clear", storeOp: "store", clearColor: red}]; const depthStencilAttachment = null; const renderPassDescriptor = {colorAttachments, depthStencilAttachment}; const renderPassEncoder = commandEncoder.beginRenderPass(renderPassDescriptor); renderPassEncoder.setPipeline(renderPipeline); renderPassEncoder.setBindGroup(0, bindGroup); renderPassEncoder.draw(4, 1, 0, 0); renderPassEncoder.endPass(); const commandBuffer = commandEncoder.finish(); device.getQueue().submit([commandBuffer]); if (window.testRunner) testRunner.notifyDone(); } if (window.testRunner) testRunner.waitUntilDone(); window.addEventListener("load", start); </script> </body> </html>
View Attachment As Raw
Actions:
View
Attachments on
bug 198163
:
370830
|
370874
|
370912
|
371158
|
371243
|
371373
|
371374
|
371375
|
371471
|
371475
|
371555
|
371900