@@ -22,63 +22,64 @@ type Adapter struct {
22
22
ref C.WGPUAdapter
23
23
}
24
24
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 )))
29
35
}
30
36
31
- features := make ([]FeatureName , size )
32
- C .wgpuAdapterEnumerateFeatures (p .ref , (* C .WGPUFeatureName )(unsafe .Pointer (& features [0 ])))
33
37
return features
34
38
}
35
39
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 ),
82
83
}
83
84
}
84
85
@@ -88,14 +89,14 @@ func (p *Adapter) GetInfo() AdapterInfo {
88
89
C .wgpuAdapterGetInfo (p .ref , & info )
89
90
90
91
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 ),
99
100
}
100
101
}
101
102
@@ -107,13 +108,13 @@ func (p *Adapter) HasFeature(feature FeatureName) bool {
107
108
type requestDeviceCb func (status RequestDeviceStatus , device * Device , message string )
108
109
109
110
//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 ) {
111
112
handle := * (* cgo .Handle )(userdata )
112
113
defer handle .Delete ()
113
114
114
115
cb , ok := handle .Value ().(requestDeviceCb )
115
116
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 ) ))
117
118
}
118
119
}
119
120
@@ -138,7 +139,8 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
138
139
label := C .CString (descriptor .Label )
139
140
defer C .free (unsafe .Pointer (label ))
140
141
141
- desc .label = label
142
+ desc .label .data = label
143
+ desc .label .length = C .WGPU_STRLEN
142
144
}
143
145
144
146
requiredFeatureCount := len (descriptor .RequiredFeatures )
@@ -154,11 +156,9 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
154
156
}
155
157
156
158
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
159
160
160
- l := descriptor .RequiredLimits .Limits
161
- requiredLimits .limits = C.WGPULimits {
161
+ requiredLimits := C.WGPULimits {
162
162
maxTextureDimension1D : C .uint32_t (l .MaxTextureDimension1D ),
163
163
maxTextureDimension2D : C .uint32_t (l .MaxTextureDimension2D ),
164
164
maxTextureDimension3D : C .uint32_t (l .MaxTextureDimension3D ),
@@ -180,7 +180,6 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
180
180
maxBufferSize : C .uint64_t (l .MaxBufferSize ),
181
181
maxVertexAttributes : C .uint32_t (l .MaxVertexAttributes ),
182
182
maxVertexBufferArrayStride : C .uint32_t (l .MaxVertexBufferArrayStride ),
183
- maxInterStageShaderComponents : C .uint32_t (l .MaxInterStageShaderComponents ),
184
183
maxInterStageShaderVariables : C .uint32_t (l .MaxInterStageShaderVariables ),
185
184
maxColorAttachments : C .uint32_t (l .MaxColorAttachments ),
186
185
maxComputeWorkgroupStorageSize : C .uint32_t (l .MaxComputeWorkgroupStorageSize ),
@@ -190,23 +189,27 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
190
189
maxComputeWorkgroupSizeZ : C .uint32_t (l .MaxComputeWorkgroupSizeZ ),
191
190
maxComputeWorkgroupsPerDimension : C .uint32_t (l .MaxComputeWorkgroupsPerDimension ),
192
191
}
193
- desc .requiredLimits = requiredLimits
194
192
195
- requiredLimitsExtras := (* C .WGPURequiredLimitsExtras )(C .malloc (C .size_t (unsafe .Sizeof (C.WGPURequiredLimitsExtras {}))))
196
- defer C .free (unsafe .Pointer (requiredLimitsExtras ))
193
+ desc .requiredLimits = & requiredLimits
197
194
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 ))
201
197
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 ))
203
204
}
204
205
205
206
if descriptor .DeviceLostCallback != nil {
206
207
handle := cgo .NewHandle (descriptor .DeviceLostCallback )
207
208
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
+ }
210
213
}
211
214
212
215
if descriptor .TracePath != "" {
@@ -219,7 +222,8 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
219
222
tracePath := C .CString (descriptor .TracePath )
220
223
defer C .free (unsafe .Pointer (tracePath ))
221
224
222
- deviceExtras .tracePath = tracePath
225
+ deviceExtras .tracePath .data = tracePath
226
+ deviceExtras .tracePath .length = C .WGPU_STRLEN
223
227
224
228
desc .nextInChain = (* C .WGPUChainedStruct )(unsafe .Pointer (deviceExtras ))
225
229
}
@@ -233,7 +237,10 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
233
237
device = d
234
238
}
235
239
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
+ })
237
244
238
245
if status != RequestDeviceStatusSuccess {
239
246
return nil , errors .New ("failed to request device" )
0 commit comments