Skip to content

feat: Validation Phase C — feature gates, texture usage, indirect count (#333) - #347

Merged
kolkov merged 5 commits into
mainfrom
feat/validation-phase-c
Sep 2, 2026
Merged

feat: Validation Phase C — feature gates, texture usage, indirect count (#333)#347
kolkov merged 5 commits into
mainfrom
feat/validation-phase-c

Conversation

@lkmavi

@lkmavi lkmavi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Implements Validation Phase C (feat: validation Phase C — expand to ~70% Rust wgpu-core parity #333): usage-time feature gates and texture usage validation toward ~70% Rust wgpu-core parity.
  • Adds core.RequireFeature / FeatureError, a 25-feature registry (AllFeatureRequirements), format/shader/query gates, texture usage matrix, Float32Filterable bind-time checks, SPIR-V OpCapability introspection, and public MultiDrawIndirectCount / MultiDrawIndexedIndirectCount APIs with Vulkan backend support.
  • Introduces tiered test infrastructure: core/testutil.ValidationEnv, registry-driven featureGateCases, smoke tests in wgpu_feature_gate_test.go, and layered indirect-count unit tests (HAL / core / public API). Docs: docs/VALIDATION-TESTING.md.

Test plan

  • go test ./... -count=1
  • go test ./core/... -run TestFeatureGates -v
  • go test ./hal/... ./core/... . -run 'IndirectCount|ValidateIndirect|RecordIndirectCount' -count=1
  • GOGPU_GRAPHICS_API=software go test . -run FeatureGate -v
  • CI green on all backends

…nt (#333)

Add usage-time validation toward Rust wgpu-core parity: RequireFeature registry,
format/shader/query gates, texture usage matrix, Float32Filterable bind checks,
SPIR-V capability scan, MultiDrawIndirectCount public API, and tiered test
infrastructure (ValidationEnv, registry-driven cases, indirect-count unit tests).
@lkmavi
lkmavi requested a review from kolkov as a code owner September 2, 2026 10:45
Run gofmt on touched files, extract CreateBindGroup validation helpers to
reduce gocognit complexity, preallocate SPIR-V test words, and nolint
vkMakeVersion patch param (used in api_test.go).
Add testutil, query, shader, SPIR-V, and indirect-count unit tests; test
helpers for validation-only devices/buffers; fix gosec bounds check in
SPIR-V capability scan.
Exercise MultiDrawIndexedIndirect, DrawIndexed firstInstance, indexed
indirect-count validation branches, and public MultiDraw*Count APIs.

@kolkov kolkov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work, @lkmavi! ~2,300 LOC, 15+ validation checks, ~80 new test cases, enterprise-quality test infrastructure (ValidationEnv, featureGateCases registry with completeness guard). The indirect count three-layer implementation with Vulkan native vkCmdDrawIndirectCount is particularly well done.

Two issues to fix before merge:

Blockers

B1. VAL-C16: Depth/stencil + RenderAttachment incorrectly rejected

// core/texture_usage_validate.go
if format.IsDepthStencil() {
    const forbidden = gputypes.TextureUsageRenderAttachment | gputypes.TextureUsageStorageBinding
    if usage&forbidden != 0 {
        return &CreateTextureError{Kind: CreateTextureErrorInvalidUsage}
    }
}

The W3C spec explicitly says RENDER_ATTACHMENT is used for both color AND depth/stencil attachments (spec line 4510): "The texture can be used as a color or depth/stencil attachment in a render pass." Rejecting depth textures with RenderAttachment usage breaks every application with depth testing. Rust wgpu does NOT reject this at texture creation time.

Fix: remove TextureUsageRenderAttachment from the depth/stencil forbidden mask:

if format.IsDepthStencil() {
    if usage.Contains(gputypes.TextureUsageStorageBinding) {
        return &CreateTextureError{Kind: CreateTextureErrorInvalidUsage}
    }
}

B2. VAL-C17: Storage + RenderAttachment blanket rejection

if usage.Contains(gputypes.TextureUsageStorageBinding) &&
    usage.Contains(gputypes.TextureUsageRenderAttachment) {
    return &CreateTextureError{Kind: CreateTextureErrorInvalidUsage}
}

The W3C WebGPU spec does NOT prohibit this combination at texture creation time. Usage conflicts are detected at bind-time and draw-time, not creation time. Rust wgpu does not have this check. A texture can be RGBA8Unorm with both Storage and RenderAttachment usages — valid per spec.

Fix: remove this check entirely, or narrow it to specific invalid cases (if any exist).


Everything else is solid:

  • RequireFeature pattern matches Rust require_features() (resource.rs:429)
  • Feature gates for BC/ETC2/ASTC/DepthClipControl/ShaderF16/Timestamp all correct
  • Indirect count buffer validation thorough (nil, usage, alignment, bounds)
  • Vulkan vkCmdDrawIndirectCount with proc address loading correct
  • SPIR-V capability scanning handles malformed modules gracefully
  • Test infrastructure (featureGateCases registry with completeness guard) is reusable and excellent
  • CI 15/15 green

Happy to re-review after the two texture usage fixes!

Align VAL-C16/C17 with W3C WebGPU and Rust wgpu: depth/stencil may use
RENDER_ATTACHMENT; Storage+RenderAttachment is not rejected at create time.
@lkmavi

lkmavi commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Addressed both blockers from the review:

  • B1 (VAL-C16): depth/stencil now only rejects StorageBinding; RenderAttachment is allowed (W3C: color or depth/stencil attachment).
  • B2 (VAL-C17): removed the blanket Storage+RenderAttachment rejection at creation; conflicts stay bind/draw-time. Dropped unused dimension param.

Tests updated (StorageAndRenderAttachment expects success; added DepthRenderAttachment). Ready for re-review.

@kolkov kolkov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both blockers verified as fixed:

B1: Depth/stencil now only rejects StorageBinding; RenderAttachment allowed (W3C spec line 4510).
B2: Blanket Storage+RenderAttachment rejection removed. Test confirms RGBA8 with both usages succeeds.

15/15 CI green. ~2,300 LOC, 15+ validation checks, ~80 tests, enterprise test infra. Excellent work, @lkmavi!

@kolkov
kolkov merged commit a6dddd6 into main Sep 2, 2026
15 checks passed
gusevgrishaem1 added a commit to gusevgrishaem1/wgpu that referenced this pull request Sep 3, 2026
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.

2 participants