Skip to content

Commit 1df0255

Browse files
Add wgpuInstanceHasWGSLLanguageFeature (#21055)
* Add wgpuInstanceHasWGSLLanguageFeature * Check wgslLanguageFeatures exists
1 parent 90ccf08 commit 1df0255

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

src/library_sigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,6 +1642,7 @@ sigs = {
16421642
wgpuDeviceSetUncapturedErrorCallback__sig: 'vppp',
16431643
wgpuGetProcAddress__sig: 'ppp',
16441644
wgpuInstanceCreateSurface__sig: 'ppp',
1645+
wgpuInstanceHasWGSLLanguageFeature__sig: 'ipi',
16451646
wgpuInstanceProcessEvents__sig: 'vp',
16461647
wgpuInstanceReference__sig: 'vp',
16471648
wgpuInstanceRelease__sig: 'vp',

src/library_webgpu.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ var LibraryWebGPU = {
350350
},
351351

352352
// This section is auto-generated. See system/include/webgpu/README.md for details.
353+
WGSLFeatureName: [
354+
undefined,
355+
'readonly_and_readwrite_storage_textures',
356+
'packed_4x8_integer_dot_product',
357+
'unrestricted_pointer_parameters',
358+
'pointer_composite_access',
359+
],
353360
AddressMode: [
354361
'repeat',
355362
'mirror-repeat',
@@ -2400,6 +2407,13 @@ var LibraryWebGPU = {
24002407
return WebGPU.mgrSurface.create(context);
24012408
},
24022409

2410+
wgpuInstanceHasWGSLLanguageFeature: (instance, featureEnumValue) => {
2411+
if (!('wgslLanguageFeatures' in navigator["gpu"])) {
2412+
return false;
2413+
}
2414+
return navigator["gpu"]["wgslLanguageFeatures"].has(WebGPU.WGSLFeatureName[featureEnumValue]);
2415+
},
2416+
24032417
wgpuInstanceProcessEvents: (instance) => {
24042418
// TODO: This could probably be emulated with ASYNCIFY.
24052419
#if ASSERTIONS

system/include/webgpu/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ test/runner browser.test_webgpu_basic_rendering --browser="google-chrome-unstabl
4141
Alternatively you can test your emscripten updates by building the source file, and then serve (e.g. use node http-server) and view in browser to make sure things work fine.
4242

4343
```
44+
emcc --clear-cache
4445
emcc test/webgpu_basic_rendering.cpp -sUSE_WEBGPU -o path/to/index.html
4546
```

system/include/webgpu/webgpu.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ struct WGPUVertexState;
169169
struct WGPUFragmentState;
170170
struct WGPURenderPipelineDescriptor;
171171

172+
typedef enum WGPUWGSLFeatureName {
173+
WGPUWGSLFeatureName_Undefined = 0x00000000,
174+
WGPUWGSLFeatureName_ReadonlyAndReadwriteStorageTextures = 0x00000001,
175+
WGPUWGSLFeatureName_Packed4x8IntegerDotProduct = 0x00000002,
176+
WGPUWGSLFeatureName_UnrestrictedPointerParameters = 0x00000003,
177+
WGPUWGSLFeatureName_PointerCompositeAccess = 0x00000004,
178+
WGPUWGSLFeatureName_Force32 = 0x7FFFFFFF
179+
} WGPUWGSLFeatureName WGPU_ENUM_ATTRIBUTE;
180+
172181
typedef enum WGPUAdapterType {
173182
WGPUAdapterType_DiscreteGPU = 0x00000000,
174183
WGPUAdapterType_IntegratedGPU = 0x00000001,
@@ -1345,6 +1354,7 @@ typedef void (*WGPUProcDeviceRelease)(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE
13451354

13461355
// Procs of Instance
13471356
typedef WGPUSurface (*WGPUProcInstanceCreateSurface)(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE;
1357+
typedef bool (*WGPUProcInstanceHasWGSLLanguageFeature)(WGPUInstance instance, WGPUWGSLFeatureName feature) WGPU_FUNCTION_ATTRIBUTE;
13481358
typedef void (*WGPUProcInstanceProcessEvents)(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE;
13491359
typedef void (*WGPUProcInstanceRequestAdapter)(WGPUInstance instance, WGPU_NULLABLE WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE;
13501360
typedef void (*WGPUProcInstanceReference)(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE;
@@ -1579,6 +1589,7 @@ WGPU_EXPORT void wgpuDeviceRelease(WGPUDevice device) WGPU_FUNCTION_ATTRIBUTE;
15791589

15801590
// Methods of Instance
15811591
WGPU_EXPORT WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, WGPUSurfaceDescriptor const * descriptor) WGPU_FUNCTION_ATTRIBUTE;
1592+
WGPU_EXPORT bool wgpuInstanceHasWGSLLanguageFeature(WGPUInstance instance, WGPUWGSLFeatureName feature) WGPU_FUNCTION_ATTRIBUTE;
15821593
WGPU_EXPORT void wgpuInstanceProcessEvents(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE;
15831594
WGPU_EXPORT void wgpuInstanceRequestAdapter(WGPUInstance instance, WGPU_NULLABLE WGPURequestAdapterOptions const * options, WGPURequestAdapterCallback callback, void * userdata) WGPU_FUNCTION_ATTRIBUTE;
15841595
WGPU_EXPORT void wgpuInstanceReference(WGPUInstance instance) WGPU_FUNCTION_ATTRIBUTE;

system/include/webgpu/webgpu_cpp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ namespace wgpu {
144144
static constexpr size_t kWholeMapSize = WGPU_WHOLE_MAP_SIZE;
145145
static constexpr uint64_t kWholeSize = WGPU_WHOLE_SIZE;
146146

147+
enum class WGSLFeatureName : uint32_t {
148+
Undefined = 0x00000000,
149+
ReadonlyAndReadwriteStorageTextures = 0x00000001,
150+
Packed4x8IntegerDotProduct = 0x00000002,
151+
UnrestrictedPointerParameters = 0x00000003,
152+
PointerCompositeAccess = 0x00000004,
153+
};
154+
147155
enum class AdapterType : uint32_t {
148156
DiscreteGPU = 0x00000000,
149157
IntegratedGPU = 0x00000001,
@@ -984,6 +992,7 @@ namespace wgpu {
984992
using ObjectBase::operator=;
985993

986994
Surface CreateSurface(SurfaceDescriptor const * descriptor) const;
995+
bool HasWGSLLanguageFeature(WGSLFeatureName feature) const;
987996
void ProcessEvents() const;
988997
void RequestAdapter(RequestAdapterOptions const * options, RequestAdapterCallback callback, void * userdata) const;
989998

system/lib/webgpu/webgpu_cpp.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77

88
namespace wgpu {
99

10+
// WGSLFeatureName
11+
12+
static_assert(sizeof(WGSLFeatureName) == sizeof(WGPUWGSLFeatureName), "sizeof mismatch for WGSLFeatureName");
13+
static_assert(alignof(WGSLFeatureName) == alignof(WGPUWGSLFeatureName), "alignof mismatch for WGSLFeatureName");
14+
15+
static_assert(static_cast<uint32_t>(WGSLFeatureName::Undefined) == WGPUWGSLFeatureName_Undefined, "value mismatch for WGSLFeatureName::Undefined");
16+
static_assert(static_cast<uint32_t>(WGSLFeatureName::ReadonlyAndReadwriteStorageTextures) == WGPUWGSLFeatureName_ReadonlyAndReadwriteStorageTextures, "value mismatch for WGSLFeatureName::ReadonlyAndReadwriteStorageTextures");
17+
static_assert(static_cast<uint32_t>(WGSLFeatureName::Packed4x8IntegerDotProduct) == WGPUWGSLFeatureName_Packed4x8IntegerDotProduct, "value mismatch for WGSLFeatureName::Packed4x8IntegerDotProduct");
18+
static_assert(static_cast<uint32_t>(WGSLFeatureName::UnrestrictedPointerParameters) == WGPUWGSLFeatureName_UnrestrictedPointerParameters, "value mismatch for WGSLFeatureName::UnrestrictedPointerParameters");
19+
static_assert(static_cast<uint32_t>(WGSLFeatureName::PointerCompositeAccess) == WGPUWGSLFeatureName_PointerCompositeAccess, "value mismatch for WGSLFeatureName::PointerCompositeAccess");
20+
1021
// AdapterType
1122

1223
static_assert(sizeof(AdapterType) == sizeof(WGPUAdapterType), "sizeof mismatch for AdapterType");
@@ -2024,6 +2035,10 @@ namespace wgpu {
20242035
auto result = wgpuInstanceCreateSurface(Get(), reinterpret_cast<WGPUSurfaceDescriptor const * >(descriptor));
20252036
return Surface::Acquire(result);
20262037
}
2038+
bool Instance::HasWGSLLanguageFeature(WGSLFeatureName feature) const {
2039+
auto result = wgpuInstanceHasWGSLLanguageFeature(Get(), static_cast<WGPUWGSLFeatureName>(feature));
2040+
return result;
2041+
}
20272042
void Instance::ProcessEvents() const {
20282043
wgpuInstanceProcessEvents(Get());
20292044
}

0 commit comments

Comments
 (0)