@@ -22,63 +22,64 @@ type Adapter struct {
2222 ref C.WGPUAdapter
2323}
2424
25- func (p * Adapter ) EnumerateFeatures () []FeatureName {
26- size := C .wgpuAdapterEnumerateFeatures (p .ref , nil )
27- if size == 0 {
28- return nil
25+ func (p * Adapter ) GetFeatures () []FeatureName {
26+ var supportedFeatures C.WGPUSupportedFeatures
27+ C .wgpuAdapterGetFeatures (p .ref , (* C .WGPUSupportedFeatures )(unsafe .Pointer (& supportedFeatures )))
28+ defer C .free (unsafe .Pointer (supportedFeatures .features ))
29+
30+ features := make ([]FeatureName , supportedFeatures .featureCount )
31+
32+ for i := range int (supportedFeatures .featureCount ) {
33+ offset := uintptr (i ) * unsafe .Sizeof (C .WGPUFeatureName (0 ))
34+ features [i ] = FeatureName (* (* C .WGPUFeatureName )(unsafe .Pointer (uintptr (unsafe .Pointer (supportedFeatures .features )) + offset )))
2935 }
3036
31- features := make ([]FeatureName , size )
32- C .wgpuAdapterEnumerateFeatures (p .ref , (* C .WGPUFeatureName )(unsafe .Pointer (& features [0 ])))
3337 return features
3438}
3539
36- func (p * Adapter ) GetLimits () SupportedLimits {
37- var supportedLimits C.WGPUSupportedLimits
38-
39- extras := (* C .WGPUSupportedLimitsExtras )(C .malloc (C .size_t (unsafe .Sizeof (C.WGPUSupportedLimitsExtras {}))))
40- defer C .free (unsafe .Pointer (extras ))
41- supportedLimits .nextInChain = (* C .WGPUChainedStructOut )(unsafe .Pointer (extras ))
42-
43- C .wgpuAdapterGetLimits (p .ref , & supportedLimits )
44-
45- limits := supportedLimits .limits
46- return SupportedLimits {
47- Limits {
48- MaxTextureDimension1D : uint32 (limits .maxTextureDimension1D ),
49- MaxTextureDimension2D : uint32 (limits .maxTextureDimension2D ),
50- MaxTextureDimension3D : uint32 (limits .maxTextureDimension3D ),
51- MaxTextureArrayLayers : uint32 (limits .maxTextureArrayLayers ),
52- MaxBindGroups : uint32 (limits .maxBindGroups ),
53- MaxBindingsPerBindGroup : uint32 (limits .maxBindingsPerBindGroup ),
54- MaxDynamicUniformBuffersPerPipelineLayout : uint32 (limits .maxDynamicUniformBuffersPerPipelineLayout ),
55- MaxDynamicStorageBuffersPerPipelineLayout : uint32 (limits .maxDynamicStorageBuffersPerPipelineLayout ),
56- MaxSampledTexturesPerShaderStage : uint32 (limits .maxSampledTexturesPerShaderStage ),
57- MaxSamplersPerShaderStage : uint32 (limits .maxSamplersPerShaderStage ),
58- MaxStorageBuffersPerShaderStage : uint32 (limits .maxStorageBuffersPerShaderStage ),
59- MaxStorageTexturesPerShaderStage : uint32 (limits .maxStorageTexturesPerShaderStage ),
60- MaxUniformBuffersPerShaderStage : uint32 (limits .maxUniformBuffersPerShaderStage ),
61- MaxUniformBufferBindingSize : uint64 (limits .maxUniformBufferBindingSize ),
62- MaxStorageBufferBindingSize : uint64 (limits .maxStorageBufferBindingSize ),
63- MinUniformBufferOffsetAlignment : uint32 (limits .minUniformBufferOffsetAlignment ),
64- MinStorageBufferOffsetAlignment : uint32 (limits .minStorageBufferOffsetAlignment ),
65- MaxVertexBuffers : uint32 (limits .maxVertexBuffers ),
66- MaxBufferSize : uint64 (limits .maxBufferSize ),
67- MaxVertexAttributes : uint32 (limits .maxVertexAttributes ),
68- MaxVertexBufferArrayStride : uint32 (limits .maxVertexBufferArrayStride ),
69- MaxInterStageShaderComponents : uint32 (limits .maxInterStageShaderComponents ),
70- MaxInterStageShaderVariables : uint32 (limits .maxInterStageShaderVariables ),
71- MaxColorAttachments : uint32 (limits .maxColorAttachments ),
72- MaxColorAttachmentBytesPerSample : uint32 (limits .maxColorAttachmentBytesPerSample ),
73- MaxComputeWorkgroupStorageSize : uint32 (limits .maxComputeWorkgroupStorageSize ),
74- MaxComputeInvocationsPerWorkgroup : uint32 (limits .maxComputeInvocationsPerWorkgroup ),
75- MaxComputeWorkgroupSizeX : uint32 (limits .maxComputeWorkgroupSizeX ),
76- MaxComputeWorkgroupSizeY : uint32 (limits .maxComputeWorkgroupSizeY ),
77- MaxComputeWorkgroupSizeZ : uint32 (limits .maxComputeWorkgroupSizeZ ),
78- MaxComputeWorkgroupsPerDimension : uint32 (limits .maxComputeWorkgroupsPerDimension ),
79-
80- MaxPushConstantSize : uint32 (extras .limits .maxPushConstantSize ),
81- },
40+ func (p * Adapter ) GetLimits () Limits {
41+ var limits C.WGPULimits
42+
43+ nativeLimits := (* C .WGPUNativeLimits )(C .malloc (C .size_t (unsafe .Sizeof (C.WGPUNativeLimits {}))))
44+ defer C .free (unsafe .Pointer (nativeLimits ))
45+ limits .nextInChain = (* C .WGPUChainedStructOut )(unsafe .Pointer (nativeLimits ))
46+
47+ C .wgpuAdapterGetLimits (p .ref , & limits )
48+
49+ return Limits {
50+ MaxTextureDimension1D : uint32 (limits .maxTextureDimension1D ),
51+ MaxTextureDimension2D : uint32 (limits .maxTextureDimension2D ),
52+ MaxTextureDimension3D : uint32 (limits .maxTextureDimension3D ),
53+ MaxTextureArrayLayers : uint32 (limits .maxTextureArrayLayers ),
54+ MaxBindGroups : uint32 (limits .maxBindGroups ),
55+ MaxBindingsPerBindGroup : uint32 (limits .maxBindingsPerBindGroup ),
56+ MaxDynamicUniformBuffersPerPipelineLayout : uint32 (limits .maxDynamicUniformBuffersPerPipelineLayout ),
57+ MaxDynamicStorageBuffersPerPipelineLayout : uint32 (limits .maxDynamicStorageBuffersPerPipelineLayout ),
58+ MaxSampledTexturesPerShaderStage : uint32 (limits .maxSampledTexturesPerShaderStage ),
59+ MaxSamplersPerShaderStage : uint32 (limits .maxSamplersPerShaderStage ),
60+ MaxStorageBuffersPerShaderStage : uint32 (limits .maxStorageBuffersPerShaderStage ),
61+ MaxStorageTexturesPerShaderStage : uint32 (limits .maxStorageTexturesPerShaderStage ),
62+ MaxUniformBuffersPerShaderStage : uint32 (limits .maxUniformBuffersPerShaderStage ),
63+ MaxUniformBufferBindingSize : uint64 (limits .maxUniformBufferBindingSize ),
64+ MaxStorageBufferBindingSize : uint64 (limits .maxStorageBufferBindingSize ),
65+ MinUniformBufferOffsetAlignment : uint32 (limits .minUniformBufferOffsetAlignment ),
66+ MinStorageBufferOffsetAlignment : uint32 (limits .minStorageBufferOffsetAlignment ),
67+ MaxVertexBuffers : uint32 (limits .maxVertexBuffers ),
68+ MaxBufferSize : uint64 (limits .maxBufferSize ),
69+ MaxVertexAttributes : uint32 (limits .maxVertexAttributes ),
70+ MaxVertexBufferArrayStride : uint32 (limits .maxVertexBufferArrayStride ),
71+ MaxInterStageShaderVariables : uint32 (limits .maxInterStageShaderVariables ),
72+ MaxColorAttachments : uint32 (limits .maxColorAttachments ),
73+ MaxColorAttachmentBytesPerSample : uint32 (limits .maxColorAttachmentBytesPerSample ),
74+ MaxComputeWorkgroupStorageSize : uint32 (limits .maxComputeWorkgroupStorageSize ),
75+ MaxComputeInvocationsPerWorkgroup : uint32 (limits .maxComputeInvocationsPerWorkgroup ),
76+ MaxComputeWorkgroupSizeX : uint32 (limits .maxComputeWorkgroupSizeX ),
77+ MaxComputeWorkgroupSizeY : uint32 (limits .maxComputeWorkgroupSizeY ),
78+ MaxComputeWorkgroupSizeZ : uint32 (limits .maxComputeWorkgroupSizeZ ),
79+ MaxComputeWorkgroupsPerDimension : uint32 (limits .maxComputeWorkgroupsPerDimension ),
80+
81+ MaxPushConstantSize : uint32 (nativeLimits .maxPushConstantSize ),
82+ MaxNonSamplerBindings : uint32 (nativeLimits .maxNonSamplerBindings ),
8283 }
8384}
8485
@@ -88,14 +89,14 @@ func (p *Adapter) GetInfo() AdapterInfo {
8889 C .wgpuAdapterGetInfo (p .ref , & info )
8990
9091 return AdapterInfo {
91- VendorId : uint32 (info .vendorID ),
92- VendorName : C . GoString (info .vendor ),
93- Architecture : C . GoString (info .architecture ),
94- DeviceId : uint32 (info .deviceID ),
95- Name : C . GoString (info .device ),
96- DriverDescription : C . GoString (info .description ),
97- AdapterType : AdapterType (info .adapterType ),
98- BackendType : BackendType (info .backendType ),
92+ Vendor : C . GoStringN ( info . vendor . data , C . int (info .vendor . length ) ),
93+ Architecture : C . GoStringN ( info . architecture . data , C . int (info .architecture . length ) ),
94+ Device : C . GoStringN (info .device . data , C . int ( info . device . length ) ),
95+ Description : C . GoStringN ( info . description . data , C . int (info .description . length ) ),
96+ AdapterType : AdapterType (info .adapterType ),
97+ BackendType : BackendType (info .backendType ),
98+ VendorId : uint32 (info .vendorID ),
99+ DeviceId : uint32 (info .deviceID ),
99100 }
100101}
101102
@@ -107,13 +108,13 @@ func (p *Adapter) HasFeature(feature FeatureName) bool {
107108type requestDeviceCb func (status RequestDeviceStatus , device * Device , message string )
108109
109110//export gowebgpu_request_device_callback_go
110- func gowebgpu_request_device_callback_go (status C.WGPURequestDeviceStatus , device C.WGPUDevice , message * C. char , userdata unsafe.Pointer ) {
111+ func gowebgpu_request_device_callback_go (status C.WGPURequestDeviceStatus , device C.WGPUDevice , message C. WGPUStringView , userdata unsafe.Pointer ) {
111112 handle := * (* cgo .Handle )(userdata )
112113 defer handle .Delete ()
113114
114115 cb , ok := handle .Value ().(requestDeviceCb )
115116 if ok {
116- cb (RequestDeviceStatus (status ), & Device {ref : device }, C .GoString (message ))
117+ cb (RequestDeviceStatus (status ), & Device {ref : device }, C .GoStringN (message . data , C . int ( message . length ) ))
117118 }
118119}
119120
@@ -138,7 +139,8 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
138139 label := C .CString (descriptor .Label )
139140 defer C .free (unsafe .Pointer (label ))
140141
141- desc .label = label
142+ desc .label .data = label
143+ desc .label .length = C .WGPU_STRLEN
142144 }
143145
144146 requiredFeatureCount := len (descriptor .RequiredFeatures )
@@ -154,11 +156,9 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
154156 }
155157
156158 if descriptor .RequiredLimits != nil {
157- requiredLimits := (* C .WGPURequiredLimits )(C .malloc (C .size_t (unsafe .Sizeof (C.WGPURequiredLimits {}))))
158- defer C .free (unsafe .Pointer (requiredLimits ))
159+ l := descriptor .RequiredLimits
159160
160- l := descriptor .RequiredLimits .Limits
161- requiredLimits .limits = C.WGPULimits {
161+ requiredLimits := C.WGPULimits {
162162 maxTextureDimension1D : C .uint32_t (l .MaxTextureDimension1D ),
163163 maxTextureDimension2D : C .uint32_t (l .MaxTextureDimension2D ),
164164 maxTextureDimension3D : C .uint32_t (l .MaxTextureDimension3D ),
@@ -180,7 +180,6 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
180180 maxBufferSize : C .uint64_t (l .MaxBufferSize ),
181181 maxVertexAttributes : C .uint32_t (l .MaxVertexAttributes ),
182182 maxVertexBufferArrayStride : C .uint32_t (l .MaxVertexBufferArrayStride ),
183- maxInterStageShaderComponents : C .uint32_t (l .MaxInterStageShaderComponents ),
184183 maxInterStageShaderVariables : C .uint32_t (l .MaxInterStageShaderVariables ),
185184 maxColorAttachments : C .uint32_t (l .MaxColorAttachments ),
186185 maxComputeWorkgroupStorageSize : C .uint32_t (l .MaxComputeWorkgroupStorageSize ),
@@ -190,23 +189,27 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
190189 maxComputeWorkgroupSizeZ : C .uint32_t (l .MaxComputeWorkgroupSizeZ ),
191190 maxComputeWorkgroupsPerDimension : C .uint32_t (l .MaxComputeWorkgroupsPerDimension ),
192191 }
193- desc .requiredLimits = requiredLimits
194192
195- requiredLimitsExtras := (* C .WGPURequiredLimitsExtras )(C .malloc (C .size_t (unsafe .Sizeof (C.WGPURequiredLimitsExtras {}))))
196- defer C .free (unsafe .Pointer (requiredLimitsExtras ))
193+ desc .requiredLimits = & requiredLimits
197194
198- requiredLimitsExtras .chain .next = nil
199- requiredLimitsExtras .chain .sType = C .WGPUSType_RequiredLimitsExtras
200- requiredLimitsExtras .limits .maxPushConstantSize = C .uint32_t (l .MaxPushConstantSize )
195+ nativeLimits := (* C .WGPUNativeLimits )(C .malloc (C .size_t (unsafe .Sizeof (C.WGPUNativeLimits {}))))
196+ defer C .free (unsafe .Pointer (nativeLimits ))
201197
202- desc .requiredLimits .nextInChain = (* C .WGPUChainedStruct )(unsafe .Pointer (requiredLimitsExtras ))
198+ nativeLimits .chain .next = nil
199+ nativeLimits .chain .sType = C .WGPUSType_NativeLimits
200+ nativeLimits .maxPushConstantSize = C .uint32_t (l .MaxPushConstantSize )
201+ nativeLimits .maxNonSamplerBindings = C .uint32_t (l .MaxNonSamplerBindings )
202+
203+ desc .requiredLimits .nextInChain = (* C .WGPUChainedStructOut )(unsafe .Pointer (nativeLimits ))
203204 }
204205
205206 if descriptor .DeviceLostCallback != nil {
206207 handle := cgo .NewHandle (descriptor .DeviceLostCallback )
207208
208- desc .deviceLostCallback = C .WGPUDeviceLostCallback (C .gowebgpu_device_lost_callback_c )
209- desc .deviceLostUserdata = unsafe .Pointer (& handle )
209+ desc .deviceLostCallbackInfo = C.WGPUDeviceLostCallbackInfo {
210+ callback : C .WGPUDeviceLostCallback (C .gowebgpu_device_lost_callback_c ),
211+ userdata1 : unsafe .Pointer (& handle ),
212+ }
210213 }
211214
212215 if descriptor .TracePath != "" {
@@ -219,7 +222,8 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
219222 tracePath := C .CString (descriptor .TracePath )
220223 defer C .free (unsafe .Pointer (tracePath ))
221224
222- deviceExtras .tracePath = tracePath
225+ deviceExtras .tracePath .data = tracePath
226+ deviceExtras .tracePath .length = C .WGPU_STRLEN
223227
224228 desc .nextInChain = (* C .WGPUChainedStruct )(unsafe .Pointer (deviceExtras ))
225229 }
@@ -233,7 +237,10 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
233237 device = d
234238 }
235239 handle := cgo .NewHandle (cb )
236- C .wgpuAdapterRequestDevice (p .ref , desc , C .WGPUAdapterRequestDeviceCallback (C .gowebgpu_request_device_callback_c ), unsafe .Pointer (& handle ))
240+ C .wgpuAdapterRequestDevice (p .ref , desc , C.WGPURequestDeviceCallbackInfo {
241+ callback : C .WGPURequestDeviceCallback (C .gowebgpu_request_device_callback_c ),
242+ userdata1 : unsafe .Pointer (& handle ),
243+ })
237244
238245 if status != RequestDeviceStatusSuccess {
239246 return nil , errors .New ("failed to request device" )
0 commit comments