diff --git a/src/webgpu/api/operation/render_pass/clear_value.spec.ts b/src/webgpu/api/operation/render_pass/clear_value.spec.ts index 270f04a84431..da9c8d763400 100644 --- a/src/webgpu/api/operation/render_pass/clear_value.spec.ts +++ b/src/webgpu/api/operation/render_pass/clear_value.spec.ts @@ -32,10 +32,17 @@ g.test('stencil_clear_value') .combine('stencilFormat', kStencilTextureFormats) .combine('stencilClearValue', [0, 1, 0xff, 0x100 + 2, 0x10000 + 3]) .combine('applyStencilClearValueAsStencilReferenceValue', [true, false]) + .combine('createStencilTextureView', [false, true] as const) + .combine('createColorTextureView', [false, true] as const) ) .fn(t => { - const { stencilFormat, stencilClearValue, applyStencilClearValueAsStencilReferenceValue } = - t.params; + const { + stencilFormat, + stencilClearValue, + applyStencilClearValueAsStencilReferenceValue, + createStencilTextureView, + createColorTextureView, + } = t.params; t.skipIfTextureFormatNotSupported(stencilFormat); @@ -112,7 +119,7 @@ g.test('stencil_clear_value') const encoder = t.device.createCommandEncoder(); const depthStencilAttachment: GPURenderPassDepthStencilAttachment = { - view: stencilTexture.createView(), + view: createStencilTextureView ? stencilTexture.createView() : stencilTexture, depthClearValue: 0, stencilLoadOp: 'clear', stencilStoreOp: 'store', @@ -126,7 +133,7 @@ g.test('stencil_clear_value') const renderPassEncoder = encoder.beginRenderPass({ colorAttachments: [ { - view: colorTexture.createView(), + view: createColorTextureView ? colorTexture.createView() : colorTexture, loadOp: 'clear', storeOp: 'store', clearValue: [1, 0, 0, 1] as const, diff --git a/src/webgpu/api/operation/render_pass/resolve.spec.ts b/src/webgpu/api/operation/render_pass/resolve.spec.ts index 63c561b79f72..c7694f06e1e9 100644 --- a/src/webgpu/api/operation/render_pass/resolve.spec.ts +++ b/src/webgpu/api/operation/render_pass/resolve.spec.ts @@ -44,6 +44,13 @@ Test basic render pass resolve behavior for combinations of: .combine('slotsToResolve', kSlotsToResolve) .combine('resolveTargetBaseMipLevel', [0, 1] as const) .combine('resolveTargetBaseArrayLayer', [0, 1] as const) + .combine('createColorAttachmentView', [false, true] as const) + .combine('createResolveTargetTextureView', [false, true] as const) + .unless( + p => + !p.createResolveTargetTextureView && + (p.resolveTargetBaseMipLevel !== 0 || p.resolveTargetBaseArrayLayer !== 0) + ) ) .fn(t => { const targets: GPUColorTargetState[] = []; @@ -108,18 +115,23 @@ Test basic render pass resolve behavior for combinations of: const kResolveTargetSize = kSize << t.params.resolveTargetBaseMipLevel; for (let i = 0; i < t.params.numColorAttachments; i++) { - const colorAttachment = t - .createTextureTracked({ - format: kFormat, - size: [kSize, kSize, 1], - sampleCount: 4, - mipLevelCount: 1, - usage: - GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT, - }) - .createView(); - - let resolveTarget: GPUTextureView | undefined; + const colorAttachmentTexture = t.createTextureTracked({ + format: kFormat, + size: [kSize, kSize, 1], + sampleCount: 4, + mipLevelCount: 1, + usage: + GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT, + }); + + let colorAttachment: GPUTexture | GPUTextureView; + if (t.params.createResolveTargetTextureView) { + colorAttachment = colorAttachmentTexture.createView(); + } else { + colorAttachment = colorAttachmentTexture; + } + + let resolveTarget: GPUTexture | GPUTextureView | undefined; if (t.params.slotsToResolve.includes(i)) { const resolveTargetTexture = t.createTextureTracked({ format: kFormat, @@ -130,10 +142,14 @@ Test basic render pass resolve behavior for combinations of: }); resolveTargets.push(resolveTargetTexture); - resolveTarget = resolveTargetTexture.createView({ - baseMipLevel: t.params.resolveTargetBaseMipLevel, - baseArrayLayer: t.params.resolveTargetBaseArrayLayer, - }); + if (t.params.createResolveTargetTextureView) { + resolveTarget = resolveTargetTexture.createView({ + baseMipLevel: t.params.resolveTargetBaseMipLevel, + baseArrayLayer: t.params.resolveTargetBaseArrayLayer, + }); + } else { + resolveTarget = resolveTargetTexture; + } } // Clear to black for the load operation. After the draw, the top left half of the attachment diff --git a/src/webgpu/api/operation/rendering/basic.spec.ts b/src/webgpu/api/operation/rendering/basic.spec.ts index 1fe0951fbb28..fd03b677168c 100644 --- a/src/webgpu/api/operation/rendering/basic.spec.ts +++ b/src/webgpu/api/operation/rendering/basic.spec.ts @@ -9,40 +9,44 @@ import { checkElementsEqual } from '../../../util/check_contents.js'; export const g = makeTestGroup(AllFeaturesMaxLimitsGPUTest); -g.test('clear').fn(t => { - const dst = t.createBufferTracked({ - size: 4, - usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST, - }); +g.test('clear') + .params(u => u.beginSubcases().combine('createColorAttachmentView', [false, true] as const)) + .fn(t => { + const dst = t.createBufferTracked({ + size: 4, + usage: GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST, + }); - const colorAttachment = t.createTextureTracked({ - format: 'rgba8unorm', - size: { width: 1, height: 1, depthOrArrayLayers: 1 }, - usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT, - }); - const colorAttachmentView = colorAttachment.createView(); + const colorAttachment = t.createTextureTracked({ + format: 'rgba8unorm', + size: { width: 1, height: 1, depthOrArrayLayers: 1 }, + usage: GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT, + }); + const colorAttachmentView = t.params.createColorAttachmentView + ? colorAttachment.createView() + : colorAttachment; - const encoder = t.device.createCommandEncoder(); - const pass = encoder.beginRenderPass({ - colorAttachments: [ - { - view: colorAttachmentView, - clearValue: { r: 0.0, g: 1.0, b: 0.0, a: 1.0 }, - loadOp: 'clear', - storeOp: 'store', - }, - ], + const encoder = t.device.createCommandEncoder(); + const pass = encoder.beginRenderPass({ + colorAttachments: [ + { + view: colorAttachmentView, + clearValue: { r: 0.0, g: 1.0, b: 0.0, a: 1.0 }, + loadOp: 'clear', + storeOp: 'store', + }, + ], + }); + pass.end(); + encoder.copyTextureToBuffer( + { texture: colorAttachment, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } }, + { buffer: dst, bytesPerRow: 256 }, + { width: 1, height: 1, depthOrArrayLayers: 1 } + ); + t.device.queue.submit([encoder.finish()]); + + t.expectGPUBufferValuesEqual(dst, new Uint8Array([0x00, 0xff, 0x00, 0xff])); }); - pass.end(); - encoder.copyTextureToBuffer( - { texture: colorAttachment, mipLevel: 0, origin: { x: 0, y: 0, z: 0 } }, - { buffer: dst, bytesPerRow: 256 }, - { width: 1, height: 1, depthOrArrayLayers: 1 } - ); - t.device.queue.submit([encoder.finish()]); - - t.expectGPUBufferValuesEqual(dst, new Uint8Array([0x00, 0xff, 0x00, 0xff])); -}); g.test('fullscreen_quad').fn(t => { const dst = t.createBufferTracked({ diff --git a/src/webgpu/api/operation/texture_view/write.spec.ts b/src/webgpu/api/operation/texture_view/write.spec.ts index 81bc4a853346..90f0725a4015 100644 --- a/src/webgpu/api/operation/texture_view/write.spec.ts +++ b/src/webgpu/api/operation/texture_view/write.spec.ts @@ -72,7 +72,7 @@ const kTextureSize = 16; function writeTextureAndGetExpectedTexelView( t: GPUTest, method: TextureViewWriteMethod, - view: GPUTextureView, + view: GPUTexture | GPUTextureView, format: RegularTextureFormat, sampleCount: number ) { @@ -334,10 +334,19 @@ TODO: Test rgb10a2uint when TexelRepresentation.numericRange is made per-compone return true; }) - .combine('viewUsageMethod', kTextureViewUsageMethods) + .combine('bindTextureResource', [false, true] as const) + .expand('viewUsageMethod', function* ({ bindTextureResource }) { + if (bindTextureResource) { + yield; + } else { + for (const method of kTextureViewUsageMethods) { + yield method; + } + } + }) ) .fn(t => { - const { format, method, sampleCount, viewUsageMethod } = t.params; + const { format, method, sampleCount, bindTextureResource, viewUsageMethod } = t.params; t.skipIfTextureFormatNotSupported(format); if (sampleCount > 1) { t.skipIfTextureFormatNotMultisampled(format); @@ -377,9 +386,14 @@ TODO: Test rgb10a2uint when TexelRepresentation.numericRange is made per-compone sampleCount, }); - const view = texture.createView({ - usage: getTextureViewUsage(viewUsageMethod, textureUsageForMethod), - }); + let view: GPUTexture | GPUTextureView; + if (bindTextureResource) { + view = texture; + } else { + view = texture.createView({ + usage: getTextureViewUsage(viewUsageMethod!, textureUsageForMethod), + }); + } const expectedTexelView = writeTextureAndGetExpectedTexelView( t, method,