// Copyright 2020 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 <string> #include <vector> #include "dawn/common/Assert.h" #include "dawn/common/Constants.h" #include "dawn/tests/unittests/validation/ValidationTest.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/WGPUHelpers.h" namespace dawn { namespace { Not; // Helper for describing bindings throughout the tests struct BindingDescriptor { … }; // Runs |func| with a modified version of |originalSizes| as an argument, adding |offset| to // each element one at a time This is useful to verify some behavior happens if any element is // offset from original template <typename F> void WithEachSizeOffsetBy(int64_t offset, const std::vector<uint64_t>& originalSizes, F func) { … } // Runs |func| with |correctSizes|, and an expectation of success and failure template <typename F> void CheckSizeBounds(const std::vector<uint64_t>& correctSizes, F func) { … } // Creates a bind group with given bindings for shader text std::string GenerateBindingString(const std::vector<BindingDescriptor>& bindings) { … } std::string GenerateReferenceString(const std::vector<BindingDescriptor>& bindings, wgpu::ShaderStage stage) { … } // Used for adding custom types available throughout the tests // NOLINTNEXTLINE(runtime/string) static const std::string kStructs = …; // Creates a compute shader with given bindings std::string CreateComputeShaderWithBindings(const std::vector<BindingDescriptor>& bindings) { … } // Creates a vertex shader with given bindings std::string CreateVertexShaderWithBindings(const std::vector<BindingDescriptor>& bindings) { … } // Creates a fragment shader with given bindings std::string CreateFragmentShaderWithBindings(const std::vector<BindingDescriptor>& bindings) { … } // Concatenates vectors containing BindingDescriptor std::vector<BindingDescriptor> CombineBindings( std::initializer_list<std::vector<BindingDescriptor>> bindings) { … } class MinBufferSizeTestsBase : public ValidationTest { … }; // The check between BGL and pipeline at pipeline creation time class MinBufferSizePipelineCreationTests : public MinBufferSizeTestsBase { … }; // Pipeline can be created if minimum buffer size in layout is specified as 0 TEST_F(MinBufferSizePipelineCreationTests, ZeroMinBufferSize) { … } // Fail if layout given has non-zero minimum sizes smaller than shader requirements TEST_F(MinBufferSizePipelineCreationTests, LayoutSizesTooSmall) { … } // Fail if layout given has non-zero minimum sizes smaller than shader requirements TEST_F(MinBufferSizePipelineCreationTests, LayoutSizesTooSmallMultipleGroups) { … } // The check between the BGL and the bindings at bindgroup creation time class MinBufferSizeBindGroupCreationTests : public MinBufferSizeTestsBase { … }; // Fail if a binding is smaller than minimum buffer size TEST_F(MinBufferSizeBindGroupCreationTests, BindingTooSmall) { … } // The check between the bindgroup binding sizes and the required pipeline sizes at draw time class MinBufferSizeDrawTimeValidationTests : public MinBufferSizeTestsBase { … }; // Fail if binding sizes are too small at draw time TEST_F(MinBufferSizeDrawTimeValidationTests, ZeroMinSizeAndTooSmallBinding) { … } // Draw time validation works for non-contiguous bindings TEST_F(MinBufferSizeDrawTimeValidationTests, UnorderedBindings) { … } // Draw time validation works for multiple bind groups TEST_F(MinBufferSizeDrawTimeValidationTests, MultipleGroups) { … } // The correctness of minimum buffer size for the defaulted layout for a pipeline class MinBufferSizeDefaultLayoutTests : public MinBufferSizeTestsBase { … }; // Test the minimum size computations for various WGSL types. TEST_F(MinBufferSizeDefaultLayoutTests, DefaultLayoutVariousWGSLTypes) { … } // Test the minimum size computations for various buffer binding types. TEST_F(MinBufferSizeDefaultLayoutTests, DefaultLayoutVariousBindingTypes) { … } // Test the minimum size computations works with multiple bind groups. TEST_F(MinBufferSizeDefaultLayoutTests, MultipleBindGroups) { … } // Test the minimum size computations with manual size/align attributes. TEST_F(MinBufferSizeDefaultLayoutTests, NonDefaultLayout) { … } // Minimum size should be the max requirement of both vertex and fragment stages. TEST_F(MinBufferSizeDefaultLayoutTests, RenderPassConsidersBothStages) { … } // Make sure that buffers with non-struct vec3 types do not include padding in the min buffer size. TEST_F(MinBufferSizePipelineCreationTests, NonStructVec3) { … } } // anonymous namespace } // namespace dawn