You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -336,17 +329,106 @@ judge if the current platform is moltenvk, for enabling some platform-specific w
336
329
#endif
337
330
```
338
331
339
-
# option macros
332
+
ncnn additionally defines most of the vulkan device-related features as macros, which we can use to distinguish different platforms, device extensions, features, and properties
333
+
334
+
### extension macros
335
+
336
+
When the device supports an extension, `ncnn_<extension_name>` is defined as the extension version
337
+
338
+
```c
339
+
voidmain()
340
+
{
341
+
#if ncnn_VK_KHR_16bit_storage
342
+
// here is the code for any device that supports VK_KHR_16bit_storage
343
+
#endif
344
+
345
+
#if ncnn_VK_KHR_sampler_ycbcr_conversion >= 10
346
+
// here is the code for any device that supports VK_KHR_sampler_ycbcr_conversion and version >= 10
347
+
#endif
348
+
}
349
+
```
350
+
351
+
### device feature and property macros
352
+
353
+
ncnn will query device features and properties and then define them as macros.
354
+
355
+
The macro name is `ncnn_<feature_name>` or `ncnn_<property_name>`
356
+
357
+
The `GL_EXT_shader_explicit_arithmetic_types_int64` extension will be automatically enabled without explicit code indication when the device supports `shaderInt64`
358
+
359
+
```c
360
+
voidmain()
361
+
{
362
+
#if ncnn_robustBufferAccess
363
+
// here is the code for any device that supports robustBufferAccess feature
364
+
#endif
365
+
366
+
#if ncnn_vendorID == 4318
367
+
// here is the vendor specific code, 4318 is nvidia graphics
368
+
#endif
369
+
370
+
#if ncnn_subgroupSize == 32
371
+
// here is the code path optimized for subgroup_size == 32
372
+
#endif
373
+
374
+
// use macro definitions
375
+
uint size; // dynamic value from some previous routines
376
+
if (size < ncnn_subgroupSize)
377
+
{
378
+
#if ncnn_supportedOperations & 4
379
+
// subgroup support arithmetic
380
+
#endif
381
+
382
+
#if ncnn_subgroup_arithmetic
383
+
// shorthand style for checking subgroup arithmetic :P
384
+
#endif
385
+
}
386
+
}
387
+
```
388
+
389
+
### validation layer macros
390
+
391
+
ncnn will define some additional convenient macros when the vulkan validation layer enabled
392
+
393
+
*`ncnn_enable_validataion_layer`
394
+
*`NCNN_LOGE`
395
+
396
+
currently, you have to modify the `ENABLE_VALIDATION_LAYER` definition at the beginning of `src/gpu.cpp` to `1` to enable these macros.
397
+
398
+
The `GL_EXT_debug_printf` extension will be enabled automatically without explicitly specifying it in your code.
399
+
400
+
```c
401
+
voidmain()
402
+
{
403
+
int gx = int(gl_GlobalInvocationID.x);
404
+
405
+
#if ncnn_enable_validataion_layer
406
+
NCNN_LOGE("gx = %d\n", gx);
407
+
#endif
408
+
}
409
+
```
410
+
411
+
At runtime, `NCNN_LOGE` will print out the value of `gx`
412
+
413
+
### option macros
340
414
341
415
enable glsl extension only if user enable some options
342
416
417
+
The `GL_EXT_shader_16bit_storage` extension will be automatically enabled without explicit code indication when the device supports 16-bit storage and the user turns on `opt.use_fp16_storage`
418
+
419
+
The `GL_EXT_shader_explicit_arithmetic_types_float16` extension will be automatically enabled without explicit code indication when the device supports 16-bit arithmetic and the user turns on `opt.use_fp16_arithmetic`
420
+
343
421
```c
422
+
voidmain()
423
+
{
344
424
#if NCNN_fp16_storage
345
-
#extension GL_EXT_shader_16bit_storage: require
425
+
// the user enable fp16 storage option and the device has fp16 storage support
0 commit comments