From a838c7d4978b49b5bb07f898f6400b05044b6b59 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Fri, 20 Sep 2019 22:59:47 +0000 Subject: [PATCH] Remove indirection for colorAttachments This is to match the work in progress webgpu.h header. BUG=dawn:22 Change-Id: I1371cda1b7666de8eb8283fa7e5da935d17e1d52 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9381 Commit-Queue: Corentin Wallez Reviewed-by: Austin Eng --- dawn.json | 2 +- examples/CHelloTriangle.cpp | 3 +- src/dawn_native/AttachmentState.cpp | 2 +- src/dawn_native/CommandEncoder.cpp | 48 +++++++------- src/tests/end2end/ClipSpaceTests.cpp | 4 +- src/tests/end2end/CullingTests.cpp | 4 +- src/tests/end2end/IOSurfaceWrappingTests.cpp | 4 +- .../end2end/MultisampledRenderingTests.cpp | 6 +- src/tests/end2end/RenderPassLoadOpTests.cpp | 4 +- src/tests/end2end/RenderPassTests.cpp | 4 +- src/tests/end2end/TextureViewTests.cpp | 2 +- src/tests/end2end/TextureZeroInitTests.cpp | 10 +-- src/tests/end2end/ViewportTests.cpp | 8 +-- .../RenderPassDescriptorValidationTests.cpp | 64 +++++++++---------- .../unittests/validation/ValidationTest.cpp | 3 +- .../unittests/validation/ValidationTest.h | 1 - .../white_box/VulkanImageWrappingTests.cpp | 2 +- src/utils/DawnHelpers.cpp | 29 +++------ src/utils/DawnHelpers.h | 7 +- 19 files changed, 91 insertions(+), 116 deletions(-) diff --git a/dawn.json b/dawn.json index c20a4c828c..7fe8cfe4db 100644 --- a/dawn.json +++ b/dawn.json @@ -929,7 +929,7 @@ "category": "structure", "members": [ {"name": "color attachment count", "type": "uint32_t"}, - {"name": "color attachments", "type": "render pass color attachment descriptor", "annotation": "const*const*", "length": "color attachment count"}, + {"name": "color attachments", "type": "render pass color attachment descriptor", "annotation": "const*", "length": "color attachment count"}, {"name": "depth stencil attachment", "type": "render pass depth stencil attachment descriptor", "annotation": "const*", "optional": true} ] }, diff --git a/examples/CHelloTriangle.cpp b/examples/CHelloTriangle.cpp index c5642ee6f6..e04bd8e05e 100644 --- a/examples/CHelloTriangle.cpp +++ b/examples/CHelloTriangle.cpp @@ -128,7 +128,6 @@ void frame() { DawnTextureView backbufferView = dawnTextureCreateView(backbuffer, nullptr); DawnRenderPassDescriptor renderpassInfo; DawnRenderPassColorAttachmentDescriptor colorAttachment; - DawnRenderPassColorAttachmentDescriptor* colorAttachments = {&colorAttachment}; { colorAttachment.attachment = backbufferView; colorAttachment.resolveTarget = nullptr; @@ -136,7 +135,7 @@ void frame() { colorAttachment.loadOp = DAWN_LOAD_OP_CLEAR; colorAttachment.storeOp = DAWN_STORE_OP_STORE; renderpassInfo.colorAttachmentCount = 1; - renderpassInfo.colorAttachments = &colorAttachments; + renderpassInfo.colorAttachments = &colorAttachment; renderpassInfo.depthStencilAttachment = nullptr; } DawnCommandBuffer commands; diff --git a/src/dawn_native/AttachmentState.cpp b/src/dawn_native/AttachmentState.cpp index d21b01885f..febf6d6305 100644 --- a/src/dawn_native/AttachmentState.cpp +++ b/src/dawn_native/AttachmentState.cpp @@ -45,7 +45,7 @@ namespace dawn_native { AttachmentStateBlueprint::AttachmentStateBlueprint(const RenderPassDescriptor* descriptor) { for (uint32_t i = 0; i < descriptor->colorAttachmentCount; ++i) { - TextureViewBase* attachment = descriptor->colorAttachments[i]->attachment; + TextureViewBase* attachment = descriptor->colorAttachments[i].attachment; mColorAttachmentsSet.set(i); mColorFormats[i] = attachment->GetFormat().format; if (mSampleCount == 0) { diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index e3bf71233e..0c5208ef04 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -310,39 +310,40 @@ namespace dawn_native { MaybeError ValidateResolveTarget( const DeviceBase* device, - const RenderPassColorAttachmentDescriptor* colorAttachment) { - if (colorAttachment->resolveTarget == nullptr) { + const RenderPassColorAttachmentDescriptor& colorAttachment) { + if (colorAttachment.resolveTarget == nullptr) { return {}; } - DAWN_TRY(device->ValidateObject(colorAttachment->resolveTarget)); + const TextureViewBase* resolveTarget = colorAttachment.resolveTarget; + const TextureViewBase* attachment = colorAttachment.attachment; + DAWN_TRY(device->ValidateObject(colorAttachment.resolveTarget)); - if (!colorAttachment->attachment->GetTexture()->IsMultisampledTexture()) { + if (!attachment->GetTexture()->IsMultisampledTexture()) { return DAWN_VALIDATION_ERROR( "Cannot set resolve target when the sample count of the color attachment is 1"); } - if (colorAttachment->resolveTarget->GetTexture()->IsMultisampledTexture()) { + if (resolveTarget->GetTexture()->IsMultisampledTexture()) { return DAWN_VALIDATION_ERROR("Cannot use multisampled texture as resolve target"); } - if (colorAttachment->resolveTarget->GetLayerCount() > 1) { + if (resolveTarget->GetLayerCount() > 1) { return DAWN_VALIDATION_ERROR( "The array layer count of the resolve target must be 1"); } - if (colorAttachment->resolveTarget->GetLevelCount() > 1) { + if (resolveTarget->GetLevelCount() > 1) { return DAWN_VALIDATION_ERROR("The mip level count of the resolve target must be 1"); } - uint32_t colorAttachmentBaseMipLevel = colorAttachment->attachment->GetBaseMipLevel(); - const Extent3D& colorTextureSize = colorAttachment->attachment->GetTexture()->GetSize(); + uint32_t colorAttachmentBaseMipLevel = attachment->GetBaseMipLevel(); + const Extent3D& colorTextureSize = attachment->GetTexture()->GetSize(); uint32_t colorAttachmentWidth = colorTextureSize.width >> colorAttachmentBaseMipLevel; uint32_t colorAttachmentHeight = colorTextureSize.height >> colorAttachmentBaseMipLevel; - uint32_t resolveTargetBaseMipLevel = colorAttachment->resolveTarget->GetBaseMipLevel(); - const Extent3D& resolveTextureSize = - colorAttachment->resolveTarget->GetTexture()->GetSize(); + uint32_t resolveTargetBaseMipLevel = resolveTarget->GetBaseMipLevel(); + const Extent3D& resolveTextureSize = resolveTarget->GetTexture()->GetSize(); uint32_t resolveTargetWidth = resolveTextureSize.width >> resolveTargetBaseMipLevel; uint32_t resolveTargetHeight = resolveTextureSize.height >> resolveTargetBaseMipLevel; if (colorAttachmentWidth != resolveTargetWidth || @@ -351,9 +352,8 @@ namespace dawn_native { "The size of the resolve target must be the same as the color attachment"); } - dawn::TextureFormat resolveTargetFormat = - colorAttachment->resolveTarget->GetFormat().format; - if (resolveTargetFormat != colorAttachment->attachment->GetFormat().format) { + dawn::TextureFormat resolveTargetFormat = resolveTarget->GetFormat().format; + if (resolveTargetFormat != attachment->GetFormat().format) { return DAWN_VALIDATION_ERROR( "The format of the resolve target must be the same as the color attachment"); } @@ -363,15 +363,13 @@ namespace dawn_native { MaybeError ValidateRenderPassColorAttachment( const DeviceBase* device, - const RenderPassColorAttachmentDescriptor* colorAttachment, + const RenderPassColorAttachmentDescriptor& colorAttachment, uint32_t* width, uint32_t* height, uint32_t* sampleCount) { - DAWN_ASSERT(colorAttachment != nullptr); + DAWN_TRY(device->ValidateObject(colorAttachment.attachment)); - DAWN_TRY(device->ValidateObject(colorAttachment->attachment)); - - const TextureViewBase* attachment = colorAttachment->attachment; + const TextureViewBase* attachment = colorAttachment.attachment; if (!attachment->GetFormat().IsColor() || !attachment->GetFormat().isRenderable) { return DAWN_VALIDATION_ERROR( "The format of the texture view used as color attachment is not color " @@ -517,13 +515,13 @@ namespace dawn_native { cmd->attachmentState = device->GetOrCreateAttachmentState(descriptor); for (uint32_t i : IterateBitSet(cmd->attachmentState->GetColorAttachmentsMask())) { - cmd->colorAttachments[i].view = descriptor->colorAttachments[i]->attachment; + cmd->colorAttachments[i].view = descriptor->colorAttachments[i].attachment; cmd->colorAttachments[i].resolveTarget = - descriptor->colorAttachments[i]->resolveTarget; - cmd->colorAttachments[i].loadOp = descriptor->colorAttachments[i]->loadOp; - cmd->colorAttachments[i].storeOp = descriptor->colorAttachments[i]->storeOp; + descriptor->colorAttachments[i].resolveTarget; + cmd->colorAttachments[i].loadOp = descriptor->colorAttachments[i].loadOp; + cmd->colorAttachments[i].storeOp = descriptor->colorAttachments[i].storeOp; cmd->colorAttachments[i].clearColor = - descriptor->colorAttachments[i]->clearColor; + descriptor->colorAttachments[i].clearColor; } if (cmd->attachmentState->HasDepthStencilAttachment()) { diff --git a/src/tests/end2end/ClipSpaceTests.cpp b/src/tests/end2end/ClipSpaceTests.cpp index 58bd477fd6..439f0d3cd1 100644 --- a/src/tests/end2end/ClipSpaceTests.cpp +++ b/src/tests/end2end/ClipSpaceTests.cpp @@ -78,8 +78,8 @@ TEST_P(ClipSpaceTest, ClipSpace) { utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateView()}, depthStencilTexture.CreateView()); - renderPassDescriptor.cColorAttachmentsInfoPtr[0]->clearColor = {0.0, 1.0, 0.0, 1.0}; - renderPassDescriptor.cColorAttachmentsInfoPtr[0]->loadOp = dawn::LoadOp::Clear; + renderPassDescriptor.cColorAttachments[0].clearColor = {0.0, 1.0, 0.0, 1.0}; + renderPassDescriptor.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; // Clear the depth stencil attachment to 0.5f, so only the bottom-right triangle should be // drawn. diff --git a/src/tests/end2end/CullingTests.cpp b/src/tests/end2end/CullingTests.cpp index eaa8a02b3d..7745348f97 100644 --- a/src/tests/end2end/CullingTests.cpp +++ b/src/tests/end2end/CullingTests.cpp @@ -78,8 +78,8 @@ class CullingTest : public DawnTest { dawn::Texture colorTexture = Create2DTextureForTest(dawn::TextureFormat::RGBA8Unorm); utils::ComboRenderPassDescriptor renderPassDescriptor({colorTexture.CreateView()}); - renderPassDescriptor.cColorAttachmentsInfoPtr[0]->clearColor = {0.0, 0.0, 1.0, 1.0}; - renderPassDescriptor.cColorAttachmentsInfoPtr[0]->loadOp = dawn::LoadOp::Clear; + renderPassDescriptor.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0}; + renderPassDescriptor.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; dawn::CommandEncoder commandEncoder = device.CreateCommandEncoder(); dawn::RenderPassEncoder renderPass = commandEncoder.BeginRenderPass(&renderPassDescriptor); diff --git a/src/tests/end2end/IOSurfaceWrappingTests.cpp b/src/tests/end2end/IOSurfaceWrappingTests.cpp index 001b3f7fb3..e4823fffe1 100644 --- a/src/tests/end2end/IOSurfaceWrappingTests.cpp +++ b/src/tests/end2end/IOSurfaceWrappingTests.cpp @@ -347,8 +347,8 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase { dawn::TextureView ioSurfaceView = ioSurfaceTexture.CreateView(); utils::ComboRenderPassDescriptor renderPassDescriptor({ioSurfaceView}, {}); - renderPassDescriptor.cColorAttachmentsInfoPtr[0]->clearColor = {1 / 255.0f, 2 / 255.0f, - 3 / 255.0f, 4 / 255.0f}; + renderPassDescriptor.cColorAttachments[0].clearColor = {1 / 255.0f, 2 / 255.0f, 3 / 255.0f, + 4 / 255.0f}; // Execute commands to clear the ioSurface dawn::CommandEncoder encoder = device.CreateCommandEncoder(); diff --git a/src/tests/end2end/MultisampledRenderingTests.cpp b/src/tests/end2end/MultisampledRenderingTests.cpp index b291487cae..c9fb5d95ff 100644 --- a/src/tests/end2end/MultisampledRenderingTests.cpp +++ b/src/tests/end2end/MultisampledRenderingTests.cpp @@ -131,9 +131,9 @@ class MultisampledRenderingTest : public DawnTest { utils::ComboRenderPassDescriptor renderPass(colorViews); uint32_t i = 0; for (const dawn::TextureView& resolveTargetView : resolveTargetViews) { - renderPass.cColorAttachmentsInfoPtr[i]->loadOp = colorLoadOp; - renderPass.cColorAttachmentsInfoPtr[i]->clearColor = kClearColor; - renderPass.cColorAttachmentsInfoPtr[i]->resolveTarget = resolveTargetView; + renderPass.cColorAttachments[i].loadOp = colorLoadOp; + renderPass.cColorAttachments[i].clearColor = kClearColor; + renderPass.cColorAttachments[i].resolveTarget = resolveTargetView; ++i; } diff --git a/src/tests/end2end/RenderPassLoadOpTests.cpp b/src/tests/end2end/RenderPassLoadOpTests.cpp index 8cf66c3a04..9c0d9ea8d5 100644 --- a/src/tests/end2end/RenderPassLoadOpTests.cpp +++ b/src/tests/end2end/RenderPassLoadOpTests.cpp @@ -122,7 +122,7 @@ TEST_P(RenderPassLoadOpTests, ColorClearThenLoadAndDraw) { auto commandsClearZero = commandsClearZeroEncoder.Finish(); utils::ComboRenderPassDescriptor renderPassClearGreen({renderTargetView}); - renderPassClearGreen.cColorAttachmentsInfoPtr[0]->clearColor = {0.0f, 1.0f, 0.0f, 1.0f}; + renderPassClearGreen.cColorAttachments[0].clearColor = {0.0f, 1.0f, 0.0f, 1.0f}; auto commandsClearGreenEncoder = device.CreateCommandEncoder(); auto clearGreenPass = commandsClearGreenEncoder.BeginRenderPass(&renderPassClearGreen); clearGreenPass.EndPass(); @@ -136,7 +136,7 @@ TEST_P(RenderPassLoadOpTests, ColorClearThenLoadAndDraw) { // Part 2: draw a blue quad into the right half of the render target, and check result utils::ComboRenderPassDescriptor renderPassLoad({renderTargetView}); - renderPassLoad.cColorAttachmentsInfoPtr[0]->loadOp = dawn::LoadOp::Load; + renderPassLoad.cColorAttachments[0].loadOp = dawn::LoadOp::Load; dawn::CommandBuffer commandsLoad; { auto encoder = device.CreateCommandEncoder(); diff --git a/src/tests/end2end/RenderPassTests.cpp b/src/tests/end2end/RenderPassTests.cpp index 578e2fa3fc..506bc11d57 100644 --- a/src/tests/end2end/RenderPassTests.cpp +++ b/src/tests/end2end/RenderPassTests.cpp @@ -89,7 +89,7 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) { // In the first render pass we clear renderTarget1 to red and draw a blue triangle in the // bottom left of renderTarget1. utils::ComboRenderPassDescriptor renderPass({renderTarget1.CreateView()}); - renderPass.cColorAttachmentsInfoPtr[0]->clearColor = {1.0f, 0.0f, 0.0f, 1.0f}; + renderPass.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f}; dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); pass.SetPipeline(pipeline); @@ -101,7 +101,7 @@ TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) { // In the second render pass we clear renderTarget2 to green and draw a blue triangle in the // bottom left of renderTarget2. utils::ComboRenderPassDescriptor renderPass({renderTarget2.CreateView()}); - renderPass.cColorAttachmentsInfoPtr[0]->clearColor = {0.0f, 1.0f, 0.0f, 1.0f}; + renderPass.cColorAttachments[0].clearColor = {0.0f, 1.0f, 0.0f, 1.0f}; dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); pass.SetPipeline(pipeline); diff --git a/src/tests/end2end/TextureViewTests.cpp b/src/tests/end2end/TextureViewTests.cpp index 76554ca4a0..27c0ff9456 100644 --- a/src/tests/end2end/TextureViewTests.cpp +++ b/src/tests/end2end/TextureViewTests.cpp @@ -491,7 +491,7 @@ class TextureViewRenderingTest : public DawnTest { // Clear textureView with Red(255, 0, 0, 255) and render Green(0, 255, 0, 255) into it utils::ComboRenderPassDescriptor renderPassInfo({textureView}); - renderPassInfo.cColorAttachmentsInfoPtr[0]->clearColor = {1.0f, 0.0f, 0.0f, 1.0f}; + renderPassInfo.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f}; const char* oneColorFragmentShader = R"( #version 450 diff --git a/src/tests/end2end/TextureZeroInitTests.cpp b/src/tests/end2end/TextureZeroInitTests.cpp index 18d98e36c3..7129c3c249 100644 --- a/src/tests/end2end/TextureZeroInitTests.cpp +++ b/src/tests/end2end/TextureZeroInitTests.cpp @@ -118,7 +118,7 @@ TEST_P(TextureZeroInitTest, RenderingMipMapClearsToZero) { utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat); - renderPass.renderPassInfo.cColorAttachmentsInfoPtr[0]->attachment = view; + renderPass.renderPassInfo.cColorAttachments[0].attachment = view; dawn::CommandEncoder encoder = device.CreateCommandEncoder(); { // Texture's first usage is in BeginRenderPass's call to RecordRenderPass @@ -146,7 +146,7 @@ TEST_P(TextureZeroInitTest, RenderingArrayLayerClearsToZero) { utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat); - renderPass.renderPassInfo.cColorAttachmentsInfoPtr[0]->attachment = view; + renderPass.renderPassInfo.cColorAttachments[0].attachment = view; dawn::CommandEncoder encoder = device.CreateCommandEncoder(); { dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); @@ -418,7 +418,7 @@ TEST_P(TextureZeroInitTest, ColorAttachmentsClear) { 1, 1, dawn::TextureUsage::OutputAttachment | dawn::TextureUsage::CopySrc, kColorFormat); dawn::Texture texture = device.CreateTexture(&descriptor); utils::BasicRenderPass renderPass = utils::BasicRenderPass(kSize, kSize, texture, kColorFormat); - renderPass.renderPassInfo.cColorAttachmentsInfoPtr[0]->loadOp = dawn::LoadOp::Load; + renderPass.renderPassInfo.cColorAttachments[0].loadOp = dawn::LoadOp::Load; dawn::CommandEncoder encoder = device.CreateCommandEncoder(); dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo); @@ -484,8 +484,8 @@ TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) { // Encode pass and submit dawn::CommandEncoder encoder = device.CreateCommandEncoder(); utils::ComboRenderPassDescriptor renderPassDesc({renderTexture.CreateView()}); - renderPassDesc.cColorAttachmentsInfoPtr[0]->clearColor = {1.0, 1.0, 1.0, 1.0}; - renderPassDesc.cColorAttachmentsInfoPtr[0]->loadOp = dawn::LoadOp::Clear; + renderPassDesc.cColorAttachments[0].clearColor = {1.0, 1.0, 1.0, 1.0}; + renderPassDesc.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc); pass.SetPipeline(renderPipeline); pass.SetBindGroup(0, bindGroup, 0, nullptr); diff --git a/src/tests/end2end/ViewportTests.cpp b/src/tests/end2end/ViewportTests.cpp index 570b377d39..fe672d86cc 100644 --- a/src/tests/end2end/ViewportTests.cpp +++ b/src/tests/end2end/ViewportTests.cpp @@ -113,8 +113,8 @@ class ViewportTest : public DawnTest { { utils::ComboRenderPassDescriptor renderPassDescriptor1( {colorTexture1.CreateView()}, depthStencilTexture1.CreateView()); - renderPassDescriptor1.cColorAttachmentsInfoPtr[0]->clearColor = {0.0, 0.0, 1.0, 1.0}; - renderPassDescriptor1.cColorAttachmentsInfoPtr[0]->loadOp = dawn::LoadOp::Clear; + renderPassDescriptor1.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0}; + renderPassDescriptor1.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPassDescriptor1.cDepthStencilAttachmentInfo.clearDepth = info.clearDepth; renderPassDescriptor1.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear; @@ -138,8 +138,8 @@ class ViewportTest : public DawnTest { { utils::ComboRenderPassDescriptor renderPassDescriptor2( {colorTexture2.CreateView()}, depthStencilTexture2.CreateView()); - renderPassDescriptor2.cColorAttachmentsInfoPtr[0]->clearColor = {0.0, 0.0, 1.0, 1.0}; - renderPassDescriptor2.cColorAttachmentsInfoPtr[0]->loadOp = dawn::LoadOp::Clear; + renderPassDescriptor2.cColorAttachments[0].clearColor = {0.0, 0.0, 1.0, 1.0}; + renderPassDescriptor2.cColorAttachments[0].loadOp = dawn::LoadOp::Clear; renderPassDescriptor2.cDepthStencilAttachmentInfo.clearDepth = 0.5; renderPassDescriptor2.cDepthStencilAttachmentInfo.depthLoadOp = dawn::LoadOp::Clear; diff --git a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp index 31ddb0d6ae..d3bae711b1 100644 --- a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp @@ -99,46 +99,42 @@ TEST_F(RenderPassDescriptorValidationTest, OneAttachment) { // Test OOB color attachment indices are handled TEST_F(RenderPassDescriptorValidationTest, ColorAttachmentOutOfBounds) { + dawn::TextureView color0 = Create2DAttachment(device, 1, 1, dawn::TextureFormat::RGBA8Unorm); dawn::TextureView color1 = Create2DAttachment(device, 1, 1, dawn::TextureFormat::RGBA8Unorm); dawn::TextureView color2 = Create2DAttachment(device, 1, 1, dawn::TextureFormat::RGBA8Unorm); dawn::TextureView color3 = Create2DAttachment(device, 1, 1, dawn::TextureFormat::RGBA8Unorm); - dawn::TextureView color4 = Create2DAttachment(device, 1, 1, dawn::TextureFormat::RGBA8Unorm); // For setting the color attachment, control case { - utils::ComboRenderPassDescriptor renderPass({color1, color2, color3, color4}); + utils::ComboRenderPassDescriptor renderPass({color0, color1, color2, color3}); AssertBeginRenderPassSuccess(&renderPass); } // For setting the color attachment, OOB { // We cannot use utils::ComboRenderPassDescriptor here because it only supports at most // kMaxColorAttachments(4) color attachments. - dawn::RenderPassColorAttachmentDescriptor colorAttachment1; - colorAttachment1.attachment = color1; - colorAttachment1.resolveTarget = nullptr; - colorAttachment1.clearColor = {0.0f, 0.0f, 0.0f, 0.0f}; - colorAttachment1.loadOp = dawn::LoadOp::Clear; - colorAttachment1.storeOp = dawn::StoreOp::Store; + std::array colorAttachments; + colorAttachments[0].attachment = color0; + colorAttachments[0].resolveTarget = nullptr; + colorAttachments[0].clearColor = {0.0f, 0.0f, 0.0f, 0.0f}; + colorAttachments[0].loadOp = dawn::LoadOp::Clear; + colorAttachments[0].storeOp = dawn::StoreOp::Store; - dawn::RenderPassColorAttachmentDescriptor colorAttachment2 = colorAttachment1; - dawn::RenderPassColorAttachmentDescriptor colorAttachment3 = colorAttachment1; - dawn::RenderPassColorAttachmentDescriptor colorAttachment4 = colorAttachment1; - colorAttachment2.attachment = color2; - colorAttachment3.attachment = color3; - colorAttachment4.attachment = color4; + colorAttachments[1] = colorAttachments[0]; + colorAttachments[1].attachment = color1; - dawn::TextureView color5 = + colorAttachments[2] = colorAttachments[0]; + colorAttachments[2].attachment = color2; + + colorAttachments[3] = colorAttachments[0]; + colorAttachments[3].attachment = color3; + + colorAttachments[4] = colorAttachments[0]; + colorAttachments[4].attachment = Create2DAttachment(device, 1, 1, dawn::TextureFormat::RGBA8Unorm); - dawn::RenderPassColorAttachmentDescriptor colorAttachment5 = colorAttachment1; - colorAttachment5.attachment = color5; - dawn::RenderPassColorAttachmentDescriptor* colorAttachments[] = {&colorAttachment1, - &colorAttachment2, - &colorAttachment3, - &colorAttachment4, - &colorAttachment5}; dawn::RenderPassDescriptor renderPass; - renderPass.colorAttachmentCount = kMaxColorAttachments + 1; - renderPass.colorAttachments = colorAttachments; + renderPass.colorAttachmentCount = 5; + renderPass.colorAttachments = colorAttachments.data(); renderPass.depthStencilAttachment = nullptr; AssertBeginRenderPassError(&renderPass); } @@ -398,7 +394,7 @@ TEST_F(RenderPassDescriptorValidationTest, NonMultisampledColorWithResolveTarget dawn::TextureView resolveTargetTextureView = resolveTargetTexture.CreateView(); utils::ComboRenderPassDescriptor renderPass({colorTextureView}); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = resolveTargetTextureView; + renderPass.cColorAttachments[0].resolveTarget = resolveTargetTextureView; AssertBeginRenderPassError(&renderPass); } @@ -457,7 +453,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledResolveTarget dawn::TextureView multisampledResolveTargetView = CreateMultisampledColorTextureView(); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = multisampledResolveTargetView; + renderPass.cColorAttachments[0].resolveTarget = multisampledResolveTargetView; AssertBeginRenderPassError(&renderPass); } @@ -470,7 +466,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetArrayLayerMo dawn::TextureView resolveTextureView = resolveTexture.CreateView(); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = resolveTextureView; + renderPass.cColorAttachments[0].resolveTarget = resolveTextureView; AssertBeginRenderPassError(&renderPass); } @@ -483,7 +479,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetMipmapLevelM dawn::TextureView resolveTextureView = resolveTexture.CreateView(); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = resolveTextureView; + renderPass.cColorAttachments[0].resolveTarget = resolveTextureView; AssertBeginRenderPassError(&renderPass); } @@ -497,7 +493,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetUsageNoOutpu dawn::TextureView nonColorUsageResolveTextureView = nonColorUsageResolveTexture.CreateView(); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = nonColorUsageResolveTextureView; + renderPass.cColorAttachments[0].resolveTarget = nonColorUsageResolveTextureView; AssertBeginRenderPassError(&renderPass); } @@ -515,7 +511,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetInErrorState resolveTexture.CreateView(&errorTextureView)); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = errorResolveTarget; + renderPass.cColorAttachments[0].resolveTarget = errorResolveTarget; AssertBeginRenderPassError(&renderPass); } @@ -524,7 +520,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledColorWithReso dawn::TextureView resolveTargetTextureView = CreateNonMultisampledColorTextureView(); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = resolveTargetTextureView; + renderPass.cColorAttachments[0].resolveTarget = resolveTargetTextureView; AssertBeginRenderPassSuccess(&renderPass); } @@ -537,7 +533,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetDifferentFor dawn::TextureView resolveTextureView = resolveTexture.CreateView(); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = resolveTextureView; + renderPass.cColorAttachments[0].resolveTarget = resolveTextureView; AssertBeginRenderPassError(&renderPass); } @@ -564,7 +560,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, ColorAttachmentResolveTar resolveTexture.CreateView(&firstMipLevelDescriptor); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = resolveTextureView; + renderPass.cColorAttachments[0].resolveTarget = resolveTextureView; AssertBeginRenderPassError(&renderPass); } @@ -576,7 +572,7 @@ TEST_F(MultisampledRenderPassDescriptorValidationTest, ColorAttachmentResolveTar resolveTexture.CreateView(&secondMipLevelDescriptor); utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass(); - renderPass.cColorAttachmentsInfoPtr[0]->resolveTarget = resolveTextureView; + renderPass.cColorAttachments[0].resolveTarget = resolveTextureView; AssertBeginRenderPassSuccess(&renderPass); } } diff --git a/src/tests/unittests/validation/ValidationTest.cpp b/src/tests/unittests/validation/ValidationTest.cpp index 5b9a5941ff..461d9d7123 100644 --- a/src/tests/unittests/validation/ValidationTest.cpp +++ b/src/tests/unittests/validation/ValidationTest.cpp @@ -114,9 +114,8 @@ ValidationTest::DummyRenderPass::DummyRenderPass(const dawn::Device& device) mColorAttachment.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f }; mColorAttachment.loadOp = dawn::LoadOp::Clear; mColorAttachment.storeOp = dawn::StoreOp::Store; - mColorAttachments[0] = &mColorAttachment; colorAttachmentCount = 1; - colorAttachments = mColorAttachments; + colorAttachments = &mColorAttachment; depthStencilAttachment = nullptr; } diff --git a/src/tests/unittests/validation/ValidationTest.h b/src/tests/unittests/validation/ValidationTest.h index 3d0b59c275..e4a266da8b 100644 --- a/src/tests/unittests/validation/ValidationTest.h +++ b/src/tests/unittests/validation/ValidationTest.h @@ -50,7 +50,6 @@ class ValidationTest : public testing::Test { private: dawn::RenderPassColorAttachmentDescriptor mColorAttachment; - dawn::RenderPassColorAttachmentDescriptor* mColorAttachments[1]; }; protected: diff --git a/src/tests/white_box/VulkanImageWrappingTests.cpp b/src/tests/white_box/VulkanImageWrappingTests.cpp index 295f3ac301..53e71663cf 100644 --- a/src/tests/white_box/VulkanImageWrappingTests.cpp +++ b/src/tests/white_box/VulkanImageWrappingTests.cpp @@ -408,7 +408,7 @@ class VulkanImageWrappingUsageTests : public VulkanImageWrappingTestBase { // Submit a clear operation utils::ComboRenderPassDescriptor renderPassDescriptor({wrappedView}, {}); - renderPassDescriptor.cColorAttachmentsInfoPtr[0]->clearColor = clearColor; + renderPassDescriptor.cColorAttachments[0].clearColor = clearColor; dawn::CommandEncoder encoder = device.CreateCommandEncoder(); dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDescriptor); diff --git a/src/utils/DawnHelpers.cpp b/src/utils/DawnHelpers.cpp index 25a8d73316..1ad9adf09e 100644 --- a/src/utils/DawnHelpers.cpp +++ b/src/utils/DawnHelpers.cpp @@ -128,13 +128,11 @@ namespace utils { ComboRenderPassDescriptor::ComboRenderPassDescriptor( std::initializer_list colorAttachmentInfo, - dawn::TextureView depthStencil) - : cColorAttachmentsInfoPtr() { + dawn::TextureView depthStencil) { for (uint32_t i = 0; i < kMaxColorAttachments; ++i) { - mColorAttachmentsInfo[i].loadOp = dawn::LoadOp::Clear; - mColorAttachmentsInfo[i].storeOp = dawn::StoreOp::Store; - mColorAttachmentsInfo[i].clearColor = {0.0f, 0.0f, 0.0f, 0.0f}; - cColorAttachmentsInfoPtr[i] = nullptr; + cColorAttachments[i].loadOp = dawn::LoadOp::Clear; + cColorAttachments[i].storeOp = dawn::StoreOp::Store; + cColorAttachments[i].clearColor = {0.0f, 0.0f, 0.0f, 0.0f}; } cDepthStencilAttachmentInfo.clearDepth = 1.0f; @@ -148,13 +146,11 @@ namespace utils { uint32_t colorAttachmentIndex = 0; for (const dawn::TextureView& colorAttachment : colorAttachmentInfo) { if (colorAttachment.Get() != nullptr) { - mColorAttachmentsInfo[colorAttachmentIndex].attachment = colorAttachment; - cColorAttachmentsInfoPtr[colorAttachmentIndex] = - &mColorAttachmentsInfo[colorAttachmentIndex]; + cColorAttachments[colorAttachmentIndex].attachment = colorAttachment; } ++colorAttachmentIndex; } - colorAttachments = cColorAttachmentsInfoPtr; + colorAttachments = cColorAttachments.data(); if (depthStencil.Get() != nullptr) { cDepthStencilAttachmentInfo.attachment = depthStencil; @@ -167,19 +163,10 @@ namespace utils { const ComboRenderPassDescriptor& ComboRenderPassDescriptor::operator=( const ComboRenderPassDescriptor& otherRenderPass) { cDepthStencilAttachmentInfo = otherRenderPass.cDepthStencilAttachmentInfo; - mColorAttachmentsInfo = otherRenderPass.mColorAttachmentsInfo; - + cColorAttachments = otherRenderPass.cColorAttachments; colorAttachmentCount = otherRenderPass.colorAttachmentCount; - // Assign the pointers in colorAttachmentsInfoPtr to items in this->mColorAttachmentsInfo - for (uint32_t i = 0; i < colorAttachmentCount; ++i) { - if (otherRenderPass.cColorAttachmentsInfoPtr[i] != nullptr) { - cColorAttachmentsInfoPtr[i] = &mColorAttachmentsInfo[i]; - } else { - cColorAttachmentsInfoPtr[i] = nullptr; - } - } - colorAttachments = cColorAttachmentsInfoPtr; + colorAttachments = cColorAttachments.data(); if (otherRenderPass.depthStencilAttachment != nullptr) { // Assign desc.depthStencilAttachment to this->depthStencilAttachmentInfo; diff --git a/src/utils/DawnHelpers.h b/src/utils/DawnHelpers.h index 4011bc41de..337ae8508c 100644 --- a/src/utils/DawnHelpers.h +++ b/src/utils/DawnHelpers.h @@ -61,12 +61,9 @@ namespace utils { const ComboRenderPassDescriptor& operator=( const ComboRenderPassDescriptor& otherRenderPass); - dawn::RenderPassColorAttachmentDescriptor* cColorAttachmentsInfoPtr[kMaxColorAttachments]; - dawn::RenderPassDepthStencilAttachmentDescriptor cDepthStencilAttachmentInfo; - - private: std::array - mColorAttachmentsInfo; + cColorAttachments; + dawn::RenderPassDepthStencilAttachmentDescriptor cDepthStencilAttachmentInfo; }; struct BasicRenderPass {