chromium/third_party/dawn/src/dawn/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp

// Copyright 2018 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <cmath>
#include <string>
#include <vector>

#include "dawn/common/Constants.h"
#include "dawn/tests/unittests/validation/ValidationTest.h"
#include "dawn/utils/ComboRenderBundleEncoderDescriptor.h"
#include "dawn/utils/ComboRenderPipelineDescriptor.h"
#include "dawn/utils/WGPUHelpers.h"

namespace dawn {
namespace {

class RenderPassDescriptorValidationTest : public ValidationTest {};

wgpu::Texture CreateTexture(wgpu::Device& device,
                            wgpu::TextureDimension dimension,
                            wgpu::TextureFormat format,
                            uint32_t width,
                            uint32_t height,
                            uint32_t arrayLayerCount,
                            uint32_t mipLevelCount,
                            uint32_t sampleCount = 1,
                            wgpu::TextureUsage usage = wgpu::TextureUsage::RenderAttachment) {}

wgpu::TextureView Create2DAttachment(wgpu::Device& device,
                                     uint32_t width,
                                     uint32_t height,
                                     wgpu::TextureFormat format) {}

// Using BeginRenderPass with no attachments isn't valid
TEST_F(RenderPassDescriptorValidationTest, Empty) {}

// A render pass with only one color or one depth attachment is ok
TEST_F(RenderPassDescriptorValidationTest, OneAttachment) {}

// Regression test for chromium:1487788 were cached attachment states used in a pass encoder created
// from an error command encoder are not cleaned up if the device's last reference is dropped before
// the pass.
TEST_F(RenderPassDescriptorValidationTest, ErrorEncoderLingeringAttachmentState) {}

// Test OOB color attachment indices are handled
TEST_F(RenderPassDescriptorValidationTest, ColorAttachmentOutOfBounds) {}

// Test sparse color attachment validations
TEST_F(RenderPassDescriptorValidationTest, SparseColorAttachment) {}

// Check that the render pass color attachment must have the RenderAttachment usage.
TEST_F(RenderPassDescriptorValidationTest, ColorAttachmentInvalidUsage) {}

// Attachments must have the same size
TEST_F(RenderPassDescriptorValidationTest, SizeMustMatch) {}

// Attachments formats must match whether they are used for color or depth-stencil
TEST_F(RenderPassDescriptorValidationTest, FormatMismatch) {}

// Depth and stencil storeOps can be different
TEST_F(RenderPassDescriptorValidationTest, DepthStencilStoreOpMismatch) {}

// Currently only texture views with arrayLayerCount == 1 are allowed to be color and depth
// stencil attachments
TEST_F(RenderPassDescriptorValidationTest, TextureViewLayerCountForColorAndDepthStencil) {}

// Check that depthSlice must be set correctly for 3D color attachments and must not be set for
// non-3D color attachments.
TEST_F(RenderPassDescriptorValidationTest, TextureViewDepthSliceForColor) {}

// Check that the depth slices of a 3D color attachment cannot overlap in same render pass.
TEST_F(RenderPassDescriptorValidationTest, TextureViewDepthSliceOverlaps) {}

// Check that the render pass depth attachment must have the RenderAttachment usage.
TEST_F(RenderPassDescriptorValidationTest, DepthAttachmentInvalidUsage) {}

// Only 2D texture views with mipLevelCount == 1 are allowed to be color attachments
TEST_F(RenderPassDescriptorValidationTest, TextureViewLevelCountForColorAndDepthStencil) {}

// It is not allowed to set resolve target when the color attachment is non-multisampled.
TEST_F(RenderPassDescriptorValidationTest, NonMultisampledColorWithResolveTarget) {}

// drawCount must not exceed maxDrawCount
TEST_F(RenderPassDescriptorValidationTest, MaxDrawCount) {}

class MultisampledRenderPassDescriptorValidationTest : public RenderPassDescriptorValidationTest {};

// Tests on the use of multisampled textures as color attachments
TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledColorAttachments) {}

// It is not allowed to use a multisampled resolve target.
TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledResolveTarget) {}

