Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gpu/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// note: WriteBuffer is the preferred method for writing, so we only need to manage Read

// BufferMapAsyncError returns an error message if the status is not success.
func BufferMapAsyncError(status wgpu.BufferMapAsyncStatus) error {
if status != wgpu.BufferMapAsyncStatusSuccess {
func BufferMapAsyncError(status wgpu.MapAsyncStatus) error {

Check failure on line 17 in gpu/buffer.go

View workflow job for this annotation

GitHub Actions / build

undefined: wgpu.MapAsyncStatus
if status != wgpu.MapAsyncStatusSuccess {

Check failure on line 18 in gpu/buffer.go

View workflow job for this annotation

GitHub Actions / build

undefined: wgpu.MapAsyncStatusSuccess
return errors.New("gpu BufferMapAsync was not successful")
}
return nil
Expand All @@ -24,8 +24,8 @@
// BufferReadSync does a MapAsync on given buffer, waiting on the device
// until the sync is complete, and returning error if any issues.
func BufferReadSync(device *Device, size int, buffer *wgpu.Buffer) error {
var status wgpu.BufferMapAsyncStatus
err := buffer.MapAsync(wgpu.MapModeRead, 0, uint64(size), func(s wgpu.BufferMapAsyncStatus) {
var status wgpu.MapAsyncStatus

Check failure on line 27 in gpu/buffer.go

View workflow job for this annotation

GitHub Actions / build

undefined: wgpu.MapAsyncStatus
err := buffer.MapAsync(wgpu.MapModeRead, 0, uint64(size), func(s wgpu.MapAsyncStatus) {

Check failure on line 28 in gpu/buffer.go

View workflow job for this annotation

GitHub Actions / build

undefined: wgpu.MapAsyncStatus
status = s
})
if errors.Log(err) != nil {
Expand All @@ -44,9 +44,9 @@
return nil
}
var errs []error
status := make([]wgpu.BufferMapAsyncStatus, nv)
status := make([]wgpu.MapAsyncStatus, nv)

Check failure on line 47 in gpu/buffer.go

View workflow job for this annotation

GitHub Actions / build

undefined: wgpu.MapAsyncStatus
for i, vl := range values {
err := vl.readBuffer.MapAsync(wgpu.MapModeRead, 0, uint64(vl.AllocSize), func(s wgpu.BufferMapAsyncStatus) {
err := vl.readBuffer.MapAsync(wgpu.MapModeRead, 0, uint64(vl.AllocSize), func(s wgpu.MapAsyncStatus) {

Check failure on line 49 in gpu/buffer.go

View workflow job for this annotation

GitHub Actions / build

undefined: wgpu.MapAsyncStatus
status[i] = s
})
if err != nil {
Expand Down
16 changes: 7 additions & 9 deletions gpu/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,28 @@
// hardware, so we may need to detect that. OTOH it probably won't be useful for compute anyway,
// but we can just sort that out later
// note: on web / chromium / dawn, limited to 10: https://issues.chromium.org/issues/366151398?pli=1
limits.MaxStorageBuffersPerShaderStage = gpu.Limits.Limits.MaxStorageBuffersPerShaderStage
// fmt.Println("MaxStorageBuffersPerShaderStage:", gpu.Limits.Limits.MaxStorageBuffersPerShaderStage)
limits.MaxStorageBuffersPerShaderStage = gpu.Limits.MaxStorageBuffersPerShaderStage
// fmt.Println("MaxStorageBuffersPerShaderStage:", gpu.Limits.MaxStorageBuffersPerShaderStage)
// note: these limits are being processed and allow the MaxBufferSize to be the
// controlling factor -- if we don't set these, then the slrand example doesn't
// work above a smaller limit.
// TODO: converting these limits to int may cause issues on 32-bit systems
limits.MaxUniformBufferBindingSize = uint64(MemSizeAlignDown(int(gpu.Limits.Limits.MaxUniformBufferBindingSize), int(gpu.Limits.Limits.MinUniformBufferOffsetAlignment)))
limits.MaxUniformBufferBindingSize = uint64(MemSizeAlignDown(int(gpu.Limits.MaxUniformBufferBindingSize), int(gpu.Limits.MinUniformBufferOffsetAlignment)))

limits.MaxStorageBufferBindingSize = uint64(MemSizeAlignDown(int(gpu.Limits.Limits.MaxStorageBufferBindingSize), int(gpu.Limits.Limits.MinStorageBufferOffsetAlignment)))
limits.MaxStorageBufferBindingSize = uint64(MemSizeAlignDown(int(gpu.Limits.MaxStorageBufferBindingSize), int(gpu.Limits.MinStorageBufferOffsetAlignment)))
// note: this limit is not working properly:
g4 := uint64(0xFFFFFF00)
limits.MaxBufferSize = uint64(MemSizeAlignDown(int(min(gpu.Limits.Limits.MaxBufferSize, g4)), int(gpu.Limits.Limits.MinStorageBufferOffsetAlignment)))
limits.MaxBufferSize = uint64(MemSizeAlignDown(int(min(gpu.Limits.MaxBufferSize, g4)), int(gpu.Limits.MinStorageBufferOffsetAlignment)))
if limits.MaxBufferSize == 0 {
limits.MaxBufferSize = g4
}
// limits.MaxBindGroups = gpu.Limits.Limits.MaxBindGroups // note: no point in changing -- web constraint
// limits.MaxBindGroups = gpu.Limits.MaxBindGroups // note: no point in changing -- web constraint

if Debug {
fmt.Printf("Requesting sizes: MaxStorageBufferBindingSize: %X MaxBufferSize: %X\n", limits.MaxStorageBufferBindingSize, limits.MaxBufferSize)
}
desc := wgpu.DeviceDescriptor{
RequiredLimits: &wgpu.RequiredLimits{
Limits: limits,
},
RequiredLimits: &limits,

Check failure on line 68 in gpu/device.go

View workflow job for this annotation

GitHub Actions / build

cannot use &limits (value of type *wgpu.Limits) as *wgpu.RequiredLimits value in struct literal
}
wdev, err := gpu.GPU.RequestDevice(&desc)
if errors.Log(err) != nil {
Expand Down
2 changes: 1 addition & 1 deletion gpu/gpipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
if pl.System.Render().Depth.texture != nil {
pd.DepthStencil = &wgpu.DepthStencilState{
Format: pl.System.Render().Depth.Format.Format,
DepthWriteEnabled: true,
DepthWriteEnabled: wgpu.OptionalBoolTrue,

Check failure on line 188 in gpu/gpipeline.go

View workflow job for this annotation

GitHub Actions / build

undefined: wgpu.OptionalBoolTrue
DepthCompare: wgpu.CompareFunctionLess,
StencilFront: wgpu.StencilFaceState{
Compare: wgpu.CompareFunctionAlways,
Expand Down
24 changes: 12 additions & 12 deletions gpu/gpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
Properties wgpu.AdapterInfo

// Limits are the limits of the current GPU adapter.
Limits wgpu.SupportedLimits
Limits wgpu.Limits

// ComputeOnly indicates if this GPU is only used for compute,
// which determines if it listens to GPU_COMPUTE_DEVICE
Expand Down Expand Up @@ -175,13 +175,13 @@
fmt.Println("gpu: Selected Device:", gpIndex, gp.DeviceName, " (set DebugAdapter to get more adapter info)")
}

gp.Limits = gp.GPU.GetLimits()

Check failure on line 178 in gpu/gpu.go

View workflow job for this annotation

GitHub Actions / build

cannot use gp.GPU.GetLimits() (value of type wgpu.SupportedLimits) as wgpu.Limits value in assignment

if DebugAdapter {
fmt.Println(gp.PropertiesString())
}

gp.MaxComputeWorkGroupCount1D = int(gp.Limits.Limits.MaxComputeWorkgroupsPerDimension)
gp.MaxComputeWorkGroupCount1D = int(gp.Limits.MaxComputeWorkgroupsPerDimension)
dv := actualVendorName(&gp.Properties)
if Debug || DebugAdapter {
fmt.Println("GPU device vendor:", dv)
Expand All @@ -201,7 +201,7 @@
// string that the adapter VendorName contains,
// or, failing that, from the description.
func actualVendorName(ai *wgpu.AdapterInfo) string {
nm := strings.ToLower(ai.VendorName)
nm := strings.ToLower(ai.Vendor)

Check failure on line 204 in gpu/gpu.go

View workflow job for this annotation

GitHub Actions / build

ai.Vendor undefined (type *wgpu.AdapterInfo has no field or method Vendor)
// source: https://www.reddit.com/r/vulkan/comments/4ta9nj/is_there_a_comprehensive_list_of_the_names_and/
switch nm {
case "0x10de":
Expand All @@ -217,21 +217,21 @@
case "0x8086":
return "intel"
}
vd := strings.ToLower(ai.DriverDescription)
vd := strings.ToLower(ai.Description)
if strings.Contains(vd, "apple") {
return "apple"
}
return nm
}

func adapterName(ai *wgpu.AdapterInfo) string {
if ai.Name != "" && !strings.HasPrefix(ai.Name, "0x") {
return ai.Name
if ai.Device != "" && !strings.HasPrefix(ai.Device, "0x") {
return ai.Device
}
if ai.DriverDescription != "" && !strings.HasPrefix(ai.DriverDescription, "0x") {
return ai.DriverDescription
if ai.Description != "" && !strings.HasPrefix(ai.Description, "0x") {
return ai.Description
}
return ai.VendorName
return ai.Vendor
}

func (gp *GPU) SelectGraphicsGPU(gpus []*wgpu.Adapter) int {
Expand Down Expand Up @@ -259,7 +259,7 @@
}
pnm := adapterName(&props)
if strings.Contains(pnm, trgDevNm) {
devNm := props.Name
devNm := props.Device
if Debug {
log.Printf("gpu: selected device named: %s, specified in GPU_DEVICE or GPU_COMPUTE_DEVICE environment variable, index: %d\n", devNm, gi)
}
Expand Down Expand Up @@ -349,7 +349,7 @@
}
pnm := adapterName(&props)
if strings.Contains(pnm, trgDevNm) {
devNm := props.Name
devNm := props.Device
if Debug {
log.Printf("gpu: selected device named: %s, specified in GPU_DEVICE or GPU_COMPUTE_DEVICE environment variable, index: %d\n", devNm, gi)
}
Expand Down Expand Up @@ -408,7 +408,7 @@

// PropertiesString returns a human-readable summary of the GPU properties.
func (gp *GPU) PropertiesString() string {
return "\n######## GPU Properties\n" + reflectx.StringJSON(&gp.Properties) + reflectx.StringJSON(gp.Limits.Limits)
return "\n######## GPU Properties\n" + reflectx.StringJSON(&gp.Properties) + reflectx.StringJSON(gp.Limits)
}

// NoDisplayGPU Initializes WebGPU and returns that and a new
Expand Down
4 changes: 2 additions & 2 deletions gpu/shader.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func (sh *Shader) OpenFileFS(fsys fs.FS, fname string) error {
// OpenCode loads given WGSL ".wgl" code for the Shader.
func (sh *Shader) OpenCode(code string) error {
module, err := sh.device.Device.CreateShaderModule(&wgpu.ShaderModuleDescriptor{
Label: sh.Name,
WGSLDescriptor: &wgpu.ShaderModuleWGSLDescriptor{Code: code},
Label: sh.Name,
WGSLSource: &wgpu.ShaderSourceWGSL{Code: code},
})
if errors.Log(err) != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions gpu/texture.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ func (tx *Texture) SetFromGoImage(img image.Image, layer int) error {

// https://www.w3.org/TR/webgpu/#gpuimagecopytexture
tx.device.Queue.WriteTexture(
&wgpu.ImageCopyTexture{
&wgpu.TexelCopyTextureInfo{
Aspect: wgpu.TextureAspectAll,
Texture: tx.texture,
MipLevel: 0,
Origin: wgpu.Origin3D{X: 0, Y: 0, Z: 0},
},
rimg.Pix,
&wgpu.TextureDataLayout{
&wgpu.TexelCopyBufferLayout{
Offset: 0,
BytesPerRow: 4 * uint32(sz.X),
RowsPerImage: uint32(sz.Y),
Expand Down Expand Up @@ -259,9 +259,9 @@ func (tx *Texture) CopyToReadBuffer(cmd *wgpu.CommandEncoder) error {
size := tx.Format.Extent3D()
cmd.CopyTextureToBuffer(
tx.texture.AsImageCopy(),
&wgpu.ImageCopyBuffer{
&wgpu.TexelCopyBufferInfo{
Buffer: tx.readBuffer,
Layout: wgpu.TextureDataLayout{
Layout: wgpu.TexelCopyBufferLayout{
Offset: 0,
BytesPerRow: uint32(tx.ReadBufferDims.PaddedRowSize),
RowsPerImage: wgpu.CopyStrideUndefined,
Expand Down
2 changes: 1 addition & 1 deletion gpu/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var TypeSizes = map[Types]int{

// TypeToVertexFormat maps gpu.Types to WebGPU VertexFormat
var TypeToVertexFormat = map[Types]wgpu.VertexFormat{
UndefinedType: wgpu.VertexFormatUndefined,
UndefinedType: 0,
// Bool32: wgpu.VertexFormatUint32,
// Int16: wgpu.VertexFormatR16Sint,
// Uint16: wgpu.VertexFormatR16Uint,
Expand Down
4 changes: 2 additions & 2 deletions gpu/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ func (vs *Vars) AddGroup(role VarRoles, name ...string) *VarGroup {
}
vg.alignBytes = 1
if role == Uniform {
vg.alignBytes = int(vs.sys.GPU().Limits.Limits.MinUniformBufferOffsetAlignment)
vg.alignBytes = int(vs.sys.GPU().Limits.MinUniformBufferOffsetAlignment)
// note: wgpu-native reports alignment sizes of 64
// but then barfs when that is used. 256 seems to keep it happy
vg.alignBytes = max(vg.alignBytes, 256)
} else if role == Storage {
vg.alignBytes = int(vs.sys.GPU().Limits.Limits.MinStorageBufferOffsetAlignment)
vg.alignBytes = int(vs.sys.GPU().Limits.MinStorageBufferOffsetAlignment)
vg.alignBytes = max(vg.alignBytes, 256)
}
vs.Groups[idx] = vg
Expand Down