Merge pull request #1212 from asuessenbach/formatTraits

Extract trait functions on vk::Format into the additional header vulkan_format_traits.hpp.
This commit is contained in:
Andreas Süßenbach 2022-02-21 11:35:53 +01:00 committed by GitHub
commit cccf0a62b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 7472 additions and 7326 deletions

View File

@ -85,6 +85,8 @@ file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan.hpp vulkan_hpp)
string(REPLACE "\\" "\\\\" vulkan_hpp ${vulkan_hpp})
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_enums.hpp vulkan_enums_hpp)
string(REPLACE "\\" "\\\\" vulkan_enums_hpp ${vulkan_enums_hpp})
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_format_traits.hpp vulkan_format_traits_hpp)
string(REPLACE "\\" "\\\\" vulkan_format_traits_hpp ${vulkan_format_traits_hpp})
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_funcs.hpp vulkan_funcs_hpp)
string(REPLACE "\\" "\\\\" vulkan_funcs_hpp ${vulkan_funcs_hpp})
file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_handles.hpp vulkan_handles_hpp)
@ -97,6 +99,7 @@ file(TO_NATIVE_PATH ${VulkanHeaders_INCLUDE_DIR}/vulkan/vulkan_raii.hpp vulkan_r
string(REPLACE "\\" "\\\\" vulkan_raii_hpp ${vulkan_raii_hpp})
add_definitions(-DVULKAN_HPP_FILE="${vulkan_hpp}"
-DVULKAN_ENUMS_HPP_FILE="${vulkan_enums_hpp}"
-DVULKAN_FORMAT_TRAITS_HPP_FILE="${vulkan_format_traits_hpp}"
-DVULKAN_FUNCS_HPP_FILE="${vulkan_funcs_hpp}"
-DVULKAN_HANDLES_HPP_FILE="${vulkan_handles_hpp}"
-DVULKAN_STRUCTS_HPP_FILE="${vulkan_structs_hpp}"

View File

@ -504,7 +504,7 @@ vulkan.hpp provides a couple of type traits, easing template programming:
### vk::Format trait functions
vulkan.hpp provides a couple of trait functions on `vk::Format`. With C++14 and above, all those functions are marked as `constexpr`, that is with appropriate arguments, they are resolved by the compiler.
With the additional header `vulkan_format_traits.hpp`, a couple of trait functions on `vk::Format` are provided. With C++14 and above, all those functions are marked as `constexpr`, that is with appropriate arguments, they are resolved by the compiler.
- `uin8_t blockSize( vk::Format format );`
Gets the texel block size of this format in bytes.
- `uint8_t texelsPerBlock( vk::Format format );`

View File

@ -17876,7 +17876,6 @@ namespace VULKAN_HPP_NAMESPACE
)";
str += typeTraits;
str += generator.generateEnums();
str += generator.generateFormatTraits();
str += generator.generateIndexTypeTraits();
str += generator.generateBitmasks();
str += R"(
@ -17885,6 +17884,24 @@ namespace VULKAN_HPP_NAMESPACE
)";
writeToFile( str, VULKAN_ENUMS_HPP_FILE );
std::cout << "VulkanHppGenerator: Generating " << VULKAN_FORMAT_TRAITS_HPP_FILE << " ..." << std::endl;
str = generator.getVulkanLicenseHeader();
str += +R"(
#ifndef VULKAN_FORMAT_TRAITS_HPP
# define VULKAN_FORMAT_TRAITS_HPP
#include <vulkan/vulkan.hpp>
namespace VULKAN_HPP_NAMESPACE
{
)";
str += generator.generateFormatTraits();
str += R"(
} // namespace VULKAN_HPP_NAMESPACE
#endif
)";
writeToFile( str, VULKAN_FORMAT_TRAITS_HPP_FILE );
std::cout << "VulkanHppGenerator: Generating " << VULKAN_HANDLES_HPP_FILE << " ..." << std::endl;
str.clear();
str = generator.getVulkanLicenseHeader();

View File

@ -0,0 +1,37 @@
# 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)
if (NOT TESTS_BUILD_ONLY_DYNAMIC)
project(FormatTraits)
set(HEADERS
)
set(SOURCES
FormatTraits.cpp
)
source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES})
add_executable(FormatTraits
${HEADERS}
${SOURCES}
)
set_target_properties(FormatTraits PROPERTIES FOLDER "Tests")
target_link_libraries(FormatTraits "${Vulkan_LIBRARIES}")
endif()

View File

@ -0,0 +1,73 @@
// 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 : FormatTraits
// Compile test on using format traits functions
#include <vulkan/vulkan_format_traits.hpp>
int main( int /*argc*/, char ** /*argv*/ )
{
static_assert( vk::blockSize( vk::Format::eR4G4UnormPack8 ) == 1, "Wrong blocksize !" );
vk::Format format = vk::Format::eR4G4UnormPack8;
if ( vk::texelsPerBlock( format ) == 1 )
{
format = vk::Format::eR4G4B4A4UnormPack16;
}
assert( vk::blockExtent( vk::Format::eBc1RgbUnormBlock )[2] == 1 );
format = vk::Format::eBc1RgbUnormBlock;
if ( std::string( vk::compressionScheme( format ) ) == "BC" )
{
format = vk::Format::eR4G4UnormPack8;
}
static_assert( vk::isCompressed( vk::Format::eBc1RgbSrgbBlock ), "IsCompressed ?" );
assert( vk::packed( format ) == 8 );
if ( vk::componentsAreCompressed( format ) )
{
format = vk::Format::eBc1RgbUnormBlock;
}
constexpr vk::Format constFormat = vk::Format::eR4G4UnormPack8;
static_assert( vk::componentBits( constFormat, 1 ) == 4, "Wrong component bits !" );
assert( vk::componentCount( constFormat ) == 2 );
if ( strcmp( vk::componentName( constFormat, 0 ), "R" ) == 0 )
{
format = constFormat;
}
assert( std::string( vk::componentNumericFormat( constFormat, 1 ) ) == "UNORM" );
static_assert( vk::componentPlaneIndex( constFormat, 8 ) == 0, "Hoo" );
if ( vk::planeCount( format ) != 1 )
{
format = constFormat;
}
assert( vk::planeCompatibleFormat( vk::Format::eG8B8R83Plane420Unorm, 2 ) == vk::Format::eR8Unorm );
if ( vk::planeHeightDivisor( format, 0 ) == vk::planeWidthDivisor( format, 0 ) )
{
format = vk::Format::eG8B8R83Plane420Unorm;
}
return 0;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff