Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for undefined constants instead of zero values #218

Merged
merged 5 commits into from
Jan 4, 2023

Conversation

rajveermalviya
Copy link
Collaborator

@rajveermalviya rajveermalviya commented Oct 11, 2022

Align better with other webgpu-headers implementations for unset/undefined values.
Currently we take zero for indicating unset/undefined values. But webgpu-headers defines constants which should be used instead.

This introduces some breaking changes

  • WGPULimits struct will have to be declared like this:
- (WGPULimits){
-     .maxBindGroups = 1,
- }
+ (WGPULimits){
+     .maxBindGroups = 1,
+     .maxTextureDimension1D = WGPU_LIMIT_U32_UNDEFINED,
+     .maxTextureDimension2D = WGPU_LIMIT_U32_UNDEFINED,
+     .maxTextureDimension3D = WGPU_LIMIT_U32_UNDEFINED,
+     .maxTextureArrayLayers = WGPU_LIMIT_U32_UNDEFINED,
+     .maxDynamicUniformBuffersPerPipelineLayout = WGPU_LIMIT_U32_UNDEFINED,
+     .maxDynamicStorageBuffersPerPipelineLayout = WGPU_LIMIT_U32_UNDEFINED,
+     .maxSampledTexturesPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
+     .maxSamplersPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
+     .maxStorageBuffersPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
+     .maxStorageTexturesPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
+     .maxUniformBuffersPerShaderStage = WGPU_LIMIT_U32_UNDEFINED,
+     .maxUniformBufferBindingSize = WGPU_LIMIT_U64_UNDEFINED,
+     .maxStorageBufferBindingSize = WGPU_LIMIT_U64_UNDEFINED,
+     .minUniformBufferOffsetAlignment = WGPU_LIMIT_U32_UNDEFINED,
+     .minStorageBufferOffsetAlignment = WGPU_LIMIT_U32_UNDEFINED,
+     .maxVertexBuffers = WGPU_LIMIT_U32_UNDEFINED,
+     .maxVertexAttributes = WGPU_LIMIT_U32_UNDEFINED,
+     .maxVertexBufferArrayStride = WGPU_LIMIT_U32_UNDEFINED,
+     .maxInterStageShaderComponents = WGPU_LIMIT_U32_UNDEFINED,
+     .maxComputeWorkgroupStorageSize = WGPU_LIMIT_U32_UNDEFINED,
+     .maxComputeInvocationsPerWorkgroup = WGPU_LIMIT_U32_UNDEFINED,
+     .maxComputeWorkgroupSizeX = WGPU_LIMIT_U32_UNDEFINED,
+     .maxComputeWorkgroupSizeY = WGPU_LIMIT_U32_UNDEFINED,
+     .maxComputeWorkgroupSizeZ = WGPU_LIMIT_U32_UNDEFINED,
+     .maxComputeWorkgroupsPerDimension = WGPU_LIMIT_U32_UNDEFINED,
+ }
  • use WGPU_ARRAY_LAYER_COUNT_UNDEFINED instead of 0 for WGPUTextureViewDescriptor.arrayLayerCount.
  • use WGPU_COPY_STRIDE_UNDEFINED instead of 0 for WGPUTextureDataLayout.bytesPerRow & WGPUTextureDataLayout.rowsPerImage.
  • use WGPU_MIP_LEVEL_COUNT_UNDEFINED instead of 0 for WGPUTextureViewDescriptor.mipLevelCount.
  • use WGPU_WHOLE_MAP_SIZE for size param in wgpuBufferGetMappedRange & wgpuBufferGetConstMappedRange.
  • use WGPU_WHOLE_SIZE instead of 0 for:
    • size param in wgpuCommandEncoderClearBuffer.
    • size param in wgpuRenderPassEncoderSetIndexBuffer.
    • size param in wgpuRenderPassEncoderSetVertexBuffer.
    • size param in wgpuRenderBundleEncoderSetIndexBuffer.
    • size param in wgpuRenderBundleEncoderSetVertexBuffer.
    • WGPUBufferBindingLayout.minBindingSize.
    • WGPUBindGroupEntry.size.

Fixes #214

Makefile Show resolved Hide resolved
src/conv.rs Outdated Show resolved Hide resolved
@rajveermalviya rajveermalviya force-pushed the use-undefined-constants branch from cee035b to 39ba477 Compare November 27, 2022 13:15
@cwfitzgerald cwfitzgerald merged commit 6e18d0c into gfx-rs:master Jan 4, 2023
@almarklein
Copy link
Collaborator

almarklein commented Jan 11, 2023

I understand that this change was done because other implementations seem to do things this way, but to be honest this approach feels rather fragile to me.

As an example, In #235 I update the webgpu.h, which introduces a new field in the Limits: the maxBufferSize. It took me about 2 hours today to figure out that I also should update the limit defaults. The nasty thing about this is that (from how I understand this) every downstream application will have to update their default limits. I foresee many devs spending hours in frustration ...

And then there's the fact that there is WGPU_LIMIT_U32_UNDEFINED and WGPU_LIMIT_U64_UNDEFINED. If the type of a field is changed upstream (from u32 to u64, or back) this will cause a lot of pain downstream.

I'm not sure what the most elegant solution would be, but I imagine that it would help a lot if we had a function to create a struct populated with these undefined-placeholders. Then here in wgpu-native we could make sure to keep that up-to-date, and save pain downstream.

@almarklein almarklein mentioned this pull request Jan 11, 2023
@rajveermalviya
Copy link
Collaborator Author

There's also some discussion here about having the default struct macros to be included in webgpu.h. It would probably be best if that happens.

@almarklein
Copy link
Collaborator

almarklein commented Jan 30, 2023

To work around this issue in wgpu-py I create the adapter, request its limits, and then use these as the default limits for creating devices.

@rajveermalviya rajveermalviya deleted the use-undefined-constants branch March 6, 2023 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistency in undefined values in requiredLimits
3 participants