From 241e70e9cd94cd7f77aca270ef34e7af778404df Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Mon, 24 Feb 2020 12:05:49 +0100 Subject: [PATCH] Correct ConstExpression2DArrayCopy + introduce new test ArrayCopy --- VulkanHppGenerator.cpp | 30 +++-------- tests/ArrayCopy/ArrayCopy.cpp | 99 ++++++++++++++++++++++++++++++++++ tests/ArrayCopy/CMakeLists.txt | 34 ++++++++++++ vulkan/vulkan.hpp | 30 +++-------- 4 files changed, 149 insertions(+), 44 deletions(-) create mode 100644 tests/ArrayCopy/ArrayCopy.cpp create mode 100644 tests/ArrayCopy/CMakeLists.txt diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 7b33db8..c7cba08 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -5457,16 +5457,10 @@ static const std::string constExpressionArrayCopy = R"( class PrivateConstExpression2DArrayCopy { public: - VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N], const T src[N] ) VULKAN_HPP_NOEXCEPT + VULKAN_HPP_CONSTEXPR_14 static void copy( T * dst, T const* src ) VULKAN_HPP_NOEXCEPT { PrivateConstExpression2DArrayCopy::copy( dst, src ); - dst[I - 1][J - 1] = src[I - 1][J - 1]; - } - - VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N], std::array const& src ) VULKAN_HPP_NOEXCEPT - { - PrivateConstExpression2DArrayCopy::copy( dst, src ); - dst[I - 1][J - 1] = src[I - 1][J - 1]; + dst[(I - 1) * M + J - 1] = src[(I - 1) * M + J - 1]; } }; @@ -5474,25 +5468,17 @@ static const std::string constExpressionArrayCopy = R"( class PrivateConstExpression2DArrayCopy { public: - VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N], const T src[N] ) VULKAN_HPP_NOEXCEPT - { - PrivateConstExpression2DArrayCopy::copy( dst, src ); - } - - VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N], std::array const& src ) VULKAN_HPP_NOEXCEPT + VULKAN_HPP_CONSTEXPR_14 static void copy( T * dst, T const* src ) VULKAN_HPP_NOEXCEPT { PrivateConstExpression2DArrayCopy::copy( dst, src ); } }; - template - class PrivateConstExpression2DArrayCopy + template + class PrivateConstExpression2DArrayCopy { public: - VULKAN_HPP_CONSTEXPR_14 static void copy( T /*dst*/[N], const T /*src*/[N] ) VULKAN_HPP_NOEXCEPT - {} - - VULKAN_HPP_CONSTEXPR_14 static void copy( T /*dst*/[N], std::array const& /*src*/ ) VULKAN_HPP_NOEXCEPT + VULKAN_HPP_CONSTEXPR_14 static void copy( T * /*dst*/, T const* /*src*/ ) VULKAN_HPP_NOEXCEPT {} }; @@ -5502,12 +5488,12 @@ static const std::string constExpressionArrayCopy = R"( public: VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N][M], const T src[N][M] ) VULKAN_HPP_NOEXCEPT { - PrivateConstExpression2DArrayCopy::copy( dst, src ); + PrivateConstExpression2DArrayCopy::copy( &dst[0][0], &src[0][0] ); } VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N][M], std::array, N> const& src ) VULKAN_HPP_NOEXCEPT { - PrivateConstExpression2DArrayCopy::copy( dst, src ); + PrivateConstExpression2DArrayCopy::copy( &dst[0][0], src.data()->data() ); } }; )"; diff --git a/tests/ArrayCopy/ArrayCopy.cpp b/tests/ArrayCopy/ArrayCopy.cpp new file mode 100644 index 0000000..82febb7 --- /dev/null +++ b/tests/ArrayCopy/ArrayCopy.cpp @@ -0,0 +1,99 @@ +// Copyright(c) 2018, NVIDIA CORPORATION. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// VulkanHpp Samples : ArrayCopy +// Compile test on array copy functions + +#include "vulkan/vulkan.hpp" + +int main(int /*argc*/, char ** /*argv*/) +{ + struct wrap1D + { + wrap1D(const float src[3]) + { + vk::ConstExpression1DArrayCopy::copy(dst, src); + } + + wrap1D(std::array const& src) + { + vk::ConstExpression1DArrayCopy::copy(dst, src); + } + + float dst[3]; + }; + + float src1D[3]; + src1D[0] = 1.0f; + src1D[1] = 2.0f; + src1D[2] = 3.0f; + + wrap1D w11(src1D); + + std::array asrc1D; + asrc1D[0] = 1.0f; + asrc1D[1] = 2.0f; + asrc1D[2] = 3.0f; + + wrap1D w12(asrc1D); + + struct wrap2D + { + wrap2D(const float src2D[3][4]) + { + vk::ConstExpression2DArrayCopy::copy(dst, src2D); + } + + wrap2D(std::array, 3> const& src2D) + { + vk::ConstExpression2DArrayCopy::copy(dst, src2D); + } + + float dst[3][4]; + }; + + float src2D[3][4]; + src2D[0][0] = 1.0f; + src2D[0][1] = 2.0f; + src2D[0][2] = 3.0f; + src2D[0][3] = 4.0f; + src2D[1][0] = 5.0f; + src2D[1][1] = 6.0f; + src2D[1][2] = 7.0f; + src2D[1][3] = 8.0f; + src2D[2][0] = 9.0f; + src2D[2][1] = 10.0f; + src2D[2][2] = 11.0f; + src2D[2][3] = 12.0f; + + wrap2D w21(src2D); + + std::array,3> asrc; + asrc[0][0] = 1.0f; + asrc[0][1] = 2.0f; + asrc[0][2] = 3.0f; + asrc[0][3] = 4.0f; + asrc[1][0] = 5.0f; + asrc[1][1] = 6.0f; + asrc[1][2] = 7.0f; + asrc[1][3] = 8.0f; + asrc[2][0] = 9.0f; + asrc[2][1] = 10.0f; + asrc[2][2] = 11.0f; + asrc[2][3] = 12.0f; + + wrap2D aw22(asrc); + + return 0; +} diff --git a/tests/ArrayCopy/CMakeLists.txt b/tests/ArrayCopy/CMakeLists.txt new file mode 100644 index 0000000..2f3479e --- /dev/null +++ b/tests/ArrayCopy/CMakeLists.txt @@ -0,0 +1,34 @@ +# Copyright(c) 2018, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.2) + +project(ArrayCopy) + +set(HEADERS +) + +set(SOURCES + ArrayCopy.cpp +) + +source_group(headers FILES ${HEADERS}) +source_group(sources FILES ${SOURCES}) + +add_executable(ArrayCopy + ${HEADERS} + ${SOURCES} +) + +set_target_properties(ArrayCopy PROPERTIES FOLDER "Tests") diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 0eb5af9..e9e90c6 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -2901,16 +2901,10 @@ namespace VULKAN_HPP_NAMESPACE class PrivateConstExpression2DArrayCopy { public: - VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N], const T src[N] ) VULKAN_HPP_NOEXCEPT + VULKAN_HPP_CONSTEXPR_14 static void copy( T * dst, T const* src ) VULKAN_HPP_NOEXCEPT { PrivateConstExpression2DArrayCopy::copy( dst, src ); - dst[I - 1][J - 1] = src[I - 1][J - 1]; - } - - VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N], std::array const& src ) VULKAN_HPP_NOEXCEPT - { - PrivateConstExpression2DArrayCopy::copy( dst, src ); - dst[I - 1][J - 1] = src[I - 1][J - 1]; + dst[(I - 1) * M + J - 1] = src[(I - 1) * M + J - 1]; } }; @@ -2918,25 +2912,17 @@ namespace VULKAN_HPP_NAMESPACE class PrivateConstExpression2DArrayCopy { public: - VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N], const T src[N] ) VULKAN_HPP_NOEXCEPT - { - PrivateConstExpression2DArrayCopy::copy( dst, src ); - } - - VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N], std::array const& src ) VULKAN_HPP_NOEXCEPT + VULKAN_HPP_CONSTEXPR_14 static void copy( T * dst, T const* src ) VULKAN_HPP_NOEXCEPT { PrivateConstExpression2DArrayCopy::copy( dst, src ); } }; - template - class PrivateConstExpression2DArrayCopy + template + class PrivateConstExpression2DArrayCopy { public: - VULKAN_HPP_CONSTEXPR_14 static void copy( T /*dst*/[N], const T /*src*/[N] ) VULKAN_HPP_NOEXCEPT - {} - - VULKAN_HPP_CONSTEXPR_14 static void copy( T /*dst*/[N], std::array const& /*src*/ ) VULKAN_HPP_NOEXCEPT + VULKAN_HPP_CONSTEXPR_14 static void copy( T * /*dst*/, T const* /*src*/ ) VULKAN_HPP_NOEXCEPT {} }; @@ -2946,12 +2932,12 @@ namespace VULKAN_HPP_NAMESPACE public: VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N][M], const T src[N][M] ) VULKAN_HPP_NOEXCEPT { - PrivateConstExpression2DArrayCopy::copy( dst, src ); + PrivateConstExpression2DArrayCopy::copy( &dst[0][0], &src[0][0] ); } VULKAN_HPP_CONSTEXPR_14 static void copy( T dst[N][M], std::array, N> const& src ) VULKAN_HPP_NOEXCEPT { - PrivateConstExpression2DArrayCopy::copy( dst, src ); + PrivateConstExpression2DArrayCopy::copy( &dst[0][0], src.data()->data() ); } };