// Test the view dimension of resolve target.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetDimension) {}

// It is not allowed to use a resolve target with array layer count > 1.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetArrayLayerMoreThanOne) {}

// It is not allowed to use a resolve target with mipmap level count > 1.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetMipmapLevelMoreThanOne) {}

// It is not allowed to use a resolve target which is created from a texture whose usage does
// not include wgpu::TextureUsage::RenderAttachment.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetUsageNoRenderAttachment) {}

// It is not allowed to use a resolve target which is in error state.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetInErrorState) {}

// It is allowed to use a multisampled color attachment and a non-multisampled resolve target.
TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledColorWithResolveTarget) {}

// It is not allowed to use a resolve target in a format different from the color attachment.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetDifferentFormat) {}

// Tests on the size of the resolve target.
TEST_F(MultisampledRenderPassDescriptorValidationTest,
       ColorAttachmentResolveTargetDimensionMismatch) {}

// Test the overlaps of multiple resolve target.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetUsedTwice) {}

// Tests the texture format of the resolve target must support being used as resolve target.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetFormat) {}

// Tests on the sample count of depth stencil attachment.
TEST_F(MultisampledRenderPassDescriptorValidationTest, DepthStencilAttachmentSampleCount) {}

// Creating a render pass with DawnRenderPassColorAttachmentRenderToSingleSampled chained struct
// without MSAARenderToSingleSampled feature enabled should result in error.
TEST_F(MultisampledRenderPassDescriptorValidationTest,
       CreateMSAARenderToSingleSampledRenderPassWithoutFeatureEnabled) {}

// Creating a render pass with LoadOp::ExpandResolveTexture without DawnLoadResolveTexture feature
// enabled should result in error.
TEST_F(MultisampledRenderPassDescriptorValidationTest, LoadResolveTextureWithoutFeatureEnabled) {}

// Creating a render pass with ExpandResolveRect and no DawnLoadResolveTexture feature
// enabled should result in error.
TEST_F(MultisampledRenderPassDescriptorValidationTest, ExpandResolveRectWithoutFeatureEnabled) {}

// Tests that NaN cannot be accepted as a valid color or depth clear value and INFINITY is valid
// in both color and depth clear values.
TEST_F(RenderPassDescriptorValidationTest, UseNaNOrINFINITYAsColorOrDepthClearValue) {}

// Tests that depth clear values mut be between 0 and 1, inclusive.
TEST_F(RenderPassDescriptorValidationTest, ValidateDepthClearValueRange) {}

// Tests that default depthClearValue is required if attachment has a depth aspect and depthLoadOp
// is clear.
TEST_F(RenderPassDescriptorValidationTest, DefaultDepthClearValue) {}

// Check the validation rules around depth/stencilReadOnly
TEST_F(RenderPassDescriptorValidationTest, ValidateDepthStencilReadOnly) {}

// Check that the depth stencil attachment must use all aspects.
TEST_F(RenderPassDescriptorValidationTest, ValidateDepthStencilAllAspects) {}

// Tests validation for per-pixel accounting for render targets. The tests currently assume that the
// default maxColorAttachmentBytesPerSample limit of 32 is used.
TEST_F(RenderPassDescriptorValidationTest, RenderPassColorAttachmentBytesPerSample) {}

// TODO([email protected]): Constraints on attachment aliasing?

class MSAARenderToSingleSampledRenderPassDescriptorValidationTest
    : public MultisampledRenderPassDescriptorValidationTest {};

// Test that using a valid color attachment with enabled MSAARenderToSingleSampled doesn't raise any
// error.
TEST_F(MSAARenderToSingleSampledRenderPassDescriptorValidationTest, ColorAttachmentValid) {}

// When MSAARenderToSingleSampled is enabled for a color attachment, it must be created with
// TextureBinding usage.
TEST_F(MSAARenderToSingleSampledRenderPassDescriptorValidationTest, ColorAttachmentInvalidUsage) {}

