feat: Validation Phase C — feature gates, texture usage, indirect count (#333) - #347
Conversation
…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).
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).
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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
left a comment
There was a problem hiding this comment.
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:
RequireFeaturepattern matches Rustrequire_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
vkCmdDrawIndirectCountwith proc address loading correct - SPIR-V capability scanning handles malformed modules gracefully
- Test infrastructure (
featureGateCasesregistry 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.
|
Addressed both blockers from the review:
Tests updated ( |
kolkov
left a comment
There was a problem hiding this comment.
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!
Summary
core.RequireFeature/FeatureError, a 25-feature registry (AllFeatureRequirements), format/shader/query gates, texture usage matrix, Float32Filterable bind-time checks, SPIR-VOpCapabilityintrospection, and publicMultiDrawIndirectCount/MultiDrawIndexedIndirectCountAPIs with Vulkan backend support.core/testutil.ValidationEnv, registry-drivenfeatureGateCases, smoke tests inwgpu_feature_gate_test.go, and layered indirect-count unit tests (HAL / core / public API). Docs:docs/VALIDATION-TESTING.md.Test plan
go test ./... -count=1go test ./core/... -run TestFeatureGates -vgo test ./hal/... ./core/... . -run 'IndirectCount|ValidateIndirect|RecordIndirectCount' -count=1GOGPU_GRAPHICS_API=software go test . -run FeatureGate -v