Skip to content

Commit

Permalink
fixes for compute_js and to make it run on firefox nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Dec 4, 2024
1 parent b11ae16 commit 774e8fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/boids/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,11 @@ func (s *State) Render() error {
defer commandEncoder.Release()

computePass := commandEncoder.BeginComputePass(nil)
defer computePass.Release()
computePass.SetPipeline(s.computePipeline)
computePass.SetBindGroup(0, s.particleBindGroups[s.frameNum%2], nil)
computePass.DispatchWorkgroups(s.workGroupCount, 1, 1)
computePass.End()
computePass.Release() // must release immediately

renderPass := commandEncoder.BeginRenderPass(&wgpu.RenderPassDescriptor{
ColorAttachments: []wgpu.RenderPassColorAttachment{
Expand All @@ -334,12 +334,12 @@ func (s *State) Render() error {
},
},
})
defer renderPass.Release()
renderPass.SetPipeline(s.renderPipeline)
renderPass.SetVertexBuffer(0, s.particleBuffers[(s.frameNum+1)%2], 0, wgpu.WholeSize)
renderPass.SetVertexBuffer(1, s.vertexBuffer, 0, wgpu.WholeSize)
renderPass.Draw(3, NumParticles, 0, 0)
renderPass.End()
renderPass.Release() // must release

s.frameNum += 1

Expand Down
3 changes: 1 addition & 2 deletions examples/compute/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,18 @@ func main() {
defer encoder.Release()

computePass := encoder.BeginComputePass(nil)
defer computePass.Release()
computePass.SetPipeline(computePipeline)
computePass.SetBindGroup(0, bindGroup, nil)
computePass.DispatchWorkgroups(uint32(len(numbers)), 1, 1)
computePass.End()
computePass.Release() // <- must call this before doing submit: https://github.com/gfx-rs/wgpu/issues/6145 https://github.com/gfx-rs/wgpu-native/issues/412

encoder.CopyBufferToBuffer(storageBuffer, 0, stagingBuffer, 0, size)

cmdBuffer, err := encoder.Finish(nil)
if err != nil {
panic(err)
}
defer cmdBuffer.Release()
queue.Submit(cmdBuffer)

var status wgpu.BufferMapAsyncStatus
Expand Down
4 changes: 3 additions & 1 deletion wgpu/compute_pass_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func (g ComputePassEncoder) SetBindGroup(index uint32, bindGroup *BindGroup, dyn
params := make([]any, 3)
params[0] = index
params[1] = pointerToJS(bindGroup)
params[2] = dynamicOffsets
params[2] = mapSlice(dynamicOffsets, func(offset uint32) any {
return offset
})
g.jsValue.Call("setBindGroup", params...)
}

Expand Down
22 changes: 11 additions & 11 deletions wgpu/to_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,16 @@ func limitsFromJS(j js.Value) Limits {
MaxBufferSize: uint64(j.Get("maxBufferSize").Int()),
MaxVertexAttributes: uint32(j.Get("maxVertexAttributes").Int()),
MaxVertexBufferArrayStride: uint32(j.Get("maxVertexBufferArrayStride").Int()),
MaxInterStageShaderComponents: uint32(j.Get("maxInterStageShaderComponents").Int()),
MaxInterStageShaderVariables: uint32(j.Get("maxInterStageShaderVariables").Int()),
MaxColorAttachments: uint32(j.Get("maxColorAttachments").Int()),
MaxColorAttachmentBytesPerSample: uint32(j.Get("maxColorAttachmentBytesPerSample").Int()),
MaxComputeWorkgroupStorageSize: uint32(j.Get("maxComputeWorkgroupStorageSize").Int()),
MaxComputeInvocationsPerWorkgroup: uint32(j.Get("maxComputeInvocationsPerWorkgroup").Int()),
MaxComputeWorkgroupSizeX: uint32(j.Get("maxComputeWorkgroupSizeX").Int()),
MaxComputeWorkgroupSizeY: uint32(j.Get("maxComputeWorkgroupSizeY").Int()),
MaxComputeWorkgroupSizeZ: uint32(j.Get("maxComputeWorkgroupSizeZ").Int()),
MaxComputeWorkgroupsPerDimension: uint32(j.Get("maxComputeWorkgroupsPerDimension").Int()),
MaxPushConstantSize: 128,
// MaxInterStageShaderComponents: uint32(j.Get("maxInterStageShaderComponents").Int()), // no present on firefox
MaxInterStageShaderVariables: uint32(j.Get("maxInterStageShaderVariables").Int()),
MaxColorAttachments: uint32(j.Get("maxColorAttachments").Int()),
MaxColorAttachmentBytesPerSample: uint32(j.Get("maxColorAttachmentBytesPerSample").Int()),
MaxComputeWorkgroupStorageSize: uint32(j.Get("maxComputeWorkgroupStorageSize").Int()),
MaxComputeInvocationsPerWorkgroup: uint32(j.Get("maxComputeInvocationsPerWorkgroup").Int()),
MaxComputeWorkgroupSizeX: uint32(j.Get("maxComputeWorkgroupSizeX").Int()),
MaxComputeWorkgroupSizeY: uint32(j.Get("maxComputeWorkgroupSizeY").Int()),
MaxComputeWorkgroupSizeZ: uint32(j.Get("maxComputeWorkgroupSizeZ").Int()),
MaxComputeWorkgroupsPerDimension: uint32(j.Get("maxComputeWorkgroupsPerDimension").Int()),
MaxPushConstantSize: 128,
}
}

0 comments on commit 774e8fe

Please sign in to comment.