// When MSAARenderToSingleSampled is enabled for a color attachment, there must be no explicit
// resolve target specified for it.
TEST_F(MSAARenderToSingleSampledRenderPassDescriptorValidationTest, ErrorSettingResolveTarget) {}

// Using unsupported implicit sample count in DawnRenderPassColorAttachmentRenderToSingleSampled
// chained struct should result in error.
TEST_F(MSAARenderToSingleSampledRenderPassDescriptorValidationTest, UnsupportedSampleCountError) {}

// When MSAARenderToSingleSampled is enabled in a color attachment, there should be an error if a
// color attachment's format doesn't support resolve. Example, RGBA8Sint format.
TEST_F(MSAARenderToSingleSampledRenderPassDescriptorValidationTest, UnresolvableColorFormatError) {}

// Depth stencil attachment's sample count must match the one specified in color attachment's
// implicitSampleCount.
TEST_F(MSAARenderToSingleSampledRenderPassDescriptorValidationTest, DepthStencilSampleCountValid) {}

// Using depth stencil attachment with sample count not matching the implicit sample count will
// result in error.
TEST_F(MSAARenderToSingleSampledRenderPassDescriptorValidationTest,
       DepthStencilSampleCountNotMatchImplicitSampleCount) {}

class DawnLoadResolveTextureValidationTest : public MultisampledRenderPassDescriptorValidationTest {};

// Test that using a valid resolve texture with LoadOp::ExpandResolveTexture doesn't raise
// any error.
TEST_F(DawnLoadResolveTextureValidationTest, ResolveTargetValid) {}

// Test that LoadOp::ExpandResolveTexture can be used even if the MSAA attachment is transient.
TEST_F(DawnLoadResolveTextureValidationTest, CompatibleWithTransientMSAATexture) {}

// When LoadOp::ExpandResolveTexture is used, a resolve texture view must be set.
TEST_F(DawnLoadResolveTextureValidationTest, ResolveTargetMustBeSet) {}

// When LoadOp::ExpandResolveTexture is used, the attached texture view must be multisampled.
TEST_F(DawnLoadResolveTextureValidationTest, ResolveTargetInvalidSampleCount) {}

// When LoadOp::ExpandResolveTexture is used, the resolve texture must be created with
// TextureBinding usage.
TEST_F(DawnLoadResolveTextureValidationTest, ResolveTargetInvalidUsage) {}

// When LoadOp::ExpandResolveTexture is enabled in a color attachment, there should be an error if a
// color attachment's format doesn't support resolve. Example, RGBA8Sint format.
TEST_F(DawnLoadResolveTextureValidationTest, UnresolvableColorFormatError) {}

// The LoadOp is NOT currently supported on depth/stencil attachment.
TEST_F(DawnLoadResolveTextureValidationTest, OnlyLoadingColorAttachmentIsSupported) {}

// Creating a render pass with ExpandResolveRect and no DawnPartialLoadResolveTexture feature
// enabled should result in error.
TEST_F(DawnLoadResolveTextureValidationTest, ExpandResolveRectWithoutFeatureEnabled) {}

class DawnPartialLoadResolveTextureValidationTest : public DawnLoadResolveTextureValidationTest {};

// Test that using a valid ExpandResolveRect with LoadOp::ExpandResolveTexture doesn't raise
// any error.
TEST_F(DawnPartialLoadResolveTextureValidationTest, ExpandResolveRectValid) {}

// Test that using a valid ExpandResolveRect with LoadOp::ExpandResolveTexture, jointed with another
// attachment without LoadOp::ExpandResolveTexture doesn't raise any error.
TEST_F(DawnPartialLoadResolveTextureValidationTest, ExpandResolveRectMixedLoadOpsValid) {}

// The area of ExpandResolveRect must be within the texture size.
TEST_F(DawnPartialLoadResolveTextureValidationTest, ExpandResolveRectInvalidSize) {}

// ExpandResolveRect must be used with wgpu::LoadOp::ExpandResolveTexture.
TEST_F(DawnPartialLoadResolveTextureValidationTest, ExpandResolveRectInvalidLoadOp) {}

}  // anonymous namespace
}  // namespace dawn