From 456d6483a475e9825bf57aec5a902b75b2c221ad Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Sat, 12 Feb 2022 20:48:03 +0100 Subject: [PATCH 01/91] exclude PSTL from ALL targets, don't use their install targets! --- 3rdparty/CMakeLists.txt | 2 +- 3rdparty/pstl/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 70a7336bdc..251ba86bc7 100755 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -65,7 +65,7 @@ if(DEFINED ENV{VULKAN_SDK}) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - add_subdirectory(pstl pstl) + add_subdirectory(pstl pstl EXCLUDE_FROM_ALL) endif() # SDL2 diff --git a/3rdparty/pstl/CMakeLists.txt b/3rdparty/pstl/CMakeLists.txt index 2f4469e2e7..f4fa4a5d6d 100644 --- a/3rdparty/pstl/CMakeLists.txt +++ b/3rdparty/pstl/CMakeLists.txt @@ -7,7 +7,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # only non-multi-generators and clang set(PREVIOUS_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) set(TBB_SANITIZE "" CACHE STRING "" FORCE) - add_subdirectory(oneTBB oneTBB) + add_subdirectory(oneTBB oneTBB EXCLUDE_FROM_ALL) if(PREVIOUS_BUILD_SHARED_LIBS) set(BUILD_SHARED_LIBS ${PREVIOUS_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE) From 48d316b71d3480637f1a82d0e6b9334bbde0e286 Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Sat, 12 Feb 2022 21:54:25 +0100 Subject: [PATCH 02/91] add nbl_install_programs to build system --- src/nbl/CMakeLists.txt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 25068456af..dc56269e34 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -674,6 +674,12 @@ nbl_install_headers("${NABLA_HEADERS_TO_INSTALL}" "${NBL_ROOT_PATH}/include") nbl_install_headers("${NABLA_HEADERS_TO_INSTALL_SOURCE_REFACTOR}" "${NBL_ROOT_PATH}/source/Nabla") nbl_install_config_header(BuildConfigOptions.h) +macro(nbl_install_program _TRGT) + install(PROGRAMS $ DESTINATION lib CONFIGURATIONS Release) + install(PROGRAMS $ DESTINATION debug/lib CONFIGURATIONS Debug) + install(PROGRAMS $ DESTINATION relwithdebinfo/lib CONFIGURATIONS RelWithDebInfo) +endmacro() + macro(nbl_install_lib _TRGT) install(TARGETS ${_TRGT} ARCHIVE DESTINATION lib CONFIGURATIONS Release) install(TARGETS ${_TRGT} ARCHIVE DESTINATION debug/lib CONFIGURATIONS Debug) @@ -718,8 +724,8 @@ nbl_install_lib(zlibstatic) nbl_install_lib(simdjson) nbl_install_lib(volk) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - nbl_install_lib(tbb) - nbl_install_lib(tbbmalloc) - nbl_install_lib(tbbmalloc_proxy) + nbl_install_program(tbb) + nbl_install_program(tbbmalloc) + nbl_install_program(tbbmalloc_proxy) endif() From be178c4d912140edaeaffd8bd774ad61d7886a57 Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Sun, 13 Feb 2022 00:07:57 +0100 Subject: [PATCH 03/91] Add missing headers to install target --- src/nbl/CMakeLists.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index dc56269e34..73a29710d3 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -176,11 +176,23 @@ file(GLOB_RECURSE TEMP_GLOB_RES "${NBL_ROOT_PATH}/include/*.h") set(NABLA_HEADERS_PUBLIC ${NABLA_HEADERS_PUBLIC} ${TEMP_GLOB_RES}) file(GLOB_RECURSE TEMP_GLOB_RES "${NBL_ROOT_PATH}/include/*.tcc") set(NABLA_HEADERS_PUBLIC ${NABLA_HEADERS_PUBLIC} ${TEMP_GLOB_RES}) +file(GLOB_RECURSE TEMP_GLOB_RES "${NBL_ROOT_PATH}/src/*.h") +set(NABLA_HEADERS_PUBLIC2 ${NABLA_HEADERS_PUBLIC2} ${TEMP_GLOB_RES}) # TODO: we should have moved all headers from src directory to /include, but we need it for install target + +foreach(NBL_CURRENT_HEADER IN LISTS NABLA_HEADERS_PUBLIC2) + install(FILES ${NBL_CURRENT_HEADER} DESTINATION include CONFIGURATIONS Release) + install(FILES ${NBL_CURRENT_HEADER} DESTINATION debug/include CONFIGURATIONS Debug) + install(FILES ${NBL_CURRENT_HEADER} DESTINATION relwithdebinfo/include CONFIGURATIONS RelWithDebInfo) + + message(STATUS ${NBL_CURRENT_HEADER}) +endforeach() + +unset(NABLA_HEADERS_PUBLIC2 ${NBL_TMP_FULL_PATHS}) file(GLOB_RECURSE NABLA_HEADERS_PRIV1 "*.h") file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") # just gather all the header files and later put them into project so it's easy to search for things using IDE -set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) +set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) # see, we don't want NABLA_HEADERS_PUBLIC2 here set(NBL_CORE_SOURCES ${NBL_ROOT_PATH}/src/nbl/core/IReferenceCounted.cpp @@ -656,7 +668,6 @@ start_tracking_variables_for_propagation_to_parent() add_subdirectory(ext) propagate_changed_variables_to_parent_scope() - set(NABLA_HEADERS_TO_INSTALL ${NABLA_HEADERS_PUBLIC} ) From d8ed2084f6ddfe5af4d11779475a3c487c606265 Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Sun, 13 Feb 2022 00:14:03 +0100 Subject: [PATCH 04/91] remove status message --- src/nbl/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 73a29710d3..4d75ef7eda 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -183,8 +183,6 @@ foreach(NBL_CURRENT_HEADER IN LISTS NABLA_HEADERS_PUBLIC2) install(FILES ${NBL_CURRENT_HEADER} DESTINATION include CONFIGURATIONS Release) install(FILES ${NBL_CURRENT_HEADER} DESTINATION debug/include CONFIGURATIONS Debug) install(FILES ${NBL_CURRENT_HEADER} DESTINATION relwithdebinfo/include CONFIGURATIONS RelWithDebInfo) - - message(STATUS ${NBL_CURRENT_HEADER}) endforeach() unset(NABLA_HEADERS_PUBLIC2 ${NBL_TMP_FULL_PATHS}) From b03fce333ee032278bd784ab7de7636d0885c78b Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Sun, 13 Feb 2022 00:28:10 +0100 Subject: [PATCH 05/91] now it's properly, I wasn't careful --- src/nbl/CMakeLists.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 73a29710d3..ce23ee8e73 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -180,11 +180,12 @@ file(GLOB_RECURSE TEMP_GLOB_RES "${NBL_ROOT_PATH}/src/*.h") set(NABLA_HEADERS_PUBLIC2 ${NABLA_HEADERS_PUBLIC2} ${TEMP_GLOB_RES}) # TODO: we should have moved all headers from src directory to /include, but we need it for install target foreach(NBL_CURRENT_HEADER IN LISTS NABLA_HEADERS_PUBLIC2) - install(FILES ${NBL_CURRENT_HEADER} DESTINATION include CONFIGURATIONS Release) - install(FILES ${NBL_CURRENT_HEADER} DESTINATION debug/include CONFIGURATIONS Debug) - install(FILES ${NBL_CURRENT_HEADER} DESTINATION relwithdebinfo/include CONFIGURATIONS RelWithDebInfo) + cmake_path(GET NBL_CURRENT_HEADER PARENT_PATH NBL_CURRENT_HEADER_DIR) + file(RELATIVE_PATH NBL_TMP_REL_DESTINATION "${NBL_ROOT_PATH}/src" ${NBL_CURRENT_HEADER_DIR}) - message(STATUS ${NBL_CURRENT_HEADER}) + install(FILES ${NBL_CURRENT_HEADER} DESTINATION include/${NBL_TMP_REL_DESTINATION} CONFIGURATIONS Release) + install(FILES ${NBL_CURRENT_HEADER} DESTINATION debug/include/${NBL_TMP_REL_DESTINATION} CONFIGURATIONS Debug) + install(FILES ${NBL_CURRENT_HEADER} DESTINATION relwithdebinfo/include/${NBL_TMP_REL_DESTINATION} CONFIGURATIONS RelWithDebInfo) endforeach() unset(NABLA_HEADERS_PUBLIC2 ${NBL_TMP_FULL_PATHS}) @@ -192,7 +193,7 @@ unset(NABLA_HEADERS_PUBLIC2 ${NBL_TMP_FULL_PATHS}) file(GLOB_RECURSE NABLA_HEADERS_PRIV1 "*.h") file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") # just gather all the header files and later put them into project so it's easy to search for things using IDE -set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) # see, we don't want NABLA_HEADERS_PUBLIC2 here +set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) set(NBL_CORE_SOURCES ${NBL_ROOT_PATH}/src/nbl/core/IReferenceCounted.cpp From 835a27359a4f766fc6e1178b73885994cea1b46e Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 13:08:41 +0100 Subject: [PATCH 06/91] Feature TODOs for @sadiuk --- include/nbl/system/CFilePOSIX.h | 4 +- include/nbl/system/CFileWin32.h | 4 +- include/nbl/system/CSystemAndroid.h | 2 +- include/nbl/system/CSystemWin32.h | 2 +- include/nbl/system/ISystem.h | 15 ++++---- source/Nabla/COSOperator.cpp | 57 +---------------------------- source/Nabla/COSOperator.h | 44 ++-------------------- src/nbl/system/CFilePOSIX.cpp | 2 +- 8 files changed, 19 insertions(+), 111 deletions(-) diff --git a/include/nbl/system/CFilePOSIX.h b/include/nbl/system/CFilePOSIX.h index a9006dfaac..e42c1ef24b 100644 --- a/include/nbl/system/CFilePOSIX.h +++ b/include/nbl/system/CFilePOSIX.h @@ -11,7 +11,7 @@ namespace nbl::system using native_file_handle_t = int; using native_file_mapping_handle_t = void*; private: - bool m_openedProperly = true; + bool m_openedProperly = true; // TODO: @sadiuk remove size_t m_size = 0; native_file_handle_t m_native = -1; native_file_mapping_handle_t m_memoryMappedObj; @@ -22,7 +22,7 @@ namespace nbl::system virtual size_t getSize() const override; virtual void* getMappedPointer() override; virtual const void* getMappedPointer() const override; - bool isOpenedProperly() const { return m_openedProperly; } + bool isOpenedProperly() const { return m_openedProperly; } // TODO: @sadiuk remove private: virtual size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) override; virtual size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) override; diff --git a/include/nbl/system/CFileWin32.h b/include/nbl/system/CFileWin32.h index fe49adc305..84a2614337 100644 --- a/include/nbl/system/CFileWin32.h +++ b/include/nbl/system/CFileWin32.h @@ -15,7 +15,7 @@ class CFileWin32 : public IFile using native_file_handle_t = HANDLE; private: DWORD m_allocGranularity; - bool m_openedProperly = true; + bool m_openedProperly = true; // TODO: @sadiuk remove size_t m_size = 0; native_file_handle_t m_native = nullptr; HANDLE m_fileMappingObj = nullptr; @@ -27,7 +27,7 @@ class CFileWin32 : public IFile virtual size_t getSize() const override; virtual void* getMappedPointer() override; virtual const void* getMappedPointer() const override; - bool isOpenedProperly() const { return m_openedProperly; } + bool isOpenedProperly() const { return m_openedProperly; } // TODO: @sadiuk remove private: virtual size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) override; virtual size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) override; diff --git a/include/nbl/system/CSystemAndroid.h b/include/nbl/system/CSystemAndroid.h index 8bb977b75e..a837699404 100644 --- a/include/nbl/system/CSystemAndroid.h +++ b/include/nbl/system/CSystemAndroid.h @@ -28,7 +28,7 @@ namespace nbl::system } SystemInfo getSystemInfo() const override { - assert(false); // TODO + assert(false); // TODO: @sadiuk return SystemInfo(); } }; diff --git a/include/nbl/system/CSystemWin32.h b/include/nbl/system/CSystemWin32.h index 0489c8097e..71a1af160d 100644 --- a/include/nbl/system/CSystemWin32.h +++ b/include/nbl/system/CSystemWin32.h @@ -26,7 +26,7 @@ class CSystemWin32 : public ISystem { public: CSystemWin32(core::smart_refctd_ptr&& caller) : ISystem(std::move(caller)) {} - //LOL the struct definition wasn't added to winapi headers do they ask to declare them yourself + //LOL the struct definition wasn't added to winapi headers do they ask to declare them yourself (probably in another header?) typedef struct _PROCESSOR_POWER_INFORMATION { ULONG Number; ULONG MaxMhz; diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index cc4b7d5576..3d67a665c0 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -12,7 +12,7 @@ #include "nbl/system/CFileView.h" #include "nbl/core/util/bitflag.h" -#if defined(_NBL_PLATFORM_LINUX_) +#if defined(_NBL_PLATFORM_LINUX_) // TODO: platform specific includes shouldn't be in global interface headers #include #endif @@ -205,7 +205,6 @@ class ISystem : public core::IReferenceCounted } m_loaders; core::CMultiObjectCache> m_cachedArchiveFiles; - //core::CMultiObjectCache m_cachedPathAliases; public: template @@ -286,13 +285,13 @@ class ISystem : public core::IReferenceCounted return file; } return nullptr; - #endif + #endif } //! Compile time resource ID template inline core::smart_refctd_ptr loadBuiltinData() { - #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ std::pair found = nbl::builtin::get_resource(); if (found.first && found.second) { @@ -301,9 +300,9 @@ class ISystem : public core::IReferenceCounted return fileView; } return nullptr; - #else + #else return loadBuiltinData(StringUniqueType::value); - #endif + #endif } //! Warning: blocking call @@ -487,12 +486,14 @@ class ISystem : public core::IReferenceCounted } } + // TODO: Merge SystemMemory into SystemInfo struct SystemMemory { uint32_t totalMemory = {}; uint32_t availableMemory = {}; }; + // TODO: integrate `getSystemMemory()` into `getSystemInfo()` static inline SystemMemory getSystemMemory() { SystemMemory systemMemory; @@ -513,7 +514,7 @@ class ISystem : public core::IReferenceCounted systemMemory.totalMemory = linuxSystemInfo.totalram; systemMemory.availableMemory = linuxSystemInfo.freeram; #endif - #elif defined(_NBL_PLATFORM_ANDROID_) + #elif defined(_NBL_PLATFORM_ANDROID_) // Also TODO: for POSIX/LINUX // @sadiuk TODO #elif defined(_NBL_PLATFORM_OSX_) // TODO: implement for OSX diff --git a/source/Nabla/COSOperator.cpp b/source/Nabla/COSOperator.cpp index bf6dac49f1..0b901b08ae 100644 --- a/source/Nabla/COSOperator.cpp +++ b/source/Nabla/COSOperator.cpp @@ -1,54 +1,3 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors - -#include "COSOperator.h" - -#ifdef _NBL_WINDOWS_API_ -#include -#else -#include -#include -#ifndef _NBL_SOLARIS_PLATFORM_ -#include -#include -#endif -#endif - -#if defined(_NBL_COMPILE_WITH_X11_DEVICE_) -#include "CIrrDeviceLinux.h" -#include -#endif - -namespace nbl -{ - -#if defined(_NBL_COMPILE_WITH_X11_DEVICE_) -// constructor linux - COSOperator::COSOperator(const core::stringc& osVersion, CIrrDeviceLinux* device) -: OperatingSystem(osVersion), IrrDeviceLinux(device) -{ -} -#endif - -// constructor -COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVersion) -{ - #ifdef _NBL_DEBUG - setDebugName("COSOperator"); - #endif -} - - -//! returns the current operating system version as string. -const core::stringc& COSOperator::getOperatingSystemVersion() const -{ - return OperatingSystem; -} - - - bool COSOperator::getProcessorSpeedMHz(uint32_t* MHz) const { #if defined(_NBL_WINDOWS_API_) && !defined(_WIN32_WCE ) @@ -154,8 +103,4 @@ bool COSOperator::getSystemMemory(uint32_t* Total, uint32_t* Avail) const // TODO: implement for OSX return false; #endif -} - - -} // end namespace - +} \ No newline at end of file diff --git a/source/Nabla/COSOperator.h b/source/Nabla/COSOperator.h index 6166d6e89a..53ff767e86 100644 --- a/source/Nabla/COSOperator.h +++ b/source/Nabla/COSOperator.h @@ -6,49 +6,11 @@ #ifndef __NBL_C_OS_OPERATOR_H_INCLUDED__ #define __NBL_C_OS_OPERATOR_H_INCLUDED__ -#include "IOSOperator.h" +// TODO: @sadiuk + virtual std::string getOperatingSystemVersion() const; -namespace nbl -{ - -class CIrrDeviceLinux; - -//! The Operating system operator provides operation system specific methods and informations. -class COSOperator : public IOSOperator -{ -public: - - // constructor -#if defined(_NBL_COMPILE_WITH_X11_DEVICE_) - COSOperator(const core::stringc& osversion, CIrrDeviceLinux* device); -#endif - COSOperator(const core::stringc& osversion); - - //! returns the current operation system version as string. - virtual const core::stringc& getOperatingSystemVersion() const; - - //! gets the processor speed in megahertz - //! \param Mhz: - //! \return Returns true if successful, false if not - virtual bool getProcessorSpeedMHz(uint32_t* MHz) const; - - //! gets the total and available system RAM in kB - //! \param Total: will contain the total system memory - //! \param Avail: will contain the available memory - //! \return Returns true if successful, false if not + // TODO: @sadiuk virtual bool getSystemMemory(uint32_t* Total, uint32_t* Avail) const; -private: - - core::stringc OperatingSystem; - -#if defined(_NBL_COMPILE_WITH_X11_DEVICE_) - CIrrDeviceLinux * IrrDeviceLinux; -#endif - -}; - -} // end namespace - #endif diff --git a/src/nbl/system/CFilePOSIX.cpp b/src/nbl/system/CFilePOSIX.cpp index af84242e28..ecd215e27b 100644 --- a/src/nbl/system/CFilePOSIX.cpp +++ b/src/nbl/system/CFilePOSIX.cpp @@ -1,4 +1,4 @@ -#ifdef __unix__ +#ifdef __unix__ // WTF: can it be `defined(_NBL_PLATFORM_ANDROID_) | defined(_NBL_PLATFORM_LINUX_)` instead? #include #include #include From 28fc967b035e2aa0090bdb79c3f43fa1a1d739fd Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 15:44:12 +0100 Subject: [PATCH 07/91] plan a half baked IFile utility, waiting on P0289R0 --- include/nbl/system/IFile.h | 43 +++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/include/nbl/system/IFile.h b/include/nbl/system/IFile.h index c965a32f27..b9992155ab 100644 --- a/include/nbl/system/IFile.h +++ b/include/nbl/system/IFile.h @@ -12,14 +12,20 @@ namespace nbl::system { class ISystem; + +// TODO: +//namespace impl +//{ template class future; +//} class IFile : public core::IReferenceCounted { - friend class ISystemCaller; - friend class ISystem; - friend class IFileArchive; + friend class ISystemCaller; + friend class ISystem; + friend class IFileArchive; + public: enum E_CREATE_FLAGS : uint32_t { @@ -54,6 +60,37 @@ class IFile : public core::IReferenceCounted void read(future& fut, void* buffer, size_t offset, size_t sizeToRead); void write(future& fut, const void* buffer, size_t offset, size_t sizeToWrite); + /* TODO: future utility + struct success + { + public: + success() = default; + ~success() = default; + inline explicit operator bool() + { + return m_internalFuture.get()==sizeToProcess; + } + inline bool operator!() + { + return m_internalFuture.get()!=sizeToProcess; + } + private: + friend IFile; + future m_internalFuture; + size_t sizeToProcess; + }; + void read(success& fut, void* buffer, size_t offset, size_t sizeToRead) + { + read(fut.m_internalFuture,buffer,offset,sizeToRead); + fut.sizeToProcess = sizeToRead; + } + void write(success& fut, const void* buffer, size_t offset, size_t sizeToWrite) + { + write(fut.m_internalFuture,buffer,offset,sizeToWrite); + fut.sizeToProcess = sizeToWrite; + } + */ + static path flattenFilename(const path& p); protected: From 1c371054c214f703326e05f2246f8180c51d02a8 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 15:45:25 +0100 Subject: [PATCH 08/91] review ZIP loader for @sadiuk, found one bug --- source/Nabla/CZipReader.cpp | 665 --------------------------- source/Nabla/CZipReader.h | 224 --------- src/nbl/system/CArchiveLoaderZip.cpp | 45 +- 3 files changed, 34 insertions(+), 900 deletions(-) delete mode 100644 source/Nabla/CZipReader.h diff --git a/source/Nabla/CZipReader.cpp b/source/Nabla/CZipReader.cpp index abea06d146..53a0b95b18 100644 --- a/source/Nabla/CZipReader.cpp +++ b/source/Nabla/CZipReader.cpp @@ -1,162 +1,3 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors -#ifdef NEW_FILESYSTEM -#include "CZipReader.h" -#include "CMemoryFile.h" -#include "CLimitReadFile.h" - -#include "nbl_os.h" -#include - -#ifdef __NBL_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ - -#include "CFileList.h" -#include "CReadFile.h" - -#ifdef _NBL_COMPILE_WITH_ZLIB_ - #include "zlib/zlib.h" - - #ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ - #include "aesGladman/fileenc.h" - #endif - #ifdef _NBL_COMPILE_WITH_BZIP2_ - #include "bzip2/bzlib.h" - #endif - #ifdef _NBL_COMPILE_WITH_LZMA_ - #include "lzma/LzmaDec.h" - #endif -#endif - -namespace nbl -{ -namespace io -{ - - -// ----------------------------------------------------------------------------- -// zip loader -// ----------------------------------------------------------------------------- - -//! Constructor -CArchiveLoaderZIP::CArchiveLoaderZIP(io::IFileSystem* fs) -: FileSystem(fs) -{ - #ifdef _NBL_DEBUG - setDebugName("CArchiveLoaderZIP"); - #endif -} - -//! returns true if the file maybe is able to be loaded by this class -bool CArchiveLoaderZIP::isALoadableFileFormat(const std::filesystem::path& filename) const -{ - return core::hasFileExtension(filename, "zip", "pk3") || - core::hasFileExtension(filename, "gz", "tgz"); -} - -//! Check to see if the loader can create archives of this type. -bool CArchiveLoaderZIP::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const -{ - return (fileType == EFAT_ZIP || fileType == EFAT_GZIP); -} - - -//! Creates an archive from the filename -/** \param file File handle to check. -\return Pointer to newly created archive, or 0 upon error. */ -IFileArchive* CArchiveLoaderZIP::createArchive(const std::filesystem::path& filename) const -{ - IFileArchive *archive = 0; - io::IReadFile* file = FileSystem->createAndOpenFile(filename); - - if (file) - { - archive = createArchive(file); - file->drop(); - } - - return archive; -} - -//! creates/loads an archive from the file. -//! \return Pointer to the created archive. Returns 0 if loading failed. -IFileArchive* CArchiveLoaderZIP::createArchive(io::IReadFile* file) const -{ - IFileArchive *archive = 0; - if (file) - { - file->seek(0); - - uint16_t sig; - file->read(&sig, 2); - - file->seek(0); - - bool isGZip = (sig == 0x8b1f); - - archive = new CZipReader(file, isGZip); - } - return archive; -} - -//! Check if the file might be loaded by this class -/** Check might look into the file. -\param file File handle to check. -\return True if file seems to be loadable. */ -bool CArchiveLoaderZIP::isALoadableFileFormat(io::IReadFile* file) const -{ - const size_t prevPos = file->getPos(); - file->seek(0u); - SZIPFileHeader header; - file->read( &header.Sig, 4 ); - file->seek(prevPos); - - return header.Sig == 0x04034b50 || // ZIP - (header.Sig&0xffff) == 0x8b1f; // gzip -} - -// ----------------------------------------------------------------------------- -// zip archive -// ----------------------------------------------------------------------------- - -CZipReader::CZipReader(IReadFile* file, bool isGZip) : CFileList(file ? file->getFileName() : std::filesystem::path("")), File(file), IsGZip(isGZip) -{ - #ifdef _NBL_DEBUG - setDebugName("CZipReader"); - #endif - - if (File) - { - File->grab(); - - // load file entries - if (IsGZip) - while (scanGZipHeader()) { } - else - while (scanZipHeader()) { } - } -} - -CZipReader::~CZipReader() -{ - if (File) - File->drop(); -} - - -//! get the archive type -E_FILE_ARCHIVE_TYPE CZipReader::getType() const -{ - return IsGZip ? EFAT_GZIP : EFAT_ZIP; -} - -const IFileList* CZipReader::getFileList() const -{ - return this; -} - - //! scans for a local header, returns false if there is no more local file header. //! The gzip file format seems to think that there can be multiple files in a gzip file //! but none @@ -251,506 +92,6 @@ bool CZipReader::scanGZipHeader() return false; } -//! scans for a local header, returns false if there is no more local file header. -bool CZipReader::scanZipHeader(bool ignoreGPBits) -{ - std::filesystem::path ZipFileName = ""; - SZipFileEntry entry; - entry.Offset = 0; - memset(&entry.header, 0, sizeof(SZIPFileHeader)); - - File->read(&entry.header, sizeof(SZIPFileHeader)); - - - if (entry.header.Sig != 0x04034b50) - return false; // local file headers end here. - - // read filename - { - char *tmp = new char [ entry.header.FilenameLength + 2 ]; - File->read(tmp, entry.header.FilenameLength); - tmp[entry.header.FilenameLength] = 0; - ZipFileName = tmp; - delete [] tmp; - } - -#ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ - // AES encryption - if ((entry.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (entry.header.CompressionMethod == 99)) - { - int16_t restSize = entry.header.ExtraFieldLength; - SZipFileExtraHeader extraHeader; - while (restSize) - { - File->read(&extraHeader, sizeof(extraHeader)); - restSize -= sizeof(extraHeader); - if (extraHeader.ID==(int16_t)0x9901) - { - SZipFileAESExtraData data; - File->read(&data, sizeof(data)); - - restSize -= sizeof(data); - if (data.Vendor[0]=='A' && data.Vendor[1]=='E') - { - // encode values into Sig - // AE-Version | Strength | ActualMode - entry.header.Sig = - ((data.Version & 0xff) << 24) | - (data.EncryptionStrength << 16) | - (data.CompressionMode); - File->seek(restSize, true); - break; - } - } - } - } - // move forward length of extra field. - else -#endif - if (entry.header.ExtraFieldLength) - File->seek(entry.header.ExtraFieldLength, true); - - // if bit 3 was set, use CentralDirectory for setup - if (!ignoreGPBits && entry.header.GeneralBitFlag & ZIP_INFO_IN_DATA_DESCRIPTOR) - { - SZIPFileCentralDirEnd dirEnd; - FileInfo.clear(); - Files.clear(); - // First place where the end record could be stored - File->seek(File->getSize()-22); - const char endID[] = {0x50, 0x4b, 0x05, 0x06, 0x0}; - char tmp[5]={'\0'}; - bool found=false; - // search for the end record ID - while (!found && File->getPos()>0) - { - int seek=8; - File->read(tmp, 4); - switch (tmp[0]) - { - case 0x50: - if (!strcmp(endID, tmp)) - { - seek=4; - found=true; - } - break; - case 0x4b: - seek=5; - break; - case 0x05: - seek=6; - break; - case 0x06: - seek=7; - break; - } - File->seek(-seek, true); - } - File->read(&dirEnd, sizeof(dirEnd)); - FileInfo.reserve(dirEnd.TotalEntries); - File->seek(dirEnd.Offset); - while (scanCentralDirectoryHeader()) { } - return false; - } - - // store position in file - entry.Offset = File->getPos(); - // move forward length of data - File->seek(entry.header.DataDescriptor.CompressedSize, true); - - #ifdef _NBL_DEBUG - //os::Debuginfo::print("added file from archive", ZipFileName.c_str()); - #endif - - addItem(ZipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, *ZipFileName.string().rbegin()=='/', FileInfo.size()); - FileInfo.push_back(entry); - - return true; -} - - -//! scans for a local header, returns false if there is no more local file header. -bool CZipReader::scanCentralDirectoryHeader() -{ - std::filesystem::path ZipFileName = ""; - SZIPFileCentralDirFileHeader entry; - File->read(&entry, sizeof(SZIPFileCentralDirFileHeader)); - - if (entry.Sig != 0x02014b50) - return false; // central dir headers end here. - - const long pos = File->getPos(); - File->seek(entry.RelativeOffsetOfLocalHeader); - scanZipHeader(true); - File->seek(pos+entry.FilenameLength+entry.ExtraFieldLength+entry.FileCommentLength); - FileInfo.back().header.DataDescriptor.CompressedSize=entry.CompressedSize; - FileInfo.back().header.DataDescriptor.UncompressedSize=entry.UncompressedSize; - FileInfo.back().header.DataDescriptor.CRC32=entry.CRC32; - Files.back().Size=entry.UncompressedSize; - return true; -} - - -//! opens a file by file name -IReadFile* CZipReader::createAndOpenFile(const std::filesystem::path& filename) -{ - auto found = findFile(Files.begin(),Files.end(),io::IFileSystem::flattenFilename(filename),false); - if (found==Files.end()) - return nullptr; - - // Irrlicht supports 0, 8, 12, 14, 99 - //0 - The file is stored (no compression) - //1 - The file is Shrunk - //2 - The file is Reduced with compression factor 1 - //3 - The file is Reduced with compression factor 2 - //4 - The file is Reduced with compression factor 3 - //5 - The file is Reduced with compression factor 4 - //6 - The file is Imploded - //7 - Reserved for Tokenizing compression algorithm - //8 - The file is Deflated - //9 - Reserved for enhanced Deflating - //10 - PKWARE Date Compression Library Imploding - //12 - bzip2 - Compression Method from libbz2, WinZip 10 - //14 - LZMA - Compression Method, WinZip 12 - //96 - Jpeg compression - Compression Method, WinZip 12 - //97 - WavPack - Compression Method, WinZip 11 - //98 - PPMd - Compression Method, WinZip 10 - //99 - AES encryption, WinZip 9 - - const SZipFileEntry &e = FileInfo[found->ID]; - wchar_t buf[64]; - int16_t actualCompressionMethod=e.header.CompressionMethod; - IReadFile* decrypted=0; - uint8_t* decryptedBuf=0; - uint32_t decryptedSize=e.header.DataDescriptor.CompressedSize; -#ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ - if ((e.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (e.header.CompressionMethod == 99)) - { - os::Printer::log("Reading encrypted file."); - uint8_t salt[16]={0}; - const uint16_t saltSize = (((e.header.Sig & 0x00ff0000) >>16)+1)*4; - File->seek(e.Offset); - File->read(salt, saltSize); - char pwVerification[2]; - char pwVerificationFile[2]; - File->read(pwVerification, 2); - fcrypt_ctx zctx; // the encryption context - int rc = fcrypt_init( - (e.header.Sig & 0x00ff0000) >>16, - (const unsigned char*)Password.c_str(), // the password - Password.size(), // number of bytes in password - salt, // the salt - (unsigned char*)pwVerificationFile, // on return contains password verifier - &zctx); // encryption context - if (strncmp(pwVerificationFile, pwVerification, 2)) - { - os::Printer::log("Wrong password"); - return 0; - } - decryptedSize= e.header.DataDescriptor.CompressedSize-saltSize-12; - decryptedBuf= new uint8_t[decryptedSize]; - uint32_t c = 0; - while ((c+32768)<=decryptedSize) - { - File->read(decryptedBuf+c, 32768); - fcrypt_decrypt( - decryptedBuf+c, // pointer to the data to decrypt - 32768, // how many bytes to decrypt - &zctx); // decryption context - c+=32768; - } - File->read(decryptedBuf+c, decryptedSize-c); - fcrypt_decrypt( - decryptedBuf+c, // pointer to the data to decrypt - decryptedSize-c, // how many bytes to decrypt - &zctx); // decryption context - - char fileMAC[10]; - char resMAC[10]; - rc = fcrypt_end( - (unsigned char*)resMAC, // on return contains the authentication code - &zctx); // encryption context - if (rc != 10) - { - os::Printer::log("Error on encryption closing"); - delete [] decryptedBuf; - return 0; - } - File->read(fileMAC, 10); - if (strncmp(fileMAC, resMAC, 10)) - { - os::Printer::log("Error on encryption check"); - delete [] decryptedBuf; - return 0; - } - decrypted = new io::CMemoryReadFile(decryptedBuf, decryptedSize, found->FullName); - actualCompressionMethod = (e.header.Sig & 0xffff); -#if 0 - if ((e.header.Sig & 0xff000000)==0x01000000) - { - } - else if ((e.header.Sig & 0xff000000)==0x02000000) - { - } - else - { - os::Printer::log("Unknown encryption method"); - return 0; - } -#endif - } -#endif - switch(actualCompressionMethod) - { - case 0: // no compression - { - delete[] decryptedBuf; - if (decrypted) - return decrypted; - else - return new CLimitReadFile(File, e.Offset, decryptedSize, found->FullName); - } - case 8: - { - #ifdef _NBL_COMPILE_WITH_ZLIB_ - - const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[ uncompressedSize ]; - if (!pBuf) - { - swprintf ( buf, 64, L"Not enough memory for decompressing %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete[] decryptedBuf; - if (decrypted) - decrypted->drop(); - return 0; - } - - uint8_t *pcData = decryptedBuf; - if (!pcData) - { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - swprintf ( buf, 64, L"Not enough memory for decompressing %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete[] decryptedBuf; - delete [] pBuf; - return 0; - } - - //memset(pcData, 0, decryptedSize); - File->seek(e.Offset); - File->read(pcData, decryptedSize); - } - - // Setup the inflate stream. - z_stream stream; - int32_t err; - - stream.next_in = (Bytef*)pcData; - stream.avail_in = (uInt)decryptedSize; - stream.next_out = (Bytef*)pBuf; - stream.avail_out = uncompressedSize; - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - - // Perform inflation. wbits < 0 indicates no zlib header inside the data. - err = inflateInit2(&stream, -MAX_WBITS); - if (err == Z_OK) - { - err = inflate(&stream, Z_FINISH); - inflateEnd(&stream); - if (err == Z_STREAM_END) - err = Z_OK; - err = Z_OK; - inflateEnd(&stream); - } - - if (decrypted) - decrypted->drop(); - else - delete[] pcData; - - delete[] decryptedBuf; - if (err != Z_OK) - { - swprintf ( buf, 64, L"Error decompressing %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete [] pBuf; - return 0; - } - else - { - auto ret = new io::CMemoryReadFile(pBuf, uncompressedSize, found->FullName); - delete[] pBuf; - return ret; - } - - #else - return 0; // zlib not compiled, we cannot decompress the data. - #endif - } - case 12: - { - #ifdef _NBL_COMPILE_WITH_BZIP2_ - - const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[ uncompressedSize ]; - if (!pBuf) - { - swprintf ( buf, 64, L"Not enough memory for decompressing %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete[] decryptedBuf; - if (decrypted) - decrypted->drop(); - return 0; - } - - uint8_t *pcData = decryptedBuf; - if (!pcData) - { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - swprintf ( buf, 64, L"Not enough memory for decompressing %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete [] pBuf; - delete[] decryptedBuf; - return 0; - } - - //memset(pcData, 0, decryptedSize); - File->seek(e.Offset); - File->read(pcData, decryptedSize); - } - - bz_stream bz_ctx={0}; - /* use BZIP2's default memory allocation - bz_ctx->bzalloc = NULL; - bz_ctx->bzfree = NULL; - bz_ctx->opaque = NULL; - */ - int err = BZ2_bzDecompressInit(&bz_ctx, 0, 0); /* decompression */ - if(err != BZ_OK) - { - os::Printer::log("bzip2 decompression failed. File cannot be read.", ELL_ERROR); - delete[] decryptedBuf; - return 0; - } - bz_ctx.next_in = (char*)pcData; - bz_ctx.avail_in = decryptedSize; - /* pass all input to decompressor */ - bz_ctx.next_out = pBuf; - bz_ctx.avail_out = uncompressedSize; - err = BZ2_bzDecompress(&bz_ctx); - err = BZ2_bzDecompressEnd(&bz_ctx); - - if (decrypted) - decrypted->drop(); - else - delete[] pcData; - - if (err != BZ_OK) - { - swprintf ( buf, 64, L"Error decompressing %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete [] pBuf; - delete[] decryptedBuf; - return 0; - } - else - { - auto ret = new io::CMemoryReadFile(pBuf, uncompressedSize, found->FullName); - delete[] pBuf; - return ret; - } - - #else - delete[] decryptedBuf; - os::Printer::log("bzip2 decompression not supported. File cannot be read.", ELL_ERROR); - return 0; - #endif - } - case 14: - { - #ifdef _NBL_COMPILE_WITH_LZMA_ - - uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[ uncompressedSize ]; - if (!pBuf) - { - swprintf ( buf, 64, L"Not enough memory for decompressing %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete[] decryptedBuf; - if (decrypted) - decrypted->drop(); - return 0; - } - - uint8_t *pcData = decryptedBuf; - if (!pcData) - { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - swprintf ( buf, 64, L"Not enough memory for decompressing %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete [] pBuf; - return 0; - } - - //memset(pcData, 0, decryptedSize); - File->seek(e.Offset); - File->read(pcData, decryptedSize); - } - - ELzmaStatus status; - SizeT tmpDstSize = uncompressedSize; - SizeT tmpSrcSize = decryptedSize; - - unsigned int propSize = (pcData[3]<<8)+pcData[2]; - int err = LzmaDecode((Byte*)pBuf, &tmpDstSize, - pcData+4+propSize, &tmpSrcSize, - pcData+4, propSize, - e.header.GeneralBitFlag&0x1?LZMA_FINISH_END:LZMA_FINISH_ANY, &status, - &lzmaAlloc); - uncompressedSize = tmpDstSize; // may be different to expected value - - if (decrypted) - decrypted->drop(); - else - delete[] pcData; - - delete[] decryptedBuf; - if (err != SZ_OK) - { - os::Printer::log( "Error decompressing", found->FullName, ELL_ERROR); - delete [] pBuf; - return 0; - } - else - return io::createMemoryReadFile(pBuf, uncompressedSize, found->FullName, true); - - #else - delete[] decryptedBuf; - os::Printer::log("lzma decompression not supported. File cannot be read.", ELL_ERROR); - return 0; - #endif - } - case 99: - // If we come here with an encrypted file, decryption support is missing - os::Printer::log("Decryption support not enabled. File cannot be read.", ELL_ERROR); - delete[] decryptedBuf; - return 0; - default: - swprintf ( buf, 64, L"file has unsupported compression method. %s", found->FullName.c_str() ); - os::Printer::log( buf, ELL_ERROR); - delete[] decryptedBuf; - return 0; - }; -} #ifdef _NBL_COMPILE_WITH_LZMA_ //! Used for LZMA decompression. The lib has no default memory management @@ -760,10 +101,4 @@ namespace void SzFree(void *p, void *address) { p = p; _NBL_ALIGNED_FREE(address); } ISzAlloc lzmaAlloc = { SzAlloc, SzFree }; } -#endif - -} // end namespace io -} // end namespace nbl - -#endif // __NBL_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ #endif \ No newline at end of file diff --git a/source/Nabla/CZipReader.h b/source/Nabla/CZipReader.h deleted file mode 100644 index 6756497cf8..0000000000 --- a/source/Nabla/CZipReader.h +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors -#ifdef NEW_FILESYSTEM -#ifndef __NBL_C_ZIP_READER_H_INCLUDED__ -#define __NBL_C_ZIP_READER_H_INCLUDED__ - -#include "nbl/asset/compile_config.h" - -#ifdef __NBL_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ - -#include "nbl/core/Types.h" -#include "nbl/system/IFile.h" -#include "IFileSystem.h" - -namespace nbl -{ -namespace io -{ - // set if the file is encrypted - const int16_t ZIP_FILE_ENCRYPTED = 0x0001; - // the fields crc-32, compressed size and uncompressed size are set to - // zero in the local header - const int16_t ZIP_INFO_IN_DATA_DESCRIPTOR = 0x0008; - -// byte-align structures -#include "nbl/nblpack.h" - - struct SZIPFileDataDescriptor - { - uint32_t CRC32; - uint32_t CompressedSize; - uint32_t UncompressedSize; - } PACK_STRUCT; - - struct SZIPFileHeader - { - uint32_t Sig; // 'PK0304' little endian (0x04034b50) - int16_t VersionToExtract; - int16_t GeneralBitFlag; - int16_t CompressionMethod; - int16_t LastModFileTime; - int16_t LastModFileDate; - SZIPFileDataDescriptor DataDescriptor; - int16_t FilenameLength; - int16_t ExtraFieldLength; - // filename (variable size) - // extra field (variable size ) - } PACK_STRUCT; - - struct SZIPFileCentralDirFileHeader - { - uint32_t Sig; // 'PK0102' (0x02014b50) - uint16_t VersionMadeBy; - uint16_t VersionToExtract; - uint16_t GeneralBitFlag; - uint16_t CompressionMethod; - uint16_t LastModFileTime; - uint16_t LastModFileDate; - uint32_t CRC32; - uint32_t CompressedSize; - uint32_t UncompressedSize; - uint16_t FilenameLength; - uint16_t ExtraFieldLength; - uint16_t FileCommentLength; - uint16_t DiskNumberStart; - uint16_t InternalFileAttributes; - uint32_t ExternalFileAttributes; - uint32_t RelativeOffsetOfLocalHeader; - - // filename (variable size) - // extra field (variable size) - // file comment (variable size) - - } PACK_STRUCT; - - struct SZIPFileCentralDirEnd - { - uint32_t Sig; // 'PK0506' end_of central dir signature // (0x06054b50) - uint16_t NumberDisk; // number of this disk - uint16_t NumberStart; // number of the disk with the start of the central directory - uint16_t TotalDisk; // total number of entries in the central dir on this disk - uint16_t TotalEntries; // total number of entries in the central dir - uint32_t Size; // size of the central directory - uint32_t Offset; // offset of start of centraldirectory with respect to the starting disk number - uint16_t CommentLength; // zipfile comment length - // zipfile comment (variable size) - } PACK_STRUCT; - - struct SZipFileExtraHeader - { - int16_t ID; - int16_t Size; - } PACK_STRUCT; - - struct SZipFileAESExtraData - { - int16_t Version; - uint8_t Vendor[2]; - uint8_t EncryptionStrength; - int16_t CompressionMode; - } PACK_STRUCT; - - enum E_GZIP_FLAGS - { - EGZF_TEXT_DAT = 1, - EGZF_CRC16 = 2, - EGZF_EXTRA_FIELDS = 4, - EGZF_FILE_NAME = 8, - EGZF_COMMENT = 16 - }; - - struct SGZIPMemberHeader - { - uint16_t sig; // 0x8b1f - uint8_t compressionMethod; // 8 = deflate - uint8_t flags; - uint32_t time; - uint8_t extraFlags; // slow compress = 2, fast compress = 4 - uint8_t operatingSystem; - } PACK_STRUCT; - -// Default alignment -#include "nbl/nblunpack.h" - - //! Contains extended info about zip files in the archive - struct SZipFileEntry - { - //! Position of data in the archive file - int32_t Offset; - - //! The header for this file containing compression info etc - SZIPFileHeader header; - }; - - //! Archiveloader capable of loading ZIP Archives - class CArchiveLoaderZIP : public IArchiveLoader - { - public: - - //! Constructor - CArchiveLoaderZIP(io::IFileSystem* fs); - - //! returns true if the file maybe is able to be loaded by this class - //! based on the file extension (e.g. ".zip") - virtual bool isALoadableFileFormat(const std::filesystem::path& filename) const; - - //! Check if the file might be loaded by this class - /** Check might look into the file. - \param file File handle to check. - \return True if file seems to be loadable. */ - virtual bool isALoadableFileFormat(io::IReadFile* file) const; - - //! Check to see if the loader can create archives of this type. - /** Check based on the archive type. - \param fileType The archive type to check. - \return True if the archile loader supports this type, false if not */ - virtual bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const; - - //! Creates an archive from the filename - /** \param file File handle to check. - \return Pointer to newly created archive, or 0 upon error. */ - virtual IFileArchive* createArchive(const std::filesystem::path& filename) const; - - //! creates/loads an archive from the file. - //! \return Pointer to the created archive. Returns 0 if loading failed. - virtual io::IFileArchive* createArchive(io::IReadFile* file) const; - - private: - io::IFileSystem* FileSystem; - }; - -/*! - Zip file Reader written April 2002 by N.Gebhardt. -*/ - class CZipReader : public virtual IFileArchive, virtual CFileList - { - protected: - //! destructor - virtual ~CZipReader(); - - public: - //! constructor - CZipReader(IReadFile* file, bool isGZip=false); - - //! opens a file by file name - virtual IReadFile* createAndOpenFile(const std::filesystem::path& filename); - - //! returns the list of files - virtual const IFileList* getFileList() const; - - //! get the archive type - virtual E_FILE_ARCHIVE_TYPE getType() const; - - protected: - - //! reads the next file header from a ZIP file, returns false if there are no more headers. - /* if ignoreGPBits is set, the item will be read despite missing - file information. This is used when reading items from the central - directory. */ - bool scanZipHeader(bool ignoreGPBits=false); - - //! the same but for gzip files - bool scanGZipHeader(); - - bool scanCentralDirectoryHeader(); - - IReadFile* File; - - // holds extended info about files - core::vector FileInfo; - - bool IsGZip; - }; - - -} // end namespace io -} // end namespace nbl - -#endif // __NBL_COMPILE_WITH_ZIP_ARCHIVE_LOADER_ -#endif - -#endif \ No newline at end of file diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index 612fc21dbd..72bd1d1550 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -32,7 +32,7 @@ namespace nbl::system system::future lenFuture; m_file->read(lenFuture, &dataLen, offset, 2); lenFuture.get(); - offset += 2; + offset += 2; // TODO: I think it should be `+= dataLen;` } std::filesystem::path zipFileName = ""; if (header.flags & EGZF_FILE_NAME) @@ -281,9 +281,28 @@ namespace nbl::system { const SZipFileEntry& e = m_fileInfo[found->ID]; wchar_t buf[64]; + // Nabla supports 0, 8, 12, 14, 99 + //0 - The file is stored (no compression) + //1 - The file is Shrunk + //2 - The file is Reduced with compression factor 1 + //3 - The file is Reduced with compression factor 2 + //4 - The file is Reduced with compression factor 3 + //5 - The file is Reduced with compression factor 4 + //6 - The file is Imploded + //7 - Reserved for Tokenizing compression algorithm + //8 - The file is Deflated + //9 - Reserved for enhanced Deflating + //10 - PKWARE Date Compression Library Imploding + //12 - bzip2 - Compression Method from libbz2, WinZip 10 + //14 - LZMA - Compression Method, WinZip 12 + //96 - Jpeg compression - Compression Method, WinZip 12 + //97 - WavPack - Compression Method, WinZip 11 + //98 - PPMd - Compression Method, WinZip 10 + //99 - AES encryption, WinZip 9 int16_t actualCompressionMethod = e.header.CompressionMethod; //TODO: CFileView factory // CFileViewVirtualAllocatorWin32 + // @sadiuk WTF!? You hand out a new file every time!? core::smart_refctd_ptr> decrypted = nullptr; uint8_t* decryptedBuf = 0; uint32_t decryptedSize = e.header.DataDescriptor.CompressedSize; @@ -318,18 +337,20 @@ namespace nbl::system } decryptedSize = e.header.DataDescriptor.CompressedSize - saltSize - 12; decryptedBuf = new uint8_t[decryptedSize]; + // + constexpr uint32_t kChunkSize = 0x8000u; uint32_t c = 0; - while ((c + 32768) <= decryptedSize) + while ((c + kChunkSize) <= decryptedSize) { { - read_blocking(m_file.get(), decryptedBuf + c, readOffset, 32768); - readOffset += 32768; + read_blocking(m_file.get(), decryptedBuf + c, readOffset, kChunkSize); + readOffset += kChunkSize; } fcrypt_decrypt( decryptedBuf + c, // pointer to the data to decrypt - 32768, // how many bytes to decrypt + kChunkSize, // how many bytes to decrypt &zctx); // decryption context - c += 32768; + c += kChunkSize; } { read_blocking(m_file.get(), decryptedBuf + c, readOffset, decryptedSize - c); @@ -395,7 +416,7 @@ namespace nbl::system auto a = core::make_smart_refctd_ptr>( core::smart_refctd_ptr(m_system), params.absolutePath, - IFile::ECF_READ_WRITE, + IFile::ECF_READ_WRITE, // TODO: should be READONLY buff, decryptedSize); return a; @@ -410,6 +431,7 @@ namespace nbl::system if (!pBuf) { delete[] decryptedBuf; + // TODO: log error return 0; } @@ -421,6 +443,7 @@ namespace nbl::system { delete[] decryptedBuf; delete[] pBuf; + // TODO: log error return 0; } @@ -462,6 +485,7 @@ namespace nbl::system if (err != Z_OK) { delete[] pBuf; + // TODO: log error return 0; } else @@ -469,7 +493,7 @@ namespace nbl::system auto ret = core::make_smart_refctd_ptr>( core::smart_refctd_ptr(m_system), params.absolutePath, - IFile::ECF_READ_WRITE, + IFile::ECF_READ_WRITE, // TODO: readonly! uncompressedSize); { write_blocking(ret.get(), pBuf, 0, uncompressedSize); @@ -547,9 +571,9 @@ namespace nbl::system } else { - auto ret = core::make_smart_refctd_ptr>(std::move(m_system), found->fullName, IFile::ECF_READ_WRITE, uncompressedSize); + auto ret = core::make_smart_refctd_ptr>(std::move(m_system), found->fullName, IFile::ECF_READ_WRITE, uncompressedSize); // TODO: readonly { - write_blocking(decrypted.get(), pBuf, 0, uncompressedSize); + write_blocking(decrypted.get(), pBuf, 0, uncompressedSize); // huh!? } delete[] pBuf; return ret; @@ -564,7 +588,6 @@ namespace nbl::system case 14: { #ifdef _NBL_COMPILE_WITH_LZMA_ - uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; char* pBuf = new char[uncompressedSize]; if (!pBuf) From 70567f75b922774594bfad28f705dfc16e62f6e5 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 15:56:56 +0100 Subject: [PATCH 09/91] review TAR archive loader --- include/nbl/system/CArchiveLoaderTar.h | 2 +- source/Nabla/CTarReader.cpp | 194 +------------------------ source/Nabla/CTarReader.h | 129 ---------------- src/nbl/system/CArchiveLoaderTar.cpp | 2 +- 4 files changed, 3 insertions(+), 324 deletions(-) delete mode 100644 source/Nabla/CTarReader.h diff --git a/include/nbl/system/CArchiveLoaderTar.h b/include/nbl/system/CArchiveLoaderTar.h index 095c216294..d859fbff76 100644 --- a/include/nbl/system/CArchiveLoaderTar.h +++ b/include/nbl/system/CArchiveLoaderTar.h @@ -66,7 +66,7 @@ namespace nbl::system CArchiveLoaderTar(core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(system), std::move(logger)) {} virtual bool isALoadableFileFormat(IFile* file) const override { - return file->getFileName().extension() == ".tar"; + return file->getFileName().extension() == ".tar"; // TODO: ekhm, check the old CTarReader } virtual const char** getAssociatedFileExtensions() const override diff --git a/source/Nabla/CTarReader.cpp b/source/Nabla/CTarReader.cpp index b86f141eb5..76f1b9ab28 100644 --- a/source/Nabla/CTarReader.cpp +++ b/source/Nabla/CTarReader.cpp @@ -1,75 +1,3 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors -#ifdef NEW_FILESYSTEM -#include "CTarReader.h" - -#ifdef __NBL_COMPILE_WITH_TAR_ARCHIVE_LOADER_ - -#include "CFileList.h" -#include "CLimitReadFile.h" -#include "nbl_os.h" -#include "errno.h" - -namespace nbl -{ -namespace io -{ - -//! Constructor -CArchiveLoaderTAR::CArchiveLoaderTAR(io::IFileSystem* fs) -: FileSystem(fs) -{ - #ifdef _NBL_DEBUG - setDebugName("CArchiveLoaderTAR"); - #endif -} - - -//! returns true if the file maybe is able to be loaded by this class -bool CArchiveLoaderTAR::isALoadableFileFormat(const std::filesystem::path& filename) const -{ - return core::hasFileExtension(filename, "tar"); -} - -//! Check to see if the loader can create archives of this type. -bool CArchiveLoaderTAR::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const -{ - return fileType == EFAT_TAR; -} - -//! Creates an archive from the filename -/** \param file File handle to check. -\return Pointer to newly created archive, or 0 upon error. */ -IFileArchive* CArchiveLoaderTAR::createArchive(const std::filesystem::path& filename) const -{ - IFileArchive *archive = 0; - io::IReadFile* file = FileSystem->createAndOpenFile(filename); - - if (file) - { - archive = createArchive(file); - file->drop(); - } - - return archive; -} - - -//! creates/loads an archive from the file. -//! \return Pointer to the created archive. Returns 0 if loading failed. -IFileArchive* CArchiveLoaderTAR::createArchive(io::IReadFile* file) const -{ - IFileArchive *archive = 0; - if (file) - { - file->seek(0); - archive = new CTarReader(file); - } - return archive; -} - //! Check if the file might be loaded by this class /** Check might look into the file. \param file File handle to check. @@ -119,124 +47,4 @@ bool CArchiveLoaderTAR::isALoadableFileFormat(io::IReadFile* file) const } } return checksum1 == checksum || checksum2 == (int32_t)checksum; -} - -/* - TAR Archive -*/ -CTarReader::CTarReader(IReadFile* file) : CFileList(file ? file->getFileName() : std::filesystem::path("")), File(file) -{ - #ifdef _NBL_DEBUG - setDebugName("CTarReader"); - #endif - - if (File) - { - File->grab(); - - // fill the file list - populateFileList(); - } -} - - -CTarReader::~CTarReader() -{ - if (File) - File->drop(); -} - -const IFileList* CTarReader::getFileList() const -{ - return this; -} - - -uint32_t CTarReader::populateFileList() -{ - STarHeader fHead; - Files.clear(); - - uint32_t pos = 0; - while (pos+sizeof(STarHeader) < File->getSize()) - { - // seek to next file header - File->seek(pos); - - // read the header - File->read(&fHead, sizeof(fHead)); - - // only add standard files for now - if (fHead.Link == ETLI_REGULAR_FILE || ETLI_REGULAR_FILE_OLD) - { - std::string fullPath = ""; - fullPath.reserve(255); - - // USTAR archives have a filename prefix - // may not be null terminated, copy carefully! - if (!strncmp(fHead.Magic, "ustar", 5)) - { - char* np = fHead.FileNamePrefix; - while(*np && (np - fHead.FileNamePrefix) < 155) - fullPath += *np; - np++; - } - - // append the file name - char* np = fHead.FileName; - while(*np && (np - fHead.FileName) < 100) - { - fullPath += *np; - np++; - } - - // get size - std::string sSize = ""; - sSize.reserve(12); - np = fHead.Size; - while(*np && (np - fHead.Size) < 12) - { - sSize += *np; - np++; - } - - uint32_t size = strtoul(sSize.c_str(), NULL, 8); - if (errno == ERANGE) - os::Printer::log("File too large", fullPath.c_str(), ELL_WARNING); - - // save start position - uint32_t offset = pos + 512; - - // move to next file header block - pos = offset + (size / 512) * 512 + ((size % 512) ? 512 : 0); - - // add file to list - addItem(fullPath, offset, size, false ); - } - else - { - // todo: ETLI_DIRECTORY, ETLI_LINK_TO_ARCHIVED_FILE - - // move to next block - pos += 512; - } - - } - - return Files.size(); -} - -//! opens a file by file name -IReadFile* CTarReader::createAndOpenFile(const std::filesystem::path& filename) -{ - auto it = findFile(Files.begin(),Files.end(),filename,false); - if (it!=Files.end()) - return new CLimitReadFile(File, it->Offset, it->Size, it->FullName); - - return 0; -} -} // end namespace io -} // end namespace nbl - -#endif // __NBL_COMPILE_WITH_TAR_ARCHIVE_LOADER_ -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/source/Nabla/CTarReader.h b/source/Nabla/CTarReader.h deleted file mode 100644 index e0a56783a9..0000000000 --- a/source/Nabla/CTarReader.h +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors -#ifdef NEW_FILESYSTEM -#ifndef __NBL_C_TAR_READER_H_INCLUDED__ -#define __NBL_C_TAR_READER_H_INCLUDED__ - -#include "nbl/asset/compile_config.h" - -#ifdef __NBL_COMPILE_WITH_TAR_ARCHIVE_LOADER_ - -#include "nbl/core/IReferenceCounted.h" -#include "nbl/system/IFile.h" -#include "IFileSystem.h" - -namespace nbl -{ -namespace io -{ - - enum E_TAR_LINK_INDICATOR - { - ETLI_REGULAR_FILE_OLD = 0 , - ETLI_REGULAR_FILE = '0', - ETLI_LINK_TO_ARCHIVED_FILE = '1', // Hard link - ETLI_SYMBOLIC_LINK = '2', - ETLI_CHAR_SPECIAL_DEVICE = '3', - ETLI_BLOCK_SPECIAL_DEVICE = '4', - ETLI_DIRECTORY = '5', - ETLI_FIFO_SPECIAL_FILE = '6', - ETLI_CONTIGUOUS_FILE = '7' - }; - -// byte-align structures -#include "nbl/nblpack.h" - - struct STarHeader - { - char FileName[100]; - char FileMode[8]; - char UserID[8]; - char GroupID[8]; - char Size[12]; - char ModifiedTime[12]; - char Checksum[8]; - char Link; - char LinkName[100]; - char Magic[6]; - char USTARVersion[2]; - char UserName[32]; - char GroupName[32]; - char DeviceMajor[8]; - char DeviceMinor[8]; - char FileNamePrefix[155]; - } PACK_STRUCT; - -// Default alignment -#include "nbl/nblunpack.h" - - //! Archiveloader capable of loading ZIP Archives - class CArchiveLoaderTAR : public IArchiveLoader - { - public: - - //! Constructor - CArchiveLoaderTAR(system::ISystem* fs); - - //! returns true if the file maybe is able to be loaded by this class - //! based on the file extension (e.g. ".tar") - virtual bool isALoadableFileFormat(const std::filesystem::path& filename) const; - - //! Check if the file might be loaded by this class - /** Check might look into the file. - \param file File handle to check. - \return True if file seems to be loadable. */ - virtual bool isALoadableFileFormat(io::IReadFile* file) const; - - //! Check to see if the loader can create archives of this type. - /** Check based on the archive type. - \param fileType The archive type to check. - \return True if the archile loader supports this type, false if not */ - virtual bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const; - - //! Creates an archive from the filename - /** \param file File handle to check. - \return Pointer to newly created archive, or 0 upon error. */ - virtual IFileArchive* createArchive(const std::filesystem::path& filename) const; - - //! creates/loads an archive from the file. - //! \return Pointer to the created archive. Returns 0 if loading failed. - virtual io::IFileArchive* createArchive(io::IReadFile* file) const; - - private: - io::IFileSystem* FileSystem; - }; - - - - class CTarReader : public virtual IFileArchive, virtual CFileList - { - protected: - virtual ~CTarReader(); - - public: - CTarReader(IReadFile* file); - - //! opens a file by file name - virtual IReadFile* createAndOpenFile(const std::filesystem::path& filename); - - //! returns the list of files - virtual const IFileList* getFileList() const; - - //! get the class Type - virtual E_FILE_ARCHIVE_TYPE getType() const { return EFAT_TAR; } - - private: - - uint32_t populateFileList(); - - IReadFile* File; - }; - -} // end namespace io -} // end namespace nbl - -#endif // __NBL_COMPILE_WITH_TAR_ARCHIVE_LOADER_ -#endif -#endif \ No newline at end of file diff --git a/src/nbl/system/CArchiveLoaderTar.cpp b/src/nbl/system/CArchiveLoaderTar.cpp index 75464766d3..9f45defabb 100644 --- a/src/nbl/system/CArchiveLoaderTar.cpp +++ b/src/nbl/system/CArchiveLoaderTar.cpp @@ -12,7 +12,7 @@ namespace nbl::system auto a = core::make_smart_refctd_ptr>( core::smart_refctd_ptr(m_system), params.absolutePath, - IFile::ECF_READ_WRITE, + IFile::ECF_READ_WRITE, // TODO: this file cannot grow, unsure whether we should allow write access! buff, found->size); return a; From f4fc401706121a98b382a7cbcf980d8632d8814f Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 15:59:25 +0100 Subject: [PATCH 10/91] remove CMake for dead submodules and 3rdparty deps --- 3rdparty/CMakeLists.txt | 239 +--------------------------------------- 1 file changed, 5 insertions(+), 234 deletions(-) diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index 70a7336bdc..ffbfd8a135 100755 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -18,8 +18,8 @@ if(NBL_UPDATE_GIT_SUBMODULE) update_git_submodule(./nbl_spirv_cross) update_git_submodule(./zlib) update_git_submodule(./openexr) - update_git_submodule(./utfcpp) - update_git_submodule(./convertutf) + update_git_submodule(./utfcpp) # TODO: remove + update_git_submodule(./convertutf) # TODO: remove update_git_submodule(./libpng) update_git_submodule(./openssl) update_git_submodule(./libjpeg-turbo) @@ -68,56 +68,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") add_subdirectory(pstl pstl) endif() -# SDL2 -if (NBL_COMPILE_WITH_SDL2) - set(SDL_STATIC_ENABLED_BY_DEFAULT ON) - set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) - set(SDL_THREADS_ENABLED_BY_DEFAULT OFF) - set(SDL_LOADSO_ENABLED_BY_DEFAULT ON) - # should I enable this - set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF) - set(SDL_SUBSYSTEMS "Audio Video Events Joystick Haptic Power Loadso CPUinfo Filesystem Sensor") - set(SDL_STATIC_PIC ON) - set(SDL_ATOMIC OFF) - set(SDL_FILESYSTEM OFF) - set(SDL_TIMERS OFF) - # oh why doesn't SDL2 prefix these options? - set(MMX OFF) - set(3DNOW OFF) - set(VIDEO_DIRECTFB OFF) - set(VIDEO_OPENGL ON) - set(PTHREADS OFF) - set(RENDER_D3D OFF) - set(RENDER_METAL OFF) - set(VIDEO_VIVANTE OFF) - # Metal? - set(VIDEO_KMSDRM OFF) - set(VIDEO_OFFSCREEN ON) - set(VIDEO_X11_XCURSOR ON) - set(VIDEO_X11_XINERAMA OFF) - set(VIDEO_X11_XINPUT ON) - set(VIDEO_X11_XRANDR ON) - set(VIDEO_X11_XSCRNSAVER ON) - set(VIDEO_X11_XSHAPE ON) - set(VIDEO_X11_XVM OFF) - # make sure as much gets shared as possible - set(OSS OFF) - set(ALSA_SHARED ON) - set(JACK_SHARED ON) - set(ESD_SHARED ON) - set(PULSEAUDIO_SHARED ON) - set(ARTS_SHARED ON) - set(NAS_SHARED ON) - set(SNDIO_SHARED ON) - set(FUSIONSOUND_SHARED ON) - set(LIBSAMPLERATE_SHARED ON) - set(WAYLAND_SHARED ON) - set(X11_SHARED ON) - add_subdirectory(SDL2 SDL2 EXCLUDE_FROM_ALL) -endif() - find_package(OpenGL OPTIONAL_COMPONENTS EGL) -find_package(Wayland) +find_package(Wayland) # TODO: remove, do it dynamically #[[if (OpenGL_EGL_FOUND) message(FATAL_ERROR "FOUND EGL!!") else() @@ -125,12 +77,8 @@ else() endif()]] # EGL set(EGL_NO_GLEW ON CACHE INTERNAL "" FORCE) -#if (EGL_NO_GLEW) -# message(FATAL_ERROR "EGL_NO_GLEW") -#else() -# message(FATAL_ERROR "NO EGL_NO_GLEW") -#endif() if (OpenGL_EGL_FOUND AND UNIX AND NOT APPLE) + # TODO: This Cannot work like that! set(EGL_PASSTHROUGH ON FORCE) if (WAYLAND_CLIENT_FOUND) set(EGL_USE_WAYLAND ON FORCE) @@ -308,6 +256,7 @@ add_library(spirv_cross OBJECT ) target_compile_definitions(spirv_cross PUBLIC SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) +# TODO: remove add_library(convert_utf OBJECT convertutf/ConvertUTF.cpp ) @@ -324,22 +273,6 @@ add_library(aesGladman OBJECT aesGladman/sha1.c ) -if (NBL_BUILD_CEGUI) # I absolutely hate and despise GLM - set(_OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) - set(_OLD_BUILD_STATIC_LIBS ${BUILD_STATIC_LIBS}) - set(BUILD_SHARED_LIBS OFF) - set(BUILD_STATIC_LIBS OFF) - option(GLM_TEST_ENABLE_CXX_14 "Enable C++ 14" ON) - if (NBL_FAST_MATH) - option(GLM_TEST_ENABLE_FAST_MATH "Enable fast math optimizations" ON) - endif() - option(GLM_TEST_ENABLE_SIMD_SSE4_2 "Enable SSE 4.2 optimizations" ON) - option(GLM_TEST_ENABLE "Build unit tests" OFF) - add_subdirectory(glm EXCLUDE_FROM_ALL) - set(BUILD_SHARED_LIBS ${_OLD_BUILD_SHARED_LIBS}) - set(BUILD_STATIC_LIBS ${_OLD_BUILD_STATIC_LIBS}) -endif() - option(GLM_TEST_ENABLE_SIMD_SSE4_2 "Enable SSE 4.2 optimizations" ON) option(GLM_TEST_ENABLE "Build unit tests" OFF) #add_subdirectory(glm EXCLUDE_FROM_ALL) @@ -371,160 +304,6 @@ if (NBL_BUILD_MITSUBA_LOADER) set(MITSUBA_LOADER_DEPENDENT_LIBS ${MITSUBA_LOADER_DEPENDENT_LIBS} PARENT_SCOPE) endif() -if (NBL_BUILD_CEGUI) - if(NBL_UPDATE_GIT_SUBMODULE) - update_git_submodule(./libexpat) - update_git_submodule(./CEGUI/pcre) - update_git_submodule(./CEGUI/glew) - update_git_submodule(./CEGUI/cegui) - endif() - add_subdirectory(CEGUI) - set(CEGUI_INCLUDE_PATH - ${CMAKE_CURRENT_SOURCE_DIR}/CEGUI/cegui/cegui/include - ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/cegui/include - ) - set(CEGUI_INCLUDE_PATH ${CEGUI_INCLUDE_PATH} PARENT_SCOPE) - - # surely there has to be a cleaner way of doing this - if (MSVC) - set(CEGUI_LIBS - ${CEGUI_DEPS_INSTALL_PATH}/lib/libglew32.lib - ${CEGUI_DEPS_INSTALL_PATH}/lib/freetype.lib - ${CEGUI_DEPS_INSTALL_PATH}/lib/expat.lib - ${CEGUI_DEPS_INSTALL_PATH}/lib/pcre.lib - ${CEGUI_DEPS_INSTALL_PATH}/lib/pcrecpp.lib - ${CEGUI_DEPS_INSTALL_PATH}/lib/pcreposix.lib - Winmm.lib - optimized ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUIOpenGLRenderer-0_Static.lib - optimized ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUIBase-0_Static.lib - optimized ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUIExpatParser_Static.lib - optimized ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUISTBImageCodec_Static.lib - optimized ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUICoreWindowRendererSet_Static.lib - optimized ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUICommonDialogs-0_Static.lib - debug ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUIOpenGLRenderer-0_Static_d.lib - debug ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUIBase-0_Static_d.lib - debug ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUIExpatParser_Static_d.lib - debug ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUISTBImageCodec_Static_d.lib - debug ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUICoreWindowRendererSet_Static_d.lib - debug ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/CEGUICommonDialogs-0_Static_d.lib - debug Dbghelp.lib - ) - else() - set(CEGUI_LIBS - ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/libCEGUIOpenGLRenderer-0_Static.a - ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/libCEGUIBase-0_Static.a - ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/libCEGUIExpatParser_Static.a - ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/libCEGUISTBImageCodec_Static.a - ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/libCEGUICoreWindowRendererSet_Static.a - ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/libCEGUICommonDialogs-0_Static.a - ${CEGUI_DEPS_INSTALL_PATH}/lib/libGLEW.a - ${CEGUI_DEPS_INSTALL_PATH}/lib/libfreetype.a - ${CEGUI_DEPS_INSTALL_PATH}/lib/libexpat.a - ${CEGUI_DEPS_INSTALL_PATH}/lib/libpcre.a - ${CEGUI_DEPS_INSTALL_PATH}/lib/libpcrecpp.a - ${CEGUI_DEPS_INSTALL_PATH}/lib/libpcreposix.a - ) - endif() - set(CEGUI_LIBS ${CEGUI_LIBS} PARENT_SCOPE) - - #[[ unsure if needed for now - install( - DIRECTORY ${CEGUI_DEPS_INSTALL_PATH}/include/ - DESTINATION ./include/nbl/ext/CEGUI/3rdparty - CONFIGURATIONS Release - ) - install( - DIRECTORY ${CEGUI_DEPS_INSTALL_PATH}/include/ - DESTINATION ./debug/include/nbl/ext/CEGUI/3rdparty - CONFIGURATIONS Debug - ) - install( - DIRECTORY ${CEGUI_DEPS_INSTALL_PATH}/lib/ - DESTINATION ./lib/nbl/ext/CEGUI - CONFIGURATIONS Release - ) - install( - DIRECTORY ${CEGUI_DEPS_INSTALL_PATH}/lib/ - DESTINATION ./debug/lib/nbl/ext/CEGUI - CONFIGURATIONS Debug - ) - ]]# - - # CEGUI headers - install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/CEGUI/cegui/cegui/include/CEGUI - DESTINATION ./include/nbl/ext/CEGUI - CONFIGURATIONS Release - ) - install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/CEGUI/cegui/cegui/include/CEGUI - DESTINATION ./debug/include/nbl/ext/CEGUI - CONFIGURATIONS Debug - ) - install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/CEGUI/cegui/cegui/include/CEGUI - DESTINATION ./relwithdebinfo/include/nbl/ext/CEGUI - CONFIGURATIONS RelWithDebInfo - ) - # CEGUI generated headers - install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/cegui/include/CEGUI - DESTINATION ./include/nbl/ext/CEGUI - CONFIGURATIONS Release - ) - install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/cegui/include/CEGUI - DESTINATION ./debug/include/nbl/ext/CEGUI - CONFIGURATIONS Debug - ) - install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/cegui/include/CEGUI - DESTINATION ./relwithdebinfo/include/nbl/ext/CEGUI - CONFIGURATIONS RelWithDebInfo - ) - # CEGUI libs - install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/ - DESTINATION ./lib/nbl/ext/CEGUI - CONFIGURATIONS Release - ) - install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/ - DESTINATION ./debug/lib/nbl/ext/CEGUI - CONFIGURATIONS Debug - ) - install( - DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/CEGUI/cegui/lib/ - DESTINATION ./relwithdebinfo/lib/nbl/ext/CEGUI - CONFIGURATIONS RelWithDebInfo - ) -endif() - -if (NBL_BUILD_RADEON_RAYS) - if(NBL_UPDATE_GIT_SUBMODULE) - update_git_submodule(./radeonrays) - endif() - - option(RR_NO_TESTS "RADEON_RAYS: don't do tests" ON) - option(RR_ENABLE_STATIC "RADEON_RAYS: compile into a static library" ON) - option(RR_EMBED_KERNELS "RADEON_RAYS: so we don't have to go looking for OpenCL kernel code" ON) - set(RR_USE_VULKAN OFF CACHE BOOL "RADEON_RAYS: Cannot use Vulkan for RR 2.0 the backend is broken" FORCE) - set(RR_ENABLE_BACKFACE_CULL OFF CACHE BOOL "RADEON_RAYS: Don't enable backface culling (we use the memory of the ray struct for something else there)." FORCE) - set(MSVC_USE_STATIC_CRT ON CACHE BOOL "Use /MT flag (static CRT) when compiling in MSVC") - add_subdirectory(radeonrays EXCLUDE_FROM_ALL) - - set(RADEON_RAYS_DEPENDENTS - RadeonRays - CLW - Calc - ) - set(RADEON_RAYS_DEPENDENTS ${RADEON_RAYS_DEPENDENTS} PARENT_SCOPE) - set(RADEON_RAYS_DEPENDENT_LIBS - RadeonRays - ) - set(RADEON_RAYS_DEPENDENT_LIBS ${RADEON_RAYS_DEPENDENT_LIBS} PARENT_SCOPE) -endif() - if (NBL_BUILD_BULLET) if(NBL_UPDATE_GIT_SUBMODULE) update_git_submodule(./bullet3) @@ -577,11 +356,6 @@ if (_NBL_COMPILE_WITH_OPEN_EXR_) IexMath ) endif() -if (NBL_COMPILE_WITH_SDL2 ) - list(APPEND NBL_3RDPARTY_TARGETS - SDL2-static - ) -endif() if(ANDROID AND NOT ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") list(APPEND NBL_3RDPARTY_TARGETS OpenSSL @@ -591,9 +365,6 @@ endif() if (NBL_BUILD_MITSUBA_LOADER) list(APPEND NBL_3RDPARTY_TARGETS expat) endif() -if (NBL_BUILD_RADEON_RAYS) - list(APPEND NBL_3RDPARTY_TARGETS ${RADEON_RAYS_DEPENDENTS}) -endif() if(ENABLE_HLSL) list(APPEND NBL_3RDPARTY_TARGETS HLSL) endif() From c95c533e52996f5ab84a7e6122e4c04444711f53 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 16:01:55 +0100 Subject: [PATCH 11/91] remove tuff we'll never reimplement --- examples_tests/CMakeLists.txt | 20 ++-- include/nbl/system/compile_config.h | 31 ----- include/nbl/system/declarations.h | 1 - source/Nabla/CMountPointReader.cpp | 168 -------------------------- source/Nabla/CMountPointReader.h | 84 ------------- source/Nabla/CPakReader.cpp | 176 ---------------------------- source/Nabla/CPakReader.h | 121 ------------------- 7 files changed, 8 insertions(+), 593 deletions(-) delete mode 100644 include/nbl/system/compile_config.h delete mode 100644 source/Nabla/CMountPointReader.cpp delete mode 100644 source/Nabla/CMountPointReader.h delete mode 100644 source/Nabla/CPakReader.cpp delete mode 100644 source/Nabla/CPakReader.h diff --git a/examples_tests/CMakeLists.txt b/examples_tests/CMakeLists.txt index f6c2c93672..d698e2d03b 100644 --- a/examples_tests/CMakeLists.txt +++ b/examples_tests/CMakeLists.txt @@ -13,16 +13,14 @@ add_subdirectory(04.Keyframe EXCLUDE_FROM_ALL) add_subdirectory(05.NablaTutorialExample EXCLUDE_FROM_ALL) add_subdirectory(06.MeshLoaders EXCLUDE_FROM_ALL) add_subdirectory(07.SubpassBaking EXCLUDE_FROM_ALL) -#add_subdirectory(08.UPFORGRABS EXCLUDE_FROM_ALL) +#add_subdirectory(08.REUSE EXCLUDE_FROM_ALL) add_subdirectory(09.ColorSpaceTest EXCLUDE_FROM_ALL) add_subdirectory(10.AllocatorTest EXCLUDE_FROM_ALL) add_subdirectory(11.LoDSystem EXCLUDE_FROM_ALL) add_subdirectory(12.glTF EXCLUDE_FROM_ALL) -if (NBL_BUILD_CEGUI) - #add_subdirectory(13.BRDF_Explorer EXCLUDE_FROM_ALL) -endif() +#add_subdirectory(13.REUSE EXCLUDE_FROM_ALL) add_subdirectory(14.ComputeScan EXCLUDE_FROM_ALL) -# 15 is reserved for Erfan +#REUSE 15 is reserved for Erfan add_subdirectory(16.OrderIndependentTransparency EXCLUDE_FROM_ALL) if (NBL_BUILD_BULLET AND NOT NBL_BUILD_ANDROID) # The reason why bullet shouldn't build on android: https://github.com/bulletphysics/bullet3/issues/4025 add_subdirectory(17.SimpleBulletIntegration EXCLUDE_FROM_ALL) # Needs example 08 to come back first @@ -33,19 +31,17 @@ endif() add_subdirectory(19.SIMDmatrixMultiplication EXCLUDE_FROM_ALL) add_subdirectory(20.Megatexture EXCLUDE_FROM_ALL) add_subdirectory(21.DynamicTextureIndexing EXCLUDE_FROM_ALL) # TODO: revive -if (NBL_BUILD_MITSUBA_LOADER AND NBL_BUILD_RADEON_RAYS) +if (NBL_BUILD_MITSUBA_LOADER) add_subdirectory(22.RaytracedAO EXCLUDE_FROM_ALL) endif() add_subdirectory(23.Autoexposure EXCLUDE_FROM_ALL) -#add_subdirectory(24.BufferSubDataAlignTest EXCLUDE_FROM_ALL) # TODO: @Anastazluk or @Hazardu +#add_subdirectory(24.REUSE EXCLUDE_FROM_ALL) # TODO: @Anastazluk or @Hazardu #add_subdirectory(25.Blur EXCLUDE_FROM_ALL) #add_subdirectory(26.MultidrawIndirectVSCPUCull EXCLUDE_FROM_ALL) add_subdirectory(27.PLYSTLDemo EXCLUDE_FROM_ALL) -if (NBL_BUILD_MITSUBA_LOADER AND NBL_BUILD_OPTIX) - #add_subdirectory(28.OptiXPathTracing EXCLUDE_FROM_ALL) -endif() +#add_subdirectory(28.REUSE EXCLUDE_FROM_ALL) add_subdirectory(29.SpecializationConstants EXCLUDE_FROM_ALL) -add_subdirectory(32.MultiThreadedRefCounting EXCLUDE_FROM_ALL) # TODO: @Anastazluk make this into example 04 +#add_subdirectory(32.REUSE EXCLUDE_FROM_ALL) # TODO: @Anastazluk make this into example 04 add_subdirectory(33.Draw3DLine EXCLUDE_FROM_ALL) add_subdirectory(34.LRUCacheUnitTest EXCLUDE_FROM_ALL) add_subdirectory(35.GeometryCreator EXCLUDE_FROM_ALL) @@ -76,4 +72,4 @@ add_subdirectory(56.RayQuery EXCLUDE_FROM_ALL) add_subdirectory(57.AndroidSample EXCLUDE_FROM_ALL) add_subdirectory(58.MediaUnpackingOnAndroid EXCLUDE_FROM_ALL) add_subdirectory(60.ClusteredRendering EXCLUDE_FROM_ALL) -add_subdirectory(0.ImportanceSamplingEnvMaps EXCLUDE_FROM_ALL) +add_subdirectory(0.ImportanceSamplingEnvMaps EXCLUDE_FROM_ALL) #TODO: integrate back into 42 diff --git a/include/nbl/system/compile_config.h b/include/nbl/system/compile_config.h deleted file mode 100644 index 41aa78c835..0000000000 --- a/include/nbl/system/compile_config.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#ifndef __NBL_SYSTEM_COMPILE_CONFIG_H_INCLUDED__ -#define __NBL_SYSTEM_COMPILE_CONFIG_H_INCLUDED__ - -#if defined(_NBL_PLATFORM_LINUX_) -# define _NBL_COMPILE_WITH_X11_DEVICE_ -#endif - -//! VidMode is ANCIENT -//#define NO_NBL_LINUX_X11_VIDMODE_ - -//! On some Linux systems the XF86 vidmode extension or X11 RandR are missing. Use these flags -//! to remove the dependencies such that Irrlicht will compile on those systems, too. -//! If you don't need colored cursors you can also disable the Xcursor extension -#if defined(_NBL_PLATFORM_LINUX_) && defined(_NBL_COMPILE_WITH_X11_) -# define _NBL_LINUX_X11_VIDMODE_ -# define _NBL_LINUX_X11_RANDR_ -#endif - -//! Define _NBL_COMPILE_WITH_X11_ to compile the Irrlicht engine with X11 support. -/** If you do not wish the engine to be compiled with X11, comment this -define out. */ -// Only used in LinuxDevice. -///#ifndef _NBL_SERVER_ -#define _NBL_COMPILE_WITH_X11_ -///#endif - -#endif diff --git a/include/nbl/system/declarations.h b/include/nbl/system/declarations.h index e4cd2fa827..1419d16c24 100644 --- a/include/nbl/system/declarations.h +++ b/include/nbl/system/declarations.h @@ -6,7 +6,6 @@ #define __NBL_SYSTEM_DECLARATIONS_H_INCLUDED__ #include "nbl/core/declarations.h" -#include "nbl/system/compile_config.h" // basic stuff #include "nbl/system/DynamicLibraryFunctionPointer.h" diff --git a/source/Nabla/CMountPointReader.cpp b/source/Nabla/CMountPointReader.cpp deleted file mode 100644 index 6bbac9a4cf..0000000000 --- a/source/Nabla/CMountPointReader.cpp +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors -#ifdef NEW_FILESYSTEM -#include "CMountPointReader.h" - -#ifdef __NBL_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ - -#include "CReadFile.h" -#include "nbl_os.h" - -namespace nbl -{ -namespace io -{ - -//! Constructor -CArchiveLoaderMount::CArchiveLoaderMount( io::IFileSystem* fs) -: FileSystem(fs) -{ - #ifdef _NBL_DEBUG - setDebugName("CArchiveLoaderMount"); - #endif -} - - -//! returns true if the file maybe is able to be loaded by this class -bool CArchiveLoaderMount::isALoadableFileFormat(const std::filesystem::path& filename) const -{ - std::filesystem::path fname(filename); - core::deletePathFromFilename(fname); - - if (!fname.string().size()) - return true; - IFileList* list = FileSystem->createFileList(); - bool ret = false; - if (list) - { - auto files = list->getFiles(); - // check if name is found as directory - if (list->findFile(files.begin(),files.end(),filename, true)!=files.end()) - ret=true; - list->drop(); - } - return ret; -} - -//! Check to see if the loader can create archives of this type. -bool CArchiveLoaderMount::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const -{ - return fileType == EFAT_FOLDER; -} - -//! Check if the file might be loaded by this class -bool CArchiveLoaderMount::isALoadableFileFormat(io::IReadFile* file) const -{ - return false; -} - -//! Creates an archive from the filename -IFileArchive* CArchiveLoaderMount::createArchive(const std::filesystem::path& filename) const -{ - IFileArchive *archive = 0; - - EFileSystemType current = FileSystem->setFileListSystem(FILESYSTEM_NATIVE); - - const std::filesystem::path save = FileSystem->getWorkingDirectory(); - std::filesystem::path fullPath = io::IFileSystem::flattenFilename(std::filesystem::absolute(filename)); - - if (FileSystem->changeWorkingDirectoryTo(fullPath)) - { - archive = new CMountPointReader(FileSystem, fullPath); - } - - FileSystem->changeWorkingDirectoryTo(save); - FileSystem->setFileListSystem(current); - - return archive; -} - -//! creates/loads an archive from the file. -//! \return Pointer to the created archive. Returns 0 if loading failed. -IFileArchive* CArchiveLoaderMount::createArchive(io::IReadFile* file) const -{ - return 0; -} - -//! compatible Folder Architecture -CMountPointReader::CMountPointReader(IFileSystem * parent, const std::filesystem::path& basename) - : CFileList(basename), Parent(parent) -{ - //! ensure CFileList path ends in a slash - if (*Path.string().rbegin() != '/' ) - Path += '/'; - - const std::filesystem::path& work = Parent->getWorkingDirectory(); - - Parent->changeWorkingDirectoryTo(basename); - buildDirectory(); - Parent->changeWorkingDirectoryTo(work); -} - - -//! returns the list of files -const IFileList* CMountPointReader::getFileList() const -{ - return this; -} - -void CMountPointReader::buildDirectory() -{ - IFileList * list = Parent->createFileList(); - if (!list) - return; - - auto files = list->getFiles(); - for (auto it=files.begin(); it!=files.end(); it++) - { - std::filesystem::path full = it->FullName; - full = full.string().substr(Path.string().size(), full.string().size() - Path.string().size()); - - if (!it->IsDirectory) - { - addItem(full, it->Offset, it->Size, false, RealFileNames.size()); - RealFileNames.push_back(it->FullName); - } - else - { - const std::filesystem::path rel = it->Name; - RealFileNames.push_back(it->FullName); - - std::filesystem::path pwd = Parent->getWorkingDirectory(); - if (*pwd.string().rbegin() != '/') - pwd.string() += '/'; - pwd += rel; - - if ( rel != "." && rel != ".." ) - { - addItem(full, 0, 0, true, 0); - Parent->changeWorkingDirectoryTo(pwd); - buildDirectory(); - Parent->changeWorkingDirectoryTo(".."); - } - } - } - - list->drop(); -} - -//! opens a file by file name -IReadFile* CMountPointReader::createAndOpenFile(const std::filesystem::path& filename) -{ - auto found = findFile(Files.begin(),Files.end(),filename,false); - if (found != Files.end()) - { - return Parent->createAndOpenFile(RealFileNames[found->ID]); - } - - return nullptr; -} - - -} // io -} // nbl - -#endif // __NBL_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ -#endif \ No newline at end of file diff --git a/source/Nabla/CMountPointReader.h b/source/Nabla/CMountPointReader.h deleted file mode 100644 index 93a6a6332e..0000000000 --- a/source/Nabla/CMountPointReader.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors - -#ifndef __NBL_C_MOUNT_READER_H_INCLUDED__ -#define __NBL_C_MOUNT_READER_H_INCLUDED__ - -#include "nbl/asset/compile_config.h" - -#ifdef __NBL_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ - -#include "nbl/system/ISystem.h" -#include "nbl/system/IFile.h" - -namespace nbl -{ -namespace io -{ - - //! Archiveloader capable of loading MountPoint Archives - class CArchiveLoaderMount : public system::IArchiveLoader - { - public: - - //! Constructor - CArchiveLoaderMount(io::IFileSystem* fs); - - //! returns true if the file maybe is able to be loaded by this class - //! based on the file extension (e.g. ".zip") - virtual bool isALoadableFileFormat(const std::filesystem::path& filename) const; - - //! Check if the file might be loaded by this class - /** Check might look into the file. - \param file File handle to check. - \return True if file seems to be loadable. */ - virtual bool isALoadableFileFormat(io::IReadFile* file) const; - - //! Check to see if the loader can create archives of this type. - /** Check based on the archive type. - \param fileType The archive type to check. - \return True if the archile loader supports this type, false if not */ - //virtual bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const; - - //! Creates an archive from the filename - /** \param file File handle to check. - \return Pointer to newly created archive, or 0 upon error. */ - //! creates/loads an archive from the file. - //! \return Pointer to the created archive. Returns 0 if loading failed. - //virtual IFileArchive* createArchive(io::IReadFile* file) const; - - private: - io::IFileSystem* FileSystem; - }; - - //! A File Archive which uses a mountpoint - class CMountPointReader : public virtual system::IFileArchive//, virtual system::CFileList - { - public: - - //! Constructor - CMountPointReader(IFileSystem *parent, const std::filesystem::path& basename); - - //! opens a file by file name - virtual IReadFile* createAndOpenFile(const std::filesystem::path& filename); - - //! returns the list of files - virtual const IFileList* getFileList() const; - - //! get the class Type - //virtual E_FILE_ARCHIVE_TYPE getType() const { return EFAT_FOLDER; } - - private: - - core::vector RealFileNames; - - IFileSystem *Parent; - void buildDirectory(); - }; -} // io -} // nbl - -#endif // __NBL_COMPILE_WITH_MOUNT_ARCHIVE_LOADER_ -#endif diff --git a/source/Nabla/CPakReader.cpp b/source/Nabla/CPakReader.cpp deleted file mode 100644 index bd67cf361c..0000000000 --- a/source/Nabla/CPakReader.cpp +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors -#ifdef NEW_FILESYSTEM -#include "CPakReader.h" - -#ifdef __NBL_COMPILE_WITH_PAK_ARCHIVE_LOADER_ - -#include "nbl_os.h" -#include "CLimitReadFile.h" - -namespace nbl -{ -namespace io -{ - -namespace -{ - -inline bool isHeaderValid(const SPAKFileHeader& header) -{ - const char* tag = header.tag; - return tag[0] == 'P' && - tag[1] == 'A' && - tag[2] == 'C' && - tag[3] == 'K'; -} - -} // end namespace - -//! Constructor -CArchiveLoaderPAK::CArchiveLoaderPAK( io::IFileSystem* fs) -: FileSystem(fs) -{ -#ifdef _NBL_DEBUG - setDebugName("CArchiveLoaderPAK"); -#endif -} - - -//! returns true if the file maybe is able to be loaded by this class -bool CArchiveLoaderPAK::isALoadableFileFormat(const std::filesystem::path& filename) const -{ - return core::hasFileExtension(filename, "pak"); -} - -//! Check to see if the loader can create archives of this type. -bool CArchiveLoaderPAK::isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const -{ - return fileType == EFAT_PAK; -} - -//! Creates an archive from the filename -/** \param file File handle to check. -\return Pointer to newly created archive, or 0 upon error. */ -IFileArchive* CArchiveLoaderPAK::createArchive(const std::filesystem::path& filename) const -{ - IFileArchive *archive = 0; - io::IReadFile* file = FileSystem->createAndOpenFile(filename); - - if (file) - { - archive = createArchive(file); - file->drop (); - } - - return archive; -} - -//! creates/loads an archive from the file. -//! \return Pointer to the created archive. Returns 0 if loading failed. -IFileArchive* CArchiveLoaderPAK::createArchive(io::IReadFile* file) const -{ - IFileArchive *archive = 0; - if ( file ) - { - file->seek ( 0 ); - archive = new CPakReader(file); - } - return archive; -} - - -//! Check if the file might be loaded by this class -/** Check might look into the file. -\param file File handle to check. -\return True if file seems to be loadable. */ -bool CArchiveLoaderPAK::isALoadableFileFormat(io::IReadFile* file) const -{ - SPAKFileHeader header; - - const size_t prevPos = file->getPos(); - file->seek(0u); - file->read(&header, sizeof(header)); - file->seek(prevPos); - - return isHeaderValid(header); -} - - -/*! - PAK Reader -*/ -CPakReader::CPakReader(IReadFile* file) : CFileList(file ? file->getFileName() : std::filesystem::path("")), File(file) -{ -#ifdef _NBL_DEBUG - setDebugName("CPakReader"); -#endif - - if (File) - { - File->grab(); - scanLocalHeader(); - } -} - - -CPakReader::~CPakReader() -{ - if (File) - File->drop(); -} - - -const IFileList* CPakReader::getFileList() const -{ - return this; -} - -bool CPakReader::scanLocalHeader() -{ - SPAKFileHeader header; - - // Read and validate the header - File->read(&header, sizeof(header)); - if (!isHeaderValid(header)) - return false; - - // Seek to the table of contents - File->seek(header.offset); - - const int numberOfFiles = header.length / sizeof(SPAKFileEntry); - - // Loop through each entry in the table of contents - for(int i = 0; i < numberOfFiles; i++) - { - // read an entry - SPAKFileEntry entry; - File->read(&entry, sizeof(entry)); - -#ifdef _NBL_DEBUG - os::Printer::log(entry.name); -#endif - - addItem(std::filesystem::path(entry.name), entry.offset, entry.length, false ); - } - return true; -} - - -//! opens a file by file name -IReadFile* CPakReader::createAndOpenFile(const std::filesystem::path& filename) -{ - auto it = findFile(Files.begin(),Files.end(),filename,false); - if (it!=Files.end()) - return new CLimitReadFile(File, it->Offset, it->Size, it->FullName); - - return 0; -} -} // end namespace io -} // end namespace nbl - -#endif // __NBL_COMPILE_WITH_PAK_ARCHIVE_LOADER_ - -#endif \ No newline at end of file diff --git a/source/Nabla/CPakReader.h b/source/Nabla/CPakReader.h deleted file mode 100644 index b2945c826f..0000000000 --- a/source/Nabla/CPakReader.h +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" -// For conditions of distribution and use, see copyright notice in nabla.h -// See the original file in irrlicht source for authors - -#ifndef __NBL_C_PAK_READER_H_INCLUDED__ -#define __NBL_C_PAK_READER_H_INCLUDED__ - -#include "nbl/asset/compile_config.h" - -#ifdef __NBL_COMPILE_WITH_PAK_ARCHIVE_LOADER_ - -#include "nbl/core/IReferenceCounted.h" -#include "nbl/system/IFile.h" -#include "IFileSystem.h" - -namespace nbl -{ -namespace io -{ - //! File header containing location and size of the table of contents - struct SPAKFileHeader - { - // Don't change the order of these fields! They must match the order stored on disk. - char tag[4]; - uint32_t offset; - uint32_t length; - }; - - //! An entry in the PAK file's table of contents. - struct SPAKFileEntry - { - // Don't change the order of these fields! They must match the order stored on disk. - char name[56]; - uint32_t offset; - uint32_t length; - }; - - //! Archiveloader capable of loading PAK Archives - class CArchiveLoaderPAK : public IArchiveLoader - { - public: - - //! Constructor - CArchiveLoaderPAK(io::IFileSystem* fs); - - //! returns true if the file maybe is able to be loaded by this class - //! based on the file extension (e.g. ".zip") - virtual bool isALoadableFileFormat(const std::filesystem::path& filename) const; - - //! Check if the file might be loaded by this class - /** Check might look into the file. - \param file File handle to check. - \return True if file seems to be loadable. */ - virtual bool isALoadableFileFormat(io::IReadFile* file) const; - - //! Check to see if the loader can create archives of this type. - /** Check based on the archive type. - \param fileType The archive type to check. - \return True if the archile loader supports this type, false if not */ - virtual bool isALoadableFileFormat(E_FILE_ARCHIVE_TYPE fileType) const; - - //! Creates an archive from the filename - /** \param file File handle to check. - \return Pointer to newly created archive, or 0 upon error. */ - virtual IFileArchive* createArchive(const std::filesystem::path& filename) const; - - //! creates/loads an archive from the file. - //! \return Pointer to the created archive. Returns 0 if loading failed. - virtual io::IFileArchive* createArchive(io::IReadFile* file) const; - - //! Returns the type of archive created by this loader - virtual E_FILE_ARCHIVE_TYPE getType() const { return EFAT_PAK; } - - private: - io::IFileSystem* FileSystem; - }; - - - //! reads from pak - class CPakReader : public virtual IFileArchive, virtual CFileList - { - protected: - virtual ~CPakReader(); - - public: - CPakReader(IReadFile* file); - - // file archive methods - - //! return the id of the file Archive - virtual const std::filesystem::path& getArchiveName() const - { - return File->getFileName(); - } - - //! opens a file by file name - virtual IReadFile* createAndOpenFile(const std::filesystem::path& filename); - - //! returns the list of files - virtual const IFileList* getFileList() const; - - //! get the class Type - virtual E_FILE_ARCHIVE_TYPE getType() const { return EFAT_PAK; } - - private: - - //! scans for a local header, returns false if the header is invalid - bool scanLocalHeader(); - - IReadFile* File; - - }; - -} // end namespace io -} // end namespace nbl - -#endif // __NBL_COMPILE_WITH_PAK_ARCHIVE_LOADER_ - -#endif - From baaa565c081efe6a2110a1d9091abe17dd12ed15 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 16:14:32 +0100 Subject: [PATCH 12/91] Remove OpenCL, but leave ext::RadeonRays around so we have some sort of a reference when porting ex 22 P.S. Also re-enable defaults that work on Android. --- 3rdparty/CL/cl.h | 1804 --- 3rdparty/CL/cl.hpp | 12956 ------------------ 3rdparty/CL/cl_d3d10.h | 131 - 3rdparty/CL/cl_d3d11.h | 131 - 3rdparty/CL/cl_dx9_media_sharing.h | 132 - 3rdparty/CL/cl_dx9_media_sharing_intel.h | 182 - 3rdparty/CL/cl_egl.h | 132 - 3rdparty/CL/cl_ext.h | 762 - 3rdparty/CL/cl_ext_intel.h | 423 - 3rdparty/CL/cl_gl.h | 171 - 3rdparty/CL/cl_gl_ext.h | 52 - 3rdparty/CL/cl_platform.h | 1384 -- 3rdparty/CL/cl_va_api_media_sharing_intel.h | 172 - 3rdparty/CL/cl_version.h | 86 - 3rdparty/CL/opencl.h | 47 - CMakeLists.txt | 3 - source/Nabla/COpenCLHandler.cpp | 25 - source/Nabla/COpenCLHandler.h | 339 - src/3rdparty/CL/cl.h | 1452 -- src/3rdparty/CL/cl_egl.h | 136 - src/3rdparty/CL/cl_ext.h | 440 - src/3rdparty/CL/cl_gl.h | 167 - src/3rdparty/CL/cl_gl_ext.h | 74 - src/3rdparty/CL/cl_platform.h | 1412 -- src/3rdparty/CL/opencl.h | 59 - src/3rdparty/clwinlib/OpenCL.lib | Bin 23076 -> 0 bytes src/3rdparty/clwinlib/readme.txt | 3 - src/nbl/CMakeLists.txt | 25 +- 28 files changed, 7 insertions(+), 22693 deletions(-) delete mode 100644 3rdparty/CL/cl.h delete mode 100644 3rdparty/CL/cl.hpp delete mode 100644 3rdparty/CL/cl_d3d10.h delete mode 100644 3rdparty/CL/cl_d3d11.h delete mode 100644 3rdparty/CL/cl_dx9_media_sharing.h delete mode 100644 3rdparty/CL/cl_dx9_media_sharing_intel.h delete mode 100644 3rdparty/CL/cl_egl.h delete mode 100644 3rdparty/CL/cl_ext.h delete mode 100644 3rdparty/CL/cl_ext_intel.h delete mode 100644 3rdparty/CL/cl_gl.h delete mode 100644 3rdparty/CL/cl_gl_ext.h delete mode 100644 3rdparty/CL/cl_platform.h delete mode 100644 3rdparty/CL/cl_va_api_media_sharing_intel.h delete mode 100644 3rdparty/CL/cl_version.h delete mode 100644 3rdparty/CL/opencl.h delete mode 100644 source/Nabla/COpenCLHandler.cpp delete mode 100644 source/Nabla/COpenCLHandler.h delete mode 100644 src/3rdparty/CL/cl.h delete mode 100644 src/3rdparty/CL/cl_egl.h delete mode 100644 src/3rdparty/CL/cl_ext.h delete mode 100644 src/3rdparty/CL/cl_gl.h delete mode 100644 src/3rdparty/CL/cl_gl_ext.h delete mode 100644 src/3rdparty/CL/cl_platform.h delete mode 100644 src/3rdparty/CL/opencl.h delete mode 100644 src/3rdparty/clwinlib/OpenCL.lib delete mode 100644 src/3rdparty/clwinlib/readme.txt diff --git a/3rdparty/CL/cl.h b/3rdparty/CL/cl.h deleted file mode 100644 index 32ae73fc52..0000000000 --- a/3rdparty/CL/cl.h +++ /dev/null @@ -1,1804 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2019 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifndef __OPENCL_CL_H -#define __OPENCL_CL_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************/ - -typedef struct _cl_platform_id * cl_platform_id; -typedef struct _cl_device_id * cl_device_id; -typedef struct _cl_context * cl_context; -typedef struct _cl_command_queue * cl_command_queue; -typedef struct _cl_mem * cl_mem; -typedef struct _cl_program * cl_program; -typedef struct _cl_kernel * cl_kernel; -typedef struct _cl_event * cl_event; -typedef struct _cl_sampler * cl_sampler; - -typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ -typedef cl_ulong cl_bitfield; -typedef cl_bitfield cl_device_type; -typedef cl_uint cl_platform_info; -typedef cl_uint cl_device_info; -typedef cl_bitfield cl_device_fp_config; -typedef cl_uint cl_device_mem_cache_type; -typedef cl_uint cl_device_local_mem_type; -typedef cl_bitfield cl_device_exec_capabilities; -#ifdef CL_VERSION_2_0 -typedef cl_bitfield cl_device_svm_capabilities; -#endif -typedef cl_bitfield cl_command_queue_properties; -#ifdef CL_VERSION_1_2 -typedef intptr_t cl_device_partition_property; -typedef cl_bitfield cl_device_affinity_domain; -#endif - -typedef intptr_t cl_context_properties; -typedef cl_uint cl_context_info; -#ifdef CL_VERSION_2_0 -typedef cl_bitfield cl_queue_properties; -#endif -typedef cl_uint cl_command_queue_info; -typedef cl_uint cl_channel_order; -typedef cl_uint cl_channel_type; -typedef cl_bitfield cl_mem_flags; -#ifdef CL_VERSION_2_0 -typedef cl_bitfield cl_svm_mem_flags; -#endif -typedef cl_uint cl_mem_object_type; -typedef cl_uint cl_mem_info; -#ifdef CL_VERSION_1_2 -typedef cl_bitfield cl_mem_migration_flags; -#endif -typedef cl_uint cl_image_info; -#ifdef CL_VERSION_1_1 -typedef cl_uint cl_buffer_create_type; -#endif -typedef cl_uint cl_addressing_mode; -typedef cl_uint cl_filter_mode; -typedef cl_uint cl_sampler_info; -typedef cl_bitfield cl_map_flags; -#ifdef CL_VERSION_2_0 -typedef intptr_t cl_pipe_properties; -typedef cl_uint cl_pipe_info; -#endif -typedef cl_uint cl_program_info; -typedef cl_uint cl_program_build_info; -#ifdef CL_VERSION_1_2 -typedef cl_uint cl_program_binary_type; -#endif -typedef cl_int cl_build_status; -typedef cl_uint cl_kernel_info; -#ifdef CL_VERSION_1_2 -typedef cl_uint cl_kernel_arg_info; -typedef cl_uint cl_kernel_arg_address_qualifier; -typedef cl_uint cl_kernel_arg_access_qualifier; -typedef cl_bitfield cl_kernel_arg_type_qualifier; -#endif -typedef cl_uint cl_kernel_work_group_info; -#ifdef CL_VERSION_2_1 -typedef cl_uint cl_kernel_sub_group_info; -#endif -typedef cl_uint cl_event_info; -typedef cl_uint cl_command_type; -typedef cl_uint cl_profiling_info; -#ifdef CL_VERSION_2_0 -typedef cl_bitfield cl_sampler_properties; -typedef cl_uint cl_kernel_exec_info; -#endif - -typedef struct _cl_image_format { - cl_channel_order image_channel_order; - cl_channel_type image_channel_data_type; -} cl_image_format; - -#ifdef CL_VERSION_1_2 - -typedef struct _cl_image_desc { - cl_mem_object_type image_type; - size_t image_width; - size_t image_height; - size_t image_depth; - size_t image_array_size; - size_t image_row_pitch; - size_t image_slice_pitch; - cl_uint num_mip_levels; - cl_uint num_samples; -#ifdef CL_VERSION_2_0 -#ifdef __GNUC__ - __extension__ /* Prevents warnings about anonymous union in -pedantic builds */ -#endif -#ifdef _MSC_VER -#pragma warning( push ) -#pragma warning( disable : 4201 ) /* Prevents warning about nameless struct/union in /W4 /Za builds */ -#endif - union { -#endif - cl_mem buffer; -#ifdef CL_VERSION_2_0 - cl_mem mem_object; - }; -#ifdef _MSC_VER -#pragma warning( pop ) -#endif -#endif -} cl_image_desc; - -#endif - -#ifdef CL_VERSION_1_1 - -typedef struct _cl_buffer_region { - size_t origin; - size_t size; -} cl_buffer_region; - -#endif - -/******************************************************************************/ - -/* Error Codes */ -#define CL_SUCCESS 0 -#define CL_DEVICE_NOT_FOUND -1 -#define CL_DEVICE_NOT_AVAILABLE -2 -#define CL_COMPILER_NOT_AVAILABLE -3 -#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 -#define CL_OUT_OF_RESOURCES -5 -#define CL_OUT_OF_HOST_MEMORY -6 -#define CL_PROFILING_INFO_NOT_AVAILABLE -7 -#define CL_MEM_COPY_OVERLAP -8 -#define CL_IMAGE_FORMAT_MISMATCH -9 -#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 -#define CL_BUILD_PROGRAM_FAILURE -11 -#define CL_MAP_FAILURE -12 -#ifdef CL_VERSION_1_1 -#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 -#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 -#endif -#ifdef CL_VERSION_1_2 -#define CL_COMPILE_PROGRAM_FAILURE -15 -#define CL_LINKER_NOT_AVAILABLE -16 -#define CL_LINK_PROGRAM_FAILURE -17 -#define CL_DEVICE_PARTITION_FAILED -18 -#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 -#endif - -#define CL_INVALID_VALUE -30 -#define CL_INVALID_DEVICE_TYPE -31 -#define CL_INVALID_PLATFORM -32 -#define CL_INVALID_DEVICE -33 -#define CL_INVALID_CONTEXT -34 -#define CL_INVALID_QUEUE_PROPERTIES -35 -#define CL_INVALID_COMMAND_QUEUE -36 -#define CL_INVALID_HOST_PTR -37 -#define CL_INVALID_MEM_OBJECT -38 -#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 -#define CL_INVALID_IMAGE_SIZE -40 -#define CL_INVALID_SAMPLER -41 -#define CL_INVALID_BINARY -42 -#define CL_INVALID_BUILD_OPTIONS -43 -#define CL_INVALID_PROGRAM -44 -#define CL_INVALID_PROGRAM_EXECUTABLE -45 -#define CL_INVALID_KERNEL_NAME -46 -#define CL_INVALID_KERNEL_DEFINITION -47 -#define CL_INVALID_KERNEL -48 -#define CL_INVALID_ARG_INDEX -49 -#define CL_INVALID_ARG_VALUE -50 -#define CL_INVALID_ARG_SIZE -51 -#define CL_INVALID_KERNEL_ARGS -52 -#define CL_INVALID_WORK_DIMENSION -53 -#define CL_INVALID_WORK_GROUP_SIZE -54 -#define CL_INVALID_WORK_ITEM_SIZE -55 -#define CL_INVALID_GLOBAL_OFFSET -56 -#define CL_INVALID_EVENT_WAIT_LIST -57 -#define CL_INVALID_EVENT -58 -#define CL_INVALID_OPERATION -59 -#define CL_INVALID_GL_OBJECT -60 -#define CL_INVALID_BUFFER_SIZE -61 -#define CL_INVALID_MIP_LEVEL -62 -#define CL_INVALID_GLOBAL_WORK_SIZE -63 -#ifdef CL_VERSION_1_1 -#define CL_INVALID_PROPERTY -64 -#endif -#ifdef CL_VERSION_1_2 -#define CL_INVALID_IMAGE_DESCRIPTOR -65 -#define CL_INVALID_COMPILER_OPTIONS -66 -#define CL_INVALID_LINKER_OPTIONS -67 -#define CL_INVALID_DEVICE_PARTITION_COUNT -68 -#endif -#ifdef CL_VERSION_2_0 -#define CL_INVALID_PIPE_SIZE -69 -#define CL_INVALID_DEVICE_QUEUE -70 -#endif -#ifdef CL_VERSION_2_2 -#define CL_INVALID_SPEC_ID -71 -#define CL_MAX_SIZE_RESTRICTION_EXCEEDED -72 -#endif - - -/* cl_bool */ -#define CL_FALSE 0 -#define CL_TRUE 1 -#ifdef CL_VERSION_1_2 -#define CL_BLOCKING CL_TRUE -#define CL_NON_BLOCKING CL_FALSE -#endif - -/* cl_platform_info */ -#define CL_PLATFORM_PROFILE 0x0900 -#define CL_PLATFORM_VERSION 0x0901 -#define CL_PLATFORM_NAME 0x0902 -#define CL_PLATFORM_VENDOR 0x0903 -#define CL_PLATFORM_EXTENSIONS 0x0904 -#ifdef CL_VERSION_2_1 -#define CL_PLATFORM_HOST_TIMER_RESOLUTION 0x0905 -#endif - -/* cl_device_type - bitfield */ -#define CL_DEVICE_TYPE_DEFAULT (1 << 0) -#define CL_DEVICE_TYPE_CPU (1 << 1) -#define CL_DEVICE_TYPE_GPU (1 << 2) -#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) -#ifdef CL_VERSION_1_2 -#define CL_DEVICE_TYPE_CUSTOM (1 << 4) -#endif -#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF - -/* cl_device_info */ -#define CL_DEVICE_TYPE 0x1000 -#define CL_DEVICE_VENDOR_ID 0x1001 -#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 -#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 -#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 -#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B -#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C -#define CL_DEVICE_ADDRESS_BITS 0x100D -#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E -#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F -#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 -#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 -#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 -#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 -#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 -#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 -#define CL_DEVICE_IMAGE_SUPPORT 0x1016 -#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 -#define CL_DEVICE_MAX_SAMPLERS 0x1018 -#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 -#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A -#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B -#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C -#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D -#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E -#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F -#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 -#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 -#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 -#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 -#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 -#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 -#define CL_DEVICE_ENDIAN_LITTLE 0x1026 -#define CL_DEVICE_AVAILABLE 0x1027 -#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 -#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 -#define CL_DEVICE_QUEUE_PROPERTIES 0x102A /* deprecated */ -#ifdef CL_VERSION_2_0 -#define CL_DEVICE_QUEUE_ON_HOST_PROPERTIES 0x102A -#endif -#define CL_DEVICE_NAME 0x102B -#define CL_DEVICE_VENDOR 0x102C -#define CL_DRIVER_VERSION 0x102D -#define CL_DEVICE_PROFILE 0x102E -#define CL_DEVICE_VERSION 0x102F -#define CL_DEVICE_EXTENSIONS 0x1030 -#define CL_DEVICE_PLATFORM 0x1031 -#ifdef CL_VERSION_1_2 -#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 -#endif -/* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG which is already defined in "cl_ext.h" */ -#ifdef CL_VERSION_1_1 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 -#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 /* deprecated */ -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C -#define CL_DEVICE_OPENCL_C_VERSION 0x103D -#endif -#ifdef CL_VERSION_1_2 -#define CL_DEVICE_LINKER_AVAILABLE 0x103E -#define CL_DEVICE_BUILT_IN_KERNELS 0x103F -#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 -#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 -#define CL_DEVICE_PARENT_DEVICE 0x1042 -#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 -#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 -#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 -#define CL_DEVICE_PARTITION_TYPE 0x1046 -#define CL_DEVICE_REFERENCE_COUNT 0x1047 -#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 -#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 -#endif -#ifdef CL_VERSION_2_0 -#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A -#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B -#define CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS 0x104C -#define CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE 0x104D -#define CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES 0x104E -#define CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE 0x104F -#define CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE 0x1050 -#define CL_DEVICE_MAX_ON_DEVICE_QUEUES 0x1051 -#define CL_DEVICE_MAX_ON_DEVICE_EVENTS 0x1052 -#define CL_DEVICE_SVM_CAPABILITIES 0x1053 -#define CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE 0x1054 -#define CL_DEVICE_MAX_PIPE_ARGS 0x1055 -#define CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS 0x1056 -#define CL_DEVICE_PIPE_MAX_PACKET_SIZE 0x1057 -#define CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT 0x1058 -#define CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT 0x1059 -#define CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT 0x105A -#endif -#ifdef CL_VERSION_2_1 -#define CL_DEVICE_IL_VERSION 0x105B -#define CL_DEVICE_MAX_NUM_SUB_GROUPS 0x105C -#define CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS 0x105D -#endif - -/* cl_device_fp_config - bitfield */ -#define CL_FP_DENORM (1 << 0) -#define CL_FP_INF_NAN (1 << 1) -#define CL_FP_ROUND_TO_NEAREST (1 << 2) -#define CL_FP_ROUND_TO_ZERO (1 << 3) -#define CL_FP_ROUND_TO_INF (1 << 4) -#define CL_FP_FMA (1 << 5) -#ifdef CL_VERSION_1_1 -#define CL_FP_SOFT_FLOAT (1 << 6) -#endif -#ifdef CL_VERSION_1_2 -#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) -#endif - -/* cl_device_mem_cache_type */ -#define CL_NONE 0x0 -#define CL_READ_ONLY_CACHE 0x1 -#define CL_READ_WRITE_CACHE 0x2 - -/* cl_device_local_mem_type */ -#define CL_LOCAL 0x1 -#define CL_GLOBAL 0x2 - -/* cl_device_exec_capabilities - bitfield */ -#define CL_EXEC_KERNEL (1 << 0) -#define CL_EXEC_NATIVE_KERNEL (1 << 1) - -/* cl_command_queue_properties - bitfield */ -#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) -#define CL_QUEUE_PROFILING_ENABLE (1 << 1) -#ifdef CL_VERSION_2_0 -#define CL_QUEUE_ON_DEVICE (1 << 2) -#define CL_QUEUE_ON_DEVICE_DEFAULT (1 << 3) -#endif - -/* cl_context_info */ -#define CL_CONTEXT_REFERENCE_COUNT 0x1080 -#define CL_CONTEXT_DEVICES 0x1081 -#define CL_CONTEXT_PROPERTIES 0x1082 -#ifdef CL_VERSION_1_1 -#define CL_CONTEXT_NUM_DEVICES 0x1083 -#endif - -/* cl_context_properties */ -#define CL_CONTEXT_PLATFORM 0x1084 -#ifdef CL_VERSION_1_2 -#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 -#endif - -#ifdef CL_VERSION_1_2 - -/* cl_device_partition_property */ -#define CL_DEVICE_PARTITION_EQUALLY 0x1086 -#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 -#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 -#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 - -#endif - -#ifdef CL_VERSION_1_2 - -/* cl_device_affinity_domain */ -#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) -#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) -#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) -#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) -#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) -#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) - -#endif - -#ifdef CL_VERSION_2_0 - -/* cl_device_svm_capabilities */ -#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER (1 << 0) -#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER (1 << 1) -#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM (1 << 2) -#define CL_DEVICE_SVM_ATOMICS (1 << 3) - -#endif - -/* cl_command_queue_info */ -#define CL_QUEUE_CONTEXT 0x1090 -#define CL_QUEUE_DEVICE 0x1091 -#define CL_QUEUE_REFERENCE_COUNT 0x1092 -#define CL_QUEUE_PROPERTIES 0x1093 -#ifdef CL_VERSION_2_0 -#define CL_QUEUE_SIZE 0x1094 -#endif -#ifdef CL_VERSION_2_1 -#define CL_QUEUE_DEVICE_DEFAULT 0x1095 -#endif - -/* cl_mem_flags and cl_svm_mem_flags - bitfield */ -#define CL_MEM_READ_WRITE (1 << 0) -#define CL_MEM_WRITE_ONLY (1 << 1) -#define CL_MEM_READ_ONLY (1 << 2) -#define CL_MEM_USE_HOST_PTR (1 << 3) -#define CL_MEM_ALLOC_HOST_PTR (1 << 4) -#define CL_MEM_COPY_HOST_PTR (1 << 5) -/* reserved (1 << 6) */ -#ifdef CL_VERSION_1_2 -#define CL_MEM_HOST_WRITE_ONLY (1 << 7) -#define CL_MEM_HOST_READ_ONLY (1 << 8) -#define CL_MEM_HOST_NO_ACCESS (1 << 9) -#endif -#ifdef CL_VERSION_2_0 -#define CL_MEM_SVM_FINE_GRAIN_BUFFER (1 << 10) /* used by cl_svm_mem_flags only */ -#define CL_MEM_SVM_ATOMICS (1 << 11) /* used by cl_svm_mem_flags only */ -#define CL_MEM_KERNEL_READ_AND_WRITE (1 << 12) -#endif - -#ifdef CL_VERSION_1_2 - -/* cl_mem_migration_flags - bitfield */ -#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) -#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) - -#endif - -/* cl_channel_order */ -#define CL_R 0x10B0 -#define CL_A 0x10B1 -#define CL_RG 0x10B2 -#define CL_RA 0x10B3 -#define CL_RGB 0x10B4 -#define CL_RGBA 0x10B5 -#define CL_BGRA 0x10B6 -#define CL_ARGB 0x10B7 -#define CL_INTENSITY 0x10B8 -#define CL_LUMINANCE 0x10B9 -#ifdef CL_VERSION_1_1 -#define CL_Rx 0x10BA -#define CL_RGx 0x10BB -#define CL_RGBx 0x10BC -#endif -#ifdef CL_VERSION_1_2 -#define CL_DEPTH 0x10BD -#define CL_DEPTH_STENCIL 0x10BE -#endif -#ifdef CL_VERSION_2_0 -#define CL_sRGB 0x10BF -#define CL_sRGBx 0x10C0 -#define CL_sRGBA 0x10C1 -#define CL_sBGRA 0x10C2 -#define CL_ABGR 0x10C3 -#endif - -/* cl_channel_type */ -#define CL_SNORM_INT8 0x10D0 -#define CL_SNORM_INT16 0x10D1 -#define CL_UNORM_INT8 0x10D2 -#define CL_UNORM_INT16 0x10D3 -#define CL_UNORM_SHORT_565 0x10D4 -#define CL_UNORM_SHORT_555 0x10D5 -#define CL_UNORM_INT_101010 0x10D6 -#define CL_SIGNED_INT8 0x10D7 -#define CL_SIGNED_INT16 0x10D8 -#define CL_SIGNED_INT32 0x10D9 -#define CL_UNSIGNED_INT8 0x10DA -#define CL_UNSIGNED_INT16 0x10DB -#define CL_UNSIGNED_INT32 0x10DC -#define CL_HALF_FLOAT 0x10DD -#define CL_FLOAT 0x10DE -#ifdef CL_VERSION_1_2 -#define CL_UNORM_INT24 0x10DF -#endif -#ifdef CL_VERSION_2_1 -#define CL_UNORM_INT_101010_2 0x10E0 -#endif - -/* cl_mem_object_type */ -#define CL_MEM_OBJECT_BUFFER 0x10F0 -#define CL_MEM_OBJECT_IMAGE2D 0x10F1 -#define CL_MEM_OBJECT_IMAGE3D 0x10F2 -#ifdef CL_VERSION_1_2 -#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 -#define CL_MEM_OBJECT_IMAGE1D 0x10F4 -#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 -#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 -#endif -#ifdef CL_VERSION_2_0 -#define CL_MEM_OBJECT_PIPE 0x10F7 -#endif - -/* cl_mem_info */ -#define CL_MEM_TYPE 0x1100 -#define CL_MEM_FLAGS 0x1101 -#define CL_MEM_SIZE 0x1102 -#define CL_MEM_HOST_PTR 0x1103 -#define CL_MEM_MAP_COUNT 0x1104 -#define CL_MEM_REFERENCE_COUNT 0x1105 -#define CL_MEM_CONTEXT 0x1106 -#ifdef CL_VERSION_1_1 -#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 -#define CL_MEM_OFFSET 0x1108 -#endif -#ifdef CL_VERSION_2_0 -#define CL_MEM_USES_SVM_POINTER 0x1109 -#endif - -/* cl_image_info */ -#define CL_IMAGE_FORMAT 0x1110 -#define CL_IMAGE_ELEMENT_SIZE 0x1111 -#define CL_IMAGE_ROW_PITCH 0x1112 -#define CL_IMAGE_SLICE_PITCH 0x1113 -#define CL_IMAGE_WIDTH 0x1114 -#define CL_IMAGE_HEIGHT 0x1115 -#define CL_IMAGE_DEPTH 0x1116 -#ifdef CL_VERSION_1_2 -#define CL_IMAGE_ARRAY_SIZE 0x1117 -#define CL_IMAGE_BUFFER 0x1118 -#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 -#define CL_IMAGE_NUM_SAMPLES 0x111A -#endif - -#ifdef CL_VERSION_2_0 - -/* cl_pipe_info */ -#define CL_PIPE_PACKET_SIZE 0x1120 -#define CL_PIPE_MAX_PACKETS 0x1121 - -#endif - -/* cl_addressing_mode */ -#define CL_ADDRESS_NONE 0x1130 -#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 -#define CL_ADDRESS_CLAMP 0x1132 -#define CL_ADDRESS_REPEAT 0x1133 -#ifdef CL_VERSION_1_1 -#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 -#endif - -/* cl_filter_mode */ -#define CL_FILTER_NEAREST 0x1140 -#define CL_FILTER_LINEAR 0x1141 - -/* cl_sampler_info */ -#define CL_SAMPLER_REFERENCE_COUNT 0x1150 -#define CL_SAMPLER_CONTEXT 0x1151 -#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 -#define CL_SAMPLER_ADDRESSING_MODE 0x1153 -#define CL_SAMPLER_FILTER_MODE 0x1154 -#ifdef CL_VERSION_2_0 -/* These enumerants are for the cl_khr_mipmap_image extension. - They have since been added to cl_ext.h with an appropriate - KHR suffix, but are left here for backwards compatibility. */ -#define CL_SAMPLER_MIP_FILTER_MODE 0x1155 -#define CL_SAMPLER_LOD_MIN 0x1156 -#define CL_SAMPLER_LOD_MAX 0x1157 -#endif - -/* cl_map_flags - bitfield */ -#define CL_MAP_READ (1 << 0) -#define CL_MAP_WRITE (1 << 1) -#ifdef CL_VERSION_1_2 -#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) -#endif - -/* cl_program_info */ -#define CL_PROGRAM_REFERENCE_COUNT 0x1160 -#define CL_PROGRAM_CONTEXT 0x1161 -#define CL_PROGRAM_NUM_DEVICES 0x1162 -#define CL_PROGRAM_DEVICES 0x1163 -#define CL_PROGRAM_SOURCE 0x1164 -#define CL_PROGRAM_BINARY_SIZES 0x1165 -#define CL_PROGRAM_BINARIES 0x1166 -#ifdef CL_VERSION_1_2 -#define CL_PROGRAM_NUM_KERNELS 0x1167 -#define CL_PROGRAM_KERNEL_NAMES 0x1168 -#endif -#ifdef CL_VERSION_2_1 -#define CL_PROGRAM_IL 0x1169 -#endif -#ifdef CL_VERSION_2_2 -#define CL_PROGRAM_SCOPE_GLOBAL_CTORS_PRESENT 0x116A -#define CL_PROGRAM_SCOPE_GLOBAL_DTORS_PRESENT 0x116B -#endif - -/* cl_program_build_info */ -#define CL_PROGRAM_BUILD_STATUS 0x1181 -#define CL_PROGRAM_BUILD_OPTIONS 0x1182 -#define CL_PROGRAM_BUILD_LOG 0x1183 -#ifdef CL_VERSION_1_2 -#define CL_PROGRAM_BINARY_TYPE 0x1184 -#endif -#ifdef CL_VERSION_2_0 -#define CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE 0x1185 -#endif - -#ifdef CL_VERSION_1_2 - -/* cl_program_binary_type */ -#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 -#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 -#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 -#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 - -#endif - -/* cl_build_status */ -#define CL_BUILD_SUCCESS 0 -#define CL_BUILD_NONE -1 -#define CL_BUILD_ERROR -2 -#define CL_BUILD_IN_PROGRESS -3 - -/* cl_kernel_info */ -#define CL_KERNEL_FUNCTION_NAME 0x1190 -#define CL_KERNEL_NUM_ARGS 0x1191 -#define CL_KERNEL_REFERENCE_COUNT 0x1192 -#define CL_KERNEL_CONTEXT 0x1193 -#define CL_KERNEL_PROGRAM 0x1194 -#ifdef CL_VERSION_1_2 -#define CL_KERNEL_ATTRIBUTES 0x1195 -#endif -#ifdef CL_VERSION_2_1 -#define CL_KERNEL_MAX_NUM_SUB_GROUPS 0x11B9 -#define CL_KERNEL_COMPILE_NUM_SUB_GROUPS 0x11BA -#endif - -#ifdef CL_VERSION_1_2 - -/* cl_kernel_arg_info */ -#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 -#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 -#define CL_KERNEL_ARG_TYPE_NAME 0x1198 -#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 -#define CL_KERNEL_ARG_NAME 0x119A - -#endif - -#ifdef CL_VERSION_1_2 - -/* cl_kernel_arg_address_qualifier */ -#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B -#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C -#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D -#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E - -#endif - -#ifdef CL_VERSION_1_2 - -/* cl_kernel_arg_access_qualifier */ -#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 -#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 -#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 -#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 - -#endif - -#ifdef CL_VERSION_1_2 - -/* cl_kernel_arg_type_qualifier */ -#define CL_KERNEL_ARG_TYPE_NONE 0 -#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) -#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) -#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) -#ifdef CL_VERSION_2_0 -#define CL_KERNEL_ARG_TYPE_PIPE (1 << 3) -#endif - -#endif - -/* cl_kernel_work_group_info */ -#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 -#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 -#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 -#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 -#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 -#ifdef CL_VERSION_1_2 -#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 -#endif - -#ifdef CL_VERSION_2_1 - -/* cl_kernel_sub_group_info */ -#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE 0x2033 -#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE 0x2034 -#define CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT 0x11B8 - -#endif - -#ifdef CL_VERSION_2_0 - -/* cl_kernel_exec_info */ -#define CL_KERNEL_EXEC_INFO_SVM_PTRS 0x11B6 -#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM 0x11B7 - -#endif - -/* cl_event_info */ -#define CL_EVENT_COMMAND_QUEUE 0x11D0 -#define CL_EVENT_COMMAND_TYPE 0x11D1 -#define CL_EVENT_REFERENCE_COUNT 0x11D2 -#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 -#ifdef CL_VERSION_1_1 -#define CL_EVENT_CONTEXT 0x11D4 -#endif - -/* cl_command_type */ -#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 -#define CL_COMMAND_TASK 0x11F1 -#define CL_COMMAND_NATIVE_KERNEL 0x11F2 -#define CL_COMMAND_READ_BUFFER 0x11F3 -#define CL_COMMAND_WRITE_BUFFER 0x11F4 -#define CL_COMMAND_COPY_BUFFER 0x11F5 -#define CL_COMMAND_READ_IMAGE 0x11F6 -#define CL_COMMAND_WRITE_IMAGE 0x11F7 -#define CL_COMMAND_COPY_IMAGE 0x11F8 -#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 -#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA -#define CL_COMMAND_MAP_BUFFER 0x11FB -#define CL_COMMAND_MAP_IMAGE 0x11FC -#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD -#define CL_COMMAND_MARKER 0x11FE -#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF -#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 -#ifdef CL_VERSION_1_1 -#define CL_COMMAND_READ_BUFFER_RECT 0x1201 -#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 -#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 -#define CL_COMMAND_USER 0x1204 -#endif -#ifdef CL_VERSION_1_2 -#define CL_COMMAND_BARRIER 0x1205 -#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 -#define CL_COMMAND_FILL_BUFFER 0x1207 -#define CL_COMMAND_FILL_IMAGE 0x1208 -#endif -#ifdef CL_VERSION_2_0 -#define CL_COMMAND_SVM_FREE 0x1209 -#define CL_COMMAND_SVM_MEMCPY 0x120A -#define CL_COMMAND_SVM_MEMFILL 0x120B -#define CL_COMMAND_SVM_MAP 0x120C -#define CL_COMMAND_SVM_UNMAP 0x120D -#endif - -/* command execution status */ -#define CL_COMPLETE 0x0 -#define CL_RUNNING 0x1 -#define CL_SUBMITTED 0x2 -#define CL_QUEUED 0x3 - -#ifdef CL_VERSION_1_1 - -/* cl_buffer_create_type */ -#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 - -#endif - -/* cl_profiling_info */ -#define CL_PROFILING_COMMAND_QUEUED 0x1280 -#define CL_PROFILING_COMMAND_SUBMIT 0x1281 -#define CL_PROFILING_COMMAND_START 0x1282 -#define CL_PROFILING_COMMAND_END 0x1283 -#ifdef CL_VERSION_2_0 -#define CL_PROFILING_COMMAND_COMPLETE 0x1284 -#endif - -/********************************************************************************************************/ - -/* Platform API */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPlatformIDs(cl_uint num_entries, - cl_platform_id * platforms, - cl_uint * num_platforms) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPlatformInfo(cl_platform_id platform, - cl_platform_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -/* Device APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceIDs(cl_platform_id platform, - cl_device_type device_type, - cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceInfo(cl_device_id device, - cl_device_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateSubDevices(cl_device_id in_device, - const cl_device_partition_property * properties, - cl_uint num_devices, - cl_device_id * out_devices, - cl_uint * num_devices_ret) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseDevice(cl_device_id device) CL_API_SUFFIX__VERSION_1_2; - -#endif - -#ifdef CL_VERSION_2_1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetDefaultDeviceCommandQueue(cl_context context, - cl_device_id device, - cl_command_queue command_queue) CL_API_SUFFIX__VERSION_2_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceAndHostTimer(cl_device_id device, - cl_ulong* device_timestamp, - cl_ulong* host_timestamp) CL_API_SUFFIX__VERSION_2_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetHostTimer(cl_device_id device, - cl_ulong * host_timestamp) CL_API_SUFFIX__VERSION_2_1; - -#endif - -/* Context APIs */ -extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContext(const cl_context_properties * properties, - cl_uint num_devices, - const cl_device_id * devices, - void (CL_CALLBACK * pfn_notify)(const char * errinfo, - const void * private_info, - size_t cb, - void * user_data), - void * user_data, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContextFromType(const cl_context_properties * properties, - cl_device_type device_type, - void (CL_CALLBACK * pfn_notify)(const char * errinfo, - const void * private_info, - size_t cb, - void * user_data), - void * user_data, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainContext(cl_context context) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseContext(cl_context context) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetContextInfo(cl_context context, - cl_context_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -/* Command Queue APIs */ - -#ifdef CL_VERSION_2_0 - -extern CL_API_ENTRY cl_command_queue CL_API_CALL -clCreateCommandQueueWithProperties(cl_context context, - cl_device_id device, - const cl_queue_properties * properties, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainCommandQueue(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseCommandQueue(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetCommandQueueInfo(cl_command_queue command_queue, - cl_command_queue_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -/* Memory Object APIs */ -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateBuffer(cl_context context, - cl_mem_flags flags, - size_t size, - void * host_ptr, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_1 - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateSubBuffer(cl_mem buffer, - cl_mem_flags flags, - cl_buffer_create_type buffer_create_type, - const void * buffer_create_info, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1; - -#endif - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateImage(cl_context context, - cl_mem_flags flags, - const cl_image_format * image_format, - const cl_image_desc * image_desc, - void * host_ptr, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -#endif - -#ifdef CL_VERSION_2_0 - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreatePipe(cl_context context, - cl_mem_flags flags, - cl_uint pipe_packet_size, - cl_uint pipe_max_packets, - const cl_pipe_properties * properties, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseMemObject(cl_mem memobj) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetSupportedImageFormats(cl_context context, - cl_mem_flags flags, - cl_mem_object_type image_type, - cl_uint num_entries, - cl_image_format * image_formats, - cl_uint * num_image_formats) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetMemObjectInfo(cl_mem memobj, - cl_mem_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetImageInfo(cl_mem image, - cl_image_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_2_0 - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPipeInfo(cl_mem pipe, - cl_pipe_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_2_0; - -#endif - -#ifdef CL_VERSION_1_1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetMemObjectDestructorCallback(cl_mem memobj, - void (CL_CALLBACK * pfn_notify)(cl_mem memobj, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_1_1; - -#endif - -/* SVM Allocation APIs */ - -#ifdef CL_VERSION_2_0 - -extern CL_API_ENTRY void * CL_API_CALL -clSVMAlloc(cl_context context, - cl_svm_mem_flags flags, - size_t size, - cl_uint alignment) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY void CL_API_CALL -clSVMFree(cl_context context, - void * svm_pointer) CL_API_SUFFIX__VERSION_2_0; - -#endif - -/* Sampler APIs */ - -#ifdef CL_VERSION_2_0 - -extern CL_API_ENTRY cl_sampler CL_API_CALL -clCreateSamplerWithProperties(cl_context context, - const cl_sampler_properties * sampler_properties, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_2_0; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainSampler(cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseSampler(cl_sampler sampler) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetSamplerInfo(cl_sampler sampler, - cl_sampler_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -/* Program Object APIs */ -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithSource(cl_context context, - cl_uint count, - const char ** strings, - const size_t * lengths, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithBinary(cl_context context, - cl_uint num_devices, - const cl_device_id * device_list, - const size_t * lengths, - const unsigned char ** binaries, - cl_int * binary_status, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithBuiltInKernels(cl_context context, - cl_uint num_devices, - const cl_device_id * device_list, - const char * kernel_names, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -#endif - -#ifdef CL_VERSION_2_1 - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithIL(cl_context context, - const void* il, - size_t length, - cl_int* errcode_ret) CL_API_SUFFIX__VERSION_2_1; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseProgram(cl_program program) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clBuildProgram(cl_program program, - cl_uint num_devices, - const cl_device_id * device_list, - const char * options, - void (CL_CALLBACK * pfn_notify)(cl_program program, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clCompileProgram(cl_program program, - cl_uint num_devices, - const cl_device_id * device_list, - const char * options, - cl_uint num_input_headers, - const cl_program * input_headers, - const char ** header_include_names, - void (CL_CALLBACK * pfn_notify)(cl_program program, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_program CL_API_CALL -clLinkProgram(cl_context context, - cl_uint num_devices, - const cl_device_id * device_list, - const char * options, - cl_uint num_input_programs, - const cl_program * input_programs, - void (CL_CALLBACK * pfn_notify)(cl_program program, - void * user_data), - void * user_data, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -#endif - -#ifdef CL_VERSION_2_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetProgramReleaseCallback(cl_program program, - void (CL_CALLBACK * pfn_notify)(cl_program program, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_2_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetProgramSpecializationConstant(cl_program program, - cl_uint spec_id, - size_t spec_size, - const void* spec_value) CL_API_SUFFIX__VERSION_2_2; - -#endif - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clUnloadPlatformCompiler(cl_platform_id platform) CL_API_SUFFIX__VERSION_1_2; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetProgramInfo(cl_program program, - cl_program_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetProgramBuildInfo(cl_program program, - cl_device_id device, - cl_program_build_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -/* Kernel Object APIs */ -extern CL_API_ENTRY cl_kernel CL_API_CALL -clCreateKernel(cl_program program, - const char * kernel_name, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateKernelsInProgram(cl_program program, - cl_uint num_kernels, - cl_kernel * kernels, - cl_uint * num_kernels_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_2_1 - -extern CL_API_ENTRY cl_kernel CL_API_CALL -clCloneKernel(cl_kernel source_kernel, - cl_int* errcode_ret) CL_API_SUFFIX__VERSION_2_1; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainKernel(cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseKernel(cl_kernel kernel) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelArg(cl_kernel kernel, - cl_uint arg_index, - size_t arg_size, - const void * arg_value) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_2_0 - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelArgSVMPointer(cl_kernel kernel, - cl_uint arg_index, - const void * arg_value) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelExecInfo(cl_kernel kernel, - cl_kernel_exec_info param_name, - size_t param_value_size, - const void * param_value) CL_API_SUFFIX__VERSION_2_0; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelInfo(cl_kernel kernel, - cl_kernel_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelArgInfo(cl_kernel kernel, - cl_uint arg_indx, - cl_kernel_arg_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_2; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelWorkGroupInfo(cl_kernel kernel, - cl_device_id device, - cl_kernel_work_group_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_2_1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelSubGroupInfo(cl_kernel kernel, - cl_device_id device, - cl_kernel_sub_group_info param_name, - size_t input_value_size, - const void* input_value, - size_t param_value_size, - void* param_value, - size_t* param_value_size_ret) CL_API_SUFFIX__VERSION_2_1; - -#endif - -/* Event Object APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clWaitForEvents(cl_uint num_events, - const cl_event * event_list) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetEventInfo(cl_event event, - cl_event_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_1 - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateUserEvent(cl_context context, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_1; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseEvent(cl_event event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetUserEventStatus(cl_event event, - cl_int execution_status) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetEventCallback(cl_event event, - cl_int command_exec_callback_type, - void (CL_CALLBACK * pfn_notify)(cl_event event, - cl_int event_command_status, - void * user_data), - void * user_data) CL_API_SUFFIX__VERSION_1_1; - -#endif - -/* Profiling APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetEventProfilingInfo(cl_event event, - cl_profiling_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -/* Flush and Finish APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clFlush(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clFinish(cl_command_queue command_queue) CL_API_SUFFIX__VERSION_1_0; - -/* Enqueued Commands APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadBuffer(cl_command_queue command_queue, - cl_mem buffer, - cl_bool blocking_read, - size_t offset, - size_t size, - void * ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadBufferRect(cl_command_queue command_queue, - cl_mem buffer, - cl_bool blocking_read, - const size_t * buffer_offset, - const size_t * host_offset, - const size_t * region, - size_t buffer_row_pitch, - size_t buffer_slice_pitch, - size_t host_row_pitch, - size_t host_slice_pitch, - void * ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_1; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteBuffer(cl_command_queue command_queue, - cl_mem buffer, - cl_bool blocking_write, - size_t offset, - size_t size, - const void * ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteBufferRect(cl_command_queue command_queue, - cl_mem buffer, - cl_bool blocking_write, - const size_t * buffer_offset, - const size_t * host_offset, - const size_t * region, - size_t buffer_row_pitch, - size_t buffer_slice_pitch, - size_t host_row_pitch, - size_t host_slice_pitch, - const void * ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_1; - -#endif - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueFillBuffer(cl_command_queue command_queue, - cl_mem buffer, - const void * pattern, - size_t pattern_size, - size_t offset, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBuffer(cl_command_queue command_queue, - cl_mem src_buffer, - cl_mem dst_buffer, - size_t src_offset, - size_t dst_offset, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBufferRect(cl_command_queue command_queue, - cl_mem src_buffer, - cl_mem dst_buffer, - const size_t * src_origin, - const size_t * dst_origin, - const size_t * region, - size_t src_row_pitch, - size_t src_slice_pitch, - size_t dst_row_pitch, - size_t dst_slice_pitch, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_1; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadImage(cl_command_queue command_queue, - cl_mem image, - cl_bool blocking_read, - const size_t * origin, - const size_t * region, - size_t row_pitch, - size_t slice_pitch, - void * ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteImage(cl_command_queue command_queue, - cl_mem image, - cl_bool blocking_write, - const size_t * origin, - const size_t * region, - size_t input_row_pitch, - size_t input_slice_pitch, - const void * ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueFillImage(cl_command_queue command_queue, - cl_mem image, - const void * fill_color, - const size_t * origin, - const size_t * region, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyImage(cl_command_queue command_queue, - cl_mem src_image, - cl_mem dst_image, - const size_t * src_origin, - const size_t * dst_origin, - const size_t * region, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyImageToBuffer(cl_command_queue command_queue, - cl_mem src_image, - cl_mem dst_buffer, - const size_t * src_origin, - const size_t * region, - size_t dst_offset, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBufferToImage(cl_command_queue command_queue, - cl_mem src_buffer, - cl_mem dst_image, - size_t src_offset, - const size_t * dst_origin, - const size_t * region, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY void * CL_API_CALL -clEnqueueMapBuffer(cl_command_queue command_queue, - cl_mem buffer, - cl_bool blocking_map, - cl_map_flags map_flags, - size_t offset, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY void * CL_API_CALL -clEnqueueMapImage(cl_command_queue command_queue, - cl_mem image, - cl_bool blocking_map, - cl_map_flags map_flags, - const size_t * origin, - const size_t * region, - size_t * image_row_pitch, - size_t * image_slice_pitch, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueUnmapMemObject(cl_command_queue command_queue, - cl_mem memobj, - void * mapped_ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMigrateMemObjects(cl_command_queue command_queue, - cl_uint num_mem_objects, - const cl_mem * mem_objects, - cl_mem_migration_flags flags, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -#endif - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueNDRangeKernel(cl_command_queue command_queue, - cl_kernel kernel, - cl_uint work_dim, - const size_t * global_work_offset, - const size_t * global_work_size, - const size_t * local_work_size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueNativeKernel(cl_command_queue command_queue, - void (CL_CALLBACK * user_func)(void *), - void * args, - size_t cb_args, - cl_uint num_mem_objects, - const cl_mem * mem_list, - const void ** args_mem_loc, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMarkerWithWaitList(cl_command_queue command_queue, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueBarrierWithWaitList(cl_command_queue command_queue, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -#endif - -#ifdef CL_VERSION_2_0 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMFree(cl_command_queue command_queue, - cl_uint num_svm_pointers, - void * svm_pointers[], - void (CL_CALLBACK * pfn_free_func)(cl_command_queue queue, - cl_uint num_svm_pointers, - void * svm_pointers[], - void * user_data), - void * user_data, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMemcpy(cl_command_queue command_queue, - cl_bool blocking_copy, - void * dst_ptr, - const void * src_ptr, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMemFill(cl_command_queue command_queue, - void * svm_ptr, - const void * pattern, - size_t pattern_size, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMap(cl_command_queue command_queue, - cl_bool blocking_map, - cl_map_flags flags, - void * svm_ptr, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMUnmap(cl_command_queue command_queue, - void * svm_ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_0; - -#endif - -#ifdef CL_VERSION_2_1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMigrateMem(cl_command_queue command_queue, - cl_uint num_svm_pointers, - const void ** svm_pointers, - const size_t * sizes, - cl_mem_migration_flags flags, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_2_1; - -#endif - -#ifdef CL_VERSION_1_2 - -/* Extension function access - * - * Returns the extension function address for the given function name, - * or NULL if a valid function can not be found. The client must - * check to make sure the address is not NULL, before using or - * calling the returned function address. - */ -extern CL_API_ENTRY void * CL_API_CALL -clGetExtensionFunctionAddressForPlatform(cl_platform_id platform, - const char * func_name) CL_API_SUFFIX__VERSION_1_2; - -#endif - -#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - /* - * WARNING: - * This API introduces mutable state into the OpenCL implementation. It has been REMOVED - * to better facilitate thread safety. The 1.0 API is not thread safe. It is not tested by the - * OpenCL 1.1 conformance test, and consequently may not work or may not work dependably. - * It is likely to be non-performant. Use of this API is not advised. Use at your own risk. - * - * Software developers previously relying on this API are instructed to set the command queue - * properties when creating the queue, instead. - */ - extern CL_API_ENTRY cl_int CL_API_CALL - clSetCommandQueueProperty(cl_command_queue command_queue, - cl_command_queue_properties properties, - cl_bool enable, - cl_command_queue_properties * old_properties) CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED; -#endif /* CL_USE_DEPRECATED_OPENCL_1_0_APIS */ - -/* Deprecated OpenCL 1.1 APIs */ -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateImage2D(cl_context context, - cl_mem_flags flags, - const cl_image_format * image_format, - size_t image_width, - size_t image_height, - size_t image_row_pitch, - void * host_ptr, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateImage3D(cl_context context, - cl_mem_flags flags, - const cl_image_format * image_format, - size_t image_width, - size_t image_height, - size_t image_depth, - size_t image_row_pitch, - size_t image_slice_pitch, - void * host_ptr, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueMarker(cl_command_queue command_queue, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueWaitForEvents(cl_command_queue command_queue, - cl_uint num_events, - const cl_event * event_list) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueBarrier(cl_command_queue command_queue) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL -clGetExtensionFunctionAddress(const char * func_name) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -/* Deprecated OpenCL 2.0 APIs */ -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_command_queue CL_API_CALL -clCreateCommandQueue(cl_context context, - cl_device_id device, - cl_command_queue_properties properties, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_sampler CL_API_CALL -clCreateSampler(cl_context context, - cl_bool normalized_coords, - cl_addressing_mode addressing_mode, - cl_filter_mode filter_mode, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int CL_API_CALL -clEnqueueTask(cl_command_queue command_queue, - cl_kernel kernel, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_H */ diff --git a/3rdparty/CL/cl.hpp b/3rdparty/CL/cl.hpp deleted file mode 100644 index 71e55e0678..0000000000 --- a/3rdparty/CL/cl.hpp +++ /dev/null @@ -1,12956 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/*! \file - * - * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and - * OpenCL 1.2 (rev 15) - * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes - * - * Additions and fixes from: - * Brian Cole, March 3rd 2010 and April 2012 - * Matt Gruenke, April 2012. - * Bruce Merry, February 2013. - * Tom Deakin and Simon McIntosh-Smith, July 2013 - * - * \version 1.2.9 - * \date December 2015 - * - * Optional extension support - * - * cl - * cl_ext_device_fission - * #define USE_CL_DEVICE_FISSION - */ - -/*! \mainpage - * \section intro Introduction - * For many large applications C++ is the language of choice and so it seems - * reasonable to define C++ bindings for OpenCL. - * - * - * The interface is contained with a single C++ header file \em cl.hpp and all - * definitions are contained within the namespace \em cl. There is no additional - * requirement to include \em cl.h and to use either the C++ or original C - * bindings it is enough to simply include \em cl.hpp. - * - * The bindings themselves are lightweight and correspond closely to the - * underlying C API. Using the C++ bindings introduces no additional execution - * overhead. - * - * For detail documentation on the bindings see: - * - * The OpenCL C++ Wrapper API 1.2 (revision 09) - * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf - * - * \section example Example - * - * The following example shows a general use case for the C++ - * bindings, including support for the optional exception feature and - * also the supplied vector and string classes, see following sections for - * decriptions of these features. - * - * \code - * #define __CL_ENABLE_EXCEPTIONS - * - * #if defined(__APPLE__) || defined(__MACOSX) - * #include - * #else - * #include - * #endif - * #include - * #include - * #include - * - * const char * helloStr = "__kernel void " - * "hello(void) " - * "{ " - * " " - * "} "; - * - * int - * main(void) - * { - * cl_int err = CL_SUCCESS; - * try { - * - * std::vector platforms; - * cl::Platform::get(&platforms); - * if (platforms.size() == 0) { - * std::cout << "Platform size 0\n"; - * return -1; - * } - * - * cl_context_properties properties[] = - * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0}; - * cl::Context context(CL_DEVICE_TYPE_CPU, properties); - * - * std::vector devices = context.getInfo(); - * - * cl::Program::Sources source(1, - * std::make_pair(helloStr,strlen(helloStr))); - * cl::Program program_ = cl::Program(context, source); - * program_.build(devices); - * - * cl::Kernel kernel(program_, "hello", &err); - * - * cl::Event event; - * cl::CommandQueue queue(context, devices[0], 0, &err); - * queue.enqueueNDRangeKernel( - * kernel, - * cl::NullRange, - * cl::NDRange(4,4), - * cl::NullRange, - * NULL, - * &event); - * - * event.wait(); - * } - * catch (cl::Error err) { - * std::cerr - * << "ERROR: " - * << err.what() - * << "(" - * << err.err() - * << ")" - * << std::endl; - * } - * - * return EXIT_SUCCESS; - * } - * - * \endcode - * - */ -#ifndef CL_HPP_ -#define CL_HPP_ - -#ifdef _WIN32 - -#include - -#if defined(USE_DX_INTEROP) -#include -#include -#endif -#endif // _WIN32 - -#if defined(_MSC_VER) -#include -#endif // _MSC_VER - -// -#if defined(USE_CL_DEVICE_FISSION) -#include -#endif - -#if defined(__APPLE__) || defined(__MACOSX) -#include -#else -#include -#endif // !__APPLE__ - -#if (_MSC_VER >= 1700) || (__cplusplus >= 201103L) -#define CL_HPP_RVALUE_REFERENCES_SUPPORTED -#define CL_HPP_CPP11_ATOMICS_SUPPORTED -#include -#endif - -#if (__cplusplus >= 201103L) -#define CL_HPP_NOEXCEPT noexcept -#else -#define CL_HPP_NOEXCEPT -#endif - - -// To avoid accidentally taking ownership of core OpenCL types -// such as cl_kernel constructors are made explicit -// under OpenCL 1.2 -#if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) -#define __CL_EXPLICIT_CONSTRUCTORS explicit -#else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) -#define __CL_EXPLICIT_CONSTRUCTORS -#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) - -// Define deprecated prefixes and suffixes to ensure compilation -// in case they are not pre-defined -#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) -#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED -#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) -#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED) -#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED -#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED) - -#if !defined(CL_CALLBACK) -#define CL_CALLBACK -#endif //CL_CALLBACK - -#include -#include -#include - -#if defined(__CL_ENABLE_EXCEPTIONS) -#include -#endif // #if defined(__CL_ENABLE_EXCEPTIONS) - -#if !defined(__NO_STD_VECTOR) -#include -#endif - -#if !defined(__NO_STD_STRING) -#include -#endif - -#if defined(__ANDROID__) || defined(linux) || defined(__APPLE__) || defined(__MACOSX) -#include -#endif // linux - -#include - - -/*! \namespace cl - * - * \brief The OpenCL C++ bindings are defined within this namespace. - * - */ -namespace cl { - -class Memory; - -/** - * Deprecated APIs for 1.2 - */ -#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) -#define __INIT_CL_EXT_FCN_PTR(name) \ - if(!pfn_##name) { \ - pfn_##name = (PFN_##name) \ - clGetExtensionFunctionAddress(#name); \ - if(!pfn_##name) { \ - } \ - } -#endif // #if defined(CL_VERSION_1_1) - -#if defined(CL_VERSION_1_2) -#define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \ - if(!pfn_##name) { \ - pfn_##name = (PFN_##name) \ - clGetExtensionFunctionAddressForPlatform(platform, #name); \ - if(!pfn_##name) { \ - } \ - } -#endif // #if defined(CL_VERSION_1_1) - -class Program; -class Device; -class Context; -class CommandQueue; -class Memory; -class Buffer; - -#if defined(__CL_ENABLE_EXCEPTIONS) -/*! \brief Exception class - * - * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined. - */ -class Error : public std::exception -{ -private: - cl_int err_; - const char * errStr_; -public: - /*! \brief Create a new CL error exception for a given error code - * and corresponding message. - * - * \param err error code value. - * - * \param errStr a descriptive string that must remain in scope until - * handling of the exception has concluded. If set, it - * will be returned by what(). - */ - Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr) - {} - - ~Error() throw() {} - - /*! \brief Get error string associated with exception - * - * \return A memory pointer to the error message string. - */ - virtual const char * what() const throw () - { - if (errStr_ == NULL) { - return "empty"; - } - else { - return errStr_; - } - } - - /*! \brief Get error code associated with exception - * - * \return The error code. - */ - cl_int err(void) const { return err_; } -}; - -#define __ERR_STR(x) #x -#else -#define __ERR_STR(x) NULL -#endif // __CL_ENABLE_EXCEPTIONS - - -namespace detail -{ -#if defined(__CL_ENABLE_EXCEPTIONS) -static inline cl_int errHandler ( - cl_int err, - const char * errStr = NULL) -{ - if (err != CL_SUCCESS) { - throw Error(err, errStr); - } - return err; -} -#else -static inline cl_int errHandler (cl_int err, const char * errStr = NULL) -{ - (void) errStr; // suppress unused variable warning - return err; -} -#endif // __CL_ENABLE_EXCEPTIONS -} - - - -//! \cond DOXYGEN_DETAIL -#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) -#define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo) -#define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo) -#define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs) -#define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs) -#define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo) -#define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo) -#define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo) -#define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo) -#define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo) -#define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo) -#define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo) -#if defined(CL_VERSION_1_2) -#define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo) -#endif // #if defined(CL_VERSION_1_2) -#define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo) -#define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo) -#define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo) -#define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo) - -#define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext) -#define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType) -#define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats) - -#define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer) -#define __COPY_ERR __ERR_STR(cl::copy) -#define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer) -#define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) -#define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer) -#define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo) -#if defined(CL_VERSION_1_2) -#define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage) -#define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture) -#define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions) -#endif // #if defined(CL_VERSION_1_2) -#define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler) -#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback) - -#define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent) -#define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus) -#define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback) -#define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents) - -#define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel) -#define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg) -#define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource) -#define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary) -#if defined(CL_VERSION_1_2) -#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels) -#endif // #if defined(CL_VERSION_1_2) -#define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram) -#if defined(CL_VERSION_1_2) -#define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram) -#define __LINK_PROGRAM_ERR __ERR_STR(clLinkProgram) -#endif // #if defined(CL_VERSION_1_2) -#define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram) - -#define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue) -#define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty) -#define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer) -#define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect) -#define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer) -#define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect) -#define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer) -#define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect) -#define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer) -#define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage) -#define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage) -#define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage) -#define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage) -#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer) -#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage) -#define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer) -#define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage) -#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject) -#define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel) -#define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask) -#define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel) -#if defined(CL_VERSION_1_2) -#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects) -#endif // #if defined(CL_VERSION_1_2) - -#define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects) -#define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects) - - -#define __RETAIN_ERR __ERR_STR(Retain Object) -#define __RELEASE_ERR __ERR_STR(Release Object) -#define __FLUSH_ERR __ERR_STR(clFlush) -#define __FINISH_ERR __ERR_STR(clFinish) -#define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error) - -/** - * CL 1.2 version that uses device fission. - */ -#if defined(CL_VERSION_1_2) -#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices) -#else -#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT) -#endif // #if defined(CL_VERSION_1_2) - -/** - * Deprecated APIs for 1.2 - */ -#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) -#define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker) -#define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents) -#define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier) -#define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler) -#define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D) -#define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D) -#define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D) -#define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D) -#endif // #if defined(CL_VERSION_1_1) - -#endif // __CL_USER_OVERRIDE_ERROR_STRINGS -//! \endcond - -/** - * CL 1.2 marker and barrier commands - */ -#if defined(CL_VERSION_1_2) -#define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList) -#define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList) -#endif // #if defined(CL_VERSION_1_2) - -#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING) -typedef std::string STRING_CLASS; -#elif !defined(__USE_DEV_STRING) - -/*! \class string - * \brief Simple string class, that provides a limited subset of std::string - * functionality but avoids many of the issues that come with that class. - - * \note Deprecated. Please use std::string as default or - * re-define the string class to match the std::string - * interface by defining STRING_CLASS - */ -class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string -{ -private: - ::size_t size_; - char * str_; -public: - //! \brief Constructs an empty string, allocating no memory. - string(void) : size_(0), str_(NULL) - { - } - - /*! \brief Constructs a string populated from an arbitrary value of - * specified size. - * - * An extra '\0' is added, in case none was contained in str. - * - * \param str the initial value of the string instance. Note that '\0' - * characters receive no special treatment. If NULL, - * the string is left empty, with a size of 0. - * - * \param size the number of characters to copy from str. - */ - string(const char * str, ::size_t size) : - size_(size), - str_(NULL) - { - if( size > 0 ) { - str_ = new char[size_+1]; - if (str_ != NULL) { - memcpy(str_, str, size_ * sizeof(char)); - str_[size_] = '\0'; - } - else { - size_ = 0; - } - } - } - - /*! \brief Constructs a string populated from a null-terminated value. - * - * \param str the null-terminated initial value of the string instance. - * If NULL, the string is left empty, with a size of 0. - */ - string(const char * str) : - size_(0), - str_(NULL) - { - if( str ) { - size_= ::strlen(str); - } - if( size_ > 0 ) { - str_ = new char[size_ + 1]; - if (str_ != NULL) { - memcpy(str_, str, (size_ + 1) * sizeof(char)); - } - } - } - - void resize( ::size_t n ) - { - if( size_ == n ) { - return; - } - if (n == 0) { - if( str_ ) { - delete [] str_; - } - str_ = NULL; - size_ = 0; - } - else { - char *newString = new char[n + 1]; - ::size_t copySize = n; - if( size_ < n ) { - copySize = size_; - } - size_ = n; - - if(str_) { - memcpy(newString, str_, (copySize + 1) * sizeof(char)); - } - if( copySize < size_ ) { - memset(newString + copySize, 0, size_ - copySize); - } - newString[size_] = '\0'; - - delete [] str_; - str_ = newString; - } - } - - const char& operator[] ( ::size_t pos ) const - { - return str_[pos]; - } - - char& operator[] ( ::size_t pos ) - { - return str_[pos]; - } - - /*! \brief Copies the value of another string to this one. - * - * \param rhs the string to copy. - * - * \returns a reference to the modified instance. - */ - string& operator=(const string& rhs) - { - if (this == &rhs) { - return *this; - } - - if( str_ != NULL ) { - delete [] str_; - str_ = NULL; - size_ = 0; - } - - if (rhs.size_ == 0 || rhs.str_ == NULL) { - str_ = NULL; - size_ = 0; - } - else { - str_ = new char[rhs.size_ + 1]; - size_ = rhs.size_; - - if (str_ != NULL) { - memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char)); - } - else { - size_ = 0; - } - } - - return *this; - } - - /*! \brief Constructs a string by copying the value of another instance. - * - * \param rhs the string to copy. - */ - string(const string& rhs) : - size_(0), - str_(NULL) - { - *this = rhs; - } - - //! \brief Destructor - frees memory used to hold the current value. - ~string() - { - delete[] str_; - str_ = NULL; - } - - //! \brief Queries the length of the string, excluding any added '\0's. - ::size_t size(void) const { return size_; } - - //! \brief Queries the length of the string, excluding any added '\0's. - ::size_t length(void) const { return size(); } - - /*! \brief Returns a pointer to the private copy held by this instance, - * or "" if empty/unset. - */ - const char * c_str(void) const { return (str_) ? str_ : "";} -} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; -typedef cl::string STRING_CLASS; -#endif // #elif !defined(__USE_DEV_STRING) - -#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) -#define VECTOR_CLASS std::vector -#elif !defined(__USE_DEV_VECTOR) -#define VECTOR_CLASS cl::vector - -#if !defined(__MAX_DEFAULT_VECTOR_SIZE) -#define __MAX_DEFAULT_VECTOR_SIZE 10 -#endif - -/*! \class vector - * \brief Fixed sized vector implementation that mirroring - * - * \note Deprecated. Please use std::vector as default or - * re-define the vector class to match the std::vector - * interface by defining VECTOR_CLASS - - * \note Not recommended for use with custom objects as - * current implementation will construct N elements - * - * std::vector functionality. - * \brief Fixed sized vector compatible with std::vector. - * - * \note - * This differs from std::vector<> not just in memory allocation, - * but also in terms of when members are constructed, destroyed, - * and assigned instead of being copy constructed. - * - * \param T type of element contained in the vector. - * - * \param N maximum size of the vector. - */ -template -class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector -{ -private: - T data_[N]; - unsigned int size_; - -public: - //! \brief Constructs an empty vector with no memory allocated. - vector() : - size_(static_cast(0)) - {} - - //! \brief Deallocates the vector's memory and destroys all of its elements. - ~vector() - { - clear(); - } - - //! \brief Returns the number of elements currently contained. - unsigned int size(void) const - { - return size_; - } - - /*! \brief Empties the vector of all elements. - * \note - * This does not deallocate memory but will invoke destructors - * on contained elements. - */ - void clear() - { - while(!empty()) { - pop_back(); - } - } - - /*! \brief Appends an element after the last valid element. - * Calling this on a vector that has reached capacity will throw an - * exception if exceptions are enabled. - */ - void push_back (const T& x) - { - if (size() < N) { - new (&data_[size_]) T(x); - size_++; - } else { - detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); - } - } - - /*! \brief Removes the last valid element from the vector. - * Calling this on an empty vector will throw an exception - * if exceptions are enabled. - */ - void pop_back(void) - { - if (size_ != 0) { - --size_; - data_[size_].~T(); - } else { - detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); - } - } - - /*! \brief Constructs with a value copied from another. - * - * \param vec the vector to copy. - */ - vector(const vector& vec) : - size_(vec.size_) - { - if (size_ != 0) { - assign(vec.begin(), vec.end()); - } - } - - /*! \brief Constructs with a specified number of initial elements. - * - * \param size number of initial elements. - * - * \param val value of initial elements. - */ - vector(unsigned int size, const T& val = T()) : - size_(0) - { - for (unsigned int i = 0; i < size; i++) { - push_back(val); - } - } - - /*! \brief Overwrites the current content with that copied from another - * instance. - * - * \param rhs vector to copy. - * - * \returns a reference to this. - */ - vector& operator=(const vector& rhs) - { - if (this == &rhs) { - return *this; - } - - if (rhs.size_ != 0) { - assign(rhs.begin(), rhs.end()); - } else { - clear(); - } - - return *this; - } - - /*! \brief Tests equality against another instance. - * - * \param vec the vector against which to compare. - */ - bool operator==(vector &vec) - { - if (size() != vec.size()) { - return false; - } - - for( unsigned int i = 0; i < size(); ++i ) { - if( operator[](i) != vec[i] ) { - return false; - } - } - return true; - } - - //! \brief Conversion operator to T*. - operator T* () { return data_; } - - //! \brief Conversion operator to const T*. - operator const T* () const { return data_; } - - //! \brief Tests whether this instance has any elements. - bool empty (void) const - { - return size_==0; - } - - //! \brief Returns the maximum number of elements this instance can hold. - unsigned int max_size (void) const - { - return N; - } - - //! \brief Returns the maximum number of elements this instance can hold. - unsigned int capacity () const - { - return N; - } - - //! \brief Resizes the vector to the given size - void resize(unsigned int newSize, T fill = T()) - { - if (newSize > N) - { - detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR); - } - else - { - while (size_ < newSize) - { - new (&data_[size_]) T(fill); - size_++; - } - while (size_ > newSize) - { - --size_; - data_[size_].~T(); - } - } - } - - /*! \brief Returns a reference to a given element. - * - * \param index which element to access. * - * \note - * The caller is responsible for ensuring index is >= 0 and < size(). - */ - T& operator[](int index) - { - return data_[index]; - } - - /*! \brief Returns a const reference to a given element. - * - * \param index which element to access. - * - * \note - * The caller is responsible for ensuring index is >= 0 and < size(). - */ - const T& operator[](int index) const - { - return data_[index]; - } - - /*! \brief Assigns elements of the vector based on a source iterator range. - * - * \param start Beginning iterator of source range - * \param end Enditerator of source range - * - * \note - * Will throw an exception if exceptions are enabled and size exceeded. - */ - template - void assign(I start, I end) - { - clear(); - while(start != end) { - push_back(*start); - start++; - } - } - - /*! \class iterator - * \brief Const iterator class for vectors - */ - class iterator - { - private: - const vector *vec_; - int index_; - - /** - * Internal iterator constructor to capture reference - * to the vector it iterates over rather than taking - * the vector by copy. - */ - iterator (const vector &vec, int index) : - vec_(&vec) - { - if( !vec.empty() ) { - index_ = index; - } else { - index_ = -1; - } - } - - public: - iterator(void) : - index_(-1), - vec_(NULL) - { - } - - iterator(const iterator& rhs) : - vec_(rhs.vec_), - index_(rhs.index_) - { - } - - ~iterator(void) {} - - static iterator begin(const cl::vector &vec) - { - iterator i(vec, 0); - - return i; - } - - static iterator end(const cl::vector &vec) - { - iterator i(vec, vec.size()); - - return i; - } - - bool operator==(iterator i) - { - return ((vec_ == i.vec_) && - (index_ == i.index_)); - } - - bool operator!=(iterator i) - { - return (!(*this==i)); - } - - iterator& operator++() - { - ++index_; - return *this; - } - - iterator operator++(int) - { - iterator retVal(*this); - ++index_; - return retVal; - } - - iterator& operator--() - { - --index_; - return *this; - } - - iterator operator--(int) - { - iterator retVal(*this); - --index_; - return retVal; - } - - const T& operator *() const - { - return (*vec_)[index_]; - } - }; - - iterator begin(void) - { - return iterator::begin(*this); - } - - iterator begin(void) const - { - return iterator::begin(*this); - } - - iterator end(void) - { - return iterator::end(*this); - } - - iterator end(void) const - { - return iterator::end(*this); - } - - T& front(void) - { - return data_[0]; - } - - T& back(void) - { - return data_[size_]; - } - - const T& front(void) const - { - return data_[0]; - } - - const T& back(void) const - { - return data_[size_-1]; - } -} CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; -#endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR) - - - - - -namespace detail { -#define __DEFAULT_NOT_INITIALIZED 1 -#define __DEFAULT_BEING_INITIALIZED 2 -#define __DEFAULT_INITIALIZED 4 - - /* - * Compare and exchange primitives are needed for handling of defaults - */ - -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED - inline int compare_exchange(std::atomic * dest, int exchange, int comparand) -#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED - inline int compare_exchange(volatile int * dest, int exchange, int comparand) -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED - { -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED - std::atomic_compare_exchange_strong(dest, &comparand, exchange); - return comparand; -#elif _MSC_VER - return (int)(_InterlockedCompareExchange( - (volatile long*)dest, - (long)exchange, - (long)comparand)); -#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED - return (__sync_val_compare_and_swap( - dest, - comparand, - exchange)); -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED - } - - inline void fence() { -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED - std::atomic_thread_fence(std::memory_order_seq_cst); -#elif _MSC_VER // !CL_HPP_CPP11_ATOMICS_SUPPORTED - _ReadWriteBarrier(); -#else // !_MSC_VER && !CL_HPP_CPP11_ATOMICS_SUPPORTED - __sync_synchronize(); -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED - } -} // namespace detail - - -/*! \brief class used to interface between C++ and - * OpenCL C calls that require arrays of size_t values, whose - * size is known statically. - */ -template -class size_t -{ -private: - ::size_t data_[N]; - -public: - //! \brief Initialize size_t to all 0s - size_t() - { - for( int i = 0; i < N; ++i ) { - data_[i] = 0; - } - } - - ::size_t& operator[](int index) - { - return data_[index]; - } - - const ::size_t& operator[](int index) const - { - return data_[index]; - } - - //! \brief Conversion operator to T*. - operator ::size_t* () { return data_; } - - //! \brief Conversion operator to const T*. - operator const ::size_t* () const { return data_; } -}; - -namespace detail { - -// Generic getInfoHelper. The final parameter is used to guide overload -// resolution: the actual parameter passed is an int, which makes this -// a worse conversion sequence than a specialization that declares the -// parameter as an int. -template -inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long) -{ - return f(name, sizeof(T), param, NULL); -} - -// Specialized getInfoHelper for VECTOR_CLASS params -template -inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, long) -{ - ::size_t required; - cl_int err = f(name, 0, NULL, &required); - if (err != CL_SUCCESS) { - return err; - } - - T* value = (T*) alloca(required); - err = f(name, required, value, NULL); - if (err != CL_SUCCESS) { - return err; - } - - param->assign(&value[0], &value[required/sizeof(T)]); - return CL_SUCCESS; -} - -/* Specialization for reference-counted types. This depends on the - * existence of Wrapper::cl_type, and none of the other types having the - * cl_type member. Note that simplify specifying the parameter as Wrapper - * does not work, because when using a derived type (e.g. Context) the generic - * template will provide a better match. - */ -template -inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int, typename T::cl_type = 0) -{ - ::size_t required; - cl_int err = f(name, 0, NULL, &required); - if (err != CL_SUCCESS) { - return err; - } - - typename T::cl_type * value = (typename T::cl_type *) alloca(required); - err = f(name, required, value, NULL); - if (err != CL_SUCCESS) { - return err; - } - - ::size_t elements = required / sizeof(typename T::cl_type); - param->assign(&value[0], &value[elements]); - for (::size_t i = 0; i < elements; i++) - { - if (value[i] != NULL) - { - err = (*param)[i].retain(); - if (err != CL_SUCCESS) { - return err; - } - } - } - return CL_SUCCESS; -} - -// Specialized for getInfo -template -inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS* param, int) -{ - cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL); - - if (err != CL_SUCCESS) { - return err; - } - - return CL_SUCCESS; -} - -// Specialized GetInfoHelper for STRING_CLASS params -template -inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long) -{ -#if defined(__NO_STD_VECTOR) || defined(__NO_STD_STRING) - ::size_t required; - cl_int err = f(name, 0, NULL, &required); - if (err != CL_SUCCESS) { - return err; - } - - char* value = (char*)alloca(required); - err = f(name, required, value, NULL); - if (err != CL_SUCCESS) { - return err; - } - - *param = value; - return CL_SUCCESS; -#else - ::size_t required; - cl_int err = f(name, 0, NULL, &required); - if (err != CL_SUCCESS) { - return err; - } - - // std::string has a constant data member - // a char vector does not - VECTOR_CLASS value(required); - err = f(name, required, value.data(), NULL); - if (err != CL_SUCCESS) { - return err; - } - if (param) { - param->assign(value.begin(), value.end()); - } -#endif - return CL_SUCCESS; -} - -// Specialized GetInfoHelper for cl::size_t params -template -inline cl_int getInfoHelper(Func f, cl_uint name, size_t* param, long) -{ - ::size_t required; - cl_int err = f(name, 0, NULL, &required); - if (err != CL_SUCCESS) { - return err; - } - - ::size_t* value = (::size_t*) alloca(required); - err = f(name, required, value, NULL); - if (err != CL_SUCCESS) { - return err; - } - - for(int i = 0; i < N; ++i) { - (*param)[i] = value[i]; - } - - return CL_SUCCESS; -} - -template struct ReferenceHandler; - -/* Specialization for reference-counted types. This depends on the - * existence of Wrapper::cl_type, and none of the other types having the - * cl_type member. Note that simplify specifying the parameter as Wrapper - * does not work, because when using a derived type (e.g. Context) the generic - * template will provide a better match. - */ -template -inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0) -{ - typename T::cl_type value; - cl_int err = f(name, sizeof(value), &value, NULL); - if (err != CL_SUCCESS) { - return err; - } - *param = value; - if (value != NULL) - { - err = param->retain(); - if (err != CL_SUCCESS) { - return err; - } - } - return CL_SUCCESS; -} - -#define __PARAM_NAME_INFO_1_0(F) \ - F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \ - F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \ - F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \ - F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \ - F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \ - \ - F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \ - F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \ - F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \ - F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \ - F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \ - F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \ - F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \ - F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \ - F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \ - F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \ - F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \ - F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \ - F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \ - F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \ - F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \ - F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \ - F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \ - F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \ - F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \ - F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \ - F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \ - F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \ - F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \ - F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \ - F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \ - F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \ - F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \ - F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \ - F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \ - F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\ - F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \ - F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \ - F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \ - F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \ - F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \ - F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \ - F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \ - F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \ - F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \ - F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \ - F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \ - F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \ - F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \ - F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \ - F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \ - F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \ - F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \ - F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \ - F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \ - F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \ - \ - F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \ - F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS) \ - F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS) \ - \ - F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \ - F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \ - F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \ - F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_int) \ - \ - F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \ - F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \ - F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \ - F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \ - \ - F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \ - F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \ - F(cl_mem_info, CL_MEM_SIZE, ::size_t) \ - F(cl_mem_info, CL_MEM_HOST_PTR, void*) \ - F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \ - F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \ - F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \ - \ - F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \ - F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \ - F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \ - F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \ - F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \ - F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \ - F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \ - \ - F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \ - F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \ - F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_bool) \ - F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_addressing_mode) \ - F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_filter_mode) \ - \ - F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \ - F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \ - F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \ - F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS) \ - F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \ - F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \ - F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS) \ - \ - F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \ - F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \ - F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \ - \ - F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \ - F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \ - F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \ - F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \ - F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \ - \ - F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \ - F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \ - F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \ - \ - F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \ - F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \ - F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \ - F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties) - -#if defined(CL_VERSION_1_1) -#define __PARAM_NAME_INFO_1_1(F) \ - F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\ - F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \ - F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \ - F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \ - F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \ - F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \ - F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \ - F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \ - F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \ - F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \ - F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \ - F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \ - F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \ - \ - F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \ - F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \ - \ - F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \ - F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \ - \ - F(cl_event_info, CL_EVENT_CONTEXT, cl::Context) -#endif // CL_VERSION_1_1 - - -#if defined(CL_VERSION_1_2) -#define __PARAM_NAME_INFO_1_2(F) \ - F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \ - \ - F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \ - F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \ - \ - F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \ - \ - F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \ - \ - F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \ - F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \ - F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \ - F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \ - F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_QUALIFIER, cl_kernel_arg_type_qualifier) \ - \ - F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \ - F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS) \ - F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS) \ - F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \ - F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \ - F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \ - F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS) -#endif // #if defined(CL_VERSION_1_2) - -#if defined(USE_CL_DEVICE_FISSION) -#define __PARAM_NAME_DEVICE_FISSION(F) \ - F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \ - F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS) \ - F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS) \ - F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \ - F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS) -#endif // USE_CL_DEVICE_FISSION - -template -struct param_traits {}; - -#define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \ -struct token; \ -template<> \ -struct param_traits \ -{ \ - enum { value = param_name }; \ - typedef T param_type; \ -}; - -__PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS) -#if defined(CL_VERSION_1_1) -__PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS) -#endif // CL_VERSION_1_1 -#if defined(CL_VERSION_1_2) -__PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS) -#endif // CL_VERSION_1_1 - -#if defined(USE_CL_DEVICE_FISSION) -__PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS); -#endif // USE_CL_DEVICE_FISSION - -#ifdef CL_PLATFORM_ICD_SUFFIX_KHR -__CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS) -#endif - -#ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong) -#endif - -#ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>) -#endif -#ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_SIMD_WIDTH_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint) -#endif -#ifdef CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_AMD, ::size_t) -#endif -#ifdef CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE_AMD, ::size_t) -#endif -#ifdef CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PREFERRED_CONSTANT_BUFFER_SIZE_AMD, ::size_t) -#endif - -#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint) -#endif -#ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint) -#endif -#ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint) -#endif -#ifdef CL_DEVICE_WARP_SIZE_NV -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint) -#endif -#ifdef CL_DEVICE_GPU_OVERLAP_NV -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool) -#endif -#ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool) -#endif -#ifdef CL_DEVICE_INTEGRATED_MEMORY_NV -__CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool) -#endif - -// Convenience functions - -template -inline cl_int -getInfo(Func f, cl_uint name, T* param) -{ - return getInfoHelper(f, name, param, 0); -} - -template -struct GetInfoFunctor0 -{ - Func f_; const Arg0& arg0_; - cl_int operator ()( - cl_uint param, ::size_t size, void* value, ::size_t* size_ret) - { return f_(arg0_, param, size, value, size_ret); } -}; - -template -struct GetInfoFunctor1 -{ - Func f_; const Arg0& arg0_; const Arg1& arg1_; - cl_int operator ()( - cl_uint param, ::size_t size, void* value, ::size_t* size_ret) - { return f_(arg0_, arg1_, param, size, value, size_ret); } -}; - -template -inline cl_int -getInfo(Func f, const Arg0& arg0, cl_uint name, T* param) -{ - GetInfoFunctor0 f0 = { f, arg0 }; - return getInfoHelper(f0, name, param, 0); -} - -template -inline cl_int -getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param) -{ - GetInfoFunctor1 f0 = { f, arg0, arg1 }; - return getInfoHelper(f0, name, param, 0); -} - -template -struct ReferenceHandler -{ }; - -#if defined(CL_VERSION_1_2) -/** - * OpenCL 1.2 devices do have retain/release. - */ -template <> -struct ReferenceHandler -{ - /** - * Retain the device. - * \param device A valid device created using createSubDevices - * \return - * CL_SUCCESS if the function executed successfully. - * CL_INVALID_DEVICE if device was not a valid subdevice - * CL_OUT_OF_RESOURCES - * CL_OUT_OF_HOST_MEMORY - */ - static cl_int retain(cl_device_id device) - { return ::clRetainDevice(device); } - /** - * Retain the device. - * \param device A valid device created using createSubDevices - * \return - * CL_SUCCESS if the function executed successfully. - * CL_INVALID_DEVICE if device was not a valid subdevice - * CL_OUT_OF_RESOURCES - * CL_OUT_OF_HOST_MEMORY - */ - static cl_int release(cl_device_id device) - { return ::clReleaseDevice(device); } -}; -#else // #if defined(CL_VERSION_1_2) -/** - * OpenCL 1.1 devices do not have retain/release. - */ -template <> -struct ReferenceHandler -{ - // cl_device_id does not have retain(). - static cl_int retain(cl_device_id) - { return CL_SUCCESS; } - // cl_device_id does not have release(). - static cl_int release(cl_device_id) - { return CL_SUCCESS; } -}; -#endif // #if defined(CL_VERSION_1_2) - -template <> -struct ReferenceHandler -{ - // cl_platform_id does not have retain(). - static cl_int retain(cl_platform_id) - { return CL_SUCCESS; } - // cl_platform_id does not have release(). - static cl_int release(cl_platform_id) - { return CL_SUCCESS; } -}; - -template <> -struct ReferenceHandler -{ - static cl_int retain(cl_context context) - { return ::clRetainContext(context); } - static cl_int release(cl_context context) - { return ::clReleaseContext(context); } -}; - -template <> -struct ReferenceHandler -{ - static cl_int retain(cl_command_queue queue) - { return ::clRetainCommandQueue(queue); } - static cl_int release(cl_command_queue queue) - { return ::clReleaseCommandQueue(queue); } -}; - -template <> -struct ReferenceHandler -{ - static cl_int retain(cl_mem memory) - { return ::clRetainMemObject(memory); } - static cl_int release(cl_mem memory) - { return ::clReleaseMemObject(memory); } -}; - -template <> -struct ReferenceHandler -{ - static cl_int retain(cl_sampler sampler) - { return ::clRetainSampler(sampler); } - static cl_int release(cl_sampler sampler) - { return ::clReleaseSampler(sampler); } -}; - -template <> -struct ReferenceHandler -{ - static cl_int retain(cl_program program) - { return ::clRetainProgram(program); } - static cl_int release(cl_program program) - { return ::clReleaseProgram(program); } -}; - -template <> -struct ReferenceHandler -{ - static cl_int retain(cl_kernel kernel) - { return ::clRetainKernel(kernel); } - static cl_int release(cl_kernel kernel) - { return ::clReleaseKernel(kernel); } -}; - -template <> -struct ReferenceHandler -{ - static cl_int retain(cl_event event) - { return ::clRetainEvent(event); } - static cl_int release(cl_event event) - { return ::clReleaseEvent(event); } -}; - - -// Extracts version number with major in the upper 16 bits, minor in the lower 16 -static cl_uint getVersion(const char *versionInfo) -{ - int highVersion = 0; - int lowVersion = 0; - int index = 7; - while(versionInfo[index] != '.' ) { - highVersion *= 10; - highVersion += versionInfo[index]-'0'; - ++index; - } - ++index; - while(versionInfo[index] != ' ' && versionInfo[index] != '\0') { - lowVersion *= 10; - lowVersion += versionInfo[index]-'0'; - ++index; - } - return (highVersion << 16) | lowVersion; -} - -static cl_uint getPlatformVersion(cl_platform_id platform) -{ - ::size_t size = 0; - clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size); - char *versionInfo = (char *) alloca(size); - clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size); - return getVersion(versionInfo); -} - -static cl_uint getDevicePlatformVersion(cl_device_id device) -{ - cl_platform_id platform; - clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL); - return getPlatformVersion(platform); -} - -#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) -static cl_uint getContextPlatformVersion(cl_context context) -{ - // The platform cannot be queried directly, so we first have to grab a - // device and obtain its context - ::size_t size = 0; - clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size); - if (size == 0) - return 0; - cl_device_id *devices = (cl_device_id *) alloca(size); - clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL); - return getDevicePlatformVersion(devices[0]); -} -#endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) - -template -class Wrapper -{ -public: - typedef T cl_type; - -protected: - cl_type object_; - -public: - Wrapper() : object_(NULL) { } - - Wrapper(const cl_type &obj) : object_(obj) { } - - ~Wrapper() - { - if (object_ != NULL) { release(); } - } - - Wrapper(const Wrapper& rhs) - { - object_ = rhs.object_; - if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT - { - object_ = rhs.object_; - rhs.object_ = NULL; - } -#endif - - Wrapper& operator = (const Wrapper& rhs) - { - if (this != &rhs) { - if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } - object_ = rhs.object_; - if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } - } - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - Wrapper& operator = (Wrapper&& rhs) - { - if (this != &rhs) { - if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } - object_ = rhs.object_; - rhs.object_ = NULL; - } - return *this; - } -#endif - - Wrapper& operator = (const cl_type &rhs) - { - if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } - object_ = rhs; - return *this; - } - - cl_type operator ()() const { return object_; } - - cl_type& operator ()() { return object_; } - -protected: - template - friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); - - cl_int retain() const - { - return ReferenceHandler::retain(object_); - } - - cl_int release() const - { - return ReferenceHandler::release(object_); - } -}; - -template <> -class Wrapper -{ -public: - typedef cl_device_id cl_type; - -protected: - cl_type object_; - bool referenceCountable_; - - static bool isReferenceCountable(cl_device_id device) - { - bool retVal = false; - if (device != NULL) { - int version = getDevicePlatformVersion(device); - if(version > ((1 << 16) + 1)) { - retVal = true; - } - } - return retVal; - } - -public: - Wrapper() : object_(NULL), referenceCountable_(false) - { - } - - Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false) - { - referenceCountable_ = isReferenceCountable(obj); - } - - ~Wrapper() - { - if (object_ != NULL) { release(); } - } - - Wrapper(const Wrapper& rhs) - { - object_ = rhs.object_; - referenceCountable_ = isReferenceCountable(object_); - if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - Wrapper(Wrapper&& rhs) CL_HPP_NOEXCEPT - { - object_ = rhs.object_; - referenceCountable_ = rhs.referenceCountable_; - rhs.object_ = NULL; - rhs.referenceCountable_ = false; - } -#endif - - Wrapper& operator = (const Wrapper& rhs) - { - if (this != &rhs) { - if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } - object_ = rhs.object_; - referenceCountable_ = rhs.referenceCountable_; - if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); } - } - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - Wrapper& operator = (Wrapper&& rhs) - { - if (this != &rhs) { - if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } - object_ = rhs.object_; - referenceCountable_ = rhs.referenceCountable_; - rhs.object_ = NULL; - rhs.referenceCountable_ = false; - } - return *this; - } -#endif - - Wrapper& operator = (const cl_type &rhs) - { - if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); } - object_ = rhs; - referenceCountable_ = isReferenceCountable(object_); - return *this; - } - - cl_type operator ()() const { return object_; } - - cl_type& operator ()() { return object_; } - -protected: - template - friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type); - - template - friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS*, int, typename U::cl_type); - - cl_int retain() const - { - if( referenceCountable_ ) { - return ReferenceHandler::retain(object_); - } - else { - return CL_SUCCESS; - } - } - - cl_int release() const - { - if( referenceCountable_ ) { - return ReferenceHandler::release(object_); - } - else { - return CL_SUCCESS; - } - } -}; - -} // namespace detail -//! \endcond - -/*! \stuct ImageFormat - * \brief Adds constructors and member functions for cl_image_format. - * - * \see cl_image_format - */ -struct ImageFormat : public cl_image_format -{ - //! \brief Default constructor - performs no initialization. - ImageFormat(){} - - //! \brief Initializing constructor. - ImageFormat(cl_channel_order order, cl_channel_type type) - { - image_channel_order = order; - image_channel_data_type = type; - } - - //! \brief Assignment operator. - ImageFormat& operator = (const ImageFormat& rhs) - { - if (this != &rhs) { - this->image_channel_data_type = rhs.image_channel_data_type; - this->image_channel_order = rhs.image_channel_order; - } - return *this; - } -}; - -/*! \brief Class interface for cl_device_id. - * - * \note Copies of these objects are inexpensive, since they don't 'own' - * any underlying resources or data structures. - * - * \see cl_device_id - */ -class Device : public detail::Wrapper -{ -public: - //! \brief Default constructor - initializes to NULL. - Device() : detail::Wrapper() { } - - /*! \brief Constructor from cl_device_id. - * - * This simply copies the device ID value, which is an inexpensive operation. - */ - __CL_EXPLICIT_CONSTRUCTORS Device(const cl_device_id &device) : detail::Wrapper(device) { } - - /*! \brief Returns the first device on the default context. - * - * \see Context::getDefault() - */ - static Device getDefault(cl_int * err = NULL); - - /*! \brief Assignment operator from cl_device_id. - * - * This simply copies the device ID value, which is an inexpensive operation. - */ - Device& operator = (const cl_device_id& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Device(const Device& dev) : detail::Wrapper(dev) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Device& operator = (const Device &dev) - { - detail::Wrapper::operator=(dev); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Device(Device&& dev) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(dev)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Device& operator = (Device &&dev) - { - detail::Wrapper::operator=(std::move(dev)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - //! \brief Wrapper for clGetDeviceInfo(). - template - cl_int getInfo(cl_device_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetDeviceInfo, object_, name, param), - __GET_DEVICE_INFO_ERR); - } - - //! \brief Wrapper for clGetDeviceInfo() that returns by value. - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_device_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - /** - * CL 1.2 version - */ -#if defined(CL_VERSION_1_2) - //! \brief Wrapper for clCreateSubDevicesEXT(). - cl_int createSubDevices( - const cl_device_partition_property * properties, - VECTOR_CLASS* devices) - { - cl_uint n = 0; - cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __CREATE_SUB_DEVICES); - } - - cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); - err = clCreateSubDevices(object_, properties, n, ids, NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __CREATE_SUB_DEVICES); - } - - devices->assign(&ids[0], &ids[n]); - return CL_SUCCESS; - } -#endif // #if defined(CL_VERSION_1_2) - -/** - * CL 1.1 version that uses device fission. - */ -#if defined(CL_VERSION_1_1) -#if defined(USE_CL_DEVICE_FISSION) - cl_int createSubDevices( - const cl_device_partition_property_ext * properties, - VECTOR_CLASS* devices) - { - typedef CL_API_ENTRY cl_int - ( CL_API_CALL * PFN_clCreateSubDevicesEXT)( - cl_device_id /*in_device*/, - const cl_device_partition_property_ext * /* properties */, - cl_uint /*num_entries*/, - cl_device_id * /*out_devices*/, - cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL; - __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT); - - cl_uint n = 0; - cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __CREATE_SUB_DEVICES); - } - - cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); - err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __CREATE_SUB_DEVICES); - } - - devices->assign(&ids[0], &ids[n]); - return CL_SUCCESS; - } -#endif // #if defined(USE_CL_DEVICE_FISSION) -#endif // #if defined(CL_VERSION_1_1) -}; - -/*! \brief Class interface for cl_platform_id. - * - * \note Copies of these objects are inexpensive, since they don't 'own' - * any underlying resources or data structures. - * - * \see cl_platform_id - */ -class Platform : public detail::Wrapper -{ -public: - //! \brief Default constructor - initializes to NULL. - Platform() : detail::Wrapper() { } - - /*! \brief Constructor from cl_platform_id. - * - * This simply copies the platform ID value, which is an inexpensive operation. - */ - __CL_EXPLICIT_CONSTRUCTORS Platform(const cl_platform_id &platform) : detail::Wrapper(platform) { } - - /*! \brief Assignment operator from cl_platform_id. - * - * This simply copies the platform ID value, which is an inexpensive operation. - */ - Platform& operator = (const cl_platform_id& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - //! \brief Wrapper for clGetPlatformInfo(). - cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetPlatformInfo, object_, name, param), - __GET_PLATFORM_INFO_ERR); - } - - //! \brief Wrapper for clGetPlatformInfo() that returns by value. - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_platform_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - /*! \brief Gets a list of devices for this platform. - * - * Wraps clGetDeviceIDs(). - */ - cl_int getDevices( - cl_device_type type, - VECTOR_CLASS* devices) const - { - cl_uint n = 0; - if( devices == NULL ) { - return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); - } - cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_DEVICE_IDS_ERR); - } - - cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); - err = ::clGetDeviceIDs(object_, type, n, ids, NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_DEVICE_IDS_ERR); - } - - devices->assign(&ids[0], &ids[n]); - return CL_SUCCESS; - } - -#if defined(USE_DX_INTEROP) - /*! \brief Get the list of available D3D10 devices. - * - * \param d3d_device_source. - * - * \param d3d_object. - * - * \param d3d_device_set. - * - * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device - * values returned in devices can be used to identify a specific OpenCL - * device. If \a devices argument is NULL, this argument is ignored. - * - * \return One of the following values: - * - CL_SUCCESS if the function is executed successfully. - * - * The application can query specific capabilities of the OpenCL device(s) - * returned by cl::getDevices. This can be used by the application to - * determine which device(s) to use. - * - * \note In the case that exceptions are enabled and a return value - * other than CL_SUCCESS is generated, then cl::Error exception is - * generated. - */ - cl_int getDevices( - cl_d3d10_device_source_khr d3d_device_source, - void * d3d_object, - cl_d3d10_device_set_khr d3d_device_set, - VECTOR_CLASS* devices) const - { - typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)( - cl_platform_id platform, - cl_d3d10_device_source_khr d3d_device_source, - void * d3d_object, - cl_d3d10_device_set_khr d3d_device_set, - cl_uint num_entries, - cl_device_id * devices, - cl_uint* num_devices); - - if( devices == NULL ) { - return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR); - } - - static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL; - __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR); - - cl_uint n = 0; - cl_int err = pfn_clGetDeviceIDsFromD3D10KHR( - object_, - d3d_device_source, - d3d_object, - d3d_device_set, - 0, - NULL, - &n); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_DEVICE_IDS_ERR); - } - - cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id)); - err = pfn_clGetDeviceIDsFromD3D10KHR( - object_, - d3d_device_source, - d3d_object, - d3d_device_set, - n, - ids, - NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_DEVICE_IDS_ERR); - } - - devices->assign(&ids[0], &ids[n]); - return CL_SUCCESS; - } -#endif - - /*! \brief Gets a list of available platforms. - * - * Wraps clGetPlatformIDs(). - */ - static cl_int get( - VECTOR_CLASS* platforms) - { - cl_uint n = 0; - - if( platforms == NULL ) { - return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); - } - - cl_int err = ::clGetPlatformIDs(0, NULL, &n); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); - } - - cl_platform_id* ids = (cl_platform_id*) alloca( - n * sizeof(cl_platform_id)); - err = ::clGetPlatformIDs(n, ids, NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); - } - - platforms->assign(&ids[0], &ids[n]); - return CL_SUCCESS; - } - - /*! \brief Gets the first available platform. - * - * Wraps clGetPlatformIDs(), returning the first result. - */ - static cl_int get( - Platform * platform) - { - cl_uint n = 0; - - if( platform == NULL ) { - return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR); - } - - cl_int err = ::clGetPlatformIDs(0, NULL, &n); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); - } - - cl_platform_id* ids = (cl_platform_id*) alloca( - n * sizeof(cl_platform_id)); - err = ::clGetPlatformIDs(n, ids, NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_PLATFORM_IDS_ERR); - } - - *platform = ids[0]; - return CL_SUCCESS; - } - - /*! \brief Gets the first available platform, returning it by value. - * - * Wraps clGetPlatformIDs(), returning the first result. - */ - static Platform get( - cl_int * errResult = NULL) - { - Platform platform; - cl_uint n = 0; - cl_int err = ::clGetPlatformIDs(0, NULL, &n); - if (err != CL_SUCCESS) { - detail::errHandler(err, __GET_PLATFORM_IDS_ERR); - if (errResult != NULL) { - *errResult = err; - } - return Platform(); - } - - cl_platform_id* ids = (cl_platform_id*) alloca( - n * sizeof(cl_platform_id)); - err = ::clGetPlatformIDs(n, ids, NULL); - - if (err != CL_SUCCESS) { - detail::errHandler(err, __GET_PLATFORM_IDS_ERR); - if (errResult != NULL) { - *errResult = err; - } - return Platform(); - } - - - return Platform(ids[0]); - } - - static Platform getDefault( - cl_int *errResult = NULL ) - { - return get(errResult); - } - - -#if defined(CL_VERSION_1_2) - //! \brief Wrapper for clUnloadCompiler(). - cl_int - unloadCompiler() - { - return ::clUnloadPlatformCompiler(object_); - } -#endif // #if defined(CL_VERSION_1_2) -}; // class Platform - -/** - * Deprecated APIs for 1.2 - */ -#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) -/** - * Unload the OpenCL compiler. - * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead. - */ -inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int -UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; -inline cl_int -UnloadCompiler() -{ - return ::clUnloadCompiler(); -} -#endif // #if defined(CL_VERSION_1_1) - -/*! \brief Class interface for cl_context. - * - * \note Copies of these objects are shallow, meaning that the copy will refer - * to the same underlying cl_context as the original. For details, see - * clRetainContext() and clReleaseContext(). - * - * \see cl_context - */ -class Context - : public detail::Wrapper -{ -private: - -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED - static std::atomic default_initialized_; -#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED - static volatile int default_initialized_; -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED - static Context default_; - static volatile cl_int default_error_; -public: - /*! \brief Constructs a context including a list of specified devices. - * - * Wraps clCreateContext(). - */ - Context( - const VECTOR_CLASS& devices, - cl_context_properties* properties = NULL, - void (CL_CALLBACK * notifyFptr)( - const char *, - const void *, - ::size_t, - void *) = NULL, - void* data = NULL, - cl_int* err = NULL) - { - cl_int error; - - ::size_t numDevices = devices.size(); - cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); - for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { - deviceIDs[deviceIndex] = (devices[deviceIndex])(); - } - - object_ = ::clCreateContext( - properties, (cl_uint) numDevices, - deviceIDs, - notifyFptr, data, &error); - - detail::errHandler(error, __CREATE_CONTEXT_ERR); - if (err != NULL) { - *err = error; - } - } - - Context( - const Device& device, - cl_context_properties* properties = NULL, - void (CL_CALLBACK * notifyFptr)( - const char *, - const void *, - ::size_t, - void *) = NULL, - void* data = NULL, - cl_int* err = NULL) - { - cl_int error; - - cl_device_id deviceID = device(); - - object_ = ::clCreateContext( - properties, 1, - &deviceID, - notifyFptr, data, &error); - - detail::errHandler(error, __CREATE_CONTEXT_ERR); - if (err != NULL) { - *err = error; - } - } - - /*! \brief Constructs a context including all or a subset of devices of a specified type. - * - * Wraps clCreateContextFromType(). - */ - Context( - cl_device_type type, - cl_context_properties* properties = NULL, - void (CL_CALLBACK * notifyFptr)( - const char *, - const void *, - ::size_t, - void *) = NULL, - void* data = NULL, - cl_int* err = NULL) - { - cl_int error; - -#if !defined(__APPLE__) && !defined(__MACOS) - cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 }; - - if (properties == NULL) { - // Get a valid platform ID as we cannot send in a blank one - VECTOR_CLASS platforms; - error = Platform::get(&platforms); - if (error != CL_SUCCESS) { - detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); - if (err != NULL) { - *err = error; - } - return; - } - - // Check the platforms we found for a device of our specified type - cl_context_properties platform_id = 0; - for (unsigned int i = 0; i < platforms.size(); i++) { - - VECTOR_CLASS devices; - -#if defined(__CL_ENABLE_EXCEPTIONS) - try { -#endif - - error = platforms[i].getDevices(type, &devices); - -#if defined(__CL_ENABLE_EXCEPTIONS) - } catch (Error) {} - // Catch if exceptions are enabled as we don't want to exit if first platform has no devices of type - // We do error checking next anyway, and can throw there if needed -#endif - - // Only squash CL_SUCCESS and CL_DEVICE_NOT_FOUND - if (error != CL_SUCCESS && error != CL_DEVICE_NOT_FOUND) { - detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); - if (err != NULL) { - *err = error; - } - } - - if (devices.size() > 0) { - platform_id = (cl_context_properties)platforms[i](); - break; - } - } - - if (platform_id == 0) { - detail::errHandler(CL_DEVICE_NOT_FOUND, __CREATE_CONTEXT_FROM_TYPE_ERR); - if (err != NULL) { - *err = CL_DEVICE_NOT_FOUND; - } - return; - } - - prop[1] = platform_id; - properties = &prop[0]; - } -#endif - object_ = ::clCreateContextFromType( - properties, type, notifyFptr, data, &error); - - detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR); - if (err != NULL) { - *err = error; - } - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Context(const Context& ctx) : detail::Wrapper(ctx) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Context& operator = (const Context &ctx) - { - detail::Wrapper::operator=(ctx); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Context(Context&& ctx) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(ctx)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Context& operator = (Context &&ctx) - { - detail::Wrapper::operator=(std::move(ctx)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT. - * - * \note All calls to this function return the same cl_context as the first. - */ - static Context getDefault(cl_int * err = NULL) - { - int state = detail::compare_exchange( - &default_initialized_, - __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); - - if (state & __DEFAULT_INITIALIZED) { - if (err != NULL) { - *err = default_error_; - } - return default_; - } - - if (state & __DEFAULT_BEING_INITIALIZED) { - // Assume writes will propagate eventually... - while(default_initialized_ != __DEFAULT_INITIALIZED) { - detail::fence(); - } - - if (err != NULL) { - *err = default_error_; - } - return default_; - } - - cl_int error; - default_ = Context( - CL_DEVICE_TYPE_DEFAULT, - NULL, - NULL, - NULL, - &error); - - detail::fence(); - - default_error_ = error; - // Assume writes will propagate eventually... - default_initialized_ = __DEFAULT_INITIALIZED; - - detail::fence(); - - if (err != NULL) { - *err = default_error_; - } - return default_; - - } - - //! \brief Default constructor - initializes to NULL. - Context() : detail::Wrapper() { } - - /*! \brief Constructor from cl_context - takes ownership. - * - * This effectively transfers ownership of a refcount on the cl_context - * into the new Context object. - */ - __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper(context) { } - - /*! \brief Assignment operator from cl_context - takes ownership. - * - * This effectively transfers ownership of a refcount on the rhs and calls - * clReleaseContext() on the value previously held by this instance. - */ - Context& operator = (const cl_context& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - //! \brief Wrapper for clGetContextInfo(). - template - cl_int getInfo(cl_context_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetContextInfo, object_, name, param), - __GET_CONTEXT_INFO_ERR); - } - - //! \brief Wrapper for clGetContextInfo() that returns by value. - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_context_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - /*! \brief Gets a list of supported image formats. - * - * Wraps clGetSupportedImageFormats(). - */ - cl_int getSupportedImageFormats( - cl_mem_flags flags, - cl_mem_object_type type, - VECTOR_CLASS* formats) const - { - cl_uint numEntries; - - if (!formats) { - return CL_SUCCESS; - } - - cl_int err = ::clGetSupportedImageFormats( - object_, - flags, - type, - 0, - NULL, - &numEntries); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); - } - - if (numEntries > 0) { - ImageFormat* value = (ImageFormat*) - alloca(numEntries * sizeof(ImageFormat)); - err = ::clGetSupportedImageFormats( - object_, - flags, - type, - numEntries, - (cl_image_format*)value, - NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR); - } - - formats->assign(&value[0], &value[numEntries]); - } - else { - formats->clear(); - } - return CL_SUCCESS; - } -}; - -inline Device Device::getDefault(cl_int * err) -{ - cl_int error; - Device device; - - Context context = Context::getDefault(&error); - detail::errHandler(error, __CREATE_CONTEXT_ERR); - - if (error != CL_SUCCESS) { - if (err != NULL) { - *err = error; - } - } - else { - device = context.getInfo()[0]; - if (err != NULL) { - *err = CL_SUCCESS; - } - } - - return device; -} - - -#ifdef _WIN32 -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED -__declspec(selectany) std::atomic Context::default_initialized_; -#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED -__declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED -__declspec(selectany) Context Context::default_; -__declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS; -#else // !_WIN32 -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED -__attribute__((weak)) std::atomic Context::default_initialized_; -#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED -__attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED; -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED -__attribute__((weak)) Context Context::default_; -__attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS; -#endif // !_WIN32 - -/*! \brief Class interface for cl_event. - * - * \note Copies of these objects are shallow, meaning that the copy will refer - * to the same underlying cl_event as the original. For details, see - * clRetainEvent() and clReleaseEvent(). - * - * \see cl_event - */ -class Event : public detail::Wrapper -{ -public: - //! \brief Default constructor - initializes to NULL. - Event() : detail::Wrapper() { } - - /*! \brief Constructor from cl_event - takes ownership. - * - * This effectively transfers ownership of a refcount on the cl_event - * into the new Event object. - */ - __CL_EXPLICIT_CONSTRUCTORS Event(const cl_event& event) : detail::Wrapper(event) { } - - /*! \brief Assignment operator from cl_event - takes ownership. - * - * This effectively transfers ownership of a refcount on the rhs and calls - * clReleaseEvent() on the value previously held by this instance. - */ - Event& operator = (const cl_event& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - //! \brief Wrapper for clGetEventInfo(). - template - cl_int getInfo(cl_event_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetEventInfo, object_, name, param), - __GET_EVENT_INFO_ERR); - } - - //! \brief Wrapper for clGetEventInfo() that returns by value. - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_event_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - //! \brief Wrapper for clGetEventProfilingInfo(). - template - cl_int getProfilingInfo(cl_profiling_info name, T* param) const - { - return detail::errHandler(detail::getInfo( - &::clGetEventProfilingInfo, object_, name, param), - __GET_EVENT_PROFILE_INFO_ERR); - } - - //! \brief Wrapper for clGetEventProfilingInfo() that returns by value. - template typename - detail::param_traits::param_type - getProfilingInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_profiling_info, name>::param_type param; - cl_int result = getProfilingInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - /*! \brief Blocks the calling thread until this event completes. - * - * Wraps clWaitForEvents(). - */ - cl_int wait() const - { - return detail::errHandler( - ::clWaitForEvents(1, &object_), - __WAIT_FOR_EVENTS_ERR); - } - -#if defined(CL_VERSION_1_1) - /*! \brief Registers a user callback function for a specific command execution status. - * - * Wraps clSetEventCallback(). - */ - cl_int setCallback( - cl_int type, - void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *), - void * user_data = NULL) - { - return detail::errHandler( - ::clSetEventCallback( - object_, - type, - pfn_notify, - user_data), - __SET_EVENT_CALLBACK_ERR); - } -#endif - - /*! \brief Blocks the calling thread until every event specified is complete. - * - * Wraps clWaitForEvents(). - */ - static cl_int - waitForEvents(const VECTOR_CLASS& events) - { - return detail::errHandler( - ::clWaitForEvents( - (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), - __WAIT_FOR_EVENTS_ERR); - } -}; - -#if defined(CL_VERSION_1_1) -/*! \brief Class interface for user events (a subset of cl_event's). - * - * See Event for details about copy semantics, etc. - */ -class UserEvent : public Event -{ -public: - /*! \brief Constructs a user event on a given context. - * - * Wraps clCreateUserEvent(). - */ - UserEvent( - const Context& context, - cl_int * err = NULL) - { - cl_int error; - object_ = ::clCreateUserEvent( - context(), - &error); - - detail::errHandler(error, __CREATE_USER_EVENT_ERR); - if (err != NULL) { - *err = error; - } - } - - //! \brief Default constructor - initializes to NULL. - UserEvent() : Event() { } - - /*! \brief Sets the execution status of a user event object. - * - * Wraps clSetUserEventStatus(). - */ - cl_int setStatus(cl_int status) - { - return detail::errHandler( - ::clSetUserEventStatus(object_,status), - __SET_USER_EVENT_STATUS_ERR); - } -}; -#endif - -/*! \brief Blocks the calling thread until every event specified is complete. - * - * Wraps clWaitForEvents(). - */ -inline static cl_int -WaitForEvents(const VECTOR_CLASS& events) -{ - return detail::errHandler( - ::clWaitForEvents( - (cl_uint) events.size(), (events.size() > 0) ? (cl_event*)&events.front() : NULL), - __WAIT_FOR_EVENTS_ERR); -} - -/*! \brief Class interface for cl_mem. - * - * \note Copies of these objects are shallow, meaning that the copy will refer - * to the same underlying cl_mem as the original. For details, see - * clRetainMemObject() and clReleaseMemObject(). - * - * \see cl_mem - */ -class Memory : public detail::Wrapper -{ -public: - //! \brief Default constructor - initializes to NULL. - Memory() : detail::Wrapper() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * This effectively transfers ownership of a refcount on the cl_mem - * into the new Memory object. - */ - __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper(memory) { } - - /*! \brief Assignment operator from cl_mem - takes ownership. - * - * This effectively transfers ownership of a refcount on the rhs and calls - * clReleaseMemObject() on the value previously held by this instance. - */ - Memory& operator = (const cl_mem& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Memory(const Memory& mem) : detail::Wrapper(mem) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Memory& operator = (const Memory &mem) - { - detail::Wrapper::operator=(mem); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Memory(Memory&& mem) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(mem)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Memory& operator = (Memory &&mem) - { - detail::Wrapper::operator=(std::move(mem)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - //! \brief Wrapper for clGetMemObjectInfo(). - template - cl_int getInfo(cl_mem_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetMemObjectInfo, object_, name, param), - __GET_MEM_OBJECT_INFO_ERR); - } - - //! \brief Wrapper for clGetMemObjectInfo() that returns by value. - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_mem_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - -#if defined(CL_VERSION_1_1) - /*! \brief Registers a callback function to be called when the memory object - * is no longer needed. - * - * Wraps clSetMemObjectDestructorCallback(). - * - * Repeated calls to this function, for a given cl_mem value, will append - * to the list of functions called (in reverse order) when memory object's - * resources are freed and the memory object is deleted. - * - * \note - * The registered callbacks are associated with the underlying cl_mem - * value - not the Memory class instance. - */ - cl_int setDestructorCallback( - void (CL_CALLBACK * pfn_notify)(cl_mem, void *), - void * user_data = NULL) - { - return detail::errHandler( - ::clSetMemObjectDestructorCallback( - object_, - pfn_notify, - user_data), - __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR); - } -#endif - -}; - -// Pre-declare copy functions -class Buffer; -template< typename IteratorType > -cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); -template< typename IteratorType > -cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); -template< typename IteratorType > -cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ); -template< typename IteratorType > -cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ); - - -/*! \brief Class interface for Buffer Memory Objects. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - */ -class Buffer : public Memory -{ -public: - - /*! \brief Constructs a Buffer in a specified context. - * - * Wraps clCreateBuffer(). - * - * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was - * specified. Note alignment & exclusivity requirements. - */ - Buffer( - const Context& context, - cl_mem_flags flags, - ::size_t size, - void* host_ptr = NULL, - cl_int* err = NULL) - { - cl_int error; - object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); - - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - } - - /*! \brief Constructs a Buffer in the default context. - * - * Wraps clCreateBuffer(). - * - * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was - * specified. Note alignment & exclusivity requirements. - * - * \see Context::getDefault() - */ - Buffer( - cl_mem_flags flags, - ::size_t size, - void* host_ptr = NULL, - cl_int* err = NULL) - { - cl_int error; - - Context context = Context::getDefault(err); - - object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error); - - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - } - - /*! - * \brief Construct a Buffer from a host container via iterators. - * IteratorType must be random access. - * If useHostPtr is specified iterators must represent contiguous data. - */ - template< typename IteratorType > - Buffer( - IteratorType startIterator, - IteratorType endIterator, - bool readOnly, - bool useHostPtr = false, - cl_int* err = NULL) - { - typedef typename std::iterator_traits::value_type DataType; - cl_int error; - - cl_mem_flags flags = 0; - if( readOnly ) { - flags |= CL_MEM_READ_ONLY; - } - else { - flags |= CL_MEM_READ_WRITE; - } - if( useHostPtr ) { - flags |= CL_MEM_USE_HOST_PTR; - } - - ::size_t size = sizeof(DataType)*(endIterator - startIterator); - - Context context = Context::getDefault(err); - - if( useHostPtr ) { - object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); - } else { - object_ = ::clCreateBuffer(context(), flags, size, 0, &error); - } - - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - - if( !useHostPtr ) { - error = cl::copy(startIterator, endIterator, *this); - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - } - } - - /*! - * \brief Construct a Buffer from a host container via iterators using a specified context. - * IteratorType must be random access. - * If useHostPtr is specified iterators must represent contiguous data. - */ - template< typename IteratorType > - Buffer(const Context &context, IteratorType startIterator, IteratorType endIterator, - bool readOnly, bool useHostPtr = false, cl_int* err = NULL); - - /*! - * \brief Construct a Buffer from a host container via iterators using a specified queue. - * If useHostPtr is specified iterators must represent contiguous data. - */ - template< typename IteratorType > - Buffer(const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, - bool readOnly, bool useHostPtr = false, cl_int* err = NULL); - - //! \brief Default constructor - initializes to NULL. - Buffer() : Memory() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - Buffer& operator = (const cl_mem& rhs) - { - Memory::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Buffer(const Buffer& buf) : Memory(buf) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Buffer& operator = (const Buffer &buf) - { - Memory::operator=(buf); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Buffer(Buffer&& buf) CL_HPP_NOEXCEPT : Memory(std::move(buf)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Buffer& operator = (Buffer &&buf) - { - Memory::operator=(std::move(buf)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - -#if defined(CL_VERSION_1_1) - /*! \brief Creates a new buffer object from this. - * - * Wraps clCreateSubBuffer(). - */ - Buffer createSubBuffer( - cl_mem_flags flags, - cl_buffer_create_type buffer_create_type, - const void * buffer_create_info, - cl_int * err = NULL) - { - Buffer result; - cl_int error; - result.object_ = ::clCreateSubBuffer( - object_, - flags, - buffer_create_type, - buffer_create_info, - &error); - - detail::errHandler(error, __CREATE_SUBBUFFER_ERR); - if (err != NULL) { - *err = error; - } - - return result; - } -#endif -}; - -#if defined (USE_DX_INTEROP) -/*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's. - * - * This is provided to facilitate interoperability with Direct3D. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - */ -class BufferD3D10 : public Buffer -{ -public: - typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)( - cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer, - cl_int* errcode_ret); - - /*! \brief Constructs a BufferD3D10, in a specified context, from a - * given ID3D10Buffer. - * - * Wraps clCreateFromD3D10BufferKHR(). - */ - BufferD3D10( - const Context& context, - cl_mem_flags flags, - ID3D10Buffer* bufobj, - cl_int * err = NULL) - { - static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL; - -#if defined(CL_VERSION_1_2) - vector props = context.getInfo(); - cl_platform platform = -1; - for( int i = 0; i < props.size(); ++i ) { - if( props[i] == CL_CONTEXT_PLATFORM ) { - platform = props[i+1]; - } - } - __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR); -#endif -#if defined(CL_VERSION_1_1) - __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR); -#endif - - cl_int error; - object_ = pfn_clCreateFromD3D10BufferKHR( - context(), - flags, - bufobj, - &error); - - detail::errHandler(error, __CREATE_GL_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - } - - //! \brief Default constructor - initializes to NULL. - BufferD3D10() : Buffer() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - BufferD3D10& operator = (const cl_mem& rhs) - { - Buffer::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - BufferD3D10(const BufferD3D10& buf) : Buffer(buf) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - BufferD3D10& operator = (const BufferD3D10 &buf) - { - Buffer::operator=(buf); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - BufferD3D10(BufferD3D10&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - BufferD3D10& operator = (BufferD3D10 &&buf) - { - Buffer::operator=(std::move(buf)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; -#endif - -/*! \brief Class interface for GL Buffer Memory Objects. - * - * This is provided to facilitate interoperability with OpenGL. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - */ -class BufferGL : public Buffer -{ -public: - /*! \brief Constructs a BufferGL in a specified context, from a given - * GL buffer. - * - * Wraps clCreateFromGLBuffer(). - */ - BufferGL( - const Context& context, - cl_mem_flags flags, - cl_GLuint bufobj, - cl_int * err = NULL) - { - cl_int error; - object_ = ::clCreateFromGLBuffer( - context(), - flags, - bufobj, - &error); - - detail::errHandler(error, __CREATE_GL_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - } - - //! \brief Default constructor - initializes to NULL. - BufferGL() : Buffer() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - BufferGL& operator = (const cl_mem& rhs) - { - Buffer::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - BufferGL(const BufferGL& buf) : Buffer(buf) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - BufferGL& operator = (const BufferGL &buf) - { - Buffer::operator=(buf); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - BufferGL(BufferGL&& buf) CL_HPP_NOEXCEPT : Buffer(std::move(buf)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - BufferGL& operator = (BufferGL &&buf) - { - Buffer::operator=(std::move(buf)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - //! \brief Wrapper for clGetGLObjectInfo(). - cl_int getObjectInfo( - cl_gl_object_type *type, - cl_GLuint * gl_object_name) - { - return detail::errHandler( - ::clGetGLObjectInfo(object_,type,gl_object_name), - __GET_GL_OBJECT_INFO_ERR); - } -}; - -/*! \brief C++ base class for Image Memory objects. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - */ -class Image : public Memory -{ -protected: - //! \brief Default constructor - initializes to NULL. - Image() : Memory() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - Image& operator = (const cl_mem& rhs) - { - Memory::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image(const Image& img) : Memory(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image& operator = (const Image &img) - { - Memory::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image(Image&& img) CL_HPP_NOEXCEPT : Memory(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image& operator = (Image &&img) - { - Memory::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - -public: - //! \brief Wrapper for clGetImageInfo(). - template - cl_int getImageInfo(cl_image_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetImageInfo, object_, name, param), - __GET_IMAGE_INFO_ERR); - } - - //! \brief Wrapper for clGetImageInfo() that returns by value. - template typename - detail::param_traits::param_type - getImageInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_image_info, name>::param_type param; - cl_int result = getImageInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } -}; - -#if defined(CL_VERSION_1_2) -/*! \brief Class interface for 1D Image Memory objects. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - */ -class Image1D : public Image -{ -public: - /*! \brief Constructs a 1D Image in a specified context. - * - * Wraps clCreateImage(). - */ - Image1D( - const Context& context, - cl_mem_flags flags, - ImageFormat format, - ::size_t width, - void* host_ptr = NULL, - cl_int* err = NULL) - { - cl_int error; - cl_image_desc desc = - { - CL_MEM_OBJECT_IMAGE1D, - width, - 0, 0, 0, 0, 0, 0, 0, 0 - }; - object_ = ::clCreateImage( - context(), - flags, - &format, - &desc, - host_ptr, - &error); - - detail::errHandler(error, __CREATE_IMAGE_ERR); - if (err != NULL) { - *err = error; - } - } - - //! \brief Default constructor - initializes to NULL. - Image1D() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - Image1D& operator = (const cl_mem& rhs) - { - Image::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image1D(const Image1D& img) : Image(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image1D& operator = (const Image1D &img) - { - Image::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image1D(Image1D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image1D& operator = (Image1D &&img) - { - Image::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; - -/*! \class Image1DBuffer - * \brief Image interface for 1D buffer images. - */ -class Image1DBuffer : public Image -{ -public: - Image1DBuffer( - const Context& context, - cl_mem_flags flags, - ImageFormat format, - ::size_t width, - const Buffer &buffer, - cl_int* err = NULL) - { - cl_int error; - cl_image_desc desc = - { - CL_MEM_OBJECT_IMAGE1D_BUFFER, - width, - 0, 0, 0, 0, 0, 0, 0, - buffer() - }; - object_ = ::clCreateImage( - context(), - flags, - &format, - &desc, - NULL, - &error); - - detail::errHandler(error, __CREATE_IMAGE_ERR); - if (err != NULL) { - *err = error; - } - } - - Image1DBuffer() { } - - __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { } - - Image1DBuffer& operator = (const cl_mem& rhs) - { - Image::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image1DBuffer(const Image1DBuffer& img) : Image(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image1DBuffer& operator = (const Image1DBuffer &img) - { - Image::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image1DBuffer(Image1DBuffer&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image1DBuffer& operator = (Image1DBuffer &&img) - { - Image::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; - -/*! \class Image1DArray - * \brief Image interface for arrays of 1D images. - */ -class Image1DArray : public Image -{ -public: - Image1DArray( - const Context& context, - cl_mem_flags flags, - ImageFormat format, - ::size_t arraySize, - ::size_t width, - ::size_t rowPitch, - void* host_ptr = NULL, - cl_int* err = NULL) - { - cl_int error; - cl_image_desc desc = - { - CL_MEM_OBJECT_IMAGE1D_ARRAY, - width, - 0, 0, // height, depth (unused) - arraySize, - rowPitch, - 0, 0, 0, 0 - }; - object_ = ::clCreateImage( - context(), - flags, - &format, - &desc, - host_ptr, - &error); - - detail::errHandler(error, __CREATE_IMAGE_ERR); - if (err != NULL) { - *err = error; - } - } - - Image1DArray() { } - - __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { } - - Image1DArray& operator = (const cl_mem& rhs) - { - Image::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image1DArray(const Image1DArray& img) : Image(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image1DArray& operator = (const Image1DArray &img) - { - Image::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image1DArray(Image1DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image1DArray& operator = (Image1DArray &&img) - { - Image::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; -#endif // #if defined(CL_VERSION_1_2) - - -/*! \brief Class interface for 2D Image Memory objects. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - */ -class Image2D : public Image -{ -public: - /*! \brief Constructs a 1D Image in a specified context. - * - * Wraps clCreateImage(). - */ - Image2D( - const Context& context, - cl_mem_flags flags, - ImageFormat format, - ::size_t width, - ::size_t height, - ::size_t row_pitch = 0, - void* host_ptr = NULL, - cl_int* err = NULL) - { - cl_int error; - bool useCreateImage; - -#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) - // Run-time decision based on the actual platform - { - cl_uint version = detail::getContextPlatformVersion(context()); - useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above - } -#elif defined(CL_VERSION_1_2) - useCreateImage = true; -#else - useCreateImage = false; -#endif - -#if defined(CL_VERSION_1_2) - if (useCreateImage) - { - cl_image_desc desc = - { - CL_MEM_OBJECT_IMAGE2D, - width, - height, - 0, 0, // depth, array size (unused) - row_pitch, - 0, 0, 0, 0 - }; - object_ = ::clCreateImage( - context(), - flags, - &format, - &desc, - host_ptr, - &error); - - detail::errHandler(error, __CREATE_IMAGE_ERR); - if (err != NULL) { - *err = error; - } - } -#endif // #if defined(CL_VERSION_1_2) -#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) - if (!useCreateImage) - { - object_ = ::clCreateImage2D( - context(), flags,&format, width, height, row_pitch, host_ptr, &error); - - detail::errHandler(error, __CREATE_IMAGE2D_ERR); - if (err != NULL) { - *err = error; - } - } -#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) - } - - //! \brief Default constructor - initializes to NULL. - Image2D() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - Image2D& operator = (const cl_mem& rhs) - { - Image::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image2D(const Image2D& img) : Image(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image2D& operator = (const Image2D &img) - { - Image::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image2D(Image2D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image2D& operator = (Image2D &&img) - { - Image::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; - - -#if !defined(CL_VERSION_1_2) -/*! \brief Class interface for GL 2D Image Memory objects. - * - * This is provided to facilitate interoperability with OpenGL. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - * \note Deprecated for OpenCL 1.2. Please use ImageGL instead. - */ -class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D -{ -public: - /*! \brief Constructs an Image2DGL in a specified context, from a given - * GL Texture. - * - * Wraps clCreateFromGLTexture2D(). - */ - Image2DGL( - const Context& context, - cl_mem_flags flags, - cl_GLenum target, - cl_GLint miplevel, - cl_GLuint texobj, - cl_int * err = NULL) - { - cl_int error; - object_ = ::clCreateFromGLTexture2D( - context(), - flags, - target, - miplevel, - texobj, - &error); - - detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR); - if (err != NULL) { - *err = error; - } - - } - - //! \brief Default constructor - initializes to NULL. - Image2DGL() : Image2D() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - Image2DGL& operator = (const cl_mem& rhs) - { - Image2D::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image2DGL(const Image2DGL& img) : Image2D(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image2DGL& operator = (const Image2DGL &img) - { - Image2D::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image2DGL(Image2DGL&& img) CL_HPP_NOEXCEPT : Image2D(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image2DGL& operator = (Image2DGL &&img) - { - Image2D::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; -#endif // #if !defined(CL_VERSION_1_2) - -#if defined(CL_VERSION_1_2) -/*! \class Image2DArray - * \brief Image interface for arrays of 2D images. - */ -class Image2DArray : public Image -{ -public: - Image2DArray( - const Context& context, - cl_mem_flags flags, - ImageFormat format, - ::size_t arraySize, - ::size_t width, - ::size_t height, - ::size_t rowPitch, - ::size_t slicePitch, - void* host_ptr = NULL, - cl_int* err = NULL) - { - cl_int error; - cl_image_desc desc = - { - CL_MEM_OBJECT_IMAGE2D_ARRAY, - width, - height, - 0, // depth (unused) - arraySize, - rowPitch, - slicePitch, - 0, 0, 0 - }; - object_ = ::clCreateImage( - context(), - flags, - &format, - &desc, - host_ptr, - &error); - - detail::errHandler(error, __CREATE_IMAGE_ERR); - if (err != NULL) { - *err = error; - } - } - - Image2DArray() { } - - __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { } - - Image2DArray& operator = (const cl_mem& rhs) - { - Image::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image2DArray(const Image2DArray& img) : Image(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image2DArray& operator = (const Image2DArray &img) - { - Image::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image2DArray(Image2DArray&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image2DArray& operator = (Image2DArray &&img) - { - Image::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; -#endif // #if defined(CL_VERSION_1_2) - -/*! \brief Class interface for 3D Image Memory objects. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - */ -class Image3D : public Image -{ -public: - /*! \brief Constructs a 3D Image in a specified context. - * - * Wraps clCreateImage(). - */ - Image3D( - const Context& context, - cl_mem_flags flags, - ImageFormat format, - ::size_t width, - ::size_t height, - ::size_t depth, - ::size_t row_pitch = 0, - ::size_t slice_pitch = 0, - void* host_ptr = NULL, - cl_int* err = NULL) - { - cl_int error; - bool useCreateImage; - -#if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) - // Run-time decision based on the actual platform - { - cl_uint version = detail::getContextPlatformVersion(context()); - useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above - } -#elif defined(CL_VERSION_1_2) - useCreateImage = true; -#else - useCreateImage = false; -#endif - -#if defined(CL_VERSION_1_2) - if (useCreateImage) - { - cl_image_desc desc = - { - CL_MEM_OBJECT_IMAGE3D, - width, - height, - depth, - 0, // array size (unused) - row_pitch, - slice_pitch, - 0, 0, 0 - }; - object_ = ::clCreateImage( - context(), - flags, - &format, - &desc, - host_ptr, - &error); - - detail::errHandler(error, __CREATE_IMAGE_ERR); - if (err != NULL) { - *err = error; - } - } -#endif // #if defined(CL_VERSION_1_2) -#if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) - if (!useCreateImage) - { - object_ = ::clCreateImage3D( - context(), flags, &format, width, height, depth, row_pitch, - slice_pitch, host_ptr, &error); - - detail::errHandler(error, __CREATE_IMAGE3D_ERR); - if (err != NULL) { - *err = error; - } - } -#endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) - } - - //! \brief Default constructor - initializes to NULL. - Image3D() : Image() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - Image3D& operator = (const cl_mem& rhs) - { - Image::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image3D(const Image3D& img) : Image(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image3D& operator = (const Image3D &img) - { - Image::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image3D(Image3D&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image3D& operator = (Image3D &&img) - { - Image::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; - -#if !defined(CL_VERSION_1_2) -/*! \brief Class interface for GL 3D Image Memory objects. - * - * This is provided to facilitate interoperability with OpenGL. - * - * See Memory for details about copy semantics, etc. - * - * \see Memory - */ -class Image3DGL : public Image3D -{ -public: - /*! \brief Constructs an Image3DGL in a specified context, from a given - * GL Texture. - * - * Wraps clCreateFromGLTexture3D(). - */ - Image3DGL( - const Context& context, - cl_mem_flags flags, - cl_GLenum target, - cl_GLint miplevel, - cl_GLuint texobj, - cl_int * err = NULL) - { - cl_int error; - object_ = ::clCreateFromGLTexture3D( - context(), - flags, - target, - miplevel, - texobj, - &error); - - detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR); - if (err != NULL) { - *err = error; - } - } - - //! \brief Default constructor - initializes to NULL. - Image3DGL() : Image3D() { } - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ - __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { } - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - Image3DGL& operator = (const cl_mem& rhs) - { - Image3D::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image3DGL(const Image3DGL& img) : Image3D(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Image3DGL& operator = (const Image3DGL &img) - { - Image3D::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Image3DGL(Image3DGL&& img) CL_HPP_NOEXCEPT : Image3D(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Image3DGL& operator = (Image3DGL &&img) - { - Image3D::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; -#endif // #if !defined(CL_VERSION_1_2) - -#if defined(CL_VERSION_1_2) -/*! \class ImageGL - * \brief general image interface for GL interop. - * We abstract the 2D and 3D GL images into a single instance here - * that wraps all GL sourced images on the grounds that setup information - * was performed by OpenCL anyway. - */ -class ImageGL : public Image -{ -public: - ImageGL( - const Context& context, - cl_mem_flags flags, - cl_GLenum target, - cl_GLint miplevel, - cl_GLuint texobj, - cl_int * err = NULL) - { - cl_int error; - object_ = ::clCreateFromGLTexture( - context(), - flags, - target, - miplevel, - texobj, - &error); - - detail::errHandler(error, __CREATE_GL_TEXTURE_ERR); - if (err != NULL) { - *err = error; - } - } - - ImageGL() : Image() { } - - __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { } - - ImageGL& operator = (const cl_mem& rhs) - { - Image::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - ImageGL(const ImageGL& img) : Image(img) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - ImageGL& operator = (const ImageGL &img) - { - Image::operator=(img); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - ImageGL(ImageGL&& img) CL_HPP_NOEXCEPT : Image(std::move(img)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - ImageGL& operator = (ImageGL &&img) - { - Image::operator=(std::move(img)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) -}; -#endif // #if defined(CL_VERSION_1_2) - -/*! \brief Class interface for GL Render Buffer Memory Objects. -* -* This is provided to facilitate interoperability with OpenGL. -* -* See Memory for details about copy semantics, etc. -* -* \see Memory -*/ -class BufferRenderGL : -#if defined(CL_VERSION_1_2) - public ImageGL -#else // #if defined(CL_VERSION_1_2) - public Image2DGL -#endif //#if defined(CL_VERSION_1_2) -{ -public: - /*! \brief Constructs a BufferRenderGL in a specified context, from a given - * GL Renderbuffer. - * - * Wraps clCreateFromGLRenderbuffer(). - */ - BufferRenderGL( - const Context& context, - cl_mem_flags flags, - cl_GLuint bufobj, - cl_int * err = NULL) - { - cl_int error; - object_ = ::clCreateFromGLRenderbuffer( - context(), - flags, - bufobj, - &error); - - detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - } - - //! \brief Default constructor - initializes to NULL. -#if defined(CL_VERSION_1_2) - BufferRenderGL() : ImageGL() {}; -#else // #if defined(CL_VERSION_1_2) - BufferRenderGL() : Image2DGL() {}; -#endif //#if defined(CL_VERSION_1_2) - - /*! \brief Constructor from cl_mem - takes ownership. - * - * See Memory for further details. - */ -#if defined(CL_VERSION_1_2) - __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : ImageGL(buffer) { } -#else // #if defined(CL_VERSION_1_2) - __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Image2DGL(buffer) { } -#endif //#if defined(CL_VERSION_1_2) - - - /*! \brief Assignment from cl_mem - performs shallow copy. - * - * See Memory for further details. - */ - BufferRenderGL& operator = (const cl_mem& rhs) - { -#if defined(CL_VERSION_1_2) - ImageGL::operator=(rhs); -#else // #if defined(CL_VERSION_1_2) - Image2DGL::operator=(rhs); -#endif //#if defined(CL_VERSION_1_2) - - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ -#if defined(CL_VERSION_1_2) - BufferRenderGL(const BufferRenderGL& buf) : ImageGL(buf) {} -#else // #if defined(CL_VERSION_1_2) - BufferRenderGL(const BufferRenderGL& buf) : Image2DGL(buf) {} -#endif //#if defined(CL_VERSION_1_2) - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - BufferRenderGL& operator = (const BufferRenderGL &rhs) - { -#if defined(CL_VERSION_1_2) - ImageGL::operator=(rhs); -#else // #if defined(CL_VERSION_1_2) - Image2DGL::operator=(rhs); -#endif //#if defined(CL_VERSION_1_2) - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ -#if defined(CL_VERSION_1_2) - BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : ImageGL(std::move(buf)) {} -#else // #if defined(CL_VERSION_1_2) - BufferRenderGL(BufferRenderGL&& buf) CL_HPP_NOEXCEPT : Image2DGL(std::move(buf)) {} -#endif //#if defined(CL_VERSION_1_2) - - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - BufferRenderGL& operator = (BufferRenderGL &&buf) - { -#if defined(CL_VERSION_1_2) - ImageGL::operator=(std::move(buf)); -#else // #if defined(CL_VERSION_1_2) - Image2DGL::operator=(std::move(buf)); -#endif //#if defined(CL_VERSION_1_2) - - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - //! \brief Wrapper for clGetGLObjectInfo(). - cl_int getObjectInfo( - cl_gl_object_type *type, - cl_GLuint * gl_object_name) - { - return detail::errHandler( - ::clGetGLObjectInfo(object_, type, gl_object_name), - __GET_GL_OBJECT_INFO_ERR); - } -}; - -/*! \brief Class interface for cl_sampler. - * - * \note Copies of these objects are shallow, meaning that the copy will refer - * to the same underlying cl_sampler as the original. For details, see - * clRetainSampler() and clReleaseSampler(). - * - * \see cl_sampler - */ -class Sampler : public detail::Wrapper -{ -public: - //! \brief Default constructor - initializes to NULL. - Sampler() { } - - /*! \brief Constructs a Sampler in a specified context. - * - * Wraps clCreateSampler(). - */ - Sampler( - const Context& context, - cl_bool normalized_coords, - cl_addressing_mode addressing_mode, - cl_filter_mode filter_mode, - cl_int* err = NULL) - { - cl_int error; - object_ = ::clCreateSampler( - context(), - normalized_coords, - addressing_mode, - filter_mode, - &error); - - detail::errHandler(error, __CREATE_SAMPLER_ERR); - if (err != NULL) { - *err = error; - } - } - - /*! \brief Constructor from cl_sampler - takes ownership. - * - * This effectively transfers ownership of a refcount on the cl_sampler - * into the new Sampler object. - */ - __CL_EXPLICIT_CONSTRUCTORS Sampler(const cl_sampler& sampler) : detail::Wrapper(sampler) { } - - /*! \brief Assignment operator from cl_sampler - takes ownership. - * - * This effectively transfers ownership of a refcount on the rhs and calls - * clReleaseSampler() on the value previously held by this instance. - */ - Sampler& operator = (const cl_sampler& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Sampler(const Sampler& sam) : detail::Wrapper(sam) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Sampler& operator = (const Sampler &sam) - { - detail::Wrapper::operator=(sam); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Sampler(Sampler&& sam) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(sam)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Sampler& operator = (Sampler &&sam) - { - detail::Wrapper::operator=(std::move(sam)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - //! \brief Wrapper for clGetSamplerInfo(). - template - cl_int getInfo(cl_sampler_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetSamplerInfo, object_, name, param), - __GET_SAMPLER_INFO_ERR); - } - - //! \brief Wrapper for clGetSamplerInfo() that returns by value. - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_sampler_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } -}; - -class Program; -class CommandQueue; -class Kernel; - -//! \brief Class interface for specifying NDRange values. -class NDRange -{ -private: - size_t<3> sizes_; - cl_uint dimensions_; - -public: - //! \brief Default constructor - resulting range has zero dimensions. - NDRange() - : dimensions_(0) - { } - - //! \brief Constructs one-dimensional range. - NDRange(::size_t size0) - : dimensions_(1) - { - sizes_[0] = size0; - } - - //! \brief Constructs two-dimensional range. - NDRange(::size_t size0, ::size_t size1) - : dimensions_(2) - { - sizes_[0] = size0; - sizes_[1] = size1; - } - - //! \brief Constructs three-dimensional range. - NDRange(::size_t size0, ::size_t size1, ::size_t size2) - : dimensions_(3) - { - sizes_[0] = size0; - sizes_[1] = size1; - sizes_[2] = size2; - } - - /*! \brief Conversion operator to const ::size_t *. - * - * \returns a pointer to the size of the first dimension. - */ - operator const ::size_t*() const { - return (const ::size_t*) sizes_; - } - - //! \brief Queries the number of dimensions in the range. - ::size_t dimensions() const { return dimensions_; } -}; - -//! \brief A zero-dimensional range. -static const NDRange NullRange; - -//! \brief Local address wrapper for use with Kernel::setArg -struct LocalSpaceArg -{ - ::size_t size_; -}; - -namespace detail { - -template -struct KernelArgumentHandler -{ - static ::size_t size(const T&) { return sizeof(T); } - static const T* ptr(const T& value) { return &value; } -}; - -template <> -struct KernelArgumentHandler -{ - static ::size_t size(const LocalSpaceArg& value) { return value.size_; } - static const void* ptr(const LocalSpaceArg&) { return NULL; } -}; - -} -//! \endcond - -/*! __local - * \brief Helper function for generating LocalSpaceArg objects. - * Deprecated. Replaced with Local. - */ -inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg -__local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; -inline LocalSpaceArg -__local(::size_t size) -{ - LocalSpaceArg ret = { size }; - return ret; -} - -/*! Local - * \brief Helper function for generating LocalSpaceArg objects. - */ -inline LocalSpaceArg -Local(::size_t size) -{ - LocalSpaceArg ret = { size }; - return ret; -} - -//class KernelFunctor; - -/*! \brief Class interface for cl_kernel. - * - * \note Copies of these objects are shallow, meaning that the copy will refer - * to the same underlying cl_kernel as the original. For details, see - * clRetainKernel() and clReleaseKernel(). - * - * \see cl_kernel - */ -class Kernel : public detail::Wrapper -{ -public: - inline Kernel(const Program& program, const char* name, cl_int* err = NULL); - - //! \brief Default constructor - initializes to NULL. - Kernel() { } - - /*! \brief Constructor from cl_kernel - takes ownership. - * - * This effectively transfers ownership of a refcount on the cl_kernel - * into the new Kernel object. - */ - __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper(kernel) { } - - /*! \brief Assignment operator from cl_kernel - takes ownership. - * - * This effectively transfers ownership of a refcount on the rhs and calls - * clReleaseKernel() on the value previously held by this instance. - */ - Kernel& operator = (const cl_kernel& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Kernel(const Kernel& kernel) : detail::Wrapper(kernel) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Kernel& operator = (const Kernel &kernel) - { - detail::Wrapper::operator=(kernel); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Kernel(Kernel&& kernel) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(kernel)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Kernel& operator = (Kernel &&kernel) - { - detail::Wrapper::operator=(std::move(kernel)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - template - cl_int getInfo(cl_kernel_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetKernelInfo, object_, name, param), - __GET_KERNEL_INFO_ERR); - } - - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_kernel_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - -#if defined(CL_VERSION_1_2) - template - cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param), - __GET_KERNEL_ARG_INFO_ERR); - } - - template typename - detail::param_traits::param_type - getArgInfo(cl_uint argIndex, cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_kernel_arg_info, name>::param_type param; - cl_int result = getArgInfo(argIndex, name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } -#endif // #if defined(CL_VERSION_1_2) - - template - cl_int getWorkGroupInfo( - const Device& device, cl_kernel_work_group_info name, T* param) const - { - return detail::errHandler( - detail::getInfo( - &::clGetKernelWorkGroupInfo, object_, device(), name, param), - __GET_KERNEL_WORK_GROUP_INFO_ERR); - } - - template typename - detail::param_traits::param_type - getWorkGroupInfo(const Device& device, cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_kernel_work_group_info, name>::param_type param; - cl_int result = getWorkGroupInfo(device, name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - template - cl_int setArg(cl_uint index, const T &value) - { - return detail::errHandler( - ::clSetKernelArg( - object_, - index, - detail::KernelArgumentHandler::size(value), - detail::KernelArgumentHandler::ptr(value)), - __SET_KERNEL_ARGS_ERR); - } - - cl_int setArg(cl_uint index, ::size_t size, const void* argPtr) - { - return detail::errHandler( - ::clSetKernelArg(object_, index, size, argPtr), - __SET_KERNEL_ARGS_ERR); - } -}; - -/*! \class Program - * \brief Program interface that implements cl_program. - */ -class Program : public detail::Wrapper -{ -public: - typedef VECTOR_CLASS > Binaries; - typedef VECTOR_CLASS > Sources; - - Program( - const STRING_CLASS& source, - bool build = false, - cl_int* err = NULL) - { - cl_int error; - - const char * strings = source.c_str(); - const ::size_t length = source.size(); - - Context context = Context::getDefault(err); - - object_ = ::clCreateProgramWithSource( - context(), (cl_uint)1, &strings, &length, &error); - - detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); - - if (error == CL_SUCCESS && build) { - - error = ::clBuildProgram( - object_, - 0, - NULL, - "", - NULL, - NULL); - - detail::errHandler(error, __BUILD_PROGRAM_ERR); - } - - if (err != NULL) { - *err = error; - } - } - - Program( - const Context& context, - const STRING_CLASS& source, - bool build = false, - cl_int* err = NULL) - { - cl_int error; - - const char * strings = source.c_str(); - const ::size_t length = source.size(); - - object_ = ::clCreateProgramWithSource( - context(), (cl_uint)1, &strings, &length, &error); - - detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); - - if (error == CL_SUCCESS && build) { - - error = ::clBuildProgram( - object_, - 0, - NULL, - "", - NULL, - NULL); - - detail::errHandler(error, __BUILD_PROGRAM_ERR); - } - - if (err != NULL) { - *err = error; - } - } - - Program( - const Context& context, - const Sources& sources, - cl_int* err = NULL) - { - cl_int error; - - const ::size_t n = (::size_t)sources.size(); - ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t)); - const char** strings = (const char**) alloca(n * sizeof(const char*)); - - for (::size_t i = 0; i < n; ++i) { - strings[i] = sources[(int)i].first; - lengths[i] = sources[(int)i].second; - } - - object_ = ::clCreateProgramWithSource( - context(), (cl_uint)n, strings, lengths, &error); - - detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR); - if (err != NULL) { - *err = error; - } - } - - /** - * Construct a program object from a list of devices and a per-device list of binaries. - * \param context A valid OpenCL context in which to construct the program. - * \param devices A vector of OpenCL device objects for which the program will be created. - * \param binaries A vector of pairs of a pointer to a binary object and its length. - * \param binaryStatus An optional vector that on completion will be resized to - * match the size of binaries and filled with values to specify if each binary - * was successfully loaded. - * Set to CL_SUCCESS if the binary was successfully loaded. - * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL. - * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device. - * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors: - * CL_INVALID_CONTEXT if context is not a valid context. - * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices; - * or if any entry in binaries is NULL or has length 0. - * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context. - * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device. - * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host. - */ - Program( - const Context& context, - const VECTOR_CLASS& devices, - const Binaries& binaries, - VECTOR_CLASS* binaryStatus = NULL, - cl_int* err = NULL) - { - cl_int error; - - const ::size_t numDevices = devices.size(); - - // Catch size mismatch early and return - if(binaries.size() != numDevices) { - error = CL_INVALID_VALUE; - detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); - if (err != NULL) { - *err = error; - } - return; - } - - ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t)); - const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**)); - - for (::size_t i = 0; i < numDevices; ++i) { - images[i] = (const unsigned char*)binaries[i].first; - lengths[i] = binaries[(int)i].second; - } - - cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); - for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { - deviceIDs[deviceIndex] = (devices[deviceIndex])(); - } - - if(binaryStatus) { - binaryStatus->resize(numDevices); - } - - object_ = ::clCreateProgramWithBinary( - context(), (cl_uint) devices.size(), - deviceIDs, - lengths, images, (binaryStatus != NULL && numDevices > 0) - ? &binaryStatus->front() - : NULL, &error); - - detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR); - if (err != NULL) { - *err = error; - } - } - - -#if defined(CL_VERSION_1_2) - /** - * Create program using builtin kernels. - * \param kernelNames Semi-colon separated list of builtin kernel names - */ - Program( - const Context& context, - const VECTOR_CLASS& devices, - const STRING_CLASS& kernelNames, - cl_int* err = NULL) - { - cl_int error; - - - ::size_t numDevices = devices.size(); - cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); - for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { - deviceIDs[deviceIndex] = (devices[deviceIndex])(); - } - - object_ = ::clCreateProgramWithBuiltInKernels( - context(), - (cl_uint) devices.size(), - deviceIDs, - kernelNames.c_str(), - &error); - - detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR); - if (err != NULL) { - *err = error; - } - } -#endif // #if defined(CL_VERSION_1_2) - - Program() { } - - __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper(program) { } - - Program& operator = (const cl_program& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - Program(const Program& program) : detail::Wrapper(program) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - Program& operator = (const Program &program) - { - detail::Wrapper::operator=(program); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - Program(Program&& program) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(program)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - Program& operator = (Program &&program) - { - detail::Wrapper::operator=(std::move(program)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - cl_int build( - const VECTOR_CLASS& devices, - const char* options = NULL, - void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, - void* data = NULL) const - { - ::size_t numDevices = devices.size(); - cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id)); - for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) { - deviceIDs[deviceIndex] = (devices[deviceIndex])(); - } - - return detail::errHandler( - ::clBuildProgram( - object_, - (cl_uint) - devices.size(), - deviceIDs, - options, - notifyFptr, - data), - __BUILD_PROGRAM_ERR); - } - - cl_int build( - const char* options = NULL, - void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, - void* data = NULL) const - { - return detail::errHandler( - ::clBuildProgram( - object_, - 0, - NULL, - options, - notifyFptr, - data), - __BUILD_PROGRAM_ERR); - } - -#if defined(CL_VERSION_1_2) - cl_int compile( - const char* options = NULL, - void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, - void* data = NULL) const - { - return detail::errHandler( - ::clCompileProgram( - object_, - 0, - NULL, - options, - 0, - NULL, - NULL, - notifyFptr, - data), - __COMPILE_PROGRAM_ERR); - } -#endif - - template - cl_int getInfo(cl_program_info name, T* param) const - { - return detail::errHandler( - detail::getInfo(&::clGetProgramInfo, object_, name, param), - __GET_PROGRAM_INFO_ERR); - } - - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_program_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - template - cl_int getBuildInfo( - const Device& device, cl_program_build_info name, T* param) const - { - return detail::errHandler( - detail::getInfo( - &::clGetProgramBuildInfo, object_, device(), name, param), - __GET_PROGRAM_BUILD_INFO_ERR); - } - - template typename - detail::param_traits::param_type - getBuildInfo(const Device& device, cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_program_build_info, name>::param_type param; - cl_int result = getBuildInfo(device, name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - cl_int createKernels(VECTOR_CLASS* kernels) - { - cl_uint numKernels; - cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); - } - - Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel)); - err = ::clCreateKernelsInProgram( - object_, numKernels, (cl_kernel*) value, NULL); - if (err != CL_SUCCESS) { - return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR); - } - - kernels->assign(&value[0], &value[numKernels]); - return CL_SUCCESS; - } -}; - -#if defined(CL_VERSION_1_2) -inline Program linkProgram( - Program input1, - Program input2, - const char* options = NULL, - void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, - void* data = NULL, - cl_int* err = NULL) -{ - cl_int error_local = CL_SUCCESS; - - cl_program programs[2] = { input1(), input2() }; - - Context ctx = input1.getInfo(&error_local); - if(error_local!=CL_SUCCESS) { - detail::errHandler(error_local, __LINK_PROGRAM_ERR); - } - - cl_program prog = ::clLinkProgram( - ctx(), - 0, - NULL, - options, - 2, - programs, - notifyFptr, - data, - &error_local); - - detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); - if (err != NULL) { - *err = error_local; - } - - return Program(prog); -} - -inline Program linkProgram( - VECTOR_CLASS inputPrograms, - const char* options = NULL, - void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL, - void* data = NULL, - cl_int* err = NULL) -{ - cl_int error_local = CL_SUCCESS; - - cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program)); - - if (programs != NULL) { - for (unsigned int i = 0; i < inputPrograms.size(); i++) { - programs[i] = inputPrograms[i](); - } - } - - Context ctx; - if(inputPrograms.size() > 0) { - ctx = inputPrograms[0].getInfo(&error_local); - if(error_local!=CL_SUCCESS) { - detail::errHandler(error_local, __LINK_PROGRAM_ERR); - } - } - cl_program prog = ::clLinkProgram( - ctx(), - 0, - NULL, - options, - (cl_uint)inputPrograms.size(), - programs, - notifyFptr, - data, - &error_local); - - detail::errHandler(error_local,__COMPILE_PROGRAM_ERR); - if (err != NULL) { - *err = error_local; - } - - return Program(prog); -} -#endif - -template<> -inline VECTOR_CLASS cl::Program::getInfo(cl_int* err) const -{ - VECTOR_CLASS< ::size_t> sizes = getInfo(); - VECTOR_CLASS binaries; - for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s) - { - char *ptr = NULL; - if (*s != 0) - ptr = new char[*s]; - binaries.push_back(ptr); - } - - cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries); - if (err != NULL) { - *err = result; - } - return binaries; -} - -inline Kernel::Kernel(const Program& program, const char* name, cl_int* err) -{ - cl_int error; - - object_ = ::clCreateKernel(program(), name, &error); - detail::errHandler(error, __CREATE_KERNEL_ERR); - - if (err != NULL) { - *err = error; - } - -} - -/*! \class CommandQueue - * \brief CommandQueue interface for cl_command_queue. - */ -class CommandQueue : public detail::Wrapper -{ -private: -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED - static std::atomic default_initialized_; -#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED - static volatile int default_initialized_; -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED - static CommandQueue default_; - static volatile cl_int default_error_; -public: - CommandQueue( - cl_command_queue_properties properties, - cl_int* err = NULL) - { - cl_int error; - - Context context = Context::getDefault(&error); - detail::errHandler(error, __CREATE_CONTEXT_ERR); - - if (error != CL_SUCCESS) { - if (err != NULL) { - *err = error; - } - } - else { - Device device = context.getInfo()[0]; - - object_ = ::clCreateCommandQueue( - context(), device(), properties, &error); - - detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); - if (err != NULL) { - *err = error; - } - } - } - /*! - * \brief Constructs a CommandQueue for an implementation defined device in the given context - */ - explicit CommandQueue( - const Context& context, - cl_command_queue_properties properties = 0, - cl_int* err = NULL) - { - cl_int error; - VECTOR_CLASS devices; - error = context.getInfo(CL_CONTEXT_DEVICES, &devices); - - detail::errHandler(error, __CREATE_CONTEXT_ERR); - - if (error != CL_SUCCESS) - { - if (err != NULL) { - *err = error; - } - return; - } - - object_ = ::clCreateCommandQueue(context(), devices[0](), properties, &error); - - detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); - - if (err != NULL) { - *err = error; - } - - } - - CommandQueue( - const Context& context, - const Device& device, - cl_command_queue_properties properties = 0, - cl_int* err = NULL) - { - cl_int error; - object_ = ::clCreateCommandQueue( - context(), device(), properties, &error); - - detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); - if (err != NULL) { - *err = error; - } - } - - /*! \brief Copy constructor to forward copy to the superclass correctly. - * Required for MSVC. - */ - CommandQueue(const CommandQueue& queue) : detail::Wrapper(queue) {} - - /*! \brief Copy assignment to forward copy to the superclass correctly. - * Required for MSVC. - */ - CommandQueue& operator = (const CommandQueue &queue) - { - detail::Wrapper::operator=(queue); - return *this; - } - -#if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - /*! \brief Move constructor to forward move to the superclass correctly. - * Required for MSVC. - */ - CommandQueue(CommandQueue&& queue) CL_HPP_NOEXCEPT : detail::Wrapper(std::move(queue)) {} - - /*! \brief Move assignment to forward move to the superclass correctly. - * Required for MSVC. - */ - CommandQueue& operator = (CommandQueue &&queue) - { - detail::Wrapper::operator=(std::move(queue)); - return *this; - } -#endif // #if defined(CL_HPP_RVALUE_REFERENCES_SUPPORTED) - - static CommandQueue getDefault(cl_int * err = NULL) - { - int state = detail::compare_exchange( - &default_initialized_, - __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED); - - if (state & __DEFAULT_INITIALIZED) { - if (err != NULL) { - *err = default_error_; - } - return default_; - } - - if (state & __DEFAULT_BEING_INITIALIZED) { - // Assume writes will propagate eventually... - while(default_initialized_ != __DEFAULT_INITIALIZED) { - detail::fence(); - } - - if (err != NULL) { - *err = default_error_; - } - return default_; - } - - cl_int error; - - Context context = Context::getDefault(&error); - detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); - - if (error != CL_SUCCESS) { - if (err != NULL) { - *err = error; - } - } - else { - Device device = context.getInfo()[0]; - - default_ = CommandQueue(context, device, 0, &error); - - detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR); - if (err != NULL) { - *err = error; - } - } - - detail::fence(); - - default_error_ = error; - // Assume writes will propagate eventually... - default_initialized_ = __DEFAULT_INITIALIZED; - - detail::fence(); - - if (err != NULL) { - *err = default_error_; - } - return default_; - - } - - CommandQueue() { } - - __CL_EXPLICIT_CONSTRUCTORS CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper(commandQueue) { } - - CommandQueue& operator = (const cl_command_queue& rhs) - { - detail::Wrapper::operator=(rhs); - return *this; - } - - template - cl_int getInfo(cl_command_queue_info name, T* param) const - { - return detail::errHandler( - detail::getInfo( - &::clGetCommandQueueInfo, object_, name, param), - __GET_COMMAND_QUEUE_INFO_ERR); - } - - template typename - detail::param_traits::param_type - getInfo(cl_int* err = NULL) const - { - typename detail::param_traits< - detail::cl_command_queue_info, name>::param_type param; - cl_int result = getInfo(name, ¶m); - if (err != NULL) { - *err = result; - } - return param; - } - - cl_int enqueueReadBuffer( - const Buffer& buffer, - cl_bool blocking, - ::size_t offset, - ::size_t size, - void* ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueReadBuffer( - object_, buffer(), blocking, offset, size, - ptr, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_READ_BUFFER_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueWriteBuffer( - const Buffer& buffer, - cl_bool blocking, - ::size_t offset, - ::size_t size, - const void* ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueWriteBuffer( - object_, buffer(), blocking, offset, size, - ptr, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_WRITE_BUFFER_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueCopyBuffer( - const Buffer& src, - const Buffer& dst, - ::size_t src_offset, - ::size_t dst_offset, - ::size_t size, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueCopyBuffer( - object_, src(), dst(), src_offset, dst_offset, size, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQEUE_COPY_BUFFER_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueReadBufferRect( - const Buffer& buffer, - cl_bool blocking, - const size_t<3>& buffer_offset, - const size_t<3>& host_offset, - const size_t<3>& region, - ::size_t buffer_row_pitch, - ::size_t buffer_slice_pitch, - ::size_t host_row_pitch, - ::size_t host_slice_pitch, - void *ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueReadBufferRect( - object_, - buffer(), - blocking, - (const ::size_t *)buffer_offset, - (const ::size_t *)host_offset, - (const ::size_t *)region, - buffer_row_pitch, - buffer_slice_pitch, - host_row_pitch, - host_slice_pitch, - ptr, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_READ_BUFFER_RECT_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueWriteBufferRect( - const Buffer& buffer, - cl_bool blocking, - const size_t<3>& buffer_offset, - const size_t<3>& host_offset, - const size_t<3>& region, - ::size_t buffer_row_pitch, - ::size_t buffer_slice_pitch, - ::size_t host_row_pitch, - ::size_t host_slice_pitch, - const void *ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueWriteBufferRect( - object_, - buffer(), - blocking, - (const ::size_t *)buffer_offset, - (const ::size_t *)host_offset, - (const ::size_t *)region, - buffer_row_pitch, - buffer_slice_pitch, - host_row_pitch, - host_slice_pitch, - ptr, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_WRITE_BUFFER_RECT_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueCopyBufferRect( - const Buffer& src, - const Buffer& dst, - const size_t<3>& src_origin, - const size_t<3>& dst_origin, - const size_t<3>& region, - ::size_t src_row_pitch, - ::size_t src_slice_pitch, - ::size_t dst_row_pitch, - ::size_t dst_slice_pitch, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueCopyBufferRect( - object_, - src(), - dst(), - (const ::size_t *)src_origin, - (const ::size_t *)dst_origin, - (const ::size_t *)region, - src_row_pitch, - src_slice_pitch, - dst_row_pitch, - dst_slice_pitch, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQEUE_COPY_BUFFER_RECT_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - -#if defined(CL_VERSION_1_2) - /** - * Enqueue a command to fill a buffer object with a pattern - * of a given size. The pattern is specified a as vector. - * \tparam PatternType The datatype of the pattern field. - * The pattern type must be an accepted OpenCL data type. - */ - template - cl_int enqueueFillBuffer( - const Buffer& buffer, - PatternType pattern, - ::size_t offset, - ::size_t size, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueFillBuffer( - object_, - buffer(), - static_cast(&pattern), - sizeof(PatternType), - offset, - size, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_FILL_BUFFER_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } -#endif // #if defined(CL_VERSION_1_2) - - cl_int enqueueReadImage( - const Image& image, - cl_bool blocking, - const size_t<3>& origin, - const size_t<3>& region, - ::size_t row_pitch, - ::size_t slice_pitch, - void* ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueReadImage( - object_, image(), blocking, (const ::size_t *) origin, - (const ::size_t *) region, row_pitch, slice_pitch, ptr, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_READ_IMAGE_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueWriteImage( - const Image& image, - cl_bool blocking, - const size_t<3>& origin, - const size_t<3>& region, - ::size_t row_pitch, - ::size_t slice_pitch, - const void* ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueWriteImage( - object_, image(), blocking, (const ::size_t *) origin, - (const ::size_t *) region, row_pitch, slice_pitch, ptr, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_WRITE_IMAGE_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueCopyImage( - const Image& src, - const Image& dst, - const size_t<3>& src_origin, - const size_t<3>& dst_origin, - const size_t<3>& region, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueCopyImage( - object_, src(), dst(), (const ::size_t *) src_origin, - (const ::size_t *)dst_origin, (const ::size_t *) region, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_COPY_IMAGE_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - -#if defined(CL_VERSION_1_2) - /** - * Enqueue a command to fill an image object with a specified color. - * \param fillColor is the color to use to fill the image. - * This is a four component RGBA floating-point color value if - * the image channel data type is not an unnormalized signed or - * unsigned data type. - */ - cl_int enqueueFillImage( - const Image& image, - cl_float4 fillColor, - const size_t<3>& origin, - const size_t<3>& region, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueFillImage( - object_, - image(), - static_cast(&fillColor), - (const ::size_t *) origin, - (const ::size_t *) region, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_FILL_IMAGE_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - /** - * Enqueue a command to fill an image object with a specified color. - * \param fillColor is the color to use to fill the image. - * This is a four component RGBA signed integer color value if - * the image channel data type is an unnormalized signed integer - * type. - */ - cl_int enqueueFillImage( - const Image& image, - cl_int4 fillColor, - const size_t<3>& origin, - const size_t<3>& region, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueFillImage( - object_, - image(), - static_cast(&fillColor), - (const ::size_t *) origin, - (const ::size_t *) region, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_FILL_IMAGE_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - /** - * Enqueue a command to fill an image object with a specified color. - * \param fillColor is the color to use to fill the image. - * This is a four component RGBA unsigned integer color value if - * the image channel data type is an unnormalized unsigned integer - * type. - */ - cl_int enqueueFillImage( - const Image& image, - cl_uint4 fillColor, - const size_t<3>& origin, - const size_t<3>& region, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueFillImage( - object_, - image(), - static_cast(&fillColor), - (const ::size_t *) origin, - (const ::size_t *) region, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_FILL_IMAGE_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } -#endif // #if defined(CL_VERSION_1_2) - - cl_int enqueueCopyImageToBuffer( - const Image& src, - const Buffer& dst, - const size_t<3>& src_origin, - const size_t<3>& region, - ::size_t dst_offset, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueCopyImageToBuffer( - object_, src(), dst(), (const ::size_t *) src_origin, - (const ::size_t *) region, dst_offset, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueCopyBufferToImage( - const Buffer& src, - const Image& dst, - ::size_t src_offset, - const size_t<3>& dst_origin, - const size_t<3>& region, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueCopyBufferToImage( - object_, src(), dst(), src_offset, - (const ::size_t *) dst_origin, (const ::size_t *) region, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - void* enqueueMapBuffer( - const Buffer& buffer, - cl_bool blocking, - cl_map_flags flags, - ::size_t offset, - ::size_t size, - const VECTOR_CLASS* events = NULL, - Event* event = NULL, - cl_int* err = NULL) const - { - cl_event tmp; - cl_int error; - void * result = ::clEnqueueMapBuffer( - object_, buffer(), blocking, flags, offset, size, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL, - &error); - - detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - if (event != NULL && error == CL_SUCCESS) - *event = tmp; - - return result; - } - - void* enqueueMapImage( - const Image& buffer, - cl_bool blocking, - cl_map_flags flags, - const size_t<3>& origin, - const size_t<3>& region, - ::size_t * row_pitch, - ::size_t * slice_pitch, - const VECTOR_CLASS* events = NULL, - Event* event = NULL, - cl_int* err = NULL) const - { - cl_event tmp; - cl_int error; - void * result = ::clEnqueueMapImage( - object_, buffer(), blocking, flags, - (const ::size_t *) origin, (const ::size_t *) region, - row_pitch, slice_pitch, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL, - &error); - - detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR); - if (err != NULL) { - *err = error; - } - if (event != NULL && error == CL_SUCCESS) - *event = tmp; - return result; - } - - cl_int enqueueUnmapMemObject( - const Memory& memory, - void* mapped_ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueUnmapMemObject( - object_, memory(), mapped_ptr, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_UNMAP_MEM_OBJECT_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - -#if defined(CL_VERSION_1_2) - /** - * Enqueues a marker command which waits for either a list of events to complete, - * or all previously enqueued commands to complete. - * - * Enqueues a marker command which waits for either a list of events to complete, - * or if the list is empty it waits for all commands previously enqueued in command_queue - * to complete before it completes. This command returns an event which can be waited on, - * i.e. this event can be waited on to insure that all events either in the event_wait_list - * or all previously enqueued commands, queued before this command to command_queue, - * have completed. - */ - cl_int enqueueMarkerWithWaitList( - const VECTOR_CLASS *events = 0, - Event *event = 0) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueMarkerWithWaitList( - object_, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_MARKER_WAIT_LIST_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - /** - * A synchronization point that enqueues a barrier operation. - * - * Enqueues a barrier command which waits for either a list of events to complete, - * or if the list is empty it waits for all commands previously enqueued in command_queue - * to complete before it completes. This command blocks command execution, that is, any - * following commands enqueued after it do not execute until it completes. This command - * returns an event which can be waited on, i.e. this event can be waited on to insure that - * all events either in the event_wait_list or all previously enqueued commands, queued - * before this command to command_queue, have completed. - */ - cl_int enqueueBarrierWithWaitList( - const VECTOR_CLASS *events = 0, - Event *event = 0) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueBarrierWithWaitList( - object_, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_BARRIER_WAIT_LIST_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - /** - * Enqueues a command to indicate with which device a set of memory objects - * should be associated. - */ - cl_int enqueueMigrateMemObjects( - const VECTOR_CLASS &memObjects, - cl_mem_migration_flags flags, - const VECTOR_CLASS* events = NULL, - Event* event = NULL - ) const - { - cl_event tmp; - - cl_mem* localMemObjects = static_cast(alloca(memObjects.size() * sizeof(cl_mem))); - for( int i = 0; i < (int)memObjects.size(); ++i ) { - localMemObjects[i] = memObjects[i](); - } - - - cl_int err = detail::errHandler( - ::clEnqueueMigrateMemObjects( - object_, - (cl_uint)memObjects.size(), - static_cast(localMemObjects), - flags, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_UNMAP_MEM_OBJECT_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } -#endif // #if defined(CL_VERSION_1_2) - - cl_int enqueueNDRangeKernel( - const Kernel& kernel, - const NDRange& offset, - const NDRange& global, - const NDRange& local = NullRange, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueNDRangeKernel( - object_, kernel(), (cl_uint) global.dimensions(), - offset.dimensions() != 0 ? (const ::size_t*) offset : NULL, - (const ::size_t*) global, - local.dimensions() != 0 ? (const ::size_t*) local : NULL, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_NDRANGE_KERNEL_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueTask( - const Kernel& kernel, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueTask( - object_, kernel(), - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_TASK_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueNativeKernel( - void (CL_CALLBACK *userFptr)(void *), - std::pair args, - const VECTOR_CLASS* mem_objects = NULL, - const VECTOR_CLASS* mem_locs = NULL, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0) - ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem)) - : NULL; - - if (mems != NULL) { - for (unsigned int i = 0; i < mem_objects->size(); i++) { - mems[i] = ((*mem_objects)[i])(); - } - } - - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueNativeKernel( - object_, userFptr, args.first, args.second, - (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, - mems, - (mem_locs != NULL && mem_locs->size() > 0) ? (const void **) &mem_locs->front() : NULL, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_NATIVE_KERNEL); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - -/** - * Deprecated APIs for 1.2 - */ -#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) - CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueMarker( - object_, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_MARKER_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - cl_int enqueueWaitForEvents(const VECTOR_CLASS& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - { - return detail::errHandler( - ::clEnqueueWaitForEvents( - object_, - (cl_uint) events.size(), - events.size() > 0 ? (const cl_event*) &events.front() : NULL), - __ENQUEUE_WAIT_FOR_EVENTS_ERR); - } -#endif // #if defined(CL_VERSION_1_1) - - cl_int enqueueAcquireGLObjects( - const VECTOR_CLASS* mem_objects = NULL, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueAcquireGLObjects( - object_, - (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, - (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_ACQUIRE_GL_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueReleaseGLObjects( - const VECTOR_CLASS* mem_objects = NULL, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueReleaseGLObjects( - object_, - (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, - (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_RELEASE_GL_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - -#if defined (USE_DX_INTEROP) -typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)( - cl_command_queue command_queue, cl_uint num_objects, - const cl_mem* mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, cl_event* event); -typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)( - cl_command_queue command_queue, cl_uint num_objects, - const cl_mem* mem_objects, cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, cl_event* event); - - cl_int enqueueAcquireD3D10Objects( - const VECTOR_CLASS* mem_objects = NULL, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL; -#if defined(CL_VERSION_1_2) - cl_context context = getInfo(); - cl::Device device(getInfo()); - cl_platform_id platform = device.getInfo(); - __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR); -#endif -#if defined(CL_VERSION_1_1) - __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR); -#endif - - cl_event tmp; - cl_int err = detail::errHandler( - pfn_clEnqueueAcquireD3D10ObjectsKHR( - object_, - (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, - (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_ACQUIRE_GL_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } - - cl_int enqueueReleaseD3D10Objects( - const VECTOR_CLASS* mem_objects = NULL, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) const - { - static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL; -#if defined(CL_VERSION_1_2) - cl_context context = getInfo(); - cl::Device device(getInfo()); - cl_platform_id platform = device.getInfo(); - __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR); -#endif // #if defined(CL_VERSION_1_2) -#if defined(CL_VERSION_1_1) - __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR); -#endif // #if defined(CL_VERSION_1_1) - - cl_event tmp; - cl_int err = detail::errHandler( - pfn_clEnqueueReleaseD3D10ObjectsKHR( - object_, - (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0, - (mem_objects != NULL && mem_objects->size() > 0) ? (const cl_mem *) &mem_objects->front(): NULL, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_RELEASE_GL_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; - } -#endif - -/** - * Deprecated APIs for 1.2 - */ -#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2)) - CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - { - return detail::errHandler( - ::clEnqueueBarrier(object_), - __ENQUEUE_BARRIER_ERR); - } -#endif // #if defined(CL_VERSION_1_1) - - cl_int flush() const - { - return detail::errHandler(::clFlush(object_), __FLUSH_ERR); - } - - cl_int finish() const - { - return detail::errHandler(::clFinish(object_), __FINISH_ERR); - } -}; - -#ifdef _WIN32 -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED -__declspec(selectany) std::atomic CommandQueue::default_initialized_; -#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED -__declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED -__declspec(selectany) CommandQueue CommandQueue::default_; -__declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; -#else // !_WIN32 -#ifdef CL_HPP_CPP11_ATOMICS_SUPPORTED -__attribute__((weak)) std::atomic CommandQueue::default_initialized_; -#else // !CL_HPP_CPP11_ATOMICS_SUPPORTED -__attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED; -#endif // !CL_HPP_CPP11_ATOMICS_SUPPORTED -__attribute__((weak)) CommandQueue CommandQueue::default_; -__attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS; -#endif // !_WIN32 - -template< typename IteratorType > -Buffer::Buffer( - const Context &context, - IteratorType startIterator, - IteratorType endIterator, - bool readOnly, - bool useHostPtr, - cl_int* err) -{ - typedef typename std::iterator_traits::value_type DataType; - cl_int error; - - cl_mem_flags flags = 0; - if( readOnly ) { - flags |= CL_MEM_READ_ONLY; - } - else { - flags |= CL_MEM_READ_WRITE; - } - if( useHostPtr ) { - flags |= CL_MEM_USE_HOST_PTR; - } - - ::size_t size = sizeof(DataType)*(endIterator - startIterator); - - if( useHostPtr ) { - object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); - } else { - object_ = ::clCreateBuffer(context(), flags, size, 0, &error); - } - - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - - if( !useHostPtr ) { - CommandQueue queue(context, 0, &error); - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - - error = cl::copy(queue, startIterator, endIterator, *this); - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - } -} - -template< typename IteratorType > -Buffer::Buffer( - const CommandQueue &queue, - IteratorType startIterator, - IteratorType endIterator, - bool readOnly, - bool useHostPtr, - cl_int* err) -{ - typedef typename std::iterator_traits::value_type DataType; - cl_int error; - - cl_mem_flags flags = 0; - if (readOnly) { - flags |= CL_MEM_READ_ONLY; - } - else { - flags |= CL_MEM_READ_WRITE; - } - if (useHostPtr) { - flags |= CL_MEM_USE_HOST_PTR; - } - - ::size_t size = sizeof(DataType)*(endIterator - startIterator); - - Context context = queue.getInfo(); - - if (useHostPtr) { - object_ = ::clCreateBuffer(context(), flags, size, static_cast(&*startIterator), &error); - } - else { - object_ = ::clCreateBuffer(context(), flags, size, 0, &error); - } - - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - - if (!useHostPtr) { - error = cl::copy(queue, startIterator, endIterator, *this); - detail::errHandler(error, __CREATE_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - } -} - -inline cl_int enqueueReadBuffer( - const Buffer& buffer, - cl_bool blocking, - ::size_t offset, - ::size_t size, - void* ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event); -} - -inline cl_int enqueueWriteBuffer( - const Buffer& buffer, - cl_bool blocking, - ::size_t offset, - ::size_t size, - const void* ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event); -} - -inline void* enqueueMapBuffer( - const Buffer& buffer, - cl_bool blocking, - cl_map_flags flags, - ::size_t offset, - ::size_t size, - const VECTOR_CLASS* events = NULL, - Event* event = NULL, - cl_int* err = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - - void * result = ::clEnqueueMapBuffer( - queue(), buffer(), blocking, flags, offset, size, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (cl_event*) event, - &error); - - detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); - if (err != NULL) { - *err = error; - } - return result; -} - -inline cl_int enqueueUnmapMemObject( - const Memory& memory, - void* mapped_ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR); - if (error != CL_SUCCESS) { - return error; - } - - cl_event tmp; - cl_int err = detail::errHandler( - ::clEnqueueUnmapMemObject( - queue(), memory(), mapped_ptr, - (events != NULL) ? (cl_uint) events->size() : 0, - (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL, - (event != NULL) ? &tmp : NULL), - __ENQUEUE_UNMAP_MEM_OBJECT_ERR); - - if (event != NULL && err == CL_SUCCESS) - *event = tmp; - - return err; -} - -inline cl_int enqueueCopyBuffer( - const Buffer& src, - const Buffer& dst, - ::size_t src_offset, - ::size_t dst_offset, - ::size_t size, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event); -} - -/** - * Blocking copy operation between iterators and a buffer. - * Host to Device. - * Uses default command queue. - */ -template< typename IteratorType > -inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - if (error != CL_SUCCESS) - return error; - - return cl::copy(queue, startIterator, endIterator, buffer); -} - -/** - * Blocking copy operation between iterators and a buffer. - * Device to Host. - * Uses default command queue. - */ -template< typename IteratorType > -inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - if (error != CL_SUCCESS) - return error; - - return cl::copy(queue, buffer, startIterator, endIterator); -} - -/** - * Blocking copy operation between iterators and a buffer. - * Host to Device. - * Uses specified queue. - */ -template< typename IteratorType > -inline cl_int copy( const CommandQueue &queue, IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer ) -{ - typedef typename std::iterator_traits::value_type DataType; - cl_int error; - - ::size_t length = endIterator-startIterator; - ::size_t byteLength = length*sizeof(DataType); - - DataType *pointer = - static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error)); - // if exceptions enabled, enqueueMapBuffer will throw - if( error != CL_SUCCESS ) { - return error; - } -#if defined(_MSC_VER) - std::copy( - startIterator, - endIterator, - stdext::checked_array_iterator( - pointer, length)); -#else - std::copy(startIterator, endIterator, pointer); -#endif - Event endEvent; - error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); - // if exceptions enabled, enqueueUnmapMemObject will throw - if( error != CL_SUCCESS ) { - return error; - } - endEvent.wait(); - return CL_SUCCESS; -} - -/** - * Blocking copy operation between iterators and a buffer. - * Device to Host. - * Uses specified queue. - */ -template< typename IteratorType > -inline cl_int copy( const CommandQueue &queue, const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator ) -{ - typedef typename std::iterator_traits::value_type DataType; - cl_int error; - - ::size_t length = endIterator-startIterator; - ::size_t byteLength = length*sizeof(DataType); - - DataType *pointer = - static_cast(queue.enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error)); - // if exceptions enabled, enqueueMapBuffer will throw - if( error != CL_SUCCESS ) { - return error; - } - std::copy(pointer, pointer + length, startIterator); - Event endEvent; - error = queue.enqueueUnmapMemObject(buffer, pointer, 0, &endEvent); - // if exceptions enabled, enqueueUnmapMemObject will throw - if( error != CL_SUCCESS ) { - return error; - } - endEvent.wait(); - return CL_SUCCESS; -} - -#if defined(CL_VERSION_1_1) -inline cl_int enqueueReadBufferRect( - const Buffer& buffer, - cl_bool blocking, - const size_t<3>& buffer_offset, - const size_t<3>& host_offset, - const size_t<3>& region, - ::size_t buffer_row_pitch, - ::size_t buffer_slice_pitch, - ::size_t host_row_pitch, - ::size_t host_slice_pitch, - void *ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueReadBufferRect( - buffer, - blocking, - buffer_offset, - host_offset, - region, - buffer_row_pitch, - buffer_slice_pitch, - host_row_pitch, - host_slice_pitch, - ptr, - events, - event); -} - -inline cl_int enqueueWriteBufferRect( - const Buffer& buffer, - cl_bool blocking, - const size_t<3>& buffer_offset, - const size_t<3>& host_offset, - const size_t<3>& region, - ::size_t buffer_row_pitch, - ::size_t buffer_slice_pitch, - ::size_t host_row_pitch, - ::size_t host_slice_pitch, - const void *ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueWriteBufferRect( - buffer, - blocking, - buffer_offset, - host_offset, - region, - buffer_row_pitch, - buffer_slice_pitch, - host_row_pitch, - host_slice_pitch, - ptr, - events, - event); -} - -inline cl_int enqueueCopyBufferRect( - const Buffer& src, - const Buffer& dst, - const size_t<3>& src_origin, - const size_t<3>& dst_origin, - const size_t<3>& region, - ::size_t src_row_pitch, - ::size_t src_slice_pitch, - ::size_t dst_row_pitch, - ::size_t dst_slice_pitch, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueCopyBufferRect( - src, - dst, - src_origin, - dst_origin, - region, - src_row_pitch, - src_slice_pitch, - dst_row_pitch, - dst_slice_pitch, - events, - event); -} -#endif - -inline cl_int enqueueReadImage( - const Image& image, - cl_bool blocking, - const size_t<3>& origin, - const size_t<3>& region, - ::size_t row_pitch, - ::size_t slice_pitch, - void* ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueReadImage( - image, - blocking, - origin, - region, - row_pitch, - slice_pitch, - ptr, - events, - event); -} - -inline cl_int enqueueWriteImage( - const Image& image, - cl_bool blocking, - const size_t<3>& origin, - const size_t<3>& region, - ::size_t row_pitch, - ::size_t slice_pitch, - const void* ptr, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueWriteImage( - image, - blocking, - origin, - region, - row_pitch, - slice_pitch, - ptr, - events, - event); -} - -inline cl_int enqueueCopyImage( - const Image& src, - const Image& dst, - const size_t<3>& src_origin, - const size_t<3>& dst_origin, - const size_t<3>& region, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueCopyImage( - src, - dst, - src_origin, - dst_origin, - region, - events, - event); -} - -inline cl_int enqueueCopyImageToBuffer( - const Image& src, - const Buffer& dst, - const size_t<3>& src_origin, - const size_t<3>& region, - ::size_t dst_offset, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueCopyImageToBuffer( - src, - dst, - src_origin, - region, - dst_offset, - events, - event); -} - -inline cl_int enqueueCopyBufferToImage( - const Buffer& src, - const Image& dst, - ::size_t src_offset, - const size_t<3>& dst_origin, - const size_t<3>& region, - const VECTOR_CLASS* events = NULL, - Event* event = NULL) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.enqueueCopyBufferToImage( - src, - dst, - src_offset, - dst_origin, - region, - events, - event); -} - - -inline cl_int flush(void) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - return queue.flush(); -} - -inline cl_int finish(void) -{ - cl_int error; - CommandQueue queue = CommandQueue::getDefault(&error); - - if (error != CL_SUCCESS) { - return error; - } - - - return queue.finish(); -} - -// Kernel Functor support -// New interface as of September 2011 -// Requires the C++11 std::tr1::function (note do not support TR1) -// Visual Studio 2010 and GCC 4.2 - -struct EnqueueArgs -{ - CommandQueue queue_; - const NDRange offset_; - const NDRange global_; - const NDRange local_; - VECTOR_CLASS events_; - - EnqueueArgs(NDRange global) : - queue_(CommandQueue::getDefault()), - offset_(NullRange), - global_(global), - local_(NullRange) - { - - } - - EnqueueArgs(NDRange global, NDRange local) : - queue_(CommandQueue::getDefault()), - offset_(NullRange), - global_(global), - local_(local) - { - - } - - EnqueueArgs(NDRange offset, NDRange global, NDRange local) : - queue_(CommandQueue::getDefault()), - offset_(offset), - global_(global), - local_(local) - { - - } - - EnqueueArgs(Event e, NDRange global) : - queue_(CommandQueue::getDefault()), - offset_(NullRange), - global_(global), - local_(NullRange) - { - events_.push_back(e); - } - - EnqueueArgs(Event e, NDRange global, NDRange local) : - queue_(CommandQueue::getDefault()), - offset_(NullRange), - global_(global), - local_(local) - { - events_.push_back(e); - } - - EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) : - queue_(CommandQueue::getDefault()), - offset_(offset), - global_(global), - local_(local) - { - events_.push_back(e); - } - - EnqueueArgs(const VECTOR_CLASS &events, NDRange global) : - queue_(CommandQueue::getDefault()), - offset_(NullRange), - global_(global), - local_(NullRange), - events_(events) - { - - } - - EnqueueArgs(const VECTOR_CLASS &events, NDRange global, NDRange local) : - queue_(CommandQueue::getDefault()), - offset_(NullRange), - global_(global), - local_(local), - events_(events) - { - - } - - EnqueueArgs(const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : - queue_(CommandQueue::getDefault()), - offset_(offset), - global_(global), - local_(local), - events_(events) - { - - } - - EnqueueArgs(CommandQueue &queue, NDRange global) : - queue_(queue), - offset_(NullRange), - global_(global), - local_(NullRange) - { - - } - - EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) : - queue_(queue), - offset_(NullRange), - global_(global), - local_(local) - { - - } - - EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) : - queue_(queue), - offset_(offset), - global_(global), - local_(local) - { - - } - - EnqueueArgs(CommandQueue &queue, Event e, NDRange global) : - queue_(queue), - offset_(NullRange), - global_(global), - local_(NullRange) - { - events_.push_back(e); - } - - EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) : - queue_(queue), - offset_(NullRange), - global_(global), - local_(local) - { - events_.push_back(e); - } - - EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) : - queue_(queue), - offset_(offset), - global_(global), - local_(local) - { - events_.push_back(e); - } - - EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global) : - queue_(queue), - offset_(NullRange), - global_(global), - local_(NullRange), - events_(events) - { - - } - - EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange global, NDRange local) : - queue_(queue), - offset_(NullRange), - global_(global), - local_(local), - events_(events) - { - - } - - EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS &events, NDRange offset, NDRange global, NDRange local) : - queue_(queue), - offset_(offset), - global_(global), - local_(local), - events_(events) - { - - } -}; - -namespace detail { - -class NullType {}; - -template -struct SetArg -{ - static void set (Kernel kernel, T0 arg) - { - kernel.setArg(index, arg); - } -}; - -template -struct SetArg -{ - static void set (Kernel, NullType) - { - } -}; - -template < - typename T0, typename T1, typename T2, typename T3, - typename T4, typename T5, typename T6, typename T7, - typename T8, typename T9, typename T10, typename T11, - typename T12, typename T13, typename T14, typename T15, - typename T16, typename T17, typename T18, typename T19, - typename T20, typename T21, typename T22, typename T23, - typename T24, typename T25, typename T26, typename T27, - typename T28, typename T29, typename T30, typename T31 - -> -class KernelFunctorGlobal -{ -private: - Kernel kernel_; - -public: - KernelFunctorGlobal( - Kernel kernel) : - kernel_(kernel) - {} - - KernelFunctorGlobal( - const Program& program, - const STRING_CLASS name, - cl_int * err = NULL) : - kernel_(program, name.c_str(), err) - {} - - Event operator() ( - const EnqueueArgs& args, - T0 t0, - T1 t1 = NullType(), - T2 t2 = NullType(), - T3 t3 = NullType(), - T4 t4 = NullType(), - T5 t5 = NullType(), - T6 t6 = NullType(), - T7 t7 = NullType(), - T8 t8 = NullType(), - T9 t9 = NullType(), - T10 t10 = NullType(), - T11 t11 = NullType(), - T12 t12 = NullType(), - T13 t13 = NullType(), - T14 t14 = NullType(), - T15 t15 = NullType(), - T16 t16 = NullType(), - T17 t17 = NullType(), - T18 t18 = NullType(), - T19 t19 = NullType(), - T20 t20 = NullType(), - T21 t21 = NullType(), - T22 t22 = NullType(), - T23 t23 = NullType(), - T24 t24 = NullType(), - T25 t25 = NullType(), - T26 t26 = NullType(), - T27 t27 = NullType(), - T28 t28 = NullType(), - T29 t29 = NullType(), - T30 t30 = NullType(), - T31 t31 = NullType() - - ) - { - Event event; - SetArg<0, T0>::set(kernel_, t0); - SetArg<1, T1>::set(kernel_, t1); - SetArg<2, T2>::set(kernel_, t2); - SetArg<3, T3>::set(kernel_, t3); - SetArg<4, T4>::set(kernel_, t4); - SetArg<5, T5>::set(kernel_, t5); - SetArg<6, T6>::set(kernel_, t6); - SetArg<7, T7>::set(kernel_, t7); - SetArg<8, T8>::set(kernel_, t8); - SetArg<9, T9>::set(kernel_, t9); - SetArg<10, T10>::set(kernel_, t10); - SetArg<11, T11>::set(kernel_, t11); - SetArg<12, T12>::set(kernel_, t12); - SetArg<13, T13>::set(kernel_, t13); - SetArg<14, T14>::set(kernel_, t14); - SetArg<15, T15>::set(kernel_, t15); - SetArg<16, T16>::set(kernel_, t16); - SetArg<17, T17>::set(kernel_, t17); - SetArg<18, T18>::set(kernel_, t18); - SetArg<19, T19>::set(kernel_, t19); - SetArg<20, T20>::set(kernel_, t20); - SetArg<21, T21>::set(kernel_, t21); - SetArg<22, T22>::set(kernel_, t22); - SetArg<23, T23>::set(kernel_, t23); - SetArg<24, T24>::set(kernel_, t24); - SetArg<25, T25>::set(kernel_, t25); - SetArg<26, T26>::set(kernel_, t26); - SetArg<27, T27>::set(kernel_, t27); - SetArg<28, T28>::set(kernel_, t28); - SetArg<29, T29>::set(kernel_, t29); - SetArg<30, T30>::set(kernel_, t30); - SetArg<31, T31>::set(kernel_, t31); - - - args.queue_.enqueueNDRangeKernel( - kernel_, - args.offset_, - args.global_, - args.local_, - &args.events_, - &event); - - return event; - } - -}; - -//------------------------------------------------------------------------------------------------------ - - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23, - typename T24, - typename T25, - typename T26, - typename T27, - typename T28, - typename T29, - typename T30, - typename T31> -struct functionImplementation_ -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30, - T31> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30, - T31); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23, - T24 arg24, - T25 arg25, - T26 arg26, - T27 arg27, - T28 arg28, - T29 arg29, - T30 arg30, - T31 arg31) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23, - arg24, - arg25, - arg26, - arg27, - arg28, - arg29, - arg30, - arg31); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23, - typename T24, - typename T25, - typename T26, - typename T27, - typename T28, - typename T29, - typename T30> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - T30); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23, - T24 arg24, - T25 arg25, - T26 arg26, - T27 arg27, - T28 arg28, - T29 arg29, - T30 arg30) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23, - arg24, - arg25, - arg26, - arg27, - arg28, - arg29, - arg30); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23, - typename T24, - typename T25, - typename T26, - typename T27, - typename T28, - typename T29> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - T29); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23, - T24 arg24, - T25 arg25, - T26 arg26, - T27 arg27, - T28 arg28, - T29 arg29) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23, - arg24, - arg25, - arg26, - arg27, - arg28, - arg29); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23, - typename T24, - typename T25, - typename T26, - typename T27, - typename T28> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - T28); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23, - T24 arg24, - T25 arg25, - T26 arg26, - T27 arg27, - T28 arg28) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23, - arg24, - arg25, - arg26, - arg27, - arg28); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23, - typename T24, - typename T25, - typename T26, - typename T27> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - T27); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23, - T24 arg24, - T25 arg25, - T26 arg26, - T27 arg27) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23, - arg24, - arg25, - arg26, - arg27); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23, - typename T24, - typename T25, - typename T26> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - T26); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23, - T24 arg24, - T25 arg25, - T26 arg26) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23, - arg24, - arg25, - arg26); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23, - typename T24, - typename T25> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - T25); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23, - T24 arg24, - T25 arg25) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23, - arg24, - arg25); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23, - typename T24> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - T24); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23, - T24 arg24) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23, - arg24); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22, - typename T23> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - T23); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22, - T23 arg23) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22, - arg23); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21, - typename T22> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - T22); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21, - T22 arg22) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21, - arg22); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20, - typename T21> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - T21); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20, - T21 arg21) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20, - arg21); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19, - typename T20> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - T20); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19, - T20 arg20) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19, - arg20); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18, - typename T19> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - T19); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18, - T19 arg19) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18, - arg19); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17, - typename T18> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - T18); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17, - T18 arg18) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17, - arg18); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16, - typename T17> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - T17); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16, - T17 arg17) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16, - arg17); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15, - typename T16> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - T16); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15, - T16 arg16) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15, - arg16); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14, - typename T15> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - T15); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14, - T15 arg15) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14, - arg15); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13, - typename T14> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - T14); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13, - T14 arg14) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13, - arg14); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12, - typename T13> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - T13); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12, - T13 arg13) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12, - arg13); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11, - typename T12> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - T12); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11, - T12 arg12) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11, - arg12); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10, - typename T11> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - T11); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10, - T11 arg11) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10, - arg11); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9, - typename T10> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - T10); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9, - T10 arg10) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9, - arg10); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8, - typename T9> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - T9); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8, - T9 arg9) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8, - arg9); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7, - typename T8> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - T8); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7, - T8 arg8) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7, - arg8); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6, - typename T7> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6, - T7); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6, - T7 arg7) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6, - arg7); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5, - typename T6> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - T6, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - T6, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5, - T6); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5, - T6 arg6) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5, - arg6); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4, - typename T5> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - T5, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - T5, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4, - T5); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4, - T5 arg5) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4, - arg5); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3, - typename T4> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - T4, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - T4, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3, - T4); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3, - T4 arg4) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3, - arg4); - } - - -}; - -template< - typename T0, - typename T1, - typename T2, - typename T3> -struct functionImplementation_ -< T0, - T1, - T2, - T3, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - T3, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2, - T3); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2, - T3 arg3) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2, - arg3); - } - - -}; - -template< - typename T0, - typename T1, - typename T2> -struct functionImplementation_ -< T0, - T1, - T2, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - T2, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1, - T2); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1, - T2 arg2) - { - return functor_( - enqueueArgs, - arg0, - arg1, - arg2); - } - - -}; - -template< - typename T0, - typename T1> -struct functionImplementation_ -< T0, - T1, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - T1, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0, - T1); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0, - T1 arg1) - { - return functor_( - enqueueArgs, - arg0, - arg1); - } - - -}; - -template< - typename T0> -struct functionImplementation_ -< T0, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> -{ - typedef detail::KernelFunctorGlobal< - T0, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType, - NullType> FunctorType; - - FunctorType functor_; - - functionImplementation_(const FunctorType &functor) : - functor_(functor) - { - - #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1)) - // Fail variadic expansion for dev11 - static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it."); - #endif - - } - - //! \brief Return type of the functor - typedef Event result_type; - - //! \brief Function signature of kernel functor with no event dependency. - typedef Event type_( - const EnqueueArgs&, - T0); - - Event operator()( - const EnqueueArgs& enqueueArgs, - T0 arg0) - { - return functor_( - enqueueArgs, - arg0); - } - - -}; - - - - - -} // namespace detail - -//---------------------------------------------------------------------------------------------- - -template < - typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType, - typename T3 = detail::NullType, typename T4 = detail::NullType, - typename T5 = detail::NullType, typename T6 = detail::NullType, - typename T7 = detail::NullType, typename T8 = detail::NullType, - typename T9 = detail::NullType, typename T10 = detail::NullType, - typename T11 = detail::NullType, typename T12 = detail::NullType, - typename T13 = detail::NullType, typename T14 = detail::NullType, - typename T15 = detail::NullType, typename T16 = detail::NullType, - typename T17 = detail::NullType, typename T18 = detail::NullType, - typename T19 = detail::NullType, typename T20 = detail::NullType, - typename T21 = detail::NullType, typename T22 = detail::NullType, - typename T23 = detail::NullType, typename T24 = detail::NullType, - typename T25 = detail::NullType, typename T26 = detail::NullType, - typename T27 = detail::NullType, typename T28 = detail::NullType, - typename T29 = detail::NullType, typename T30 = detail::NullType, - typename T31 = detail::NullType - -> -struct make_kernel : - public detail::functionImplementation_< - T0, T1, T2, T3, - T4, T5, T6, T7, - T8, T9, T10, T11, - T12, T13, T14, T15, - T16, T17, T18, T19, - T20, T21, T22, T23, - T24, T25, T26, T27, - T28, T29, T30, T31 - - > -{ -public: - typedef detail::KernelFunctorGlobal< - T0, T1, T2, T3, - T4, T5, T6, T7, - T8, T9, T10, T11, - T12, T13, T14, T15, - T16, T17, T18, T19, - T20, T21, T22, T23, - T24, T25, T26, T27, - T28, T29, T30, T31 - - > FunctorType; - - make_kernel( - const Program& program, - const STRING_CLASS name, - cl_int * err = NULL) : - detail::functionImplementation_< - T0, T1, T2, T3, - T4, T5, T6, T7, - T8, T9, T10, T11, - T12, T13, T14, T15, - T16, T17, T18, T19, - T20, T21, T22, T23, - T24, T25, T26, T27, - T28, T29, T30, T31 - - >( - FunctorType(program, name, err)) - {} - - make_kernel( - const Kernel kernel) : - detail::functionImplementation_< - T0, T1, T2, T3, - T4, T5, T6, T7, - T8, T9, T10, T11, - T12, T13, T14, T15, - T16, T17, T18, T19, - T20, T21, T22, T23, - T24, T25, T26, T27, - T28, T29, T30, T31 - - >( - FunctorType(kernel)) - {} -}; - - -//---------------------------------------------------------------------------------------------------------------------- - -#undef __ERR_STR -#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS) -#undef __GET_DEVICE_INFO_ERR -#undef __GET_PLATFORM_INFO_ERR -#undef __GET_DEVICE_IDS_ERR -#undef __GET_CONTEXT_INFO_ERR -#undef __GET_EVENT_INFO_ERR -#undef __GET_EVENT_PROFILE_INFO_ERR -#undef __GET_MEM_OBJECT_INFO_ERR -#undef __GET_IMAGE_INFO_ERR -#undef __GET_SAMPLER_INFO_ERR -#undef __GET_KERNEL_INFO_ERR -#undef __GET_KERNEL_ARG_INFO_ERR -#undef __GET_KERNEL_WORK_GROUP_INFO_ERR -#undef __GET_PROGRAM_INFO_ERR -#undef __GET_PROGRAM_BUILD_INFO_ERR -#undef __GET_COMMAND_QUEUE_INFO_ERR - -#undef __CREATE_CONTEXT_ERR -#undef __CREATE_CONTEXT_FROM_TYPE_ERR -#undef __GET_SUPPORTED_IMAGE_FORMATS_ERR - -#undef __CREATE_BUFFER_ERR -#undef __CREATE_SUBBUFFER_ERR -#undef __CREATE_IMAGE2D_ERR -#undef __CREATE_IMAGE3D_ERR -#undef __CREATE_SAMPLER_ERR -#undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR - -#undef __CREATE_USER_EVENT_ERR -#undef __SET_USER_EVENT_STATUS_ERR -#undef __SET_EVENT_CALLBACK_ERR -#undef __SET_PRINTF_CALLBACK_ERR - -#undef __WAIT_FOR_EVENTS_ERR - -#undef __CREATE_KERNEL_ERR -#undef __SET_KERNEL_ARGS_ERR -#undef __CREATE_PROGRAM_WITH_SOURCE_ERR -#undef __CREATE_PROGRAM_WITH_BINARY_ERR -#undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR -#undef __BUILD_PROGRAM_ERR -#undef __CREATE_KERNELS_IN_PROGRAM_ERR - -#undef __CREATE_COMMAND_QUEUE_ERR -#undef __SET_COMMAND_QUEUE_PROPERTY_ERR -#undef __ENQUEUE_READ_BUFFER_ERR -#undef __ENQUEUE_WRITE_BUFFER_ERR -#undef __ENQUEUE_READ_BUFFER_RECT_ERR -#undef __ENQUEUE_WRITE_BUFFER_RECT_ERR -#undef __ENQEUE_COPY_BUFFER_ERR -#undef __ENQEUE_COPY_BUFFER_RECT_ERR -#undef __ENQUEUE_READ_IMAGE_ERR -#undef __ENQUEUE_WRITE_IMAGE_ERR -#undef __ENQUEUE_COPY_IMAGE_ERR -#undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR -#undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR -#undef __ENQUEUE_MAP_BUFFER_ERR -#undef __ENQUEUE_MAP_IMAGE_ERR -#undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR -#undef __ENQUEUE_NDRANGE_KERNEL_ERR -#undef __ENQUEUE_TASK_ERR -#undef __ENQUEUE_NATIVE_KERNEL - -#undef __CL_EXPLICIT_CONSTRUCTORS - -#undef __UNLOAD_COMPILER_ERR -#endif //__CL_USER_OVERRIDE_ERROR_STRINGS - -#undef __CL_FUNCTION_TYPE - -// Extensions -/** - * Deprecated APIs for 1.2 - */ -#if defined(CL_VERSION_1_1) -#undef __INIT_CL_EXT_FCN_PTR -#endif // #if defined(CL_VERSION_1_1) -#undef __CREATE_SUB_DEVICES - -#if defined(USE_CL_DEVICE_FISSION) -#undef __PARAM_NAME_DEVICE_FISSION -#endif // USE_CL_DEVICE_FISSION - -#undef __DEFAULT_NOT_INITIALIZED -#undef __DEFAULT_BEING_INITIALIZED -#undef __DEFAULT_INITIALIZED - -#undef CL_HPP_RVALUE_REFERENCES_SUPPORTED -#undef CL_HPP_NOEXCEPT - -} // namespace cl - -#endif // CL_HPP_ diff --git a/3rdparty/CL/cl_d3d10.h b/3rdparty/CL/cl_d3d10.h deleted file mode 100644 index d5960a43f7..0000000000 --- a/3rdparty/CL/cl_d3d10.h +++ /dev/null @@ -1,131 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_CL_D3D10_H -#define __OPENCL_CL_D3D10_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/****************************************************************************** - * cl_khr_d3d10_sharing */ -#define cl_khr_d3d10_sharing 1 - -typedef cl_uint cl_d3d10_device_source_khr; -typedef cl_uint cl_d3d10_device_set_khr; - -/******************************************************************************/ - -/* Error Codes */ -#define CL_INVALID_D3D10_DEVICE_KHR -1002 -#define CL_INVALID_D3D10_RESOURCE_KHR -1003 -#define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 -#define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 - -/* cl_d3d10_device_source_nv */ -#define CL_D3D10_DEVICE_KHR 0x4010 -#define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 - -/* cl_d3d10_device_set_nv */ -#define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 -#define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 - -/* cl_context_info */ -#define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 -#define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C - -/* cl_mem_info */ -#define CL_MEM_D3D10_RESOURCE_KHR 0x4015 - -/* cl_image_info */ -#define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 - -/* cl_command_type */ -#define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 -#define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 - -/******************************************************************************/ - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( - cl_platform_id platform, - cl_d3d10_device_source_khr d3d_device_source, - void * d3d_object, - cl_d3d10_device_set_khr d3d_device_set, - cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D10Buffer * resource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D10Texture2D * resource, - UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D10Texture3D * resource, - UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_D3D10_H */ - diff --git a/3rdparty/CL/cl_d3d11.h b/3rdparty/CL/cl_d3d11.h deleted file mode 100644 index 39f9072398..0000000000 --- a/3rdparty/CL/cl_d3d11.h +++ /dev/null @@ -1,131 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_CL_D3D11_H -#define __OPENCL_CL_D3D11_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/****************************************************************************** - * cl_khr_d3d11_sharing */ -#define cl_khr_d3d11_sharing 1 - -typedef cl_uint cl_d3d11_device_source_khr; -typedef cl_uint cl_d3d11_device_set_khr; - -/******************************************************************************/ - -/* Error Codes */ -#define CL_INVALID_D3D11_DEVICE_KHR -1006 -#define CL_INVALID_D3D11_RESOURCE_KHR -1007 -#define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 -#define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 - -/* cl_d3d11_device_source */ -#define CL_D3D11_DEVICE_KHR 0x4019 -#define CL_D3D11_DXGI_ADAPTER_KHR 0x401A - -/* cl_d3d11_device_set */ -#define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B -#define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C - -/* cl_context_info */ -#define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D -#define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D - -/* cl_mem_info */ -#define CL_MEM_D3D11_RESOURCE_KHR 0x401E - -/* cl_image_info */ -#define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F - -/* cl_command_type */ -#define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 -#define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 - -/******************************************************************************/ - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( - cl_platform_id platform, - cl_d3d11_device_source_khr d3d_device_source, - void * d3d_object, - cl_d3d11_device_set_khr d3d_device_set, - cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D11Buffer * resource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D11Texture2D * resource, - UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D11Texture3D * resource, - UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_D3D11_H */ - diff --git a/3rdparty/CL/cl_dx9_media_sharing.h b/3rdparty/CL/cl_dx9_media_sharing.h deleted file mode 100644 index 2729e8b9e8..0000000000 --- a/3rdparty/CL/cl_dx9_media_sharing.h +++ /dev/null @@ -1,132 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H -#define __OPENCL_CL_DX9_MEDIA_SHARING_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************/ -/* cl_khr_dx9_media_sharing */ -#define cl_khr_dx9_media_sharing 1 - -typedef cl_uint cl_dx9_media_adapter_type_khr; -typedef cl_uint cl_dx9_media_adapter_set_khr; - -#if defined(_WIN32) -#include -typedef struct _cl_dx9_surface_info_khr -{ - IDirect3DSurface9 *resource; - HANDLE shared_handle; -} cl_dx9_surface_info_khr; -#endif - - -/******************************************************************************/ - -/* Error Codes */ -#define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 -#define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 -#define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 -#define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 - -/* cl_media_adapter_type_khr */ -#define CL_ADAPTER_D3D9_KHR 0x2020 -#define CL_ADAPTER_D3D9EX_KHR 0x2021 -#define CL_ADAPTER_DXVA_KHR 0x2022 - -/* cl_media_adapter_set_khr */ -#define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 -#define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 - -/* cl_context_info */ -#define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 -#define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 -#define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 - -/* cl_mem_info */ -#define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 -#define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 - -/* cl_image_info */ -#define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A - -/* cl_command_type */ -#define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B -#define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C - -/******************************************************************************/ - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( - cl_platform_id platform, - cl_uint num_media_adapters, - cl_dx9_media_adapter_type_khr * media_adapter_type, - void * media_adapters, - cl_dx9_media_adapter_set_khr media_adapter_set, - cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( - cl_context context, - cl_mem_flags flags, - cl_dx9_media_adapter_type_khr adapter_type, - void * surface_info, - cl_uint plane, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */ - diff --git a/3rdparty/CL/cl_dx9_media_sharing_intel.h b/3rdparty/CL/cl_dx9_media_sharing_intel.h deleted file mode 100644 index 737e685649..0000000000 --- a/3rdparty/CL/cl_dx9_media_sharing_intel.h +++ /dev/null @@ -1,182 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2019 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ -/*****************************************************************************\ - -Copyright (c) 2013-2019 Intel Corporation All Rights Reserved. - -THESE MATERIALS ARE 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 INTEL OR ITS -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 THESE -MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -File Name: cl_dx9_media_sharing_intel.h - -Abstract: - -Notes: - -\*****************************************************************************/ - -#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_INTEL_H -#define __OPENCL_CL_DX9_MEDIA_SHARING_INTEL_H - -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/*************************************** -* cl_intel_dx9_media_sharing extension * -****************************************/ - -#define cl_intel_dx9_media_sharing 1 - -typedef cl_uint cl_dx9_device_source_intel; -typedef cl_uint cl_dx9_device_set_intel; - -/* error codes */ -#define CL_INVALID_DX9_DEVICE_INTEL -1010 -#define CL_INVALID_DX9_RESOURCE_INTEL -1011 -#define CL_DX9_RESOURCE_ALREADY_ACQUIRED_INTEL -1012 -#define CL_DX9_RESOURCE_NOT_ACQUIRED_INTEL -1013 - -/* cl_dx9_device_source_intel */ -#define CL_D3D9_DEVICE_INTEL 0x4022 -#define CL_D3D9EX_DEVICE_INTEL 0x4070 -#define CL_DXVA_DEVICE_INTEL 0x4071 - -/* cl_dx9_device_set_intel */ -#define CL_PREFERRED_DEVICES_FOR_DX9_INTEL 0x4024 -#define CL_ALL_DEVICES_FOR_DX9_INTEL 0x4025 - -/* cl_context_info */ -#define CL_CONTEXT_D3D9_DEVICE_INTEL 0x4026 -#define CL_CONTEXT_D3D9EX_DEVICE_INTEL 0x4072 -#define CL_CONTEXT_DXVA_DEVICE_INTEL 0x4073 - -/* cl_mem_info */ -#define CL_MEM_DX9_RESOURCE_INTEL 0x4027 -#define CL_MEM_DX9_SHARED_HANDLE_INTEL 0x4074 - -/* cl_image_info */ -#define CL_IMAGE_DX9_PLANE_INTEL 0x4075 - -/* cl_command_type */ -#define CL_COMMAND_ACQUIRE_DX9_OBJECTS_INTEL 0x402A -#define CL_COMMAND_RELEASE_DX9_OBJECTS_INTEL 0x402B -/******************************************************************************/ - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceIDsFromDX9INTEL( - cl_platform_id platform, - cl_dx9_device_source_intel dx9_device_source, - void* dx9_object, - cl_dx9_device_set_intel dx9_device_set, - cl_uint num_entries, - cl_device_id* devices, - cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int (CL_API_CALL* clGetDeviceIDsFromDX9INTEL_fn)( - cl_platform_id platform, - cl_dx9_device_source_intel dx9_device_source, - void* dx9_object, - cl_dx9_device_set_intel dx9_device_set, - cl_uint num_entries, - cl_device_id* devices, - cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromDX9MediaSurfaceINTEL( - cl_context context, - cl_mem_flags flags, - IDirect3DSurface9* resource, - HANDLE sharedHandle, - UINT plane, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceINTEL_fn)( - cl_context context, - cl_mem_flags flags, - IDirect3DSurface9* resource, - HANDLE sharedHandle, - UINT plane, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireDX9ObjectsINTEL( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem* mem_objects, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9ObjectsINTEL_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem* mem_objects, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseDX9ObjectsINTEL( - cl_command_queue command_queue, - cl_uint num_objects, - cl_mem* mem_objects, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9ObjectsINTEL_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - cl_mem* mem_objects, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_1; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_INTEL_H */ - diff --git a/3rdparty/CL/cl_egl.h b/3rdparty/CL/cl_egl.h deleted file mode 100644 index bc4d998eb3..0000000000 --- a/3rdparty/CL/cl_egl.h +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2019 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifndef __OPENCL_CL_EGL_H -#define __OPENCL_CL_EGL_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ -#define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F -#define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D -#define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E - -/* Error type for clCreateFromEGLImageKHR */ -#define CL_INVALID_EGL_OBJECT_KHR -1093 -#define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 - -/* CLeglImageKHR is an opaque handle to an EGLImage */ -typedef void* CLeglImageKHR; - -/* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ -typedef void* CLeglDisplayKHR; - -/* CLeglSyncKHR is an opaque handle to an EGLSync object */ -typedef void* CLeglSyncKHR; - -/* properties passed to clCreateFromEGLImageKHR */ -typedef intptr_t cl_egl_image_properties_khr; - - -#define cl_khr_egl_image 1 - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromEGLImageKHR(cl_context context, - CLeglDisplayKHR egldisplay, - CLeglImageKHR eglimage, - cl_mem_flags flags, - const cl_egl_image_properties_khr * properties, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( - cl_context context, - CLeglDisplayKHR egldisplay, - CLeglImageKHR eglimage, - cl_mem_flags flags, - const cl_egl_image_properties_khr * properties, - cl_int * errcode_ret); - - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireEGLObjectsKHR(cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); - - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseEGLObjectsKHR(cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); - - -#define cl_khr_egl_event 1 - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateEventFromEGLSyncKHR(cl_context context, - CLeglSyncKHR sync, - CLeglDisplayKHR display, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( - cl_context context, - CLeglSyncKHR sync, - CLeglDisplayKHR display, - cl_int * errcode_ret); - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_EGL_H */ diff --git a/3rdparty/CL/cl_ext.h b/3rdparty/CL/cl_ext.h deleted file mode 100644 index 5c185915c3..0000000000 --- a/3rdparty/CL/cl_ext.h +++ /dev/null @@ -1,762 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2019 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/* cl_ext.h contains OpenCL extensions which don't have external */ -/* (OpenGL, D3D) dependencies. */ - -#ifndef __CL_EXT_H -#define __CL_EXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* cl_khr_fp64 extension - no extension #define since it has no functions */ -/* CL_DEVICE_DOUBLE_FP_CONFIG is defined in CL.h for OpenCL >= 120 */ - -#if CL_TARGET_OPENCL_VERSION <= 110 -#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 -#endif - -/* cl_khr_fp16 extension - no extension #define since it has no functions */ -#define CL_DEVICE_HALF_FP_CONFIG 0x1033 - -/* Memory object destruction - * - * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR - * - * Registers a user callback function that will be called when the memory object is deleted and its resources - * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback - * stack associated with memobj. The registered user callback functions are called in the reverse order in - * which they were registered. The user callback functions are called and then the memory object is deleted - * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be - * notified when the memory referenced by host_ptr, specified when the memory object is created and used as - * the storage bits for the memory object, can be reused or freed. - * - * The application may not call CL api's with the cl_mem object passed to the pfn_notify. - * - * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) - * before using. - */ -#define cl_APPLE_SetMemObjectDestructor 1 -cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem memobj, - void (* pfn_notify)(cl_mem memobj, void * user_data), - void * user_data) CL_EXT_SUFFIX__VERSION_1_0; - - -/* Context Logging Functions - * - * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). - * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) - * before using. - * - * clLogMessagesToSystemLog forwards on all log messages to the Apple System Logger - */ -#define cl_APPLE_ContextLoggingFunctions 1 -extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * errstr, - const void * private_info, - size_t cb, - void * user_data) CL_EXT_SUFFIX__VERSION_1_0; - -/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ -extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * errstr, - const void * private_info, - size_t cb, - void * user_data) CL_EXT_SUFFIX__VERSION_1_0; - -/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ -extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * errstr, - const void * private_info, - size_t cb, - void * user_data) CL_EXT_SUFFIX__VERSION_1_0; - - -/************************ -* cl_khr_icd extension * -************************/ -#define cl_khr_icd 1 - -/* cl_platform_info */ -#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 - -/* Additional Error Codes */ -#define CL_PLATFORM_NOT_FOUND_KHR -1001 - -extern CL_API_ENTRY cl_int CL_API_CALL -clIcdGetPlatformIDsKHR(cl_uint num_entries, - cl_platform_id * platforms, - cl_uint * num_platforms); - -typedef CL_API_ENTRY cl_int -(CL_API_CALL *clIcdGetPlatformIDsKHR_fn)(cl_uint num_entries, - cl_platform_id * platforms, - cl_uint * num_platforms); - - -/******************************* - * cl_khr_il_program extension * - *******************************/ -#define cl_khr_il_program 1 - -/* New property to clGetDeviceInfo for retrieving supported intermediate - * languages - */ -#define CL_DEVICE_IL_VERSION_KHR 0x105B - -/* New property to clGetProgramInfo for retrieving for retrieving the IL of a - * program - */ -#define CL_PROGRAM_IL_KHR 0x1169 - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithILKHR(cl_context context, - const void * il, - size_t length, - cl_int * errcode_ret); - -typedef CL_API_ENTRY cl_program -(CL_API_CALL *clCreateProgramWithILKHR_fn)(cl_context context, - const void * il, - size_t length, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; - -/* Extension: cl_khr_image2d_from_buffer - * - * This extension allows a 2D image to be created from a cl_mem buffer without - * a copy. The type associated with a 2D image created from a buffer in an - * OpenCL program is image2d_t. Both the sampler and sampler-less read_image - * built-in functions are supported for 2D images and 2D images created from - * a buffer. Similarly, the write_image built-ins are also supported for 2D - * images created from a buffer. - * - * When the 2D image from buffer is created, the client must specify the - * width, height, image format (i.e. channel order and channel data type) - * and optionally the row pitch. - * - * The pitch specified must be a multiple of - * CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR pixels. - * The base address of the buffer must be aligned to - * CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR pixels. - */ - -#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT_KHR 0x104A -#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT_KHR 0x104B - - -/************************************** - * cl_khr_initialize_memory extension * - **************************************/ - -#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x2030 - - -/************************************** - * cl_khr_terminate_context extension * - **************************************/ - -#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x2031 -#define CL_CONTEXT_TERMINATE_KHR 0x2032 - -#define cl_khr_terminate_context 1 -extern CL_API_ENTRY cl_int CL_API_CALL -clTerminateContextKHR(cl_context context) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int -(CL_API_CALL *clTerminateContextKHR_fn)(cl_context context) CL_EXT_SUFFIX__VERSION_1_2; - - -/* - * Extension: cl_khr_spir - * - * This extension adds support to create an OpenCL program object from a - * Standard Portable Intermediate Representation (SPIR) instance - */ - -#define CL_DEVICE_SPIR_VERSIONS 0x40E0 -#define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE 0x40E1 - - -/***************************************** - * cl_khr_create_command_queue extension * - *****************************************/ -#define cl_khr_create_command_queue 1 - -typedef cl_bitfield cl_queue_properties_khr; - -extern CL_API_ENTRY cl_command_queue CL_API_CALL -clCreateCommandQueueWithPropertiesKHR(cl_context context, - cl_device_id device, - const cl_queue_properties_khr* properties, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_command_queue -(CL_API_CALL *clCreateCommandQueueWithPropertiesKHR_fn)(cl_context context, - cl_device_id device, - const cl_queue_properties_khr* properties, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; - - -/****************************************** -* cl_nv_device_attribute_query extension * -******************************************/ - -/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ -#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 -#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 -#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 -#define CL_DEVICE_WARP_SIZE_NV 0x4003 -#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 -#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 -#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 - - -/********************************* -* cl_amd_device_attribute_query * -*********************************/ - -#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 - - -/********************************* -* cl_arm_printf extension -*********************************/ - -#define CL_PRINTF_CALLBACK_ARM 0x40B0 -#define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 - - -/*********************************** -* cl_ext_device_fission extension -***********************************/ -#define cl_ext_device_fission 1 - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseDeviceEXT(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int -(CL_API_CALL *clReleaseDeviceEXT_fn)(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainDeviceEXT(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int -(CL_API_CALL *clRetainDeviceEXT_fn)(cl_device_id device) CL_EXT_SUFFIX__VERSION_1_1; - -typedef cl_ulong cl_device_partition_property_ext; -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateSubDevicesEXT(cl_device_id in_device, - const cl_device_partition_property_ext * properties, - cl_uint num_entries, - cl_device_id * out_devices, - cl_uint * num_devices) CL_EXT_SUFFIX__VERSION_1_1; - -typedef CL_API_ENTRY cl_int -(CL_API_CALL * clCreateSubDevicesEXT_fn)(cl_device_id in_device, - const cl_device_partition_property_ext * properties, - cl_uint num_entries, - cl_device_id * out_devices, - cl_uint * num_devices) CL_EXT_SUFFIX__VERSION_1_1; - -/* cl_device_partition_property_ext */ -#define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 -#define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 -#define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 -#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 - -/* clDeviceGetInfo selectors */ -#define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 -#define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 -#define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 -#define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 -#define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 - -/* error codes */ -#define CL_DEVICE_PARTITION_FAILED_EXT -1057 -#define CL_INVALID_PARTITION_COUNT_EXT -1058 -#define CL_INVALID_PARTITION_NAME_EXT -1059 - -/* CL_AFFINITY_DOMAINs */ -#define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 -#define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 -#define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 -#define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 -#define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 -#define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 - -/* cl_device_partition_property_ext list terminators */ -#define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) -#define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) -#define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) - - -/*********************************** - * cl_ext_migrate_memobject extension definitions - ***********************************/ -#define cl_ext_migrate_memobject 1 - -typedef cl_bitfield cl_mem_migration_flags_ext; - -#define CL_MIGRATE_MEM_OBJECT_HOST_EXT 0x1 - -#define CL_COMMAND_MIGRATE_MEM_OBJECT_EXT 0x4040 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMigrateMemObjectEXT(cl_command_queue command_queue, - cl_uint num_mem_objects, - const cl_mem * mem_objects, - cl_mem_migration_flags_ext flags, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); - -typedef CL_API_ENTRY cl_int -(CL_API_CALL *clEnqueueMigrateMemObjectEXT_fn)(cl_command_queue command_queue, - cl_uint num_mem_objects, - const cl_mem * mem_objects, - cl_mem_migration_flags_ext flags, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); - - -/********************************* -* cl_qcom_ext_host_ptr extension -*********************************/ -#define cl_qcom_ext_host_ptr 1 - -#define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) - -#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 -#define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 -#define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 -#define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 -#define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 -#define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 -#define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 -#define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 - -typedef cl_uint cl_image_pitch_info_qcom; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceImageInfoQCOM(cl_device_id device, - size_t image_width, - size_t image_height, - const cl_image_format *image_format, - cl_image_pitch_info_qcom param_name, - size_t param_value_size, - void *param_value, - size_t *param_value_size_ret); - -typedef struct _cl_mem_ext_host_ptr -{ - /* Type of external memory allocation. */ - /* Legal values will be defined in layered extensions. */ - cl_uint allocation_type; - - /* Host cache policy for this external memory allocation. */ - cl_uint host_cache_policy; - -} cl_mem_ext_host_ptr; - - -/******************************************* -* cl_qcom_ext_host_ptr_iocoherent extension -********************************************/ - -/* Cache policy specifying io-coherence */ -#define CL_MEM_HOST_IOCOHERENT_QCOM 0x40A9 - - -/********************************* -* cl_qcom_ion_host_ptr extension -*********************************/ - -#define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 - -typedef struct _cl_mem_ion_host_ptr -{ - /* Type of external memory allocation. */ - /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ - cl_mem_ext_host_ptr ext_host_ptr; - - /* ION file descriptor */ - int ion_filedesc; - - /* Host pointer to the ION allocated memory */ - void* ion_hostptr; - -} cl_mem_ion_host_ptr; - - -/********************************* -* cl_qcom_android_native_buffer_host_ptr extension -*********************************/ - -#define CL_MEM_ANDROID_NATIVE_BUFFER_HOST_PTR_QCOM 0x40C6 - -typedef struct _cl_mem_android_native_buffer_host_ptr -{ - /* Type of external memory allocation. */ - /* Must be CL_MEM_ANDROID_NATIVE_BUFFER_HOST_PTR_QCOM for Android native buffers. */ - cl_mem_ext_host_ptr ext_host_ptr; - - /* Virtual pointer to the android native buffer */ - void* anb_ptr; - -} cl_mem_android_native_buffer_host_ptr; - - -/****************************************** - * cl_img_yuv_image extension * - ******************************************/ - -/* Image formats used in clCreateImage */ -#define CL_NV21_IMG 0x40D0 -#define CL_YV12_IMG 0x40D1 - - -/****************************************** - * cl_img_cached_allocations extension * - ******************************************/ - -/* Flag values used by clCreateBuffer */ -#define CL_MEM_USE_UNCACHED_CPU_MEMORY_IMG (1 << 26) -#define CL_MEM_USE_CACHED_CPU_MEMORY_IMG (1 << 27) - - -/****************************************** - * cl_img_use_gralloc_ptr extension * - ******************************************/ -#define cl_img_use_gralloc_ptr 1 - -/* Flag values used by clCreateBuffer */ -#define CL_MEM_USE_GRALLOC_PTR_IMG (1 << 28) - -/* To be used by clGetEventInfo: */ -#define CL_COMMAND_ACQUIRE_GRALLOC_OBJECTS_IMG 0x40D2 -#define CL_COMMAND_RELEASE_GRALLOC_OBJECTS_IMG 0x40D3 - -/* Error code from clEnqueueReleaseGrallocObjectsIMG */ -#define CL_GRALLOC_RESOURCE_NOT_ACQUIRED_IMG 0x40D4 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireGrallocObjectsIMG(cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseGrallocObjectsIMG(cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; - - -/********************************* -* cl_khr_subgroups extension -*********************************/ -#define cl_khr_subgroups 1 - -#if !defined(CL_VERSION_2_1) -/* For OpenCL 2.1 and newer, cl_kernel_sub_group_info is declared in CL.h. - In hindsight, there should have been a khr suffix on this type for - the extension, but keeping it un-suffixed to maintain backwards - compatibility. */ -typedef cl_uint cl_kernel_sub_group_info; -#endif - -/* cl_kernel_sub_group_info */ -#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR 0x2033 -#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR 0x2034 - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelSubGroupInfoKHR(cl_kernel in_kernel, - cl_device_id in_device, - cl_kernel_sub_group_info param_name, - size_t input_value_size, - const void * input_value, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; - -typedef CL_API_ENTRY cl_int -(CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel in_kernel, - cl_device_id in_device, - cl_kernel_sub_group_info param_name, - size_t input_value_size, - const void * input_value, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; - - -/********************************* -* cl_khr_mipmap_image extension -*********************************/ - -/* cl_sampler_properties */ -#define CL_SAMPLER_MIP_FILTER_MODE_KHR 0x1155 -#define CL_SAMPLER_LOD_MIN_KHR 0x1156 -#define CL_SAMPLER_LOD_MAX_KHR 0x1157 - - -/********************************* -* cl_khr_priority_hints extension -*********************************/ -/* This extension define is for backwards compatibility. - It shouldn't be required since this extension has no new functions. */ -#define cl_khr_priority_hints 1 - -typedef cl_uint cl_queue_priority_khr; - -/* cl_command_queue_properties */ -#define CL_QUEUE_PRIORITY_KHR 0x1096 - -/* cl_queue_priority_khr */ -#define CL_QUEUE_PRIORITY_HIGH_KHR (1<<0) -#define CL_QUEUE_PRIORITY_MED_KHR (1<<1) -#define CL_QUEUE_PRIORITY_LOW_KHR (1<<2) - - -/********************************* -* cl_khr_throttle_hints extension -*********************************/ -/* This extension define is for backwards compatibility. - It shouldn't be required since this extension has no new functions. */ -#define cl_khr_throttle_hints 1 - -typedef cl_uint cl_queue_throttle_khr; - -/* cl_command_queue_properties */ -#define CL_QUEUE_THROTTLE_KHR 0x1097 - -/* cl_queue_throttle_khr */ -#define CL_QUEUE_THROTTLE_HIGH_KHR (1<<0) -#define CL_QUEUE_THROTTLE_MED_KHR (1<<1) -#define CL_QUEUE_THROTTLE_LOW_KHR (1<<2) - - -/********************************* -* cl_khr_subgroup_named_barrier -*********************************/ -/* This extension define is for backwards compatibility. - It shouldn't be required since this extension has no new functions. */ -#define cl_khr_subgroup_named_barrier 1 - -/* cl_device_info */ -#define CL_DEVICE_MAX_NAMED_BARRIER_COUNT_KHR 0x2035 - - -/********************************** - * cl_arm_import_memory extension * - **********************************/ -#define cl_arm_import_memory 1 - -typedef intptr_t cl_import_properties_arm; - -/* Default and valid proporties name for cl_arm_import_memory */ -#define CL_IMPORT_TYPE_ARM 0x40B2 - -/* Host process memory type default value for CL_IMPORT_TYPE_ARM property */ -#define CL_IMPORT_TYPE_HOST_ARM 0x40B3 - -/* DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ -#define CL_IMPORT_TYPE_DMA_BUF_ARM 0x40B4 - -/* Protected DMA BUF memory type value for CL_IMPORT_TYPE_ARM property */ -#define CL_IMPORT_TYPE_PROTECTED_ARM 0x40B5 - -/* This extension adds a new function that allows for direct memory import into - * OpenCL via the clImportMemoryARM function. - * - * Memory imported through this interface will be mapped into the device's page - * tables directly, providing zero copy access. It will never fall back to copy - * operations and aliased buffers. - * - * Types of memory supported for import are specified as additional extension - * strings. - * - * This extension produces cl_mem allocations which are compatible with all other - * users of cl_mem in the standard API. - * - * This extension maps pages with the same properties as the normal buffer creation - * function clCreateBuffer. - */ -extern CL_API_ENTRY cl_mem CL_API_CALL -clImportMemoryARM( cl_context context, - cl_mem_flags flags, - const cl_import_properties_arm *properties, - void *memory, - size_t size, - cl_int *errcode_ret) CL_EXT_SUFFIX__VERSION_1_0; - - -/****************************************** - * cl_arm_shared_virtual_memory extension * - ******************************************/ -#define cl_arm_shared_virtual_memory 1 - -/* Used by clGetDeviceInfo */ -#define CL_DEVICE_SVM_CAPABILITIES_ARM 0x40B6 - -/* Used by clGetMemObjectInfo */ -#define CL_MEM_USES_SVM_POINTER_ARM 0x40B7 - -/* Used by clSetKernelExecInfoARM: */ -#define CL_KERNEL_EXEC_INFO_SVM_PTRS_ARM 0x40B8 -#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM_ARM 0x40B9 - -/* To be used by clGetEventInfo: */ -#define CL_COMMAND_SVM_FREE_ARM 0x40BA -#define CL_COMMAND_SVM_MEMCPY_ARM 0x40BB -#define CL_COMMAND_SVM_MEMFILL_ARM 0x40BC -#define CL_COMMAND_SVM_MAP_ARM 0x40BD -#define CL_COMMAND_SVM_UNMAP_ARM 0x40BE - -/* Flag values returned by clGetDeviceInfo with CL_DEVICE_SVM_CAPABILITIES_ARM as the param_name. */ -#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER_ARM (1 << 0) -#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER_ARM (1 << 1) -#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM_ARM (1 << 2) -#define CL_DEVICE_SVM_ATOMICS_ARM (1 << 3) - -/* Flag values used by clSVMAllocARM: */ -#define CL_MEM_SVM_FINE_GRAIN_BUFFER_ARM (1 << 10) -#define CL_MEM_SVM_ATOMICS_ARM (1 << 11) - -typedef cl_bitfield cl_svm_mem_flags_arm; -typedef cl_uint cl_kernel_exec_info_arm; -typedef cl_bitfield cl_device_svm_capabilities_arm; - -extern CL_API_ENTRY void * CL_API_CALL -clSVMAllocARM(cl_context context, - cl_svm_mem_flags_arm flags, - size_t size, - cl_uint alignment) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY void CL_API_CALL -clSVMFreeARM(cl_context context, - void * svm_pointer) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMFreeARM(cl_command_queue command_queue, - cl_uint num_svm_pointers, - void * svm_pointers[], - void (CL_CALLBACK * pfn_free_func)(cl_command_queue queue, - cl_uint num_svm_pointers, - void * svm_pointers[], - void * user_data), - void * user_data, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMemcpyARM(cl_command_queue command_queue, - cl_bool blocking_copy, - void * dst_ptr, - const void * src_ptr, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMemFillARM(cl_command_queue command_queue, - void * svm_ptr, - const void * pattern, - size_t pattern_size, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMapARM(cl_command_queue command_queue, - cl_bool blocking_map, - cl_map_flags flags, - void * svm_ptr, - size_t size, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMUnmapARM(cl_command_queue command_queue, - void * svm_ptr, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelArgSVMPointerARM(cl_kernel kernel, - cl_uint arg_index, - const void * arg_value) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelExecInfoARM(cl_kernel kernel, - cl_kernel_exec_info_arm param_name, - size_t param_value_size, - const void * param_value) CL_EXT_SUFFIX__VERSION_1_2; - -/******************************** - * cl_arm_get_core_id extension * - ********************************/ - -#ifdef CL_VERSION_1_2 - -#define cl_arm_get_core_id 1 - -/* Device info property for bitfield of cores present */ -#define CL_DEVICE_COMPUTE_UNITS_BITFIELD_ARM 0x40BF - -#endif /* CL_VERSION_1_2 */ - -/********************************* -* cl_arm_job_slot_selection -*********************************/ - -#define cl_arm_job_slot_selection 1 - -/* cl_device_info */ -#define CL_DEVICE_JOB_SLOTS_ARM 0x41E0 - -/* cl_command_queue_properties */ -#define CL_QUEUE_JOB_SLOT_ARM 0x41E1 - -#ifdef __cplusplus -} -#endif - - -#endif /* __CL_EXT_H */ diff --git a/3rdparty/CL/cl_ext_intel.h b/3rdparty/CL/cl_ext_intel.h deleted file mode 100644 index 9d1e4b5877..0000000000 --- a/3rdparty/CL/cl_ext_intel.h +++ /dev/null @@ -1,423 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2019 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ -/*****************************************************************************\ - -Copyright (c) 2013-2019 Intel Corporation All Rights Reserved. - -THESE MATERIALS ARE 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 INTEL OR ITS -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 THESE -MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -File Name: cl_ext_intel.h - -Abstract: - -Notes: - -\*****************************************************************************/ - -#ifndef __CL_EXT_INTEL_H -#define __CL_EXT_INTEL_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/*************************************** -* cl_intel_thread_local_exec extension * -****************************************/ - -#define cl_intel_thread_local_exec 1 - -#define CL_QUEUE_THREAD_LOCAL_EXEC_ENABLE_INTEL (((cl_bitfield)1) << 31) - -/*********************************************** -* cl_intel_device_partition_by_names extension * -************************************************/ - -#define cl_intel_device_partition_by_names 1 - -#define CL_DEVICE_PARTITION_BY_NAMES_INTEL 0x4052 -#define CL_PARTITION_BY_NAMES_LIST_END_INTEL -1 - -/************************************************ -* cl_intel_accelerator extension * -* cl_intel_motion_estimation extension * -* cl_intel_advanced_motion_estimation extension * -*************************************************/ - -#define cl_intel_accelerator 1 -#define cl_intel_motion_estimation 1 -#define cl_intel_advanced_motion_estimation 1 - -typedef struct _cl_accelerator_intel* cl_accelerator_intel; -typedef cl_uint cl_accelerator_type_intel; -typedef cl_uint cl_accelerator_info_intel; - -typedef struct _cl_motion_estimation_desc_intel { - cl_uint mb_block_type; - cl_uint subpixel_mode; - cl_uint sad_adjust_mode; - cl_uint search_path_type; -} cl_motion_estimation_desc_intel; - -/* error codes */ -#define CL_INVALID_ACCELERATOR_INTEL -1094 -#define CL_INVALID_ACCELERATOR_TYPE_INTEL -1095 -#define CL_INVALID_ACCELERATOR_DESCRIPTOR_INTEL -1096 -#define CL_ACCELERATOR_TYPE_NOT_SUPPORTED_INTEL -1097 - -/* cl_accelerator_type_intel */ -#define CL_ACCELERATOR_TYPE_MOTION_ESTIMATION_INTEL 0x0 - -/* cl_accelerator_info_intel */ -#define CL_ACCELERATOR_DESCRIPTOR_INTEL 0x4090 -#define CL_ACCELERATOR_REFERENCE_COUNT_INTEL 0x4091 -#define CL_ACCELERATOR_CONTEXT_INTEL 0x4092 -#define CL_ACCELERATOR_TYPE_INTEL 0x4093 - -/* cl_motion_detect_desc_intel flags */ -#define CL_ME_MB_TYPE_16x16_INTEL 0x0 -#define CL_ME_MB_TYPE_8x8_INTEL 0x1 -#define CL_ME_MB_TYPE_4x4_INTEL 0x2 - -#define CL_ME_SUBPIXEL_MODE_INTEGER_INTEL 0x0 -#define CL_ME_SUBPIXEL_MODE_HPEL_INTEL 0x1 -#define CL_ME_SUBPIXEL_MODE_QPEL_INTEL 0x2 - -#define CL_ME_SAD_ADJUST_MODE_NONE_INTEL 0x0 -#define CL_ME_SAD_ADJUST_MODE_HAAR_INTEL 0x1 - -#define CL_ME_SEARCH_PATH_RADIUS_2_2_INTEL 0x0 -#define CL_ME_SEARCH_PATH_RADIUS_4_4_INTEL 0x1 -#define CL_ME_SEARCH_PATH_RADIUS_16_12_INTEL 0x5 - -#define CL_ME_SKIP_BLOCK_TYPE_16x16_INTEL 0x0 -#define CL_ME_CHROMA_INTRA_PREDICT_ENABLED_INTEL 0x1 -#define CL_ME_LUMA_INTRA_PREDICT_ENABLED_INTEL 0x2 -#define CL_ME_SKIP_BLOCK_TYPE_8x8_INTEL 0x4 - -#define CL_ME_FORWARD_INPUT_MODE_INTEL 0x1 -#define CL_ME_BACKWARD_INPUT_MODE_INTEL 0x2 -#define CL_ME_BIDIRECTION_INPUT_MODE_INTEL 0x3 - -#define CL_ME_BIDIR_WEIGHT_QUARTER_INTEL 16 -#define CL_ME_BIDIR_WEIGHT_THIRD_INTEL 21 -#define CL_ME_BIDIR_WEIGHT_HALF_INTEL 32 -#define CL_ME_BIDIR_WEIGHT_TWO_THIRD_INTEL 43 -#define CL_ME_BIDIR_WEIGHT_THREE_QUARTER_INTEL 48 - -#define CL_ME_COST_PENALTY_NONE_INTEL 0x0 -#define CL_ME_COST_PENALTY_LOW_INTEL 0x1 -#define CL_ME_COST_PENALTY_NORMAL_INTEL 0x2 -#define CL_ME_COST_PENALTY_HIGH_INTEL 0x3 - -#define CL_ME_COST_PRECISION_QPEL_INTEL 0x0 -#define CL_ME_COST_PRECISION_HPEL_INTEL 0x1 -#define CL_ME_COST_PRECISION_PEL_INTEL 0x2 -#define CL_ME_COST_PRECISION_DPEL_INTEL 0x3 - -#define CL_ME_LUMA_PREDICTOR_MODE_VERTICAL_INTEL 0x0 -#define CL_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1 -#define CL_ME_LUMA_PREDICTOR_MODE_DC_INTEL 0x2 -#define CL_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_LEFT_INTEL 0x3 - -#define CL_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_RIGHT_INTEL 0x4 -#define CL_ME_LUMA_PREDICTOR_MODE_PLANE_INTEL 0x4 -#define CL_ME_LUMA_PREDICTOR_MODE_VERTICAL_RIGHT_INTEL 0x5 -#define CL_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_DOWN_INTEL 0x6 -#define CL_ME_LUMA_PREDICTOR_MODE_VERTICAL_LEFT_INTEL 0x7 -#define CL_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_UP_INTEL 0x8 - -#define CL_ME_CHROMA_PREDICTOR_MODE_DC_INTEL 0x0 -#define CL_ME_CHROMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1 -#define CL_ME_CHROMA_PREDICTOR_MODE_VERTICAL_INTEL 0x2 -#define CL_ME_CHROMA_PREDICTOR_MODE_PLANE_INTEL 0x3 - -/* cl_device_info */ -#define CL_DEVICE_ME_VERSION_INTEL 0x407E - -#define CL_ME_VERSION_LEGACY_INTEL 0x0 -#define CL_ME_VERSION_ADVANCED_VER_1_INTEL 0x1 -#define CL_ME_VERSION_ADVANCED_VER_2_INTEL 0x2 - -extern CL_API_ENTRY cl_accelerator_intel CL_API_CALL -clCreateAcceleratorINTEL( - cl_context context, - cl_accelerator_type_intel accelerator_type, - size_t descriptor_size, - const void* descriptor, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_accelerator_intel (CL_API_CALL *clCreateAcceleratorINTEL_fn)( - cl_context context, - cl_accelerator_type_intel accelerator_type, - size_t descriptor_size, - const void* descriptor, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetAcceleratorInfoINTEL( - cl_accelerator_intel accelerator, - cl_accelerator_info_intel param_name, - size_t param_value_size, - void* param_value, - size_t* param_value_size_ret) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetAcceleratorInfoINTEL_fn)( - cl_accelerator_intel accelerator, - cl_accelerator_info_intel param_name, - size_t param_value_size, - void* param_value, - size_t* param_value_size_ret) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainAcceleratorINTEL( - cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clRetainAcceleratorINTEL_fn)( - cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseAcceleratorINTEL( - cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clReleaseAcceleratorINTEL_fn)( - cl_accelerator_intel accelerator) CL_EXT_SUFFIX__VERSION_1_2; - -/****************************************** -* cl_intel_simultaneous_sharing extension * -*******************************************/ - -#define cl_intel_simultaneous_sharing 1 - -#define CL_DEVICE_SIMULTANEOUS_INTEROPS_INTEL 0x4104 -#define CL_DEVICE_NUM_SIMULTANEOUS_INTEROPS_INTEL 0x4105 - -/*********************************** -* cl_intel_egl_image_yuv extension * -************************************/ - -#define cl_intel_egl_image_yuv 1 - -#define CL_EGL_YUV_PLANE_INTEL 0x4107 - -/******************************** -* cl_intel_packed_yuv extension * -*********************************/ - -#define cl_intel_packed_yuv 1 - -#define CL_YUYV_INTEL 0x4076 -#define CL_UYVY_INTEL 0x4077 -#define CL_YVYU_INTEL 0x4078 -#define CL_VYUY_INTEL 0x4079 - -/******************************************** -* cl_intel_required_subgroup_size extension * -*********************************************/ - -#define cl_intel_required_subgroup_size 1 - -#define CL_DEVICE_SUB_GROUP_SIZES_INTEL 0x4108 -#define CL_KERNEL_SPILL_MEM_SIZE_INTEL 0x4109 -#define CL_KERNEL_COMPILE_SUB_GROUP_SIZE_INTEL 0x410A - -/**************************************** -* cl_intel_driver_diagnostics extension * -*****************************************/ - -#define cl_intel_driver_diagnostics 1 - -typedef cl_uint cl_diagnostics_verbose_level; - -#define CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL 0x4106 - -#define CL_CONTEXT_DIAGNOSTICS_LEVEL_ALL_INTEL ( 0xff ) -#define CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL ( 1 ) -#define CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL ( 1 << 1 ) -#define CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL ( 1 << 2 ) - -/******************************** -* cl_intel_planar_yuv extension * -*********************************/ - -#define CL_NV12_INTEL 0x410E - -#define CL_MEM_NO_ACCESS_INTEL ( 1 << 24 ) -#define CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL ( 1 << 25 ) - -#define CL_DEVICE_PLANAR_YUV_MAX_WIDTH_INTEL 0x417E -#define CL_DEVICE_PLANAR_YUV_MAX_HEIGHT_INTEL 0x417F - -/******************************************************* -* cl_intel_device_side_avc_motion_estimation extension * -********************************************************/ - -#define CL_DEVICE_AVC_ME_VERSION_INTEL 0x410B -#define CL_DEVICE_AVC_ME_SUPPORTS_TEXTURE_SAMPLER_USE_INTEL 0x410C -#define CL_DEVICE_AVC_ME_SUPPORTS_PREEMPTION_INTEL 0x410D - -#define CL_AVC_ME_VERSION_0_INTEL 0x0; // No support. -#define CL_AVC_ME_VERSION_1_INTEL 0x1; // First supported version. - -#define CL_AVC_ME_MAJOR_16x16_INTEL 0x0 -#define CL_AVC_ME_MAJOR_16x8_INTEL 0x1 -#define CL_AVC_ME_MAJOR_8x16_INTEL 0x2 -#define CL_AVC_ME_MAJOR_8x8_INTEL 0x3 - -#define CL_AVC_ME_MINOR_8x8_INTEL 0x0 -#define CL_AVC_ME_MINOR_8x4_INTEL 0x1 -#define CL_AVC_ME_MINOR_4x8_INTEL 0x2 -#define CL_AVC_ME_MINOR_4x4_INTEL 0x3 - -#define CL_AVC_ME_MAJOR_FORWARD_INTEL 0x0 -#define CL_AVC_ME_MAJOR_BACKWARD_INTEL 0x1 -#define CL_AVC_ME_MAJOR_BIDIRECTIONAL_INTEL 0x2 - -#define CL_AVC_ME_PARTITION_MASK_ALL_INTEL 0x0 -#define CL_AVC_ME_PARTITION_MASK_16x16_INTEL 0x7E -#define CL_AVC_ME_PARTITION_MASK_16x8_INTEL 0x7D -#define CL_AVC_ME_PARTITION_MASK_8x16_INTEL 0x7B -#define CL_AVC_ME_PARTITION_MASK_8x8_INTEL 0x77 -#define CL_AVC_ME_PARTITION_MASK_8x4_INTEL 0x6F -#define CL_AVC_ME_PARTITION_MASK_4x8_INTEL 0x5F -#define CL_AVC_ME_PARTITION_MASK_4x4_INTEL 0x3F - -#define CL_AVC_ME_SEARCH_WINDOW_EXHAUSTIVE_INTEL 0x0 -#define CL_AVC_ME_SEARCH_WINDOW_SMALL_INTEL 0x1 -#define CL_AVC_ME_SEARCH_WINDOW_TINY_INTEL 0x2 -#define CL_AVC_ME_SEARCH_WINDOW_EXTRA_TINY_INTEL 0x3 -#define CL_AVC_ME_SEARCH_WINDOW_DIAMOND_INTEL 0x4 -#define CL_AVC_ME_SEARCH_WINDOW_LARGE_DIAMOND_INTEL 0x5 -#define CL_AVC_ME_SEARCH_WINDOW_RESERVED0_INTEL 0x6 -#define CL_AVC_ME_SEARCH_WINDOW_RESERVED1_INTEL 0x7 -#define CL_AVC_ME_SEARCH_WINDOW_CUSTOM_INTEL 0x8 -#define CL_AVC_ME_SEARCH_WINDOW_16x12_RADIUS_INTEL 0x9 -#define CL_AVC_ME_SEARCH_WINDOW_4x4_RADIUS_INTEL 0x2 -#define CL_AVC_ME_SEARCH_WINDOW_2x2_RADIUS_INTEL 0xa - -#define CL_AVC_ME_SAD_ADJUST_MODE_NONE_INTEL 0x0 -#define CL_AVC_ME_SAD_ADJUST_MODE_HAAR_INTEL 0x2 - -#define CL_AVC_ME_SUBPIXEL_MODE_INTEGER_INTEL 0x0 -#define CL_AVC_ME_SUBPIXEL_MODE_HPEL_INTEL 0x1 -#define CL_AVC_ME_SUBPIXEL_MODE_QPEL_INTEL 0x3 - -#define CL_AVC_ME_COST_PRECISION_QPEL_INTEL 0x0 -#define CL_AVC_ME_COST_PRECISION_HPEL_INTEL 0x1 -#define CL_AVC_ME_COST_PRECISION_PEL_INTEL 0x2 -#define CL_AVC_ME_COST_PRECISION_DPEL_INTEL 0x3 - -#define CL_AVC_ME_BIDIR_WEIGHT_QUARTER_INTEL 0x10 -#define CL_AVC_ME_BIDIR_WEIGHT_THIRD_INTEL 0x15 -#define CL_AVC_ME_BIDIR_WEIGHT_HALF_INTEL 0x20 -#define CL_AVC_ME_BIDIR_WEIGHT_TWO_THIRD_INTEL 0x2B -#define CL_AVC_ME_BIDIR_WEIGHT_THREE_QUARTER_INTEL 0x30 - -#define CL_AVC_ME_BORDER_REACHED_LEFT_INTEL 0x0 -#define CL_AVC_ME_BORDER_REACHED_RIGHT_INTEL 0x2 -#define CL_AVC_ME_BORDER_REACHED_TOP_INTEL 0x4 -#define CL_AVC_ME_BORDER_REACHED_BOTTOM_INTEL 0x8 - -#define CL_AVC_ME_SKIP_BLOCK_PARTITION_16x16_INTEL 0x0 -#define CL_AVC_ME_SKIP_BLOCK_PARTITION_8x8_INTEL 0x4000 - -#define CL_AVC_ME_SKIP_BLOCK_16x16_FORWARD_ENABLE_INTEL ( 0x1 << 24 ) -#define CL_AVC_ME_SKIP_BLOCK_16x16_BACKWARD_ENABLE_INTEL ( 0x2 << 24 ) -#define CL_AVC_ME_SKIP_BLOCK_16x16_DUAL_ENABLE_INTEL ( 0x3 << 24 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_FORWARD_ENABLE_INTEL ( 0x55 << 24 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_BACKWARD_ENABLE_INTEL ( 0xAA << 24 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_DUAL_ENABLE_INTEL ( 0xFF << 24 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_0_FORWARD_ENABLE_INTEL ( 0x1 << 24 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_0_BACKWARD_ENABLE_INTEL ( 0x2 << 24 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_1_FORWARD_ENABLE_INTEL ( 0x1 << 26 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_1_BACKWARD_ENABLE_INTEL ( 0x2 << 26 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_2_FORWARD_ENABLE_INTEL ( 0x1 << 28 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_2_BACKWARD_ENABLE_INTEL ( 0x2 << 28 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_3_FORWARD_ENABLE_INTEL ( 0x1 << 30 ) -#define CL_AVC_ME_SKIP_BLOCK_8x8_3_BACKWARD_ENABLE_INTEL ( 0x2 << 30 ) - -#define CL_AVC_ME_BLOCK_BASED_SKIP_4x4_INTEL 0x00 -#define CL_AVC_ME_BLOCK_BASED_SKIP_8x8_INTEL 0x80 - -#define CL_AVC_ME_INTRA_16x16_INTEL 0x0 -#define CL_AVC_ME_INTRA_8x8_INTEL 0x1 -#define CL_AVC_ME_INTRA_4x4_INTEL 0x2 - -#define CL_AVC_ME_INTRA_LUMA_PARTITION_MASK_16x16_INTEL 0x6 -#define CL_AVC_ME_INTRA_LUMA_PARTITION_MASK_8x8_INTEL 0x5 -#define CL_AVC_ME_INTRA_LUMA_PARTITION_MASK_4x4_INTEL 0x3 - -#define CL_AVC_ME_INTRA_NEIGHBOR_LEFT_MASK_ENABLE_INTEL 0x60 -#define CL_AVC_ME_INTRA_NEIGHBOR_UPPER_MASK_ENABLE_INTEL 0x10 -#define CL_AVC_ME_INTRA_NEIGHBOR_UPPER_RIGHT_MASK_ENABLE_INTEL 0x8 -#define CL_AVC_ME_INTRA_NEIGHBOR_UPPER_LEFT_MASK_ENABLE_INTEL 0x4 - -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_INTEL 0x0 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_DC_INTEL 0x2 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_LEFT_INTEL 0x3 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_DIAGONAL_DOWN_RIGHT_INTEL 0x4 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_PLANE_INTEL 0x4 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_RIGHT_INTEL 0x5 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_DOWN_INTEL 0x6 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_VERTICAL_LEFT_INTEL 0x7 -#define CL_AVC_ME_LUMA_PREDICTOR_MODE_HORIZONTAL_UP_INTEL 0x8 -#define CL_AVC_ME_CHROMA_PREDICTOR_MODE_DC_INTEL 0x0 -#define CL_AVC_ME_CHROMA_PREDICTOR_MODE_HORIZONTAL_INTEL 0x1 -#define CL_AVC_ME_CHROMA_PREDICTOR_MODE_VERTICAL_INTEL 0x2 -#define CL_AVC_ME_CHROMA_PREDICTOR_MODE_PLANE_INTEL 0x3 - -#define CL_AVC_ME_FRAME_FORWARD_INTEL 0x1 -#define CL_AVC_ME_FRAME_BACKWARD_INTEL 0x2 -#define CL_AVC_ME_FRAME_DUAL_INTEL 0x3 - -#define CL_AVC_ME_SLICE_TYPE_PRED_INTEL 0x0 -#define CL_AVC_ME_SLICE_TYPE_BPRED_INTEL 0x1 -#define CL_AVC_ME_SLICE_TYPE_INTRA_INTEL 0x2 - -#define CL_AVC_ME_INTERLACED_SCAN_TOP_FIELD_INTEL 0x0 -#define CL_AVC_ME_INTERLACED_SCAN_BOTTOM_FIELD_INTEL 0x1 - -#ifdef __cplusplus -} -#endif - -#endif /* __CL_EXT_INTEL_H */ diff --git a/3rdparty/CL/cl_gl.h b/3rdparty/CL/cl_gl.h deleted file mode 100644 index fbdaf62977..0000000000 --- a/3rdparty/CL/cl_gl.h +++ /dev/null @@ -1,171 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2019 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -#ifndef __OPENCL_CL_GL_H -#define __OPENCL_CL_GL_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef cl_uint cl_gl_object_type; -typedef cl_uint cl_gl_texture_info; -typedef cl_uint cl_gl_platform_info; -typedef struct __GLsync *cl_GLsync; - -/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ -#define CL_GL_OBJECT_BUFFER 0x2000 -#define CL_GL_OBJECT_TEXTURE2D 0x2001 -#define CL_GL_OBJECT_TEXTURE3D 0x2002 -#define CL_GL_OBJECT_RENDERBUFFER 0x2003 -#ifdef CL_VERSION_1_2 -#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E -#define CL_GL_OBJECT_TEXTURE1D 0x200F -#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 -#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 -#endif - -/* cl_gl_texture_info */ -#define CL_GL_TEXTURE_TARGET 0x2004 -#define CL_GL_MIPMAP_LEVEL 0x2005 -#ifdef CL_VERSION_1_2 -#define CL_GL_NUM_SAMPLES 0x2012 -#endif - - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLBuffer(cl_context context, - cl_mem_flags flags, - cl_GLuint bufobj, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -#ifdef CL_VERSION_1_2 - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLTexture(cl_context context, - cl_mem_flags flags, - cl_GLenum target, - cl_GLint miplevel, - cl_GLuint texture, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -#endif - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLRenderbuffer(cl_context context, - cl_mem_flags flags, - cl_GLuint renderbuffer, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLObjectInfo(cl_mem memobj, - cl_gl_object_type * gl_object_type, - cl_GLuint * gl_object_name) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLTextureInfo(cl_mem memobj, - cl_gl_texture_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireGLObjects(cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseGLObjects(cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - - -/* Deprecated OpenCL 1.1 APIs */ -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateFromGLTexture2D(cl_context context, - cl_mem_flags flags, - cl_GLenum target, - cl_GLint miplevel, - cl_GLuint texture, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateFromGLTexture3D(cl_context context, - cl_mem_flags flags, - cl_GLenum target, - cl_GLint miplevel, - cl_GLuint texture, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -/* cl_khr_gl_sharing extension */ - -#define cl_khr_gl_sharing 1 - -typedef cl_uint cl_gl_context_info; - -/* Additional Error Codes */ -#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 - -/* cl_gl_context_info */ -#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 -#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 - -/* Additional cl_context_properties */ -#define CL_GL_CONTEXT_KHR 0x2008 -#define CL_EGL_DISPLAY_KHR 0x2009 -#define CL_GLX_DISPLAY_KHR 0x200A -#define CL_WGL_HDC_KHR 0x200B -#define CL_CGL_SHAREGROUP_KHR 0x200C - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLContextInfoKHR(const cl_context_properties * properties, - cl_gl_context_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( - const cl_context_properties * properties, - cl_gl_context_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret); - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_GL_H */ diff --git a/3rdparty/CL/cl_gl_ext.h b/3rdparty/CL/cl_gl_ext.h deleted file mode 100644 index c26d31abed..0000000000 --- a/3rdparty/CL/cl_gl_ext.h +++ /dev/null @@ -1,52 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2019 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -#ifndef __OPENCL_CL_GL_EXT_H -#define __OPENCL_CL_GL_EXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* - * cl_khr_gl_event extension - */ -#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateEventFromGLsyncKHR(cl_context context, - cl_GLsync cl_GLsync, - cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_1; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_GL_EXT_H */ diff --git a/3rdparty/CL/cl_platform.h b/3rdparty/CL/cl_platform.h deleted file mode 100644 index 7f4ddea5b3..0000000000 --- a/3rdparty/CL/cl_platform.h +++ /dev/null @@ -1,1384 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2018 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -#ifndef __CL_PLATFORM_H -#define __CL_PLATFORM_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_WIN32) - #define CL_API_ENTRY - #define CL_API_CALL __stdcall - #define CL_CALLBACK __stdcall -#else - #define CL_API_ENTRY - #define CL_API_CALL - #define CL_CALLBACK -#endif - -/* - * Deprecation flags refer to the last version of the header in which the - * feature was not deprecated. - * - * E.g. VERSION_1_1_DEPRECATED means the feature is present in 1.1 without - * deprecation but is deprecated in versions later than 1.1. - */ - -#define CL_EXTENSION_WEAK_LINK -#define CL_API_SUFFIX__VERSION_1_0 -#define CL_EXT_SUFFIX__VERSION_1_0 -#define CL_API_SUFFIX__VERSION_1_1 -#define CL_EXT_SUFFIX__VERSION_1_1 -#define CL_API_SUFFIX__VERSION_1_2 -#define CL_EXT_SUFFIX__VERSION_1_2 -#define CL_API_SUFFIX__VERSION_2_0 -#define CL_EXT_SUFFIX__VERSION_2_0 -#define CL_API_SUFFIX__VERSION_2_1 -#define CL_EXT_SUFFIX__VERSION_2_1 -#define CL_API_SUFFIX__VERSION_2_2 -#define CL_EXT_SUFFIX__VERSION_2_2 - - -#ifdef __GNUC__ - #define CL_EXT_SUFFIX_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX_DEPRECATED -#elif defined(_WIN32) - #define CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX_DEPRECATED __declspec(deprecated) -#else - #define CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX_DEPRECATED -#endif - -#ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED -#else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED CL_EXT_PREFIX_DEPRECATED -#endif - -#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED -#else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED CL_EXT_PREFIX_DEPRECATED -#endif - -#ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED -#else - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED CL_EXT_PREFIX_DEPRECATED - #endif - -#ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED -#else - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED CL_EXT_PREFIX_DEPRECATED -#endif - -#ifdef CL_USE_DEPRECATED_OPENCL_2_1_APIS - #define CL_EXT_SUFFIX__VERSION_2_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_1_DEPRECATED -#else - #define CL_EXT_SUFFIX__VERSION_2_1_DEPRECATED CL_EXT_SUFFIX_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_1_DEPRECATED CL_EXT_PREFIX_DEPRECATED -#endif - -#if (defined (_WIN32) && defined(_MSC_VER)) - -/* scalar types */ -typedef signed __int8 cl_char; -typedef unsigned __int8 cl_uchar; -typedef signed __int16 cl_short; -typedef unsigned __int16 cl_ushort; -typedef signed __int32 cl_int; -typedef unsigned __int32 cl_uint; -typedef signed __int64 cl_long; -typedef unsigned __int64 cl_ulong; - -typedef unsigned __int16 cl_half; -typedef float cl_float; -typedef double cl_double; - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 340282346638528859811704183484516925440.0f -#define CL_FLT_MIN 1.175494350822287507969e-38f -#define CL_FLT_EPSILON 1.1920928955078125e-7f - -#define CL_HALF_DIG 3 -#define CL_HALF_MANT_DIG 11 -#define CL_HALF_MAX_10_EXP +4 -#define CL_HALF_MAX_EXP +16 -#define CL_HALF_MIN_10_EXP -4 -#define CL_HALF_MIN_EXP -13 -#define CL_HALF_RADIX 2 -#define CL_HALF_MAX 65504.0f -#define CL_HALF_MIN 6.103515625e-05f -#define CL_HALF_EPSILON 9.765625e-04f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 1.7976931348623158e+308 -#define CL_DBL_MIN 2.225073858507201383090e-308 -#define CL_DBL_EPSILON 2.220446049250313080847e-16 - -#define CL_M_E 2.7182818284590452354 -#define CL_M_LOG2E 1.4426950408889634074 -#define CL_M_LOG10E 0.43429448190325182765 -#define CL_M_LN2 0.69314718055994530942 -#define CL_M_LN10 2.30258509299404568402 -#define CL_M_PI 3.14159265358979323846 -#define CL_M_PI_2 1.57079632679489661923 -#define CL_M_PI_4 0.78539816339744830962 -#define CL_M_1_PI 0.31830988618379067154 -#define CL_M_2_PI 0.63661977236758134308 -#define CL_M_2_SQRTPI 1.12837916709551257390 -#define CL_M_SQRT2 1.41421356237309504880 -#define CL_M_SQRT1_2 0.70710678118654752440 - -#define CL_M_E_F 2.718281828f -#define CL_M_LOG2E_F 1.442695041f -#define CL_M_LOG10E_F 0.434294482f -#define CL_M_LN2_F 0.693147181f -#define CL_M_LN10_F 2.302585093f -#define CL_M_PI_F 3.141592654f -#define CL_M_PI_2_F 1.570796327f -#define CL_M_PI_4_F 0.785398163f -#define CL_M_1_PI_F 0.318309886f -#define CL_M_2_PI_F 0.636619772f -#define CL_M_2_SQRTPI_F 1.128379167f -#define CL_M_SQRT2_F 1.414213562f -#define CL_M_SQRT1_2_F 0.707106781f - -#define CL_NAN (CL_INFINITY - CL_INFINITY) -#define CL_HUGE_VALF ((cl_float) 1e50) -#define CL_HUGE_VAL ((cl_double) 1e500) -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#else - -#include - -/* scalar types */ -typedef int8_t cl_char; -typedef uint8_t cl_uchar; -typedef int16_t cl_short; -typedef uint16_t cl_ushort; -typedef int32_t cl_int; -typedef uint32_t cl_uint; -typedef int64_t cl_long; -typedef uint64_t cl_ulong; - -typedef uint16_t cl_half; -typedef float cl_float; -typedef double cl_double; - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 340282346638528859811704183484516925440.0f -#define CL_FLT_MIN 1.175494350822287507969e-38f -#define CL_FLT_EPSILON 1.1920928955078125e-7f - -#define CL_HALF_DIG 3 -#define CL_HALF_MANT_DIG 11 -#define CL_HALF_MAX_10_EXP +4 -#define CL_HALF_MAX_EXP +16 -#define CL_HALF_MIN_10_EXP -4 -#define CL_HALF_MIN_EXP -13 -#define CL_HALF_RADIX 2 -#define CL_HALF_MAX 65504.0f -#define CL_HALF_MIN 6.103515625e-05f -#define CL_HALF_EPSILON 9.765625e-04f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 -#define CL_DBL_MIN 2.225073858507201383090e-308 -#define CL_DBL_EPSILON 2.220446049250313080847e-16 - -#define CL_M_E 2.7182818284590452354 -#define CL_M_LOG2E 1.4426950408889634074 -#define CL_M_LOG10E 0.43429448190325182765 -#define CL_M_LN2 0.69314718055994530942 -#define CL_M_LN10 2.30258509299404568402 -#define CL_M_PI 3.14159265358979323846 -#define CL_M_PI_2 1.57079632679489661923 -#define CL_M_PI_4 0.78539816339744830962 -#define CL_M_1_PI 0.31830988618379067154 -#define CL_M_2_PI 0.63661977236758134308 -#define CL_M_2_SQRTPI 1.12837916709551257390 -#define CL_M_SQRT2 1.41421356237309504880 -#define CL_M_SQRT1_2 0.70710678118654752440 - -#define CL_M_E_F 2.718281828f -#define CL_M_LOG2E_F 1.442695041f -#define CL_M_LOG10E_F 0.434294482f -#define CL_M_LN2_F 0.693147181f -#define CL_M_LN10_F 2.302585093f -#define CL_M_PI_F 3.141592654f -#define CL_M_PI_2_F 1.570796327f -#define CL_M_PI_4_F 0.785398163f -#define CL_M_1_PI_F 0.318309886f -#define CL_M_2_PI_F 0.636619772f -#define CL_M_2_SQRTPI_F 1.128379167f -#define CL_M_SQRT2_F 1.414213562f -#define CL_M_SQRT1_2_F 0.707106781f - -#if defined( __GNUC__ ) - #define CL_HUGE_VALF __builtin_huge_valf() - #define CL_HUGE_VAL __builtin_huge_val() - #define CL_NAN __builtin_nanf( "" ) -#else - #define CL_HUGE_VALF ((cl_float) 1e50) - #define CL_HUGE_VAL ((cl_double) 1e500) - float nanf( const char * ); - #define CL_NAN nanf( "" ) -#endif -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#endif - -#include - -/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */ -typedef unsigned int cl_GLuint; -typedef int cl_GLint; -typedef unsigned int cl_GLenum; - -/* - * Vector types - * - * Note: OpenCL requires that all types be naturally aligned. - * This means that vector types must be naturally aligned. - * For example, a vector of four floats must be aligned to - * a 16 byte boundary (calculated as 4 * the natural 4-byte - * alignment of the float). The alignment qualifiers here - * will only function properly if your compiler supports them - * and if you don't actively work to defeat them. For example, - * in order for a cl_float4 to be 16 byte aligned in a struct, - * the start of the struct must itself be 16-byte aligned. - * - * Maintaining proper alignment is the user's responsibility. - */ - -/* Define basic vector types */ -#if defined( __VEC__ ) - #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ - typedef __vector unsigned char __cl_uchar16; - typedef __vector signed char __cl_char16; - typedef __vector unsigned short __cl_ushort8; - typedef __vector signed short __cl_short8; - typedef __vector unsigned int __cl_uint4; - typedef __vector signed int __cl_int4; - typedef __vector float __cl_float4; - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_UINT4__ 1 - #define __CL_INT4__ 1 - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef float __cl_float4 __attribute__((vector_size(16))); - #else - typedef __m128 __cl_float4; - #endif - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE2__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); - typedef cl_char __cl_char16 __attribute__((vector_size(16))); - typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); - typedef cl_short __cl_short8 __attribute__((vector_size(16))); - typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); - typedef cl_int __cl_int4 __attribute__((vector_size(16))); - typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); - typedef cl_long __cl_long2 __attribute__((vector_size(16))); - typedef cl_double __cl_double2 __attribute__((vector_size(16))); - #else - typedef __m128i __cl_uchar16; - typedef __m128i __cl_char16; - typedef __m128i __cl_ushort8; - typedef __m128i __cl_short8; - typedef __m128i __cl_uint4; - typedef __m128i __cl_int4; - typedef __m128i __cl_ulong2; - typedef __m128i __cl_long2; - typedef __m128d __cl_double2; - #endif - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_INT4__ 1 - #define __CL_UINT4__ 1 - #define __CL_ULONG2__ 1 - #define __CL_LONG2__ 1 - #define __CL_DOUBLE2__ 1 -#endif - -#if defined( __MMX__ ) - #include - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); - typedef cl_char __cl_char8 __attribute__((vector_size(8))); - typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); - typedef cl_short __cl_short4 __attribute__((vector_size(8))); - typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); - typedef cl_int __cl_int2 __attribute__((vector_size(8))); - typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); - typedef cl_long __cl_long1 __attribute__((vector_size(8))); - typedef cl_float __cl_float2 __attribute__((vector_size(8))); - #else - typedef __m64 __cl_uchar8; - typedef __m64 __cl_char8; - typedef __m64 __cl_ushort4; - typedef __m64 __cl_short4; - typedef __m64 __cl_uint2; - typedef __m64 __cl_int2; - typedef __m64 __cl_ulong1; - typedef __m64 __cl_long1; - typedef __m64 __cl_float2; - #endif - #define __CL_UCHAR8__ 1 - #define __CL_CHAR8__ 1 - #define __CL_USHORT4__ 1 - #define __CL_SHORT4__ 1 - #define __CL_INT2__ 1 - #define __CL_UINT2__ 1 - #define __CL_ULONG1__ 1 - #define __CL_LONG1__ 1 - #define __CL_FLOAT2__ 1 -#endif - -#if defined( __AVX__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef cl_float __cl_float8 __attribute__((vector_size(32))); - typedef cl_double __cl_double4 __attribute__((vector_size(32))); - #else - typedef __m256 __cl_float8; - typedef __m256d __cl_double4; - #endif - #define __CL_FLOAT8__ 1 - #define __CL_DOUBLE4__ 1 -#endif - -/* Define capabilities for anonymous struct members. */ -#if !defined(__cplusplus) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L -#define __CL_HAS_ANON_STRUCT__ 1 -#define __CL_ANON_STRUCT__ -#elif defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) -#define __CL_HAS_ANON_STRUCT__ 1 -#define __CL_ANON_STRUCT__ __extension__ -#elif defined( _WIN32) && defined(_MSC_VER) - #if _MSC_VER >= 1500 - /* Microsoft Developer Studio 2008 supports anonymous structs, but - * complains by default. */ - #define __CL_HAS_ANON_STRUCT__ 1 - #define __CL_ANON_STRUCT__ - /* Disable warning C4201: nonstandard extension used : nameless - * struct/union */ - #pragma warning( push ) - #pragma warning( disable : 4201 ) - #endif -#else -#define __CL_HAS_ANON_STRUCT__ 0 -#define __CL_ANON_STRUCT__ -#endif - -/* Define alignment keys */ -#if defined( __GNUC__ ) - #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) -#elif defined( _WIN32) && (_MSC_VER) - /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ - /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ - /* #include */ - /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ - #define CL_ALIGNED(_x) -#else - #warning Need to implement some method to align data here - #define CL_ALIGNED(_x) -#endif - -/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ -#if __CL_HAS_ANON_STRUCT__ - /* .xyzw and .s0123...{f|F} are supported */ - #define CL_HAS_NAMED_VECTOR_FIELDS 1 - /* .hi and .lo are supported */ - #define CL_HAS_HI_LO_VECTOR_FIELDS 1 -#endif - -/* Define cl_vector types */ - -/* ---- cl_charn ---- */ -typedef union -{ - cl_char CL_ALIGNED(2) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_char lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2; -#endif -}cl_char2; - -typedef union -{ - cl_char CL_ALIGNED(4) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_char2 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[2]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4; -#endif -}cl_char4; - -/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ -typedef cl_char4 cl_char3; - -typedef union -{ - cl_char CL_ALIGNED(8) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_char4 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[4]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[2]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8; -#endif -}cl_char8; - -typedef union -{ - cl_char CL_ALIGNED(16) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_char8 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[8]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[4]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8[2]; -#endif -#if defined( __CL_CHAR16__ ) - __cl_char16 v16; -#endif -}cl_char16; - - -/* ---- cl_ucharn ---- */ -typedef union -{ - cl_uchar CL_ALIGNED(2) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_uchar lo, hi; }; -#endif -#if defined( __cl_uchar2__) - __cl_uchar2 v2; -#endif -}cl_uchar2; - -typedef union -{ - cl_uchar CL_ALIGNED(4) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_uchar2 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[2]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4; -#endif -}cl_uchar4; - -/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ -typedef cl_uchar4 cl_uchar3; - -typedef union -{ - cl_uchar CL_ALIGNED(8) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_uchar4 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[4]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[2]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8; -#endif -}cl_uchar8; - -typedef union -{ - cl_uchar CL_ALIGNED(16) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_uchar8 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[8]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[4]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8[2]; -#endif -#if defined( __CL_UCHAR16__ ) - __cl_uchar16 v16; -#endif -}cl_uchar16; - - -/* ---- cl_shortn ---- */ -typedef union -{ - cl_short CL_ALIGNED(4) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_short lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2; -#endif -}cl_short2; - -typedef union -{ - cl_short CL_ALIGNED(8) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_short2 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[2]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4; -#endif -}cl_short4; - -/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ -typedef cl_short4 cl_short3; - -typedef union -{ - cl_short CL_ALIGNED(16) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_short4 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[4]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[2]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8; -#endif -}cl_short8; - -typedef union -{ - cl_short CL_ALIGNED(32) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_short8 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[8]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[4]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8[2]; -#endif -#if defined( __CL_SHORT16__ ) - __cl_short16 v16; -#endif -}cl_short16; - - -/* ---- cl_ushortn ---- */ -typedef union -{ - cl_ushort CL_ALIGNED(4) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_ushort lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2; -#endif -}cl_ushort2; - -typedef union -{ - cl_ushort CL_ALIGNED(8) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_ushort2 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[2]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4; -#endif -}cl_ushort4; - -/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ -typedef cl_ushort4 cl_ushort3; - -typedef union -{ - cl_ushort CL_ALIGNED(16) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_ushort4 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[4]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[2]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8; -#endif -}cl_ushort8; - -typedef union -{ - cl_ushort CL_ALIGNED(32) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_ushort8 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[8]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[4]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8[2]; -#endif -#if defined( __CL_USHORT16__ ) - __cl_ushort16 v16; -#endif -}cl_ushort16; - - -/* ---- cl_halfn ---- */ -typedef union -{ - cl_half CL_ALIGNED(4) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_half lo, hi; }; -#endif -#if defined( __CL_HALF2__) - __cl_half2 v2; -#endif -}cl_half2; - -typedef union -{ - cl_half CL_ALIGNED(8) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_half2 lo, hi; }; -#endif -#if defined( __CL_HALF2__) - __cl_half2 v2[2]; -#endif -#if defined( __CL_HALF4__) - __cl_half4 v4; -#endif -}cl_half4; - -/* cl_half3 is identical in size, alignment and behavior to cl_half4. See section 6.1.5. */ -typedef cl_half4 cl_half3; - -typedef union -{ - cl_half CL_ALIGNED(16) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_half4 lo, hi; }; -#endif -#if defined( __CL_HALF2__) - __cl_half2 v2[4]; -#endif -#if defined( __CL_HALF4__) - __cl_half4 v4[2]; -#endif -#if defined( __CL_HALF8__ ) - __cl_half8 v8; -#endif -}cl_half8; - -typedef union -{ - cl_half CL_ALIGNED(32) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_half8 lo, hi; }; -#endif -#if defined( __CL_HALF2__) - __cl_half2 v2[8]; -#endif -#if defined( __CL_HALF4__) - __cl_half4 v4[4]; -#endif -#if defined( __CL_HALF8__ ) - __cl_half8 v8[2]; -#endif -#if defined( __CL_HALF16__ ) - __cl_half16 v16; -#endif -}cl_half16; - -/* ---- cl_intn ---- */ -typedef union -{ - cl_int CL_ALIGNED(8) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_int lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2; -#endif -}cl_int2; - -typedef union -{ - cl_int CL_ALIGNED(16) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_int2 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[2]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4; -#endif -}cl_int4; - -/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ -typedef cl_int4 cl_int3; - -typedef union -{ - cl_int CL_ALIGNED(32) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_int4 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[4]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[2]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8; -#endif -}cl_int8; - -typedef union -{ - cl_int CL_ALIGNED(64) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_int8 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[8]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[4]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8[2]; -#endif -#if defined( __CL_INT16__ ) - __cl_int16 v16; -#endif -}cl_int16; - - -/* ---- cl_uintn ---- */ -typedef union -{ - cl_uint CL_ALIGNED(8) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_uint lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2; -#endif -}cl_uint2; - -typedef union -{ - cl_uint CL_ALIGNED(16) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_uint2 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[2]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4; -#endif -}cl_uint4; - -/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ -typedef cl_uint4 cl_uint3; - -typedef union -{ - cl_uint CL_ALIGNED(32) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_uint4 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[4]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[2]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8; -#endif -}cl_uint8; - -typedef union -{ - cl_uint CL_ALIGNED(64) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_uint8 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[8]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[4]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8[2]; -#endif -#if defined( __CL_UINT16__ ) - __cl_uint16 v16; -#endif -}cl_uint16; - -/* ---- cl_longn ---- */ -typedef union -{ - cl_long CL_ALIGNED(16) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_long lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2; -#endif -}cl_long2; - -typedef union -{ - cl_long CL_ALIGNED(32) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_long2 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[2]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4; -#endif -}cl_long4; - -/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ -typedef cl_long4 cl_long3; - -typedef union -{ - cl_long CL_ALIGNED(64) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_long4 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[4]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[2]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8; -#endif -}cl_long8; - -typedef union -{ - cl_long CL_ALIGNED(128) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_long8 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[8]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[4]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8[2]; -#endif -#if defined( __CL_LONG16__ ) - __cl_long16 v16; -#endif -}cl_long16; - - -/* ---- cl_ulongn ---- */ -typedef union -{ - cl_ulong CL_ALIGNED(16) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_ulong lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2; -#endif -}cl_ulong2; - -typedef union -{ - cl_ulong CL_ALIGNED(32) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_ulong2 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[2]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4; -#endif -}cl_ulong4; - -/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ -typedef cl_ulong4 cl_ulong3; - -typedef union -{ - cl_ulong CL_ALIGNED(64) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_ulong4 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[4]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[2]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8; -#endif -}cl_ulong8; - -typedef union -{ - cl_ulong CL_ALIGNED(128) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_ulong8 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[8]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[4]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8[2]; -#endif -#if defined( __CL_ULONG16__ ) - __cl_ulong16 v16; -#endif -}cl_ulong16; - - -/* --- cl_floatn ---- */ - -typedef union -{ - cl_float CL_ALIGNED(8) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_float lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2; -#endif -}cl_float2; - -typedef union -{ - cl_float CL_ALIGNED(16) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_float2 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[2]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4; -#endif -}cl_float4; - -/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ -typedef cl_float4 cl_float3; - -typedef union -{ - cl_float CL_ALIGNED(32) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_float4 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[4]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[2]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8; -#endif -}cl_float8; - -typedef union -{ - cl_float CL_ALIGNED(64) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_float8 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[8]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[4]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8[2]; -#endif -#if defined( __CL_FLOAT16__ ) - __cl_float16 v16; -#endif -}cl_float16; - -/* --- cl_doublen ---- */ - -typedef union -{ - cl_double CL_ALIGNED(16) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_double lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2; -#endif -}cl_double2; - -typedef union -{ - cl_double CL_ALIGNED(32) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_double2 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[2]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4; -#endif -}cl_double4; - -/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ -typedef cl_double4 cl_double3; - -typedef union -{ - cl_double CL_ALIGNED(64) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_double4 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[4]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[2]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8; -#endif -}cl_double8; - -typedef union -{ - cl_double CL_ALIGNED(128) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_double8 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[8]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[4]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8[2]; -#endif -#if defined( __CL_DOUBLE16__ ) - __cl_double16 v16; -#endif -}cl_double16; - -/* Macro to facilitate debugging - * Usage: - * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. - * The first line ends with: CL_PROGRAM_STRING_DEBUG_INFO \" - * Each line thereafter of OpenCL C source must end with: \n\ - * The last line ends in "; - * - * Example: - * - * const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\ - * kernel void foo( int a, float * b ) \n\ - * { \n\ - * // my comment \n\ - * *b[ get_global_id(0)] = a; \n\ - * } \n\ - * "; - * - * This should correctly set up the line, (column) and file information for your source - * string so you can do source level debugging. - */ -#define __CL_STRINGIFY( _x ) # _x -#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) -#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" - -#ifdef __cplusplus -} -#endif - -#undef __CL_HAS_ANON_STRUCT__ -#undef __CL_ANON_STRUCT__ -#if defined( _WIN32) && defined(_MSC_VER) - #if _MSC_VER >=1500 - #pragma warning( pop ) - #endif -#endif - -#endif /* __CL_PLATFORM_H */ diff --git a/3rdparty/CL/cl_va_api_media_sharing_intel.h b/3rdparty/CL/cl_va_api_media_sharing_intel.h deleted file mode 100644 index 934f3f52a0..0000000000 --- a/3rdparty/CL/cl_va_api_media_sharing_intel.h +++ /dev/null @@ -1,172 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2019 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ -/*****************************************************************************\ - -Copyright (c) 2013-2019 Intel Corporation All Rights Reserved. - -THESE MATERIALS ARE 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 INTEL OR ITS -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 THESE -MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -File Name: cl_va_api_media_sharing_intel.h - -Abstract: - -Notes: - -\*****************************************************************************/ - - -#ifndef __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H -#define __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/****************************************** -* cl_intel_va_api_media_sharing extension * -*******************************************/ - -#define cl_intel_va_api_media_sharing 1 - -/* error codes */ -#define CL_INVALID_VA_API_MEDIA_ADAPTER_INTEL -1098 -#define CL_INVALID_VA_API_MEDIA_SURFACE_INTEL -1099 -#define CL_VA_API_MEDIA_SURFACE_ALREADY_ACQUIRED_INTEL -1100 -#define CL_VA_API_MEDIA_SURFACE_NOT_ACQUIRED_INTEL -1101 - -/* cl_va_api_device_source_intel */ -#define CL_VA_API_DISPLAY_INTEL 0x4094 - -/* cl_va_api_device_set_intel */ -#define CL_PREFERRED_DEVICES_FOR_VA_API_INTEL 0x4095 -#define CL_ALL_DEVICES_FOR_VA_API_INTEL 0x4096 - -/* cl_context_info */ -#define CL_CONTEXT_VA_API_DISPLAY_INTEL 0x4097 - -/* cl_mem_info */ -#define CL_MEM_VA_API_MEDIA_SURFACE_INTEL 0x4098 - -/* cl_image_info */ -#define CL_IMAGE_VA_API_PLANE_INTEL 0x4099 - -/* cl_command_type */ -#define CL_COMMAND_ACQUIRE_VA_API_MEDIA_SURFACES_INTEL 0x409A -#define CL_COMMAND_RELEASE_VA_API_MEDIA_SURFACES_INTEL 0x409B - -typedef cl_uint cl_va_api_device_source_intel; -typedef cl_uint cl_va_api_device_set_intel; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceIDsFromVA_APIMediaAdapterINTEL( - cl_platform_id platform, - cl_va_api_device_source_intel media_adapter_type, - void* media_adapter, - cl_va_api_device_set_intel media_adapter_set, - cl_uint num_entries, - cl_device_id* devices, - cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL * clGetDeviceIDsFromVA_APIMediaAdapterINTEL_fn)( - cl_platform_id platform, - cl_va_api_device_source_intel media_adapter_type, - void* media_adapter, - cl_va_api_device_set_intel media_adapter_set, - cl_uint num_entries, - cl_device_id* devices, - cl_uint* num_devices) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromVA_APIMediaSurfaceINTEL( - cl_context context, - cl_mem_flags flags, - VASurfaceID* surface, - cl_uint plane, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL * clCreateFromVA_APIMediaSurfaceINTEL_fn)( - cl_context context, - cl_mem_flags flags, - VASurfaceID* surface, - cl_uint plane, - cl_int* errcode_ret) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireVA_APIMediaSurfacesINTEL( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem* mem_objects, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireVA_APIMediaSurfacesINTEL_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem* mem_objects, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseVA_APIMediaSurfacesINTEL( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem* mem_objects, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseVA_APIMediaSurfacesINTEL_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem* mem_objects, - cl_uint num_events_in_wait_list, - const cl_event* event_wait_list, - cl_event* event) CL_EXT_SUFFIX__VERSION_1_2; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_VA_API_MEDIA_SHARING_INTEL_H */ - diff --git a/3rdparty/CL/cl_version.h b/3rdparty/CL/cl_version.h deleted file mode 100644 index bb766cb9bb..0000000000 --- a/3rdparty/CL/cl_version.h +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2018 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifndef __CL_VERSION_H -#define __CL_VERSION_H - -/* Detect which version to target */ -#if !defined(CL_TARGET_OPENCL_VERSION) -#pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)") -#define CL_TARGET_OPENCL_VERSION 220 -#endif -#if CL_TARGET_OPENCL_VERSION != 100 && \ - CL_TARGET_OPENCL_VERSION != 110 && \ - CL_TARGET_OPENCL_VERSION != 120 && \ - CL_TARGET_OPENCL_VERSION != 200 && \ - CL_TARGET_OPENCL_VERSION != 210 && \ - CL_TARGET_OPENCL_VERSION != 220 -#pragma message("cl_version: CL_TARGET_OPENCL_VERSION is not a valid value (100, 110, 120, 200, 210, 220). Defaulting to 220 (OpenCL 2.2)") -#undef CL_TARGET_OPENCL_VERSION -#define CL_TARGET_OPENCL_VERSION 220 -#endif - - -/* OpenCL Version */ -#if CL_TARGET_OPENCL_VERSION >= 220 && !defined(CL_VERSION_2_2) -#define CL_VERSION_2_2 1 -#endif -#if CL_TARGET_OPENCL_VERSION >= 210 && !defined(CL_VERSION_2_1) -#define CL_VERSION_2_1 1 -#endif -#if CL_TARGET_OPENCL_VERSION >= 200 && !defined(CL_VERSION_2_0) -#define CL_VERSION_2_0 1 -#endif -#if CL_TARGET_OPENCL_VERSION >= 120 && !defined(CL_VERSION_1_2) -#define CL_VERSION_1_2 1 -#endif -#if CL_TARGET_OPENCL_VERSION >= 110 && !defined(CL_VERSION_1_1) -#define CL_VERSION_1_1 1 -#endif -#if CL_TARGET_OPENCL_VERSION >= 100 && !defined(CL_VERSION_1_0) -#define CL_VERSION_1_0 1 -#endif - -/* Allow deprecated APIs for older OpenCL versions. */ -#if CL_TARGET_OPENCL_VERSION <= 210 && !defined(CL_USE_DEPRECATED_OPENCL_2_1_APIS) -#define CL_USE_DEPRECATED_OPENCL_2_1_APIS -#endif -#if CL_TARGET_OPENCL_VERSION <= 200 && !defined(CL_USE_DEPRECATED_OPENCL_2_0_APIS) -#define CL_USE_DEPRECATED_OPENCL_2_0_APIS -#endif -#if CL_TARGET_OPENCL_VERSION <= 120 && !defined(CL_USE_DEPRECATED_OPENCL_1_2_APIS) -#define CL_USE_DEPRECATED_OPENCL_1_2_APIS -#endif -#if CL_TARGET_OPENCL_VERSION <= 110 && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) -#define CL_USE_DEPRECATED_OPENCL_1_1_APIS -#endif -#if CL_TARGET_OPENCL_VERSION <= 100 && !defined(CL_USE_DEPRECATED_OPENCL_1_0_APIS) -#define CL_USE_DEPRECATED_OPENCL_1_0_APIS -#endif - -#endif /* __CL_VERSION_H */ diff --git a/3rdparty/CL/opencl.h b/3rdparty/CL/opencl.h deleted file mode 100644 index 143d1d2dc6..0000000000 --- a/3rdparty/CL/opencl.h +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_H -#define __OPENCL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_H */ diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ee5220339..f29f957ea3 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,6 @@ endif() #option(NBL_TARGET_ARCH_ARM "Build for ARM?" OFF) option(NBL_COMPILE_WITH_OPENGL "Compile with OpenGL backend?" ON) -option(NBL_COMPILE_WITH_OPENCL "Compile with OpenCL interop?" ON) option(NBL_PCH "Enable pre-compiled header" ON) @@ -256,8 +255,6 @@ option(NBL_BUILD_TOOLS "Enable building tools (just convert2BAW as for now)" ON) option(NBL_BUILD_MITSUBA_LOADER "Enable nbl::ext::MitsubaLoader?" ON) -option(NBL_BUILD_RADEON_RAYS "Enable nbl::ext::RadeonRays?" OFF) - if (NBL_COMPILE_WITH_CUDA) find_package(OPTIX) if (OPTIX_FOUND) diff --git a/source/Nabla/COpenCLHandler.cpp b/source/Nabla/COpenCLHandler.cpp deleted file mode 100644 index 361af2e24e..0000000000 --- a/source/Nabla/COpenCLHandler.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#include "COpenCLHandler.h" - -#ifdef _NBL_COMPILE_WITH_OPENCL_ -namespace nbl -{ -namespace ocl -{ - -bool COpenCLHandler::alreadyEnumeratedPlatforms = false; - -core::vector COpenCLHandler::platformInformation; - - -COpenCLHandler::OpenCL COpenCLHandler::ocl; -COpenCLHandler::OpenCLExtensions COpenCLHandler::ocl_ext; - -} -} - - -#endif // _NBL_COMPILE_WITH_OPENCL_ diff --git a/source/Nabla/COpenCLHandler.h b/source/Nabla/COpenCLHandler.h deleted file mode 100644 index 99e320e65d..0000000000 --- a/source/Nabla/COpenCLHandler.h +++ /dev/null @@ -1,339 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#ifndef __NBL_C_OPENCL_HANDLER_H__ -#define __NBL_C_OPENCL_HANDLER_H__ - -#include "nbl/core/core.h" -#include "nbl/system/system.h" - -#include - -#ifdef _NBL_COMPILE_WITH_OPENCL_ - -#include "CL/opencl.h" - -#endif // _NBL_COMPILE_WITH_OPENGL_ - - -namespace nbl -{ -namespace ocl -{ - - -static const char* const OpenCLFeatureStrings[] = { - "cl_khr_gl_sharing", - "cl_khr_gl_event" -}; - - -class COpenCLHandler -{ - COpenCLHandler() = delete; - public: - class SOpenCLPlatformInfo : public core::AllocationOverrideDefault - { - public: - enum EOpenCLFeatures - { - NBL_KHR_GL_SHARING=0, - NBL_KHR_GL_EVENT, - NBL_OpenCL_Feature_Count - }; - class SOpenCLDeviceInfo : public core::AllocationOverrideDefault - { - public: - std::string Name; - std::string ReportedExtensions; - - uint32_t MaxComputeUnits; - size_t MaxWorkGroupSize; - size_t ProbableUnifiedShaders; - }; - - cl_platform_id id; - std::string Vendor; - std::string Name; - uint32_t Version; - std::string ReportedExtensions; - bool FeatureAvailable[NBL_OpenCL_Feature_Count] = { false }; - - core::vector devices; - core::vector deviceInformation; - }; - - static inline bool CL_ERROR(cl_int retval) - { - return retval!=CL_SUCCESS; - } - - static bool enumeratePlatformsAndDevices() - { - if (alreadyEnumeratedPlatforms) - return platformInformation.size()!=0ull; - ocl = OpenCL("OpenCL"); - ocl_ext = OpenCLExtensions(&ocl.pclGetExtensionFunctionAddress); - alreadyEnumeratedPlatforms = true; - - cl_uint actualPlatformCount = 0u; - if (CL_ERROR(ocl.pclGetPlatformIDs(~0u,nullptr,&actualPlatformCount)) || actualPlatformCount==0u) - return false; - - core::vector platforms(actualPlatformCount); - if (CL_ERROR(ocl.pclGetPlatformIDs(platforms.size(),platforms.data(),nullptr))) - return false; - - //printf("Found %d OpenCL Platforms\n",actualPlatformCount); - - - char tmpBuf[128*1024]; - for (auto platform : platforms) - { - auto getPlatformInfoString = [platform,&tmpBuf](auto infoEnum, std::string& outStr) -> bool - { - size_t actualSize = 0; - if (CL_ERROR(ocl.pclGetPlatformInfo(platform,infoEnum,sizeof(tmpBuf),tmpBuf,&actualSize))) - return true; - - if (actualSize) - outStr.assign(tmpBuf,actualSize-1u); - else - outStr.clear(); - return false; - }; - - // check profile - { - std::string profile; - if (getPlatformInfoString(CL_PLATFORM_PROFILE,profile)) - continue; - - if (profile!="FULL_PROFILE") - continue; - } - - // fill out info - SOpenCLPlatformInfo info; - info.id = platform; - - if (getPlatformInfoString(CL_PLATFORM_VENDOR,info.Vendor)) - continue; - //printf("VENDOR = %s\n",tmpBuf); - if (getPlatformInfoString(CL_PLATFORM_EXTENSIONS,info.ReportedExtensions)) - continue; - //printf("CL_PLATFORM_EXTENSIONS = %s\n",tmpBuf); - if (getPlatformInfoString(CL_PLATFORM_NAME,info.Name)) - continue; - //printf("NAME = %s\n",tmpBuf); - - // TODO: Redo this version extraction at some point - { - size_t actualSize = 0; - if (CL_ERROR(ocl.pclGetPlatformInfo(platform,CL_PLATFORM_VERSION,sizeof(tmpBuf),tmpBuf,&actualSize))) - continue; - //printf("VERSION = %s\n",tmpBuf); - size_t j=7; - for (; j>extension; ) - { - // TODO: turn into find_if - for (size_t m=0; mName = std::string(tmpBuf,tmpSize); - //printf("Device Name: %s\n",tmpBuf); - - tmpSize = 0; - ocl.pclGetDeviceInfo(device,CL_DEVICE_EXTENSIONS,sizeof(tmpBuf),tmpBuf,&tmpSize); - deviceInfoIt->ReportedExtensions = std::string(tmpBuf,tmpSize); - //printf("Device Extensions: %s\n",tmpBuf); - - ocl.pclGetDeviceInfo(device,CL_DEVICE_MAX_COMPUTE_UNITS,4,&deviceInfoIt->MaxComputeUnits,&tmpSize); - ocl.pclGetDeviceInfo(device,CL_DEVICE_MAX_WORK_GROUP_SIZE,8,&deviceInfoIt->MaxWorkGroupSize,&tmpSize); - deviceInfoIt->ProbableUnifiedShaders = deviceInfoIt->MaxComputeUnits*deviceInfoIt->MaxWorkGroupSize; - //printf("Device %d has probably %d shader cores!\n",j,deviceInfoIt->ProbableUnifiedShaders); - - deviceInfoIt++; - } - } - - platformInformation.push_back(std::move(info)); - } - - return platformInformation.size()!=0ull; - } - - static auto getPlatformCount() {return platformInformation.size();} - - static const SOpenCLPlatformInfo& getPlatformInfo(const size_t& ix) {return platformInformation[ix];} - -#ifdef _NBL_COMPILE_WITH_OPENGL_ - static bool getCLDeviceFromGLContext(cl_device_id& outDevice, cl_context_properties properties[7], -#if defined(_NBL_WINDOWS_API_) - const HGLRC& context, const HDC& hDC) -#else - const GLXContext& context, const Display* display) -#endif - { - if (!alreadyEnumeratedPlatforms) - return false; - - if (!ocl_ext.pclGetGLContextInfoKHR) - return false; - - properties[0] = CL_GL_CONTEXT_KHR; - properties[1] = (cl_context_properties)context; -#if defined(_NBL_WINDOWS_API_) - properties[2] = CL_WGL_HDC_KHR; - properties[3] = (cl_context_properties)hDC; -#else - properties[2] = CL_GLX_DISPLAY_KHR; - properties[3] = (cl_context_properties)display; -#endif - properties[4] = properties[5] = properties[6] = 0; - - auto getCurrentDeviceForGL = [&properties,&outDevice]() - { - size_t writeOutSize = 0; - auto retval = ocl_ext.pclGetGLContextInfoKHR(properties,CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR,sizeof(cl_device_id),&outDevice,&writeOutSize); - if (retval!=CL_SUCCESS) - return retval; - return writeOutSize!=sizeof(cl_device_id) ? CL_INVALID_BUFFER_SIZE:CL_SUCCESS; - }; - auto retval = getCurrentDeviceForGL(); - if (retval==CL_INVALID_PLATFORM) - { - properties[4] = CL_CONTEXT_PLATFORM; - for (auto& platform : platformInformation) - { - properties[5] = (cl_context_properties)platform.id; - retval = getCurrentDeviceForGL(); - if (retval==CL_SUCCESS) - break; - } - } - - return retval==CL_SUCCESS; - } -#endif // defined - - // function pointers - using LibLoader = system::DefaultFuncPtrLoader; - - NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(OpenCL, LibLoader - ,clGetExtensionFunctionAddress - ,clGetPlatformIDs - ,clGetPlatformInfo - ,clGetDeviceIDs - ,clGetDeviceInfo - ,clFlush - ,clFinish - ,clReleaseEvent - ,clEnqueueWaitForEvents - ,clEnqueueMarker - ,clWaitForEvents - ,clGetEventInfo - ,clReleaseMemObject - ,clEnqueueAcquireGLObjects - ,clEnqueueReleaseGLObjects - ); - static OpenCL ocl; - - - private: - static bool alreadyEnumeratedPlatforms; - static core::vector platformInformation; - - class OpenCLExtensionLoader final : system::FuncPtrLoader - { - using FUNC_PTR_TYPE = decltype(clGetExtensionFunctionAddress)*; - FUNC_PTR_TYPE pClGetExtensionFunctionAddress; - - public: - OpenCLExtensionLoader() : pClGetExtensionFunctionAddress(nullptr) {} - OpenCLExtensionLoader(FUNC_PTR_TYPE _pClGetExtensionFunctionAddress) : pClGetExtensionFunctionAddress(_pClGetExtensionFunctionAddress) {} - OpenCLExtensionLoader(OpenCLExtensionLoader&& other) : OpenCLExtensionLoader() - { - operator=(std::move(other)); - } - - - inline OpenCLExtensionLoader& operator=(OpenCLExtensionLoader&& other) - { - std::swap(pClGetExtensionFunctionAddress, other.pClGetExtensionFunctionAddress); - return *this; - } - - inline bool isLibraryLoaded() override final - { - return pClGetExtensionFunctionAddress!=nullptr; - } - - inline void* loadFuncPtr(const char* funcname) override final - { - return pClGetExtensionFunctionAddress(funcname); - } - }; - NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(OpenCLExtensions, OpenCLExtensionLoader - ,clGetGLContextInfoKHR - ); - static OpenCLExtensions ocl_ext; -}; - -} -} - -#endif // _NBL_COMPILE_WITH_OPENCL_ - - diff --git a/src/3rdparty/CL/cl.h b/src/3rdparty/CL/cl.h deleted file mode 100644 index 22a16c646a..0000000000 --- a/src/3rdparty/CL/cl.h +++ /dev/null @@ -1,1452 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifndef __OPENCL_CL_H -#define __OPENCL_CL_H - -#ifdef __APPLE__ - #include -#else - #include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************/ - -typedef struct _cl_platform_id * cl_platform_id; -typedef struct _cl_device_id * cl_device_id; -typedef struct _cl_context * cl_context; -typedef struct _cl_command_queue * cl_command_queue; -typedef struct _cl_mem * cl_mem; -typedef struct _cl_program * cl_program; -typedef struct _cl_kernel * cl_kernel; -typedef struct _cl_event * cl_event; -typedef struct _cl_sampler * cl_sampler; - -typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ -typedef cl_ulong cl_bitfield; -typedef cl_bitfield cl_device_type; -typedef cl_uint cl_platform_info; -typedef cl_uint cl_device_info; -typedef cl_bitfield cl_device_fp_config; -typedef cl_uint cl_device_mem_cache_type; -typedef cl_uint cl_device_local_mem_type; -typedef cl_bitfield cl_device_exec_capabilities; -typedef cl_bitfield cl_device_svm_capabilities; -typedef cl_bitfield cl_command_queue_properties; -typedef intptr_t cl_device_partition_property; -typedef cl_bitfield cl_device_affinity_domain; - -typedef intptr_t cl_context_properties; -typedef cl_uint cl_context_info; -typedef cl_bitfield cl_queue_properties; -typedef cl_uint cl_command_queue_info; -typedef cl_uint cl_channel_order; -typedef cl_uint cl_channel_type; -typedef cl_bitfield cl_mem_flags; -typedef cl_bitfield cl_svm_mem_flags; -typedef cl_uint cl_mem_object_type; -typedef cl_uint cl_mem_info; -typedef cl_bitfield cl_mem_migration_flags; -typedef cl_uint cl_image_info; -typedef cl_uint cl_buffer_create_type; -typedef cl_uint cl_addressing_mode; -typedef cl_uint cl_filter_mode; -typedef cl_uint cl_sampler_info; -typedef cl_bitfield cl_map_flags; -typedef intptr_t cl_pipe_properties; -typedef cl_uint cl_pipe_info; -typedef cl_uint cl_program_info; -typedef cl_uint cl_program_build_info; -typedef cl_uint cl_program_binary_type; -typedef cl_int cl_build_status; -typedef cl_uint cl_kernel_info; -typedef cl_uint cl_kernel_arg_info; -typedef cl_uint cl_kernel_arg_address_qualifier; -typedef cl_uint cl_kernel_arg_access_qualifier; -typedef cl_bitfield cl_kernel_arg_type_qualifier; -typedef cl_uint cl_kernel_work_group_info; -typedef cl_uint cl_kernel_sub_group_info; -typedef cl_uint cl_event_info; -typedef cl_uint cl_command_type; -typedef cl_uint cl_profiling_info; -typedef cl_bitfield cl_sampler_properties; -typedef cl_uint cl_kernel_exec_info; - -typedef struct _cl_image_format { - cl_channel_order image_channel_order; - cl_channel_type image_channel_data_type; -} cl_image_format; - -typedef struct _cl_image_desc { - cl_mem_object_type image_type; - size_t image_width; - size_t image_height; - size_t image_depth; - size_t image_array_size; - size_t image_row_pitch; - size_t image_slice_pitch; - cl_uint num_mip_levels; - cl_uint num_samples; -#ifdef __GNUC__ - __extension__ /* Prevents warnings about anonymous union in -pedantic builds */ -#endif - union { - cl_mem buffer; - cl_mem mem_object; - }; -} cl_image_desc; - -typedef struct _cl_buffer_region { - size_t origin; - size_t size; -} cl_buffer_region; - - -/******************************************************************************/ - -/* Error Codes */ -#define CL_SUCCESS 0 -#define CL_DEVICE_NOT_FOUND -1 -#define CL_DEVICE_NOT_AVAILABLE -2 -#define CL_COMPILER_NOT_AVAILABLE -3 -#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 -#define CL_OUT_OF_RESOURCES -5 -#define CL_OUT_OF_HOST_MEMORY -6 -#define CL_PROFILING_INFO_NOT_AVAILABLE -7 -#define CL_MEM_COPY_OVERLAP -8 -#define CL_IMAGE_FORMAT_MISMATCH -9 -#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 -#define CL_BUILD_PROGRAM_FAILURE -11 -#define CL_MAP_FAILURE -12 -#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 -#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 -#define CL_COMPILE_PROGRAM_FAILURE -15 -#define CL_LINKER_NOT_AVAILABLE -16 -#define CL_LINK_PROGRAM_FAILURE -17 -#define CL_DEVICE_PARTITION_FAILED -18 -#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 - -#define CL_INVALID_VALUE -30 -#define CL_INVALID_DEVICE_TYPE -31 -#define CL_INVALID_PLATFORM -32 -#define CL_INVALID_DEVICE -33 -#define CL_INVALID_CONTEXT -34 -#define CL_INVALID_QUEUE_PROPERTIES -35 -#define CL_INVALID_COMMAND_QUEUE -36 -#define CL_INVALID_HOST_PTR -37 -#define CL_INVALID_MEM_OBJECT -38 -#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 -#define CL_INVALID_IMAGE_SIZE -40 -#define CL_INVALID_SAMPLER -41 -#define CL_INVALID_BINARY -42 -#define CL_INVALID_BUILD_OPTIONS -43 -#define CL_INVALID_PROGRAM -44 -#define CL_INVALID_PROGRAM_EXECUTABLE -45 -#define CL_INVALID_KERNEL_NAME -46 -#define CL_INVALID_KERNEL_DEFINITION -47 -#define CL_INVALID_KERNEL -48 -#define CL_INVALID_ARG_INDEX -49 -#define CL_INVALID_ARG_VALUE -50 -#define CL_INVALID_ARG_SIZE -51 -#define CL_INVALID_KERNEL_ARGS -52 -#define CL_INVALID_WORK_DIMENSION -53 -#define CL_INVALID_WORK_GROUP_SIZE -54 -#define CL_INVALID_WORK_ITEM_SIZE -55 -#define CL_INVALID_GLOBAL_OFFSET -56 -#define CL_INVALID_EVENT_WAIT_LIST -57 -#define CL_INVALID_EVENT -58 -#define CL_INVALID_OPERATION -59 -#define CL_INVALID_GL_OBJECT -60 -#define CL_INVALID_BUFFER_SIZE -61 -#define CL_INVALID_MIP_LEVEL -62 -#define CL_INVALID_GLOBAL_WORK_SIZE -63 -#define CL_INVALID_PROPERTY -64 -#define CL_INVALID_IMAGE_DESCRIPTOR -65 -#define CL_INVALID_COMPILER_OPTIONS -66 -#define CL_INVALID_LINKER_OPTIONS -67 -#define CL_INVALID_DEVICE_PARTITION_COUNT -68 -#define CL_INVALID_PIPE_SIZE -69 -#define CL_INVALID_DEVICE_QUEUE -70 - -/* OpenCL Version */ -#define CL_VERSION_1_0 1 -#define CL_VERSION_1_1 1 -#define CL_VERSION_1_2 1 -#define CL_VERSION_2_0 1 -#define CL_VERSION_2_1 1 - -/* cl_bool */ -#define CL_FALSE 0 -#define CL_TRUE 1 -#define CL_BLOCKING CL_TRUE -#define CL_NON_BLOCKING CL_FALSE - -/* cl_platform_info */ -#define CL_PLATFORM_PROFILE 0x0900 -#define CL_PLATFORM_VERSION 0x0901 -#define CL_PLATFORM_NAME 0x0902 -#define CL_PLATFORM_VENDOR 0x0903 -#define CL_PLATFORM_EXTENSIONS 0x0904 -#define CL_PLATFORM_HOST_TIMER_RESOLUTION 0x0905 - -/* cl_device_type - bitfield */ -#define CL_DEVICE_TYPE_DEFAULT (1 << 0) -#define CL_DEVICE_TYPE_CPU (1 << 1) -#define CL_DEVICE_TYPE_GPU (1 << 2) -#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) -#define CL_DEVICE_TYPE_CUSTOM (1 << 4) -#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF - -/* cl_device_info */ -#define CL_DEVICE_TYPE 0x1000 -#define CL_DEVICE_VENDOR_ID 0x1001 -#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 -#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 -#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 -#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B -#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C -#define CL_DEVICE_ADDRESS_BITS 0x100D -#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E -#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F -#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 -#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 -#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 -#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 -#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 -#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 -#define CL_DEVICE_IMAGE_SUPPORT 0x1016 -#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 -#define CL_DEVICE_MAX_SAMPLERS 0x1018 -#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 -#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A -#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B -#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C -#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D -#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E -#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F -#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 -#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 -#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 -#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 -#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 -#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 -#define CL_DEVICE_ENDIAN_LITTLE 0x1026 -#define CL_DEVICE_AVAILABLE 0x1027 -#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 -#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 -#define CL_DEVICE_QUEUE_PROPERTIES 0x102A /* deprecated */ -#define CL_DEVICE_QUEUE_ON_HOST_PROPERTIES 0x102A -#define CL_DEVICE_NAME 0x102B -#define CL_DEVICE_VENDOR 0x102C -#define CL_DRIVER_VERSION 0x102D -#define CL_DEVICE_PROFILE 0x102E -#define CL_DEVICE_VERSION 0x102F -#define CL_DEVICE_EXTENSIONS 0x1030 -#define CL_DEVICE_PLATFORM 0x1031 -#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 -#define CL_DEVICE_HALF_FP_CONFIG 0x1033 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 -#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 /* deprecated */ -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C -#define CL_DEVICE_OPENCL_C_VERSION 0x103D -#define CL_DEVICE_LINKER_AVAILABLE 0x103E -#define CL_DEVICE_BUILT_IN_KERNELS 0x103F -#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 -#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 -#define CL_DEVICE_PARENT_DEVICE 0x1042 -#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 -#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 -#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 -#define CL_DEVICE_PARTITION_TYPE 0x1046 -#define CL_DEVICE_REFERENCE_COUNT 0x1047 -#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 -#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 -#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A -#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B -#define CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS 0x104C -#define CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE 0x104D -#define CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES 0x104E -#define CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE 0x104F -#define CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE 0x1050 -#define CL_DEVICE_MAX_ON_DEVICE_QUEUES 0x1051 -#define CL_DEVICE_MAX_ON_DEVICE_EVENTS 0x1052 -#define CL_DEVICE_SVM_CAPABILITIES 0x1053 -#define CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE 0x1054 -#define CL_DEVICE_MAX_PIPE_ARGS 0x1055 -#define CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS 0x1056 -#define CL_DEVICE_PIPE_MAX_PACKET_SIZE 0x1057 -#define CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT 0x1058 -#define CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT 0x1059 -#define CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT 0x105A -#define CL_DEVICE_IL_VERSION 0x105B -#define CL_DEVICE_MAX_NUM_SUB_GROUPS 0x105C -#define CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS 0x105D - -/* cl_device_fp_config - bitfield */ -#define CL_FP_DENORM (1 << 0) -#define CL_FP_INF_NAN (1 << 1) -#define CL_FP_ROUND_TO_NEAREST (1 << 2) -#define CL_FP_ROUND_TO_ZERO (1 << 3) -#define CL_FP_ROUND_TO_INF (1 << 4) -#define CL_FP_FMA (1 << 5) -#define CL_FP_SOFT_FLOAT (1 << 6) -#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) - -/* cl_device_mem_cache_type */ -#define CL_NONE 0x0 -#define CL_READ_ONLY_CACHE 0x1 -#define CL_READ_WRITE_CACHE 0x2 - -/* cl_device_local_mem_type */ -#define CL_LOCAL 0x1 -#define CL_GLOBAL 0x2 - -/* cl_device_exec_capabilities - bitfield */ -#define CL_EXEC_KERNEL (1 << 0) -#define CL_EXEC_NATIVE_KERNEL (1 << 1) - -/* cl_command_queue_properties - bitfield */ -#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) -#define CL_QUEUE_PROFILING_ENABLE (1 << 1) -#define CL_QUEUE_ON_DEVICE (1 << 2) -#define CL_QUEUE_ON_DEVICE_DEFAULT (1 << 3) - -/* cl_context_info */ -#define CL_CONTEXT_REFERENCE_COUNT 0x1080 -#define CL_CONTEXT_DEVICES 0x1081 -#define CL_CONTEXT_PROPERTIES 0x1082 -#define CL_CONTEXT_NUM_DEVICES 0x1083 - -/* cl_context_properties */ -#define CL_CONTEXT_PLATFORM 0x1084 -#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 - -/* cl_device_partition_property */ -#define CL_DEVICE_PARTITION_EQUALLY 0x1086 -#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 -#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 -#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 - -/* cl_device_affinity_domain */ -#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) -#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) -#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) -#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) -#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) -#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) - -/* cl_device_svm_capabilities */ -#define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER (1 << 0) -#define CL_DEVICE_SVM_FINE_GRAIN_BUFFER (1 << 1) -#define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM (1 << 2) -#define CL_DEVICE_SVM_ATOMICS (1 << 3) - -/* cl_command_queue_info */ -#define CL_QUEUE_CONTEXT 0x1090 -#define CL_QUEUE_DEVICE 0x1091 -#define CL_QUEUE_REFERENCE_COUNT 0x1092 -#define CL_QUEUE_PROPERTIES 0x1093 -#define CL_QUEUE_SIZE 0x1094 -#define CL_QUEUE_DEVICE_DEFAULT 0x1095 - -/* cl_mem_flags and cl_svm_mem_flags - bitfield */ -#define CL_MEM_READ_WRITE (1 << 0) -#define CL_MEM_WRITE_ONLY (1 << 1) -#define CL_MEM_READ_ONLY (1 << 2) -#define CL_MEM_USE_HOST_PTR (1 << 3) -#define CL_MEM_ALLOC_HOST_PTR (1 << 4) -#define CL_MEM_COPY_HOST_PTR (1 << 5) -/* reserved (1 << 6) */ -#define CL_MEM_HOST_WRITE_ONLY (1 << 7) -#define CL_MEM_HOST_READ_ONLY (1 << 8) -#define CL_MEM_HOST_NO_ACCESS (1 << 9) -#define CL_MEM_SVM_FINE_GRAIN_BUFFER (1 << 10) /* used by cl_svm_mem_flags only */ -#define CL_MEM_SVM_ATOMICS (1 << 11) /* used by cl_svm_mem_flags only */ -#define CL_MEM_KERNEL_READ_AND_WRITE (1 << 12) - -/* cl_mem_migration_flags - bitfield */ -#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) -#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) - -/* cl_channel_order */ -#define CL_R 0x10B0 -#define CL_A 0x10B1 -#define CL_RG 0x10B2 -#define CL_RA 0x10B3 -#define CL_RGB 0x10B4 -#define CL_RGBA 0x10B5 -#define CL_BGRA 0x10B6 -#define CL_ARGB 0x10B7 -#define CL_INTENSITY 0x10B8 -#define CL_LUMINANCE 0x10B9 -#define CL_Rx 0x10BA -#define CL_RGx 0x10BB -#define CL_RGBx 0x10BC -#define CL_DEPTH 0x10BD -#define CL_DEPTH_STENCIL 0x10BE -#define CL_sRGB 0x10BF -#define CL_sRGBx 0x10C0 -#define CL_sRGBA 0x10C1 -#define CL_sBGRA 0x10C2 -#define CL_ABGR 0x10C3 - -/* cl_channel_type */ -#define CL_SNORM_INT8 0x10D0 -#define CL_SNORM_INT16 0x10D1 -#define CL_UNORM_INT8 0x10D2 -#define CL_UNORM_INT16 0x10D3 -#define CL_UNORM_SHORT_565 0x10D4 -#define CL_UNORM_SHORT_555 0x10D5 -#define CL_UNORM_INT_101010 0x10D6 -#define CL_SIGNED_INT8 0x10D7 -#define CL_SIGNED_INT16 0x10D8 -#define CL_SIGNED_INT32 0x10D9 -#define CL_UNSIGNED_INT8 0x10DA -#define CL_UNSIGNED_INT16 0x10DB -#define CL_UNSIGNED_INT32 0x10DC -#define CL_HALF_FLOAT 0x10DD -#define CL_FLOAT 0x10DE -#define CL_UNORM_INT24 0x10DF -#define CL_UNORM_INT_101010_2 0x10E0 - -/* cl_mem_object_type */ -#define CL_MEM_OBJECT_BUFFER 0x10F0 -#define CL_MEM_OBJECT_IMAGE2D 0x10F1 -#define CL_MEM_OBJECT_IMAGE3D 0x10F2 -#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 -#define CL_MEM_OBJECT_IMAGE1D 0x10F4 -#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 -#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 -#define CL_MEM_OBJECT_PIPE 0x10F7 - -/* cl_mem_info */ -#define CL_MEM_TYPE 0x1100 -#define CL_MEM_FLAGS 0x1101 -#define CL_MEM_SIZE 0x1102 -#define CL_MEM_HOST_PTR 0x1103 -#define CL_MEM_MAP_COUNT 0x1104 -#define CL_MEM_REFERENCE_COUNT 0x1105 -#define CL_MEM_CONTEXT 0x1106 -#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 -#define CL_MEM_OFFSET 0x1108 -#define CL_MEM_USES_SVM_POINTER 0x1109 - -/* cl_image_info */ -#define CL_IMAGE_FORMAT 0x1110 -#define CL_IMAGE_ELEMENT_SIZE 0x1111 -#define CL_IMAGE_ROW_PITCH 0x1112 -#define CL_IMAGE_SLICE_PITCH 0x1113 -#define CL_IMAGE_WIDTH 0x1114 -#define CL_IMAGE_HEIGHT 0x1115 -#define CL_IMAGE_DEPTH 0x1116 -#define CL_IMAGE_ARRAY_SIZE 0x1117 -#define CL_IMAGE_BUFFER 0x1118 -#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 -#define CL_IMAGE_NUM_SAMPLES 0x111A - -/* cl_pipe_info */ -#define CL_PIPE_PACKET_SIZE 0x1120 -#define CL_PIPE_MAX_PACKETS 0x1121 - -/* cl_addressing_mode */ -#define CL_ADDRESS_NONE 0x1130 -#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 -#define CL_ADDRESS_CLAMP 0x1132 -#define CL_ADDRESS_REPEAT 0x1133 -#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 - -/* cl_filter_mode */ -#define CL_FILTER_NEAREST 0x1140 -#define CL_FILTER_LINEAR 0x1141 - -/* cl_sampler_info */ -#define CL_SAMPLER_REFERENCE_COUNT 0x1150 -#define CL_SAMPLER_CONTEXT 0x1151 -#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 -#define CL_SAMPLER_ADDRESSING_MODE 0x1153 -#define CL_SAMPLER_FILTER_MODE 0x1154 -#define CL_SAMPLER_MIP_FILTER_MODE 0x1155 -#define CL_SAMPLER_LOD_MIN 0x1156 -#define CL_SAMPLER_LOD_MAX 0x1157 - -/* cl_map_flags - bitfield */ -#define CL_MAP_READ (1 << 0) -#define CL_MAP_WRITE (1 << 1) -#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) - -/* cl_program_info */ -#define CL_PROGRAM_REFERENCE_COUNT 0x1160 -#define CL_PROGRAM_CONTEXT 0x1161 -#define CL_PROGRAM_NUM_DEVICES 0x1162 -#define CL_PROGRAM_DEVICES 0x1163 -#define CL_PROGRAM_SOURCE 0x1164 -#define CL_PROGRAM_BINARY_SIZES 0x1165 -#define CL_PROGRAM_BINARIES 0x1166 -#define CL_PROGRAM_NUM_KERNELS 0x1167 -#define CL_PROGRAM_KERNEL_NAMES 0x1168 -#define CL_PROGRAM_IL 0x1169 - -/* cl_program_build_info */ -#define CL_PROGRAM_BUILD_STATUS 0x1181 -#define CL_PROGRAM_BUILD_OPTIONS 0x1182 -#define CL_PROGRAM_BUILD_LOG 0x1183 -#define CL_PROGRAM_BINARY_TYPE 0x1184 -#define CL_PROGRAM_BUILD_GLOBAL_VARIABLE_TOTAL_SIZE 0x1185 - -/* cl_program_binary_type */ -#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 -#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 -#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 -#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 - -/* cl_build_status */ -#define CL_BUILD_SUCCESS 0 -#define CL_BUILD_NONE -1 -#define CL_BUILD_ERROR -2 -#define CL_BUILD_IN_PROGRESS -3 - -/* cl_kernel_info */ -#define CL_KERNEL_FUNCTION_NAME 0x1190 -#define CL_KERNEL_NUM_ARGS 0x1191 -#define CL_KERNEL_REFERENCE_COUNT 0x1192 -#define CL_KERNEL_CONTEXT 0x1193 -#define CL_KERNEL_PROGRAM 0x1194 -#define CL_KERNEL_ATTRIBUTES 0x1195 -#define CL_KERNEL_MAX_NUM_SUB_GROUPS 0x11B9 -#define CL_KERNEL_COMPILE_NUM_SUB_GROUPS 0x11BA - -/* cl_kernel_arg_info */ -#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 -#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 -#define CL_KERNEL_ARG_TYPE_NAME 0x1198 -#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 -#define CL_KERNEL_ARG_NAME 0x119A - -/* cl_kernel_arg_address_qualifier */ -#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B -#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C -#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D -#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E - -/* cl_kernel_arg_access_qualifier */ -#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 -#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 -#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 -#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 - -/* cl_kernel_arg_type_qualifer */ -#define CL_KERNEL_ARG_TYPE_NONE 0 -#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) -#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) -#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) -#define CL_KERNEL_ARG_TYPE_PIPE (1 << 3) - -/* cl_kernel_work_group_info */ -#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 -#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 -#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 -#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 -#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 -#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 - -/* cl_kernel_sub_group_info */ -#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE 0x2033 -#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE 0x2034 -#define CL_KERNEL_LOCAL_SIZE_FOR_SUB_GROUP_COUNT 0x11B8 - -/* cl_kernel_exec_info */ -#define CL_KERNEL_EXEC_INFO_SVM_PTRS 0x11B6 -#define CL_KERNEL_EXEC_INFO_SVM_FINE_GRAIN_SYSTEM 0x11B7 - -/* cl_event_info */ -#define CL_EVENT_COMMAND_QUEUE 0x11D0 -#define CL_EVENT_COMMAND_TYPE 0x11D1 -#define CL_EVENT_REFERENCE_COUNT 0x11D2 -#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 -#define CL_EVENT_CONTEXT 0x11D4 - -/* cl_command_type */ -#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 -#define CL_COMMAND_TASK 0x11F1 -#define CL_COMMAND_NATIVE_KERNEL 0x11F2 -#define CL_COMMAND_READ_BUFFER 0x11F3 -#define CL_COMMAND_WRITE_BUFFER 0x11F4 -#define CL_COMMAND_COPY_BUFFER 0x11F5 -#define CL_COMMAND_READ_IMAGE 0x11F6 -#define CL_COMMAND_WRITE_IMAGE 0x11F7 -#define CL_COMMAND_COPY_IMAGE 0x11F8 -#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 -#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA -#define CL_COMMAND_MAP_BUFFER 0x11FB -#define CL_COMMAND_MAP_IMAGE 0x11FC -#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD -#define CL_COMMAND_MARKER 0x11FE -#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF -#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 -#define CL_COMMAND_READ_BUFFER_RECT 0x1201 -#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 -#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 -#define CL_COMMAND_USER 0x1204 -#define CL_COMMAND_BARRIER 0x1205 -#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 -#define CL_COMMAND_FILL_BUFFER 0x1207 -#define CL_COMMAND_FILL_IMAGE 0x1208 -#define CL_COMMAND_SVM_FREE 0x1209 -#define CL_COMMAND_SVM_MEMCPY 0x120A -#define CL_COMMAND_SVM_MEMFILL 0x120B -#define CL_COMMAND_SVM_MAP 0x120C -#define CL_COMMAND_SVM_UNMAP 0x120D - -/* command execution status */ -#define CL_COMPLETE 0x0 -#define CL_RUNNING 0x1 -#define CL_SUBMITTED 0x2 -#define CL_QUEUED 0x3 - -/* cl_buffer_create_type */ -#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 - -/* cl_profiling_info */ -#define CL_PROFILING_COMMAND_QUEUED 0x1280 -#define CL_PROFILING_COMMAND_SUBMIT 0x1281 -#define CL_PROFILING_COMMAND_START 0x1282 -#define CL_PROFILING_COMMAND_END 0x1283 -#define CL_PROFILING_COMMAND_COMPLETE 0x1284 - -/********************************************************************************************************/ - -/* Platform API */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPlatformIDs(cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPlatformInfo(cl_platform_id /* platform */, - cl_platform_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Device APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceIDs(cl_platform_id /* platform */, - cl_device_type /* device_type */, - cl_uint /* num_entries */, - cl_device_id * /* devices */, - cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceInfo(cl_device_id /* device */, - cl_device_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateSubDevices(cl_device_id /* in_device */, - const cl_device_partition_property * /* properties */, - cl_uint /* num_devices */, - cl_device_id * /* out_devices */, - cl_uint * /* num_devices_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetDefaultDeviceCommandQueue(cl_context /* context */, - cl_device_id /* device */, - cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_2_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceAndHostTimer(cl_device_id /* device */, - cl_ulong* /* device_timestamp */, - cl_ulong* /* host_timestamp */) CL_API_SUFFIX__VERSION_2_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetHostTimer(cl_device_id /* device */, - cl_ulong * /* host_timestamp */) CL_API_SUFFIX__VERSION_2_1; - - -/* Context APIs */ -extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContext(const cl_context_properties * /* properties */, - cl_uint /* num_devices */, - const cl_device_id * /* devices */, - void (CL_CALLBACK * /* pfn_notify */)(const char *, const void *, size_t, void *), - void * /* user_data */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContextFromType(const cl_context_properties * /* properties */, - cl_device_type /* device_type */, - void (CL_CALLBACK * /* pfn_notify*/ )(const char *, const void *, size_t, void *), - void * /* user_data */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetContextInfo(cl_context /* context */, - cl_context_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Command Queue APIs */ -extern CL_API_ENTRY cl_command_queue CL_API_CALL -clCreateCommandQueueWithProperties(cl_context /* context */, - cl_device_id /* device */, - const cl_queue_properties * /* properties */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetCommandQueueInfo(cl_command_queue /* command_queue */, - cl_command_queue_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Memory Object APIs */ -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateBuffer(cl_context /* context */, - cl_mem_flags /* flags */, - size_t /* size */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateSubBuffer(cl_mem /* buffer */, - cl_mem_flags /* flags */, - cl_buffer_create_type /* buffer_create_type */, - const void * /* buffer_create_info */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateImage(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - const cl_image_desc * /* image_desc */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreatePipe(cl_context /* context */, - cl_mem_flags /* flags */, - cl_uint /* pipe_packet_size */, - cl_uint /* pipe_max_packets */, - const cl_pipe_properties * /* properties */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetSupportedImageFormats(cl_context /* context */, - cl_mem_flags /* flags */, - cl_mem_object_type /* image_type */, - cl_uint /* num_entries */, - cl_image_format * /* image_formats */, - cl_uint * /* num_image_formats */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetMemObjectInfo(cl_mem /* memobj */, - cl_mem_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetImageInfo(cl_mem /* image */, - cl_image_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPipeInfo(cl_mem /* pipe */, - cl_pipe_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_2_0; - - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetMemObjectDestructorCallback(cl_mem /* memobj */, - void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), - void * /*user_data */ ) CL_API_SUFFIX__VERSION_1_1; - -/* SVM Allocation APIs */ -extern CL_API_ENTRY void * CL_API_CALL -clSVMAlloc(cl_context /* context */, - cl_svm_mem_flags /* flags */, - size_t /* size */, - cl_uint /* alignment */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY void CL_API_CALL -clSVMFree(cl_context /* context */, - void * /* svm_pointer */) CL_API_SUFFIX__VERSION_2_0; - -/* Sampler APIs */ -extern CL_API_ENTRY cl_sampler CL_API_CALL -clCreateSamplerWithProperties(cl_context /* context */, - const cl_sampler_properties * /* normalized_coords */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetSamplerInfo(cl_sampler /* sampler */, - cl_sampler_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Program Object APIs */ -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithSource(cl_context /* context */, - cl_uint /* count */, - const char ** /* strings */, - const size_t * /* lengths */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithBinary(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const size_t * /* lengths */, - const unsigned char ** /* binaries */, - cl_int * /* binary_status */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithBuiltInKernels(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* kernel_names */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithIL(cl_context /* context */, - const void* /* il */, - size_t /* length */, - cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_2_1; - - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clBuildProgram(cl_program /* program */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCompileProgram(cl_program /* program */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - cl_uint /* num_input_headers */, - const cl_program * /* input_headers */, - const char ** /* header_include_names */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_program CL_API_CALL -clLinkProgram(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - cl_uint /* num_input_programs */, - const cl_program * /* input_programs */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */, - cl_int * /* errcode_ret */ ) CL_API_SUFFIX__VERSION_1_2; - - -extern CL_API_ENTRY cl_int CL_API_CALL -clUnloadPlatformCompiler(cl_platform_id /* platform */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetProgramInfo(cl_program /* program */, - cl_program_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetProgramBuildInfo(cl_program /* program */, - cl_device_id /* device */, - cl_program_build_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Kernel Object APIs */ -extern CL_API_ENTRY cl_kernel CL_API_CALL -clCreateKernel(cl_program /* program */, - const char * /* kernel_name */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateKernelsInProgram(cl_program /* program */, - cl_uint /* num_kernels */, - cl_kernel * /* kernels */, - cl_uint * /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_kernel CL_API_CALL -clCloneKernel(cl_kernel /* source_kernel */, - cl_int* /* errcode_ret */) CL_API_SUFFIX__VERSION_2_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelArg(cl_kernel /* kernel */, - cl_uint /* arg_index */, - size_t /* arg_size */, - const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelArgSVMPointer(cl_kernel /* kernel */, - cl_uint /* arg_index */, - const void * /* arg_value */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelExecInfo(cl_kernel /* kernel */, - cl_kernel_exec_info /* param_name */, - size_t /* param_value_size */, - const void * /* param_value */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelInfo(cl_kernel /* kernel */, - cl_kernel_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelArgInfo(cl_kernel /* kernel */, - cl_uint /* arg_indx */, - cl_kernel_arg_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelWorkGroupInfo(cl_kernel /* kernel */, - cl_device_id /* device */, - cl_kernel_work_group_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelSubGroupInfo(cl_kernel /* kernel */, - cl_device_id /* device */, - cl_kernel_sub_group_info /* param_name */, - size_t /* input_value_size */, - const void* /*input_value */, - size_t /* param_value_size */, - void* /* param_value */, - size_t* /* param_value_size_ret */ ) CL_API_SUFFIX__VERSION_2_1; - - -/* Event Object APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clWaitForEvents(cl_uint /* num_events */, - const cl_event * /* event_list */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetEventInfo(cl_event /* event */, - cl_event_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateUserEvent(cl_context /* context */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetUserEventStatus(cl_event /* event */, - cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetEventCallback( cl_event /* event */, - cl_int /* command_exec_callback_type */, - void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_1; - -/* Profiling APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetEventProfilingInfo(cl_event /* event */, - cl_profiling_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Flush and Finish APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clFlush(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clFinish(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -/* Enqueued Commands APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_read */, - size_t /* offset */, - size_t /* size */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadBufferRect(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_read */, - const size_t * /* buffer_offset */, - const size_t * /* host_offset */, - const size_t * /* region */, - size_t /* buffer_row_pitch */, - size_t /* buffer_slice_pitch */, - size_t /* host_row_pitch */, - size_t /* host_slice_pitch */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_write */, - size_t /* offset */, - size_t /* size */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteBufferRect(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_write */, - const size_t * /* buffer_offset */, - const size_t * /* host_offset */, - const size_t * /* region */, - size_t /* buffer_row_pitch */, - size_t /* buffer_slice_pitch */, - size_t /* host_row_pitch */, - size_t /* host_slice_pitch */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueFillBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - const void * /* pattern */, - size_t /* pattern_size */, - size_t /* offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBuffer(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_buffer */, - size_t /* src_offset */, - size_t /* dst_offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBufferRect(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_buffer */, - const size_t * /* src_origin */, - const size_t * /* dst_origin */, - const size_t * /* region */, - size_t /* src_row_pitch */, - size_t /* src_slice_pitch */, - size_t /* dst_row_pitch */, - size_t /* dst_slice_pitch */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_read */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t /* row_pitch */, - size_t /* slice_pitch */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_write */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t /* input_row_pitch */, - size_t /* input_slice_pitch */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueFillImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - const void * /* fill_color */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyImage(cl_command_queue /* command_queue */, - cl_mem /* src_image */, - cl_mem /* dst_image */, - const size_t * /* src_origin[3] */, - const size_t * /* dst_origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyImageToBuffer(cl_command_queue /* command_queue */, - cl_mem /* src_image */, - cl_mem /* dst_buffer */, - const size_t * /* src_origin[3] */, - const size_t * /* region[3] */, - size_t /* dst_offset */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBufferToImage(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_image */, - size_t /* src_offset */, - const size_t * /* dst_origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY void * CL_API_CALL -clEnqueueMapBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_map */, - cl_map_flags /* map_flags */, - size_t /* offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY void * CL_API_CALL -clEnqueueMapImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_map */, - cl_map_flags /* map_flags */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t * /* image_row_pitch */, - size_t * /* image_slice_pitch */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueUnmapMemObject(cl_command_queue /* command_queue */, - cl_mem /* memobj */, - void * /* mapped_ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMigrateMemObjects(cl_command_queue /* command_queue */, - cl_uint /* num_mem_objects */, - const cl_mem * /* mem_objects */, - cl_mem_migration_flags /* flags */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueNDRangeKernel(cl_command_queue /* command_queue */, - cl_kernel /* kernel */, - cl_uint /* work_dim */, - const size_t * /* global_work_offset */, - const size_t * /* global_work_size */, - const size_t * /* local_work_size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueNativeKernel(cl_command_queue /* command_queue */, - void (CL_CALLBACK * /*user_func*/)(void *), - void * /* args */, - size_t /* cb_args */, - cl_uint /* num_mem_objects */, - const cl_mem * /* mem_list */, - const void ** /* args_mem_loc */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMarkerWithWaitList(cl_command_queue /* command_queue */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueBarrierWithWaitList(cl_command_queue /* command_queue */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMFree(cl_command_queue /* command_queue */, - cl_uint /* num_svm_pointers */, - void *[] /* svm_pointers[] */, - void (CL_CALLBACK * /*pfn_free_func*/)(cl_command_queue /* queue */, - cl_uint /* num_svm_pointers */, - void *[] /* svm_pointers[] */, - void * /* user_data */), - void * /* user_data */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMemcpy(cl_command_queue /* command_queue */, - cl_bool /* blocking_copy */, - void * /* dst_ptr */, - const void * /* src_ptr */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMemFill(cl_command_queue /* command_queue */, - void * /* svm_ptr */, - const void * /* pattern */, - size_t /* pattern_size */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMap(cl_command_queue /* command_queue */, - cl_bool /* blocking_map */, - cl_map_flags /* flags */, - void * /* svm_ptr */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMUnmap(cl_command_queue /* command_queue */, - void * /* svm_ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_2_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueSVMMigrateMem(cl_command_queue /* command_queue */, - cl_uint /* num_svm_pointers */, - const void ** /* svm_pointers */, - const size_t * /* sizes */, - cl_mem_migration_flags /* flags */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_2_1; - - -/* Extension function access - * - * Returns the extension function address for the given function name, - * or NULL if a valid function can not be found. The client must - * check to make sure the address is not NULL, before using or - * calling the returned function address. - */ -extern CL_API_ENTRY void * CL_API_CALL -clGetExtensionFunctionAddressForPlatform(cl_platform_id /* platform */, - const char * /* func_name */) CL_API_SUFFIX__VERSION_1_2; - - -/* Deprecated OpenCL 1.1 APIs */ -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateImage2D(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - size_t /* image_width */, - size_t /* image_height */, - size_t /* image_row_pitch */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateImage3D(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - size_t /* image_width */, - size_t /* image_height */, - size_t /* image_depth */, - size_t /* image_row_pitch */, - size_t /* image_slice_pitch */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueMarker(cl_command_queue /* command_queue */, - cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueWaitForEvents(cl_command_queue /* command_queue */, - cl_uint /* num_events */, - const cl_event * /* event_list */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueBarrier(cl_command_queue /* command_queue */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL -clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -/* Deprecated OpenCL 2.0 APIs */ -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_command_queue CL_API_CALL -clCreateCommandQueue(cl_context /* context */, - cl_device_id /* device */, - cl_command_queue_properties /* properties */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; - - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_sampler CL_API_CALL -clCreateSampler(cl_context /* context */, - cl_bool /* normalized_coords */, - cl_addressing_mode /* addressing_mode */, - cl_filter_mode /* filter_mode */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_2_DEPRECATED cl_int CL_API_CALL -clEnqueueTask(cl_command_queue /* command_queue */, - cl_kernel /* kernel */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_H */ - diff --git a/src/3rdparty/CL/cl_egl.h b/src/3rdparty/CL/cl_egl.h deleted file mode 100644 index a765bd5266..0000000000 --- a/src/3rdparty/CL/cl_egl.h +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifndef __OPENCL_CL_EGL_H -#define __OPENCL_CL_EGL_H - -#ifdef __APPLE__ - -#else -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ -#define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F -#define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D -#define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E - -/* Error type for clCreateFromEGLImageKHR */ -#define CL_INVALID_EGL_OBJECT_KHR -1093 -#define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 - -/* CLeglImageKHR is an opaque handle to an EGLImage */ -typedef void* CLeglImageKHR; - -/* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ -typedef void* CLeglDisplayKHR; - -/* CLeglSyncKHR is an opaque handle to an EGLSync object */ -typedef void* CLeglSyncKHR; - -/* properties passed to clCreateFromEGLImageKHR */ -typedef intptr_t cl_egl_image_properties_khr; - - -#define cl_khr_egl_image 1 - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromEGLImageKHR(cl_context /* context */, - CLeglDisplayKHR /* egldisplay */, - CLeglImageKHR /* eglimage */, - cl_mem_flags /* flags */, - const cl_egl_image_properties_khr * /* properties */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( - cl_context context, - CLeglDisplayKHR egldisplay, - CLeglImageKHR eglimage, - cl_mem_flags flags, - const cl_egl_image_properties_khr * properties, - cl_int * errcode_ret); - - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireEGLObjectsKHR(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); - - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseEGLObjectsKHR(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); - - -#define cl_khr_egl_event 1 - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateEventFromEGLSyncKHR(cl_context /* context */, - CLeglSyncKHR /* sync */, - CLeglDisplayKHR /* display */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( - cl_context context, - CLeglSyncKHR sync, - CLeglDisplayKHR display, - cl_int * errcode_ret); - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_EGL_H */ diff --git a/src/3rdparty/CL/cl_ext.h b/src/3rdparty/CL/cl_ext.h deleted file mode 100644 index 05a32568d0..0000000000 --- a/src/3rdparty/CL/cl_ext.h +++ /dev/null @@ -1,440 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ - -/* cl_ext.h contains OpenCL extensions which don't have external */ -/* (OpenGL, D3D) dependencies. */ - -#ifndef __CL_EXT_H -#define __CL_EXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - #include - #include -#else - #include -#endif - -/* cl_khr_fp16 extension - no extension #define since it has no functions */ -#define CL_DEVICE_HALF_FP_CONFIG 0x1033 - -/* Memory object destruction - * - * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR - * - * Registers a user callback function that will be called when the memory object is deleted and its resources - * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback - * stack associated with memobj. The registered user callback functions are called in the reverse order in - * which they were registered. The user callback functions are called and then the memory object is deleted - * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be - * notified when the memory referenced by host_ptr, specified when the memory object is created and used as - * the storage bits for the memory object, can be reused or freed. - * - * The application may not call CL api's with the cl_mem object passed to the pfn_notify. - * - * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) - * before using. - */ -#define cl_APPLE_SetMemObjectDestructor 1 -cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */, - void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), - void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - - -/* Context Logging Functions - * - * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). - * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) - * before using. - * - * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger - */ -#define cl_APPLE_ContextLoggingFunctions 1 -extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - -/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ -extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - -/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ -extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - - -/************************ -* cl_khr_icd extension * -************************/ -#define cl_khr_icd 1 - -/* cl_platform_info */ -#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 - -/* Additional Error Codes */ -#define CL_PLATFORM_NOT_FOUND_KHR -1001 - -extern CL_API_ENTRY cl_int CL_API_CALL -clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */); - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( - cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */); - - -/* Extension: cl_khr_image2D_buffer - * - * This extension allows a 2D image to be created from a cl_mem buffer without a copy. - * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. - * Both the sampler and sampler-less read_image built-in functions are supported for 2D images - * and 2D images created from a buffer. Similarly, the write_image built-ins are also supported - * for 2D images created from a buffer. - * - * When the 2D image from buffer is created, the client must specify the width, - * height, image format (i.e. channel order and channel data type) and optionally the row pitch - * - * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. - * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. - */ - -/************************************* - * cl_khr_initalize_memory extension * - *************************************/ - -#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x2030 - - -/************************************** - * cl_khr_terminate_context extension * - **************************************/ - -#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x2031 -#define CL_CONTEXT_TERMINATE_KHR 0x2032 - -#define cl_khr_terminate_context 1 -extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; - - -/* - * Extension: cl_khr_spir - * - * This extension adds support to create an OpenCL program object from a - * Standard Portable Intermediate Representation (SPIR) instance - */ - -#define CL_DEVICE_SPIR_VERSIONS 0x40E0 -#define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE 0x40E1 - - -/****************************************** -* cl_nv_device_attribute_query extension * -******************************************/ -/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ -#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 -#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 -#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 -#define CL_DEVICE_WARP_SIZE_NV 0x4003 -#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 -#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 -#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 - -/********************************* -* cl_amd_device_attribute_query * -*********************************/ -#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 - -/********************************* -* cl_arm_printf extension -*********************************/ -#define CL_PRINTF_CALLBACK_ARM 0x40B0 -#define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 - -#ifdef CL_VERSION_1_1 - /*********************************** - * cl_ext_device_fission extension * - ***********************************/ - #define cl_ext_device_fission 1 - - extern CL_API_ENTRY cl_int CL_API_CALL - clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - extern CL_API_ENTRY cl_int CL_API_CALL - clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef cl_ulong cl_device_partition_property_ext; - extern CL_API_ENTRY cl_int CL_API_CALL - clCreateSubDevicesEXT( cl_device_id /*in_device*/, - const cl_device_partition_property_ext * /* properties */, - cl_uint /*num_entries*/, - cl_device_id * /*out_devices*/, - cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - ( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, - const cl_device_partition_property_ext * /* properties */, - cl_uint /*num_entries*/, - cl_device_id * /*out_devices*/, - cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - /* cl_device_partition_property_ext */ - #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 - #define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 - #define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 - #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 - - /* clDeviceGetInfo selectors */ - #define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 - #define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 - #define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 - #define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 - #define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 - - /* error codes */ - #define CL_DEVICE_PARTITION_FAILED_EXT -1057 - #define CL_INVALID_PARTITION_COUNT_EXT -1058 - #define CL_INVALID_PARTITION_NAME_EXT -1059 - - /* CL_AFFINITY_DOMAINs */ - #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 - #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 - #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 - #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 - #define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 - #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 - - /* cl_device_partition_property_ext list terminators */ - #define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) - #define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) - #define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) - -/********************************* -* cl_qcom_ext_host_ptr extension -*********************************/ - -#define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) - -#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 -#define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 -#define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 -#define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 -#define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 -#define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 -#define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 -#define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 - -typedef cl_uint cl_image_pitch_info_qcom; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceImageInfoQCOM(cl_device_id device, - size_t image_width, - size_t image_height, - const cl_image_format *image_format, - cl_image_pitch_info_qcom param_name, - size_t param_value_size, - void *param_value, - size_t *param_value_size_ret); - -typedef struct _cl_mem_ext_host_ptr -{ - /* Type of external memory allocation. */ - /* Legal values will be defined in layered extensions. */ - cl_uint allocation_type; - - /* Host cache policy for this external memory allocation. */ - cl_uint host_cache_policy; - -} cl_mem_ext_host_ptr; - -/********************************* -* cl_qcom_ion_host_ptr extension -*********************************/ - -#define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 - -typedef struct _cl_mem_ion_host_ptr -{ - /* Type of external memory allocation. */ - /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ - cl_mem_ext_host_ptr ext_host_ptr; - - /* ION file descriptor */ - int ion_filedesc; - - /* Host pointer to the ION allocated memory */ - void* ion_hostptr; - -} cl_mem_ion_host_ptr; - -#endif /* CL_VERSION_1_1 */ - -#if defined(CL_VERSION_1_2) - -/****************************************** - * cl_img_yuv_image extension * - ******************************************/ - -/* Image formats used in clCreateImage */ -#define CL_NV21_IMG 0x40D0 -#define CL_YV12_IMG 0x40D1 - -/****************************************** - * cl_img_cached_allocations extension * - ******************************************/ - -/* Flag values used by clCreteBuffer */ -#define CL_MEM_USE_UNCACHED_CPU_MEMORY_IMG (1 << 26) -#define CL_MEM_USE_CACHED_CPU_MEMORY_IMG (1 << 27) - -/****************************************** - * cl_img_use_gralloc_ptr extension * - ******************************************/ - -/* Flag values used by clCreteBuffer */ -#define CL_MEM_USE_GRALLOC_PTR_IMG (1 << 28) - -/* To be used by clGetEventInfo: */ -#define CL_COMMAND_ACQUIRE_GRALLOC_OBJECTS_IMG 0x40D2 -#define CL_COMMAND_RELEASE_GRALLOC_OBJECTS_IMG 0x40D3 - -/* Error code from clEnqueueReleaseGrallocObjectsIMG */ -#define CL_GRALLOC_RESOURCE_NOT_ACQUIRED_IMG 0x40D4 - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireGrallocObjectsIMG(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseGrallocObjectsIMG(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_2; - -#endif /* CL_VERSION_1_2 */ - -#ifdef CL_VERSION_2_0 -/********************************* -* cl_khr_sub_groups extension -*********************************/ -#define cl_khr_sub_groups 1 - -typedef cl_uint cl_kernel_sub_group_info_khr; - -/* cl_khr_sub_group_info */ -#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR 0x2033 -#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR 0x2034 - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelSubGroupInfoKHR(cl_kernel /* in_kernel */, - cl_device_id /*in_device*/, - cl_kernel_sub_group_info_khr /* param_name */, - size_t /*input_value_size*/, - const void * /*input_value*/, - size_t /*param_value_size*/, - void* /*param_value*/, - size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; - -typedef CL_API_ENTRY cl_int - ( CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel /* in_kernel */, - cl_device_id /*in_device*/, - cl_kernel_sub_group_info_khr /* param_name */, - size_t /*input_value_size*/, - const void * /*input_value*/, - size_t /*param_value_size*/, - void* /*param_value*/, - size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; -#endif /* CL_VERSION_2_0 */ - -#ifdef CL_VERSION_2_1 -/********************************* -* cl_khr_priority_hints extension -*********************************/ -#define cl_khr_priority_hints 1 - -typedef cl_uint cl_queue_priority_khr; - -/* cl_command_queue_properties */ -#define CL_QUEUE_PRIORITY_KHR 0x1096 - -/* cl_queue_priority_khr */ -#define CL_QUEUE_PRIORITY_HIGH_KHR (1<<0) -#define CL_QUEUE_PRIORITY_MED_KHR (1<<1) -#define CL_QUEUE_PRIORITY_LOW_KHR (1<<2) - -#endif /* CL_VERSION_2_1 */ - -#ifdef CL_VERSION_2_1 -/********************************* -* cl_khr_throttle_hints extension -*********************************/ -#define cl_khr_throttle_hints 1 - -typedef cl_uint cl_queue_throttle_khr; - -/* cl_command_queue_properties */ -#define CL_QUEUE_THROTTLE_KHR 0x1097 - -/* cl_queue_throttle_khr */ -#define CL_QUEUE_THROTTLE_HIGH_KHR (1<<0) -#define CL_QUEUE_THROTTLE_MED_KHR (1<<1) -#define CL_QUEUE_THROTTLE_LOW_KHR (1<<2) - -#endif /* CL_VERSION_2_1 */ - -#ifdef __cplusplus -} -#endif - - -#endif /* __CL_EXT_H */ diff --git a/src/3rdparty/CL/cl_gl.h b/src/3rdparty/CL/cl_gl.h deleted file mode 100644 index 945daa83d7..0000000000 --- a/src/3rdparty/CL/cl_gl.h +++ /dev/null @@ -1,167 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -#ifndef __OPENCL_CL_GL_H -#define __OPENCL_CL_GL_H - -#ifdef __APPLE__ -#include -#else -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef cl_uint cl_gl_object_type; -typedef cl_uint cl_gl_texture_info; -typedef cl_uint cl_gl_platform_info; -typedef struct __GLsync *cl_GLsync; - -/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ -#define CL_GL_OBJECT_BUFFER 0x2000 -#define CL_GL_OBJECT_TEXTURE2D 0x2001 -#define CL_GL_OBJECT_TEXTURE3D 0x2002 -#define CL_GL_OBJECT_RENDERBUFFER 0x2003 -#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E -#define CL_GL_OBJECT_TEXTURE1D 0x200F -#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 -#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 - -/* cl_gl_texture_info */ -#define CL_GL_TEXTURE_TARGET 0x2004 -#define CL_GL_MIPMAP_LEVEL 0x2005 -#define CL_GL_NUM_SAMPLES 0x2012 - - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLBuffer(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLuint /* bufobj */, - int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLTexture(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLRenderbuffer(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLuint /* renderbuffer */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLObjectInfo(cl_mem /* memobj */, - cl_gl_object_type * /* gl_object_type */, - cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLTextureInfo(cl_mem /* memobj */, - cl_gl_texture_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - - -/* Deprecated OpenCL 1.1 APIs */ -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateFromGLTexture2D(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateFromGLTexture3D(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -/* cl_khr_gl_sharing extension */ - -#define cl_khr_gl_sharing 1 - -typedef cl_uint cl_gl_context_info; - -/* Additional Error Codes */ -#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 - -/* cl_gl_context_info */ -#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 -#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 - -/* Additional cl_context_properties */ -#define CL_GL_CONTEXT_KHR 0x2008 -#define CL_EGL_DISPLAY_KHR 0x2009 -#define CL_GLX_DISPLAY_KHR 0x200A -#define CL_WGL_HDC_KHR 0x200B -#define CL_CGL_SHAREGROUP_KHR 0x200C - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLContextInfoKHR(const cl_context_properties * /* properties */, - cl_gl_context_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( - const cl_context_properties * properties, - cl_gl_context_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret); - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_GL_H */ diff --git a/src/3rdparty/CL/cl_gl_ext.h b/src/3rdparty/CL/cl_gl_ext.h deleted file mode 100644 index e3c14c6408..0000000000 --- a/src/3rdparty/CL/cl_gl_ext.h +++ /dev/null @@ -1,74 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ -/* OpenGL dependencies. */ - -#ifndef __OPENCL_CL_GL_EXT_H -#define __OPENCL_CL_GL_EXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - #include -#else - #include -#endif - -/* - * For each extension, follow this template - * cl_VEN_extname extension */ -/* #define cl_VEN_extname 1 - * ... define new types, if any - * ... define new tokens, if any - * ... define new APIs, if any - * - * If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header - * This allows us to avoid having to decide whether to include GL headers or GLES here. - */ - -/* - * cl_khr_gl_event extension - * See section 9.9 in the OpenCL 1.1 spec for more information - */ -#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateEventFromGLsyncKHR(cl_context /* context */, - cl_GLsync /* cl_GLsync */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_GL_EXT_H */ diff --git a/src/3rdparty/CL/cl_platform.h b/src/3rdparty/CL/cl_platform.h deleted file mode 100644 index 43520fd9bd..0000000000 --- a/src/3rdparty/CL/cl_platform.h +++ /dev/null @@ -1,1412 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11803 $ on $Date: 2010-06-25 10:02:12 -0700 (Fri, 25 Jun 2010) $ */ - -#ifndef __CL_PLATFORM_H -#define __CL_PLATFORM_H - -#ifdef __APPLE__ - /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */ - #include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_WIN32) - #define CL_API_ENTRY - #define CL_API_CALL __stdcall - #define CL_CALLBACK __stdcall -#else - #define CL_API_ENTRY - #define CL_API_CALL - #define CL_CALLBACK -#endif - -/* - * Deprecation flags refer to the last version of the header in which the - * feature was not deprecated. - * - * E.g. VERSION_1_1_DEPRECATED means the feature is present in 1.1 without - * deprecation but is deprecated in versions later than 1.1. - */ - -#ifdef __APPLE__ - #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import)) - #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7 - - #ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_8 - #else - #warning This path should never happen outside of internal operating system development. AvailabilityMacros do not function correctly here! - #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #endif -#else - #define CL_EXTENSION_WEAK_LINK - #define CL_API_SUFFIX__VERSION_1_0 - #define CL_EXT_SUFFIX__VERSION_1_0 - #define CL_API_SUFFIX__VERSION_1_1 - #define CL_EXT_SUFFIX__VERSION_1_1 - #define CL_API_SUFFIX__VERSION_1_2 - #define CL_EXT_SUFFIX__VERSION_1_2 - #define CL_API_SUFFIX__VERSION_2_0 - #define CL_EXT_SUFFIX__VERSION_2_0 - #define CL_API_SUFFIX__VERSION_2_1 - #define CL_EXT_SUFFIX__VERSION_2_1 - - #ifdef __GNUC__ - #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED - #endif - #elif _WIN32 - #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED __declspec(deprecated) - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED __declspec(deprecated) - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_2_APIS - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED __declspec(deprecated) - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_2_0_APIS - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED __declspec(deprecated) - #endif - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - - #define CL_EXT_SUFFIX__VERSION_1_2_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_2_DEPRECATED - - #define CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_2_0_DEPRECATED - #endif -#endif - -#if (defined (_WIN32) && defined(_MSC_VER)) - -/* scalar types */ -typedef signed __int8 cl_char; -typedef unsigned __int8 cl_uchar; -typedef signed __int16 cl_short; -typedef unsigned __int16 cl_ushort; -typedef signed __int32 cl_int; -typedef unsigned __int32 cl_uint; -typedef signed __int64 cl_long; -typedef unsigned __int64 cl_ulong; - -typedef unsigned __int16 cl_half; -typedef float cl_float; -typedef double cl_double; - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 340282346638528859811704183484516925440.0f -#define CL_FLT_MIN 1.175494350822287507969e-38f -#define CL_FLT_EPSILON 0x1.0p-23f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 -#define CL_DBL_MIN 2.225073858507201383090e-308 -#define CL_DBL_EPSILON 2.220446049250313080847e-16 - -#define CL_M_E 2.718281828459045090796 -#define CL_M_LOG2E 1.442695040888963387005 -#define CL_M_LOG10E 0.434294481903251816668 -#define CL_M_LN2 0.693147180559945286227 -#define CL_M_LN10 2.302585092994045901094 -#define CL_M_PI 3.141592653589793115998 -#define CL_M_PI_2 1.570796326794896557999 -#define CL_M_PI_4 0.785398163397448278999 -#define CL_M_1_PI 0.318309886183790691216 -#define CL_M_2_PI 0.636619772367581382433 -#define CL_M_2_SQRTPI 1.128379167095512558561 -#define CL_M_SQRT2 1.414213562373095145475 -#define CL_M_SQRT1_2 0.707106781186547572737 - -#define CL_M_E_F 2.71828174591064f -#define CL_M_LOG2E_F 1.44269502162933f -#define CL_M_LOG10E_F 0.43429449200630f -#define CL_M_LN2_F 0.69314718246460f -#define CL_M_LN10_F 2.30258512496948f -#define CL_M_PI_F 3.14159274101257f -#define CL_M_PI_2_F 1.57079637050629f -#define CL_M_PI_4_F 0.78539818525314f -#define CL_M_1_PI_F 0.31830987334251f -#define CL_M_2_PI_F 0.63661974668503f -#define CL_M_2_SQRTPI_F 1.12837922573090f -#define CL_M_SQRT2_F 1.41421353816986f -#define CL_M_SQRT1_2_F 0.70710676908493f - -#define CL_NAN (CL_INFINITY - CL_INFINITY) -#define CL_HUGE_VALF ((cl_float) 1e50) -#define CL_HUGE_VAL ((cl_double) 1e500) -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#else - -#include - -/* scalar types */ -typedef int8_t cl_char; -typedef uint8_t cl_uchar; -typedef int16_t cl_short __attribute__((aligned(2))); -typedef uint16_t cl_ushort __attribute__((aligned(2))); -typedef int32_t cl_int __attribute__((aligned(4))); -typedef uint32_t cl_uint __attribute__((aligned(4))); -typedef int64_t cl_long __attribute__((aligned(8))); -typedef uint64_t cl_ulong __attribute__((aligned(8))); - -typedef uint16_t cl_half __attribute__((aligned(2))); -typedef float cl_float __attribute__((aligned(4))); -typedef double cl_double __attribute__((aligned(8))); - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 0x1.fffffep127f -#define CL_FLT_MIN 0x1.0p-126f -#define CL_FLT_EPSILON 0x1.0p-23f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 0x1.fffffffffffffp1023 -#define CL_DBL_MIN 0x1.0p-1022 -#define CL_DBL_EPSILON 0x1.0p-52 - -#define CL_M_E 2.718281828459045090796 -#define CL_M_LOG2E 1.442695040888963387005 -#define CL_M_LOG10E 0.434294481903251816668 -#define CL_M_LN2 0.693147180559945286227 -#define CL_M_LN10 2.302585092994045901094 -#define CL_M_PI 3.141592653589793115998 -#define CL_M_PI_2 1.570796326794896557999 -#define CL_M_PI_4 0.785398163397448278999 -#define CL_M_1_PI 0.318309886183790691216 -#define CL_M_2_PI 0.636619772367581382433 -#define CL_M_2_SQRTPI 1.128379167095512558561 -#define CL_M_SQRT2 1.414213562373095145475 -#define CL_M_SQRT1_2 0.707106781186547572737 - -#define CL_M_E_F 2.71828174591064f -#define CL_M_LOG2E_F 1.44269502162933f -#define CL_M_LOG10E_F 0.43429449200630f -#define CL_M_LN2_F 0.69314718246460f -#define CL_M_LN10_F 2.30258512496948f -#define CL_M_PI_F 3.14159274101257f -#define CL_M_PI_2_F 1.57079637050629f -#define CL_M_PI_4_F 0.78539818525314f -#define CL_M_1_PI_F 0.31830987334251f -#define CL_M_2_PI_F 0.63661974668503f -#define CL_M_2_SQRTPI_F 1.12837922573090f -#define CL_M_SQRT2_F 1.41421353816986f -#define CL_M_SQRT1_2_F 0.70710676908493f - -#if defined( __GNUC__ ) - #define CL_HUGE_VALF __builtin_huge_valf() - #define CL_HUGE_VAL __builtin_huge_val() - #define CL_NAN __builtin_nanf( "" ) -#else - #define CL_HUGE_VALF ((cl_float) 1e50) - #define CL_HUGE_VAL ((cl_double) 1e500) - float nanf( const char * ); - #define CL_NAN nanf( "" ) -#endif -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#endif - -#include - -/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */ -typedef unsigned int cl_GLuint; -typedef int cl_GLint; -typedef unsigned int cl_GLenum; - -/* - * Vector types - * - * Note: OpenCL requires that all types be naturally aligned. - * This means that vector types must be naturally aligned. - * For example, a vector of four floats must be aligned to - * a 16 byte boundary (calculated as 4 * the natural 4-byte - * alignment of the float). The alignment qualifiers here - * will only function properly if your compiler supports them - * and if you don't actively work to defeat them. For example, - * in order for a cl_float4 to be 16 byte aligned in a struct, - * the start of the struct must itself be 16-byte aligned. - * - * Maintaining proper alignment is the user's responsibility. - */ - -/* Define basic vector types */ -#if defined( __VEC__ ) - #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ - typedef vector unsigned char __cl_uchar16; - typedef vector signed char __cl_char16; - typedef vector unsigned short __cl_ushort8; - typedef vector signed short __cl_short8; - typedef vector unsigned int __cl_uint4; - typedef vector signed int __cl_int4; - typedef vector float __cl_float4; - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_UINT4__ 1 - #define __CL_INT4__ 1 - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef float __cl_float4 __attribute__((vector_size(16))); - #else - typedef __m128 __cl_float4; - #endif - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE2__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); - typedef cl_char __cl_char16 __attribute__((vector_size(16))); - typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); - typedef cl_short __cl_short8 __attribute__((vector_size(16))); - typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); - typedef cl_int __cl_int4 __attribute__((vector_size(16))); - typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); - typedef cl_long __cl_long2 __attribute__((vector_size(16))); - typedef cl_double __cl_double2 __attribute__((vector_size(16))); - #else - typedef __m128i __cl_uchar16; - typedef __m128i __cl_char16; - typedef __m128i __cl_ushort8; - typedef __m128i __cl_short8; - typedef __m128i __cl_uint4; - typedef __m128i __cl_int4; - typedef __m128i __cl_ulong2; - typedef __m128i __cl_long2; - typedef __m128d __cl_double2; - #endif - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_INT4__ 1 - #define __CL_UINT4__ 1 - #define __CL_ULONG2__ 1 - #define __CL_LONG2__ 1 - #define __CL_DOUBLE2__ 1 -#endif - -#if defined( __MMX__ ) - #include - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); - typedef cl_char __cl_char8 __attribute__((vector_size(8))); - typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); - typedef cl_short __cl_short4 __attribute__((vector_size(8))); - typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); - typedef cl_int __cl_int2 __attribute__((vector_size(8))); - typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); - typedef cl_long __cl_long1 __attribute__((vector_size(8))); - typedef cl_float __cl_float2 __attribute__((vector_size(8))); - #else - typedef __m64 __cl_uchar8; - typedef __m64 __cl_char8; - typedef __m64 __cl_ushort4; - typedef __m64 __cl_short4; - typedef __m64 __cl_uint2; - typedef __m64 __cl_int2; - typedef __m64 __cl_ulong1; - typedef __m64 __cl_long1; - typedef __m64 __cl_float2; - #endif - #define __CL_UCHAR8__ 1 - #define __CL_CHAR8__ 1 - #define __CL_USHORT4__ 1 - #define __CL_SHORT4__ 1 - #define __CL_INT2__ 1 - #define __CL_UINT2__ 1 - #define __CL_ULONG1__ 1 - #define __CL_LONG1__ 1 - #define __CL_FLOAT2__ 1 -#endif - -#if defined( __AVX__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef cl_float __cl_float8 __attribute__((vector_size(32))); - typedef cl_double __cl_double4 __attribute__((vector_size(32))); - #else - typedef __m256 __cl_float8; - typedef __m256d __cl_double4; - #endif - #define __CL_FLOAT8__ 1 - #define __CL_DOUBLE4__ 1 -#endif - -/* Define capabilities for anonymous struct members. */ -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) -#define __CL_HAS_ANON_STRUCT__ 1 -#define __CL_ANON_STRUCT__ __extension__ -#elif defined( _WIN32) && defined(_MSC_VER) - #if _MSC_VER >= 1500 - /* Microsoft Developer Studio 2008 supports anonymous structs, but - * complains by default. */ - #define __CL_HAS_ANON_STRUCT__ 1 - #define __CL_ANON_STRUCT__ - /* Disable warning C4201: nonstandard extension used : nameless - * struct/union */ - #pragma warning( push ) - #pragma warning( disable : 4201 ) - #endif -#else -#define __CL_HAS_ANON_STRUCT__ 0 -#define __CL_ANON_STRUCT__ -#endif - -/* Define alignment keys */ -#if defined( __GNUC__ ) - #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) -#elif defined( _WIN32) && (_MSC_VER) - /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ - /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ - /* #include */ - /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ - #define CL_ALIGNED(_x) -#else - #warning Need to implement some method to align data here - #define CL_ALIGNED(_x) -#endif - -/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ -#if __CL_HAS_ANON_STRUCT__ - /* .xyzw and .s0123...{f|F} are supported */ - #define CL_HAS_NAMED_VECTOR_FIELDS 1 - /* .hi and .lo are supported */ - #define CL_HAS_HI_LO_VECTOR_FIELDS 1 -#endif - -/* Define cl_vector types */ - -/* ---- cl_charn ---- */ -typedef union -{ - cl_char CL_ALIGNED(2) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_char lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2; -#endif -}cl_char2; - -typedef union -{ - cl_char CL_ALIGNED(4) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_char2 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[2]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4; -#endif -}cl_char4; - -/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ -typedef cl_char4 cl_char3; - -typedef union -{ - cl_char CL_ALIGNED(8) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_char4 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[4]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[2]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8; -#endif -}cl_char8; - -typedef union -{ - cl_char CL_ALIGNED(16) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_char8 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[8]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[4]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8[2]; -#endif -#if defined( __CL_CHAR16__ ) - __cl_char16 v16; -#endif -}cl_char16; - - -/* ---- cl_ucharn ---- */ -typedef union -{ - cl_uchar CL_ALIGNED(2) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_uchar lo, hi; }; -#endif -#if defined( __cl_uchar2__) - __cl_uchar2 v2; -#endif -}cl_uchar2; - -typedef union -{ - cl_uchar CL_ALIGNED(4) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_uchar2 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[2]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4; -#endif -}cl_uchar4; - -/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ -typedef cl_uchar4 cl_uchar3; - -typedef union -{ - cl_uchar CL_ALIGNED(8) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_uchar4 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[4]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[2]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8; -#endif -}cl_uchar8; - -typedef union -{ - cl_uchar CL_ALIGNED(16) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_uchar8 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[8]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[4]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8[2]; -#endif -#if defined( __CL_UCHAR16__ ) - __cl_uchar16 v16; -#endif -}cl_uchar16; - - -/* ---- cl_shortn ---- */ -typedef union -{ - cl_short CL_ALIGNED(4) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_short lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2; -#endif -}cl_short2; - -typedef union -{ - cl_short CL_ALIGNED(8) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_short2 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[2]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4; -#endif -}cl_short4; - -/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ -typedef cl_short4 cl_short3; - -typedef union -{ - cl_short CL_ALIGNED(16) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_short4 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[4]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[2]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8; -#endif -}cl_short8; - -typedef union -{ - cl_short CL_ALIGNED(32) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_short8 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[8]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[4]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8[2]; -#endif -#if defined( __CL_SHORT16__ ) - __cl_short16 v16; -#endif -}cl_short16; - - -/* ---- cl_ushortn ---- */ -typedef union -{ - cl_ushort CL_ALIGNED(4) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_ushort lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2; -#endif -}cl_ushort2; - -typedef union -{ - cl_ushort CL_ALIGNED(8) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_ushort2 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[2]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4; -#endif -}cl_ushort4; - -/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ -typedef cl_ushort4 cl_ushort3; - -typedef union -{ - cl_ushort CL_ALIGNED(16) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_ushort4 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[4]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[2]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8; -#endif -}cl_ushort8; - -typedef union -{ - cl_ushort CL_ALIGNED(32) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_ushort8 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[8]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[4]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8[2]; -#endif -#if defined( __CL_USHORT16__ ) - __cl_ushort16 v16; -#endif -}cl_ushort16; - - -/* ---- cl_halfn ---- */ -typedef union -{ - cl_half CL_ALIGNED(4) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_half lo, hi; }; -#endif -#if defined( __CL_HALF2__) - __cl_half2 v2; -#endif -}cl_half2; - -typedef union -{ - cl_half CL_ALIGNED(8) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_half2 lo, hi; }; -#endif -#if defined( __CL_HALF2__) - __cl_half2 v2[2]; -#endif -#if defined( __CL_HALF4__) - __cl_half4 v4; -#endif -}cl_half4; - -/* cl_half3 is identical in size, alignment and behavior to cl_half4. See section 6.1.5. */ -typedef cl_half4 cl_half3; - -typedef union -{ - cl_half CL_ALIGNED(16) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_half4 lo, hi; }; -#endif -#if defined( __CL_HALF2__) - __cl_half2 v2[4]; -#endif -#if defined( __CL_HALF4__) - __cl_half4 v4[2]; -#endif -#if defined( __CL_HALF8__ ) - __cl_half8 v8; -#endif -}cl_half8; - -typedef union -{ - cl_half CL_ALIGNED(32) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_half x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_half s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_half8 lo, hi; }; -#endif -#if defined( __CL_HALF2__) - __cl_half2 v2[8]; -#endif -#if defined( __CL_HALF4__) - __cl_half4 v4[4]; -#endif -#if defined( __CL_HALF8__ ) - __cl_half8 v8[2]; -#endif -#if defined( __CL_HALF16__ ) - __cl_half16 v16; -#endif -}cl_half16; - -/* ---- cl_intn ---- */ -typedef union -{ - cl_int CL_ALIGNED(8) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_int lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2; -#endif -}cl_int2; - -typedef union -{ - cl_int CL_ALIGNED(16) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_int2 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[2]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4; -#endif -}cl_int4; - -/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ -typedef cl_int4 cl_int3; - -typedef union -{ - cl_int CL_ALIGNED(32) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_int4 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[4]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[2]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8; -#endif -}cl_int8; - -typedef union -{ - cl_int CL_ALIGNED(64) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_int8 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[8]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[4]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8[2]; -#endif -#if defined( __CL_INT16__ ) - __cl_int16 v16; -#endif -}cl_int16; - - -/* ---- cl_uintn ---- */ -typedef union -{ - cl_uint CL_ALIGNED(8) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_uint lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2; -#endif -}cl_uint2; - -typedef union -{ - cl_uint CL_ALIGNED(16) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_uint2 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[2]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4; -#endif -}cl_uint4; - -/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ -typedef cl_uint4 cl_uint3; - -typedef union -{ - cl_uint CL_ALIGNED(32) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_uint4 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[4]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[2]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8; -#endif -}cl_uint8; - -typedef union -{ - cl_uint CL_ALIGNED(64) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_uint8 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[8]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[4]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8[2]; -#endif -#if defined( __CL_UINT16__ ) - __cl_uint16 v16; -#endif -}cl_uint16; - -/* ---- cl_longn ---- */ -typedef union -{ - cl_long CL_ALIGNED(16) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_long lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2; -#endif -}cl_long2; - -typedef union -{ - cl_long CL_ALIGNED(32) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_long2 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[2]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4; -#endif -}cl_long4; - -/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ -typedef cl_long4 cl_long3; - -typedef union -{ - cl_long CL_ALIGNED(64) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_long4 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[4]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[2]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8; -#endif -}cl_long8; - -typedef union -{ - cl_long CL_ALIGNED(128) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_long8 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[8]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[4]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8[2]; -#endif -#if defined( __CL_LONG16__ ) - __cl_long16 v16; -#endif -}cl_long16; - - -/* ---- cl_ulongn ---- */ -typedef union -{ - cl_ulong CL_ALIGNED(16) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_ulong lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2; -#endif -}cl_ulong2; - -typedef union -{ - cl_ulong CL_ALIGNED(32) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_ulong2 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[2]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4; -#endif -}cl_ulong4; - -/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ -typedef cl_ulong4 cl_ulong3; - -typedef union -{ - cl_ulong CL_ALIGNED(64) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_ulong4 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[4]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[2]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8; -#endif -}cl_ulong8; - -typedef union -{ - cl_ulong CL_ALIGNED(128) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_ulong8 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[8]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[4]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8[2]; -#endif -#if defined( __CL_ULONG16__ ) - __cl_ulong16 v16; -#endif -}cl_ulong16; - - -/* --- cl_floatn ---- */ - -typedef union -{ - cl_float CL_ALIGNED(8) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_float lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2; -#endif -}cl_float2; - -typedef union -{ - cl_float CL_ALIGNED(16) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_float2 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[2]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4; -#endif -}cl_float4; - -/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ -typedef cl_float4 cl_float3; - -typedef union -{ - cl_float CL_ALIGNED(32) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_float4 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[4]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[2]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8; -#endif -}cl_float8; - -typedef union -{ - cl_float CL_ALIGNED(64) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_float8 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[8]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[4]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8[2]; -#endif -#if defined( __CL_FLOAT16__ ) - __cl_float16 v16; -#endif -}cl_float16; - -/* --- cl_doublen ---- */ - -typedef union -{ - cl_double CL_ALIGNED(16) s[2]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1; }; - __CL_ANON_STRUCT__ struct{ cl_double lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2; -#endif -}cl_double2; - -typedef union -{ - cl_double CL_ALIGNED(32) s[4]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3; }; - __CL_ANON_STRUCT__ struct{ cl_double2 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[2]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4; -#endif -}cl_double4; - -/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ -typedef cl_double4 cl_double3; - -typedef union -{ - cl_double CL_ALIGNED(64) s[8]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; - __CL_ANON_STRUCT__ struct{ cl_double4 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[4]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[2]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8; -#endif -}cl_double8; - -typedef union -{ - cl_double CL_ALIGNED(128) s[16]; -#if __CL_HAS_ANON_STRUCT__ - __CL_ANON_STRUCT__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __CL_ANON_STRUCT__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __CL_ANON_STRUCT__ struct{ cl_double8 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[8]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[4]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8[2]; -#endif -#if defined( __CL_DOUBLE16__ ) - __cl_double16 v16; -#endif -}cl_double16; - -/* Macro to facilitate debugging - * Usage: - * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. - * The first line ends with: CL_PROGRAM_STRING_DEBUG_INFO \" - * Each line thereafter of OpenCL C source must end with: \n\ - * The last line ends in "; - * - * Example: - * - * const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\ - * kernel void foo( int a, float * b ) \n\ - * { \n\ - * // my comment \n\ - * *b[ get_global_id(0)] = a; \n\ - * } \n\ - * "; - * - * This should correctly set up the line, (column) and file information for your source - * string so you can do source level debugging. - */ -#define __CL_STRINGIFY( _x ) # _x -#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) -#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" - -#ifdef __cplusplus -} -#endif - -#undef __CL_HAS_ANON_STRUCT__ -#undef __CL_ANON_STRUCT__ -#if defined( _WIN32) && defined(_MSC_VER) - #if _MSC_VER >=1500 - #pragma warning( pop ) - #endif -#endif - -#endif /* __CL_PLATFORM_H */ diff --git a/src/3rdparty/CL/opencl.h b/src/3rdparty/CL/opencl.h deleted file mode 100644 index 9855cd75e7..0000000000 --- a/src/3rdparty/CL/opencl.h +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2015 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS - * KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS - * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT - * https://www.khronos.org/registry/ - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_H -#define __OPENCL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - -#include -#include -#include -#include - -#else - -#include -#include -#include -#include - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_H */ - diff --git a/src/3rdparty/clwinlib/OpenCL.lib b/src/3rdparty/clwinlib/OpenCL.lib deleted file mode 100644 index 98bc2d748d735f2cc19ac7e5c50267ece18fb5b9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23076 zcmds9OKhA)5-tcVU?2n%LI@C?5b`1FzeC# zu6|Wlx3l#~p*nxzSi}BC``4UnZaa9OwY{Us=BsF1u1S8*HUPlC0QP(Vu=hH^zKsC; z%YvGE0XThvAyV@eN$+6D=ubf{D9@<%w4`q_M9O_EsBHrPr#CTV^pl|Wa{!DECiPnhra}1bfiVnhZrIqMHxoN<|KWGAyVfaN$+Eb)U{U9uNWeA&r13p zL!_QgNuOef)Vo7aUjqQAH!x)MgP{Iy08S{|k2KII=^YFi{VwPP;&8f(A=2O#K_?N9 z6YBOP($Hl|Shpdh;YCT9XBcS&$+so_f+5n>8A)Gbh;+I|(gzqKO}{1R3}Q1n`?;Ww8~~$( z>jWJ>f&GZobxBa~d#Gom=?#*8#t`Yu1ws3_16*RO7^^7!D7Bv1D>I-Rdv!Js${?GQ#%nXi|Sj8`k?tA!YbRjc1`;Cr3UiEVxZ1Jdd=~ zNG9xUWj-oJg%#g;i={XylZBOwW-#!WBQaH8DlCsgOJXP+S%>fBnl2P;{grCpt5KN_ zf1B;*sTRpDAP4m{Vfy496>)J}NBzZeapeM5Tz;rh`b(>V%|pc3*@A#YnrK``<4PeGCsJIo2G2xY8C=m8i=|@uyd!M$X|C65 zQF*0UDfh3I=W7^tEi6={6>B<}B2vJuz zjB8Y5Vs<%1F-#<;7sfO?V2!Xjc40UXDWw4=rQ%9z!d`{3kmaaaV-{Xg3dt#2 z&{aJz#7$JmOqENO!UF1hxhRY|hoR)`-DYRwq{H^xp1rY{{vWNbHMPJt1j0 zN-}2A<p?NK30Pe6)rkmF|=Hjoj|SAl`^xgy)e~svyF)K4gNh!2K2Tq&Y|yv>B$XF8s3f}ucQLi$Vo50l zNx6D)F}tVDQnJIv@v%`WP!?$Bh(QeTfi>DjBhysdmNIxmZGWpK7!A zsYU?s#U6m`djU4?11RrD4_6bwCrDeG0p3CS6RFHRXsrO>B7K|#*w6;>Celwx=i1RL zcL3lUq)P_@enYx;2;j@Z=mkTM)`v*H9R-*}PuO=zdpZH$M_Stj@GH_RdMCd}>g)md z6ln)~vl{vU-az^Rsk%( zBYM%^MfwBj+8BB;#{ssTLLSl|NQ-$a2kF=Z$|Jo!3GfTjnJIv;ky=gze1P=UH0D18 z@cCKv>U99D!*-s)HeSLuyoYt(fayOYT|k*@sK*~sXU9-iS5ZG7q5LfBWFzX~GSZRb z*e0Y=tp6sga~bRP8P;nv;`Uf}co891-oGnJO_K>dDsX0VHTR88CswKt&oE@XomyP0SDm_9ELeK0!LvUj=^#0 zgf8fY9_WPy=!1S3fD(SIFTY+lrxajTlp~_QY%;RY9Iifty ziEFf1R(Ug%r zk=`@ulx)rbZbz6DUq`T1duqv=NGnBocvjqEQ@9kJD*8`Z5{?{3TqKg@YXMKTo8WZ_ zs@k9}NS903X(Crfmn~)-^ZJl-B-3%|@WYdvpEGeiAwD}&P?8l(!IEUCrAvxb9p_eL zVEBf9I8ut==0z2X1h;U(P3dSOFv@au^sCv9hUL0!TxPT=;v6Gv>4kPM&KKd}NvJtHZp16@IfRH(+-fty zSgje;S82wN*O_tMDyQ%Y@tSClgHi!z6xCtwBEro1MU>cPDnX7M?s-YRAGYl=PhRJSSdBa-X{;~8QFfPN>0yG6lp9&h*3v1; z%5oW&!Jre3g=ES$Jlm6J_{y5HiV>S*oTV)&okVOWi|3SJ>?JLw?`a9gcSGxMY{2_t zTSU6_QFXY|!3e#lEr zpYGK zc3E!Rwl{cDdYLz}+L%zcw3?xHB3Bk;SMahV*OWwU2`=HcB5ZG<_WN1;FX4(~x@Jgg zLC3|0tD}0clxBo(Fm{Y&$$A@xS>imF0L#X9V6&r$IH?CqHq~G;QVSNfE5SIl4lHh} zkhHUVE*m&Yj|OZH=G9Q1ecXFo(sdE#|8_#-S9jvq!{|d~zXsE&ov?o0J;?fw zCtwnWSMraH6z8jzmC9nRaaVqK6WLKh6G;KUO-vyOc2&+=(7i zKzlK}NAFgRl9t>-`QVw2k~{e*`JC5`)em1cdq&BENYek3QG#B1@nfUppDH3lHcDpspb~?@WqeG zT~!eoGPzr=-87ng67g@%*Z1s|J)55km)W|7&x`SQ7p}#Y2b)Z6^O>#(a~*yp z)|xvwl3bwGmSOfwglj!IDPTVZx`zGaSxW|&@^D#SDt47p3ly!n<=hw_7aSn=*fgN zhgok=`0==(k~A^%Iv290p7diXhcep!iZ7W4H7Zap$<};lxLo4bw2QAjL%$f}CgU{G# z{659B<|gKR!aleYdu@9hD`{!V+{Vznf7Zf{y^kTyHJ|DFu}!&zoSktSwsr?awXc{A zO!iqAIJfPz5b5m|0nD!1z`Wl@5zQ?aY1K`Ppun!N+mBcOt`V61dtA)egf!YsIcfsd z@N+hrb6IGRvg3Gj%gs3!KzqKapQ0oz+ zRbcRoZ~~FJ9c_VCI>#}5m+bW*hR!c-2GLyL6EO3cPJ;x)vpM_f0p|H%81_EV1)3qwJJ|47?&<8|bOBkH&tABgKOx}%}Jfty` z{zAJRR>$}F$mdp9XbsjHE8s43V}19DchE? zFR=TwV+xHg&HQ3|1i@p{k4KttV#z^Q4eL`b-|GNeQm3dVOol6EeDt#kQfU?i>fK_&qBk9-m zmf*!@uTjP++O2qv62Lk|u{>8{S$iz>9wjfa z*gMVt#e0+q3okasGLMkZ8DWxO#iv+SErwRbDS{N6V7IhQrwLMgf@N+~z%H03NZ#p{ zyny?YOs~vXq5IJnI9AfTXVYKVSNxFe|DrJS(xGQ;tl k_v>|Fg-%qn1WO$` Date: Thu, 17 Feb 2022 16:20:13 +0100 Subject: [PATCH 13/91] Remove old code that @Erfan , @achal and @Criss implemented correctly --- include/IVideoCapabilityReporter.h | 28 - include/IVideoDriver.h | 38 - source/Nabla/COpenGLDriver.cpp | 1544 +-------- source/Nabla/COpenGLDriver.h | 213 -- source/Nabla/COpenGLExtensionHandler.h | 4160 +----------------------- source/Nabla/COpenGLQuery.cpp | 200 -- source/Nabla/COpenGLQuery.h | 64 - source/Nabla/COpenGLTimestampQuery.h | 67 - 8 files changed, 178 insertions(+), 6136 deletions(-) delete mode 100644 source/Nabla/COpenGLQuery.cpp delete mode 100644 source/Nabla/COpenGLQuery.h delete mode 100644 source/Nabla/COpenGLTimestampQuery.h diff --git a/include/IVideoCapabilityReporter.h b/include/IVideoCapabilityReporter.h index 162ea6be61..39fc6a5f54 100644 --- a/include/IVideoCapabilityReporter.h +++ b/include/IVideoCapabilityReporter.h @@ -5,10 +5,6 @@ #ifndef __NBL_I_VIDEO_CAPABILITY_REPORTER_H_INCLUDED__ #define __NBL_I_VIDEO_CAPABILITY_REPORTER_H_INCLUDED__ -#include - -#include "nbl/video/IGPUImageView.h" -//#include "EDriverTypes.h" namespace nbl @@ -59,32 +55,8 @@ namespace video EDF_COUNT }; - //! Queries the features of the driver. - /** Returns true if a feature is available - \param feature Feature to query. - \return True if the feature is available, false if not. */ - virtual bool queryFeature(const E_DRIVER_FEATURE& feature) const {return false;} - - //! Gets name of this video driver. - /** \return Returns the name of the video driver, e.g. in case - of the Direct3D8 driver, it would return "Direct3D 8.1". */ - virtual const wchar_t* getName() const =0; - - //! Get the graphics card vendor name. - virtual std::string getVendorInfo() =0; - - //! - virtual uint32_t getMinimumMemoryMapAlignment() const { return _NBL_MIN_MAP_BUFFER_ALIGNMENT; } - virtual uint16_t retrieveDisplayRefreshRate() const { return 0u; } virtual uint32_t getMaxTextureBindingsCompute() const { return 0u; } - - virtual bool isAllowedBufferViewFormat(asset::E_FORMAT _fmt) const { return false; } - virtual bool isAllowedVertexAttribFormat(asset::E_FORMAT _fmt) const { return false; } - virtual bool isColorRenderableFormat(asset::E_FORMAT _fmt) const { return false; } - virtual bool isAllowedImageStoreFormat(asset::E_FORMAT _fmt) const { return false; } - virtual bool isAllowedTextureFormat(asset::E_FORMAT _fmt) const { return false; } - virtual bool isHardwareBlendableFormat(asset::E_FORMAT _fmt) const { return false; } }; } // end namespace video diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index 75760b156f..5a4a5d56ed 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -6,11 +6,6 @@ #ifndef __NBL_I_VIDEO_DRIVER_H_INCLUDED__ #define __NBL_I_VIDEO_DRIVER_H_INCLUDED__ -#include "rect.h" -#include "matrixutil.h" -#include "dimension2d.h" -#include "position2d.h" -#include "nbl/video/IGPURenderpassIndependentPipeline.h" namespace nbl { @@ -24,39 +19,6 @@ namespace video //! virtual void issueGPUTextureBarrier() =0; - //! Allows data in one framebuffer to be blitted to another framebuffer - /** - A blit operation is a special form of copy operation. It copies a - rectangular area of pixels from one framebuffer to another. Note that - you should take care of your attachement inputs, so if for instance - their depth attachements don't match - you must not try to copy depth - between them. - - \param in Specifies an in framebuffer which data will be copied to out framebuffer. - \param out Specifies an out framebuffer that will be taking data from in framebuffer. - \param copyDepth Specifies whether depth attachement should be copied. - \param copyStencil Specifies whether stencil attachement should be copied. - \param srcRect Rectangular area in pixels for original source needed to copy to \bdstRect\b. - \param dstRect Rectangular area in pixels for destination source where \bsrcRect\b is a reference. - - It is perfectly valid to blit from or to the Default Framebuffer, - in such a case use \bnullptr\b. - */ - - virtual void blitRenderTargets(IFrameBuffer* in, IFrameBuffer* out, - bool copyDepth=true, bool copyStencil=true, - core::recti srcRect=core::recti(0,0,0,0), - core::recti dstRect=core::recti(0,0,0,0), - bool bilinearFilter=false) {} - - //! Draws a mesh buffer - /** \param mb Buffer to draw */ - virtual void drawMeshBuffer(const video::IGPUMeshBuffer* mb) =0; - - //! Get the size of the screen or render window. - /** \return Size of screen or render window. */ - virtual const core::dimension2d& getScreenSize() const =0; - //! Event handler for resize events. Only used by the engine internally. /** Used to notify the driver that the window was resized. Usually, there is no need to call this method. */ diff --git a/source/Nabla/COpenGLDriver.cpp b/source/Nabla/COpenGLDriver.cpp index 2300b8b5dc..eb6be51df9 100644 --- a/source/Nabla/COpenGLDriver.cpp +++ b/source/Nabla/COpenGLDriver.cpp @@ -5,98 +5,16 @@ #include "vectorSIMD.h" -#include "os.h" - -#include "nbl/asset/utils/IGLSLCompiler.h" -#include "nbl/asset/utils/CShaderIntrospector.h" -#include "nbl/asset/utils/spvUtils.h" #ifdef _NBL_COMPILE_WITH_OPENGL_ #include "COpenGLDriver.h" -#include "nbl/video/COpenGLImageView.h" -#include "nbl/video/COpenGLBufferView.h" - -#include "nbl/video/COpenGLPipelineCache.h" -#include "nbl/video/COpenGLShader.h" -#include "nbl/video/COpenGLSpecializedShader.h" - -#include "COpenGLBuffer.h" -#include "COpenGLFrameBuffer.h" -#include "COpenGLQuery.h" -#include "COpenGLTimestampQuery.h" - -#ifdef _NBL_COMPILE_WITH_SDL_DEVICE_ -#include "CIrrDeviceSDL.h" -#include -#endif - -#if defined(_NBL_COMPILE_WITH_WINDOWS_DEVICE_) -#define WIN32_LEAN_AND_MEAN -#include -#include "CIrrDeviceWin32.h" -#elif defined(_NBL_COMPILE_WITH_X11_DEVICE_) -#include "CIrrDeviceLinux.h" -#include -#include -#include -#ifdef _NBL_LINUX_X11_RANDR_ -#include -#endif -#endif - namespace nbl { namespace video { -// ----------------------------------------------------------------------- -// WINDOWS CONSTRUCTOR -// ----------------------------------------------------------------------- -#ifdef _NBL_COMPILE_WITH_WINDOWS_DEVICE_ -//! Windows constructor and init code -COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, - io::IFileSystem* io, CIrrDeviceWin32* device, const asset::IGLSLCompiler* glslcomp) -: CNullDriver(device, io, params), COpenGLExtensionHandler(), - runningInRenderDoc(false), ColorFormat(asset::EF_R8G8B8_UNORM), - HDc(0), Window(static_cast(params.WindowId)), Win32Device(device), - AuxContexts(0), GLSLCompiler(glslcomp), DeviceType(EIDT_WIN32) -{ - #ifdef _NBL_DEBUG - setDebugName("COpenGLDriver"); - #endif -} - -bool COpenGLDriver::changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWin32* device) -{ - if (videoData.OpenGLWin32.HWnd && videoData.OpenGLWin32.HDc && videoData.OpenGLWin32.HRc) - { - if (!wglMakeCurrent((HDC)videoData.OpenGLWin32.HDc, (HGLRC)videoData.OpenGLWin32.HRc)) - { - os::Printer::log("Render Context switch failed."); - return false; - } - else - { - HDc = (HDC)videoData.OpenGLWin32.HDc; - } - } - // set back to main context - else if (HDc != ExposedData.OpenGLWin32.HDc) - { - if (!wglMakeCurrent((HDC)ExposedData.OpenGLWin32.HDc, (HGLRC)ExposedData.OpenGLWin32.HRc)) - { - os::Printer::log("Render Context switch failed."); - return false; - } - else - { - HDc = (HDC)ExposedData.OpenGLWin32.HDc; - } - } - return true; -} //! inits the open gl driver bool COpenGLDriver::initDriver(CIrrDeviceWin32* device) @@ -456,41 +374,6 @@ bool COpenGLDriver::initDriver(CIrrDeviceWin32* device) return true; } -bool COpenGLDriver::initAuxContext() -{ - if (!AuxContexts) // opengl dead and never inited - return false; - - bool retval = false; - const std::lock_guard lock(glContextMutex); - SAuxContext* found = getThreadContext_helper(true,std::thread::id()); - if (found) - { - retval = wglMakeCurrent((HDC)ExposedData.OpenGLWin32.HDc,found->ctx); - if (retval) - found->threadId = std::this_thread::get_id(); - } - return retval; -} - -bool COpenGLDriver::deinitAuxContext() -{ - bool retval = false; - const std::lock_guard lock(glContextMutex); - SAuxContext* found = getThreadContext_helper(true); - if (found) - { - { - const core::unlock_guard lock(glContextMutex); - cleanUpContextBeforeDelete(); - } - retval = wglMakeCurrent(NULL,NULL); - if (retval) - found->threadId = std::thread::id(); - } - return retval; -} - #endif // _NBL_COMPILE_WITH_WINDOWS_DEVICE_ @@ -498,69 +381,6 @@ bool COpenGLDriver::deinitAuxContext() // LINUX CONSTRUCTOR // ----------------------------------------------------------------------- #ifdef _NBL_COMPILE_WITH_X11_DEVICE_ -//! Linux constructor and init code -COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, - io::IFileSystem* io, CIrrDeviceLinux* device, const asset::IGLSLCompiler* glslcomp) - : CNullDriver(device, io, Params), COpenGLExtensionHandler(), - runningInRenderDoc(false), ColorFormat(asset::EF_R8G8B8_UNORM), - X11Device(device), DeviceType(EIDT_X11), AuxContexts(0), GLSLCompiler(glslcomp) -{ - #ifdef _NBL_DEBUG - setDebugName("COpenGLDriver"); - #endif -} - - -bool COpenGLDriver::changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceLinux* device) -{ - if (videoData.OpenGLLinux.X11Window) - { - if (videoData.OpenGLLinux.X11Display && videoData.OpenGLLinux.X11Context) - { - if (!glXMakeCurrent((Display*)videoData.OpenGLLinux.X11Display, videoData.OpenGLLinux.X11Window, (GLXContext)videoData.OpenGLLinux.X11Context)) - { - os::Printer::log("Render Context switch failed."); - return false; - } - else - { - Drawable = videoData.OpenGLLinux.X11Window; - X11Display = (Display*)videoData.OpenGLLinux.X11Display; - } - } - else - { - // in case we only got a window ID, try with the existing values for display and context - if (!glXMakeCurrent((Display*)ExposedData.OpenGLLinux.X11Display, videoData.OpenGLLinux.X11Window, (GLXContext)ExposedData.OpenGLLinux.X11Context)) - { - os::Printer::log("Render Context switch failed."); - return false; - } - else - { - Drawable = videoData.OpenGLLinux.X11Window; - X11Display = (Display*)ExposedData.OpenGLLinux.X11Display; - } - } - } - // set back to main context - else if (X11Display != ExposedData.OpenGLLinux.X11Display) - { - if (!glXMakeCurrent((Display*)ExposedData.OpenGLLinux.X11Display, ExposedData.OpenGLLinux.X11Window, (GLXContext)ExposedData.OpenGLLinux.X11Context)) - { - os::Printer::log("Render Context switch failed."); - return false; - } - else - { - Drawable = ExposedData.OpenGLLinux.X11Window; - X11Display = (Display*)ExposedData.OpenGLLinux.X11Display; - } - } - return true; -} - - //! inits the open gl driver bool COpenGLDriver::initDriver(CIrrDeviceLinux* device, SAuxContext* auxCtxts) { @@ -584,120 +404,14 @@ bool COpenGLDriver::initDriver(CIrrDeviceLinux* device, SAuxContext* auxCtxts) extGlSwapInterval(Params.Vsync ? -1 : 0); return true; } - -bool COpenGLDriver::initAuxContext() -{ - if (!AuxContexts) // opengl dead and never inited - return false; - - bool retval = false; - const std::lock_guard lock(glContextMutex); - SAuxContext* found = getThreadContext_helper(true,std::thread::id()); - if (found) - { - retval = glXMakeCurrent((Display*)ExposedData.OpenGLLinux.X11Display, found->pbuff, found->ctx); - if (retval) - found->threadId = std::this_thread::get_id(); - } - return retval; -} - -bool COpenGLDriver::deinitAuxContext() -{ - if (!AuxContexts) // opengl dead and never inited - return false; - - bool retval = false; - const std::lock_guard lock(glContextMutex); - SAuxContext* found = getThreadContext_helper(true); - if (found) - { - { - const core::unlock_guard lock(glContextMutex); - cleanUpContextBeforeDelete(); - } - retval = glXMakeCurrent((Display*)ExposedData.OpenGLLinux.X11Display, None, NULL); - if (retval) - found->threadId = std::thread::id(); - } - return retval; -} - #endif // _NBL_COMPILE_WITH_X11_DEVICE_ //! destructor COpenGLDriver::~COpenGLDriver() { - if (!AuxContexts) //opengl dead and never initialized in the first place - return; - quitEventHandler.execute(); cleanUpContextBeforeDelete(); - - //! Spin wait for other contexts to deinit - //! @TODO: Change trylock to semaphore - while (true) - { - while (!glContextMutex.try_lock()) {} - - bool allDead = true; - for (size_t i=1; i<=Params.AuxGLContexts; i++) - { - if (AuxContexts[i].threadId==std::thread::id()) - continue; - - // found one alive - glContextMutex.unlock(); - allDead = false; - break; - } - - if (allDead) - break; - } - -#ifdef _NBL_COMPILE_WITH_WINDOWS_DEVICE_ - if (DeviceType == EIDT_WIN32) - { - for (size_t i=1; i<=Params.AuxGLContexts; i++) - wglDeleteContext(AuxContexts[i].ctx); - - if (ExposedData.OpenGLWin32.HRc) - { - if (!wglMakeCurrent(HDc, 0)) - os::Printer::log("Release of dc and rc failed.", ELL_WARNING); - - if (!wglDeleteContext((HGLRC)ExposedData.OpenGLWin32.HRc)) - os::Printer::log("Release of rendering context failed.", ELL_WARNING); - } - - if (HDc) - ReleaseDC(Window, HDc); - - //if (!ExternalWindow) - //{ - // DestroyWindow(temporary_wnd); - // UnregisterClass(ClassName, lhInstance); - //} - } -#ifdef _NBL_COMPILE_WITH_X11_DEVICE_ - else -#endif // _NBL_COMPILE_WITH_X11_DEVICE_ -#endif -#ifdef _NBL_COMPILE_WITH_X11_DEVICE_ - if (DeviceType == EIDT_X11) - { - for (size_t i=1; i<=Params.AuxGLContexts; i++) - { - assert(AuxContexts[i].threadId==std::thread::id()); - glXDestroyPbuffer((Display*)ExposedData.OpenGLLinux.X11Display,AuxContexts[i].pbuff); - glXDestroyContext((Display*)ExposedData.OpenGLLinux.X11Display,AuxContexts[i].ctx); - } - } -#endif // _NBL_COMPILE_WITH_X11_DEVICE_ - _NBL_DELETE_ARRAY(AuxContexts,Params.AuxGLContexts+1); - glContextMutex.unlock(); } @@ -734,35 +448,6 @@ uint16_t COpenGLDriver::retrieveDisplayRefreshRate() const #endif } -const COpenGLDriver::SAuxContext* COpenGLDriver::getThreadContext(const std::thread::id& tid) -{ - const std::lock_guard lock(glContextMutex); - for (size_t i=0; i<=Params.AuxGLContexts; i++) - { - if (AuxContexts[i].threadId==tid) - return AuxContexts+i; - } - return NULL; -} - -COpenGLDriver::SAuxContext* COpenGLDriver::getThreadContext_helper(const bool& alreadyLockedMutex, const std::thread::id& tid) -{ - if (!alreadyLockedMutex) - glContextMutex.lock(); - for (size_t i=0; i<=Params.AuxGLContexts; i++) - { - if (AuxContexts[i].threadId==tid) - { - if (!alreadyLockedMutex) - glContextMutex.unlock(); - return AuxContexts+i; - } - } - if (!alreadyLockedMutex) - glContextMutex.unlock(); - return NULL; -} - void COpenGLDriver::cleanUpContextBeforeDelete() { SAuxContext* found = getThreadContext_helper(false); @@ -835,33 +520,10 @@ bool COpenGLDriver::genericDriverInit(asset::IAssetManager* assMgr) VendorName = reinterpret_cast(vendor); } - + // TODO: disregard those maxConcurrentShaderInvocations = 4; maxALUShaderInvocations = 4; maxShaderComputeUnits = 1; -#ifdef _NBL_COMPILE_WITH_OPENCL_ - clPlatformIx = 0xdeadbeefu; - clDeviceIx = 0xdeadbeefu; - for (size_t i=0; ifreeUpVAOCache(false); - ctx->freeUpGraphicsPipelineCache(false); - - return false; -} - - -//! init call for rendering start -bool COpenGLDriver::beginScene(bool backBuffer, bool zBuffer, SColor color, - const SExposedVideoData& videoData, core::rect* sourceRect) -{ - CNullDriver::beginScene(backBuffer, zBuffer, color, videoData, sourceRect); - - if (zBuffer) - { - clearZBuffer(0.0); - } - - if (backBuffer) - { - core::vectorSIMDf colorf(color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha()); - colorf /= 255.f; - clearScreen(Params.Doublebuffer ? ESB_BACK_LEFT:ESB_FRONT_LEFT,colorf.pointer); - } - return true; -} - const core::smart_refctd_dynamic_array COpenGLDriver::getSupportedGLSLExtensions() const { @@ -1012,678 +613,31 @@ const core::smart_refctd_dynamic_array COpenGLDriver::getSupportedG return m_supportedGLSLExtsNames; } -bool COpenGLDriver::bindGraphicsPipeline(const video::IGPURenderpassIndependentPipeline* _gpipeline) -{ - SAuxContext* ctx = getThreadContext_helper(false); - if (!ctx) - return false; - - ctx->updateNextState_pipelineAndRaster(_gpipeline); - - return true; -} - -bool COpenGLDriver::bindComputePipeline(const video::IGPUComputePipeline* _cpipeline) -{ - SAuxContext* ctx = getThreadContext_helper(false); - if (!ctx) - return false; - - const COpenGLComputePipeline* glppln = static_cast(_cpipeline); - ctx->nextState.pipeline.compute.usedShader = glppln ? glppln->getShaderGLnameForCtx(0u,ctx->ID) : 0u; - ctx->nextState.pipeline.compute.pipeline = core::smart_refctd_ptr(glppln); - - return true; -} - -bool COpenGLDriver::bindDescriptorSets(E_PIPELINE_BIND_POINT _pipelineType, const IGPUPipelineLayout* _layout, - uint32_t _first, uint32_t _count, const IGPUDescriptorSet* const* _descSets, core::smart_refctd_dynamic_array* _dynamicOffsets) -{ - if (_first + _count > IGPUPipelineLayout::DESCRIPTOR_SET_COUNT) - return false; - - SAuxContext* ctx = getThreadContext_helper(false); - if (!ctx) - return false; - - const IGPUPipelineLayout* layouts[IGPUPipelineLayout::DESCRIPTOR_SET_COUNT]{}; - for (uint32_t i = 0u; i < IGPUPipelineLayout::DESCRIPTOR_SET_COUNT; ++i) - layouts[i] = ctx->nextState.descriptorsParams[_pipelineType].descSets[i].pplnLayout.get(); - bindDescriptorSets_generic(_layout, _first, _count, _descSets, layouts); - - for (uint32_t i = 0u; i < IGPUPipelineLayout::DESCRIPTOR_SET_COUNT; ++i) - if (!layouts[i]) - ctx->nextState.descriptorsParams[_pipelineType].descSets[i] = { nullptr, nullptr, nullptr }; - - for (uint32_t i = 0u; i < _count; i++) - { - ctx->nextState.descriptorsParams[_pipelineType].descSets[_first + i] = - { - core::smart_refctd_ptr(static_cast(_layout)), - core::smart_refctd_ptr(static_cast(_descSets[i])), - _dynamicOffsets ? _dynamicOffsets[i]:nullptr //intentionally copy, not move - }; - } - - return true; -} - -bool COpenGLDriver::dispatch(uint32_t _groupCountX, uint32_t _groupCountY, uint32_t _groupCountZ) -{ - SAuxContext* ctx = getThreadContext_helper(false); - if (!ctx) - return false; - - ctx->flushStateCompute(GSB_PIPELINE | GSB_DESCRIPTOR_SETS | GSB_PUSH_CONSTANTS); - - extGlDispatchCompute(_groupCountX, _groupCountY, _groupCountZ); - - return true; -} - -bool COpenGLDriver::dispatchIndirect(const IGPUBuffer* _indirectBuf, size_t _offset) -{ - SAuxContext* ctx = getThreadContext_helper(false); - if (!ctx) - return false; - - ctx->nextState.dispatchIndirect.buffer = core::smart_refctd_ptr(static_cast(_indirectBuf)); - - ctx->flushStateCompute(GSB_PIPELINE | GSB_DISPATCH_INDIRECT | GSB_DESCRIPTOR_SETS | GSB_PUSH_CONSTANTS); - - extGlDispatchComputeIndirect(static_cast(_offset)); - - return true; -} - -bool COpenGLDriver::pushConstants(const IGPUPipelineLayout* _layout, uint32_t _stages, uint32_t _offset, uint32_t _size, const void* _values) -{ - if (!CNullDriver::pushConstants(_layout, _stages, _offset, _size, _values)) - return false; - - SAuxContext* ctx = getThreadContext_helper(false); - if (!ctx) - return false; - - asset::SPushConstantRange updtRng; - updtRng.offset = _offset; - updtRng.size = _size; - - if (_stages & asset::ISpecializedShader::ESS_ALL_GRAPHICS) - ctx->pushConstants(static_cast(_layout), _stages, _offset, _size, _values); - if (_stages & asset::ISpecializedShader::ESS_COMPUTE) - ctx->pushConstants(static_cast(_layout), _stages, _offset, _size, _values); - - return true; -} - -core::smart_refctd_ptr COpenGLDriver::createGPUShader(core::smart_refctd_ptr&& _cpushader) -{ - auto source = _cpushader->getSPVorGLSL(); - auto clone = core::smart_refctd_ptr_static_cast(source->clone(1u)); - if (_cpushader->containsGLSL()) - return core::make_smart_refctd_ptr(std::move(clone),IGPUShader::buffer_contains_glsl); - else - return core::make_smart_refctd_ptr(std::move(clone)); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUSpecializedShader(const IGPUShader* _unspecialized, const asset::ISpecializedShader::SInfo& _specInfo, const asset::ISPIRVOptimizer* _spvopt) -{ - const COpenGLShader* glUnspec = static_cast(_unspecialized); - - const std::string& EP = _specInfo.entryPoint; - const asset::ISpecializedShader::E_SHADER_STAGE stage = _specInfo.shaderStage; - - core::smart_refctd_ptr spirv; - if (glUnspec->containsGLSL()) - { - auto begin = reinterpret_cast(glUnspec->getSPVorGLSL()->getPointer()); - auto end = begin+glUnspec->getSPVorGLSL()->getSize(); - std::string glsl(begin,end); - COpenGLShader::insertGLtoVKextensionsMapping(glsl, getSupportedGLSLExtensions().get()); - auto glslShader_woIncludes = GLSLCompiler->resolveIncludeDirectives(glsl.c_str(), stage, _specInfo.m_filePathHint.c_str()); - auto src = reinterpret_cast(glslShader_woIncludes->getSPVorGLSL()->getPointer()); - { - auto fl = fopen("shader.glsl", "w"); - fwrite(src, 1, glslShader_woIncludes->getSPVorGLSL()->getSize(), fl); - fclose(fl); - } - spirv = GLSLCompiler->compileSPIRVFromGLSL(src,stage,EP.c_str(),_specInfo.m_filePathHint.c_str()); - - if (!spirv) - return nullptr; - } - else - { - spirv = glUnspec->m_code; - } - - if (_spvopt) - spirv = _spvopt->optimize(spirv.get()); - - if (!spirv) - return nullptr; - - core::smart_refctd_ptr spvCPUShader = core::make_smart_refctd_ptr(std::move(spirv)); - - asset::CShaderIntrospector::SIntrospectionParams introspectionParams{ _specInfo.shaderStage, _specInfo.entryPoint, getSupportedGLSLExtensions(), _specInfo.m_filePathHint}; - asset::CShaderIntrospector introspector(GLSLCompiler.get()); // TODO: shouldn't the introspection be cached for all calls to `createGPUSpecializedShader` (or somehow embedded into the OpenGL pipeline cache?) - const asset::CIntrospectionData* introspection = introspector.introspect(spvCPUShader.get(), introspectionParams); - if (!introspection) - { - _NBL_DEBUG_BREAK_IF(true); - os::Printer::log("Unable to introspect the SPIR-V shader to extract information about bindings and push constants. Creation failed.", ELL_ERROR); - return nullptr; - } - - core::vector uniformList; - if (!COpenGLSpecializedShader::getUniformsFromPushConstants(&uniformList,introspection)) - { - _NBL_DEBUG_BREAK_IF(true); - os::Printer::log("Attempted to create OpenGL GPU specialized shader from SPIR-V without debug info - unable to set push constants. Creation failed.", ELL_ERROR); - return nullptr; - } - - auto ctx = getThreadContext_helper(false); - return core::make_smart_refctd_ptr(this->ShaderLanguageVersion, spvCPUShader->getSPVorGLSL(), _specInfo, std::move(uniformList)); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUBufferView(IGPUBuffer* _underlying, asset::E_FORMAT _fmt, size_t _offset, size_t _size) -{ - if (!_underlying) - return nullptr; - const size_t effectiveSize = (_size != IGPUBufferView::whole_buffer) ? _size:(_underlying->getSize() - _offset); - if ((_offset + effectiveSize) > _underlying->getSize()) - return nullptr; - if (!core::is_aligned_to(_offset, reqTBOAlignment)) //offset must be aligned to GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT - return nullptr; - if (!isAllowedBufferViewFormat(_fmt)) - return nullptr; - if (effectiveSize > (maxTBOSizeInTexels * asset::getTexelOrBlockBytesize(_fmt))) - return nullptr; - - COpenGLBuffer* glbuf = static_cast(_underlying); - return core::make_smart_refctd_ptr(core::smart_refctd_ptr(glbuf), _fmt, _offset, _size); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUDescriptorSetLayout(const IGPUDescriptorSetLayout::SBinding* _begin, const IGPUDescriptorSetLayout::SBinding* _end) -{ - return core::make_smart_refctd_ptr(_begin, _end);//there's no COpenGLDescriptorSetLayout (no need for such) -} - -core::smart_refctd_ptr COpenGLDriver::createGPUSampler(const IGPUSampler::SParams& _params) -{ - return core::make_smart_refctd_ptr(_params); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUImageOnDedMem(IGPUImage::SCreationParams&& _params, const IDriverMemoryBacked::SDriverMemoryRequirements& initialMreqs) -{ - if (!asset::IImage::validateCreationParameters(_params)) - return nullptr; - - return core::make_smart_refctd_ptr(std::move(_params)); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUImageView(IGPUImageView::SCreationParams&& _params) -{ - if (!IGPUImageView::validateCreationParameters(_params)) - return nullptr; - - return core::make_smart_refctd_ptr(std::move(_params)); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUPipelineLayout(const asset::SPushConstantRange* const _pcRangesBegin, const asset::SPushConstantRange* const _pcRangesEnd, core::smart_refctd_ptr&& _layout0, core::smart_refctd_ptr&& _layout1, core::smart_refctd_ptr&& _layout2, core::smart_refctd_ptr&& _layout3) -{ - return core::make_smart_refctd_ptr( - _pcRangesBegin, _pcRangesEnd, - std::move(_layout0), std::move(_layout1), - std::move(_layout2), std::move(_layout3) - ); -} - -core::smart_refctd_ptr COpenGLDriver::createGPURenderpassIndependentPipeline(IGPUPipelineCache* _pipelineCache, core::smart_refctd_ptr&& _layout, IGPUSpecializedShader* const* _shadersBegin, IGPUSpecializedShader* const* _shadersEnd, const asset::SVertexInputParams& _vertexInputParams, const asset::SBlendParams& _blendParams, const asset::SPrimitiveAssemblyParams& _primAsmParams, const asset::SRasterizationParams& _rasterParams) -{ - //_parent parameter is ignored - - using GLPpln = COpenGLRenderpassIndependentPipeline; - - SAuxContext* ctx = getThreadContext_helper(false); - if (!ctx) - return nullptr; - - auto shaders = core::SRange(_shadersBegin, _shadersEnd); - auto vsIsPresent = [&shaders] { - return std::find_if(shaders.begin(), shaders.end(), [](IGPUSpecializedShader* shdr) {return shdr->getStage()==asset::ISpecializedShader::ESS_VERTEX;}) != shaders.end(); - }; - - if (!_layout || !vsIsPresent()) - return nullptr; - - GLuint GLnames[COpenGLRenderpassIndependentPipeline::SHADER_STAGE_COUNT]{}; - COpenGLSpecializedShader::SProgramBinary binaries[COpenGLRenderpassIndependentPipeline::SHADER_STAGE_COUNT]; - - COpenGLPipelineCache* cache = static_cast(_pipelineCache); - COpenGLPipelineLayout* layout = static_cast(_layout.get()); - for (auto shdr = _shadersBegin; shdr!=_shadersEnd; ++shdr) - { - COpenGLSpecializedShader* glshdr = static_cast(*shdr); - - auto stage = glshdr->getStage(); - uint32_t ix = core::findLSB(stage); - assert(ixgetSpirvHash(), glshdr->getSpecializationInfo(), core::smart_refctd_ptr(layout) }; - auto bin = cache ? cache->find(key) : COpenGLSpecializedShader::SProgramBinary{0,nullptr}; - if (bin.binary) - { - const GLuint GLname = extGlCreateProgram(); - extGlProgramBinary(GLname, bin.format, bin.binary->data(), bin.binary->size()); - GLnames[ix] = GLname; - binaries[ix] = bin; - - continue; - } - std::tie(GLnames[ix], bin) = glshdr->compile(layout, cache ? cache->findParsedSpirv(key.hash):nullptr); - binaries[ix] = bin; - - if (cache) - { - cache->insertParsedSpirv(key.hash, glshdr->getSpirv()); - - COpenGLPipelineCache::SCacheVal val{std::move(bin)}; - cache->insert(std::move(key), std::move(val)); - } - } - - return core::make_smart_refctd_ptr( - std::move(_layout), - _shadersBegin, _shadersEnd, - _vertexInputParams, _blendParams, _primAsmParams, _rasterParams, - Params.AuxGLContexts+1, ctx->ID, GLnames, binaries - ); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUComputePipeline(IGPUPipelineCache* _pipelineCache, core::smart_refctd_ptr&& _layout, core::smart_refctd_ptr&& _shader) -{ - if (!_layout || !_shader) - return nullptr; - if (_shader->getStage() != asset::ISpecializedShader::ESS_COMPUTE) - return nullptr; - - SAuxContext* ctx = getThreadContext_helper(false); - if (!ctx) - return nullptr; - - GLuint GLname = 0u; - COpenGLSpecializedShader::SProgramBinary binary; - COpenGLPipelineCache* cache = static_cast(_pipelineCache); - COpenGLPipelineLayout* layout = static_cast(_layout.get()); - COpenGLSpecializedShader* glshdr = static_cast(_shader.get()); - - COpenGLPipelineCache::SCacheKey key{ glshdr->getSpirvHash(), glshdr->getSpecializationInfo(), core::smart_refctd_ptr(layout) }; - auto bin = cache ? cache->find(key) : COpenGLSpecializedShader::SProgramBinary{0,nullptr}; - if (bin.binary) - { - const GLuint GLshader = extGlCreateProgram(); - extGlProgramBinary(GLname, bin.format, bin.binary->data(), bin.binary->size()); - GLname = GLshader; - binary = bin; - } - else - { - std::tie(GLname, bin) = glshdr->compile(layout, cache ? cache->findParsedSpirv(key.hash):nullptr); - binary = bin; - - if (cache) - { - cache->insertParsedSpirv(key.hash, glshdr->getSpirv()); - - COpenGLPipelineCache::SCacheVal val{std::move(bin)}; - cache->insert(std::move(key), std::move(val)); - } - } - - return core::make_smart_refctd_ptr(std::move(_layout), std::move(_shader), Params.AuxGLContexts+1, ctx->ID, GLname, binary); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUPipelineCache() -{ - return core::make_smart_refctd_ptr(); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUDescriptorSet(core::smart_refctd_ptr&& _layout) -{ - if (!_layout) - return nullptr; - - return core::make_smart_refctd_ptr(std::move(_layout)); -} - -core::smart_refctd_ptr COpenGLDriver::createGPUBufferOnDedMem(const IDriverMemoryBacked::SDriverMemoryRequirements& initialMreqs, const bool canModifySubData) -{ - auto extraMreqs = initialMreqs; - - if (extraMreqs.memoryHeapLocation==IDriverMemoryAllocation::ESMT_DONT_KNOW) - extraMreqs.memoryHeapLocation = (initialMreqs.mappingCapability&IDriverMemoryAllocation::EMCF_CAN_MAP_FOR_READ)!=0u ? IDriverMemoryAllocation::ESMT_NOT_DEVICE_LOCAL:IDriverMemoryAllocation::ESMT_DEVICE_LOCAL; - - if ((extraMreqs.mappingCapability&IDriverMemoryAllocation::EMCF_CAN_MAP_FOR_READ) && !runningInRenderDoc) - extraMreqs.mappingCapability |= IDriverMemoryAllocation::EMCF_COHERENT; - - return core::make_smart_refctd_ptr(extraMreqs, canModifySubData); -} - - -void COpenGLDriver::updateDescriptorSets( uint32_t descriptorWriteCount, const IGPUDescriptorSet::SWriteDescriptorSet* pDescriptorWrites, - uint32_t descriptorCopyCount, const IGPUDescriptorSet::SCopyDescriptorSet* pDescriptorCopies) -{ - for (uint32_t i=0u; i(pDescriptorWrites[i].dstSet)->writeDescriptorSet(pDescriptorWrites[i]); - for (uint32_t i=0u; i< descriptorCopyCount; i++) - static_cast(pDescriptorCopies[i].dstSet)->copyDescriptorSet(pDescriptorCopies[i]); -} - - -void COpenGLDriver::flushMappedMemoryRanges(uint32_t memoryRangeCount, const video::IDriverMemoryAllocation::MappedMemoryRange* pMemoryRanges) -{ - for (uint32_t i=0; imemory->haveToMakeVisible()) - os::Printer::log("Why are you flushing mapped memory that does not need to be flushed!?",ELL_WARNING); - #endif // _NBL_DEBUG - extGlFlushMappedNamedBufferRange(static_cast(range->memory)->getOpenGLName(),range->offset,range->length); - } -} - -void COpenGLDriver::invalidateMappedMemoryRanges(uint32_t memoryRangeCount, const video::IDriverMemoryAllocation::MappedMemoryRange* pMemoryRanges) -{ - for (uint32_t i=0; imemory->haveToMakeVisible()) - os::Printer::log("Why are you invalidating mapped memory that does not need to be invalidated!?",ELL_WARNING); - #endif // _NBL_DEBUG - extGlMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT); - } -} - - -void COpenGLDriver::fillBuffer(IGPUBuffer* buffer, size_t offset, size_t length, uint32_t value) -{ - COpenGLBuffer* glbuffer = static_cast(buffer); - extGlClearNamedBufferSubData(glbuffer->getOpenGLName(),GL_R32UI,offset,length,GL_RED,GL_UNSIGNED_INT,&value); -} - -void COpenGLDriver::copyBuffer(IGPUBuffer* readBuffer, IGPUBuffer* writeBuffer, size_t readOffset, size_t writeOffset, size_t length) -{ - COpenGLBuffer* readbuffer = static_cast(readBuffer); - COpenGLBuffer* writebuffer = static_cast(writeBuffer); - extGlCopyNamedBufferSubData(readbuffer->getOpenGLName(),writebuffer->getOpenGLName(),readOffset,writeOffset,length); -} - -void COpenGLDriver::copyImage(IGPUImage* srcImage, IGPUImage* dstImage, uint32_t regionCount, const IGPUImage::SImageCopy* pRegions) -{ - if (!dstImage->validateCopies(pRegions,pRegions+regionCount,srcImage)) - return; - - auto src = static_cast(srcImage); - auto dst = static_cast(dstImage); - IGPUImage::E_TYPE srcType = srcImage->getCreationParameters().type; - IGPUImage::E_TYPE dstType = dstImage->getCreationParameters().type; - GLenum type2Target[3u] = {GL_TEXTURE_1D_ARRAY,GL_TEXTURE_2D_ARRAY,GL_TEXTURE_3D}; - for (auto it=pRegions; it!=pRegions+regionCount; it++) - { - extGlCopyImageSubData( src->getOpenGLName(),type2Target[srcType],it->srcSubresource.mipLevel, - it->srcOffset.x,srcType==IGPUImage::ET_1D ? it->srcSubresource.baseArrayLayer:it->srcOffset.y,srcType==IGPUImage::ET_2D ? it->srcSubresource.baseArrayLayer:it->srcOffset.z, - dst->getOpenGLName(),type2Target[dstType],it->dstSubresource.mipLevel, - it->dstOffset.x,dstType==IGPUImage::ET_1D ? it->dstSubresource.baseArrayLayer:it->dstOffset.y,dstType==IGPUImage::ET_2D ? it->dstSubresource.baseArrayLayer:it->dstOffset.z, - it->extent.width,dstType==IGPUImage::ET_1D ? it->dstSubresource.layerCount:it->extent.height,dstType==IGPUImage::ET_2D ? it->dstSubresource.layerCount:it->extent.depth); - } -} - -void COpenGLDriver::copyBufferToImage(IGPUBuffer* srcBuffer, IGPUImage* dstImage, uint32_t regionCount, const IGPUImage::SBufferCopy* pRegions) -{ - auto ctx = getThreadContext_helper(false); - if (!ctx) - return; - if (!dstImage->validateCopies(pRegions,pRegions+regionCount,srcBuffer)) - return; - - const auto params = dstImage->getCreationParameters(); - const auto type = params.type; - const auto format = params.format; - const bool compressed = asset::isBlockCompressionFormat(format); - auto dstImageGL = static_cast(dstImage); - GLuint dst = dstImageGL->getOpenGLName(); - GLenum glfmt,gltype; - getOpenGLFormatAndParametersFromColorFormat(format,glfmt,gltype); - - const auto bpp = asset::getBytesPerPixel(format); - const auto blockDims = asset::getBlockDimensions(format); - - ctx->nextState.pixelUnpack.buffer = core::smart_refctd_ptr(static_cast(srcBuffer)); - for (auto it=pRegions; it!=pRegions+regionCount; it++) - { - // TODO: check it->bufferOffset is aligned to data type of E_FORMAT - //assert(?); - - uint32_t pitch = ((it->bufferRowLength ? it->bufferRowLength:it->imageExtent.width)*bpp).getIntegerApprox(); - int32_t alignment = 0x1<(core::findLSB(it->bufferOffset),core::findLSB(pitch)),3u); - ctx->nextState.pixelUnpack.alignment = alignment; - ctx->nextState.pixelUnpack.rowLength = it->bufferRowLength; - ctx->nextState.pixelUnpack.imgHeight = it->bufferImageHeight; - - if (compressed) - { - ctx->nextState.pixelUnpack.BCwidth = blockDims[0]; - ctx->nextState.pixelUnpack.BCheight = blockDims[1]; - ctx->nextState.pixelUnpack.BCdepth = blockDims[2]; - ctx->flushStateGraphics(GSB_PIXEL_PACK_UNPACK); - - uint32_t imageSize = pitch; - switch (type) - { - case IGPUImage::ET_1D: - imageSize *= it->imageSubresource.layerCount; - extGlCompressedTextureSubImage2D( dst,GL_TEXTURE_1D_ARRAY,it->imageSubresource.mipLevel, - it->imageOffset.x,it->imageSubresource.baseArrayLayer, - it->imageExtent.width,it->imageSubresource.layerCount, - dstImageGL->getOpenGLSizedFormat(),imageSize,reinterpret_cast(it->bufferOffset)); - break; - case IGPUImage::ET_2D: - imageSize *= (it->bufferImageHeight ? it->bufferImageHeight:it->imageExtent.height); - imageSize *= it->imageSubresource.layerCount; - extGlCompressedTextureSubImage3D( dst,GL_TEXTURE_2D_ARRAY,it->imageSubresource.mipLevel, - it->imageOffset.x,it->imageOffset.y,it->imageSubresource.baseArrayLayer, - it->imageExtent.width,it->imageExtent.height,it->imageSubresource.layerCount, - dstImageGL->getOpenGLSizedFormat(),imageSize,reinterpret_cast(it->bufferOffset)); - break; - case IGPUImage::ET_3D: - imageSize *= (it->bufferImageHeight ? it->bufferImageHeight:it->imageExtent.height); - imageSize *= it->imageExtent.depth; - extGlCompressedTextureSubImage3D( dst,GL_TEXTURE_3D,it->imageSubresource.mipLevel, - it->imageOffset.x,it->imageOffset.y,it->imageOffset.z, - it->imageExtent.width,it->imageExtent.height,it->imageExtent.depth, - dstImageGL->getOpenGLSizedFormat(),imageSize,reinterpret_cast(it->bufferOffset)); - break; - } - } - else - { - ctx->flushStateGraphics(GSB_PIXEL_PACK_UNPACK); - switch (type) - { - case IGPUImage::ET_1D: - extGlTextureSubImage2D( dst,GL_TEXTURE_1D_ARRAY,it->imageSubresource.mipLevel, - it->imageOffset.x,it->imageSubresource.baseArrayLayer, - it->imageExtent.width,it->imageSubresource.layerCount, - glfmt,gltype,reinterpret_cast(it->bufferOffset)); - break; - case IGPUImage::ET_2D: - extGlTextureSubImage3D(dst,GL_TEXTURE_2D_ARRAY,it->imageSubresource.mipLevel, - it->imageOffset.x,it->imageOffset.y,it->imageSubresource.baseArrayLayer, - it->imageExtent.width,it->imageExtent.height,it->imageSubresource.layerCount, - glfmt,gltype,reinterpret_cast(it->bufferOffset)); - break; - case IGPUImage::ET_3D: - extGlTextureSubImage3D(dst,GL_TEXTURE_3D,it->imageSubresource.mipLevel, - it->imageOffset.x,it->imageOffset.y,it->imageOffset.z, - it->imageExtent.width,it->imageExtent.height,it->imageExtent.depth, - glfmt,gltype,reinterpret_cast(it->bufferOffset)); - break; - } - } - } -} - -void COpenGLDriver::copyImageToBuffer(IGPUImage* srcImage, IGPUBuffer* dstBuffer, uint32_t regionCount, const IGPUImage::SBufferCopy* pRegions) -{ - auto ctx = getThreadContext_helper(false); - if (!ctx) - return; - if (!srcImage->validateCopies(pRegions,pRegions+regionCount,dstBuffer)) - return; - - const auto params = srcImage->getCreationParameters(); - const auto type = params.type; - const auto format = params.format; - const bool compressed = asset::isBlockCompressionFormat(format); - GLuint src = static_cast(srcImage)->getOpenGLName(); - GLenum glfmt,gltype; - getOpenGLFormatAndParametersFromColorFormat(format,glfmt,gltype); - - const auto bpp = asset::getBytesPerPixel(format); - const auto blockDims = asset::getBlockDimensions(format); - - ctx->nextState.pixelPack.buffer = core::smart_refctd_ptr(static_cast(dstBuffer)); - for (auto it=pRegions; it!=pRegions+regionCount; it++) - { - // TODO: check it->bufferOffset is aligned to data type of E_FORMAT - //assert(?); - - uint32_t pitch = ((it->bufferRowLength ? it->bufferRowLength:it->imageExtent.width)*bpp).getIntegerApprox(); - int32_t alignment = 0x1<bufferOffset),core::findLSB(pitch)),3u); - ctx->nextState.pixelPack.alignment = alignment; - ctx->nextState.pixelPack.rowLength = it->bufferRowLength; - ctx->nextState.pixelPack.imgHeight = it->bufferImageHeight; - - auto yStart = type==IGPUImage::ET_1D ? it->imageSubresource.baseArrayLayer:it->imageOffset.y; - auto yRange = type==IGPUImage::ET_1D ? it->imageSubresource.layerCount:it->imageExtent.height; - auto zStart = type==IGPUImage::ET_2D ? it->imageSubresource.baseArrayLayer:it->imageOffset.z; - auto zRange = type==IGPUImage::ET_2D ? it->imageSubresource.layerCount:it->imageExtent.depth; - if (compressed) - { - ctx->nextState.pixelPack.BCwidth = blockDims[0]; - ctx->nextState.pixelPack.BCheight = blockDims[1]; - ctx->nextState.pixelPack.BCdepth = blockDims[2]; - ctx->flushStateGraphics(GSB_PIXEL_PACK_UNPACK); - - extGlGetCompressedTextureSubImage( src,it->imageSubresource.mipLevel,it->imageOffset.x,yStart,zStart,it->imageExtent.width,yRange,zRange, - dstBuffer->getSize()-it->bufferOffset,reinterpret_cast(it->bufferOffset)); - } - else - { - ctx->flushStateGraphics(GSB_PIXEL_PACK_UNPACK); - - extGlGetTextureSubImage(src,it->imageSubresource.mipLevel,it->imageOffset.x,yStart,zStart,it->imageExtent.width,yRange,zRange, - glfmt,gltype,dstBuffer->getSize()-it->bufferOffset,reinterpret_cast(it->bufferOffset)); - } - } -} - - -IQueryObject* COpenGLDriver::createPrimitivesGeneratedQuery() -{ - return new COpenGLQuery(GL_PRIMITIVES_GENERATED); -} - -IQueryObject* COpenGLDriver::createElapsedTimeQuery() -{ - return new COpenGLQuery(GL_TIME_ELAPSED); -} - -IGPUTimestampQuery* COpenGLDriver::createTimestampQuery() -{ - return new COpenGLTimestampQuery(); -} - -void COpenGLDriver::beginQuery(IQueryObject* query) +void COpenGLDriver::fillBuffer(IGPUBuffer* buffer, size_t offset, size_t length, uint32_t value) { - if (!query) - return; //error - - COpenGLQuery* queryGL = static_cast(query); - if (queryGL->getGLHandle()==0||queryGL->isActive()) - return; - - if (currentQuery[query->getQueryObjectType()]) - return; //error - - query->grab(); - currentQuery[query->getQueryObjectType()] = query; - - - extGlBeginQuery(queryGL->getType(),queryGL->getGLHandle()); - queryGL->flagBegun(); + COpenGLBuffer* glbuffer = static_cast(buffer); + extGlClearNamedBufferSubData(glbuffer->getOpenGLName(),GL_R32UI,offset,length,GL_RED,GL_UNSIGNED_INT,&value); } -void COpenGLDriver::endQuery(IQueryObject* query) -{ - if (!query) - return; //error - if (currentQuery[query->getQueryObjectType()]!=query) - return; //error - - COpenGLQuery* queryGL = static_cast(query); - if (queryGL->getGLHandle()==0||!queryGL->isActive()) - return; - if (currentQuery[query->getQueryObjectType()]) - currentQuery[query->getQueryObjectType()]->drop(); - currentQuery[query->getQueryObjectType()] = nullptr; - - extGlEndQuery(queryGL->getType()); - queryGL->flagEnded(); -} - -// small helper function to create vertex buffer object adress offsets -static inline uint8_t* buffer_offset(const long offset) +void COpenGLDriver::copyImage(IGPUImage* srcImage, IGPUImage* dstImage, uint32_t regionCount, const IGPUImage::SImageCopy* pRegions) { - return ((uint8_t*)0 + offset); -} + if (!dstImage->validateCopies(pRegions,pRegions+regionCount,srcImage)) + return; -static GLenum getGLprimitiveType(asset::E_PRIMITIVE_TOPOLOGY pt) -{ - using namespace asset; - switch (pt) - { - case EPT_POINT_LIST: - return GL_POINTS; - case EPT_LINE_LIST: - return GL_LINES; - case EPT_LINE_STRIP: - return GL_LINE_STRIP; - case EPT_TRIANGLE_LIST: - return GL_TRIANGLES; - case EPT_TRIANGLE_STRIP: - return GL_TRIANGLE_STRIP; - case EPT_TRIANGLE_FAN: - return GL_TRIANGLE_FAN; - case EPT_LINE_LIST_WITH_ADJACENCY: - return GL_LINES_ADJACENCY; - case EPT_LINE_STRIP_WITH_ADJACENCY: - return GL_LINE_STRIP_ADJACENCY; - case EPT_TRIANGLE_LIST_WITH_ADJACENCY: - return GL_TRIANGLES_ADJACENCY; - case EPT_TRIANGLE_STRIP_WITH_ADJACENCY: - return GL_TRIANGLE_STRIP_ADJACENCY; - case EPT_PATCH_LIST: - return GL_PATCHES; - default: - return GL_INVALID_ENUM; - } + auto src = static_cast(srcImage); + auto dst = static_cast(dstImage); + IGPUImage::E_TYPE srcType = srcImage->getCreationParameters().type; + IGPUImage::E_TYPE dstType = dstImage->getCreationParameters().type; + GLenum type2Target[3u] = {GL_TEXTURE_1D_ARRAY,GL_TEXTURE_2D_ARRAY,GL_TEXTURE_3D}; + for (auto it=pRegions; it!=pRegions+regionCount; it++) + { + extGlCopyImageSubData( src->getOpenGLName(),type2Target[srcType],it->srcSubresource.mipLevel, + it->srcOffset.x,srcType==IGPUImage::ET_1D ? it->srcSubresource.baseArrayLayer:it->srcOffset.y,srcType==IGPUImage::ET_2D ? it->srcSubresource.baseArrayLayer:it->srcOffset.z, + dst->getOpenGLName(),type2Target[dstType],it->dstSubresource.mipLevel, + it->dstOffset.x,dstType==IGPUImage::ET_1D ? it->dstSubresource.baseArrayLayer:it->dstOffset.y,dstType==IGPUImage::ET_2D ? it->dstSubresource.baseArrayLayer:it->dstOffset.z, + it->extent.width,dstType==IGPUImage::ET_1D ? it->dstSubresource.layerCount:it->extent.height,dstType==IGPUImage::ET_2D ? it->dstSubresource.layerCount:it->extent.depth); + } } @@ -1744,49 +698,6 @@ void COpenGLDriver::drawMeshBuffer(const IGPUMeshBuffer* mb) } -//! Indirect Draw -void COpenGLDriver::drawArraysIndirect(const asset::SBufferBinding _vtxBindings[IGPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT], - asset::E_PRIMITIVE_TOPOLOGY mode, - const IGPUBuffer* indirectDrawBuff, - size_t offset, size_t maxCount, size_t stride, - const IGPUBuffer* countBuffer, size_t countOffset) -{ - if (!indirectDrawBuff) - return; - - SAuxContext* found = getThreadContext_helper(false); - if (!found) - return; - if (!found->nextState.pipeline.graphics.pipeline) - return; - - if (countBuffer && !FeatureAvailable[NBL_ARB_indirect_parameters] && (Version < 460u)) - { - os::Printer::log("OpenGL driver: glMultiDrawArraysIndirectCount() not supported!"); - return; - } - if (!core::is_aligned_to(countOffset, 4ull)) - { - os::Printer::log("COpenGLDriver::drawArraysIndirect: countOffset must be aligned to 4!"); - return; - } - - found->updateNextState_vertexInput(_vtxBindings, found->nextState.vertexInputParams.vao.idxBinding.get(), indirectDrawBuff, countBuffer); - - found->flushStateGraphics(GSB_ALL); - - GLenum primType = getGLprimitiveType(found->currentState.pipeline.graphics.pipeline->getPrimitiveAssemblyParams().primitiveType); - if (primType == GL_POINTS) - extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 1.0f); - - //actual drawing - if (countBuffer) - extGlMultiDrawArraysIndirectCount(primType, (void*)offset, countOffset, maxCount, stride); - else - extGlMultiDrawArraysIndirect(primType, (void*)offset, maxCount, stride); -} - - bool COpenGLDriver::queryFeature(const E_DRIVER_FEATURE &feature) const { switch (feature) @@ -1830,48 +741,6 @@ bool COpenGLDriver::queryFeature(const E_DRIVER_FEATURE &feature) const return false; } -void COpenGLDriver::drawIndexedIndirect(const asset::SBufferBinding _vtxBindings[IGPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT], - asset::E_PRIMITIVE_TOPOLOGY mode, - asset::E_INDEX_TYPE indexType, const IGPUBuffer* indexBuff, - const IGPUBuffer* indirectDrawBuff, - size_t offset, size_t maxCount, size_t stride, - const IGPUBuffer* countBuffer, size_t countOffset) -{ - if (!indirectDrawBuff) - return; - - SAuxContext* found = getThreadContext_helper(false); - if (!found) - return; - if (!found->nextState.pipeline.graphics.pipeline) - return; - - if (countBuffer && !FeatureAvailable[NBL_ARB_indirect_parameters] && (Version < 460u)) - { - os::Printer::log("OpenGL driver: glMultiDrawElementsIndirectCount() not supported!"); - return; - } - if (!core::is_aligned_to(countOffset, 4ull)) - { - os::Printer::log("COpenGLDriver::drawIndexedIndirect: countOffset must be aligned to 4!"); - return; - } - - found->updateNextState_vertexInput(_vtxBindings, indexBuff, indirectDrawBuff, countBuffer); - - found->flushStateGraphics(GSB_ALL); - - GLenum indexSize = (indexType!=asset::EIT_16BIT) ? GL_UNSIGNED_INT:GL_UNSIGNED_SHORT; - GLenum primType = getGLprimitiveType(found->currentState.pipeline.graphics.pipeline->getPrimitiveAssemblyParams().primitiveType); - if (primType == GL_POINTS) - extGlPointParameterf(GL_POINT_FADE_THRESHOLD_SIZE, 1.0f); - - //actual drawing - if (countBuffer) - extGlMultiDrawElementsIndirectCount(primType, indexSize, (void*)offset, countOffset, maxCount, stride); - else - extGlMultiDrawElementsIndirect(primType,indexSize,(void*)offset,maxCount,stride); -} void COpenGLDriver::SAuxContext::flushState_descriptors(E_PIPELINE_BIND_POINT _pbp, const COpenGLPipelineLayout* _currentLayout) { @@ -2451,48 +1320,6 @@ void COpenGLDriver::SAuxContext::flushStateCompute(uint32_t stateBits) } } -static GLenum getGLpolygonMode(asset::E_POLYGON_MODE pm) -{ - const static GLenum glpm[3]{ GL_FILL, GL_LINE, GL_POINT }; - return glpm[pm]; -} -static GLenum getGLcullFace(asset::E_FACE_CULL_MODE cf) -{ - const static GLenum glcf[4]{ 0, GL_FRONT, GL_BACK, GL_FRONT_AND_BACK }; - return glcf[cf]; -} -static GLenum getGLstencilOp(asset::E_STENCIL_OP so) -{ - static const GLenum glso[]{ GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP }; - return glso[so]; -} -static GLenum getGLcmpFunc(asset::E_COMPARE_OP sf) -{ - static const GLenum glsf[]{ GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER, GL_NOTEQUAL, GL_GEQUAL, GL_ALWAYS }; - return glsf[sf]; -} -static GLenum getGLlogicOp(asset::E_LOGIC_OP lo) -{ - static const GLenum gllo[]{ GL_CLEAR, GL_AND, GL_AND_REVERSE, GL_COPY, GL_AND_INVERTED, GL_NOOP, GL_XOR, GL_OR, GL_NOR, GL_EQUIV, GL_INVERT, GL_OR_REVERSE, - GL_COPY_INVERTED, GL_OR_INVERTED, GL_NAND, GL_SET - }; - return gllo[lo]; -} -static GLenum getGLblendFunc(asset::E_BLEND_FACTOR bf) -{ - static const GLenum glbf[]{ GL_ZERO , GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, - GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, - GL_SRC_ALPHA_SATURATE, GL_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR, GL_SRC1_ALPHA, GL_ONE_MINUS_SRC1_ALPHA - }; - return glbf[bf]; -} -static GLenum getGLblendEq(asset::E_BLEND_OP bo) -{ - GLenum glbo[]{ GL_FUNC_ADD, GL_FUNC_SUBTRACT, GL_FUNC_REVERSE_SUBTRACT, GL_MIN, GL_MAX }; - if (bo >= std::extent::value) - return GL_INVALID_ENUM; - return glbo[bo]; -} GLuint COpenGLDriver::SAuxContext::createGraphicsPipeline(const SOpenGLState::SGraphicsPipelineHash& _hash) { @@ -2638,155 +1465,6 @@ void COpenGLDriver::SAuxContext::updateNextState_vertexInput(const asset::SBuffe nextState.vertexInputParams.vao.first = nextState.pipeline.graphics.pipeline->getVAOHash(); } - - -//! \return Returns the name of the video driver. -const wchar_t* COpenGLDriver::getName() const -{ - return Name.c_str(); -} - - - -// this code was sent in by Oliver Klems, thank you! (I modified the glViewport -// method just a bit. -void COpenGLDriver::setViewPort(const core::rect& area) -{ - if (area == ViewPort) - return; - core::rect vp = area; - core::rect rendert(0,0, getCurrentRenderTargetSize().Width, getCurrentRenderTargetSize().Height); - vp.clipAgainst(rendert); - - if (vp.getHeight()>0 && vp.getWidth()>0) - { - glViewport(vp.UpperLeftCorner.X, - vp.UpperLeftCorner.Y, - vp.getWidth(), vp.getHeight()); - - ViewPort = vp; - } -} - - -IFrameBuffer* COpenGLDriver::addFrameBuffer() -{ - SAuxContext* found = getThreadContext_helper(false); - if (!found) - return nullptr; - - IFrameBuffer* fbo = new COpenGLFrameBuffer(this); - auto it = std::lower_bound(found->FrameBuffers.begin(),found->FrameBuffers.end(),fbo); - found->FrameBuffers.insert(it,fbo); - return fbo; -} - -void COpenGLDriver::removeFrameBuffer(IFrameBuffer* framebuf) -{ - if (!framebuf) - return; - - _NBL_CHECK_OWNING_THREAD(framebuf,return;); - - SAuxContext* found = getThreadContext_helper(false); - if (!found) - return; - - auto it = std::lower_bound(found->FrameBuffers.begin(),found->FrameBuffers.end(),framebuf); - if (it!=found->FrameBuffers.end() && !(framebuf<*it)) - found->FrameBuffers.erase(it); - else - return; - - framebuf->drop(); -} - -void COpenGLDriver::removeAllFrameBuffers() -{ - SAuxContext* found = getThreadContext_helper(false); - if (!found) - return; - - for (auto fb : found->FrameBuffers) - fb->drop(); - found->FrameBuffers.clear(); -} - - -void COpenGLDriver::blitRenderTargets(IFrameBuffer* in, IFrameBuffer* out, - bool copyDepth, bool copyStencil, - core::recti srcRect, core::recti dstRect, - bool bilinearFilter) -{ - GLuint inFBOHandle = 0; - GLuint outFBOHandle = 0; - - SAuxContext * found = getThreadContext_helper(false); - if (!found) - return; - - - GLboolean rasterDiscard = 0; - GLboolean colormask[4]{}; - GLboolean depthWrite = found->nextState.rasterParams.depthWriteEnable; - GLuint smask_back = found->nextState.rasterParams.stencilFunc_back.mask; - GLuint smask_front = found->nextState.rasterParams.stencilFunc_front.mask; - - if (copyDepth) - found->nextState.rasterParams.depthWriteEnable = 1; - if (copyStencil) - { - found->nextState.rasterParams.stencilFunc_back.mask = ~0u; - found->nextState.rasterParams.stencilFunc_front.mask = ~0u; - } - clearColor_gatherAndOverrideState(found, 0u, &rasterDiscard, colormask); - - if (srcRect.getArea()==0) - { - if (in) - { - auto rttsize = in->getSize(); - srcRect = core::recti(0,0,rttsize.Width,rttsize.Height); - } - else - srcRect = core::recti(0,0,Params.WindowSize.Width,Params.WindowSize.Height); - } - if (dstRect.getArea()==0) - { - if (out) - { - auto rttsize = out->getSize(); - dstRect = core::recti(0,0,rttsize.Width,rttsize.Height); - } - else - dstRect = core::recti(0,0,Params.WindowSize.Width,Params.WindowSize.Height); - } - if (srcRect==dstRect||copyDepth||copyStencil) //and some checks for multisample - bilinearFilter = false; - - setViewPort(dstRect); - - if (in) - inFBOHandle = static_cast(in)->getOpenGLName(); - if (out) - outFBOHandle = static_cast(out)->getOpenGLName(); - - extGlBlitNamedFramebuffer(inFBOHandle,outFBOHandle, - srcRect.UpperLeftCorner.X,srcRect.UpperLeftCorner.Y,srcRect.LowerRightCorner.X,srcRect.LowerRightCorner.Y, - dstRect.UpperLeftCorner.X,dstRect.UpperLeftCorner.Y,dstRect.LowerRightCorner.X,dstRect.LowerRightCorner.Y, - GL_COLOR_BUFFER_BIT|(copyDepth ? GL_DEPTH_BUFFER_BIT:0)|(copyStencil ? GL_STENCIL_BUFFER_BIT:0), - bilinearFilter ? GL_LINEAR:GL_NEAREST); - - if (copyDepth) - found->nextState.rasterParams.depthWriteEnable = depthWrite; - if (copyStencil) - { - found->nextState.rasterParams.stencilFunc_back.mask = smask_back; - found->nextState.rasterParams.stencilFunc_front.mask = smask_front; - } - clearColor_bringbackState(found, 0u, rasterDiscard, colormask); -} - void COpenGLDriver::clearColor_gatherAndOverrideState(SAuxContext * found, uint32_t _attIx, GLboolean* _rasterDiscard, GLboolean* _colorWmask) { _rasterDiscard[0] = found->nextState.rasterParams.rasterizerDiscardEnable; @@ -2804,63 +1482,6 @@ void COpenGLDriver::clearColor_bringbackState(SAuxContext * found, uint32_t _att memcpy(found->nextState.rasterParams.drawbufferBlend[_attIx].colorMask.colorWritemask, _colorWmask, 4); } -//! Sets multiple render targets -bool COpenGLDriver::setRenderTarget(IFrameBuffer* frameBuffer, bool setNewViewport) -{ - SAuxContext* found = getThreadContext_helper(false); - if (!found) - return false; - - if (frameBuffer==found->CurrentFBO) - return true; - - if (!frameBuffer) - { - found->CurrentRendertargetSize = Params.WindowSize; - extGlBindFramebuffer(GL_FRAMEBUFFER, 0); - if (found->CurrentFBO) - found->CurrentFBO->drop(); - found->CurrentFBO = NULL; - - if (setNewViewport) - setViewPort(core::recti(0,0,Params.WindowSize.Width,Params.WindowSize.Height)); - - return true; - } - - _NBL_CHECK_OWNING_THREAD(frameBuffer,return false;); - - core::dimension2du newRTTSize = frameBuffer->getSize(); - found->CurrentRendertargetSize = newRTTSize; - - - extGlBindFramebuffer(GL_FRAMEBUFFER, static_cast(frameBuffer)->getOpenGLName()); - if (setNewViewport) - setViewPort(core::recti(0,0,newRTTSize.Width,newRTTSize.Height)); - - - frameBuffer->grab(); - if (found->CurrentFBO) - found->CurrentFBO->drop(); - found->CurrentFBO = static_cast(frameBuffer); - //found->flushStateGraphics(GSB_ALL); //! OPTIMIZE: Needed? - - - return true; -} - - -// returns the current size of the screen or rendertarget -const core::dimension2d& COpenGLDriver::getCurrentRenderTargetSize() -{ - const SAuxContext* found = getThreadContext(); - if (!found || found->CurrentRendertargetSize.Width == 0) - return Params.WindowSize; - else - return found->CurrentRendertargetSize; -} - - //! Clears the ZBuffer. void COpenGLDriver::clearZBuffer(const float &depth) { @@ -3002,58 +1623,6 @@ void COpenGLDriver::clearColorBuffer(const E_FBO_ATTACHMENT_POINT &attachment, c clearColor_bringbackState(found, attIx, rasterizerDiscard, colormask); } -void COpenGLDriver::clearScreen(const E_SCREEN_BUFFERS &buffer, const float* vals) -{ - auto ctx = getThreadContext_helper(false); - if (!ctx) - return; - - GLboolean rasterDiscard; - GLboolean colorWmask[4]; - clearColor_gatherAndOverrideState(ctx, 0u, &rasterDiscard, colorWmask); - switch (buffer) - { - case ESB_BACK_LEFT: - extGlClearNamedFramebufferfv(0,GL_COLOR,0,vals); - break; - case ESB_BACK_RIGHT: - extGlClearNamedFramebufferfv(0,GL_COLOR,0,vals); - break; - case ESB_FRONT_LEFT: - extGlClearNamedFramebufferfv(0,GL_COLOR,0,vals); - break; - case ESB_FRONT_RIGHT: - extGlClearNamedFramebufferfv(0,GL_COLOR,0,vals); - break; - } - clearColor_bringbackState(ctx, 0u, rasterDiscard, colorWmask); -} -void COpenGLDriver::clearScreen(const E_SCREEN_BUFFERS &buffer, const uint32_t* vals) -{ - auto ctx = getThreadContext_helper(false); - if (!ctx) - return; - - GLboolean rasterDiscard; - GLboolean colorWmask[4]; - clearColor_gatherAndOverrideState(ctx, 0u, &rasterDiscard, colorWmask); - switch (buffer) - { - case ESB_BACK_LEFT: - extGlClearNamedFramebufferuiv(0,GL_COLOR,0,vals); - break; - case ESB_BACK_RIGHT: - extGlClearNamedFramebufferuiv(0,GL_COLOR,0,vals); - break; - case ESB_FRONT_LEFT: - extGlClearNamedFramebufferuiv(0,GL_COLOR,0,vals); - break; - case ESB_FRONT_RIGHT: - extGlClearNamedFramebufferuiv(0,GL_COLOR,0,vals); - break; - } - clearColor_bringbackState(ctx, 0u, rasterDiscard, colorWmask); -} //! Enable/disable a clipping plane. void COpenGLDriver::enableClipPlane(uint32_t index, bool enable) @@ -3071,76 +1640,3 @@ void COpenGLDriver::enableClipPlane(uint32_t index, bool enable) } // end namespace #endif // _NBL_COMPILE_WITH_OPENGL_ - -namespace nbl -{ -namespace video -{ - - -// ----------------------------------- -// WINDOWS VERSION -// ----------------------------------- -#ifdef _NBL_COMPILE_WITH_WINDOWS_DEVICE_ -IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, - io::IFileSystem* io, CIrrDeviceWin32* device, const asset::IGLSLCompiler* glslcomp) -{ -#ifdef _NBL_COMPILE_WITH_OPENGL_ - COpenGLDriver* ogl = new COpenGLDriver(params, io, device, glslcomp); - - if (!ogl->initDriver(device)) - { - ogl->drop(); - ogl = 0; - } - return ogl; -#else - return 0; -#endif // _NBL_COMPILE_WITH_OPENGL_ -} -#endif // _NBL_COMPILE_WITH_WINDOWS_DEVICE_ - -// ----------------------------------- -// X11 VERSION -// ----------------------------------- -#ifdef _NBL_COMPILE_WITH_X11_DEVICE_ -IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, - io::IFileSystem* io, CIrrDeviceLinux* device, const asset::IGLSLCompiler* glslcomp -#ifdef _IRR_COMPILE_WITH_OPENGL_ - , COpenGLDriver::SAuxContext* auxCtxts -#endif // _NBL_COMPILE_WITH_OPENGL_ - ) -{ -#ifdef _NBL_COMPILE_WITH_OPENGL_ - COpenGLDriver* ogl = new COpenGLDriver(params, io, device, glslcomp); - if (!ogl->initDriver(device,auxCtxts)) - { - ogl->drop(); - ogl = 0; - } - return ogl; -#else - return nullptr; -#endif // _NBL_COMPILE_WITH_OPENGL_ -} -#endif // _NBL_COMPILE_WITH_X11_DEVICE_ - - -// ----------------------------------- -// SDL VERSION -// ----------------------------------- -#ifdef _NBL_COMPILE_WITH_SDL_DEVICE_ -IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, - io::IFileSystem* io, CIrrDeviceSDL* device) -{ -#ifdef _NBL_COMPILE_WITH_OPENGL_ - return new COpenGLDriver(params, io, device); -#else - return 0; -#endif // _NBL_COMPILE_WITH_OPENGL_ -} -#endif // _NBL_COMPILE_WITH_SDL_DEVICE_ - -} // end namespace -} // end namespace - diff --git a/source/Nabla/COpenGLDriver.h b/source/Nabla/COpenGLDriver.h index cd834cb28c..2d4c9758c4 100644 --- a/source/Nabla/COpenGLDriver.h +++ b/source/Nabla/COpenGLDriver.h @@ -169,176 +169,25 @@ struct SOpenGLState SPixelPackUnpack pixelUnpack; }; -// GCC is special -template -struct pipeline_for_bindpoint; -template<> struct pipeline_for_bindpoint { using type = COpenGLComputePipeline; }; -template<> struct pipeline_for_bindpoint { using type = COpenGLRenderpassIndependentPipeline; }; - -template -using pipeline_for_bindpoint_t = typename pipeline_for_bindpoint::type; class COpenGLDriver final : public CNullDriver, public COpenGLExtensionHandler { - - bool bindDescriptorSets(E_PIPELINE_BIND_POINT _pipelineType, const IGPUPipelineLayout* _layout, - uint32_t _first, uint32_t _count, const IGPUDescriptorSet* const* _descSets, core::smart_refctd_dynamic_array* _dynamicOffsets) override; - - - core::smart_refctd_ptr createGPUBufferOnDedMem(const IDriverMemoryBacked::SDriverMemoryRequirements& initialMreqs, const bool canModifySubData = false) override; - - core::smart_refctd_ptr createGPUBufferView(IGPUBuffer* _underlying, asset::E_FORMAT _fmt, size_t _offset, size_t _size) override; - - core::smart_refctd_ptr createGPUSampler(const IGPUSampler::SParams& _params) override; - - core::smart_refctd_ptr createGPUImageOnDedMem(IGPUImage::SCreationParams&& params, const IDriverMemoryBacked::SDriverMemoryRequirements& initialMreqs) override; - - core::smart_refctd_ptr createGPUImageView(IGPUImageView::SCreationParams&& params) override; - - core::smart_refctd_ptr createGPUShader(core::smart_refctd_ptr&& _cpushader) override; - core::smart_refctd_ptr createGPUSpecializedShader(const IGPUShader* _unspecialized, const asset::ISpecializedShader::SInfo& _specInfo, const asset::ISPIRVOptimizer* _spvopt) override; - - core::smart_refctd_ptr createGPUDescriptorSetLayout(const IGPUDescriptorSetLayout::SBinding* _begin, const IGPUDescriptorSetLayout::SBinding* _end) override; - - core::smart_refctd_ptr createGPUPipelineLayout( - const asset::SPushConstantRange* const _pcRangesBegin = nullptr, const asset::SPushConstantRange* const _pcRangesEnd = nullptr, - core::smart_refctd_ptr&& _layout0 = nullptr, core::smart_refctd_ptr&& _layout1 = nullptr, - core::smart_refctd_ptr&& _layout2 = nullptr, core::smart_refctd_ptr&& _layout3 = nullptr - ) override; - - core::smart_refctd_ptr createGPURenderpassIndependentPipeline( - IGPUPipelineCache* _pipelineCache, - core::smart_refctd_ptr&& _layout, - IGPUSpecializedShader* const* _shadersBegin, IGPUSpecializedShader* const* _shadersEnd, - const asset::SVertexInputParams& _vertexInputParams, - const asset::SBlendParams& _blendParams, - const asset::SPrimitiveAssemblyParams& _primAsmParams, - const asset::SRasterizationParams& _rasterParams - ) override; - - virtual core::smart_refctd_ptr createGPUComputePipeline( - IGPUPipelineCache* _pipelineCache, - core::smart_refctd_ptr&& _layout, - core::smart_refctd_ptr&& _shader - ) override; - - core::smart_refctd_ptr createGPUPipelineCache() override; - - core::smart_refctd_ptr createGPUDescriptorSet(core::smart_refctd_ptr&& _layout) override; - - void updateDescriptorSets(uint32_t descriptorWriteCount, const IGPUDescriptorSet::SWriteDescriptorSet* pDescriptorWrites, uint32_t descriptorCopyCount, const IGPUDescriptorSet::SCopyDescriptorSet* pDescriptorCopies) override; - - - bool pushConstants(const IGPUPipelineLayout* _layout, uint32_t _stages, uint32_t _offset, uint32_t _size, const void* _values) override; - - bool dispatch(uint32_t _groupCountX, uint32_t _groupCountY, uint32_t _groupCountZ) override; - bool dispatchIndirect(const IGPUBuffer* _indirectBuf, size_t _offset) override; - - - //! generic version which overloads the unimplemented versions - bool changeRenderContext(const SExposedVideoData& videoData) {return false;} - - bool initAuxContext(); - const SAuxContext* getThreadContext(const std::thread::id& tid=std::this_thread::get_id()); - bool deinitAuxContext(); - uint16_t retrieveDisplayRefreshRate() const override; - - void flushMappedMemoryRanges(uint32_t memoryRangeCount, const video::IDriverMemoryAllocation::MappedMemoryRange* pMemoryRanges) override; - - void invalidateMappedMemoryRanges(uint32_t memoryRangeCount, const video::IDriverMemoryAllocation::MappedMemoryRange* pMemoryRanges) override; - void fillBuffer(IGPUBuffer* buffer, size_t offset, size_t length, uint32_t value) override; - void copyBuffer(IGPUBuffer* readBuffer, IGPUBuffer* writeBuffer, size_t readOffset, size_t writeOffset, size_t length) override; - void copyImage(IGPUImage* srcImage, IGPUImage* dstImage, uint32_t regionCount, const IGPUImage::SImageCopy* pRegions) override; - void copyBufferToImage(IGPUBuffer* srcBuffer, IGPUImage* dstImage, uint32_t regionCount, const IGPUImage::SBufferCopy* pRegions) override; - - void copyImageToBuffer(IGPUImage* srcImage, IGPUBuffer* dstBuffer, uint32_t regionCount, const IGPUImage::SBufferCopy* pRegions) override; - - //! clears the zbuffer - bool beginScene(bool backBuffer=true, bool zBuffer=true, - SColor color=SColor(255,0,0,0), - const SExposedVideoData& videoData=SExposedVideoData(), - core::rect* sourceRect=0); - - //! presents the rendered scene on the screen, returns false if failed - bool endScene(); - - - void beginQuery(IQueryObject* query); - void endQuery(IQueryObject* query); - - IQueryObject* createPrimitivesGeneratedQuery() override; - IQueryObject* createElapsedTimeQuery() override; - IGPUTimestampQuery* createTimestampQuery() override; - - - virtual void drawMeshBuffer(const video::IGPUMeshBuffer* mb); - - virtual void drawArraysIndirect(const asset::SBufferBinding _vtxBindings[IGPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT], - asset::E_PRIMITIVE_TOPOLOGY mode, - const IGPUBuffer* indirectDrawBuff, - size_t offset, size_t maxCount, size_t stride, - const IGPUBuffer* countBuffer = nullptr, size_t countOffset = 0u) override; - virtual void drawIndexedIndirect(const asset::SBufferBinding _vtxBindings[IGPUMeshBuffer::MAX_ATTR_BUF_BINDING_COUNT], - asset::E_PRIMITIVE_TOPOLOGY mode, - asset::E_INDEX_TYPE indexType, const IGPUBuffer* indexBuff, - const IGPUBuffer* indirectDrawBuff, - size_t offset, size_t maxCount, size_t stride, - const IGPUBuffer* countBuffer = nullptr, size_t countOffset = 0u) override; - - - //! queries the features of the driver, returns true if feature is available - virtual bool queryFeature(const E_DRIVER_FEATURE& feature) const; - //! virtual void issueGPUTextureBarrier() {COpenGLExtensionHandler::extGlTextureBarrier();} - //! needs to be "deleted" since its not refcounted - virtual core::smart_refctd_ptr placeFence(const bool& implicitFlushWaitSameThread=false) override final - { - return core::make_smart_refctd_ptr(implicitFlushWaitSameThread); - } - - //! \return Returns the name of the video driver. Example: In case of the Direct3D8 - //! driver, it would return "Direct3D8.1". - virtual const wchar_t* getName() const; - - //! sets a viewport - virtual void setViewPort(const core::rect& area); - - //! Returns type of video driver - inline E_DRIVER_TYPE getDriverType() const override { return EDT_OPENGL; } - - virtual IFrameBuffer* addFrameBuffer(); - - //! Remove - virtual void removeFrameBuffer(IFrameBuffer* framebuf); - - virtual void removeAllFrameBuffers(); - - virtual bool setRenderTarget(IFrameBuffer* frameBuffer, bool setNewViewport=true); - - virtual void blitRenderTargets(IFrameBuffer* in, IFrameBuffer* out, - bool copyDepth=true, bool copyStencil=true, - core::recti srcRect=core::recti(0,0,0,0), - core::recti dstRect=core::recti(0,0,0,0), - bool bilinearFilter=false); - private: void clearColor_gatherAndOverrideState(SAuxContext* found, uint32_t _attIx, GLboolean* _rasterDiscard, GLboolean* _colorWmask); void clearColor_bringbackState(SAuxContext* found, uint32_t _attIx, GLboolean _rasterDiscard, const GLboolean* _colorWmask); public: - //! Clears the ZBuffer. - virtual void clearZBuffer(const float &depth=0.0); - virtual void clearStencilBuffer(const int32_t &stencil); virtual void clearZStencilBuffers(const float &depth, const int32_t &stencil); @@ -347,9 +196,6 @@ class COpenGLDriver final : public CNullDriver, public COpenGLExtensionHandler virtual void clearColorBuffer(const E_FBO_ATTACHMENT_POINT &attachment, const uint32_t* vals); virtual void clearColorBuffer(const E_FBO_ATTACHMENT_POINT &attachment, const float* vals); - virtual void clearScreen(const E_SCREEN_BUFFERS &buffer, const float* vals) override; - virtual void clearScreen(const E_SCREEN_BUFFERS &buffer, const uint32_t* vals) override; - //! Enable/disable a clipping plane. //! There are at least 6 clipping planes available for the user to set at will. //! \param index: The plane index. Must be between 0 and MaxUserClipPlanes. @@ -368,14 +214,6 @@ class COpenGLDriver final : public CNullDriver, public COpenGLExtensionHandler //! const size_t& getMaxShaderInvocationsPerALU() const {return maxALUShaderInvocations;} -#ifdef _NBL_COMPILE_WITH_OPENCL_ - const cl_device_id& getOpenCLAssociatedDevice() const {return clDevice;} - const cl_context_properties* getOpenCLAssociatedContextProperties() const { return clProperties; } - - size_t getOpenCLAssociatedDeviceID() const {return clDeviceIx;} - size_t getOpenCLAssociatedPlatformID() const {return clPlatformIx;} -#endif // _NBL_COMPILE_WITH_OPENCL_ - struct SAuxContext { //public: @@ -408,26 +246,8 @@ class COpenGLDriver final : public CNullDriver, public COpenGLExtensionHandler core::smart_refctd_ptr layout; } effectivelyBoundDescriptors; - //push constants are tracked outside of next/currentState because there can be multiple pushConstants() calls and each of them kinda depends on the pervious one (layout compatibility) - pipeline_for_bindpoint_t::PushConstantsState pushConstantsStateCompute; - pipeline_for_bindpoint_t::PushConstantsState pushConstantsStateGraphics; - template - typename pipeline_for_bindpoint_t::PushConstantsState* pushConstantsState() - { - if constexpr(PBP==EPBP_COMPUTE) - return &pushConstantsStateCompute; - else if (PBP== EPBP_GRAPHICS) - return &pushConstantsStateGraphics; - else - return nullptr; - } //private: - std::thread::id threadId; - uint8_t ID; //index in array of contexts, just to be easier in use - EGLContext ctx; - EGLSurface surface; - //! FBOs core::vector FrameBuffers; COpenGLFrameBuffer* CurrentFBO; @@ -454,30 +274,6 @@ class COpenGLDriver final : public CNullDriver, public COpenGLExtensionHandler const IGPUBuffer* _indirectDrawBuffer, const IGPUBuffer* _paramBuffer ); - template - inline void pushConstants(const COpenGLPipelineLayout* _layout, uint32_t _stages, uint32_t _offset, uint32_t _size, const void* _values) - { - //validation is done in CNullDriver::pushConstants() - //if arguments were invalid (dont comply Valid Usage section of vkCmdPushConstants docs), execution should not even get to this point - - if (pushConstantsState()->layout && !pushConstantsState()->layout->isCompatibleForPushConstants(_layout)) - { - //#ifdef _NBL_DEBUG - constexpr size_t toFill = IGPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE / sizeof(uint64_t); - constexpr size_t bytesLeft = IGPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE - (toFill * sizeof(uint64_t)); - constexpr uint64_t pattern = 0xdeadbeefDEADBEEFull; - std::fill(reinterpret_cast(pushConstantsState()->data), reinterpret_cast(pushConstantsState()->data)+toFill, pattern); - if constexpr (bytesLeft > 0ull) - memcpy(reinterpret_cast(pushConstantsState()->data) + toFill, &pattern, bytesLeft); - //#endif - - _stages |= IGPUSpecializedShader::ESS_ALL; - } - pushConstantsState()->incrementStamps(_stages); - - pushConstantsState()->layout = core::smart_refctd_ptr(_layout); - memcpy(pushConstantsState()->data+_offset, _values, _size); - } inline size_t getVAOCacheSize() const { @@ -575,9 +371,6 @@ class COpenGLDriver final : public CNullDriver, public COpenGLExtensionHandler bool runningInRenderDoc; - // returns the current size of the screen or rendertarget - virtual const core::dimension2d& getCurrentRenderTargetSize(); - void createMaterialRenderers(); core::stringw Name; @@ -592,15 +385,9 @@ class COpenGLDriver final : public CNullDriver, public COpenGLExtensionHandler size_t maxALUShaderInvocations; size_t maxConcurrentShaderInvocations; uint32_t maxShaderComputeUnits; -#ifdef _NBL_COMPILE_WITH_OPENCL_ - cl_device_id clDevice; - cl_context_properties clProperties[7]; - size_t clPlatformIx, clDeviceIx; -#endif // _NBL_COMPILE_WITH_OPENCL_ std::mutex glContextMutex; SAuxContext* AuxContexts; - core::smart_refctd_ptr GLSLCompiler; }; } // end namespace nbl::video diff --git a/source/Nabla/COpenGLExtensionHandler.h b/source/Nabla/COpenGLExtensionHandler.h index 087d992240..a57eebdd17 100644 --- a/source/Nabla/COpenGLExtensionHandler.h +++ b/source/Nabla/COpenGLExtensionHandler.h @@ -13,1136 +13,16 @@ #include "COpenGLStateManager.h" -#ifdef _NBL_WINDOWS_API_ - // include windows headers for HWND - #include "../src/3rdparty/GL/wglext.h" -#elif defined(_NBL_COMPILE_WITH_X11_) - #include "GL/glx.h" - #include "../src/3rdparty/GL/glxext.h" -#endif - -#include "os.h" -#include "nbl/video/IGPUImageView.h" - - namespace nbl { namespace video { - -struct DrawArraysIndirectCommand -{ - GLuint count; - GLuint instanceCount; - GLuint first; - GLuint reservedMustBeZero; -}; - -struct DrawElementsIndirectCommand -{ - GLuint count; - GLuint instanceCount; - GLuint firstIndex; - GLuint baseVertex; - GLuint baseInstance; -}; - - -static const char* const OpenGLFeatureStrings[] = { - "GL_3DFX_multisample", - "GL_3DFX_tbuffer", - "GL_3DFX_texture_compression_FXT1", - "GL_AMD_blend_minmax_factor", - "GL_AMD_conservative_depth", - "GL_AMD_debug_output", - "GL_AMD_depth_clamp_separate", - "GL_AMD_draw_buffers_blend", - "GL_AMD_multi_draw_indirect", - "GL_AMD_name_gen_delete", - "GL_AMD_performance_monitor", - "GL_AMD_sample_positions", - "GL_AMD_seamless_cubemap_per_texture", - "GL_AMD_shader_stencil_export", - "GL_AMD_texture_texture4", - "GL_AMD_transform_feedback3_lines_triangles", - "GL_AMD_vertex_shader_tesselator", - "GL_AMD_gcn_shader", - "GL_AMD_gpu_shader_half_float_fetch", - "GL_AMD_shader_explicit_vertex_parameter", - "GL_AMD_shader_fragment_mask", - "GL_AMD_shader_image_load_store_lod", - "GL_AMD_shader_trinary_minmax", - "GL_AMD_texture_gather_bias_lod", - "GL_AMD_vertex_shader_viewport_index", - "GL_AMD_vertex_shader_layer", - "GL_AMD_sparse_texture", - "GL_AMD_shader_stencil_value_export", - "GL_AMD_gpu_shader_int64", - "GL_AMD_shader_ballot", - "GL_APPLE_aux_depth_stencil", - "GL_APPLE_client_storage", - "GL_APPLE_element_array", - "GL_APPLE_fence", - "GL_APPLE_float_pixels", - "GL_APPLE_flush_buffer_range", - "GL_APPLE_object_purgeable", - "GL_APPLE_rgb_422", - "GL_APPLE_row_bytes", - "GL_APPLE_specular_vector", - "GL_APPLE_texture_range", - "GL_APPLE_transform_hint", - "GL_APPLE_vertex_array_object", - "GL_APPLE_vertex_array_range", - "GL_APPLE_vertex_program_evaluators", - "GL_APPLE_ycbcr_422", - "GL_ARB_base_instance", - "GL_ARB_bindless_texture", - "GL_ARB_buffer_storage", - "GL_ARB_blend_func_extended", - "GL_ARB_cl_event", - "GL_ARB_clip_control", - "GL_ARB_color_buffer_float", - "GL_ARB_compatibility", - "GL_ARB_compressed_texture_pixel_storage", - "GL_ARB_compute_shader", - "GL_ARB_conservative_depth", - "GL_ARB_copy_buffer", - "GL_ARB_debug_output", - "GL_ARB_depth_buffer_float", - "GL_ARB_depth_clamp", - "GL_ARB_depth_texture", - "GL_ARB_direct_state_access", - "GL_ARB_draw_buffers", - "GL_ARB_draw_buffers_blend", - "GL_ARB_draw_elements_base_vertex", - "GL_ARB_draw_indirect", - "GL_ARB_draw_instanced", - "GL_ARB_ES2_compatibility", - "GL_ARB_explicit_attrib_location", - "GL_ARB_explicit_uniform_location", - "GL_ARB_fragment_coord_conventions", - "GL_ARB_fragment_program", - "GL_ARB_fragment_program_shadow", - "GL_ARB_fragment_shader", - "GL_ARB_fragment_shader_interlock", - "GL_ARB_framebuffer_object", - "GL_ARB_framebuffer_sRGB", - "GL_ARB_geometry_shader4", - "GL_ARB_get_program_binary", - "GL_ARB_get_texture_sub_image", - "GL_ARB_gpu_shader5", - "GL_ARB_gpu_shader_fp64", - "GL_ARB_half_float_pixel", - "GL_ARB_half_float_vertex", - "GL_ARB_imaging", - "GL_ARB_indirect_parameters", - "GL_ARB_instanced_arrays", - "GL_ARB_internalformat_query", - "GL_ARB_internalformat_query2", - "GL_ARB_map_buffer_alignment", - "GL_ARB_map_buffer_range", - "GL_ARB_matrix_palette", - "GL_ARB_multi_bind", - "GL_ARB_multi_draw_indirect", - "GL_ARB_multisample", - "GL_ARB_multitexture", - "GL_ARB_occlusion_query", - "GL_ARB_occlusion_query2", - "GL_ARB_pixel_buffer_object", - "GL_ARB_point_parameters", - "GL_ARB_point_sprite", - "GL_ARB_program_interface_query", - "GL_ARB_provoking_vertex", - "GL_ARB_query_buffer_object", - "GL_ARB_robustness", - "GL_ARB_sample_shading", - "GL_ARB_sampler_objects", - "GL_ARB_seamless_cube_map", - "GL_ARB_separate_shader_objects", - "GL_ARB_shader_atomic_counters", - "GL_ARB_shader_ballot", - "GL_ARB_shader_bit_encoding", - "GL_ARB_shader_draw_parameters", - "GL_ARB_shader_group_vote", - "GL_ARB_shader_image_load_store", - "GL_ARB_shader_objects", - "GL_ARB_shader_precision", - "GL_ARB_shader_stencil_export", - "GL_ARB_shader_subroutine", - "GL_ARB_shader_texture_lod", - "GL_ARB_shading_language_100", - "GL_ARB_shading_language_420pack", - "GL_ARB_shading_language_include", - "GL_ARB_shading_language_packing", - "GL_ARB_shadow", - "GL_ARB_shadow_ambient", - "GL_ARB_sync", - "GL_ARB_tessellation_shader", - "GL_ARB_texture_barrier", - "GL_ARB_texture_border_clamp", - "GL_ARB_texture_buffer_object", - "GL_ARB_texture_buffer_object_rgb32", - "GL_ARB_texture_buffer_range", - "GL_ARB_texture_compression", - "GL_ARB_texture_compression_bptc", - "GL_ARB_texture_compression_rgtc", - "GL_ARB_texture_cube_map", - "GL_ARB_texture_cube_map_array", - "GL_ARB_texture_env_add", - "GL_ARB_texture_env_combine", - "GL_ARB_texture_env_crossbar", - "GL_ARB_texture_env_dot3", - "GL_ARB_texture_float", - "GL_ARB_texture_gather", - "GL_ARB_texture_mirrored_repeat", - "GL_ARB_texture_multisample", - "GL_ARB_texture_non_power_of_two", - "GL_ARB_texture_query_lod", - "GL_ARB_texture_rectangle", - "GL_ARB_texture_rg", - "GL_ARB_texture_rgb10_a2ui", - "GL_ARB_texture_stencil8", - "GL_ARB_texture_storage", - "GL_ARB_texture_storage_multisample", - "GL_ARB_texture_swizzle", - "GL_ARB_texture_view", - "GL_ARB_timer_query", - "GL_ARB_transform_feedback2", - "GL_ARB_transform_feedback3", - "GL_ARB_transform_feedback_instanced", - "GL_ARB_transpose_matrix", - "GL_ARB_uniform_buffer_object", - "GL_ARB_vertex_array_bgra", - "GL_ARB_vertex_array_object", - "GL_ARB_vertex_attrib_64bit", - "GL_ARB_vertex_attrib_binding", - "GL_ARB_vertex_blend", - "GL_ARB_vertex_buffer_object", - "GL_ARB_vertex_program", - "GL_ARB_vertex_shader", - "GL_ARB_vertex_type_2_10_10_10_rev", - "GL_ARB_viewport_array", - "GL_ARB_window_pos", - "GL_ARB_enhanced_layouts", - "GL_ARB_cull_distance", - "GL_ARB_derivative_control", - "GL_ARB_shader_texture_image_samples", - "GL_ARB_gpu_shader_int64", - "GL_ARB_post_depth_coverage", - "GL_ARB_shader_clock", - "GL_ARB_shader_viewport_layer_array", - "GL_ARB_sparse_texture2", - "GL_ARB_sparse_texture_clamp", - "GL_ARB_gl_spirv", - "GL_ARB_spirv_extensions", - "GL_ATI_draw_buffers", - "GL_ATI_element_array", - "GL_ATI_envmap_bumpmap", - "GL_ATI_fragment_shader", - "GL_ATI_map_object_buffer", - "GL_ATI_meminfo", - "GL_ATI_pixel_format_float", - "GL_ATI_pn_triangles", - "GL_ATI_separate_stencil", - "GL_ATI_text_fragment_shader", - "GL_ATI_texture_env_combine3", - "GL_ATI_texture_float", - "GL_ATI_texture_mirror_once", - "GL_ATI_vertex_array_object", - "GL_ATI_vertex_attrib_array_object", - "GL_ATI_vertex_streams", - "GL_EXT_422_pixels", - "GL_EXT_abgr", - "GL_EXT_bgra", - "GL_EXT_bindable_uniform", - "GL_EXT_blend_color", - "GL_EXT_blend_equation_separate", - "GL_EXT_blend_func_separate", - "GL_EXT_blend_logic_op", - "GL_EXT_blend_minmax", - "GL_EXT_blend_subtract", - "GL_EXT_clip_volume_hint", - "GL_EXT_cmyka", - "GL_EXT_color_subtable", - "GL_EXT_compiled_vertex_array", - "GL_EXT_convolution", - "GL_EXT_coordinate_frame", - "GL_EXT_copy_texture", - "GL_EXT_cull_vertex", - "GL_EXT_depth_bounds_test", - "GL_EXT_direct_state_access", - "GL_EXT_draw_buffers2", - "GL_EXT_draw_instanced", - "GL_EXT_draw_range_elements", - "GL_EXT_fog_coord", - "GL_EXT_framebuffer_blit", - "GL_EXT_framebuffer_multisample", - "GL_EXT_framebuffer_multisample_blit_scaled", - "GL_EXT_framebuffer_object", - "GL_EXT_framebuffer_sRGB", - "GL_EXT_geometry_shader4", - "GL_EXT_gpu_program_parameters", - "GL_EXT_gpu_shader4", - "GL_EXT_histogram", - "GL_EXT_index_array_formats", - "GL_EXT_index_func", - "GL_EXT_index_material", - "GL_EXT_index_texture", - "GL_EXT_light_texture", - "GL_EXT_misc_attribute", - "GL_EXT_multi_draw_arrays", - "GL_EXT_multisample", - "GL_EXT_packed_depth_stencil", - "GL_EXT_packed_float", - "GL_EXT_packed_pixels", - "GL_EXT_paletted_texture", - "GL_EXT_pixel_buffer_object", - "GL_EXT_pixel_transform", - "GL_EXT_pixel_transform_color_table", - "GL_EXT_point_parameters", - "GL_EXT_polygon_offset", - "GL_EXT_provoking_vertex", - "GL_EXT_rescale_normal", - "GL_EXT_secondary_color", - "GL_EXT_separate_shader_objects", - "GL_EXT_separate_specular_color", - "GL_EXT_shader_image_load_store", - "GL_EXT_shadow_funcs", - "GL_EXT_shared_texture_palette", - "GL_EXT_stencil_clear_tag", - "GL_EXT_stencil_two_side", - "GL_EXT_stencil_wrap", - "GL_EXT_subtexture", - "GL_EXT_texture", - "GL_EXT_texture3D", - "GL_EXT_texture_array", - "GL_EXT_texture_buffer_object", - "GL_EXT_texture_compression_latc", - "GL_EXT_texture_compression_rgtc", - "GL_EXT_texture_compression_s3tc", - "GL_EXT_texture_cube_map", - "GL_EXT_texture_env_add", - "GL_EXT_texture_env_combine", - "GL_EXT_texture_env_dot3", - "GL_EXT_texture_filter_anisotropic", - "GL_EXT_texture_integer", - "GL_EXT_texture_lod_bias", - "GL_EXT_texture_mirror_clamp", - "GL_EXT_texture_object", - "GL_EXT_texture_perturb_normal", - "GL_EXT_texture_shared_exponent", - "GL_EXT_texture_snorm", - "GL_EXT_texture_sRGB", - "GL_EXT_texture_sRGB_decode", - "GL_EXT_texture_sRGB_R8", - "GL_EXT_texture_sRGB_RG8", - "GL_EXT_texture_swizzle", - "GL_EXT_texture_view", - "GL_EXT_timer_query", - "GL_EXT_transform_feedback", - "GL_EXT_vertex_array", - "GL_EXT_vertex_array_bgra", - "GL_EXT_vertex_attrib_64bit", - "GL_EXT_vertex_shader", - "GL_EXT_vertex_weighting", - "GL_EXT_x11_sync_object", - "GL_EXT_shader_pixel_local_storage", - "GL_EXT_shader_pixel_local_storage2", - "GL_EXT_shader_integer_mix", - "GL_EXT_shader_image_load_formatted", - "GL_EXT_post_depth_coverage", - "GL_EXT_sparse_texture2", - "GL_EXT_shader_framebuffer_fetch", - "GL_EXT_shader_framebuffer_fetch_non_coherent", - "GL_FfdMaskSGIX", - "GL_GREMEDY_frame_terminator", - "GL_GREMEDY_string_marker", - "GL_HP_convolution_border_modes", - "GL_HP_image_transform", - "GL_HP_occlusion_test", - "GL_HP_texture_lighting", - "GL_IBM_cull_vertex", - "GL_IBM_multimode_draw_arrays", - "GL_IBM_rasterpos_clip", - "GL_IBM_texture_mirrored_repeat", - "GL_IBM_vertex_array_lists", - "GL_INGR_blend_func_separate", - "GL_INGR_color_clamp", - "GL_INGR_interlace_read", - "GL_INGR_palette_buffer", - "GL_INTEL_fragment_shader_interlock", - "GL_INTEL_parallel_arrays", - "GL_INTEL_texture_scissor", - "GL_INTEL_conservative_rasterization", - "GL_INTEL_blackhole_render", - "GL_KHR_debug", - "GL_MESA_pack_invert", - "GL_MESA_resize_buffers", - "GL_MESA_window_pos", - "GL_MESAX_texture_stack", - "GL_MESA_ycbcr_texture", - "GL_NV_blend_square", - "GL_NV_conditional_render", - "GL_NV_copy_depth_to_color", - "GL_NV_copy_image", - "GL_NV_depth_buffer_float", - "GL_NV_depth_clamp", - "GL_NV_evaluators", - "GL_NV_explicit_multisample", - "GL_NV_fence", - "GL_NV_float_buffer", - "GL_NV_fog_distance", - "GL_NV_fragment_program", - "GL_NV_fragment_program2", - "GL_NV_fragment_program4", - "GL_NV_fragment_program_option", - "GL_NV_fragment_shader_interlock", - "GL_NV_framebuffer_multisample_coverage", - "GL_NV_geometry_program4", - "GL_NV_geometry_shader4", - "GL_NV_gpu_program4", - "GL_NV_gpu_program5", - "GL_NV_gpu_shader5", - "GL_NV_half_float", - "GL_NV_light_max_exponent", - "GL_NV_multisample_coverage", - "GL_NV_multisample_filter_hint", - "GL_NV_occlusion_query", - "GL_NV_packed_depth_stencil", - "GL_NV_parameter_buffer_object", - "GL_NV_parameter_buffer_object2", - "GL_NV_pixel_data_range", - "GL_NV_point_sprite", - "GL_NV_present_video", - "GL_NV_primitive_restart", - "GL_NV_register_combiners", - "GL_NV_register_combiners2", - "GL_NV_shader_buffer_load", - "GL_NV_shader_buffer_store", - "GL_NV_shader_thread_group", - "GL_NV_shader_thread_shuffle", - "GL_NV_tessellation_program5", - "GL_NV_texgen_emboss", - "GL_NV_texgen_reflection", - "GL_NV_texture_barrier", - "GL_NV_texture_compression_vtc", - "GL_NV_texture_env_combine4", - "GL_NV_texture_expand_normal", - "GL_NV_texture_multisample", - "GL_NV_texture_rectangle", - "GL_NV_texture_shader", - "GL_NV_texture_shader2", - "GL_NV_texture_shader3", - "GL_NV_transform_feedback", - "GL_NV_transform_feedback2", - "GL_NV_vdpau_interop", - "GL_NV_vertex_array_range", - "GL_NV_vertex_array_range2", - "GL_NV_vertex_attrib_integer_64bit", - "GL_NV_vertex_buffer_unified_memory", - "GL_NV_vertex_program", - "GL_NV_vertex_program1_1", - "GL_NV_vertex_program2", - "GL_NV_vertex_program2_option", - "GL_NV_vertex_program3", - "GL_NV_vertex_program4", - "GL_NV_video_capture", - "GL_NV_viewport_array2", - "GL_NV_stereo_view_rendering", - "GL_NV_sample_mask_override_coverage", - "GL_NV_geometry_shader_passthrough", - "GL_NV_shader_subgroup_partitioned", - "GL_NV_compute_shader_derivatives", - "GL_NV_fragment_shader_barycentric", - "GL_NV_mesh_shader", - "GL_NV_shader_image_footprint", - "GL_NV_shading_rate_image", - "GL_NV_bindless_texture", - "GL_NV_shader_atomic_float", - "GL_NV_shader_atomic_int64", - "GL_NV_sample_locations", - "GL_NV_shader_atomic_fp16_vector", - "GL_NV_command_list", - "GL_NV_shader_atomic_float64", - "GL_NV_conservative_raster_pre_snap", - "GL_NV_shader_texture_footprint", - "GL_OES_read_format", - "GL_OML_interlace", - "GL_OML_resample", - "GL_OML_subsample", - "GL_OVR_multiview", - "GL_OVR_multiview2", - "GL_PGI_misc_hints", - "GL_PGI_vertex_hints", - "GL_REND_screen_coordinates", - "GL_S3_s3tc", - "GL_SGI_color_matrix", - "GL_SGI_color_table", - "GL_SGI_depth_pass_instrument", - "GL_SGIS_detail_texture", - "GL_SGIS_fog_function", - "GL_SGIS_generate_mipmap", - "GL_SGIS_multisample", - "GL_SGIS_pixel_texture", - "GL_SGIS_point_line_texgen", - "GL_SGIS_point_parameters", - "GL_SGIS_sharpen_texture", - "GL_SGIS_texture4D", - "GL_SGIS_texture_border_clamp", - "GL_SGIS_texture_color_mask", - "GL_SGIS_texture_edge_clamp", - "GL_SGIS_texture_filter4", - "GL_SGIS_texture_lod", - "GL_SGIS_texture_select", - "GL_SGI_texture_color_table", - "GL_SGIX_async", - "GL_SGIX_async_histogram", - "GL_SGIX_async_pixel", - "GL_SGIX_blend_alpha_minmax", - "GL_SGIX_calligraphic_fragment", - "GL_SGIX_clipmap", - "GL_SGIX_convolution_accuracy", - "GL_SGIX_depth_pass_instrument", - "GL_SGIX_depth_texture", - "GL_SGIX_flush_raster", - "GL_SGIX_fog_offset", - "GL_SGIX_fog_scale", - "GL_SGIX_fragment_lighting", - "GL_SGIX_framezoom", - "GL_SGIX_igloo_interface", - "GL_SGIX_impact_pixel_texture", - "GL_SGIX_instruments", - "GL_SGIX_interlace", - "GL_SGIX_ir_instrument1", - "GL_SGIX_list_priority", - "GL_SGIX_pixel_texture", - "GL_SGIX_pixel_tiles", - "GL_SGIX_polynomial_ffd", - "GL_SGIX_reference_plane", - "GL_SGIX_resample", - "GL_SGIX_scalebias_hint", - "GL_SGIX_shadow", - "GL_SGIX_shadow_ambient", - "GL_SGIX_sprite", - "GL_SGIX_subsample", - "GL_SGIX_tag_sample_buffer", - "GL_SGIX_texture_add_env", - "GL_SGIX_texture_coordinate_clamp", - "GL_SGIX_texture_lod_bias", - "GL_SGIX_texture_multi_buffer", - "GL_SGIX_texture_scale_bias", - "GL_SGIX_texture_select", - "GL_SGIX_vertex_preclip", - "GL_SGIX_ycrcb", - "GL_SGIX_ycrcba", - "GL_SGIX_ycrcb_subsample", - "GL_SUN_convolution_border_modes", - "GL_SUN_global_alpha", - "GL_SUN_mesh_array", - "GL_SUN_slice_accum", - "GL_SUN_triangle_list", - "GL_SUN_vertex", - "GL_SUNX_constant_data", - "GL_WIN_phong_shading", - "GL_WIN_specular_fog", - "GL_KHR_texture_compression_astc_hdr", - "GL_KHR_texture_compression_astc_ldr", - "GL_KHR_blend_equation_advanced", - "GL_KHR_blend_equation_advanced_coherent", - //"GLX_EXT_swap_control_tear", - "GL_NVX_gpu_memory_info", - "GL_NVX_multiview_per_view_attributes" -}; //extra extension name that is reported as supported when irrbaw app is running in renderdoc _NBL_STATIC_INLINE_CONSTEXPR const char* RUNNING_IN_RENDERDOC_EXTENSION_NAME = "GL_NBL_RUNNING_IN_RENDERDOC"; -class COpenGLExtensionHandler -{ - public: - enum EOpenGLFeatures { - NBL_3DFX_multisample = 0, - NBL_3DFX_tbuffer, - NBL_3DFX_texture_compression_FXT1, - NBL_AMD_blend_minmax_factor, - NBL_AMD_conservative_depth, - NBL_AMD_debug_output, - NBL_AMD_depth_clamp_separate, - NBL_AMD_draw_buffers_blend, - NBL_AMD_multi_draw_indirect, - NBL_AMD_name_gen_delete, - NBL_AMD_performance_monitor, - NBL_AMD_sample_positions, - NBL_AMD_seamless_cubemap_per_texture, - NBL_AMD_shader_stencil_export, - NBL_AMD_texture_texture4, - NBL_AMD_transform_feedback3_lines_triangles, - NBL_AMD_vertex_shader_tesselator, - NBL_AMD_gcn_shader, - NBL_AMD_gpu_shader_half_float_fetch, - NBL_AMD_shader_explicit_vertex_parameter, - NBL_AMD_shader_fragment_mask, - NBL_AMD_shader_image_load_store_lod, - NBL_AMD_shader_trinary_minmax, - NBL_AMD_texture_gather_bias_lod, - NBL_AMD_vertex_shader_viewport_index, - NBL_AMD_vertex_shader_layer, - NBL_AMD_sparse_texture, - NBL_AMD_shader_stencil_value_export, - NBL_AMD_gpu_shader_int64, - NBL_AMD_shader_ballot, - NBL_APPLE_aux_depth_stencil, - NBL_APPLE_client_storage, - NBL_APPLE_element_array, - NBL_APPLE_fence, - NBL_APPLE_float_pixels, - NBL_APPLE_flush_buffer_range, - NBL_APPLE_object_purgeable, - NBL_APPLE_rgb_422, - NBL_APPLE_row_bytes, - NBL_APPLE_specular_vector, - NBL_APPLE_texture_range, - NBL_APPLE_transform_hint, - NBL_APPLE_vertex_array_object, - NBL_APPLE_vertex_array_range, - NBL_APPLE_vertex_program_evaluators, - NBL_APPLE_ycbcr_422, - NBL_ARB_base_instance, - NBL_ARB_bindless_texture, - NBL_ARB_buffer_storage, - NBL_ARB_blend_func_extended, - NBL_ARB_clip_control, - NBL_ARB_cl_event, - NBL_ARB_color_buffer_float, - NBL_ARB_compatibility, - NBL_ARB_compressed_texture_pixel_storage, - NBL_ARB_compute_shader, - NBL_ARB_conservative_depth, - NBL_ARB_copy_buffer, - NBL_ARB_debug_output, - NBL_ARB_depth_buffer_float, - NBL_ARB_depth_clamp, - NBL_ARB_depth_texture, - NBL_ARB_direct_state_access, - NBL_ARB_draw_buffers, - NBL_ARB_draw_buffers_blend, - NBL_ARB_draw_elements_base_vertex, - NBL_ARB_draw_indirect, - NBL_ARB_draw_instanced, - NBL_ARB_ES2_compatibility, - NBL_ARB_explicit_attrib_location, - NBL_ARB_explicit_uniform_location, - NBL_ARB_fragment_coord_conventions, - NBL_ARB_fragment_program, - NBL_ARB_fragment_program_shadow, - NBL_ARB_fragment_shader, - NBL_ARB_fragment_shader_interlock, - NBL_ARB_framebuffer_object, - NBL_ARB_framebuffer_sRGB, - NBL_ARB_geometry_shader4, - NBL_ARB_get_program_binary, - NBL_ARB_get_texture_sub_image, - NBL_ARB_gpu_shader5, - NBL_ARB_gpu_shader_fp64, - NBL_ARB_half_float_pixel, - NBL_ARB_half_float_vertex, - NBL_ARB_imaging, - NBL_ARB_instanced_arrays, - NBL_ARB_indirect_parameters, - NBL_ARB_internalformat_query, - NBL_ARB_internalformat_query2, - NBL_ARB_map_buffer_alignment, - NBL_ARB_map_buffer_range, - NBL_ARB_matrix_palette, - NBL_ARB_multi_bind, - NBL_ARB_multi_draw_indirect, - NBL_ARB_multisample, - NBL_ARB_multitexture, - NBL_ARB_occlusion_query, - NBL_ARB_occlusion_query2, - NBL_ARB_pixel_buffer_object, - NBL_ARB_point_parameters, - NBL_ARB_point_sprite, - NBL_ARB_program_interface_query, - NBL_ARB_provoking_vertex, - NBL_ARB_query_buffer_object, - NBL_ARB_robustness, - NBL_ARB_sample_shading, - NBL_ARB_sampler_objects, - NBL_ARB_seamless_cube_map, - NBL_ARB_separate_shader_objects, - NBL_ARB_shader_atomic_counters, - NBL_ARB_shader_ballot, - NBL_ARB_shader_bit_encoding, - NBL_ARB_shader_draw_parameters, - NBL_ARB_shader_group_vote, - NBL_ARB_shader_image_load_store, - NBL_ARB_shader_objects, - NBL_ARB_shader_precision, - NBL_ARB_shader_stencil_export, - NBL_ARB_shader_subroutine, - NBL_ARB_shader_texture_lod, - NBL_ARB_shading_language_100, - NBL_ARB_shading_language_420pack, - NBL_ARB_shading_language_include, - NBL_ARB_shading_language_packing, - NBL_ARB_shadow, - NBL_ARB_shadow_ambient, - NBL_ARB_sync, - NBL_ARB_tessellation_shader, - NBL_ARB_texture_barrier, - NBL_ARB_texture_border_clamp, - NBL_ARB_texture_buffer_object, - NBL_ARB_texture_buffer_object_rgb32, - NBL_ARB_texture_buffer_range, - NBL_ARB_texture_compression, - NBL_ARB_texture_compression_bptc, - NBL_ARB_texture_compression_rgtc, - NBL_ARB_texture_cube_map, - NBL_ARB_texture_cube_map_array, - NBL_ARB_texture_env_add, - NBL_ARB_texture_env_combine, - NBL_ARB_texture_env_crossbar, - NBL_ARB_texture_env_dot3, - NBL_ARB_texture_float, - NBL_ARB_texture_gather, - NBL_ARB_texture_mirrored_repeat, - NBL_ARB_texture_multisample, - NBL_ARB_texture_non_power_of_two, - NBL_ARB_texture_query_lod, - NBL_ARB_texture_rectangle, - NBL_ARB_texture_rg, - NBL_ARB_texture_rgb10_a2ui, - NBL_ARB_texture_stencil8, - NBL_ARB_texture_storage, - NBL_ARB_texture_storage_multisample, - NBL_ARB_texture_swizzle, - NBL_ARB_texture_view, - NBL_ARB_timer_query, - NBL_ARB_transform_feedback2, - NBL_ARB_transform_feedback3, - NBL_ARB_transform_feedback_instanced, - NBL_ARB_transpose_matrix, - NBL_ARB_uniform_buffer_object, - NBL_ARB_vertex_array_bgra, - NBL_ARB_vertex_array_object, - NBL_ARB_vertex_attrib_64bit, - NBL_ARB_vertex_attrib_binding, - NBL_ARB_vertex_blend, - NBL_ARB_vertex_buffer_object, - NBL_ARB_vertex_program, - NBL_ARB_vertex_shader, - NBL_ARB_vertex_type_2_10_10_10_rev, - NBL_ARB_viewport_array, - NBL_ARB_window_pos, - NBL_ARB_enhanced_layouts, - NBL_ARB_cull_distance, - NBL_ARB_derivative_control, - NBL_ARB_shader_texture_image_samples, - NBL_ARB_gpu_shader_int64, - NBL_ARB_post_depth_coverage, - NBL_ARB_shader_clock, - NBL_ARB_shader_viewport_layer_array, - NBL_ARB_sparse_texture2, - NBL_ARB_sparse_texture_clamp, - NBL_ARB_gl_spirv, - NBL_ARB_spirv_extensions, - NBL_ATI_draw_buffers, - NBL_ATI_element_array, - NBL_ATI_envmap_bumpmap, - NBL_ATI_fragment_shader, - NBL_ATI_map_object_buffer, - NBL_ATI_meminfo, - NBL_ATI_pixel_format_float, - NBL_ATI_pn_triangles, - NBL_ATI_separate_stencil, - NBL_ATI_text_fragment_shader, - NBL_ATI_texture_env_combine3, - NBL_ATI_texture_float, - NBL_ATI_texture_mirror_once, - NBL_ATI_vertex_array_object, - NBL_ATI_vertex_attrib_array_object, - NBL_ATI_vertex_streams, - NBL_EXT_422_pixels, - NBL_EXT_abgr, - NBL_EXT_bgra, - NBL_EXT_bindable_uniform, - NBL_EXT_blend_color, - NBL_EXT_blend_equation_separate, - NBL_EXT_blend_func_separate, - NBL_EXT_blend_logic_op, - NBL_EXT_blend_minmax, - NBL_EXT_blend_subtract, - NBL_EXT_clip_volume_hint, - NBL_EXT_cmyka, - NBL_EXT_color_subtable, - NBL_EXT_compiled_vertex_array, - NBL_EXT_convolution, - NBL_EXT_coordinate_frame, - NBL_EXT_copy_texture, - NBL_EXT_cull_vertex, - NBL_EXT_depth_bounds_test, - NBL_EXT_direct_state_access, - NBL_EXT_draw_buffers2, - NBL_EXT_draw_instanced, - NBL_EXT_draw_range_elements, - NBL_EXT_fog_coord, - NBL_EXT_framebuffer_blit, - NBL_EXT_framebuffer_multisample, - NBL_EXT_framebuffer_multisample_blit_scaled, - NBL_EXT_framebuffer_object, - NBL_EXT_framebuffer_sRGB, - NBL_EXT_geometry_shader4, - NBL_EXT_gpu_program_parameters, - NBL_EXT_gpu_shader4, - NBL_EXT_histogram, - NBL_EXT_index_array_formats, - NBL_EXT_index_func, - NBL_EXT_index_material, - NBL_EXT_index_texture, - NBL_EXT_light_texture, - NBL_EXT_misc_attribute, - NBL_EXT_multi_draw_arrays, - NBL_EXT_multisample, - NBL_EXT_packed_depth_stencil, - NBL_EXT_packed_float, - NBL_EXT_packed_pixels, - NBL_EXT_paletted_texture, - NBL_EXT_pixel_buffer_object, - NBL_EXT_pixel_transform, - NBL_EXT_pixel_transform_color_table, - NBL_EXT_point_parameters, - NBL_EXT_polygon_offset, - NBL_EXT_provoking_vertex, - NBL_EXT_rescale_normal, - NBL_EXT_secondary_color, - NBL_EXT_separate_shader_objects, - NBL_EXT_separate_specular_color, - NBL_EXT_shader_image_load_store, - NBL_EXT_shadow_funcs, - NBL_EXT_shared_texture_palette, - NBL_EXT_stencil_clear_tag, - NBL_EXT_stencil_two_side, - NBL_EXT_stencil_wrap, - NBL_EXT_subtexture, - NBL_EXT_texture, - NBL_EXT_texture3D, - NBL_EXT_texture_array, - NBL_EXT_texture_buffer_object, - NBL_EXT_texture_compression_latc, - NBL_EXT_texture_compression_rgtc, - NBL_EXT_texture_compression_s3tc, - NBL_EXT_texture_cube_map, - NBL_EXT_texture_env_add, - NBL_EXT_texture_env_combine, - NBL_EXT_texture_env_dot3, - NBL_EXT_texture_filter_anisotropic, - NBL_EXT_texture_integer, - NBL_EXT_texture_lod_bias, - NBL_EXT_texture_mirror_clamp, - NBL_EXT_texture_object, - NBL_EXT_texture_perturb_normal, - NBL_EXT_texture_shared_exponent, - NBL_EXT_texture_snorm, - NBL_EXT_texture_sRGB, - NBL_EXT_texture_sRGB_decode, - NBL_EXT_texture_sRGB_R8, - NBL_EXT_texture_sRGB_RG8, - NBL_EXT_texture_swizzle, - NBL_EXT_texture_view, - NBL_EXT_timer_query, - NBL_EXT_transform_feedback, - NBL_EXT_vertex_array, - NBL_EXT_vertex_array_bgra, - NBL_EXT_vertex_attrib_64bit, - NBL_EXT_vertex_shader, - NBL_EXT_vertex_weighting, - NBL_EXT_x11_sync_object, - NBL_EXT_shader_pixel_local_storage, - NBL_EXT_shader_pixel_local_storage2, - NBL_EXT_shader_integer_mix, - NBL_EXT_shader_image_load_formatted, - NBL_EXT_post_depth_coverage, - NBL_EXT_sparse_texture2, - NBL_EXT_shader_framebuffer_fetch, - NBL_EXT_shader_framebuffer_fetch_non_coherent, - NBL_FfdMaskSGIX, - NBL_GREMEDY_frame_terminator, - NBL_GREMEDY_string_marker, - NBL_HP_convolution_border_modes, - NBL_HP_image_transform, - NBL_HP_occlusion_test, - NBL_HP_texture_lighting, - NBL_IBM_cull_vertex, - NBL_IBM_multimode_draw_arrays, - NBL_IBM_rasterpos_clip, - NBL_IBM_texture_mirrored_repeat, - NBL_IBM_vertex_array_lists, - NBL_INGR_blend_func_separate, - NBL_INGR_color_clamp, - NBL_INGR_interlace_read, - NBL_INGR_palette_buffer, - NBL_INTEL_fragment_shader_ordering, - NBL_INTEL_parallel_arrays, - NBL_INTEL_texture_scissor, - NBL_INTEL_conservative_rasterization, - NBL_INTEL_blackhole_render, - NBL_KHR_debug, - NBL_MESA_pack_invert, - NBL_MESA_resize_buffers, - NBL_MESA_window_pos, - NBL_MESAX_texture_stack, - NBL_MESA_ycbcr_texture, - NBL_NV_blend_square, - NBL_NV_conditional_render, - NBL_NV_copy_depth_to_color, - NBL_NV_copy_image, - NBL_NV_depth_buffer_float, - NBL_NV_depth_clamp, - NBL_NV_evaluators, - NBL_NV_explicit_multisample, - NBL_NV_fence, - NBL_NV_float_buffer, - NBL_NV_fog_distance, - NBL_NV_fragment_program, - NBL_NV_fragment_program2, - NBL_NV_fragment_program4, - NBL_NV_fragment_program_option, - NBL_NV_fragment_shader_interlock, - NBL_NV_framebuffer_multisample_coverage, - NBL_NV_geometry_program4, - NBL_NV_geometry_shader4, - NBL_NV_gpu_program4, - NBL_NV_gpu_program5, - NBL_NV_gpu_shader5, - NBL_NV_half_float, - NBL_NV_light_max_exponent, - NBL_NV_multisample_coverage, - NBL_NV_multisample_filter_hint, - NBL_NV_occlusion_query, - NBL_NV_packed_depth_stencil, - NBL_NV_parameter_buffer_object, - NBL_NV_parameter_buffer_object2, - NBL_NV_pixel_data_range, - NBL_NV_point_sprite, - NBL_NV_present_video, - NBL_NV_primitive_restart, - NBL_NV_register_combiners, - NBL_NV_register_combiners2, - NBL_NV_shader_buffer_load, - NBL_NV_shader_buffer_store, - NBL_NV_shader_thread_group, - NBL_NV_shader_thread_shuffle, - NBL_NV_tessellation_program5, - NBL_NV_texgen_emboss, - NBL_NV_texgen_reflection, - NBL_NV_texture_barrier, - NBL_NV_texture_compression_vtc, - NBL_NV_texture_env_combine4, - NBL_NV_texture_expand_normal, - NBL_NV_texture_multisample, - NBL_NV_texture_rectangle, - NBL_NV_texture_shader, - NBL_NV_texture_shader2, - NBL_NV_texture_shader3, - NBL_NV_transform_feedback, - NBL_NV_transform_feedback2, - NBL_NV_vdpau_interop, - NBL_NV_vertex_array_range, - NBL_NV_vertex_array_range2, - NBL_NV_vertex_attrib_integer_64bit, - NBL_NV_vertex_buffer_unified_memory, - NBL_NV_vertex_program, - NBL_NV_vertex_program1_1, - NBL_NV_vertex_program2, - NBL_NV_vertex_program2_option, - NBL_NV_vertex_program3, - NBL_NV_vertex_program4, - NBL_NV_video_capture, - NBL_NV_viewport_array2, - NBL_NV_stereo_view_rendering, - NBL_NV_sample_mask_override_coverage, - NBL_NV_geometry_shader_passthrough, - NBL_NV_shader_subgroup_partitioned, - NBL_NV_compute_shader_derivatives, - NBL_NV_fragment_shader_barycentric, - NBL_NV_mesh_shader, - NBL_NV_shader_image_footprint, - NBL_NV_shading_rate_image, - NBL_NV_bindless_texture, - NBL_NV_shader_atomic_float, - NBL_NV_shader_atomic_int64, - NBL_NV_sample_locations, - NBL_NV_shader_atomic_fp16_vector, - NBL_NV_command_list, - NBL_NV_shader_atomic_float64, - NBL_NV_conservative_raster_pre_snap, - NBL_NV_shader_texture_footprint, - NBL_OES_read_format, - NBL_OML_interlace, - NBL_OML_resample, - NBL_OML_subsample, - NBL_OVR_multiview, - NBL_OVR_multiview2, - NBL_PGI_misc_hints, - NBL_PGI_vertex_hints, - NBL_REND_screen_coordinates, - NBL_S3_s3tc, - NBL_SGI_color_matrix, - NBL_SGI_color_table, - NBL_SGI_depth_pass_instrument, - NBL_SGIS_detail_texture, - NBL_SGIS_fog_function, - NBL_SGIS_generate_mipmap, - NBL_SGIS_multisample, - NBL_SGIS_pixel_texture, - NBL_SGIS_point_line_texgen, - NBL_SGIS_point_parameters, - NBL_SGIS_sharpen_texture, - NBL_SGIS_texture4D, - NBL_SGIS_texture_border_clamp, - NBL_SGIS_texture_color_mask, - NBL_SGIS_texture_edge_clamp, - NBL_SGIS_texture_filter4, - NBL_SGIS_texture_lod, - NBL_SGIS_texture_select, - NBL_SGI_texture_color_table, - NBL_SGIX_async, - NBL_SGIX_async_histogram, - NBL_SGIX_async_pixel, - NBL_SGIX_blend_alpha_minmax, - NBL_SGIX_calligraphic_fragment, - NBL_SGIX_clipmap, - NBL_SGIX_convolution_accuracy, - NBL_SGIX_depth_pass_instrument, - NBL_SGIX_depth_texture, - NBL_SGIX_flush_raster, - NBL_SGIX_fog_offset, - NBL_SGIX_fog_scale, - NBL_SGIX_fragment_lighting, - NBL_SGIX_framezoom, - NBL_SGIX_igloo_interface, - NBL_SGIX_impact_pixel_texture, - NBL_SGIX_instruments, - NBL_SGIX_interlace, - NBL_SGIX_ir_instrument1, - NBL_SGIX_list_priority, - NBL_SGIX_pixel_texture, - NBL_SGIX_pixel_tiles, - NBL_SGIX_polynomial_ffd, - NBL_SGIX_reference_plane, - NBL_SGIX_resample, - NBL_SGIX_scalebias_hint, - NBL_SGIX_shadow, - NBL_SGIX_shadow_ambient, - NBL_SGIX_sprite, - NBL_SGIX_subsample, - NBL_SGIX_tag_sample_buffer, - NBL_SGIX_texture_add_env, - NBL_SGIX_texture_coordinate_clamp, - NBL_SGIX_texture_lod_bias, - NBL_SGIX_texture_multi_buffer, - NBL_SGIX_texture_scale_bias, - NBL_SGIX_texture_select, - NBL_SGIX_vertex_preclip, - NBL_SGIX_ycrcb, - NBL_SGIX_ycrcba, - NBL_SGIX_ycrcb_subsample, - NBL_SUN_convolution_border_modes, - NBL_SUN_global_alpha, - NBL_SUN_mesh_array, - NBL_SUN_slice_accum, - NBL_SUN_triangle_list, - NBL_SUN_vertex, - NBL_SUNX_constant_data, - NBL_WIN_phong_shading, - NBL_WIN_specular_fog, - NBL_KHR_texture_compression_astc_hdr, - NBL_KHR_texture_compression_astc_ldr, - NBL_KHR_blend_equation_advanced, - NBL_KHR_blend_equation_advanced_coherent, - //NBL_GLX_EXT_swap_control_tear, - NBL_NVX_gpu_memory_info, - NBL_NVX_multiview_per_view_attributes, - NBL_OpenGL_Feature_Count - }; - _NBL_STATIC_INLINE_CONSTEXPR EOpenGLFeatures m_GLSLExtensions[]{ - NBL_AMD_gcn_shader, - NBL_AMD_gpu_shader_half_float_fetch, - NBL_AMD_shader_ballot, - NBL_AMD_shader_explicit_vertex_parameter, - NBL_AMD_shader_fragment_mask, - NBL_AMD_shader_image_load_store_lod, - NBL_AMD_shader_trinary_minmax, - NBL_AMD_texture_gather_bias_lod, - NBL_NVX_multiview_per_view_attributes, - NBL_NV_viewport_array2, - NBL_NV_stereo_view_rendering, - NBL_NV_sample_mask_override_coverage, - NBL_NV_geometry_shader_passthrough, - NBL_NV_shader_subgroup_partitioned, - NBL_NV_compute_shader_derivatives, - NBL_NV_fragment_shader_barycentric, - NBL_NV_mesh_shader, - NBL_NV_shader_image_footprint, - NBL_NV_shading_rate_image, - NBL_ARB_shading_language_include, - NBL_ARB_shader_stencil_export, - NBL_ARB_enhanced_layouts, - NBL_ARB_bindless_texture, - NBL_ARB_shader_draw_parameters, - NBL_ARB_shader_group_vote, - NBL_ARB_cull_distance, - NBL_ARB_derivative_control, - NBL_ARB_shader_texture_image_samples, - NBL_KHR_blend_equation_advanced, - NBL_KHR_blend_equation_advanced_coherent, - NBL_ARB_fragment_shader_interlock, - NBL_ARB_gpu_shader_int64, - NBL_ARB_post_depth_coverage, - NBL_ARB_shader_ballot, - NBL_ARB_shader_clock, - NBL_ARB_shader_viewport_layer_array, - NBL_ARB_sparse_texture2, - NBL_ARB_sparse_texture_clamp, - NBL_ARB_gl_spirv, - NBL_ARB_spirv_extensions, - NBL_AMD_shader_stencil_export, - NBL_AMD_vertex_shader_viewport_index, - NBL_AMD_vertex_shader_layer, - NBL_NV_bindless_texture, - NBL_NV_shader_atomic_float, - NBL_AMD_sparse_texture, - NBL_EXT_shader_integer_mix, - NBL_INTEL_fragment_shader_ordering, - NBL_AMD_shader_stencil_value_export, - NBL_NV_shader_thread_group, - NBL_NV_shader_thread_shuffle, - NBL_EXT_shader_image_load_formatted, - NBL_AMD_gpu_shader_int64, - NBL_NV_shader_atomic_int64, - NBL_EXT_post_depth_coverage, - NBL_EXT_sparse_texture2, - NBL_NV_fragment_shader_interlock, - NBL_NV_sample_locations, - NBL_NV_shader_atomic_fp16_vector, - NBL_NV_command_list, - NBL_OVR_multiview, - NBL_OVR_multiview2, - NBL_NV_shader_atomic_float64, - NBL_INTEL_conservative_rasterization, - NBL_NV_conservative_raster_pre_snap, - NBL_EXT_shader_framebuffer_fetch, - NBL_EXT_shader_framebuffer_fetch_non_coherent, - NBL_INTEL_blackhole_render, - NBL_NV_shader_texture_footprint, - NBL_NV_gpu_shader5 - }; - - static core::CLeakDebugger bufferLeaker; - static core::CLeakDebugger textureLeaker; // deferred initialization void initExtensions(bool stencilBuffer); @@ -1245,257 +125,6 @@ class COpenGLExtensionHandler static bool IsIntelGPU; static bool needsDSAFramebufferHack; - // - static bool extGlIsEnabledi(GLenum cap, GLuint index); - static void extGlEnablei(GLenum cap, GLuint index); - static void extGlDisablei(GLenum cap, GLuint index); - static void extGlGetBooleani_v(GLenum pname, GLuint index, GLboolean* data); - static void extGlGetFloati_v(GLenum pname, GLuint index, float* data); - static void extGlGetInteger64v(GLenum pname, GLint64* data); - static void extGlGetIntegeri_v(GLenum pname, GLuint index, GLint* data); - static void extGlProvokingVertex(GLenum provokeMode); - static void extGlClipControl(GLenum origin, GLenum depth); - - // - static GLsync extGlFenceSync(GLenum condition, GLbitfield flags); - static void extGlDeleteSync(GLsync sync); - static GLenum extGlClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout); - static void extGlWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout); - - // the above function definitions can stay, the rest towards the bottom are up for review - // public access to the (loaded) extensions. - static void extGlActiveTexture(GLenum target); - static void extGlBindTextures(const GLuint& first, const GLsizei& count, const GLuint* textures, const GLenum* targets); - static void extGlCreateTextures(GLenum target, GLsizei n, GLuint *textures); - - - static void extGlTextureBuffer(GLuint texture, GLenum internalformat, GLuint buffer); - static void extGlTextureBufferRange(GLuint texture, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizei length); - static void extGlTextureStorage1D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width); - static void extGlTextureStorage2D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); - static void extGlTextureStorage3D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); - //multisample textures - static void extGlTextureStorage2DMultisample(GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations); - static void extGlTextureStorage3DMultisample(GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations); - // views - static void extGlTextureView(GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers); - // texture update functions - static void extGlGetTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLsizei bufSize, void* pixels); - static void extGlGetCompressedTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei bufSize, void* pixels); - static void extGlGetTextureImage(GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSizeHint, void* pixels); - static void extGlGetCompressedTextureImage(GLuint texture, GLenum target, GLint level, GLsizei bufSizeHint, void* pixels); - static void extGlTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels); - static void extGlTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels); - static void extGlTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels); - static void extGlCompressedTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data); - static void extGlCompressedTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); - static void extGlCompressedTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); - static void extGlCopyImageSubData(GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); - static void extGlGenerateTextureMipmap(GLuint texture, GLenum target); - // texture "parameter" functions - static void extGlTextureParameterIuiv(GLuint texture, GLenum target, GLenum pname, const GLuint* params); - static void extGlClampColor(GLenum target, GLenum clamp); - - static void extGlCreateSamplers(GLsizei n, GLuint* samplers); - static void extGlDeleteSamplers(GLsizei n, GLuint* samplers); - static void extGlBindSamplers(const GLuint& first, const GLsizei& count, const GLuint* samplers); - static void extGlSamplerParameteri(GLuint sampler, GLenum pname, GLint param); - static void extGlSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param); - static void extGlSamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* params); - - // - static void extGlBindImageTexture(GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format); - static void extGlBindImageTextures(GLuint first, GLsizei count, const GLuint* textures, const GLenum* formats); - - //bindless textures - static GLuint64 extGlGetTextureHandle(GLuint texture); - static GLuint64 extGlGetTextureSamplerHandle(GLuint texture, GLuint sampler); - static void extGlMakeTextureHandleResident(GLuint64 handle); - static void extGlMakeTextureHandleNonResident(GLuint64 handle); - static GLuint64 extGlGetImageHandle(GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum format); - static void extGlMakeImageHandleResident(GLuint64 handle, GLenum access); - static void extGlMakeImageHandleNonResident(GLuint64 handle); - GLboolean extGlIsTextureHandleResident(GLuint64 handle); - GLboolean extGlIsImageHandleResident(GLuint64 handle); - - static void extGlPointParameterf(GLint loc, GLfloat f); - static void extGlPointParameterfv(GLint loc, const GLfloat *v); - static void extGlStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask); - static void extGlStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass); - static void extGlStencilMaskSeparate(GLenum face, GLuint mask); - - - // shader programming - static void extGlCreateProgramPipelines(GLsizei n, GLuint* pipelines); - static void extGlDeleteProgramPipelines(GLsizei n, const GLuint* pipelines); - static void extGlUseProgramStages(GLuint pipeline, GLbitfield stages, GLuint program); - static GLuint extGlCreateShader(GLenum shaderType); - static GLuint extGlCreateShaderProgramv(GLenum shaderType, GLsizei count, const char** strings); - static void extGlShaderSource(GLuint shader, GLsizei numOfStrings, const char **strings, const GLint *lenOfStrings); - static void extGlCompileShader(GLuint shader); - static GLuint extGlCreateProgram(void); - static void extGlAttachShader(GLuint program, GLuint shader); - static void extGlTransformFeedbackVaryings(GLuint program, GLsizei count, const char** varyings, GLenum bufferMode); - static void extGlLinkProgram(GLuint program); - static void extGlUseProgram(GLuint prog); - static void extGlDeleteProgram(GLuint object); - static void extGlDeleteShader(GLuint shader); - static void extGlGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders); - static void extGlGetShaderInfoLog(GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog); - static void extGlGetProgramInfoLog(GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infoLog); - static void extGlGetShaderiv(GLuint shader, GLenum type, GLint *param); - static void extGlGetProgramiv(GLuint program, GLenum type, GLint *param); - static GLint extGlGetUniformLocation(GLuint program, const char *name); - static void extGlProgramUniform1fv(GLuint program, GLint loc, GLsizei count, const GLfloat *v); - static void extGlProgramUniform2fv(GLuint program, GLint loc, GLsizei count, const GLfloat *v); - static void extGlProgramUniform3fv(GLuint program, GLint loc, GLsizei count, const GLfloat *v); - static void extGlProgramUniform4fv(GLuint program, GLint loc, GLsizei count, const GLfloat *v); - static void extGlProgramUniform1iv(GLuint program, GLint loc, GLsizei count, const GLint *v); - static void extGlProgramUniform2iv(GLuint program, GLint loc, GLsizei count, const GLint *v); - static void extGlProgramUniform3iv(GLuint program, GLint loc, GLsizei count, const GLint *v); - static void extGlProgramUniform4iv(GLuint program, GLint loc, GLsizei count, const GLint *v); - static void extGlProgramUniform1uiv(GLuint program, GLint loc, GLsizei count, const GLuint *v); - static void extGlProgramUniform2uiv(GLuint program, GLint loc, GLsizei count, const GLuint *v); - static void extGlProgramUniform3uiv(GLuint program, GLint loc, GLsizei count, const GLuint *v); - static void extGlProgramUniform4uiv(GLuint program, GLint loc, GLsizei count, const GLuint *v); - static void extGlProgramUniformMatrix2fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlProgramUniformMatrix3fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlProgramUniformMatrix4fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlProgramUniformMatrix2x3fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlProgramUniformMatrix2x4fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlProgramUniformMatrix3x2fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlProgramUniformMatrix3x4fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlProgramUniformMatrix4x2fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlProgramUniformMatrix4x3fv(GLuint program, GLint loc, GLsizei count, GLboolean transpose, const GLfloat *v); - static void extGlGetActiveUniform(GLuint program, GLuint index, GLsizei maxlength, GLsizei *length, GLint *size, GLenum *type, GLchar *name); - static void extGlBindProgramPipeline(GLuint pipeline); - static void extGlGetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, void* binary); - static void extGlProgramBinary(GLuint program, GLenum binaryFormat, const void* binary, GLsizei length); - - //compute - static void extGlMemoryBarrier(GLbitfield barriers); - static void extGlDispatchCompute(GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z); - static void extGlDispatchComputeIndirect(GLintptr indirect); - - // framebuffer objects - static void extGlDeleteFramebuffers(GLsizei n, const GLuint *framebuffers); - static void extGlCreateFramebuffers(GLsizei n, GLuint *framebuffers); - static void extGlBindFramebuffer(GLenum target, GLuint framebuffer); - static GLenum extGlCheckNamedFramebufferStatus(GLuint framebuffer, GLenum target); - static void extGlNamedFramebufferTexture(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level); - static void extGlNamedFramebufferTextureLayer(GLuint framebuffer, GLenum attachment, GLuint texture, GLenum textureType, GLint level, GLint layer); - static void extGlBlitNamedFramebuffer(GLuint readFramebuffer, GLuint drawFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); - static void extGlNamedFramebufferReadBuffer(GLuint framebuffer, GLenum mode); - static void extGlNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs); - static void extGlNamedFramebufferDrawBuffer(GLuint framebuffer, GLenum buf); - static void extGlClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint* value); - static void extGlClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint* value); - static void extGlClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat* value); - static void extGlClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); - - static void extGlActiveStencilFace(GLenum face); - - // vertex buffer object - static void extGlCreateBuffers(GLsizei n, GLuint *buffers); - static void extGlBindBuffer(const GLenum& target, const GLuint& buffer); - static void extGlBindBuffersBase(const GLenum& target, const GLuint& first, const GLsizei& count, const GLuint* buffers); - static void extGlBindBuffersRange(const GLenum& target, const GLuint& first, const GLsizei& count, const GLuint* buffers, const GLintptr* offsets, const GLsizeiptr* sizes); - static void extGlDeleteBuffers(GLsizei n, const GLuint *buffers); - static void extGlNamedBufferStorage(GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags); - static void extGlNamedBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data); - static void extGlGetNamedBufferSubData (GLuint buffer, GLintptr offset, GLsizeiptr size, void *data); - static void* extGlMapNamedBuffer(GLuint buffer, GLbitfield access); - static void* extGlMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access); - static void extGlFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length); - static GLboolean extGlUnmapNamedBuffer(GLuint buffer); - static void extGlClearNamedBufferData(GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data); - static void extGlClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data); - static void extGlCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); - static GLboolean extGlIsBuffer (GLuint buffer); - static void extGlGetNamedBufferParameteriv(const GLuint& buffer, const GLenum& value, GLint* data); - static void extGlGetNamedBufferParameteri64v(const GLuint& buffer, const GLenum& value, GLint64* data); - - //vao - static void extGlCreateVertexArrays(GLsizei n, GLuint *arrays); - static void extGlDeleteVertexArrays(GLsizei n, GLuint *arrays); - static void extGlBindVertexArray(GLuint vaobj); - static void extGlVertexArrayElementBuffer(GLuint vaobj, GLuint buffer); - static void extGlVertexArrayVertexBuffer(GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride); - static void extGlVertexArrayAttribBinding(GLuint vaobj, GLuint attribindex, GLuint bindingindex); - static void extGlEnableVertexArrayAttrib(GLuint vaobj, GLuint index); - static void extGlDisableVertexArrayAttrib(GLuint vaobj, GLuint index); - static void extGlVertexArrayAttribFormat(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset); - static void extGlVertexArrayAttribIFormat(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); - static void extGlVertexArrayAttribLFormat(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLuint relativeoffset); - static void extGlVertexArrayBindingDivisor(GLuint vaobj, GLuint bindingindex, GLuint divisor); - - //transform feedback - static void extGlCreateTransformFeedbacks(GLsizei n, GLuint* ids); - static void extGlDeleteTransformFeedbacks(GLsizei n, const GLuint* ids); - static void extGlBindTransformFeedback(GLenum target, GLuint id); - static void extGlBeginTransformFeedback(GLenum primitiveMode); - static void extGlPauseTransformFeedback(); - static void extGlResumeTransformFeedback(); - static void extGlEndTransformFeedback(); - static void extGlTransformFeedbackBufferBase(GLuint xfb, GLuint index, GLuint buffer); - static void extGlTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); - - - //draw - static void extGlPrimitiveRestartIndex(GLuint index); - static void extGlDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instancecount); - static void extGlDrawArraysInstancedBaseInstance(GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance); - static void extGlDrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex); - static void extGlDrawElementsInstancedBaseVertexBaseInstance(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance); - static void extGlDrawTransformFeedback(GLenum mode, GLuint id); - static void extGlDrawTransformFeedbackInstanced(GLenum mode, GLuint id, GLsizei instancecount); - static void extGlDrawTransformFeedbackStream(GLenum mode, GLuint id, GLuint stream); - static void extGlDrawTransformFeedbackStreamInstanced(GLenum mode, GLuint id, GLuint stream, GLsizei instancecount); - static void extGlDrawArraysIndirect(GLenum mode, const void* indirect); - static void extGlDrawElementsIndirect(GLenum mode, GLenum type, const void *indirect); - static void extGlMultiDrawArraysIndirect(GLenum mode, const void* indirect, GLsizei drawcount, GLsizei stride); - static void extGlMultiDrawElementsIndirect(GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); - static void extGlMultiDrawArraysIndirectCount(GLenum mode, const void *indirect, GLintptr drawcount, GLintptr maxdrawcount, GLsizei stride); - static void extGlMultiDrawElementsIndirectCount(GLenum mode, GLenum type, const void *indirect, GLintptr drawcount, GLintptr maxdrawcount, GLsizei stride); - - // ROP - static void extGlBlendColor(float red, float green, float blue, float alpha); - static void extGlDepthRangeIndexed(GLuint index, GLdouble nearVal, GLdouble farVal); - static void extGlViewportIndexedfv(GLuint index, const GLfloat* v); - static void extGlScissorIndexedv(GLuint index, const GLint* v); - static void extGlSampleCoverage(float value, bool invert); - static void extGlSampleMaski(GLuint maskNumber, GLbitfield mask); - static void extGlMinSampleShading(float value); - static void extGlBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha); - static void extGlBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); - static void extGlColorMaski(GLuint buf, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha); - - // - static void extGlBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); - static void extGlColorMaskIndexed(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a); - static void extGlEnableIndexed(GLenum target, GLuint index); - static void extGlDisableIndexed(GLenum target, GLuint index); - static void extGlBlendFuncIndexed(GLuint buf, GLenum src, GLenum dst); - static void extGlBlendEquationIndexed(GLuint buf, GLenum mode); - static void extGlProgramParameteri(GLuint program, GLenum pname, GLint value); - static void extGlPatchParameterfv(GLenum pname, const float* values); - static void extGlPatchParameteri(GLenum pname, GLuint value); - - // queries - static void extGlCreateQueries(GLenum target, GLsizei n, GLuint *ids); - static void extGlDeleteQueries(GLsizei n, const GLuint *ids); - static GLboolean extGlIsQuery(GLuint id); - static void extGlBeginQuery(GLenum target, GLuint id); - static void extGlEndQuery(GLenum target); - static void extGlBeginQueryIndexed(GLenum target, GLuint index, GLuint id); - static void extGlEndQueryIndexed(GLenum target, GLuint index); - static void extGlGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params); - static void extGlGetQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params); - static void extGlGetQueryBufferObjectuiv(GLuint id, GLuint buffer, GLenum pname, GLintptr offset); - static void extGlGetQueryBufferObjectui64v(GLuint id, GLuint buffer, GLenum pname, GLintptr offset); - static void extGlQueryCounter(GLuint id, GLenum target); - static void extGlBeginConditionalRender(GLuint id, GLenum mode); - static void extGlEndConditionalRender(); // static void extGlTextureBarrier(); @@ -1503,386 +132,12 @@ class COpenGLExtensionHandler // generic vsync setting method for several extensions static void extGlSwapInterval(int interval); - // blend operations - static void extGlBlendEquation(GLenum mode); - - // ARB_internalformat_query - static void extGlGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params); - static void extGlGetInternalformati64v(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64* params); - // the global feature array static bool FeatureAvailable[NBL_OpenGL_Feature_Count]; - - // - static PFNGLISENABLEDIPROC pGlIsEnabledi; - static PFNGLENABLEIPROC pGlEnablei; - static PFNGLDISABLEIPROC pGlDisablei; - static PFNGLGETBOOLEANI_VPROC pGlGetBooleani_v; - static PFNGLGETFLOATI_VPROC pGlGetFloati_v; - static PFNGLGETINTEGER64VPROC pGlGetInteger64v; - static PFNGLGETINTEGERI_VPROC pGlGetIntegeri_v; - static PFNGLGETSTRINGIPROC pGlGetStringi; - static PFNGLPROVOKINGVERTEXPROC pGlProvokingVertex; - static PFNGLCLIPCONTROLPROC pGlClipControl; - - //fences - static PFNGLFENCESYNCPROC pGlFenceSync; - static PFNGLDELETESYNCPROC pGlDeleteSync; - static PFNGLCLIENTWAITSYNCPROC pGlClientWaitSync; - static PFNGLWAITSYNCPROC pGlWaitSync; - - //textures - static PFNGLACTIVETEXTUREPROC pGlActiveTexture; - static PFNGLBINDTEXTURESPROC pGlBindTextures; //NULL - static PFNGLCREATETEXTURESPROC pGlCreateTextures; //NULL - static PFNGLTEXSTORAGE1DPROC pGlTexStorage1D; - static PFNGLTEXSTORAGE2DPROC pGlTexStorage2D; - static PFNGLTEXSTORAGE3DPROC pGlTexStorage3D; - static PFNGLTEXSTORAGE2DMULTISAMPLEPROC pGlTexStorage2DMultisample; - static PFNGLTEXSTORAGE3DMULTISAMPLEPROC pGlTexStorage3DMultisample; - static PFNGLTEXBUFFERPROC pGlTexBuffer; - static PFNGLTEXBUFFERRANGEPROC pGlTexBufferRange; - static PFNGLTEXTURESTORAGE1DPROC pGlTextureStorage1D; //NULL - static PFNGLTEXTURESTORAGE2DPROC pGlTextureStorage2D; //NULL - static PFNGLTEXTURESTORAGE3DPROC pGlTextureStorage3D; //NULL - static PFNGLTEXTURESTORAGE2DMULTISAMPLEPROC pGlTextureStorage2DMultisample; - static PFNGLTEXTURESTORAGE3DMULTISAMPLEPROC pGlTextureStorage3DMultisample; - static PFNGLTEXTUREVIEWPROC pGlTextureView; - static PFNGLTEXTUREBUFFERPROC pGlTextureBuffer; //NULL - static PFNGLTEXTUREBUFFERRANGEPROC pGlTextureBufferRange; //NULL - static PFNGLTEXTURESTORAGE1DEXTPROC pGlTextureStorage1DEXT; - static PFNGLTEXTURESTORAGE2DEXTPROC pGlTextureStorage2DEXT; - static PFNGLTEXTURESTORAGE3DEXTPROC pGlTextureStorage3DEXT; - static PFNGLTEXTUREBUFFEREXTPROC pGlTextureBufferEXT; - static PFNGLTEXTUREBUFFERRANGEEXTPROC pGlTextureBufferRangeEXT; - static PFNGLTEXTURESTORAGE2DMULTISAMPLEEXTPROC pGlTextureStorage2DMultisampleEXT; - static PFNGLTEXTURESTORAGE3DMULTISAMPLEEXTPROC pGlTextureStorage3DMultisampleEXT; - static PFNGLGETTEXTURESUBIMAGEPROC pGlGetTextureSubImage; - static PFNGLGETCOMPRESSEDTEXTURESUBIMAGEPROC pGlGetCompressedTextureSubImage; - static PFNGLGETTEXTUREIMAGEPROC pGlGetTextureImage; - static PFNGLGETTEXTUREIMAGEEXTPROC pGlGetTextureImageEXT; - static PFNGLGETCOMPRESSEDTEXTUREIMAGEPROC pGlGetCompressedTextureImage; - static PFNGLGETCOMPRESSEDTEXTUREIMAGEEXTPROC pGlGetCompressedTextureImageEXT; - static PFNGLGETCOMPRESSEDTEXIMAGEPROC pGlGetCompressedTexImage; - static PFNGLTEXSUBIMAGE3DPROC pGlTexSubImage3D; - static PFNGLMULTITEXSUBIMAGE1DEXTPROC pGlMultiTexSubImage1DEXT; - static PFNGLMULTITEXSUBIMAGE2DEXTPROC pGlMultiTexSubImage2DEXT; - static PFNGLMULTITEXSUBIMAGE3DEXTPROC pGlMultiTexSubImage3DEXT; - static PFNGLTEXTURESUBIMAGE1DPROC pGlTextureSubImage1D; //NULL - static PFNGLTEXTURESUBIMAGE2DPROC pGlTextureSubImage2D; //NULL - static PFNGLTEXTURESUBIMAGE3DPROC pGlTextureSubImage3D; //NULL - static PFNGLTEXTURESUBIMAGE1DEXTPROC pGlTextureSubImage1DEXT; - static PFNGLTEXTURESUBIMAGE2DEXTPROC pGlTextureSubImage2DEXT; - static PFNGLTEXTURESUBIMAGE3DEXTPROC pGlTextureSubImage3DEXT; - static PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC pGlCompressedTexSubImage1D; - static PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC pGlCompressedTexSubImage2D; - static PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC pGlCompressedTexSubImage3D; - static PFNGLCOMPRESSEDTEXTURESUBIMAGE1DPROC pGlCompressedTextureSubImage1D; //NULL - static PFNGLCOMPRESSEDTEXTURESUBIMAGE2DPROC pGlCompressedTextureSubImage2D; //NULL - static PFNGLCOMPRESSEDTEXTURESUBIMAGE3DPROC pGlCompressedTextureSubImage3D; //NULL - static PFNGLCOMPRESSEDTEXTURESUBIMAGE1DEXTPROC pGlCompressedTextureSubImage1DEXT; - static PFNGLCOMPRESSEDTEXTURESUBIMAGE2DEXTPROC pGlCompressedTextureSubImage2DEXT; - static PFNGLCOMPRESSEDTEXTURESUBIMAGE3DEXTPROC pGlCompressedTextureSubImage3DEXT; - static PFNGLCOPYIMAGESUBDATAPROC pGlCopyImageSubData; - static PFNGLTEXTUREPARAMETERIUIVPROC pGlTextureParameterIuiv; - static PFNGLTEXTUREPARAMETERIUIVEXTPROC pGlTextureParameterIuivEXT; - static PFNGLTEXPARAMETERIUIVPROC pGlTexParameterIuiv; - static PFNGLGENERATEMIPMAPPROC pGlGenerateMipmap; - static PFNGLGENERATETEXTUREMIPMAPPROC pGlGenerateTextureMipmap; //NULL - static PFNGLGENERATETEXTUREMIPMAPEXTPROC pGlGenerateTextureMipmapEXT; - static PFNGLCLAMPCOLORPROC pGlClampColor; - - //samplers - static PFNGLGENSAMPLERSPROC pGlGenSamplers; - static PFNGLCREATESAMPLERSPROC pGlCreateSamplers; - static PFNGLDELETESAMPLERSPROC pGlDeleteSamplers; - static PFNGLBINDSAMPLERPROC pGlBindSampler; - static PFNGLBINDSAMPLERSPROC pGlBindSamplers; - static PFNGLSAMPLERPARAMETERIPROC pGlSamplerParameteri; - static PFNGLSAMPLERPARAMETERFPROC pGlSamplerParameterf; - static PFNGLSAMPLERPARAMETERFVPROC pGlSamplerParameterfv; - - // - static PFNGLBINDIMAGETEXTUREPROC pGlBindImageTexture; - static PFNGLBINDIMAGETEXTURESPROC pGlBindImageTextures; - - //bindless textures - //ARB - static PFNGLGETTEXTUREHANDLEARBPROC pGlGetTextureHandleARB; - static PFNGLGETTEXTURESAMPLERHANDLEARBPROC pGlGetTextureSamplerHandleARB; - static PFNGLMAKETEXTUREHANDLERESIDENTARBPROC pGlMakeTextureHandleResidentARB; - static PFNGLMAKETEXTUREHANDLENONRESIDENTARBPROC pGlMakeTextureHandleNonResidentARB; - static PFNGLGETIMAGEHANDLEARBPROC pGlGetImageHandleARB; - static PFNGLMAKEIMAGEHANDLERESIDENTARBPROC pGlMakeImageHandleResidentARB; - static PFNGLMAKEIMAGEHANDLENONRESIDENTARBPROC pGlMakeImageHandleNonResidentARB; - static PFNGLISTEXTUREHANDLERESIDENTARBPROC pGlIsTextureHandleResidentARB; - static PFNGLISIMAGEHANDLERESIDENTARBPROC pGlIsImageHandleResidentARB; - //NV - static PFNGLGETTEXTUREHANDLENVPROC pGlGetTextureHandleNV; - static PFNGLGETTEXTURESAMPLERHANDLENVPROC pGlGetTextureSamplerHandleNV; - static PFNGLMAKETEXTUREHANDLERESIDENTNVPROC pGlMakeTextureHandleResidentNV; - static PFNGLMAKETEXTUREHANDLENONRESIDENTNVPROC pGlMakeTextureHandleNonResidentNV; - static PFNGLGETIMAGEHANDLENVPROC pGlGetImageHandleNV; - static PFNGLMAKEIMAGEHANDLERESIDENTNVPROC pGlMakeImageHandleResidentNV; - static PFNGLMAKEIMAGEHANDLENONRESIDENTNVPROC pGlMakeImageHandleNonResidentNV; - static PFNGLISTEXTUREHANDLERESIDENTNVPROC pGlIsTextureHandleResidentNV; - static PFNGLISIMAGEHANDLERESIDENTNVPROC pGlIsImageHandleResidentNV; - - // stuff - static PFNGLBINDBUFFERBASEPROC pGlBindBufferBase; - static PFNGLBINDBUFFERRANGEPROC pGlBindBufferRange; - static PFNGLBINDBUFFERSBASEPROC pGlBindBuffersBase; - static PFNGLBINDBUFFERSRANGEPROC pGlBindBuffersRange; - - //shaders - static PFNGLCREATEPROGRAMPIPELINESPROC pGlCreateProgramPipelines; - static PFNGLDELETEPROGRAMPIPELINESPROC pGlDeleteProgramPipelines; - static PFNGLUSEPROGRAMSTAGESPROC pGlUseProgramStages; - static PFNGLBINDATTRIBLOCATIONPROC pGlBindAttribLocation; //NULL - static PFNGLCREATEPROGRAMPROC pGlCreateProgram; - static PFNGLUSEPROGRAMPROC pGlUseProgram; - static PFNGLDELETEPROGRAMPROC pGlDeleteProgram; - static PFNGLDELETESHADERPROC pGlDeleteShader; - static PFNGLGETATTACHEDSHADERSPROC pGlGetAttachedShaders; - static PFNGLCREATESHADERPROC pGlCreateShader; - static PFNGLCREATESHADERPROGRAMVPROC pGlCreateShaderProgramv; - static PFNGLSHADERSOURCEPROC pGlShaderSource; - static PFNGLCOMPILESHADERPROC pGlCompileShader; - static PFNGLATTACHSHADERPROC pGlAttachShader; - static PFNGLTRANSFORMFEEDBACKVARYINGSPROC pGlTransformFeedbackVaryings; - static PFNGLLINKPROGRAMPROC pGlLinkProgram; - static PFNGLGETSHADERINFOLOGPROC pGlGetShaderInfoLog; - static PFNGLGETPROGRAMINFOLOGPROC pGlGetProgramInfoLog; - static PFNGLGETSHADERIVPROC pGlGetShaderiv; - static PFNGLGETSHADERIVPROC pGlGetProgramiv; - static PFNGLGETUNIFORMLOCATIONPROC pGlGetUniformLocation; - static PFNGLPROGRAMUNIFORM1FVPROC pGlProgramUniform1fv; - static PFNGLPROGRAMUNIFORM2FVPROC pGlProgramUniform2fv; - static PFNGLPROGRAMUNIFORM3FVPROC pGlProgramUniform3fv; - static PFNGLPROGRAMUNIFORM4FVPROC pGlProgramUniform4fv; - static PFNGLPROGRAMUNIFORM1IVPROC pGlProgramUniform1iv; - static PFNGLPROGRAMUNIFORM2IVPROC pGlProgramUniform2iv; - static PFNGLPROGRAMUNIFORM3IVPROC pGlProgramUniform3iv; - static PFNGLPROGRAMUNIFORM4IVPROC pGlProgramUniform4iv; - static PFNGLPROGRAMUNIFORM1UIVPROC pGlProgramUniform1uiv; - static PFNGLPROGRAMUNIFORM2UIVPROC pGlProgramUniform2uiv; - static PFNGLPROGRAMUNIFORM3UIVPROC pGlProgramUniform3uiv; - static PFNGLPROGRAMUNIFORM4UIVPROC pGlProgramUniform4uiv; - static PFNGLPROGRAMUNIFORMMATRIX2FVPROC pGlProgramUniformMatrix2fv; - static PFNGLPROGRAMUNIFORMMATRIX3FVPROC pGlProgramUniformMatrix3fv; - static PFNGLPROGRAMUNIFORMMATRIX4FVPROC pGlProgramUniformMatrix4fv; - static PFNGLPROGRAMUNIFORMMATRIX2X3FVPROC pGlProgramUniformMatrix2x3fv; - static PFNGLPROGRAMUNIFORMMATRIX2X4FVPROC pGlProgramUniformMatrix2x4fv; - static PFNGLPROGRAMUNIFORMMATRIX3X2FVPROC pGlProgramUniformMatrix3x2fv; - static PFNGLPROGRAMUNIFORMMATRIX3X4FVPROC pGlProgramUniformMatrix3x4fv; - static PFNGLPROGRAMUNIFORMMATRIX4X2FVPROC pGlProgramUniformMatrix4x2fv; - static PFNGLPROGRAMUNIFORMMATRIX4X3FVPROC pGlProgramUniformMatrix4x3fv; - static PFNGLGETACTIVEUNIFORMPROC pGlGetActiveUniform; - static PFNGLPOINTPARAMETERFPROC pGlPointParameterf; - static PFNGLPOINTPARAMETERFVPROC pGlPointParameterfv; - static PFNGLBINDPROGRAMPIPELINEPROC pGlBindProgramPipeline; - static PFNGLGETPROGRAMBINARYPROC pGlGetProgramBinary; - static PFNGLPROGRAMBINARYPROC pGlProgramBinary; - - // Compute - static PFNGLMEMORYBARRIERPROC pGlMemoryBarrier; - static PFNGLDISPATCHCOMPUTEPROC pGlDispatchCompute; - static PFNGLDISPATCHCOMPUTEINDIRECTPROC pGlDispatchComputeIndirect; - - //ROP - static PFNGLBLENDCOLORPROC pGlBlendColor; - static PFNGLDEPTHRANGEINDEXEDPROC pGlDepthRangeIndexed; - static PFNGLVIEWPORTINDEXEDFVPROC pGlViewportIndexedfv; - static PFNGLSCISSORINDEXEDVPROC pGlScissorIndexedv; - static PFNGLSAMPLECOVERAGEPROC pGlSampleCoverage; - static PFNGLSAMPLEMASKIPROC pGlSampleMaski; - static PFNGLMINSAMPLESHADINGPROC pGlMinSampleShading; - static PFNGLBLENDEQUATIONSEPARATEIPROC pGlBlendEquationSeparatei; - static PFNGLBLENDFUNCSEPARATEIPROC pGlBlendFuncSeparatei; - static PFNGLCOLORMASKIPROC pGlColorMaski; - static PFNGLSTENCILFUNCSEPARATEPROC pGlStencilFuncSeparate; - static PFNGLSTENCILOPSEPARATEPROC pGlStencilOpSeparate; - static PFNGLSTENCILMASKSEPARATEPROC pGlStencilMaskSeparate; - - // ARB framebuffer object - static PFNGLBLITNAMEDFRAMEBUFFERPROC pGlBlitNamedFramebuffer; //NULL - static PFNGLBLITFRAMEBUFFERPROC pGlBlitFramebuffer; - static PFNGLDELETEFRAMEBUFFERSPROC pGlDeleteFramebuffers; - static PFNGLCREATEFRAMEBUFFERSPROC pGlCreateFramebuffers; //NULL - static PFNGLBINDFRAMEBUFFERPROC pGlBindFramebuffer; - static PFNGLGENFRAMEBUFFERSPROC pGlGenFramebuffers; - static PFNGLCHECKFRAMEBUFFERSTATUSPROC pGlCheckFramebufferStatus; - static PFNGLCHECKNAMEDFRAMEBUFFERSTATUSPROC pGlCheckNamedFramebufferStatus; //NULL - static PFNGLCHECKNAMEDFRAMEBUFFERSTATUSEXTPROC pGlCheckNamedFramebufferStatusEXT; - static PFNGLFRAMEBUFFERTEXTUREPROC pGlFramebufferTexture; - static PFNGLNAMEDFRAMEBUFFERTEXTUREPROC pGlNamedFramebufferTexture; //NULL - static PFNGLNAMEDFRAMEBUFFERTEXTUREEXTPROC pGlNamedFramebufferTextureEXT; - static PFNGLFRAMEBUFFERTEXTURELAYERPROC pGlFramebufferTextureLayer; - static PFNGLNAMEDFRAMEBUFFERTEXTURELAYERPROC pGlNamedFramebufferTextureLayer; //NULL - static PFNGLNAMEDFRAMEBUFFERTEXTURELAYEREXTPROC pGlNamedFramebufferTextureLayerEXT; - static PFNGLFRAMEBUFFERTEXTURE2DPROC pGlFramebufferTexture2D; - static PFNGLNAMEDFRAMEBUFFERTEXTURE2DEXTPROC pGlNamedFramebufferTexture2DEXT; - - //! REMOVE ALL BELOW - // EXT framebuffer object - static PFNGLACTIVESTENCILFACEEXTPROC pGlActiveStencilFaceEXT; //NULL - static PFNGLNAMEDFRAMEBUFFERREADBUFFERPROC pGlNamedFramebufferReadBuffer; //NULL - static PFNGLFRAMEBUFFERREADBUFFEREXTPROC pGlFramebufferReadBufferEXT; - static PFNGLNAMEDFRAMEBUFFERDRAWBUFFERPROC pGlNamedFramebufferDrawBuffer; //NULL - static PFNGLFRAMEBUFFERDRAWBUFFEREXTPROC pGlFramebufferDrawBufferEXT; - static PFNGLDRAWBUFFERSPROC pGlDrawBuffers; - static PFNGLNAMEDFRAMEBUFFERDRAWBUFFERSPROC pGlNamedFramebufferDrawBuffers; //NULL - static PFNGLFRAMEBUFFERDRAWBUFFERSEXTPROC pGlFramebufferDrawBuffersEXT; - static PFNGLCLEARNAMEDFRAMEBUFFERIVPROC pGlClearNamedFramebufferiv; //NULL - static PFNGLCLEARNAMEDFRAMEBUFFERUIVPROC pGlClearNamedFramebufferuiv; //NULL - static PFNGLCLEARNAMEDFRAMEBUFFERFVPROC pGlClearNamedFramebufferfv; //NULL - static PFNGLCLEARNAMEDFRAMEBUFFERFIPROC pGlClearNamedFramebufferfi; //NULL - static PFNGLCLEARBUFFERIVPROC pGlClearBufferiv; - static PFNGLCLEARBUFFERUIVPROC pGlClearBufferuiv; - static PFNGLCLEARBUFFERFVPROC pGlClearBufferfv; - static PFNGLCLEARBUFFERFIPROC pGlClearBufferfi; - // - static PFNGLGENBUFFERSPROC pGlGenBuffers; - static PFNGLCREATEBUFFERSPROC pGlCreateBuffers; //NULL - static PFNGLBINDBUFFERPROC pGlBindBuffer; - static PFNGLDELETEBUFFERSPROC pGlDeleteBuffers; - static PFNGLBUFFERSTORAGEPROC pGlBufferStorage; - static PFNGLNAMEDBUFFERSTORAGEPROC pGlNamedBufferStorage; //NULL - static PFNGLNAMEDBUFFERSTORAGEEXTPROC pGlNamedBufferStorageEXT; - static PFNGLBUFFERSUBDATAPROC pGlBufferSubData; - static PFNGLNAMEDBUFFERSUBDATAPROC pGlNamedBufferSubData; //NULL - static PFNGLNAMEDBUFFERSUBDATAEXTPROC pGlNamedBufferSubDataEXT; - static PFNGLGETBUFFERSUBDATAPROC pGlGetBufferSubData; - static PFNGLGETNAMEDBUFFERSUBDATAPROC pGlGetNamedBufferSubData; //NULL - static PFNGLGETNAMEDBUFFERSUBDATAEXTPROC pGlGetNamedBufferSubDataEXT; - static PFNGLMAPBUFFERPROC pGlMapBuffer; - static PFNGLMAPNAMEDBUFFERPROC pGlMapNamedBuffer; //NULL - static PFNGLMAPNAMEDBUFFEREXTPROC pGlMapNamedBufferEXT; - static PFNGLMAPBUFFERRANGEPROC pGlMapBufferRange; - static PFNGLMAPNAMEDBUFFERRANGEPROC pGlMapNamedBufferRange; //NULL - static PFNGLMAPNAMEDBUFFERRANGEEXTPROC pGlMapNamedBufferRangeEXT; - static PFNGLFLUSHMAPPEDBUFFERRANGEPROC pGlFlushMappedBufferRange; - static PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEPROC pGlFlushMappedNamedBufferRange; //NULL - static PFNGLFLUSHMAPPEDNAMEDBUFFERRANGEEXTPROC pGlFlushMappedNamedBufferRangeEXT; - static PFNGLUNMAPBUFFERPROC pGlUnmapBuffer; - static PFNGLUNMAPNAMEDBUFFERPROC pGlUnmapNamedBuffer; //NULL - static PFNGLUNMAPNAMEDBUFFEREXTPROC pGlUnmapNamedBufferEXT; - static PFNGLCLEARBUFFERDATAPROC pGlClearBufferData; - static PFNGLCLEARNAMEDBUFFERDATAPROC pGlClearNamedBufferData; //NULL - static PFNGLCLEARNAMEDBUFFERDATAEXTPROC pGlClearNamedBufferDataEXT; - static PFNGLCLEARBUFFERSUBDATAPROC pGlClearBufferSubData; - static PFNGLCLEARNAMEDBUFFERSUBDATAPROC pGlClearNamedBufferSubData; //NULL - static PFNGLCLEARNAMEDBUFFERSUBDATAEXTPROC pGlClearNamedBufferSubDataEXT; - static PFNGLCOPYBUFFERSUBDATAPROC pGlCopyBufferSubData; - static PFNGLCOPYNAMEDBUFFERSUBDATAPROC pGlCopyNamedBufferSubData; //NULL - static PFNGLNAMEDCOPYBUFFERSUBDATAEXTPROC pGlNamedCopyBufferSubDataEXT; - static PFNGLISBUFFERPROC pGlIsBuffer; - static PFNGLGETNAMEDBUFFERPARAMETERI64VPROC pGlGetNamedBufferParameteri64v; - static PFNGLGETBUFFERPARAMETERI64VPROC pGlGetBufferParameteri64v; - static PFNGLGETNAMEDBUFFERPARAMETERIVPROC pGlGetNamedBufferParameteriv; - static PFNGLGETNAMEDBUFFERPARAMETERIVEXTPROC pGlGetNamedBufferParameterivEXT; - static PFNGLGETBUFFERPARAMETERIVPROC pGlGetBufferParameteriv; - //vao - static PFNGLGENVERTEXARRAYSPROC pGlGenVertexArrays; - static PFNGLCREATEVERTEXARRAYSPROC pGlCreateVertexArrays; //NULL - static PFNGLDELETEVERTEXARRAYSPROC pGlDeleteVertexArrays; - static PFNGLBINDVERTEXARRAYPROC pGlBindVertexArray; - static PFNGLVERTEXARRAYELEMENTBUFFERPROC pGlVertexArrayElementBuffer; //NULL - static PFNGLBINDVERTEXBUFFERPROC pGlBindVertexBuffer; - static PFNGLVERTEXARRAYVERTEXBUFFERPROC pGlVertexArrayVertexBuffer; //NULL - static PFNGLVERTEXARRAYBINDVERTEXBUFFEREXTPROC pGlVertexArrayBindVertexBufferEXT; - static PFNGLVERTEXATTRIBBINDINGPROC pGlVertexAttribBinding; - static PFNGLVERTEXARRAYATTRIBBINDINGPROC pGlVertexArrayAttribBinding; //NULL - static PFNGLVERTEXARRAYVERTEXATTRIBBINDINGEXTPROC pGlVertexArrayVertexAttribBindingEXT; - static PFNGLENABLEVERTEXATTRIBARRAYPROC pGlEnableVertexAttribArray; - static PFNGLENABLEVERTEXARRAYATTRIBPROC pGlEnableVertexArrayAttrib; //NULL - static PFNGLENABLEVERTEXARRAYATTRIBEXTPROC pGlEnableVertexArrayAttribEXT; - static PFNGLDISABLEVERTEXATTRIBARRAYPROC pGlDisableVertexAttribArray; - static PFNGLDISABLEVERTEXARRAYATTRIBPROC pGlDisableVertexArrayAttrib; //NULL - static PFNGLDISABLEVERTEXARRAYATTRIBEXTPROC pGlDisableVertexArrayAttribEXT; - static PFNGLVERTEXATTRIBFORMATPROC pGlVertexAttribFormat; - static PFNGLVERTEXATTRIBIFORMATPROC pGlVertexAttribIFormat; - static PFNGLVERTEXATTRIBLFORMATPROC pGlVertexAttribLFormat; - static PFNGLVERTEXARRAYATTRIBFORMATPROC pGlVertexArrayAttribFormat; //NULL - static PFNGLVERTEXARRAYATTRIBIFORMATPROC pGlVertexArrayAttribIFormat; //NULL - static PFNGLVERTEXARRAYATTRIBLFORMATPROC pGlVertexArrayAttribLFormat; //NULL - static PFNGLVERTEXARRAYVERTEXATTRIBFORMATEXTPROC pGlVertexArrayVertexAttribFormatEXT; - static PFNGLVERTEXARRAYVERTEXATTRIBIFORMATEXTPROC pGlVertexArrayVertexAttribIFormatEXT; - static PFNGLVERTEXARRAYVERTEXATTRIBLFORMATEXTPROC pGlVertexArrayVertexAttribLFormatEXT; - static PFNGLVERTEXARRAYBINDINGDIVISORPROC pGlVertexArrayBindingDivisor; //NULL - static PFNGLVERTEXARRAYVERTEXBINDINGDIVISOREXTPROC pGlVertexArrayVertexBindingDivisorEXT; - static PFNGLVERTEXBINDINGDIVISORPROC pGlVertexBindingDivisor; - // - static PFNGLPRIMITIVERESTARTINDEXPROC pGlPrimitiveRestartIndex; - static PFNGLDRAWARRAYSINSTANCEDPROC pGlDrawArraysInstanced; - static PFNGLDRAWARRAYSINSTANCEDBASEINSTANCEPROC pGlDrawArraysInstancedBaseInstance; - static PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXPROC pGlDrawElementsInstancedBaseVertex; - static PFNGLDRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCEPROC pGlDrawElementsInstancedBaseVertexBaseInstance; - static PFNGLDRAWTRANSFORMFEEDBACKPROC pGlDrawTransformFeedback; - static PFNGLDRAWTRANSFORMFEEDBACKINSTANCEDPROC pGlDrawTransformFeedbackInstanced; - static PFNGLDRAWTRANSFORMFEEDBACKSTREAMPROC pGlDrawTransformFeedbackStream; - static PFNGLDRAWTRANSFORMFEEDBACKSTREAMINSTANCEDPROC pGlDrawTransformFeedbackStreamInstanced; - static PFNGLDRAWARRAYSINDIRECTPROC pGlDrawArraysIndirect; - static PFNGLDRAWELEMENTSINDIRECTPROC pGlDrawElementsIndirect; - static PFNGLMULTIDRAWARRAYSINDIRECTPROC pGlMultiDrawArraysIndirect; - static PFNGLMULTIDRAWELEMENTSINDIRECTPROC pGlMultiDrawElementsIndirect; - static PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC pGlMultiDrawArrysIndirectCount; - static PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC pGlMultiDrawElementsIndirectCount; - // - static PFNGLCREATETRANSFORMFEEDBACKSPROC pGlCreateTransformFeedbacks; - static PFNGLGENTRANSFORMFEEDBACKSPROC pGlGenTransformFeedbacks; - static PFNGLDELETETRANSFORMFEEDBACKSPROC pGlDeleteTransformFeedbacks; - static PFNGLBINDTRANSFORMFEEDBACKPROC pGlBindTransformFeedback; - static PFNGLBEGINTRANSFORMFEEDBACKPROC pGlBeginTransformFeedback; - static PFNGLPAUSETRANSFORMFEEDBACKPROC pGlPauseTransformFeedback; - static PFNGLRESUMETRANSFORMFEEDBACKPROC pGlResumeTransformFeedback; - static PFNGLENDTRANSFORMFEEDBACKPROC pGlEndTransformFeedback; - static PFNGLTRANSFORMFEEDBACKBUFFERBASEPROC pGlTransformFeedbackBufferBase; - static PFNGLTRANSFORMFEEDBACKBUFFERRANGEPROC pGlTransformFeedbackBufferRange; - - static PFNGLGETINTERNALFORMATIVPROC pGlGetInternalformativ; - static PFNGLGETINTERNALFORMATI64VPROC pGlGetInternalformati64v; - - //! REMOVE ALL BELOW - static PFNGLBLENDFUNCSEPARATEPROC pGlBlendFuncSeparate; - static PFNGLBLENDFUNCINDEXEDAMDPROC pGlBlendFuncIndexedAMD; //NULL - static PFNGLBLENDFUNCIPROC pGlBlendFunciARB; - static PFNGLBLENDEQUATIONINDEXEDAMDPROC pGlBlendEquationIndexedAMD; //NULL - static PFNGLBLENDEQUATIONIPROC pGlBlendEquationiARB; //NULL - // - static PFNGLPROGRAMPARAMETERIPROC pGlProgramParameteri; - static PFNGLPATCHPARAMETERIPROC pGlPatchParameteri; - static PFNGLPATCHPARAMETERFVPROC pGlPatchParameterfv; - // - static PFNGLCREATEQUERIESPROC pGlCreateQueries; - static PFNGLGENQUERIESPROC pGlGenQueries; - static PFNGLDELETEQUERIESPROC pGlDeleteQueries; - static PFNGLISQUERYPROC pGlIsQuery; - static PFNGLBEGINQUERYPROC pGlBeginQuery; - static PFNGLENDQUERYPROC pGlEndQuery; - static PFNGLBEGINQUERYINDEXEDPROC pGlBeginQueryIndexed; - static PFNGLENDQUERYINDEXEDPROC pGlEndQueryIndexed; - static PFNGLGETQUERYIVPROC pGlGetQueryiv; - static PFNGLGETQUERYOBJECTUIVPROC pGlGetQueryObjectuiv; - static PFNGLGETQUERYOBJECTUI64VPROC pGlGetQueryObjectui64v; - static PFNGLGETQUERYBUFFEROBJECTUIVPROC pGlGetQueryBufferObjectuiv; - static PFNGLGETQUERYBUFFEROBJECTUI64VPROC pGlGetQueryBufferObjectui64v; - static PFNGLQUERYCOUNTERPROC pGlQueryCounter; - static PFNGLBEGINCONDITIONALRENDERPROC pGlBeginConditionalRender; - static PFNGLENDCONDITIONALRENDERPROC pGlEndConditionalRender; // static PFNGLTEXTUREBARRIERPROC pGlTextureBarrier; static PFNGLTEXTUREBARRIERNVPROC pGlTextureBarrierNV; - // - static PFNGLBLENDEQUATIONEXTPROC pGlBlendEquationEXT; - static PFNGLBLENDEQUATIONPROC pGlBlendEquation; - - // the following can stay also - static PFNGLDEBUGMESSAGECONTROLPROC pGlDebugMessageControl; - static PFNGLDEBUGMESSAGECONTROLARBPROC pGlDebugMessageControlARB; - static PFNGLDEBUGMESSAGECALLBACKPROC pGlDebugMessageCallback; - static PFNGLDEBUGMESSAGECALLBACKARBPROC pGlDebugMessageCallbackARB; // os specific stuff for swapchain #if defined(WGL_EXT_swap_control) @@ -1897,1389 +152,161 @@ class COpenGLExtensionHandler #if defined(GLX_MESA_swap_control) static PFNGLXSWAPINTERVALMESAPROC pGlxSwapIntervalMESA; #endif -protected: - // constructor - COpenGLExtensionHandler(); -private: - static bool functionsAlreadyLoaded; - - static int32_t pixelUnpackAlignment; -}; - -inline bool COpenGLExtensionHandler::extGlIsEnabledi(GLenum cap, GLuint index) -{ - return pGlIsEnabledi(cap,index); -} -inline void COpenGLExtensionHandler::extGlEnablei(GLenum cap, GLuint index) -{ - pGlEnablei(cap,index); -} -inline void COpenGLExtensionHandler::extGlDisablei(GLenum cap, GLuint index) -{ - pGlDisablei(cap,index); -} -inline void COpenGLExtensionHandler::extGlGetBooleani_v(GLenum pname, GLuint index, GLboolean* data) -{ - pGlGetBooleani_v(pname,index,data); -} -inline void COpenGLExtensionHandler::extGlGetFloati_v(GLenum pname, GLuint index, float* data) -{ - pGlGetFloati_v(pname,index,data); -} -inline void COpenGLExtensionHandler::extGlGetInteger64v(GLenum pname, GLint64* data) -{ - pGlGetInteger64v(pname, data); -} -inline void COpenGLExtensionHandler::extGlGetIntegeri_v(GLenum pname, GLuint index, GLint* data) -{ - pGlGetIntegeri_v(pname,index,data); -} -inline void COpenGLExtensionHandler::extGlProvokingVertex(GLenum provokeMode) -{ - pGlProvokingVertex(provokeMode); -} -inline void COpenGLExtensionHandler::extGlClipControl(GLenum origin, GLenum depth) -{ - pGlClipControl(origin,depth); -} - - -inline GLsync COpenGLExtensionHandler::extGlFenceSync(GLenum condition, GLbitfield flags) -{ - return pGlFenceSync(condition,flags); -} - -inline void COpenGLExtensionHandler::extGlDeleteSync(GLsync sync) -{ - pGlDeleteSync(sync); -} -inline GLenum COpenGLExtensionHandler::extGlClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) -{ - return pGlClientWaitSync(sync,flags,timeout); -} -inline void COpenGLExtensionHandler::extGlWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) +inline void COpenGLExtensionHandler::extGlBindImageTexture(GLuint index, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format) { - pGlWaitSync(sync,flags,timeout); + if (pGlBindImageTexture) + pGlBindImageTexture(index,texture,level,layered,layer,access,format); } -inline void COpenGLExtensionHandler::extGlActiveTexture(GLenum target) // kill this function in favour of multibind (but need to upgrade OpenGL tracker) -{ - pGlActiveTexture(target); -} -inline void COpenGLExtensionHandler::extGlBindTextures(const GLuint& first, const GLsizei& count, const GLuint* textures, const GLenum* targets) +inline void COpenGLExtensionHandler::extGlBindImageTextures(GLuint first, GLsizei count, const GLuint* textures, const GLenum* formats) { - const GLenum supportedTargets[] = { GL_TEXTURE_1D,GL_TEXTURE_2D, // GL 1.x - GL_TEXTURE_3D,GL_TEXTURE_RECTANGLE,GL_TEXTURE_CUBE_MAP, // GL 2.x - GL_TEXTURE_1D_ARRAY,GL_TEXTURE_2D_ARRAY,GL_TEXTURE_BUFFER, // GL 3.x - GL_TEXTURE_CUBE_MAP_ARRAY,GL_TEXTURE_2D_MULTISAMPLE,GL_TEXTURE_2D_MULTISAMPLE_ARRAY}; // GL 4.x - - if (Version>=440||FeatureAvailable[NBL_ARB_multi_bind]) - pGlBindTextures(first,count,textures); + if (pGlBindImageTextures && !IsIntelGPU) // Intel is a special boy, as always + pGlBindImageTextures(first, count, textures); else { - int32_t activeTex = 0; - glGetIntegerv(GL_ACTIVE_TEXTURE,&activeTex); - for (GLsizei i=0; i=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlCreateTextures(target,n,textures); - else - glGenTextures(n,textures); -} - -inline void COpenGLExtensionHandler::extGlTextureBuffer(GLuint texture, GLenum internalformat, GLuint buffer) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlTextureBuffer(texture,internalformat,buffer); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlTextureBufferEXT(texture,GL_TEXTURE_BUFFER,internalformat,buffer); - else - { - GLint bound; - glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &bound); - glBindTexture(GL_TEXTURE_BUFFER, texture); - pGlTexBuffer(GL_TEXTURE_BUFFER,internalformat,buffer); - glBindTexture(GL_TEXTURE_BUFFER, bound); } } -inline void COpenGLExtensionHandler::extGlTextureBufferRange(GLuint texture, GLenum internalformat, GLuint buffer, GLintptr offset, GLsizei length) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlTextureBufferRange) - pGlTextureBufferRange(texture,internalformat,buffer,offset,length); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlTextureBufferRangeEXT) - pGlTextureBufferRangeEXT(texture,GL_TEXTURE_BUFFER,internalformat,buffer,offset,length); - } - else - { - GLint bound; - glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &bound); - glBindTexture(GL_TEXTURE_BUFFER, texture); - if (pGlTexBufferRange) - pGlTexBufferRange(GL_TEXTURE_BUFFER,internalformat,buffer,offset,length); - glBindTexture(GL_TEXTURE_BUFFER, bound); - } -} -inline void COpenGLExtensionHandler::extGlTextureStorage1D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width) +inline void COpenGLExtensionHandler::extGlCreateFramebuffers(GLsizei n, GLuint *framebuffers) { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlTextureStorage1D) - pGlTextureStorage1D(texture,levels,internalformat,width); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlTextureStorage1DEXT) - pGlTextureStorage1DEXT(texture,target,levels,internalformat,width); - } - else if (pGlTexStorage1D) + if (!needsDSAFramebufferHack) { - GLint bound; - switch (target) + if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) { - case GL_TEXTURE_1D: - glGetIntegerv(GL_TEXTURE_BINDING_1D, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; + pGlCreateFramebuffers(n, framebuffers); + return; } - glBindTexture(target, texture); - pGlTexStorage1D(target,levels,internalformat,width); - glBindTexture(target, bound); } + + pGlGenFramebuffers(n, framebuffers); } -inline void COpenGLExtensionHandler::extGlTextureStorage2D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height) + +inline GLenum COpenGLExtensionHandler::extGlCheckNamedFramebufferStatus(GLuint framebuffer, GLenum target) { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlTextureStorage2D) - pGlTextureStorage2D(texture,levels,internalformat,width,height); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlTextureStorage2DEXT) - pGlTextureStorage2DEXT(texture,target,levels,internalformat,width,height); - } - else if (pGlTexStorage2D) + if (!needsDSAFramebufferHack) { - GLint bound; - switch (target) - { - case GL_TEXTURE_1D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); - break; - case GL_TEXTURE_2D: - glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); - break; - case GL_TEXTURE_CUBE_MAP: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - case GL_TEXTURE_RECTANGLE: - glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - pGlTexStorage2D(target,levels,internalformat,width,height); - glBindTexture(target, bound); + if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) + return pGlCheckNamedFramebufferStatus(framebuffer,target); + else if (FeatureAvailable[NBL_EXT_direct_state_access]) + return pGlCheckNamedFramebufferStatusEXT(framebuffer,target); } + + GLenum retval; + GLuint bound; + glGetIntegerv(target==GL_READ_FRAMEBUFFER ? GL_READ_FRAMEBUFFER_BINDING:GL_DRAW_FRAMEBUFFER_BINDING,reinterpret_cast(&bound)); + + if (bound!=framebuffer) + pGlBindFramebuffer(target,framebuffer); + retval = pGlCheckFramebufferStatus(target); + if (bound!=framebuffer) + pGlBindFramebuffer(target,bound); + + return retval; } -inline void COpenGLExtensionHandler::extGlTextureStorage3D(GLuint texture, GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) + +inline void COpenGLExtensionHandler::extGlNamedFramebufferTexture(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level) { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlTextureStorage3D(texture,levels,internalformat,width,height,depth); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlTextureStorage3DEXT(texture,target,levels,internalformat,width,height,depth); - else + if (!needsDSAFramebufferHack) { - GLint bound; - switch (target) + if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) { - case GL_TEXTURE_2D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); - break; - case GL_TEXTURE_3D: - glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); - break; - case GL_TEXTURE_CUBE_MAP_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; + pGlNamedFramebufferTexture(framebuffer, attachment, texture, level); + return; } - glBindTexture(target, texture); - pGlTexStorage3D(target,levels,internalformat,width,height,depth); - glBindTexture(target, bound); - } -} - -inline void COpenGLExtensionHandler::extGlTextureStorage2DMultisample(GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLboolean fixedsamplelocations) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlTextureStorage2DMultisample(texture,samples,internalformat,width,height,fixedsamplelocations); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlTextureStorage2DMultisampleEXT(texture,target,samples,internalformat,width,height,fixedsamplelocations); - else - { - GLint bound; - if (target!=GL_TEXTURE_2D_MULTISAMPLE) + else if (FeatureAvailable[NBL_EXT_direct_state_access]) { - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); + pGlNamedFramebufferTextureEXT(framebuffer, attachment, texture, level); return; } - else - glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE, &bound); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, texture); - pGlTexStorage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE,samples,internalformat,width,height,fixedsamplelocations); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, bound); } + + GLuint bound; + glGetIntegerv(GL_FRAMEBUFFER_BINDING,reinterpret_cast(&bound)); + + if (bound!=framebuffer) + pGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); + pGlFramebufferTexture(GL_FRAMEBUFFER,attachment,texture,level); + if (bound!=framebuffer) + pGlBindFramebuffer(GL_FRAMEBUFFER,bound); } -inline void COpenGLExtensionHandler::extGlTextureStorage3DMultisample(GLuint texture, GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLboolean fixedsamplelocations) + +inline void COpenGLExtensionHandler::extGlNamedFramebufferTextureLayer(GLuint framebuffer, GLenum attachment, GLuint texture, GLenum textureType, GLint level, GLint layer) { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlTextureStorage3DMultisample(texture,samples,internalformat,width,height,depth,fixedsamplelocations); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlTextureStorage3DMultisampleEXT(texture,target,samples,internalformat,width,height,depth,fixedsamplelocations); - else + if (!needsDSAFramebufferHack) { - GLint bound; - if (target!=GL_TEXTURE_2D_MULTISAMPLE_ARRAY) + if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) { - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); + pGlNamedFramebufferTextureLayer(framebuffer, attachment, texture, level, layer); return; } - else - glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY, &bound); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, texture); - pGlTexStorage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY,samples,internalformat,width,height,depth,fixedsamplelocations); - glBindTexture(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, bound); } -} -inline void COpenGLExtensionHandler::extGlTextureView(GLuint texture, GLenum target, GLuint origtexture, GLenum internalformat, GLuint minlevel, GLuint numlevels, GLuint minlayer, GLuint numlayers) -{ - pGlTextureView(texture,target,origtexture,internalformat,minlevel,numlevels,minlayer,numlayers); -} + if (textureType!=GL_TEXTURE_CUBE_MAP) + { + if (!needsDSAFramebufferHack && FeatureAvailable[NBL_EXT_direct_state_access]) + { + pGlNamedFramebufferTextureLayerEXT(framebuffer, attachment, texture, level, layer); + } + else + { + GLuint bound; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, reinterpret_cast(&bound)); -inline void COpenGLExtensionHandler::extGlGetTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, GLsizei bufSize, void* pixels) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_get_texture_sub_image]) - pGlGetTextureSubImage(texture, level, xoffset, yoffset, zoffset, width, height, depth, format, type, bufSize, pixels); -#ifdef _NBL_DEBUG + if (bound != framebuffer) + pGlBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + pGlFramebufferTextureLayer(GL_FRAMEBUFFER, attachment, texture, level, layer); + if (bound != framebuffer) + pGlBindFramebuffer(GL_FRAMEBUFFER, bound); + } + } else - os::Printer::log("EDF_GET_TEXTURE_SUB_IMAGE Not Available! Tell DevSH to implement!\n", ELL_ERROR); -#endif // _NBL_DEBUG -} + { + constexpr GLenum CubeMapFaceToCubeMapFaceGLenum[IGPUImageView::ECMF_COUNT] = { + GL_TEXTURE_CUBE_MAP_POSITIVE_X,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,GL_TEXTURE_CUBE_MAP_POSITIVE_Y,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,GL_TEXTURE_CUBE_MAP_POSITIVE_Z,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z + }; -inline void COpenGLExtensionHandler::extGlGetCompressedTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei bufSize, void* pixels) -{ - if (Version >= 450 || FeatureAvailable[NBL_ARB_get_texture_sub_image]) - extGlGetCompressedTextureSubImage(texture, level, xoffset, yoffset, zoffset, width, height, depth, bufSize, pixels); -#ifdef _NBL_DEBUG - else - os::Printer::log("EDF_GET_TEXTURE_SUB_IMAGE Not Available! Tell DevSH to implement!\n", ELL_ERROR); -#endif // _NBL_DEBUG + if (!needsDSAFramebufferHack && FeatureAvailable[NBL_EXT_direct_state_access]) + { + pGlNamedFramebufferTexture2DEXT(framebuffer, attachment, CubeMapFaceToCubeMapFaceGLenum[layer], texture, level); + } + else + { + GLuint bound; + glGetIntegerv(GL_FRAMEBUFFER_BINDING, reinterpret_cast(&bound)); + + if (bound != framebuffer) + pGlBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + pGlFramebufferTexture2D(GL_FRAMEBUFFER, attachment, CubeMapFaceToCubeMapFaceGLenum[layer], texture, level); + if (bound != framebuffer) + pGlBindFramebuffer(GL_FRAMEBUFFER, bound); + } + } } -inline void COpenGLExtensionHandler::extGlGetTextureImage(GLuint texture, GLenum target, GLint level, GLenum format, GLenum type, GLsizei bufSizeHint, void* pixels) +inline void COpenGLExtensionHandler::extGlBlitNamedFramebuffer(GLuint readFramebuffer, GLuint drawFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlGetTextureImage(texture, level, format, type, bufSizeHint, pixels); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlGetTextureImageEXT(texture, target, level, format, type, pixels); - else + if (!needsDSAFramebufferHack) { - GLint bound = 0; - switch (target) + if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) { - case GL_TEXTURE_1D: - glGetIntegerv(GL_TEXTURE_BINDING_1D, &bound); - break; - case GL_TEXTURE_1D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); - break; - case GL_TEXTURE_2D: - glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - case GL_TEXTURE_CUBE_MAP: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - case GL_TEXTURE_RECTANGLE: - glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); - break; - case GL_TEXTURE_2D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); - break; - case GL_TEXTURE_CUBE_MAP_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); - break; - case GL_TEXTURE_3D: - glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); - break; - default: - break; - } - glBindTexture(target, texture); - glGetTexImage(target, level, format, type, pixels); - glBindTexture(target, bound); - } -} - -inline void COpenGLExtensionHandler::extGlGetCompressedTextureImage(GLuint texture, GLenum target, GLint level, GLsizei bufSizeHint, void* pixels) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlGetCompressedTextureImage(texture, level, bufSizeHint, pixels); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlGetCompressedTextureImageEXT(texture, target, level, pixels); - else - { - GLint bound = 0; - switch (target) - { - case GL_TEXTURE_1D: - glGetIntegerv(GL_TEXTURE_BINDING_1D, &bound); - break; - case GL_TEXTURE_1D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); - break; - case GL_TEXTURE_2D: - glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - case GL_TEXTURE_CUBE_MAP: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - case GL_TEXTURE_RECTANGLE: - glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); - break; - case GL_TEXTURE_2D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); - break; - case GL_TEXTURE_CUBE_MAP_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); - break; - case GL_TEXTURE_3D: - glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); - break; - default: - break; - } - glBindTexture(target, texture); - pGlGetCompressedTexImage(target, level, pixels); - glBindTexture(target, bound); - } -} - -inline void COpenGLExtensionHandler::extGlTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const void *pixels) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlTextureSubImage1D(texture, level, xoffset, width,format, type, pixels); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlTextureSubImage1DEXT(texture, target, level, xoffset, width,format, type, pixels); - else - { - GLint bound; - switch (target) - { - case GL_TEXTURE_1D: - glGetIntegerv(GL_TEXTURE_BINDING_1D, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - glTexSubImage1D(target, level, xoffset, width,format, type, pixels); - glBindTexture(target, bound); - } -} -inline void COpenGLExtensionHandler::extGlTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlTextureSubImage2D(texture, level, xoffset, yoffset,width, height,format, type, pixels); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlTextureSubImage2DEXT(texture, target, level, xoffset, yoffset,width, height,format, type, pixels); - else - { - GLint bound; - switch (target) - { - case GL_TEXTURE_1D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); - break; - case GL_TEXTURE_2D: - glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); - break; - case GL_TEXTURE_2D_MULTISAMPLE: - glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE, &bound); - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - case GL_TEXTURE_RECTANGLE: - glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - glTexSubImage2D(target, level, xoffset, yoffset,width, height,format, type, pixels); - glBindTexture(target, bound); - } -} -inline void COpenGLExtensionHandler::extGlTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlTextureSubImage3D(texture, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlTextureSubImage3DEXT(texture, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels); - else - { - GLint bound; - switch (target) - { - case GL_TEXTURE_2D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); - break; - case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY, &bound); - break; - case GL_TEXTURE_3D: - glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); - break; - case GL_TEXTURE_CUBE_MAP: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - case GL_TEXTURE_CUBE_MAP_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - pGlTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels); - glBindTexture(target, bound); - } -} -inline void COpenGLExtensionHandler::extGlCompressedTextureSubImage1D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLsizei imageSize, const void *data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlCompressedTextureSubImage1D) - pGlCompressedTextureSubImage1D(texture, level, xoffset, width,format, imageSize, data); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlCompressedTextureSubImage1DEXT) - pGlCompressedTextureSubImage1DEXT(texture, target, level, xoffset, width,format, imageSize, data); - } - else if (pGlCompressedTexSubImage1D) - { - GLint bound; - switch (target) - { - case GL_TEXTURE_1D: - glGetIntegerv(GL_TEXTURE_BINDING_1D, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - pGlCompressedTexSubImage1D(target, level, xoffset, width,format, imageSize, data); - glBindTexture(target, bound); - } -} -inline void COpenGLExtensionHandler::extGlCompressedTextureSubImage2D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlCompressedTextureSubImage2D) - pGlCompressedTextureSubImage2D(texture, level, xoffset, yoffset,width, height,format, imageSize, data); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlCompressedTextureSubImage2DEXT) - pGlCompressedTextureSubImage2DEXT(texture, target, level, xoffset, yoffset,width, height,format, imageSize, data); - } - else if (pGlCompressedTexSubImage2D) - { - GLint bound; - switch (target) - { - case GL_TEXTURE_1D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); - break; - case GL_TEXTURE_2D: - glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); - break; - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: - case GL_TEXTURE_CUBE_MAP_POSITIVE_X: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - pGlCompressedTexSubImage2D(target, level, xoffset, yoffset,width, height,format, imageSize, data); - glBindTexture(target, bound); - } -} -inline void COpenGLExtensionHandler::extGlCompressedTextureSubImage3D(GLuint texture, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlCompressedTextureSubImage3D) - pGlCompressedTextureSubImage3D(texture, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlCompressedTextureSubImage3DEXT) - pGlCompressedTextureSubImage3DEXT(texture, target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data); - } - else if (pGlCompressedTexSubImage3D) - { - GLint bound; - switch (target) - { - case GL_TEXTURE_2D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); - break; - case GL_TEXTURE_3D: - glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); - break; - case GL_TEXTURE_CUBE_MAP: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - case GL_TEXTURE_CUBE_MAP_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - pGlCompressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data); - glBindTexture(target, bound); - } -} - -inline void COpenGLExtensionHandler::extGlCopyImageSubData(GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth) -{ - pGlCopyImageSubData(srcName,srcTarget,srcLevel,srcX,srcY,srcZ,dstName,dstTarget,dstLevel,dstX,dstY,dstZ,srcWidth,srcHeight,srcDepth); -} - -inline void COpenGLExtensionHandler::extGlGenerateTextureMipmap(GLuint texture, GLenum target) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlGenerateTextureMipmap) - pGlGenerateTextureMipmap(texture); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlGenerateTextureMipmapEXT) - pGlGenerateTextureMipmapEXT(texture,target); - } - else - { - GLint bound; - switch (target) - { - case GL_TEXTURE_1D: - glGetIntegerv(GL_TEXTURE_BINDING_1D, &bound); - break; - case GL_TEXTURE_1D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); - break; - case GL_TEXTURE_2D: - glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); - break; - case GL_TEXTURE_2D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); - break; - case GL_TEXTURE_2D_MULTISAMPLE: - glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE, &bound); - break; - case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY, &bound); - break; - case GL_TEXTURE_3D: - glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); - break; - case GL_TEXTURE_BUFFER: - glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &bound); - break; - case GL_TEXTURE_CUBE_MAP: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - case GL_TEXTURE_CUBE_MAP_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); - break; - case GL_TEXTURE_RECTANGLE: - glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - pGlGenerateMipmap(target); - glBindTexture(target, bound); - } -} - -inline void COpenGLExtensionHandler::extGlTextureParameterIuiv(GLuint texture, GLenum target, GLenum pname, const GLuint* params) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - pGlTextureParameterIuiv(texture,pname,params); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - pGlTextureParameterIuivEXT(texture,target,pname,params); - else - { - GLint bound; - switch (target) - { - case GL_TEXTURE_1D: - glGetIntegerv(GL_TEXTURE_BINDING_1D, &bound); - break; - case GL_TEXTURE_1D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_1D_ARRAY, &bound); - break; - case GL_TEXTURE_2D: - glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound); - break; - case GL_TEXTURE_2D_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, &bound); - break; - case GL_TEXTURE_2D_MULTISAMPLE: - glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE, &bound); - break; - case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY, &bound); - break; - case GL_TEXTURE_3D: - glGetIntegerv(GL_TEXTURE_BINDING_3D, &bound); - break; - case GL_TEXTURE_BUFFER: - glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &bound); - break; - case GL_TEXTURE_CUBE_MAP: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP, &bound); - break; - case GL_TEXTURE_CUBE_MAP_ARRAY: - glGetIntegerv(GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, &bound); - break; - case GL_TEXTURE_RECTANGLE: - glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE, &bound); - break; - default: - os::Printer::log("DevSH would like to ask you what are you doing!!??\n",ELL_ERROR); - return; - } - glBindTexture(target, texture); - pGlTexParameterIuiv(target,pname,params); - glBindTexture(target, bound); - } -} - -inline void COpenGLExtensionHandler::extGlClampColor(GLenum target, GLenum clamp) -{ - if (pGlClampColor) - pGlClampColor(GL_CLAMP_READ_COLOR,clamp); -} - -inline void COpenGLExtensionHandler::extGlCreateSamplers(GLsizei n, GLuint* samplers) -{ - if (pGlCreateSamplers) - pGlCreateSamplers(n, samplers); - else if (pGlGenSamplers) - pGlGenSamplers(n, samplers); - else memset(samplers, 0, 4*n); -} - -inline void COpenGLExtensionHandler::extGlDeleteSamplers(GLsizei n, GLuint* samplers) -{ - if (pGlDeleteSamplers) - pGlDeleteSamplers(n,samplers); -} - -inline void COpenGLExtensionHandler::extGlBindSamplers(const GLuint& first, const GLsizei& count, const GLuint* samplers) -{ - if (Version>=440||FeatureAvailable[NBL_ARB_multi_bind]) - { - if (pGlBindSamplers) - pGlBindSamplers(first,count,samplers); - } - else - { - for (GLsizei i=0; i=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - pGlCreateFramebuffers(n, framebuffers); - return; - } - } - - pGlGenFramebuffers(n, framebuffers); -} - -inline GLenum COpenGLExtensionHandler::extGlCheckNamedFramebufferStatus(GLuint framebuffer, GLenum target) -{ - if (!needsDSAFramebufferHack) - { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - return pGlCheckNamedFramebufferStatus(framebuffer,target); - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - return pGlCheckNamedFramebufferStatusEXT(framebuffer,target); - } - - GLenum retval; - GLuint bound; - glGetIntegerv(target==GL_READ_FRAMEBUFFER ? GL_READ_FRAMEBUFFER_BINDING:GL_DRAW_FRAMEBUFFER_BINDING,reinterpret_cast(&bound)); - - if (bound!=framebuffer) - pGlBindFramebuffer(target,framebuffer); - retval = pGlCheckFramebufferStatus(target); - if (bound!=framebuffer) - pGlBindFramebuffer(target,bound); - - return retval; -} - -inline void COpenGLExtensionHandler::extGlNamedFramebufferTexture(GLuint framebuffer, GLenum attachment, GLuint texture, GLint level) -{ - if (!needsDSAFramebufferHack) - { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - pGlNamedFramebufferTexture(framebuffer, attachment, texture, level); - return; - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - pGlNamedFramebufferTextureEXT(framebuffer, attachment, texture, level); - return; - } - } - - GLuint bound; - glGetIntegerv(GL_FRAMEBUFFER_BINDING,reinterpret_cast(&bound)); - - if (bound!=framebuffer) - pGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); - pGlFramebufferTexture(GL_FRAMEBUFFER,attachment,texture,level); - if (bound!=framebuffer) - pGlBindFramebuffer(GL_FRAMEBUFFER,bound); -} - -inline void COpenGLExtensionHandler::extGlNamedFramebufferTextureLayer(GLuint framebuffer, GLenum attachment, GLuint texture, GLenum textureType, GLint level, GLint layer) -{ - if (!needsDSAFramebufferHack) - { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - pGlNamedFramebufferTextureLayer(framebuffer, attachment, texture, level, layer); - return; - } - } - - if (textureType!=GL_TEXTURE_CUBE_MAP) - { - if (!needsDSAFramebufferHack && FeatureAvailable[NBL_EXT_direct_state_access]) - { - pGlNamedFramebufferTextureLayerEXT(framebuffer, attachment, texture, level, layer); - } - else - { - GLuint bound; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, reinterpret_cast(&bound)); - - if (bound != framebuffer) - pGlBindFramebuffer(GL_FRAMEBUFFER, framebuffer); - pGlFramebufferTextureLayer(GL_FRAMEBUFFER, attachment, texture, level, layer); - if (bound != framebuffer) - pGlBindFramebuffer(GL_FRAMEBUFFER, bound); - } - } - else - { - constexpr GLenum CubeMapFaceToCubeMapFaceGLenum[IGPUImageView::ECMF_COUNT] = { - GL_TEXTURE_CUBE_MAP_POSITIVE_X,GL_TEXTURE_CUBE_MAP_NEGATIVE_X,GL_TEXTURE_CUBE_MAP_POSITIVE_Y,GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,GL_TEXTURE_CUBE_MAP_POSITIVE_Z,GL_TEXTURE_CUBE_MAP_NEGATIVE_Z - }; - - if (!needsDSAFramebufferHack && FeatureAvailable[NBL_EXT_direct_state_access]) - { - pGlNamedFramebufferTexture2DEXT(framebuffer, attachment, CubeMapFaceToCubeMapFaceGLenum[layer], texture, level); - } - else - { - GLuint bound; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, reinterpret_cast(&bound)); - - if (bound != framebuffer) - pGlBindFramebuffer(GL_FRAMEBUFFER, framebuffer); - pGlFramebufferTexture2D(GL_FRAMEBUFFER, attachment, CubeMapFaceToCubeMapFaceGLenum[layer], texture, level); - if (bound != framebuffer) - pGlBindFramebuffer(GL_FRAMEBUFFER, bound); - } - } -} - -inline void COpenGLExtensionHandler::extGlBlitNamedFramebuffer(GLuint readFramebuffer, GLuint drawFramebuffer, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) -{ - if (!needsDSAFramebufferHack) - { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - pGlBlitNamedFramebuffer(readFramebuffer, drawFramebuffer, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); - return; + pGlBlitNamedFramebuffer(readFramebuffer, drawFramebuffer, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); + return; } } @@ -3301,12 +328,6 @@ inline void COpenGLExtensionHandler::extGlBlitNamedFramebuffer(GLuint readFrameb extGlBindFramebuffer(GL_DRAW_FRAMEBUFFER,boundDrawFBO); } -//! there should be a GL 3.1 thing for this -inline void COpenGLExtensionHandler::extGlActiveStencilFace(GLenum face) -{ - pGlActiveStencilFaceEXT(face); -} - inline void COpenGLExtensionHandler::extGlNamedFramebufferReadBuffer(GLuint framebuffer, GLenum mode) { if (!needsDSAFramebufferHack) @@ -3356,88 +377,42 @@ inline void COpenGLExtensionHandler::extGlNamedFramebufferDrawBuffer(GLuint fram pGlBindFramebuffer(GL_DRAW_FRAMEBUFFER,framebuffer); glDrawBuffer(buf); if (static_cast(boundFBO)!=framebuffer) - pGlBindFramebuffer(GL_DRAW_FRAMEBUFFER,boundFBO); -} - -inline void COpenGLExtensionHandler::extGlNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs) -{ - if (!needsDSAFramebufferHack) - { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - pGlNamedFramebufferDrawBuffers(framebuffer, n, bufs); - return; - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - pGlFramebufferDrawBuffersEXT(framebuffer, n, bufs); - return; - } - } - - GLint boundFBO; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&boundFBO); - - if (static_cast(boundFBO)!=framebuffer) - pGlBindFramebuffer(GL_DRAW_FRAMEBUFFER,framebuffer); - pGlDrawBuffers(n,bufs); - if (static_cast(boundFBO)!=framebuffer) - pGlBindFramebuffer(GL_DRAW_FRAMEBUFFER,boundFBO); -} - -inline void COpenGLExtensionHandler::extGlClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint* value) -{ - if (!needsDSAFramebufferHack) - { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - pGlClearNamedFramebufferiv(framebuffer, buffer, drawbuffer, value); - return; - } - } - - GLint boundFBO = -1; - glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&boundFBO); - if (boundFBO<0) - return; - - if (static_cast(boundFBO)!=framebuffer) - extGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); - pGlClearBufferiv(buffer, drawbuffer, value); - if (static_cast(boundFBO)!=framebuffer) - extGlBindFramebuffer(GL_FRAMEBUFFER,boundFBO); + pGlBindFramebuffer(GL_DRAW_FRAMEBUFFER,boundFBO); } -inline void COpenGLExtensionHandler::extGlClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint* value) +inline void COpenGLExtensionHandler::extGlNamedFramebufferDrawBuffers(GLuint framebuffer, GLsizei n, const GLenum *bufs) { if (!needsDSAFramebufferHack) { if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) { - pGlClearNamedFramebufferuiv(framebuffer, buffer, drawbuffer, value); + pGlNamedFramebufferDrawBuffers(framebuffer, n, bufs); + return; + } + else if (FeatureAvailable[NBL_EXT_direct_state_access]) + { + pGlFramebufferDrawBuffersEXT(framebuffer, n, bufs); return; } } - GLint boundFBO = -1; + GLint boundFBO; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&boundFBO); - if (boundFBO<0) - return; if (static_cast(boundFBO)!=framebuffer) - extGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); - pGlClearBufferuiv(buffer, drawbuffer, value); + pGlBindFramebuffer(GL_DRAW_FRAMEBUFFER,framebuffer); + pGlDrawBuffers(n,bufs); if (static_cast(boundFBO)!=framebuffer) - extGlBindFramebuffer(GL_FRAMEBUFFER,boundFBO); + pGlBindFramebuffer(GL_DRAW_FRAMEBUFFER,boundFBO); } -inline void COpenGLExtensionHandler::extGlClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat* value) +inline void COpenGLExtensionHandler::extGlClearNamedFramebufferiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLint* value) { if (!needsDSAFramebufferHack) { if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) { - pGlClearNamedFramebufferfv(framebuffer, buffer, drawbuffer, value); + pGlClearNamedFramebufferiv(framebuffer, buffer, drawbuffer, value); return; } } @@ -3449,18 +424,18 @@ inline void COpenGLExtensionHandler::extGlClearNamedFramebufferfv(GLuint framebu if (static_cast(boundFBO)!=framebuffer) extGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); - pGlClearBufferfv(buffer, drawbuffer, value); + pGlClearBufferiv(buffer, drawbuffer, value); if (static_cast(boundFBO)!=framebuffer) extGlBindFramebuffer(GL_FRAMEBUFFER,boundFBO); } -inline void COpenGLExtensionHandler::extGlClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) +inline void COpenGLExtensionHandler::extGlClearNamedFramebufferuiv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLuint* value) { if (!needsDSAFramebufferHack) { if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) { - pGlClearNamedFramebufferfi(framebuffer, buffer, drawbuffer, depth, stencil); + pGlClearNamedFramebufferuiv(framebuffer, buffer, drawbuffer, value); return; } } @@ -3469,511 +444,58 @@ inline void COpenGLExtensionHandler::extGlClearNamedFramebufferfi(GLuint framebu glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&boundFBO); if (boundFBO<0) return; - extGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); - pGlClearBufferfi(buffer, drawbuffer, depth, stencil); - extGlBindFramebuffer(GL_FRAMEBUFFER,boundFBO); -} - - -inline void COpenGLExtensionHandler::extGlCreateBuffers(GLsizei n, GLuint *buffers) -{ -#ifdef OPENGL_LEAK_DEBUG - for (size_t i=0; i=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlCreateBuffers) - pGlCreateBuffers(n, buffers); - else if (buffers) - memset(buffers,0,n*sizeof(GLuint)); - } - else - { - if (pGlGenBuffers) - pGlGenBuffers(n, buffers); - else if (buffers) - memset(buffers,0,n*sizeof(GLuint)); - } -} - -inline void COpenGLExtensionHandler::extGlDeleteBuffers(GLsizei n, const GLuint *buffers) -{ -#ifdef OPENGL_LEAK_DEBUG - for (size_t i=0; i=440||FeatureAvailable[NBL_ARB_multi_bind]) - { - if (pGlBindBuffersBase) - pGlBindBuffersBase(target,first,count,buffers); - } - else - { - for (GLsizei i=0; i=440||FeatureAvailable[NBL_ARB_multi_bind]) - { - if (pGlBindBuffersRange) - pGlBindBuffersRange(target,first,count,buffers,offsets,sizes); - } - else - { - for (GLsizei i=0; i=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlNamedBufferStorage) - pGlNamedBufferStorage(buffer,size,data,flags); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlNamedBufferStorageEXT) - pGlNamedBufferStorageEXT(buffer,size,data,flags); - } - else if (pGlBufferStorage&&pGlBindBuffer) - { - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - pGlBufferStorage(GL_ARRAY_BUFFER, size, data, flags); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - } -} - -inline void COpenGLExtensionHandler::extGlNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlNamedBufferSubData) - pGlNamedBufferSubData(buffer,offset,size,data); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlNamedBufferSubDataEXT) - pGlNamedBufferSubDataEXT(buffer,offset,size,data); - } - else if (pGlBufferSubData&&pGlBindBuffer) - { - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - pGlBufferSubData(GL_ARRAY_BUFFER, offset, size, data); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - } -} - -inline void COpenGLExtensionHandler::extGlGetNamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, void *data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlGetNamedBufferSubData) - pGlGetNamedBufferSubData(buffer,offset,size,data); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlGetNamedBufferSubDataEXT) - pGlGetNamedBufferSubDataEXT(buffer,offset,size,data); - } - else if (pGlGetBufferSubData&&pGlBindBuffer) - { - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - pGlGetBufferSubData(GL_ARRAY_BUFFER, offset, size, data); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - } -} - -inline void *COpenGLExtensionHandler::extGlMapNamedBuffer(GLuint buffer, GLbitfield access) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlMapNamedBuffer) - return pGlMapNamedBuffer(buffer,access); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlMapNamedBufferEXT) - return pGlMapNamedBufferEXT(buffer,access); - } - else if (pGlMapBuffer&&pGlBindBuffer) - { - GLvoid* retval; - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - retval = pGlMapBuffer(GL_ARRAY_BUFFER,access); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - return retval; - } - return NULL; -} - -inline void *COpenGLExtensionHandler::extGlMapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length, GLbitfield access) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlMapNamedBufferRange) - return pGlMapNamedBufferRange(buffer,offset,length,access); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlMapNamedBufferRangeEXT) - return pGlMapNamedBufferRangeEXT(buffer,offset,length,access); - } - else if (pGlMapBufferRange&&pGlBindBuffer) - { - GLvoid* retval; - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - retval = pGlMapBufferRange(GL_ARRAY_BUFFER,offset,length,access); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - return retval; - } - return NULL; -} - -inline void COpenGLExtensionHandler::extGlFlushMappedNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlFlushMappedNamedBufferRange) - pGlFlushMappedNamedBufferRange(buffer,offset,length); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlFlushMappedNamedBufferRangeEXT) - pGlFlushMappedNamedBufferRangeEXT(buffer,offset,length); - } - else if (pGlFlushMappedBufferRange&&pGlBindBuffer) - { - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - pGlFlushMappedBufferRange(GL_ARRAY_BUFFER, offset, length); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - } -} - -inline GLboolean COpenGLExtensionHandler::extGlUnmapNamedBuffer(GLuint buffer) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlUnmapNamedBuffer) - return pGlUnmapNamedBuffer(buffer); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlUnmapNamedBufferEXT) - return pGlUnmapNamedBufferEXT(buffer); - } - else if (pGlUnmapBuffer&&pGlBindBuffer) - { - GLboolean retval; - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - retval = pGlUnmapBuffer(GL_ARRAY_BUFFER); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - return retval; - } - return false; -} - -inline void COpenGLExtensionHandler::extGlClearNamedBufferData(GLuint buffer, GLenum internalformat, GLenum format, GLenum type, const void *data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlClearNamedBufferData) - pGlClearNamedBufferData(buffer,internalformat,format,type,data); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlClearNamedBufferDataEXT) - pGlClearNamedBufferDataEXT(buffer,internalformat,format,type,data); - } - else if (pGlClearBufferData&&pGlBindBuffer) - { - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - pGlClearBufferData(GL_ARRAY_BUFFER, internalformat,format,type,data); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - } -} - -inline void COpenGLExtensionHandler::extGlClearNamedBufferSubData(GLuint buffer, GLenum internalformat, GLintptr offset, GLsizeiptr size, GLenum format, GLenum type, const void *data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlClearNamedBufferSubData) - pGlClearNamedBufferSubData(buffer,internalformat,offset,size,format,type,data); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlClearNamedBufferSubDataEXT) - pGlClearNamedBufferSubDataEXT(buffer,internalformat,offset,size,format,type,data); - } - else if (pGlClearBufferSubData&&pGlBindBuffer) - { - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - pGlClearBufferSubData(GL_ARRAY_BUFFER, internalformat,offset,size,format,type,data); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - } -} - -inline void COpenGLExtensionHandler::extGlCopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlCopyNamedBufferSubData) - pGlCopyNamedBufferSubData(readBuffer, writeBuffer, readOffset, writeOffset, size); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlNamedCopyBufferSubDataEXT) - pGlNamedCopyBufferSubDataEXT(readBuffer, writeBuffer, readOffset, writeOffset, size); - } - else if (pGlCopyBufferSubData&&pGlBindBuffer) - { - GLint boundRead,boundWrite; - glGetIntegerv(GL_COPY_READ_BUFFER_BINDING,&boundRead); - glGetIntegerv(GL_COPY_WRITE_BUFFER_BINDING,&boundWrite); - pGlBindBuffer(GL_COPY_READ_BUFFER,readBuffer); - pGlBindBuffer(GL_COPY_WRITE_BUFFER,writeBuffer); - pGlCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, readOffset, writeOffset, size); - pGlBindBuffer(GL_COPY_READ_BUFFER,boundRead); - pGlBindBuffer(GL_COPY_WRITE_BUFFER,boundWrite); - } -} - -inline GLboolean COpenGLExtensionHandler::extGlIsBuffer(GLuint buffer) -{ - if (pGlIsBuffer) - return pGlIsBuffer(buffer); - return false; -} - -inline void COpenGLExtensionHandler::extGlGetNamedBufferParameteriv(const GLuint& buffer, const GLenum& value, GLint* data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlGetNamedBufferParameteriv) - pGlGetNamedBufferParameteriv(buffer, value, data); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlGetNamedBufferParameterivEXT) - pGlGetNamedBufferParameterivEXT(buffer, value, data); - } - else if (pGlGetBufferParameteriv&&pGlBindBuffer) - { - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - pGlGetBufferParameteriv(GL_ARRAY_BUFFER, value, data); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - } -} - -inline void COpenGLExtensionHandler::extGlGetNamedBufferParameteri64v(const GLuint& buffer, const GLenum& value, GLint64* data) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlGetNamedBufferParameteri64v) - pGlGetNamedBufferParameteri64v(buffer, value, data); - } - else if (pGlGetBufferParameteri64v&&pGlBindBuffer) - { - GLint bound; - glGetIntegerv(GL_ARRAY_BUFFER_BINDING,&bound); - pGlBindBuffer(GL_ARRAY_BUFFER,buffer); - pGlGetBufferParameteri64v(GL_ARRAY_BUFFER, value, data); - pGlBindBuffer(GL_ARRAY_BUFFER,bound); - } -} - - -inline void COpenGLExtensionHandler::extGlCreateVertexArrays(GLsizei n, GLuint *arrays) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlCreateVertexArrays) - pGlCreateVertexArrays(n,arrays); - } - else - { - if (pGlGenVertexArrays) - pGlGenVertexArrays(n,arrays); - else - memset(arrays,0,sizeof(GLuint)*n); - } -} - -inline void COpenGLExtensionHandler::extGlDeleteVertexArrays(GLsizei n, GLuint *arrays) -{ - if (pGlDeleteVertexArrays) - pGlDeleteVertexArrays(n,arrays); -} - -inline void COpenGLExtensionHandler::extGlBindVertexArray(GLuint vaobj) -{ - if (pGlBindVertexArray) - pGlBindVertexArray(vaobj); -} - -inline void COpenGLExtensionHandler::extGlVertexArrayElementBuffer(GLuint vaobj, GLuint buffer) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlVertexArrayElementBuffer) - pGlVertexArrayElementBuffer(vaobj,buffer); - } - else if (pGlBindBuffer&&pGlBindVertexArray) - { - // Save the previous bound vertex array - GLint restoreVertexArray; - glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &restoreVertexArray); - pGlBindVertexArray(vaobj); - pGlBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); - pGlBindVertexArray(restoreVertexArray); - } -} - -inline void COpenGLExtensionHandler::extGlVertexArrayVertexBuffer(GLuint vaobj, GLuint bindingindex, GLuint buffer, GLintptr offset, GLsizei stride) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlVertexArrayVertexBuffer) - pGlVertexArrayVertexBuffer(vaobj,bindingindex,buffer,offset,stride); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlVertexArrayBindVertexBufferEXT) - pGlVertexArrayBindVertexBufferEXT(vaobj,bindingindex,buffer,offset,stride); - } - else if (pGlBindVertexBuffer&&pGlBindVertexArray) - { - // Save the previous bound vertex array - GLint restoreVertexArray; - glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &restoreVertexArray); - pGlBindVertexArray(vaobj); - pGlBindVertexBuffer(bindingindex,buffer,offset,stride); - pGlBindVertexArray(restoreVertexArray); - } -} - -inline void COpenGLExtensionHandler::extGlVertexArrayAttribBinding(GLuint vaobj, GLuint attribindex, GLuint bindingindex) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlVertexArrayAttribBinding) - pGlVertexArrayAttribBinding(vaobj,attribindex,bindingindex); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlVertexArrayVertexAttribBindingEXT) - pGlVertexArrayVertexAttribBindingEXT(vaobj,attribindex,bindingindex); - } - else if (pGlVertexAttribBinding&&pGlBindVertexArray) - { - // Save the previous bound vertex array - GLint restoreVertexArray; - glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &restoreVertexArray); - pGlBindVertexArray(vaobj); - pGlVertexAttribBinding(attribindex,bindingindex); - pGlBindVertexArray(restoreVertexArray); - } + + if (static_cast(boundFBO)!=framebuffer) + extGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); + pGlClearBufferuiv(buffer, drawbuffer, value); + if (static_cast(boundFBO)!=framebuffer) + extGlBindFramebuffer(GL_FRAMEBUFFER,boundFBO); } -inline void COpenGLExtensionHandler::extGlEnableVertexArrayAttrib(GLuint vaobj, GLuint index) +inline void COpenGLExtensionHandler::extGlClearNamedFramebufferfv(GLuint framebuffer, GLenum buffer, GLint drawbuffer, const GLfloat* value) { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlEnableVertexArrayAttrib) - pGlEnableVertexArrayAttrib(vaobj,index); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlEnableVertexArrayAttribEXT) - pGlEnableVertexArrayAttribEXT(vaobj,index); - } - else if (pGlEnableVertexAttribArray&&pGlBindVertexArray) + if (!needsDSAFramebufferHack) { - // Save the previous bound vertex array - GLint restoreVertexArray; - glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &restoreVertexArray); - pGlBindVertexArray(vaobj); - pGlEnableVertexAttribArray(index); - pGlBindVertexArray(restoreVertexArray); + if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) + { + pGlClearNamedFramebufferfv(framebuffer, buffer, drawbuffer, value); + return; + } } + + GLint boundFBO = -1; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&boundFBO); + if (boundFBO<0) + return; + + if (static_cast(boundFBO)!=framebuffer) + extGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); + pGlClearBufferfv(buffer, drawbuffer, value); + if (static_cast(boundFBO)!=framebuffer) + extGlBindFramebuffer(GL_FRAMEBUFFER,boundFBO); } -inline void COpenGLExtensionHandler::extGlDisableVertexArrayAttrib(GLuint vaobj, GLuint index) +inline void COpenGLExtensionHandler::extGlClearNamedFramebufferfi(GLuint framebuffer, GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) { - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlDisableVertexArrayAttrib) - pGlDisableVertexArrayAttrib(vaobj,index); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlDisableVertexArrayAttribEXT) - pGlDisableVertexArrayAttribEXT(vaobj,index); - } - else if (pGlDisableVertexAttribArray&&pGlBindVertexArray) + if (!needsDSAFramebufferHack) { - // Save the previous bound vertex array - GLint restoreVertexArray; - glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &restoreVertexArray); - pGlBindVertexArray(vaobj); - pGlDisableVertexAttribArray(index); - pGlBindVertexArray(restoreVertexArray); + if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) + { + pGlClearNamedFramebufferfi(framebuffer, buffer, drawbuffer, depth, stencil); + return; + } } + + GLint boundFBO = -1; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING,&boundFBO); + if (boundFBO<0) + return; + extGlBindFramebuffer(GL_FRAMEBUFFER,framebuffer); + pGlClearBufferfi(buffer, drawbuffer, depth, stencil); + extGlBindFramebuffer(GL_FRAMEBUFFER,boundFBO); } + inline void COpenGLExtensionHandler::extGlVertexArrayAttribFormat(GLuint vaobj, GLuint attribindex, GLint size, GLenum type, GLboolean normalized, GLuint relativeoffset) { if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) @@ -4043,313 +565,6 @@ inline void COpenGLExtensionHandler::extGlVertexArrayAttribLFormat(GLuint vaobj, } } -inline void COpenGLExtensionHandler::extGlVertexArrayBindingDivisor(GLuint vaobj, GLuint bindingindex, GLuint divisor) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlVertexArrayBindingDivisor) - pGlVertexArrayBindingDivisor(vaobj,bindingindex,divisor); - } - else if (FeatureAvailable[NBL_EXT_direct_state_access]) - { - if (pGlVertexArrayVertexBindingDivisorEXT) - pGlVertexArrayVertexBindingDivisorEXT(vaobj,bindingindex,divisor); - } - else if (pGlVertexBindingDivisor&&pGlBindVertexArray) - { - // Save the previous bound vertex array - GLint restoreVertexArray; - glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &restoreVertexArray); - pGlBindVertexArray(vaobj); - pGlVertexBindingDivisor(bindingindex,divisor); - pGlBindVertexArray(restoreVertexArray); - } -} - - - -inline void COpenGLExtensionHandler::extGlCreateTransformFeedbacks(GLsizei n, GLuint* ids) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlCreateTransformFeedbacks) - pGlCreateTransformFeedbacks(n,ids); - } - else - { - if (pGlGenTransformFeedbacks) - pGlGenTransformFeedbacks(n,ids); - } -} - -inline void COpenGLExtensionHandler::extGlDeleteTransformFeedbacks(GLsizei n, const GLuint* ids) -{ - if (pGlDeleteTransformFeedbacks) - pGlDeleteTransformFeedbacks(n,ids); -} - -inline void COpenGLExtensionHandler::extGlBindTransformFeedback(GLenum target, GLuint id) -{ - if (pGlBindTransformFeedback) - pGlBindTransformFeedback(target,id); -} - -inline void COpenGLExtensionHandler::extGlBeginTransformFeedback(GLenum primitiveMode) -{ - if (pGlBeginTransformFeedback) - pGlBeginTransformFeedback(primitiveMode); -} - -inline void COpenGLExtensionHandler::extGlPauseTransformFeedback() -{ - if (pGlPauseTransformFeedback) - pGlPauseTransformFeedback(); -} - -inline void COpenGLExtensionHandler::extGlResumeTransformFeedback() -{ - if (pGlResumeTransformFeedback) - pGlResumeTransformFeedback(); -} - -inline void COpenGLExtensionHandler::extGlEndTransformFeedback() -{ - if (pGlEndTransformFeedback) - pGlEndTransformFeedback(); -} - -inline void COpenGLExtensionHandler::extGlTransformFeedbackBufferBase(GLuint xfb, GLuint index, GLuint buffer) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlTransformFeedbackBufferBase) - pGlTransformFeedbackBufferBase(xfb,index,buffer); - } - else - { - GLint restoreXFormFeedback; - glGetIntegerv(GL_TRANSFORM_FEEDBACK_BINDING, &restoreXFormFeedback); - extGlBindTransformFeedback(GL_TRANSFORM_FEEDBACK,xfb); - extGlBindBuffersBase(GL_TRANSFORM_FEEDBACK_BUFFER,index,1,&buffer); - extGlBindTransformFeedback(GL_TRANSFORM_FEEDBACK,restoreXFormFeedback); - } -} - -inline void COpenGLExtensionHandler::extGlTransformFeedbackBufferRange(GLuint xfb, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) -{ - if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) - { - if (pGlTransformFeedbackBufferRange) - pGlTransformFeedbackBufferRange(xfb,index,buffer,offset,size); - } - else - { - GLint restoreXFormFeedback; - glGetIntegerv(GL_TRANSFORM_FEEDBACK_BINDING, &restoreXFormFeedback); - extGlBindTransformFeedback(GL_TRANSFORM_FEEDBACK,xfb); - extGlBindBuffersRange(GL_TRANSFORM_FEEDBACK_BUFFER,index,1,&buffer,&offset,&size); - extGlBindTransformFeedback(GL_TRANSFORM_FEEDBACK,restoreXFormFeedback); - } -} - - -inline void COpenGLExtensionHandler::extGlPrimitiveRestartIndex(GLuint index) -{ - if (pGlPrimitiveRestartIndex) - pGlPrimitiveRestartIndex(index); -} - -inline void COpenGLExtensionHandler::extGlDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instancecount) -{ - if (pGlDrawArraysInstanced) - pGlDrawArraysInstanced(mode,first,count,instancecount); -} - -inline void COpenGLExtensionHandler::extGlDrawArraysInstancedBaseInstance(GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance) -{ - if (pGlDrawArraysInstancedBaseInstance) - pGlDrawArraysInstancedBaseInstance(mode,first,count,instancecount,baseinstance); -} - -inline void COpenGLExtensionHandler::extGlDrawElementsInstancedBaseVertex(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex) -{ - if (pGlDrawElementsInstancedBaseVertex) - pGlDrawElementsInstancedBaseVertex(mode,count,type,indices,instancecount,basevertex); -} - -inline void COpenGLExtensionHandler::extGlDrawElementsInstancedBaseVertexBaseInstance(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount, GLint basevertex, GLuint baseinstance) -{ - if (pGlDrawElementsInstancedBaseVertexBaseInstance) - pGlDrawElementsInstancedBaseVertexBaseInstance(mode,count,type,indices,instancecount,basevertex,baseinstance); -} - -inline void COpenGLExtensionHandler::extGlDrawTransformFeedback(GLenum mode, GLuint id) -{ - if (pGlDrawTransformFeedback) - pGlDrawTransformFeedback(mode,id); -} - -inline void COpenGLExtensionHandler::extGlDrawTransformFeedbackInstanced(GLenum mode, GLuint id, GLsizei instancecount) -{ - if (pGlDrawTransformFeedbackInstanced) - pGlDrawTransformFeedbackInstanced(mode,id,instancecount); -} - -inline void COpenGLExtensionHandler::extGlDrawTransformFeedbackStream(GLenum mode, GLuint id, GLuint stream) -{ - if (pGlDrawTransformFeedbackStream) - pGlDrawTransformFeedbackStream(mode,id,stream); -} - -inline void COpenGLExtensionHandler::extGlDrawTransformFeedbackStreamInstanced(GLenum mode, GLuint id, GLuint stream, GLsizei instancecount) -{ - if (pGlDrawTransformFeedbackStreamInstanced) - pGlDrawTransformFeedbackStreamInstanced(mode,id,stream,instancecount); -} - -inline void COpenGLExtensionHandler::extGlDrawArraysIndirect(GLenum mode, const void *indirect) -{ - if (pGlDrawArraysIndirect) - pGlDrawArraysIndirect(mode,indirect); -} - -inline void COpenGLExtensionHandler::extGlDrawElementsIndirect(GLenum mode, GLenum type, const void *indirect) -{ - if (pGlDrawElementsIndirect) - pGlDrawElementsIndirect(mode,type,indirect); -} - -inline void COpenGLExtensionHandler::extGlMultiDrawArraysIndirect(GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride) -{ - if (pGlMultiDrawArraysIndirect) - pGlMultiDrawArraysIndirect(mode,indirect,drawcount,stride); -} - -inline void COpenGLExtensionHandler::extGlMultiDrawElementsIndirect(GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride) -{ - if (pGlMultiDrawElementsIndirect) - pGlMultiDrawElementsIndirect(mode,type,indirect,drawcount,stride); -} - -inline void COpenGLExtensionHandler::extGlMultiDrawArraysIndirectCount(GLenum mode, const void * indirect, GLintptr drawcount, GLintptr maxdrawcount, GLsizei stride) -{ - if (pGlMultiDrawArrysIndirectCount) - pGlMultiDrawArrysIndirectCount(mode, indirect, drawcount, maxdrawcount, stride); -} - -inline void COpenGLExtensionHandler::extGlMultiDrawElementsIndirectCount(GLenum mode, GLenum type, const void * indirect, GLintptr drawcount, GLintptr maxdrawcount, GLsizei stride) -{ - if (pGlMultiDrawElementsIndirectCount) - pGlMultiDrawElementsIndirectCount(mode, type, indirect, drawcount, maxdrawcount, stride); -} - - - -// ROP -inline void COpenGLExtensionHandler::extGlBlendColor(float red, float green, float blue, float alpha) -{ - if (pGlBlendColor) - pGlBlendColor(red,green,blue,alpha); -} -inline void COpenGLExtensionHandler::extGlDepthRangeIndexed(GLuint index, GLdouble nearVal, GLdouble farVal) -{ - if (pGlDepthRangeIndexed) - pGlDepthRangeIndexed(index,nearVal,farVal); -} -inline void COpenGLExtensionHandler::extGlViewportIndexedfv(GLuint index, const GLfloat* v) -{ - if (pGlViewportIndexedfv) - pGlViewportIndexedfv(index,v); -} -inline void COpenGLExtensionHandler::extGlScissorIndexedv(GLuint index, const GLint* v) -{ - if (pGlScissorIndexedv) - pGlScissorIndexedv(index,v); -} -inline void COpenGLExtensionHandler::extGlSampleCoverage(float value, bool invert) -{ - if (pGlSampleCoverage) - pGlSampleCoverage(value,invert); -} -inline void COpenGLExtensionHandler::extGlSampleMaski(GLuint maskNumber, GLbitfield mask) -{ - if (pGlSampleMaski) - pGlSampleMaski(maskNumber,mask); -} -inline void COpenGLExtensionHandler::extGlMinSampleShading(float value) -{ - if (pGlMinSampleShading) - pGlMinSampleShading(value); -} -inline void COpenGLExtensionHandler::extGlBlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeAlpha) -{ - if (pGlBlendEquationSeparatei) - pGlBlendEquationSeparatei(buf,modeRGB,modeAlpha); -} -inline void COpenGLExtensionHandler::extGlBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) -{ - if (pGlBlendFuncSeparatei) - pGlBlendFuncSeparatei(buf,srcRGB,dstRGB,srcAlpha,dstAlpha); -} -inline void COpenGLExtensionHandler::extGlColorMaski(GLuint buf, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) -{ - if (pGlColorMaski) - pGlColorMaski(buf,red,green,blue,alpha); -} - - - -inline void COpenGLExtensionHandler::extGlBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) -{ - if (pGlBlendFuncSeparate) - pGlBlendFuncSeparate(srcRGB,dstRGB,srcAlpha,dstAlpha); -} - - -inline void COpenGLExtensionHandler::extGlColorMaskIndexed(GLuint buf, GLboolean r, GLboolean g, GLboolean b, GLboolean a) -{ - if (pGlColorMaski) - pGlColorMaski(buf, r, g, b, a); -} - - -inline void COpenGLExtensionHandler::extGlEnableIndexed(GLenum target, GLuint index) -{ - if (pGlEnablei) - pGlEnablei(target, index); -} - -inline void COpenGLExtensionHandler::extGlDisableIndexed(GLenum target, GLuint index) -{ - if (pGlDisablei) - pGlDisablei(target, index); -} - -inline void COpenGLExtensionHandler::extGlBlendFuncIndexed(GLuint buf, GLenum src, GLenum dst) -{ - pGlBlendFunciARB(buf, src, dst); -} - -inline void COpenGLExtensionHandler::extGlBlendEquationIndexed(GLuint buf, GLenum mode) -{ - pGlBlendEquationiARB(buf, mode); -} - -inline void COpenGLExtensionHandler::extGlPatchParameterfv(GLenum pname, const float* values) -{ - pGlPatchParameterfv(pname, values); -} - -inline void COpenGLExtensionHandler::extGlPatchParameteri(GLenum pname, GLuint value) -{ - pGlPatchParameteri(pname, value); -} - -inline void COpenGLExtensionHandler::extGlProgramParameteri(GLuint program, GLenum pname, GLint value) -{ - pGlProgramParameteri(program, pname, value); -} - inline void COpenGLExtensionHandler::extGlCreateQueries(GLenum target, GLsizei n, GLuint *ids) { if (Version>=450||FeatureAvailable[NBL_ARB_direct_state_access]) @@ -4363,45 +578,6 @@ inline void COpenGLExtensionHandler::extGlCreateQueries(GLenum target, GLsizei n pGlGenQueries(n, ids); } } - -inline void COpenGLExtensionHandler::extGlDeleteQueries(GLsizei n, const GLuint *ids) -{ - if (pGlDeleteQueries) - pGlDeleteQueries(n, ids); -} - -inline GLboolean COpenGLExtensionHandler::extGlIsQuery(GLuint id) -{ - if (pGlIsQuery) - return pGlIsQuery(id); - return false; -} - -inline void COpenGLExtensionHandler::extGlBeginQuery(GLenum target, GLuint id) -{ - if (pGlBeginQuery) - pGlBeginQuery(target, id); -} - -inline void COpenGLExtensionHandler::extGlEndQuery(GLenum target) -{ - if (pGlEndQuery) - pGlEndQuery(target); -} - -inline void COpenGLExtensionHandler::extGlBeginQueryIndexed(GLenum target, GLuint index, GLuint id) -{ - if (pGlBeginQueryIndexed) - pGlBeginQueryIndexed(target, index, id); -} - -inline void COpenGLExtensionHandler::extGlEndQueryIndexed(GLenum target, GLuint index) -{ - if (pGlEndQueryIndexed) - pGlEndQueryIndexed(target, index); -} - - inline void COpenGLExtensionHandler::extGlGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) { if (pGlGetQueryObjectuiv) @@ -4472,18 +648,6 @@ inline void COpenGLExtensionHandler::extGlQueryCounter(GLuint id, GLenum target) pGlQueryCounter(id, target); } -inline void COpenGLExtensionHandler::extGlBeginConditionalRender(GLuint id, GLenum mode) -{ - if (pGlBeginConditionalRender) - pGlBeginConditionalRender(id, mode); -} - -inline void COpenGLExtensionHandler::extGlEndConditionalRender() -{ - if (pGlEndConditionalRender) - pGlEndConditionalRender(); -} - inline void COpenGLExtensionHandler::extGlTextureBarrier() { @@ -4526,27 +690,19 @@ inline void COpenGLExtensionHandler::extGlSwapInterval(int interval) #endif } -inline void COpenGLExtensionHandler::extGlBlendEquation(GLenum mode) -{ - pGlBlendEquation(mode); -} inline void COpenGLExtensionHandler::extGlGetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params) { - if (Version>=460 || FeatureAvailable[NBL_ARB_internalformat_query]) - { if (pGlGetInternalformativ) pGlGetInternalformativ(target, internalformat, pname, bufSize, params); - } + } inline void COpenGLExtensionHandler::extGlGetInternalformati64v(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint64* params) { - if (Version>=460 || FeatureAvailable[NBL_ARB_internalformat_query]) - { if (pGlGetInternalformati64v) pGlGetInternalformati64v(target, internalformat, pname, bufSize, params); - } + } } diff --git a/source/Nabla/COpenGLQuery.cpp b/source/Nabla/COpenGLQuery.cpp deleted file mode 100644 index 5a666525ec..0000000000 --- a/source/Nabla/COpenGLQuery.cpp +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#include "COpenGLQuery.h" -#include "COpenGLBuffer.h" -#include "COpenGLExtensionHandler.h" - -#ifdef _NBL_COMPILE_WITH_OPENGL_ -namespace nbl -{ -namespace video -{ - -COpenGLQuery::COpenGLQuery(const GLenum& type_in) : object(0), type(type_in), active(false), queryNeedsUpdate(false), queryIsReady(true), cachedCounter32(0), cachedCounter64(0) -{ - COpenGLExtensionHandler::extGlCreateQueries(type,1,&object); - - switch (type) - { - case GL_PRIMITIVES_GENERATED: - cachedIrrType = EQOT_PRIMITIVES_GENERATED; - break; - case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: - cachedIrrType = EQOT_XFORM_FEEDBACK_PRIMITIVES_WRITTEN; - break; - case GL_TIME_ELAPSED: - cachedIrrType = EQOT_TIME_ELAPSED; - break; - default: - cachedIrrType = EQOT_COUNT; - break; - } -} - -COpenGLQuery::~COpenGLQuery() -{ - COpenGLExtensionHandler::extGlDeleteQueries(1,&object); -} - -void COpenGLQuery::updateQueryResult() -{ - if (queryNeedsUpdate) - { - switch (cachedIrrType) - { - case EQOT_PRIMITIVES_GENERATED: - case EQOT_XFORM_FEEDBACK_PRIMITIVES_WRITTEN: - COpenGLExtensionHandler::extGlGetQueryObjectuiv(object,GL_QUERY_RESULT,&cachedCounter32); - cachedCounter64 = cachedCounter32; - break; - default: - COpenGLExtensionHandler::extGlGetQueryObjectui64v(object,GL_QUERY_RESULT,&cachedCounter64); - cachedCounter32 = cachedCounter64; - break; - } - } - queryNeedsUpdate = false; - queryIsReady = true; -} - -void COpenGLQuery::getQueryResult(uint32_t* queryResult) -{ -#ifdef _NBL_DEBUG - if (active) - { - os::Printer::log("CANNOT FETCH QUERY RESULT WHILE THE QUERY IS RUNNING!\n",ELL_ERROR); - return; - } -#endif // _NBL_DEBUG - - updateQueryResult(); - *queryResult = cachedCounter32; -} - -void COpenGLQuery::getQueryResult(uint64_t* queryResult) -{ -#ifdef _NBL_DEBUG - if (active) - { - os::Printer::log("CANNOT FETCH QUERY RESULT WHILE THE QUERY IS RUNNING!\n",ELL_ERROR); - return; - } -#endif // _NBL_DEBUG - - updateQueryResult(); - *queryResult = cachedCounter64; -} - -bool COpenGLQuery::getQueryResult32(IGPUBuffer* buffer, const size_t& offset, const bool& conditionalWrite) -{ -#ifdef _NBL_DEBUG - if (active) - { - os::Printer::log("CANNOT FETCH QUERY RESULT WHILE THE QUERY IS RUNNING!\n",ELL_ERROR); - return false; - } -#endif // _NBL_DEBUG - - COpenGLBuffer* asGLBuf = static_cast(buffer); - if (!asGLBuf) - { -#ifdef _NBL_DEBUG - os::Printer::log("CANNOT FETCH QUERY RESULT, buffer is NULL or not OpenGLBuffer!\n",ELL_ERROR); -#endif // _NBL_DEBUG - return false; - } - - COpenGLExtensionHandler::extGlGetQueryBufferObjectuiv(object,asGLBuf->getOpenGLName(),conditionalWrite ? GL_QUERY_RESULT_NO_WAIT:GL_QUERY_RESULT,offset); - return COpenGLExtensionHandler::Version>=440&&COpenGLExtensionHandler::FeatureAvailable[COpenGLExtensionHandler::NBL_ARB_query_buffer_object]; -} - -bool COpenGLQuery::getQueryResult64(IGPUBuffer* buffer, const size_t& offset, const bool& conditionalWrite) -{ -#ifdef _NBL_DEBUG - if (active) - { - os::Printer::log("CANNOT FETCH QUERY RESULT WHILE THE QUERY IS RUNNING!\n",ELL_ERROR); - return false; - } -#endif // _NBL_DEBUG - - COpenGLBuffer* asGLBuf = static_cast(buffer); - if (!asGLBuf) - { -#ifdef _NBL_DEBUG - os::Printer::log("CANNOT FETCH QUERY RESULT, buffer is NULL or not OpenGLBuffer!\n",ELL_ERROR); -#endif // _NBL_DEBUG - return false; - } - - COpenGLExtensionHandler::extGlGetQueryBufferObjectui64v(object,asGLBuf->getOpenGLName(),conditionalWrite ? GL_QUERY_RESULT_NO_WAIT:GL_QUERY_RESULT,offset); - return COpenGLExtensionHandler::Version>=440&&COpenGLExtensionHandler::FeatureAvailable[COpenGLExtensionHandler::NBL_ARB_query_buffer_object]; -} - - -bool COpenGLQuery::isQueryReady() -{ - if (active) - return false; - - if (!queryNeedsUpdate || queryIsReady) - return true; - - GLuint available = GL_FALSE; - COpenGLExtensionHandler::extGlGetQueryObjectuiv(object,GL_QUERY_RESULT_AVAILABLE,&available); - queryIsReady = available!=GL_FALSE; - - return queryIsReady; -} - -void COpenGLQuery::isQueryReady32(IGPUBuffer* buffer, const size_t& offset) -{ -#ifdef _NBL_DEBUG - if (active) - { - os::Printer::log("CANNOT FETCH QUERY RESULT WHILE THE QUERY IS RUNNING!\n",ELL_ERROR); - return; - } -#endif // _NBL_DEBUG - - COpenGLBuffer* asGLBuf = static_cast(buffer); - if (!asGLBuf) - { -#ifdef _NBL_DEBUG - os::Printer::log("CANNOT FETCH QUERY RESULT, buffer is NULL or not OpenGLBuffer!\n",ELL_ERROR); -#endif // _NBL_DEBUG - return; - } - - COpenGLExtensionHandler::extGlGetQueryBufferObjectuiv(object,asGLBuf->getOpenGLName(),GL_QUERY_RESULT_AVAILABLE,offset); -} - -void COpenGLQuery::isQueryReady64(IGPUBuffer* buffer, const size_t& offset) -{ - //if (COpenGLExtensionHandler::Version<440 && !COpenGLExtensionHandler::FeatureAvailable[NBL_ARB_query_buffer_object]) -#ifdef _NBL_DEBUG - if (active) - { - os::Printer::log("CANNOT FETCH QUERY RESULT WHILE THE QUERY IS RUNNING!\n",ELL_ERROR); - return; - } -#endif // _NBL_DEBUG - - COpenGLBuffer* asGLBuf = static_cast(buffer); - if (!asGLBuf) - { -#ifdef _NBL_DEBUG - os::Printer::log("CANNOT FETCH QUERY RESULT, buffer is NULL or not OpenGLBuffer!\n",ELL_ERROR); -#endif // _NBL_DEBUG - return; - } - - COpenGLExtensionHandler::extGlGetQueryBufferObjectui64v(object,asGLBuf->getOpenGLName(),GL_QUERY_RESULT_AVAILABLE,offset); -} - - -} -} -#endif // _NBL_COMPILE_WITH_OPENGL_ diff --git a/source/Nabla/COpenGLQuery.h b/source/Nabla/COpenGLQuery.h deleted file mode 100644 index 6fbddd0840..0000000000 --- a/source/Nabla/COpenGLQuery.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#ifndef __NBL_C_OPENGL_QUERY_H_INCLUDED__ -#define __NBL_C_OPENGL_QUERY_H_INCLUDED__ - -#include "IQueryObject.h" - -#ifdef _NBL_COMPILE_WITH_OPENGL_ -#include "COpenGLExtensionHandler.h" - -namespace nbl -{ -namespace video -{ - -class COpenGLQuery : public IQueryObject -{ - protected: - virtual ~COpenGLQuery(); - - public: - COpenGLQuery(const GLenum& type_in); - - virtual E_QUERY_OBJECT_TYPE getQueryObjectType() const {return cachedIrrType;} - - virtual void getQueryResult(uint32_t* queryResult); - virtual void getQueryResult(uint64_t* queryResult); - virtual bool getQueryResult32(IGPUBuffer* buffer, const size_t& offset=0, const bool& conditionalWrite=true); - virtual bool getQueryResult64(IGPUBuffer* buffer, const size_t& offset=0, const bool& conditionalWrite=true); - - virtual bool isQueryReady(); - virtual void isQueryReady32(IGPUBuffer* buffer, const size_t& offset=0); - virtual void isQueryReady64(IGPUBuffer* buffer, const size_t& offset=0); - - inline GLenum getType() const {return type;} - inline GLuint getGLHandle() const {return object;} - - inline void flagBegun() {active=true; queryIsReady=false;} - inline void flagEnded() {active=false; queryNeedsUpdate=true;} - inline bool isActive() const {return active;} - - private: - GLuint object; - GLenum type; - E_QUERY_OBJECT_TYPE cachedIrrType; - - void updateQueryResult(); - - bool active; - bool queryNeedsUpdate; - bool queryIsReady; - GLuint cachedCounter32; - GLuint64 cachedCounter64; -}; - - -} -} -#endif // _NBL_COMPILE_WITH_OPENGL_ - -#endif - diff --git a/source/Nabla/COpenGLTimestampQuery.h b/source/Nabla/COpenGLTimestampQuery.h deleted file mode 100644 index 846bfd06d0..0000000000 --- a/source/Nabla/COpenGLTimestampQuery.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#ifndef __NBL_C_OPENGL_TIMESTAMP_QUERY_H_INCLUDED__ -#define __NBL_C_OPENGL_TIMESTAMP_QUERY_H_INCLUDED__ - -#include "IGPUTimestampQuery.h" -#ifdef _NBL_COMPILE_WITH_OPENGL_ -#include "COpenGLExtensionHandler.h" - -namespace nbl -{ -namespace video -{ - - -class COpenGLTimestampQuery : public IGPUTimestampQuery -{ - protected: - virtual ~COpenGLTimestampQuery() - { - COpenGLExtensionHandler::extGlDeleteQueries(1,&object); - } - - public: - COpenGLTimestampQuery() : object(0), ready(false), hasResult(false), cachedCompletedTime(0xdeadbeefbadc0ffeu) - { - COpenGLExtensionHandler::extGlCreateQueries(GL_TIMESTAMP,1,&object); - COpenGLExtensionHandler::extGlQueryCounter(object,GL_TIMESTAMP); - } - - virtual bool isQueryReady() - { - if (ready) - return true; - - GLuint available = GL_FALSE; - COpenGLExtensionHandler::extGlGetQueryObjectuiv(object,GL_QUERY_RESULT_AVAILABLE,&available); - ready = available!=GL_FALSE; - - return ready; - } - - virtual uint64_t getTimestampWhenCompleted() - { - if (hasResult) - return cachedCompletedTime; - - COpenGLExtensionHandler::extGlGetQueryObjectui64v(object,GL_QUERY_RESULT,&cachedCompletedTime); - return cachedCompletedTime; - } - private: - GLuint object; - - bool ready; - bool hasResult; - uint64_t cachedCompletedTime; -}; - -} -} -#endif // _NBL_COMPILE_WITH_OPENGL_ - -#endif - - From e74a368615351d339da69c6ed41817eab8a17327 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 16:21:50 +0100 Subject: [PATCH 14/91] remove correctly replaced legacy code and joystick stuff from IrrDeviceWin32 --- source/Nabla/CIrrDeviceWin32.cpp | 531 ------------------------------- source/Nabla/CIrrDeviceWin32.h | 31 +- 2 files changed, 1 insertion(+), 561 deletions(-) diff --git a/source/Nabla/CIrrDeviceWin32.cpp b/source/Nabla/CIrrDeviceWin32.cpp index f6bc59c956..853108b2bf 100644 --- a/source/Nabla/CIrrDeviceWin32.cpp +++ b/source/Nabla/CIrrDeviceWin32.cpp @@ -10,413 +10,10 @@ #include "CNullDriver.h" #include "CIrrDeviceWin32.h" -#include "CSceneManager.h" #include "IEventReceiver.h" -#include #include "nbl_os.h" -#include "nbl/asset/IAssetManager.h" #include "COSOperator.h" -#include "dimension2d.h" -#include -#include "nbl/core/Types.h" -#if defined(_NBL_COMPILE_WITH_JOYSTICK_EVENTS_) -#ifdef _NBL_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ -#define DIRECTINPUT_VERSION 0x0800 -#include -#ifdef _MSC_VER -#pragma comment(lib, "dinput8.lib") -#pragma comment(lib, "dxguid.lib") -#endif -#else -#ifdef _MSC_VER -#pragma comment(lib, "winmm.lib") -#endif -#endif -#endif - -namespace nbl -{ -struct SJoystickWin32Control -{ - CIrrDeviceWin32* Device; - -#if defined(_NBL_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_NBL_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) - IDirectInput8* DirectInputDevice; -#endif -#if defined(_NBL_COMPILE_WITH_JOYSTICK_EVENTS_) - struct JoystickInfo - { - uint32_t Index; -#ifdef _NBL_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ - core::stringc Name; - GUID guid; - LPDIRECTINPUTDEVICE8 lpdijoy; - DIDEVCAPS devcaps; - uint8_t axisValid[8]; -#else - JOYCAPS Caps; -#endif - }; - core::vector ActiveJoysticks; -#endif - - SJoystickWin32Control(CIrrDeviceWin32* dev) : Device(dev) - { -#if defined(_NBL_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_NBL_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) - DirectInputDevice=0; - if (DI_OK != (DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&DirectInputDevice, NULL))) - { - os::Printer::log("Could not create DirectInput8 Object", ELL_WARNING); - return; - } -#endif - } - ~SJoystickWin32Control() - { -#if defined(_NBL_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_NBL_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) - for(uint32_t joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) - { - LPDIRECTINPUTDEVICE8 dev = ActiveJoysticks[joystick].lpdijoy; - if (dev) - { - dev->Unacquire(); - } - dev->Release(); - } - - if (DirectInputDevice) - DirectInputDevice->Release(); -#endif - } - -#if defined(_NBL_COMPILE_WITH_JOYSTICK_EVENTS_) && defined(_NBL_COMPILE_WITH_DIRECTINPUT_JOYSTICK_) - static BOOL CALLBACK EnumJoysticks(LPCDIDEVICEINSTANCE lpddi, LPVOID cp) - { - SJoystickWin32Control* p=(SJoystickWin32Control*)cp; - p->directInputAddJoystick(lpddi); - return DIENUM_CONTINUE; - } - void directInputAddJoystick(LPCDIDEVICEINSTANCE lpddi) - { - //Get the GUID of the joystuck - const GUID guid = lpddi->guidInstance; - - JoystickInfo activeJoystick; - activeJoystick.Index=ActiveJoysticks.size(); - activeJoystick.guid=guid; - activeJoystick.Name=lpddi->tszProductName; - if (FAILED(DirectInputDevice->CreateDevice(guid, &activeJoystick.lpdijoy, NULL))) - { - os::Printer::log("Could not create DirectInput device", ELL_WARNING); - return; - } - - activeJoystick.devcaps.dwSize=sizeof(activeJoystick.devcaps); - if (FAILED(activeJoystick.lpdijoy->GetCapabilities(&activeJoystick.devcaps))) - { - os::Printer::log("Could not create DirectInput device", ELL_WARNING); - return; - } - - if (FAILED(activeJoystick.lpdijoy->SetCooperativeLevel(Device->HWnd, DISCL_BACKGROUND | DISCL_EXCLUSIVE))) - { - os::Printer::log("Could not set DirectInput device cooperative level", ELL_WARNING); - return; - } - - if (FAILED(activeJoystick.lpdijoy->SetDataFormat(&c_dfDIJoystick2))) - { - os::Printer::log("Could not set DirectInput device data format", ELL_WARNING); - return; - } - - if (FAILED(activeJoystick.lpdijoy->Acquire())) - { - os::Printer::log("Could not set DirectInput cooperative level", ELL_WARNING); - return; - } - - DIJOYSTATE2 info; - if (FAILED(activeJoystick.lpdijoy->GetDeviceState(sizeof(info),&info))) - { - os::Printer::log("Could not read DirectInput device state", ELL_WARNING); - return; - } - - ZeroMemory(activeJoystick.axisValid,sizeof(activeJoystick.axisValid)); - activeJoystick.axisValid[0]= (info.lX!=0) ? 1 : 0; - activeJoystick.axisValid[1]= (info.lY!=0) ? 1 : 0; - activeJoystick.axisValid[2]= (info.lZ!=0) ? 1 : 0; - activeJoystick.axisValid[3]= (info.lRx!=0) ? 1 : 0; - activeJoystick.axisValid[4]= (info.lRy!=0) ? 1 : 0; - activeJoystick.axisValid[5]= (info.lRz!=0) ? 1 : 0; - - int caxis=0; - for (uint8_t i=0; i<6; i++) - { - if (activeJoystick.axisValid[i]) - caxis++; - } - - for (uint8_t i=0; i<(activeJoystick.devcaps.dwAxes)-caxis; i++) - { - if (i+caxis < 8) - activeJoystick.axisValid[i+caxis]=1; - } - - ActiveJoysticks.push_back(activeJoystick); - } -#endif - -void pollJoysticks() -{ -#if defined _NBL_COMPILE_WITH_JOYSTICK_EVENTS_ -#ifdef _NBL_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ - if(0 == ActiveJoysticks.size()) - return; - - uint32_t joystick; - DIJOYSTATE2 info; - - for(joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) - { - // needs to be reset for each joystick - // request ALL values and POV as continuous if possible - - const DIDEVCAPS & caps = ActiveJoysticks[joystick].devcaps; - // if no POV is available don't ask for POV values - - if (!FAILED(ActiveJoysticks[joystick].lpdijoy->GetDeviceState(sizeof(info),&info))) - { - SEvent event; - - event.EventType = nbl::EET_JOYSTICK_INPUT_EVENT; - event.JoystickEvent.Joystick = (uint8_t)joystick; - - event.JoystickEvent.POV = (uint16_t)info.rgdwPOV[0]; - // set to undefined if no POV value was returned or the value - // is out of range - if ((caps.dwPOVs==0) || (event.JoystickEvent.POV > 35900)) - event.JoystickEvent.POV = 65535; - - for(int axis = 0; axis < SEvent::SJoystickEvent::NUMBER_OF_AXES; ++axis) - event.JoystickEvent.Axis[axis] = 0; - - uint16_t dxAxis=0; - uint16_t irrAxis=0; - - while (dxAxis < 6 && irrAxis 0) - axisFound=1; - - if (axisFound) - { - int32_t val=axisValue - 32768; - - if (val <-32767) val=-32767; - if (val > 32767) val=32767; - event.JoystickEvent.Axis[irrAxis]=(int16_t)(val); - irrAxis++; - } - - dxAxis++; - } - uint32_t buttons=0; - BYTE* bytebuttons=info.rgbButtons; - for (uint16_t i=0; i<32; i++) - { - if (bytebuttons[i] >0) - { - buttons |= (1 << i); - } - } - event.JoystickEvent.ButtonStates = buttons; - - (void)Device->postEventFromUser(event); - } - } -#else - if (0 == ActiveJoysticks.size()) - return; - - uint32_t joystick; - JOYINFOEX info; - - for(joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) - { - // needs to be reset for each joystick - // request ALL values and POV as continuous if possible - info.dwSize = sizeof(info); - info.dwFlags = JOY_RETURNALL|JOY_RETURNPOVCTS; - const JOYCAPS & caps = ActiveJoysticks[joystick].Caps; - // if no POV is available don't ask for POV values - if (!(caps.wCaps & JOYCAPS_HASPOV)) - info.dwFlags &= ~(JOY_RETURNPOV|JOY_RETURNPOVCTS); - if(JOYERR_NOERROR == joyGetPosEx(ActiveJoysticks[joystick].Index, &info)) - { - SEvent event; - - event.EventType = nbl::EET_JOYSTICK_INPUT_EVENT; - event.JoystickEvent.Joystick = (uint8_t)joystick; - - event.JoystickEvent.POV = (uint16_t)info.dwPOV; - // set to undefined if no POV value was returned or the value - // is out of range - if (!(info.dwFlags & JOY_RETURNPOV) || (event.JoystickEvent.POV > 35900)) - event.JoystickEvent.POV = 65535; - - for(int axis = 0; axis < SEvent::SJoystickEvent::NUMBER_OF_AXES; ++axis) - event.JoystickEvent.Axis[axis] = 0; - - event.JoystickEvent.ButtonStates = info.dwButtons; - - switch(caps.wNumAxes) - { - default: - case 6: - event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_V] = - (int16_t)((65535 * (info.dwVpos - caps.wVmin)) / (caps.wVmax - caps.wVmin) - 32768); - - case 5: - event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_U] = - (int16_t)((65535 * (info.dwUpos - caps.wUmin)) / (caps.wUmax - caps.wUmin) - 32768); - - case 4: - event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_R] = - (int16_t)((65535 * (info.dwRpos - caps.wRmin)) / (caps.wRmax - caps.wRmin) - 32768); - - case 3: - event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Z] = - (int16_t)((65535 * (info.dwZpos - caps.wZmin)) / (caps.wZmax - caps.wZmin) - 32768); - - case 2: - event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Y] = - (int16_t)((65535 * (info.dwYpos - caps.wYmin)) / (caps.wYmax - caps.wYmin) - 32768); - - case 1: - event.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_X] = - (int16_t)((65535 * (info.dwXpos - caps.wXmin)) / (caps.wXmax - caps.wXmin) - 32768); - } - - (void)Device->postEventFromUser(event); - } - } -#endif -#endif // _NBL_COMPILE_WITH_JOYSTICK_EVENTS_ -} - -bool activateJoysticks(core::vector & joystickInfo) -{ -#if defined _NBL_COMPILE_WITH_JOYSTICK_EVENTS_ -#ifdef _NBL_COMPILE_WITH_DIRECTINPUT_JOYSTICK_ - if (!DirectInputDevice || (DirectInputDevice->EnumDevices(DI8DEVCLASS_GAMECTRL, SJoystickWin32Control::EnumJoysticks, this, DIEDFL_ATTACHEDONLY ))) - { - os::Printer::log("Could not enum DirectInput8 controllers", ELL_WARNING); - return false; - } - - for(uint32_t joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) - { - JoystickInfo& activeJoystick = ActiveJoysticks[joystick]; - SJoystickInfo info; - info.Axes=activeJoystick.devcaps.dwAxes; - info.Buttons=activeJoystick.devcaps.dwButtons; - info.Name=activeJoystick.Name; - info.PovHat = (activeJoystick.devcaps.dwPOVs != 0) - ? SJoystickInfo::POV_HAT_PRESENT : SJoystickInfo::POV_HAT_ABSENT; - joystickInfo.push_back(info); - } - return true; -#else - joystickInfo.clear(); - ActiveJoysticks.clear(); - - const uint32_t numberOfJoysticks = ::joyGetNumDevs(); - JOYINFOEX info; - info.dwSize = sizeof(info); - info.dwFlags = JOY_RETURNALL; - - JoystickInfo activeJoystick; - SJoystickInfo returnInfo; - - joystickInfo.reserve(numberOfJoysticks); - ActiveJoysticks.reserve(numberOfJoysticks); - - uint32_t joystick = 0; - for(; joystick < numberOfJoysticks; ++joystick) - { - if(JOYERR_NOERROR == joyGetPosEx(joystick, &info) - && - JOYERR_NOERROR == joyGetDevCaps(joystick, - &activeJoystick.Caps, - sizeof(activeJoystick.Caps))) - { - activeJoystick.Index = joystick; - ActiveJoysticks.push_back(activeJoystick); - - returnInfo.Joystick = (uint8_t)joystick; - returnInfo.Axes = activeJoystick.Caps.wNumAxes; - returnInfo.Buttons = activeJoystick.Caps.wNumButtons; - returnInfo.Name = activeJoystick.Caps.szPname; - returnInfo.PovHat = ((activeJoystick.Caps.wCaps & JOYCAPS_HASPOV) == JOYCAPS_HASPOV) - ? SJoystickInfo::POV_HAT_PRESENT : SJoystickInfo::POV_HAT_ABSENT; - - joystickInfo.push_back(returnInfo); - } - } - - for(joystick = 0; joystick < joystickInfo.size(); ++joystick) - { - char logString[256]; - (void)sprintf(logString, "Found joystick %d, %d axes, %d buttons '%s'", - joystick, joystickInfo[joystick].Axes, - joystickInfo[joystick].Buttons, joystickInfo[joystick].Name.c_str()); - os::Printer::log(logString, ELL_INFORMATION); - } - - return true; -#endif -#else - return false; -#endif // _NBL_COMPILE_WITH_JOYSTICK_EVENTS_ -} -}; -} // end namespace nbl // Get the codepage from the locale language id // Based on the table from http://www.science.co.il/Language/Locale-Codes.asp?s=decimal @@ -578,39 +175,6 @@ static unsigned int LocaleIdToCodepage(unsigned int lcid) return 65001; // utf-8 } -namespace -{ - struct SEnvMapper - { - HWND hWnd; - nbl::CIrrDeviceWin32* irrDev; - }; - nbl::core::list EnvMap; - - HKL KEYBOARD_INPUT_HKL=0; - unsigned int KEYBOARD_INPUT_CODEPAGE = 1252; -} - -SEnvMapper* getEnvMapperFromHWnd(HWND hWnd) -{ - nbl::core::list::iterator it = EnvMap.begin(); - for (; it!= EnvMap.end(); ++it) - if ((*it).hWnd == hWnd) - return &(*it); - - return 0; -} - - -nbl::CIrrDeviceWin32* getDeviceFromHWnd(HWND hWnd) -{ - nbl::core::list::iterator it = EnvMap.begin(); - for (; it!= EnvMap.end(); ++it) - if ((*it).hWnd == hWnd) - return (*it).irrDev; - - return 0; -} LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) @@ -894,16 +458,9 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params) : CIrrDeviceStub(params), HWnd(0), ChangedToFullScreen(false), Resized(false), ExternalWindow(false), Win32CursorControl(0), JoyControl(0) { - #ifdef _NBL_DEBUG - setDebugName("CIrrDeviceWin32"); - #endif - // get windows version and create OS operator core::stringc winversion; getWindowsVersion(winversion); - Operator = new COSOperator(winversion); - os::Printer::log(winversion.c_str(), ELL_INFORMATION); - // get handle to exe file HINSTANCE hInstance = GetModuleHandle(0); @@ -997,30 +554,14 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params) Win32CursorControl = new CCursorControl(this, CreationParams.WindowSize, HWnd, CreationParams.Fullscreen); CursorControl = Win32CursorControl; - JoyControl = new SJoystickWin32Control(this); // initialize doubleclicks with system values MouseMultiClicks.DoubleClickTime = GetDoubleClickTime(); -#ifdef _NBL_COMPILE_WITH_CUDA_ - cuda::CCUDAHandler::init(); -#endif // _NBL_COMPILE_WITH_CUDA_ -#ifdef _NBL_COMPILE_WITH_OPENCL_ - ocl::COpenCLHandler::enumeratePlatformsAndDevices(); -#endif // _NBL_COMPILE_WITH_OPENCL_ // create driver createDriver(); - if (VideoDriver) - createGUIAndScene(); - - // register environment - - SEnvMapper em; - em.irrDev = this; - em.hWnd = HWnd; - EnvMap.push_back(em); // set this as active window if (!ExternalWindow) @@ -1038,36 +579,6 @@ CIrrDeviceWin32::CIrrDeviceWin32(const SIrrlichtCreationParameters& params) } -//! destructor -CIrrDeviceWin32::~CIrrDeviceWin32() -{ - delete JoyControl; - - // unregister environment - - auto it = EnvMap.begin(); - for (; it!= EnvMap.end(); ++it) - { - if ((*it).hWnd == HWnd) - { - EnvMap.erase(it); - break; - } - } - - switchToFullscreen(true); - - if (SceneManager) - SceneManager->drop(); - - if (InputReceivingSceneManager) - InputReceivingSceneManager->drop(); - - if (CursorControl) - CursorControl->drop(); -} - - //! runs the device. Returns false if device wants to be deleted bool CIrrDeviceWin32::run() { @@ -1080,19 +591,10 @@ bool CIrrDeviceWin32::run() if (!Close) resizeIfNecessary(); - if(!Close && JoyControl) - JoyControl->pollJoysticks(); - return !Close; } -//! Pause the current process for the minimum time allowed only to allow other processes to execute -void CIrrDeviceWin32::yield() -{ - Sleep(1); -} - //! Pause execution and let other processes to run for a specified amount of time. void CIrrDeviceWin32::sleep(uint32_t timeMs, bool pauseTimer) { @@ -1146,25 +648,6 @@ void CIrrDeviceWin32::setWindowCaption(const std::wstring& text) SMTO_ABORTIFHUNG, 2000, &dwResult); } - -//! notifies the device that it should close itself -void CIrrDeviceWin32::closeDevice() -{ - MSG msg; - PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE); - PostQuitMessage(0); - PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE); - if (!ExternalWindow) - { - DestroyWindow(HWnd); - const char* ClassName = __TEXT("CIrrDeviceWin32"); - HINSTANCE hInstance = GetModuleHandle(0); - UnregisterClass(ClassName, hInstance); - } - Close=true; -} - - //! returns if window is active. if not, nothing needs to be drawn bool CIrrDeviceWin32::isWindowActive() const { @@ -1487,12 +970,6 @@ void CIrrDeviceWin32::getWindowsVersion(core::stringc& out) } } -//! Notifies the device, that it has been resized -void CIrrDeviceWin32::OnResized() -{ - Resized = true; -} - //! Sets if the window should be resizable in windowed mode. void CIrrDeviceWin32::setResizable(bool resize) { @@ -1563,14 +1040,6 @@ void CIrrDeviceWin32::restoreWindow() } -bool CIrrDeviceWin32::activateJoysticks(core::vector & joystickInfo) -{ - if (JoyControl) - return JoyControl->activateJoysticks(joystickInfo); - else - return false; -} - //! Process system events void CIrrDeviceWin32::handleSystemMessages() { diff --git a/source/Nabla/CIrrDeviceWin32.h b/source/Nabla/CIrrDeviceWin32.h index 17b3a69465..54b4072477 100644 --- a/source/Nabla/CIrrDeviceWin32.h +++ b/source/Nabla/CIrrDeviceWin32.h @@ -6,29 +6,13 @@ #ifndef __NBL_C_NBL_DEVICE_WIN32_H_INCLUDED__ #define __NBL_C_NBL_DEVICE_WIN32_H_INCLUDED__ -#include "nbl/core/compile_config.h" - #ifdef _NBL_COMPILE_WITH_WINDOWS_DEVICE_ -#include "CIrrDeviceStub.h" -#include "IrrlichtDevice.h" - -#define WIN32_LEAN_AND_MEAN - #include - #include // For JOYCAPS - #include -#if !defined(GET_X_LPARAM) -#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) -#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) -#endif - namespace nbl { - struct SJoystickWin32Control; - + class CIrrDeviceWin32 : public CIrrDeviceStub { - friend struct SJoystickWin32Control; protected: //! destructor @@ -63,9 +47,6 @@ namespace nbl //! notifies the device that it should close itself virtual void closeDevice(); - //! Notifies the device, that it has been resized - void OnResized(); - //! Sets if the window should be resizable in windowed mode. virtual void setResizable(bool resize=false); @@ -78,17 +59,9 @@ namespace nbl //! Restores the window size. virtual void restoreWindow(); - //! Activate any joysticks, and generate events for them. - virtual bool activateJoysticks(core::vector & joystickInfo); - //! Remove all messages pending in the system message loop virtual void clearSystemMessages(); - //! Get the device type - virtual E_DEVICE_TYPE getType() const - { - return EIDT_WIN32; - } //! Compares to the last call of this function to return double and triple clicks. //! \return Returns only 1,2 or 3. A 4th click will start with 1 again. @@ -392,8 +365,6 @@ namespace nbl #if 0 DEVMODE DesktopMode; #endif - - SJoystickWin32Control* JoyControl; }; } // end namespace nbl From f65045905c661ca228513b92ff471836d63cf0af Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 16:22:44 +0100 Subject: [PATCH 15/91] remove some legacy cruft and empty file --- source/Nabla/CSceneManager.cpp | 64 --------------------------------- source/Nabla/CSceneManager.h | 37 +++---------------- src/nbl/system/CSystemWin32.cpp | 0 3 files changed, 5 insertions(+), 96 deletions(-) delete mode 100644 src/nbl/system/CSystemWin32.cpp diff --git a/source/Nabla/CSceneManager.cpp b/source/Nabla/CSceneManager.cpp index a473c0b092..f254d49ba2 100644 --- a/source/Nabla/CSceneManager.cpp +++ b/source/Nabla/CSceneManager.cpp @@ -5,10 +5,6 @@ #include "BuildConfigOptions.h" #include "CSceneManager.h" -#include "IFileSystem.h" -#include "IReadFile.h" -#include "IWriteFile.h" -#include "IrrlichtDevice.h" #include "nbl_os.h" @@ -23,44 +19,6 @@ namespace nbl namespace scene { -//! constructor -CSceneManager::CSceneManager(IrrlichtDevice* device, video::IVideoDriver* driver, nbl::ITimer* timer, io::IFileSystem* fs, - gui::ICursorControl* cursorControl) -: ISceneNode(0, 0), Driver(driver), Timer(timer), Device(device), - CursorControl(cursorControl), ActiveCamera(0) -{ - #ifdef _NBL_DEBUG - ISceneManager::setDebugName("CSceneManager ISceneManager"); - #endif - - if (Driver) - Driver->grab(); - if (CursorControl) - CursorControl->grab(); -} - - -//! destructor -CSceneManager::~CSceneManager() -{ - if (CursorControl) - CursorControl->drop(); - - if (ActiveCamera) - ActiveCamera->drop(); - ActiveCamera = 0; - - // remove all nodes and animators before dropping the driver - // as render targets may be destroyed twice - - removeAll(); - removeAnimators(); - - if (Driver) - Driver->drop(); -} - - //! Adds a camera scene node to the tree and sets it as active camera. //! \param position: Position of the space relative to its parent where the camera will be placed. //! \param lookat: Position where the camera will look at. Also known as target. @@ -172,12 +130,6 @@ void CSceneManager::setActiveCamera(ICameraSceneNode* camera) ActiveCamera = camera; } - -//! renders the node. -void CSceneManager::render() -{ -} - //! void CSceneManager::OnAnimate(uint32_t timeMs) { @@ -209,22 +161,6 @@ bool CSceneManager::receiveIfEventReceiverDidNotAbsorb(const SEvent& event) return ret; } - -//! Removes all children of this scene node -void CSceneManager::removeAll() -{ - ISceneNode::removeAll(); - setActiveCamera(0); -} - - -//! Clears the whole scene. All scene nodes are removed. -void CSceneManager::clear() -{ - removeAll(); -} - - } // end namespace scene } // end namespace nbl diff --git a/source/Nabla/CSceneManager.h b/source/Nabla/CSceneManager.h index 81d8b603f1..f3aa4f2a68 100644 --- a/source/Nabla/CSceneManager.h +++ b/source/Nabla/CSceneManager.h @@ -8,38 +8,18 @@ #include "ISceneManager.h" #include "ISceneNode.h" -#include "ICursorControl.h" - -#include -#include namespace nbl { - class ITimer; -namespace io -{ - class IFileSystem; -} namespace scene { - /*! - The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff. - */ - class CSceneManager : public ISceneManager, public ISceneNode - { - protected: - //! destructor - virtual ~CSceneManager(); - +/*! + The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff. +*/ +class CSceneManager : public ISceneManager, public ISceneNode +{ public: - //! constructor - CSceneManager( IrrlichtDevice* device, video::IVideoDriver* driver, - nbl::ITimer* timer, io::IFileSystem* fs, gui::ICursorControl* cursorControl); - - //! returns the video driver - inline video::IVideoDriver* getVideoDriver() override { return Driver; } - //! virtual void OnAnimate(uint32_t timeMs); @@ -88,10 +68,6 @@ namespace scene //! \param camera: The new camera which should be active. virtual void setActiveCamera(ICameraSceneNode* camera); - //! Posts an input event to the environment. Usually you do not have to - //! use this method, it is used by the internal engine. - virtual bool receiveIfEventReceiverDidNotAbsorb(const SEvent& event); - //! Clears the whole scene. All scene nodes are removed. virtual void clear(); @@ -112,9 +88,6 @@ namespace scene //! parent device IrrlichtDevice* Device; - //! cursor control - gui::ICursorControl* CursorControl; - //! current active camera ICameraSceneNode* ActiveCamera; }; diff --git a/src/nbl/system/CSystemWin32.cpp b/src/nbl/system/CSystemWin32.cpp deleted file mode 100644 index e69de29bb2..0000000000 From ae353c491299b0f1efe17085b3996efacefd7a2f Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 16:22:55 +0100 Subject: [PATCH 16/91] tiny TODOs --- include/nbl/config/BuildConfigOptions.h.in | 6 ++++-- include/nbl/system/IApplicationFramework.h | 1 + include/nbl/system/IThreadHandler.h | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/nbl/config/BuildConfigOptions.h.in b/include/nbl/config/BuildConfigOptions.h.in index 2575a2cdf5..f32bc50b1f 100644 --- a/include/nbl/config/BuildConfigOptions.h.in +++ b/include/nbl/config/BuildConfigOptions.h.in @@ -1,10 +1,12 @@ #ifndef __NBL_BUILD_CONFIG_OPTIONS_H_INCLUDED__ #define __NBL_BUILD_CONFIG_OPTIONS_H_INCLUDED__ +// TODO: figure out _ and _ suffixes and prefixes + #cmakedefine _NBL_DEBUG #cmakedefine _NBL_RELWITHDEBINFO -// architecture +// architecture (TODO: rethink) #cmakedefine __NBL_COMPILE_WITH_ARM_SIMD_ // libraries @@ -17,6 +19,7 @@ #cmakedefine _NBL_PLATFORM_OSX_ #cmakedefine _NBL_PLATFORM_ANDROID_ +// TODO: X11 vs Wayland shouldn't even be an option (dlopen at runtime!) #cmakedefine _NBL_BUILD_WITH_WAYLAND // graphics API backend @@ -57,7 +60,6 @@ #cmakedefine _NBL_COMPILE_WITH_GLTF_WRITER_ // compute interop -#cmakedefine _NBL_COMPILE_WITH_OPENCL_ #cmakedefine _NBL_COMPILE_WITH_CUDA_ #cmakedefine _NBL_BUILD_OPTIX_ diff --git a/include/nbl/system/IApplicationFramework.h b/include/nbl/system/IApplicationFramework.h index a878c8d908..946dd86d9a 100644 --- a/include/nbl/system/IApplicationFramework.h +++ b/include/nbl/system/IApplicationFramework.h @@ -38,6 +38,7 @@ class IApplicationFramework : public core::IReferenceCounted protected: ~IApplicationFramework() {} + // TODO: why aren't these pure virtual, and why do we even need a `_impl()`suffix? virtual void onAppInitialized_impl() {} virtual void onAppTerminated_impl() {} diff --git a/include/nbl/system/IThreadHandler.h b/include/nbl/system/IThreadHandler.h index c2eb71c79d..0230bf8b02 100644 --- a/include/nbl/system/IThreadHandler.h +++ b/include/nbl/system/IThreadHandler.h @@ -26,7 +26,7 @@ template class IThreadHandler { private: - // TODO: @Crisspl factor this out somewhere? `nbl/core/reflection` ? + // TODO: @AnastzIuk factor this out somewhere? `nbl/core/reflection` ? #define _NBL_IMPL_MEMBER_FUNC_PRESENCE_CHECKER(member_func_name)\ class has_##member_func_name\ {\ From a15d1da942b03b96e5c6937d196d8b49171bae07 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 19:57:30 +0100 Subject: [PATCH 17/91] CUDA Handler initialization and device finding --- examples_tests/36.CUDAInterop/main.cpp | 2 - include/nbl/video/CCUDADevice.h | 195 +++++ {src => include}/nbl/video/CCUDAHandler.h | 309 ++------ include/nbl/video/IPhysicalDevice.h | 63 +- include/nbl/video/declarations.h | 3 + src/nbl/CMakeLists.txt | 1 + src/nbl/video/CCUDADevice.cpp | 131 ++++ src/nbl/video/CCUDAHandler.cpp | 828 ++++++++++------------ 8 files changed, 826 insertions(+), 706 deletions(-) create mode 100644 include/nbl/video/CCUDADevice.h rename {src => include}/nbl/video/CCUDAHandler.h (53%) create mode 100644 src/nbl/video/CCUDADevice.cpp diff --git a/examples_tests/36.CUDAInterop/main.cpp b/examples_tests/36.CUDAInterop/main.cpp index 69d5420291..1d7ce869ff 100644 --- a/examples_tests/36.CUDAInterop/main.cpp +++ b/examples_tests/36.CUDAInterop/main.cpp @@ -6,8 +6,6 @@ #include -#include "../src/nbl/video/CCUDAHandler.h" - /** This example just shows a screen which clears to red, nothing fancy, just to show that Irrlicht links fine diff --git a/include/nbl/video/CCUDADevice.h b/include/nbl/video/CCUDADevice.h new file mode 100644 index 0000000000..c444e05254 --- /dev/null +++ b/include/nbl/video/CCUDADevice.h @@ -0,0 +1,195 @@ +// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. +// This file is part of the "Nabla Engine". +// For conditions of distribution and use, see copyright notice in nabla.h +#ifndef _NBL_VIDEO_C_CUDA_DEVICE_H_ +#define _NBL_VIDEO_C_CUDA_DEVICE_H_ + + +#include "nbl/video/IPhysicalDevice.h" + + +#ifdef _NBL_COMPILE_WITH_CUDA_ + +#include "cuda.h" +#include "nvrtc.h" +#if CUDA_VERSION < 9000 + #error "Need CUDA 9.0 SDK or higher." +#endif + +// useful includes in the future +//#include "cudaEGL.h" +//#include "cudaVDPAU.h" + +namespace nbl::video +{ +class CCUDAHandler; + +class CCUDADevice : public core::IReferenceCounted +{ + public: + enum E_VIRTUAL_ARCHITECTURE + { + EVA_30, + EVA_32, + EVA_35, + EVA_37, + EVA_50, + EVA_52, + EVA_53, + EVA_60, + EVA_61, + EVA_62, + EVA_70, + EVA_72, + EVA_75, + EVA_80, + EVA_COUNT + }; + static inline constexpr const char* virtualArchCompileOption[] = { + "-arch=compute_30", + "-arch=compute_32", + "-arch=compute_35", + "-arch=compute_37", + "-arch=compute_50", + "-arch=compute_52", + "-arch=compute_53", + "-arch=compute_60", + "-arch=compute_61", + "-arch=compute_62", + "-arch=compute_70", + "-arch=compute_72", + "-arch=compute_75", + "-arch=compute_80" + }; + inline E_VIRTUAL_ARCHITECTURE getVirtualArchitecture() {return m_virtualArchitecture;} + + inline const auto& geDefaultCompileOptions() const {return m_defaultCompileOptions;} + + // TODO/REDO Vulkan: https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__EXTRES__INTEROP.html + // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#vulkan-interoperability + // Watch out, use Driver API (`cu` functions) NOT the Runtime API (`cuda` functions) + // Also maybe separate this out into its own `CCUDA` class instead of nesting it here? +#if 0 + template + struct GraphicsAPIObjLink + { + GraphicsAPIObjLink() : obj(nullptr), cudaHandle(nullptr), acquired(false) + { + asImage = {nullptr}; + } + GraphicsAPIObjLink(core::smart_refctd_ptr&& _obj) : GraphicsAPIObjLink() + { + obj = std::move(_obj); + } + GraphicsAPIObjLink(GraphicsAPIObjLink&& other) : GraphicsAPIObjLink() + { + operator=(std::move(other)); + } + + GraphicsAPIObjLink(const GraphicsAPIObjLink& other) = delete; + GraphicsAPIObjLink& operator=(const GraphicsAPIObjLink& other) = delete; + GraphicsAPIObjLink& operator=(GraphicsAPIObjLink&& other) + { + std::swap(obj,other.obj); + std::swap(cudaHandle,other.cudaHandle); + std::swap(acquired,other.acquired); + std::swap(asImage,other.asImage); + return *this; + } + + ~GraphicsAPIObjLink() + { + assert(!acquired); // you've fucked up, there's no way for us to fix it, you need to release the objects on a proper stream + if (obj) + CCUDAHandler::cuda.pcuGraphicsUnregisterResource(cudaHandle); + } + + // + auto* getObject() const {return obj.get();} + + private: + core::smart_refctd_ptr obj; + CUgraphicsResource cudaHandle; + bool acquired; + + friend class CCUDAHandler; + public: + union + { + struct + { + CUdeviceptr pointer; + } asBuffer; + struct + { + CUmipmappedArray mipmappedArray; + CUarray array; + } asImage; + }; + }; + + // + static CUresult registerBuffer(GraphicsAPIObjLink* link, uint32_t flags = CU_GRAPHICS_REGISTER_FLAGS_NONE); + static CUresult registerImage(GraphicsAPIObjLink* link, uint32_t flags = CU_GRAPHICS_REGISTER_FLAGS_NONE); + + + template + static CUresult acquireResourcesFromGraphics(void* tmpStorage, GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream) + { + auto count = std::distance(linksBegin,linksEnd); + + auto resources = reinterpret_cast(tmpStorage); + auto rit = resources; + for (auto iit=linksBegin; iit!=linksEnd; iit++,rit++) + { + if (iit->acquired) + return CUDA_ERROR_UNKNOWN; + *rit = iit->cudaHandle; + } + + auto retval = cuda.pcuGraphicsMapResources(count,resources,stream); + for (auto iit=linksBegin; iit!=linksEnd; iit++) + iit->acquired = true; + return retval; + } + template + static CUresult releaseResourcesToGraphics(void* tmpStorage, GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream) + { + auto count = std::distance(linksBegin,linksEnd); + + auto resources = reinterpret_cast(tmpStorage); + auto rit = resources; + for (auto iit=linksBegin; iit!=linksEnd; iit++,rit++) + { + if (!iit->acquired) + return CUDA_ERROR_UNKNOWN; + *rit = iit->cudaHandle; + } + + auto retval = cuda.pcuGraphicsUnmapResources(count,resources,stream); + for (auto iit=linksBegin; iit!=linksEnd; iit++) + iit->acquired = false; + return retval; + } + + static CUresult acquireAndGetPointers(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream, size_t* outbufferSizes = nullptr); + static CUresult acquireAndGetMipmappedArray(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream); + static CUresult acquireAndGetArray(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, uint32_t* arrayIndices, uint32_t* mipLevels, CUstream stream); +#endif + + protected: + friend class CCUDAHandler; + CCUDADevice(core::smart_refctd_ptr&& _vulkanConnection, IPhysicalDevice* const _vulkanDevice, const E_VIRTUAL_ARCHITECTURE _virtualArchitecture); + ~CCUDADevice() = default; + + std::vector m_defaultCompileOptions; + core::smart_refctd_ptr m_vulkanConnection; + IPhysicalDevice* const m_vulkanDevice; + E_VIRTUAL_ARCHITECTURE m_virtualArchitecture; +}; + +} + +#endif // _NBL_COMPILE_WITH_CUDA_ + +#endif diff --git a/src/nbl/video/CCUDAHandler.h b/include/nbl/video/CCUDAHandler.h similarity index 53% rename from src/nbl/video/CCUDAHandler.h rename to include/nbl/video/CCUDAHandler.h index 5affe81ad4..64ff944298 100644 --- a/src/nbl/video/CCUDAHandler.h +++ b/include/nbl/video/CCUDAHandler.h @@ -1,49 +1,41 @@ // Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h - -#ifndef __NBL_VIDEO_C_CUDA_HANDLER_H__ -#define __NBL_VIDEO_C_CUDA_HANDLER_H__ +#ifndef _NBL_VIDEO_C_CUDA_HANDLER_H_ +#define _NBL_VIDEO_C_CUDA_HANDLER_H_ #include "nbl/system/declarations.h" +#include "nbl/video/CCUDADevice.h" -#ifdef _NBL_COMPILE_WITH_CUDA_ - -#include "cuda.h" -#include "nvrtc.h" -#if CUDA_VERSION < 9000 - #error "Need CUDA 9.0 SDK or higher." -#endif - -#ifdef _NBL_COMPILE_WITH_OPENGL_ - #include "COpenGLDriver.h" - // make CUDA play nice - #define WGL_NV_gpu_affinity 0 - #include "cudaGL.h" - #undef WGL_NV_gpu_affinity -#endif // _NBL_COMPILE_WITH_OPENGL_ - -// useful includes in the future -//#include "cudaEGL.h" -//#include "cudaVDPAU.h" - -#include "nbl_os.h" -namespace nbl +#ifdef _NBL_COMPILE_WITH_CUDA_ +namespace nbl::video { -namespace cuda + +class CCUDAHandler : public core::IReferenceCounted { + public: + static bool defaultHandleResult(CUresult result, const system::logger_opt_ptr& logger=nullptr); + inline bool defaultHandleResult(CUresult result) + { + core::smart_refctd_ptr logger = m_logger.get(); + return defaultHandleResult(result,logger.get()); + } -#define _NBL_DEFAULT_NVRTC_OPTIONS "--std=c++14",virtualCUDAArchitecture,"-dc","-use_fast_math" + // + bool defaultHandleResult(nvrtcResult result); + // + template + static T* cast_CUDA_ptr(CUdeviceptr ptr) { return reinterpret_cast(ptr); } -class CCUDAHandler -{ - public: - using LibLoader = system::DefaultFuncPtrLoader; + // + core::smart_refctd_ptr create(system::ISystem* system, core::smart_refctd_ptr&& _logger); - NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(CUDA, LibLoader + // + using LibLoader = system::DefaultFuncPtrLoader; + NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(CUDA,LibLoader ,cuCtxCreate_v2 ,cuDevicePrimaryCtxRetain ,cuDevicePrimaryCtxRelease @@ -81,8 +73,6 @@ class CCUDAHandler ,cuFuncSetCacheConfig ,cuGetErrorName ,cuGetErrorString - ,cuGraphicsGLRegisterBuffer - ,cuGraphicsGLRegisterImage ,cuGraphicsMapResources ,cuGraphicsResourceGetMappedPointer_v2 ,cuGraphicsResourceGetMappedMipmappedArray @@ -126,28 +116,10 @@ class CCUDAHandler ,cuSurfObjectDestroy ,cuTexObjectCreate ,cuTexObjectDestroy - ,cuGLGetDevices_v2 ); - static CUDA cuda; - - struct Device - { - Device() {} - Device(int ordinal); - ~Device() - { - } - - CUdevice handle = -1; - char name[122] = {}; - char luid = -1; - unsigned int deviceNodeMask = 0; - CUuuid uuid = {}; - size_t vram_size = 0ull; - int attributes[CU_DEVICE_ATTRIBUTE_MAX] = {}; - }; + const CUDA& getCUDAFunctionTable() const {return m_cuda;} - NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(NVRTC, LibLoader, + NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(NVRTC,LibLoader, nvrtcGetErrorString, nvrtcVersion, nvrtcAddNameExpression, @@ -160,182 +132,9 @@ class CCUDAHandler nvrtcGetProgramLog, nvrtcGetProgramLogSize ); - static NVRTC nvrtc; - - protected: - CCUDAHandler() = default; - - _NBL_STATIC_INLINE int CudaVersion = 0; - _NBL_STATIC_INLINE int DeviceCount = 0; - static core::vector devices; - - static core::vector > headers; - static core::vector headerContents; - static core::vector headerNames; - - _NBL_STATIC_INLINE_CONSTEXPR const char* virtualCUDAArchitectures[] = { "-arch=compute_30", - "-arch=compute_32", - "-arch=compute_35", - "-arch=compute_37", - "-arch=compute_50", - "-arch=compute_52", - "-arch=compute_53", - "-arch=compute_60", - "-arch=compute_61", - "-arch=compute_62", - "-arch=compute_70", - "-arch=compute_72", - "-arch=compute_75", - "-arch=compute_80"}; - _NBL_STATIC_INLINE const char* virtualCUDAArchitecture = nullptr; - - #ifdef _MSC_VER - _NBL_STATIC_INLINE_CONSTEXPR const char* CUDA_EXTRA_DEFINES = "#ifndef _WIN64\n#define _WIN64\n#endif\n"; - #else - _NBL_STATIC_INLINE_CONSTEXPR const char* CUDA_EXTRA_DEFINES = "#ifndef __LP64__\n#define __LP64__\n#endif\n"; - #endif - - public: - static CUresult init(); - static void deinit(); - - static const char* getCommonVirtualCUDAArchitecture() {return virtualCUDAArchitecture;} - - static bool defaultHandleResult(CUresult result); - - static CUresult getDefaultGLDevices(uint32_t* foundCount, CUdevice* pCudaDevices, uint32_t cudaDeviceCount) - { - return cuda.pcuGLGetDevices_v2(foundCount,pCudaDevices,cudaDeviceCount,CU_GL_DEVICE_LIST_ALL); - } - - template - static T* cast_CUDA_ptr(CUdeviceptr ptr) {return reinterpret_cast(ptr);} - - template - struct GraphicsAPIObjLink - { - GraphicsAPIObjLink() : obj(nullptr), cudaHandle(nullptr), acquired(false) - { - asImage = {nullptr}; - } - GraphicsAPIObjLink(core::smart_refctd_ptr&& _obj) : GraphicsAPIObjLink() - { - obj = std::move(_obj); - } - GraphicsAPIObjLink(GraphicsAPIObjLink&& other) : GraphicsAPIObjLink() - { - operator=(std::move(other)); - } - - GraphicsAPIObjLink(const GraphicsAPIObjLink& other) = delete; - GraphicsAPIObjLink& operator=(const GraphicsAPIObjLink& other) = delete; - GraphicsAPIObjLink& operator=(GraphicsAPIObjLink&& other) - { - std::swap(obj,other.obj); - std::swap(cudaHandle,other.cudaHandle); - std::swap(acquired,other.acquired); - std::swap(asImage,other.asImage); - return *this; - } - - ~GraphicsAPIObjLink() - { - assert(!acquired); // you've fucked up, there's no way for us to fix it, you need to release the objects on a proper stream - if (obj) - CCUDAHandler::cuda.pcuGraphicsUnregisterResource(cudaHandle); - } - - // - auto* getObject() const {return obj.get();} - - private: - core::smart_refctd_ptr obj; - CUgraphicsResource cudaHandle; - bool acquired; - - friend class CCUDAHandler; - public: - union - { - struct - { - CUdeviceptr pointer; - } asBuffer; - struct - { - CUmipmappedArray mipmappedArray; - CUarray array; - } asImage; - }; - }; - - // - static CUresult registerBuffer(GraphicsAPIObjLink* link, uint32_t flags = CU_GRAPHICS_REGISTER_FLAGS_NONE); - static CUresult registerImage(GraphicsAPIObjLink* link, uint32_t flags = CU_GRAPHICS_REGISTER_FLAGS_NONE); - - - template - static CUresult acquireResourcesFromGraphics(void* tmpStorage, GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream) - { - auto count = std::distance(linksBegin,linksEnd); - - auto resources = reinterpret_cast(tmpStorage); - auto rit = resources; - for (auto iit=linksBegin; iit!=linksEnd; iit++,rit++) - { - if (iit->acquired) - return CUDA_ERROR_UNKNOWN; - *rit = iit->cudaHandle; - } - - auto retval = cuda.pcuGraphicsMapResources(count,resources,stream); - for (auto iit=linksBegin; iit!=linksEnd; iit++) - iit->acquired = true; - return retval; - } - template - static CUresult releaseResourcesToGraphics(void* tmpStorage, GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream) - { - auto count = std::distance(linksBegin,linksEnd); - - auto resources = reinterpret_cast(tmpStorage); - auto rit = resources; - for (auto iit=linksBegin; iit!=linksEnd; iit++,rit++) - { - if (!iit->acquired) - return CUDA_ERROR_UNKNOWN; - *rit = iit->cudaHandle; - } - - auto retval = cuda.pcuGraphicsUnmapResources(count,resources,stream); - for (auto iit=linksBegin; iit!=linksEnd; iit++) - iit->acquired = false; - return retval; - } - - static CUresult acquireAndGetPointers(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream, size_t* outbufferSizes = nullptr); - static CUresult acquireAndGetMipmappedArray(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream); - static CUresult acquireAndGetArray(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, uint32_t* arrayIndices, uint32_t* mipLevels, CUstream stream); - - - static bool defaultHandleResult(nvrtcResult result) - { - switch (result) - { - case NVRTC_SUCCESS: - return true; - break; - default: - if (nvrtc.pnvrtcGetErrorString) - printf("%s\n",nvrtc.pnvrtcGetErrorString(result)); - else - printf(R"===(CudaHandler: `pnvrtcGetErrorString` is nullptr, the nvrtc library probably not found on the system.\n)==="); - break; - } - _NBL_DEBUG_BREAK_IF(true); - return false; - } + const NVRTC& getNVRTCFunctionTable() const {return m_nvrtc;} +#if 0 // static core::SRange getCUDASTDHeaders() { @@ -410,24 +209,29 @@ class CCUDAHandler } return nvrtc.pnvrtcCreateProgram(prog, sources.data(), main->getFileName().c_str(), numHeaders, headers.data(), includeNames.data()); } - +#endif + // + inline nvrtcResult compileProgram(nvrtcProgram prog, const size_t optionCount, const char* const* options) + { + return m_nvrtc.pnvrtcCompileProgram(prog, optionCount, options); + } template&> - static nvrtcResult compileProgram(nvrtcProgram prog, OptionsT options={_NBL_DEFAULT_NVRTC_OPTIONS}) + inline nvrtcResult compileProgram(nvrtcProgram prog, OptionsT options) { - return nvrtc.pnvrtcCompileProgram(prog, options.size(), options.begin()); + return compileProgram(prog, options.size(), options.begin()); } - - static nvrtcResult compileProgram(nvrtcProgram prog, const std::vector& options) + inline nvrtcResult compileProgram(nvrtcProgram prog, const std::vector& options) { - return nvrtc.pnvrtcCompileProgram(prog, options.size(), options.data()); + return compileProgram(prog, options.size(), options.data()); } // - static nvrtcResult getProgramLog(nvrtcProgram prog, std::string& log); + nvrtcResult getProgramLog(nvrtcProgram prog, std::string& log); // - static nvrtcResult getPTX(nvrtcProgram prog, std::string& ptx); + std::pair,nvrtcResult> getPTX(nvrtcProgram prog); +#if 0 // template&> static nvrtcResult compileDirectlyToPTX(std::string& ptx, const char* source, const char* filename, @@ -485,9 +289,30 @@ class CCUDAHandler return result = compileDirectlyToPTX_helper(ptx,program,std::forward(options),log); } +#endif + core::smart_refctd_ptr createDevice(core::smart_refctd_ptr&& vulkanConnection, IPhysicalDevice* physicalDevice); protected: + CCUDAHandler( + CUDA&& _cuda, + NVRTC&& _nvrtc, + core::vector>&& _headers, + core::smart_refctd_ptr&& _logger, + int _version + ); + ~CCUDAHandler() = default; + +#if 0 + static core::vector headerContents; + static core::vector headerNames; + +#ifdef _MSC_VER + _NBL_STATIC_INLINE_CONSTEXPR const char* CUDA_EXTRA_DEFINES = "#ifndef _WIN64\n#define _WIN64\n#endif\n"; +#else + _NBL_STATIC_INLINE_CONSTEXPR const char* CUDA_EXTRA_DEFINES = "#ifndef __LP64__\n#define __LP64__\n#endif\n"; +#endif + template&> static nvrtcResult compileDirectlyToPTX_helper(std::string& ptx, nvrtcProgram program, OptionsT options, std::string* log=nullptr) { @@ -499,9 +324,17 @@ class CCUDAHandler return getPTX(program, ptx); } +#endif + // function tables + CUDA m_cuda; + NVRTC m_nvrtc; + + // + core::vector> m_headers; + system::logger_opt_smart_ptr m_logger; + int m_version; }; -} } #endif // _NBL_COMPILE_WITH_CUDA_ diff --git a/include/nbl/video/IPhysicalDevice.h b/include/nbl/video/IPhysicalDevice.h index 22f10765ee..31fe6f1cf1 100644 --- a/include/nbl/video/IPhysicalDevice.h +++ b/include/nbl/video/IPhysicalDevice.h @@ -24,8 +24,24 @@ namespace nbl::video class IPhysicalDevice : public core::Interface, public core::Unmovable { public: + // + virtual E_API_TYPE getAPIType() const = 0; + + // TODO: fold into SLimits + struct APIVersion + { + uint32_t major : 5; + uint32_t minor : 5; + uint32_t patch : 22; + }; + const APIVersion& getAPIVersion() const { return m_apiVersion; } + + // struct SLimits { + uint8_t deviceUUID[VK_UUID_SIZE] = {}; // TODO: implement on Vulkan with VkPhysicalDeviceIDProperties + + // uint32_t UBOAlignment; uint32_t SSBOAlignment; uint32_t bufferViewAlignment; @@ -110,7 +126,9 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable return static_cast(core::min(infinitelyWideDeviceWGCount,maxResidentWorkgroups)); } }; + const SLimits& getLimits() const { return m_limits; } + // struct SFeatures { bool robustBufferAccess = false; @@ -163,7 +181,9 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable // Buffer Device Address bool bufferDeviceAddress = false; }; + const SFeatures& getFeatures() const { return m_features; } + // struct SMemoryProperties { uint32_t memoryTypeCount = 0u; @@ -171,7 +191,9 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable uint32_t memoryHeapCount = 0u; VkMemoryHeap memoryHeaps[VK_MAX_MEMORY_HEAPS]; }; + const SMemoryProperties& getMemoryProperties() const { return m_memoryProperties; } + // struct SFormatBufferUsage { uint8_t isInitialized : 1u; @@ -225,7 +247,9 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable (accelerationStructureVertex == other.accelerationStructureVertex); } }; + virtual const SFormatBufferUsage& getBufferFormatUsages(const asset::E_FORMAT format) = 0; + // struct SFormatImageUsage { uint8_t isInitialized : 1u; @@ -304,8 +328,10 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable (log2MaxSamples == other.log2MaxSamples); } }; + virtual const SFormatImageUsage& getImageFormatUsagesLinear(const asset::E_FORMAT format) = 0; + virtual const SFormatImageUsage& getImageFormatUsagesOptimal(const asset::E_FORMAT format) = 0; - + // enum E_QUEUE_FLAGS : uint32_t { EQF_GRAPHICS_BIT = 0x01, @@ -321,26 +347,6 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable uint32_t timestampValidBits; asset::VkExtent3D minImageTransferGranularity; }; - - struct APIVersion - { - uint32_t major : 5; - uint32_t minor : 5; - uint32_t patch : 22; - }; - - const SLimits& getLimits() const { return m_limits; } - const SFeatures& getFeatures() const { return m_features; } - const SMemoryProperties& getMemoryProperties() const { return m_memoryProperties; } - const APIVersion& getAPIVersion() const { return m_apiVersion; } - - // these are the defines which shall be added to any IGPUShader which has its source as GLSL - inline core::SRange getExtraGLSLDefines() const - { - const char* const* begin = m_extraGLSLDefines.data(); - return {begin,begin+m_extraGLSLDefines.size()}; - } - auto getQueueFamilyProperties() const { using citer_t = qfam_props_array_t::pointee::const_iterator; @@ -350,11 +356,20 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable ); } + // these are the defines which shall be added to any IGPUShader which has its source as GLSL + inline core::SRange getExtraGLSLDefines() const + { + const char* const* begin = m_extraGLSLDefines.data(); + return {begin,begin+m_extraGLSLDefines.size()}; + } + + // inline system::ISystem* getSystem() const {return m_system.get();} inline asset::IGLSLCompiler* getGLSLCompiler() const {return m_GLSLCompiler.get();} virtual IDebugCallback* getDebugCallback() = 0; + // TODO: shouldn't this be in SFeatures? virtual bool isSwapchainSupported() const = 0; core::smart_refctd_ptr createLogicalDevice(const ILogicalDevice::SCreationParams& params) @@ -365,12 +380,6 @@ class IPhysicalDevice : public core::Interface, public core::Unmovable return createLogicalDevice_impl(params); } - virtual E_API_TYPE getAPIType() const = 0; - - virtual const SFormatImageUsage& getImageFormatUsagesLinear(const asset::E_FORMAT format) = 0; - virtual const SFormatImageUsage& getImageFormatUsagesOptimal(const asset::E_FORMAT format) = 0; - virtual const SFormatBufferUsage& getBufferFormatUsages(const asset::E_FORMAT format) = 0; - protected: IPhysicalDevice(core::smart_refctd_ptr&& s, core::smart_refctd_ptr&& glslc); diff --git a/include/nbl/video/declarations.h b/include/nbl/video/declarations.h index 197de04033..d4131a75dd 100644 --- a/include/nbl/video/declarations.h +++ b/include/nbl/video/declarations.h @@ -26,6 +26,9 @@ #include "nbl/video/surface/CSurfaceGL.h" #include "nbl/video/surface/CSurfaceVulkan.h" +// CUDA +#include "nbl/video/CCUDAHandler.h" + // utilities #include "nbl/video/utilities/CDumbPresentationOracle.h" #include "nbl/video/utilities/ICommandPoolCache.h" diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index e058135888..bda3be1862 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -369,6 +369,7 @@ set(NABLA_SRCS_NORMAL # CUDA ${NBL_ROOT_PATH}/src/nbl/video/CCUDAHandler.cpp + ${NBL_ROOT_PATH}/src/nbl/video/CCUDADevice.cpp ) set(COMMON_INCLUDE_DIRS diff --git a/src/nbl/video/CCUDADevice.cpp b/src/nbl/video/CCUDADevice.cpp new file mode 100644 index 0000000000..4d2e880095 --- /dev/null +++ b/src/nbl/video/CCUDADevice.cpp @@ -0,0 +1,131 @@ +// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. +// This file is part of the "Nabla Engine". +// For conditions of distribution and use, see copyright notice in nabla.h +#include "nbl/video/CCUDADevice.h" + +#ifdef _NBL_COMPILE_WITH_CUDA_ +namespace nbl::video +{ + +CCUDADevice::CCUDADevice(core::smart_refctd_ptr&& _vulkanConnection, IPhysicalDevice* const _vulkanDevice, const E_VIRTUAL_ARCHITECTURE _virtualArchitecture) + : m_defaultCompileOptions(), m_vulkanConnection(std::move(_vulkanConnection)), m_vulkanDevice(_vulkanDevice), m_virtualArchitecture(_virtualArchitecture) +{ + m_defaultCompileOptions.push_back("--std=c++14"); + m_defaultCompileOptions.push_back(virtualArchCompileOption[m_virtualArchitecture]); + m_defaultCompileOptions.push_back("-dc"); + m_defaultCompileOptions.push_back("-use_fast_math"); +} + + +#if 0 +CUresult CCUDAHandler::registerBuffer(GraphicsAPIObjLink* link, uint32_t flags) +{ + assert(link->obj); + auto glbuf = static_cast(link->obj.get()); + auto retval = cuda.pcuGraphicsGLRegisterBuffer(&link->cudaHandle,glbuf->getOpenGLName(),flags); + if (retval!=CUDA_SUCCESS) + link->obj = nullptr; + return retval; +} +CUresult CCUDAHandler::registerImage(GraphicsAPIObjLink* link, uint32_t flags) +{ + assert(link->obj); + + auto format = link->obj->getCreationParameters().format; + if (asset::isBlockCompressionFormat(format) || asset::isDepthOrStencilFormat(format) || asset::isScaledFormat(format) || asset::isPlanarFormat(format)) + return CUDA_ERROR_INVALID_IMAGE; + + auto glimg = static_cast(link->obj.get()); + GLenum target = glimg->getOpenGLTarget(); + switch (target) + { + case GL_TEXTURE_2D: + case GL_TEXTURE_2D_ARRAY: + case GL_TEXTURE_CUBE_MAP: + case GL_TEXTURE_3D: + break; + default: + return CUDA_ERROR_INVALID_IMAGE; + break; + } + auto retval = cuda.pcuGraphicsGLRegisterImage(&link->cudaHandle,glimg->getOpenGLName(),target,flags); + if (retval != CUDA_SUCCESS) + link->obj = nullptr; + return retval; +} + + +constexpr auto MaxAquireOps = 4096u; + +CUresult CCUDAHandler::acquireAndGetPointers(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream, size_t* outbufferSizes) +{ + if (linksBegin+MaxAquireOpsacquired) + return CUDA_ERROR_UNKNOWN; + + result = cuda::CCUDAHandler::cuda.pcuGraphicsResourceGetMappedPointer_v2(&iit->asBuffer.pointer,outbufferSizes ? sit:&tmp,iit->cudaHandle); + if (result != CUDA_SUCCESS) + return result; + } + return CUDA_SUCCESS; +} +CUresult CCUDAHandler::acquireAndGetMipmappedArray(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream) +{ + if (linksBegin+MaxAquireOpsacquired) + return CUDA_ERROR_UNKNOWN; + + result = cuda::CCUDAHandler::cuda.pcuGraphicsResourceGetMappedMipmappedArray(&iit->asImage.mipmappedArray,iit->cudaHandle); + if (result != CUDA_SUCCESS) + return result; + } + return CUDA_SUCCESS; +} +CUresult CCUDAHandler::acquireAndGetArray(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, uint32_t* arrayIndices, uint32_t* mipLevels, CUstream stream) +{ + if (linksBegin+MaxAquireOpsacquired) + return CUDA_ERROR_UNKNOWN; + + result = cuda::CCUDAHandler::cuda.pcuGraphicsSubResourceGetMappedArray(&iit->asImage.array,iit->cudaHandle,*ait,*mit); + if (result != CUDA_SUCCESS) + return result; + } + return CUDA_SUCCESS; +} +#endif + +} + +#endif // _NBL_COMPILE_WITH_CUDA_ diff --git a/src/nbl/video/CCUDAHandler.cpp b/src/nbl/video/CCUDAHandler.cpp index 41e86ca24f..ddddf77c45 100644 --- a/src/nbl/video/CCUDAHandler.cpp +++ b/src/nbl/video/CCUDAHandler.cpp @@ -2,302 +2,16 @@ // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h -#include "CCUDAHandler.h" +#include "nbl/video/CCUDAHandler.h" #ifdef _NBL_COMPILE_WITH_CUDA_ #include "jitify/jitify.hpp" -namespace nbl +namespace nbl::video { -namespace cuda -{ - -CCUDAHandler::CUDA CCUDAHandler::cuda; -CCUDAHandler::NVRTC CCUDAHandler::nvrtc; - -core::vector CCUDAHandler::devices; - -core::vector > CCUDAHandler::headers; -core::vector CCUDAHandler::headerContents; -core::vector CCUDAHandler::headerNames; - - - -CUresult CCUDAHandler::init() -{ - if (CudaVersion) - return CUDA_SUCCESS; - - CUresult result = CUDA_ERROR_UNKNOWN; - auto cleanup = core::makeRAIIExiter([&result]() -> void - { - if (result != CUDA_SUCCESS) - { - CudaVersion = 0; - DeviceCount = 0; - devices.clear(); - } - } - ); - - - cuda = CUDA( - #if defined(_NBL_WINDOWS_API_) - "nvcuda" - #elif defined(_NBL_POSIX_API_) - "cuda" - #endif - ); - #define SAFE_CUDA_CALL(NO_PTR_ERROR,FUNC,...) \ - {\ - if (!cuda.p ## FUNC)\ - return result=NO_PTR_ERROR;\ - result = cuda.p ## FUNC ## (__VA_ARGS__);\ - if (result!=CUDA_SUCCESS)\ - return result;\ - } - - SAFE_CUDA_CALL(CUDA_ERROR_NOT_SUPPORTED,cuInit,0) - - SAFE_CUDA_CALL(CUDA_ERROR_NOT_SUPPORTED,cuDriverGetVersion,&CudaVersion) - if (CudaVersion<9000) - return result=CUDA_ERROR_SYSTEM_DRIVER_MISMATCH; - - SAFE_CUDA_CALL(CUDA_ERROR_NOT_SUPPORTED,cuDeviceGetCount,&DeviceCount) - - devices.resize(DeviceCount); - int j = 0; - for (int i=0; i8 || archVersion[0]==8&&archVersion[1]>0) - { - assert(strcmp(virtualCUDAArchitectures[13],"-arch=compute_80")==0); - if (!virtualCUDAArchitecture) - virtualCUDAArchitecture = virtualCUDAArchitectures[13]; - } - else - { - const std::string virtualArchString = "-arch=compute_"+std::to_string(archVersion[0])+std::to_string(archVersion[1]); - - int32_t i = sizeof(virtualCUDAArchitectures)/sizeof(const char*); - while (i>0) - if (virtualCUDAArchitecture==virtualCUDAArchitectures[--i] || !virtualCUDAArchitecture) - break; - - if (!virtualCUDAArchitecture || virtualArchString!=virtualCUDAArchitecture) - { - i++; - while (i>0) - if (virtualArchString==virtualCUDAArchitectures[--i]) - { - virtualCUDAArchitecture = virtualCUDAArchitectures[i]; - break; - } - } - } - - devices[j++] = tmp; - } - devices.resize(j); - - if (!virtualCUDAArchitecture) - return result=CUDA_ERROR_INVALID_DEVICE; - - #undef SAFE_CUDA_CALL - - #if defined(_NBL_WINDOWS_API_) - const char* nvrtc64_versions[] = { "nvrtc64_111","nvrtc64_110","nvrtc64_102","nvrtc64_101","nvrtc64_100","nvrtc64_92","nvrtc64_91","nvrtc64_90","nvrtc64_80","nvrtc64_75","nvrtc64_70",nullptr }; - const char* nvrtc64_suffices[] = {"","_","_0","_1","_2",nullptr}; - for (auto verpath=nvrtc64_versions; *verpath; verpath++) - { - for (auto suffix=nvrtc64_suffices; *suffix; suffix++) - { - std::string path(*verpath); - path += *suffix; - nvrtc = NVRTC(path.c_str()); - if (nvrtc.pnvrtcVersion) - break; - } - if (nvrtc.pnvrtcVersion) - break; - } - #elif defined(_NBL_POSIX_API_) - nvrtc = NVRTC("nvrtc"); - //nvrtc_builtins = NVRTC("nvrtc-builtins"); - #endif - - int nvrtcVersion[2] = {-1,-1}; - cuda::CCUDAHandler::nvrtc.pnvrtcVersion(nvrtcVersion+0,nvrtcVersion+1); - if (nvrtcVersion[0]<9) - return result=CUDA_ERROR_SYSTEM_DRIVER_MISMATCH; - - - for (const auto& it : jitify::detail::get_jitsafe_headers_map()) - { - auto file = core::make_smart_refctd_ptr(it.second.c_str(),it.second.size()+1ull,it.first.c_str()); - headerContents.push_back(reinterpret_cast(file->getData())); - headerNames.push_back(file->getFileName().c_str()); - headers.push_back(core::move_and_static_cast(file)); - } - - return result=CUDA_SUCCESS; -} - -void CCUDAHandler::deinit() -{ - CudaVersion = 0; - DeviceCount = 0; - devices.resize(0u); - - cuda = CUDA(); - - - nvrtc = NVRTC(); - - headerContents.clear(); - headerNames.clear(); - headers.clear(); -} - - -CCUDAHandler::Device::Device(int ordinal) : Device() -{ - if (cuda.pcuDeviceGet(&handle, ordinal)!=CUDA_SUCCESS) - { - handle = 0; - return; - } - - uint32_t namelen = sizeof(name); - if (cuda.pcuDeviceGetName(name,namelen,handle)!=CUDA_SUCCESS) - return; - - if (cuda.pcuDeviceGetLuid(&luid,&deviceNodeMask,handle)) - return; - - if (cuda.pcuDeviceGetUuid(&uuid,handle)!=CUDA_SUCCESS) - return; - - if (cuda.pcuDeviceTotalMem_v2(&vram_size,handle)!=CUDA_SUCCESS) - return; - - for (int i=0; i(i),handle); -} - -CUresult CCUDAHandler::registerBuffer(GraphicsAPIObjLink* link, uint32_t flags) -{ - assert(link->obj); - auto glbuf = static_cast(link->obj.get()); - auto retval = cuda.pcuGraphicsGLRegisterBuffer(&link->cudaHandle,glbuf->getOpenGLName(),flags); - if (retval!=CUDA_SUCCESS) - link->obj = nullptr; - return retval; -} -CUresult CCUDAHandler::registerImage(GraphicsAPIObjLink* link, uint32_t flags) -{ - assert(link->obj); - - auto format = link->obj->getCreationParameters().format; - if (asset::isBlockCompressionFormat(format) || asset::isDepthOrStencilFormat(format) || asset::isScaledFormat(format) || asset::isPlanarFormat(format)) - return CUDA_ERROR_INVALID_IMAGE; - - auto glimg = static_cast(link->obj.get()); - GLenum target = glimg->getOpenGLTarget(); - switch (target) - { - case GL_TEXTURE_2D: - case GL_TEXTURE_2D_ARRAY: - case GL_TEXTURE_CUBE_MAP: - case GL_TEXTURE_3D: - break; - default: - return CUDA_ERROR_INVALID_IMAGE; - break; - } - auto retval = cuda.pcuGraphicsGLRegisterImage(&link->cudaHandle,glimg->getOpenGLName(),target,flags); - if (retval != CUDA_SUCCESS) - link->obj = nullptr; - return retval; -} - - -constexpr auto MaxAquireOps = 4096u; - -CUresult CCUDAHandler::acquireAndGetPointers(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream, size_t* outbufferSizes) -{ - if (linksBegin+MaxAquireOpsacquired) - return CUDA_ERROR_UNKNOWN; - - result = cuda::CCUDAHandler::cuda.pcuGraphicsResourceGetMappedPointer_v2(&iit->asBuffer.pointer,outbufferSizes ? sit:&tmp,iit->cudaHandle); - if (result != CUDA_SUCCESS) - return result; - } - return CUDA_SUCCESS; -} -CUresult CCUDAHandler::acquireAndGetMipmappedArray(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, CUstream stream) -{ - if (linksBegin+MaxAquireOpsacquired) - return CUDA_ERROR_UNKNOWN; - - result = cuda::CCUDAHandler::cuda.pcuGraphicsResourceGetMappedMipmappedArray(&iit->asImage.mipmappedArray,iit->cudaHandle); - if (result != CUDA_SUCCESS) - return result; - } - return CUDA_SUCCESS; -} -CUresult CCUDAHandler::acquireAndGetArray(GraphicsAPIObjLink* linksBegin, GraphicsAPIObjLink* linksEnd, uint32_t* arrayIndices, uint32_t* mipLevels, CUstream stream) -{ - if (linksBegin+MaxAquireOpsacquired) - return CUDA_ERROR_UNKNOWN; - - result = cuda::CCUDAHandler::cuda.pcuGraphicsSubResourceGetMappedArray(&iit->asImage.array,iit->cudaHandle,*ait,*mit); - if (result != CUDA_SUCCESS) - return result; - } - return CUDA_SUCCESS; -} - - -bool CCUDAHandler::defaultHandleResult(CUresult result) + +bool CCUDAHandler::defaultHandleResult(CUresult result, const system::logger_opt_ptr& logger) { switch (result) { @@ -305,393 +19,629 @@ bool CCUDAHandler::defaultHandleResult(CUresult result) return true; break; case CUDA_ERROR_INVALID_VALUE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that one or more of the parameters passed to the API call is not within an acceptable range of values. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_OUT_OF_MEMORY: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: The API call failed because it was unable to allocate enough memory to perform the requested operation. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NOT_INITIALIZED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the CUDA driver has not been initialized with cuInit() or that initialization has failed. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_DEINITIALIZED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the CUDA driver is in the process of shutting down. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_PROFILER_DISABLED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates profiler is not initialized for this run. This can happen when the application is running with external profiling tools like visual profiler. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NO_DEVICE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that no CUDA-capable devices were detected by the installed CUDA driver. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_DEVICE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the device ordinal supplied by the user does not correspond to a valid CUDA device. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_IMAGE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the device kernel image is invalid. This can also indicate an invalid CUDA module. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_CONTEXT: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This most frequently indicates that there is no context bound to the current thread. This can also be returned if the context passed to an API call is not a valid handle (such as a context that has had cuCtxDestroy() invoked on it). This can also be returned if a user mixes different API versions (i.e. 3010 context with 3020 API calls). See cuCtxGetApiVersion() for more details. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_MAP_FAILED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a map or register operation has failed. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_UNMAP_FAILED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that an unmap or unregister operation has failed. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_ARRAY_IS_MAPPED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the specified array is currently mapped and thus cannot be destroyed. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_ALREADY_MAPPED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the resource is already mapped. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NO_BINARY_FOR_GPU: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that there is no kernel image available that is suitable for the device. This can occur when a user specifies code generation options for a particular CUDA source file that do not include the corresponding device configuration. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_ALREADY_ACQUIRED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a resource has already been acquired. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NOT_MAPPED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a resource is not mapped. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NOT_MAPPED_AS_ARRAY: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a mapped resource is not available for access as an array. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NOT_MAPPED_AS_POINTER: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a mapped resource is not available for access as a pointer. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_ECC_UNCORRECTABLE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that an uncorrectable ECC error was detected during execution. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_UNSUPPORTED_LIMIT: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the CUlimit passed to the API call is not supported by the active device. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_CONTEXT_ALREADY_IN_USE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the CUcontext passed to the API call can only be bound to a single CPU thread at a time but is already bound to a CPU thread. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_PEER_ACCESS_UNSUPPORTED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that peer access is not supported across the given devices. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_PTX: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a PTX JIT compilation failed. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_GRAPHICS_CONTEXT: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates an error with OpenGL or DirectX context. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NVLINK_UNCORRECTABLE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that an uncorrectable NVLink error was detected during the execution. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_JIT_COMPILER_NOT_FOUND: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the PTX JIT compiler library was not found. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_SOURCE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the device kernel source is invalid. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_FILE_NOT_FOUND: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the file specified was not found. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a link to a shared object failed to resolve. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that initialization of a shared object failed. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_OPERATING_SYSTEM: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that an OS call failed. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_HANDLE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a resource handle passed to the API call was not valid. Resource handles are opaque types like CUstream and CUevent. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_ILLEGAL_STATE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a resource required by the API call is not in a valid state to perform the requested operation. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NOT_FOUND: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a named symbol was not found. Examples of symbols are global/constant variable names, texture names, and surface names. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NOT_READY: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that asynchronous operations issued previously have not completed yet. This result is not actually an error, but must be indicated differently than CUDA_SUCCESS (which indicates completion). Calls that may return this value include cuEventQuery() and cuStreamQuery(). - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_ILLEGAL_ADDRESS: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: While executing a kernel, the device encountered a load or store instruction on an invalid memory address. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that a launch did not occur because it did not have appropriate resources. This error usually indicates that the user has attempted to pass too many arguments to the device kernel, or the kernel launch specifies too many threads for the kernel's register count. Passing arguments of the wrong size (i.e. a 64-bit pointer when a 32-bit int is expected) is equivalent to passing too many arguments and can also result in this error. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_LAUNCH_TIMEOUT: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This indicates that the device kernel took too long to execute. This can only occur if timeouts are enabled - see the device attribute CU_DEVICE_ATTRIBUTE_KERNEL_EXEC_TIMEOUT for more information. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates a kernel launch that uses an incompatible texturing mode. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that a call to cuCtxEnablePeerAccess() is trying to re-enable peer access to a context which has already had peer access to it enabled. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that cuCtxDisablePeerAccess() is trying to disable peer access which has not been enabled yet via cuCtxEnablePeerAccess(). - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the primary context for the specified device has already been initialized. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_CONTEXT_IS_DESTROYED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the context current to the calling thread has been destroyed using cuCtxDestroy, or is a primary context which has not yet been initialized. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_ASSERT: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: A device-side assert triggered during kernel execution. The context cannot be used anymore, and must be destroyed. All existing device memory allocations from this context are invalid and must be reconstructed if the program is to continue using CUDA. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_TOO_MANY_PEERS: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the hardware resources required to enable peer access have been exhausted for one or more of the devices passed to cuCtxEnablePeerAccess(). - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the memory range passed to cuMemHostRegister() has already been registered. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the pointer passed to cuMemHostUnregister() does not correspond to any currently registered memory region. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_HARDWARE_STACK_ERROR: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: While executing a kernel, the device encountered a stack error. This can be due to stack corruption or exceeding the stack size limit. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_ILLEGAL_INSTRUCTION: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: While executing a kernel, the device encountered an illegal instruction. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_MISALIGNED_ADDRESS: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: While executing a kernel, the device encountered a load or store instruction on a memory address which is not aligned. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_ADDRESS_SPACE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: While executing a kernel, the device encountered an instruction which can only operate on memory locations in certain address spaces (global, shared, or local), but was supplied a memory address not belonging to an allowed address space. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_INVALID_PC: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: While executing a kernel, the device program counter wrapped its address space. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_LAUNCH_FAILED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: An exception occurred on the device while executing a kernel. Common causes include dereferencing an invalid device pointer and accessing out of bounds shared memory. Less common cases can be system specific - more information about these cases can be found in the system specific user guide. This leaves the process in an inconsistent state and any further CUDA work will return the same error. To continue using CUDA, the process must be terminated and relaunched. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_COOPERATIVE_LAUNCH_TOO_LARGE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the number of blocks launched per grid for a kernel that was launched via either cuLaunchCooperativeKernel or cuLaunchCooperativeKernelMultiDevice exceeds the maximum number of blocks as allowed by cuOccupancyMaxActiveBlocksPerMultiprocessor or cuOccupancyMaxActiveBlocksPerMultiprocessorWithFlags times the number of multiprocessors as specified by the device attribute CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NOT_PERMITTED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the attempted operation is not permitted. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_NOT_SUPPORTED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the attempted operation is not supported on the current system or device. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_SYSTEM_NOT_READY: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the system is not yet ready to start any CUDA work. To continue using CUDA, verify the system configuration is in a valid state and all required driver daemons are actively running. More information about this error can be found in the system specific user guide. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_SYSTEM_DRIVER_MISMATCH: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that there is a mismatch between the versions of the display driver and the CUDA driver. Refer to the compatibility documentation for supported versions. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_COMPAT_NOT_SUPPORTED_ON_DEVICE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the system was upgraded to run with forward compatibility but the visible hardware detected by CUDA does not support this configuration. Refer to the compatibility documentation for the supported hardware matrix or ensure that only supported hardware is visible during initialization via the CUDA_VISIBLE_DEVICES environment variable. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_STREAM_CAPTURE_UNSUPPORTED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the operation is not permitted when the stream is capturing. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_STREAM_CAPTURE_INVALIDATED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the current capture sequence on the stream has been invalidated due to a previous error. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_STREAM_CAPTURE_MERGE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the operation would have resulted in a merge of two independent capture sequences. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_STREAM_CAPTURE_UNMATCHED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the capture was not initiated in this stream. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_STREAM_CAPTURE_UNJOINED: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the capture sequence contains a fork that was not joined to the primary stream. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_STREAM_CAPTURE_ISOLATION: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that a dependency would have been created which crosses the capture sequence boundary. Only implicit in-stream ordering dependencies are allowed to cross the boundary. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_STREAM_CAPTURE_IMPLICIT: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates a disallowed implicit dependency on a current capture sequence from cudaStreamLegacy. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_CAPTURED_EVENT: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the operation is not permitted on an event which was last recorded in a capturing stream. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_STREAM_CAPTURE_WRONG_THREAD: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: A stream capture sequence not initiated with the CU_STREAM_CAPTURE_MODE_RELAXED argument to cuStreamBeginCapture was passed to cuStreamEndCapture in a different thread. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_TIMEOUT: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the timeout specified for the wait operation has lapsed. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_GRAPH_EXEC_UPDATE_FAILURE: - printf(R"===(CCUDAHandler: + logger.log(R"===(CCUDAHandler: This error indicates that the graph update was not performed because it included changes which violated constraints specific to instantiated graph update. - )==="); + )===",system::ILogger::ELL_ERROR); break; case CUDA_ERROR_UNKNOWN: default: - printf("CCUDAHandler: Unknown CUDA Error!\n"); + logger.log("CCUDAHandler: Unknown CUDA Error!\n",system::ILogger::ELL_ERROR); break; } _NBL_DEBUG_BREAK_IF(true); return false; } +bool CCUDAHandler::defaultHandleResult(nvrtcResult result) +{ + switch (result) + { + case NVRTC_SUCCESS: + return true; + break; + default: + if (m_nvrtc.pnvrtcGetErrorString) + m_logger.log("%s\n",system::ILogger::ELL_ERROR,m_nvrtc.pnvrtcGetErrorString(result)); + else + m_logger.log(R"===(CudaHandler: `pnvrtcGetErrorString` is nullptr, the nvrtc library probably not found on the system.\n)===",system::ILogger::ELL_ERROR); + break; + } + _NBL_DEBUG_BREAK_IF(true); + return false; +} + +core::smart_refctd_ptr CCUDAHandler::create(system::ISystem* system, core::smart_refctd_ptr&& _logger) +{ + CUDA cuda = CUDA( + #if defined(_NBL_WINDOWS_API_) + "nvcuda" + #elif defined(_NBL_POSIX_API_) + "cuda" + #endif + ); + + NVRTC nvrtc = {}; + #if defined(_NBL_WINDOWS_API_) + // Perpetual TODO: any new CUDA releases we need to account for? + const char* nvrtc64_versions[] = { "nvrtc64_111","nvrtc64_110","nvrtc64_102","nvrtc64_101","nvrtc64_100","nvrtc64_92","nvrtc64_91","nvrtc64_90","nvrtc64_80","nvrtc64_75","nvrtc64_70",nullptr }; + const char* nvrtc64_suffices[] = {"","_","_0","_1","_2",nullptr}; + for (auto verpath=nvrtc64_versions; *verpath; verpath++) + { + for (auto suffix=nvrtc64_suffices; *suffix; suffix++) + { + std::string path(*verpath); + path += *suffix; + nvrtc = NVRTC(path.c_str()); + if (nvrtc.pnvrtcVersion) + break; + } + if (nvrtc.pnvrtcVersion) + break; + } + #elif defined(_NBL_POSIX_API_) + nvrtc = NVRTC("nvrtc"); + //nvrtc_builtins = NVRTC("nvrtc-builtins"); + #endif + + + // need a complex safe calling chain because DLL/SO might not have loaded + #define SAFE_CUDA_CALL(FUNC,...) \ + {\ + if (!cuda.p ## FUNC)\ + return nullptr;\ + auto result = cuda.p ## FUNC ## (__VA_ARGS__);\ + if (result!=CUDA_SUCCESS)\ + return nullptr;\ + } + + SAFE_CUDA_CALL(cuInit,0) + + int cudaVersion = 0; + SAFE_CUDA_CALL(cuDriverGetVersion,&cudaVersion) + if (cudaVersion<9000) + return nullptr; + + // stop the pollution + #undef SAFE_CUDA_CALL + + + // check nvrtc existence and compatibility + if (!nvrtc.pnvrtcVersion) + return nullptr; + int nvrtcVersion[2] = { -1,-1 }; + nvrtc.pnvrtcVersion(nvrtcVersion+0,nvrtcVersion+1); + if (nvrtcVersion[0]<9) + return nullptr; + + + CCUDAHandler* handler = new CCUDAHandler(std::move(cuda), std::move(nvrtc),/*std::move(headers)*/{}, std::move(_logger), cudaVersion); + return core::smart_refctd_ptr(handler,core::dont_grab); +} + +#if 0 +core::vector > CCUDAHandler::headers; +core::vector CCUDAHandler::headerContents; +core::vector CCUDAHandler::headerNames; +#endif nvrtcResult CCUDAHandler::getProgramLog(nvrtcProgram prog, std::string& log) { size_t _size = 0ull; - nvrtcResult sizeRes = nvrtc.pnvrtcGetProgramLogSize(prog, &_size); + nvrtcResult sizeRes = m_nvrtc.pnvrtcGetProgramLogSize(prog, &_size); if (sizeRes != NVRTC_SUCCESS) return sizeRes; if (_size == 0ull) return NVRTC_ERROR_INVALID_INPUT; log.resize(_size); - return nvrtc.pnvrtcGetProgramLog(prog, log.data()); + return m_nvrtc.pnvrtcGetProgramLog(prog,log.data()); } -nvrtcResult CCUDAHandler::getPTX(nvrtcProgram prog, std::string& ptx) +std::pair,nvrtcResult> CCUDAHandler::getPTX(nvrtcProgram prog) { size_t _size = 0ull; - nvrtcResult sizeRes = nvrtc.pnvrtcGetPTXSize(prog, &_size); + nvrtcResult sizeRes = m_nvrtc.pnvrtcGetPTXSize(prog,&_size); if (sizeRes!=NVRTC_SUCCESS) - return sizeRes; + return {nullptr,sizeRes}; if (_size==0ull) - return NVRTC_ERROR_INVALID_INPUT; + return {nullptr,NVRTC_ERROR_INVALID_INPUT}; - ptx.resize(_size); - return nvrtc.pnvrtcGetPTX(prog,ptx.data()); + auto ptx = core::make_smart_refctd_ptr(_size); + return {std::move(ptx),m_nvrtc.pnvrtcGetPTX(prog,reinterpret_cast(ptx->getPointer()))}; } +#if 0 + const int archVersion[2] = { tmp.attributes[CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR],tmp.attributes[CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR] }; + if (archVersion[0] > 8 || archVersion[0] == 8 && archVersion[1] > 0) + { + assert(strcmp(virtualCUDAArchitectures[13], "-arch=compute_80") == 0); + if (!virtualCUDAArchitecture) + virtualCUDAArchitecture = virtualCUDAArchitectures[13]; + } + else + { + const std::string virtualArchString = "-arch=compute_" + std::to_string(archVersion[0]) + std::to_string(archVersion[1]); + + int32_t i = sizeof(virtualCUDAArchitectures) / sizeof(const char*); + while (i > 0) + if (virtualCUDAArchitecture == virtualCUDAArchitectures[--i] || !virtualCUDAArchitecture) + break; + + if (!virtualCUDAArchitecture || virtualArchString != virtualCUDAArchitecture) + { + i++; + while (i > 0) + if (virtualArchString == virtualCUDAArchitectures[--i]) + { + virtualCUDAArchitecture = virtualCUDAArchitectures[i]; + break; + } + } + } + +if (!virtualCUDAArchitecture) +return result = CUDA_ERROR_INVALID_DEVICE; +#endif +core::smart_refctd_ptr CCUDAHandler::createDevice(core::smart_refctd_ptr&& vulkanConnection, IPhysicalDevice* physicalDevice) +{ + if (!vulkanConnection) + return nullptr; + const auto devices = vulkanConnection->getPhysicalDevices(); + if (std::find(devices.begin(),devices.end(),physicalDevice)==devices.end()) + return nullptr; + + int deviceCount = 0; + if (m_cuda.pcuDeviceGetCount(&deviceCount)!=CUDA_SUCCESS || deviceCount<=0) + return nullptr; + + for (int ordinal=0; ordinalgetLimits().deviceUUID,VK_UUID_SIZE)) + { + int attributes[CU_DEVICE_ATTRIBUTE_MAX] = {}; + for (int i=0; i(i),handle); + + CCUDADevice::E_VIRTUAL_ARCHITECTURE arch = CCUDADevice::EVA_COUNT; + const int& archMajor = attributes[CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR]; + const int& archMinor = attributes[CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR]; + switch (archMajor) + { + case 3: + switch (archMinor) + { + case 0: + arch = CCUDADevice::EVA_30; + break; + case 2: + arch = CCUDADevice::EVA_32; + break; + case 5: + arch = CCUDADevice::EVA_35; + break; + case 7: + arch = CCUDADevice::EVA_37; + break; + default: + break; + } + break; + case 5: + switch (archMinor) + { + case 0: + arch = CCUDADevice::EVA_50; + break; + case 2: + arch = CCUDADevice::EVA_52; + break; + case 3: + arch = CCUDADevice::EVA_53; + break; + default: + break; + } + break; + case 6: + switch (archMinor) + { + case 0: + arch = CCUDADevice::EVA_60; + break; + case 1: + arch = CCUDADevice::EVA_61; + break; + case 2: + arch = CCUDADevice::EVA_62; + break; + default: + break; + } + break; + case 7: + switch (archMinor) + { + case 0: + arch = CCUDADevice::EVA_70; + break; + case 2: + arch = CCUDADevice::EVA_72; + break; + case 5: + arch = CCUDADevice::EVA_75; + break; + default: + break; + } + break; + default: + if (archMajor>=8) + arch = CCUDADevice::EVA_80; + break; + } + if (arch==CCUDADevice::EVA_COUNT) + continue; + + auto device = new CCUDADevice(std::move(vulkanConnection),physicalDevice,arch); + return core::smart_refctd_ptr(device,core::dont_grab); + } + } + return nullptr; } + } #endif // _NBL_COMPILE_WITH_CUDA_ From fafa8e7e9477b02769402fa3a7ab48c5b622e52e Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 21:26:06 +0100 Subject: [PATCH 18/91] fix CUDA JIT headers --- include/nbl/video/CCUDADevice.h | 5 +- include/nbl/video/CCUDAHandler.h | 227 +++++++++++-------------------- src/nbl/video/CCUDAHandler.cpp | 67 ++++----- 3 files changed, 112 insertions(+), 187 deletions(-) diff --git a/include/nbl/video/CCUDADevice.h b/include/nbl/video/CCUDADevice.h index c444e05254..1120224fdb 100644 --- a/include/nbl/video/CCUDADevice.h +++ b/include/nbl/video/CCUDADevice.h @@ -63,7 +63,10 @@ class CCUDADevice : public core::IReferenceCounted }; inline E_VIRTUAL_ARCHITECTURE getVirtualArchitecture() {return m_virtualArchitecture;} - inline const auto& geDefaultCompileOptions() const {return m_defaultCompileOptions;} + inline core::SRange geDefaultCompileOptions() const + { + return {m_defaultCompileOptions.data(),m_defaultCompileOptions.data()+m_defaultCompileOptions.size()}; + } // TODO/REDO Vulkan: https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__EXTRES__INTEROP.html // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#vulkan-interoperability diff --git a/include/nbl/video/CCUDAHandler.h b/include/nbl/video/CCUDAHandler.h index 64ff944298..01774b25d2 100644 --- a/include/nbl/video/CCUDAHandler.h +++ b/include/nbl/video/CCUDAHandler.h @@ -4,6 +4,9 @@ #ifndef _NBL_VIDEO_C_CUDA_HANDLER_H_ #define _NBL_VIDEO_C_CUDA_HANDLER_H_ +#include "nbl/core/declarations.h" +#include "nbl/core/definitions.h" + #include "nbl/system/declarations.h" #include "nbl/video/CCUDADevice.h" @@ -134,203 +137,133 @@ class CCUDAHandler : public core::IReferenceCounted ); const NVRTC& getNVRTCFunctionTable() const {return m_nvrtc;} -#if 0 // - static core::SRange getCUDASTDHeaders() + inline core::SRange getSTDHeaders() { - auto begin = headers.empty() ? nullptr:reinterpret_cast(&headers[0].get()); - return {begin,begin+headers.size()}; + auto begin = m_headers.empty() ? nullptr:(&m_headers[0].get()); + return {begin,begin+m_headers.size()}; } - static const auto& getCUDASTDHeaderContents() { return headerContents; } - static const auto& getCUDASTDHeaderNames() { return headerNames; } + inline const auto& getSTDHeaderContents() { return m_headerContents; } + inline const auto& getSTDHeaderNames() { return m_headerNames; } // - static nvrtcResult createProgram( nvrtcProgram* prog, const char* source, const char* name, - const char* const* headersBegin=nullptr, const char* const* headersEnd=nullptr, - const char* const* includeNamesBegin=nullptr, const char* const* includeNamesEnd=nullptr) + nvrtcResult createProgram(nvrtcProgram* prog, std::string&& source, const char* name, const int headerCount=0, const char* const* headerContents=nullptr, const char* const* includeNames=nullptr); + inline nvrtcResult createProgram(nvrtcProgram* prog, const char* source, const char* name, const int headerCount=0, const char* const* headerContents=nullptr, const char* const* includeNames=nullptr) { - auto headerCount = std::distance(headersBegin, headersEnd); - if (headerCount) - { - if (std::distance(includeNamesBegin,includeNamesEnd)!=headerCount) - return NVRTC_ERROR_INVALID_INPUT; - } - else - { - headersBegin = nullptr; - includeNamesBegin = nullptr; - } - auto extraLen = strlen(CUDA_EXTRA_DEFINES); - auto origLen = strlen(source); - auto totalLen = extraLen+origLen; - auto tmp = _NBL_NEW_ARRAY(char,totalLen+1u); - memcpy(tmp, CUDA_EXTRA_DEFINES, extraLen); - memcpy(tmp+extraLen, source, origLen); - tmp[totalLen] = 0; - auto result = nvrtc.pnvrtcCreateProgram(prog, tmp, name, headerCount, headersBegin, includeNamesBegin); - _NBL_DELETE_ARRAY(tmp,totalLen); - return result; + return createProgram(prog,std::string(source),name,headerCount,headerContents,includeNames); } - - template - static nvrtcResult createProgram( nvrtcProgram* prog, nbl::io::IReadFile* main, - const HeaderFileIt includesBegin, const HeaderFileIt includesEnd) + inline nvrtcResult createProgram(nvrtcProgram* prog, system::IFile* file, const int headerCount=0, const char* const* headerContents=nullptr, const char* const* includeNames=nullptr) { - int numHeaders = std::distance(includesBegin,includesEnd); - core::vector headers(numHeaders); - core::vector includeNames(numHeaders); - size_t sourceIt = strlen(CUDA_EXTRA_DEFINES); - size_t sourceSize = sourceIt+main->getSize(); - sourceSize++; - for (auto it=includesBegin; it!=includesEnd; it++) - { - sourceSize += it->getSize()+1u; - includeNames.emplace_back(it->getFileName().c_str()); - } - core::vector sources(sourceSize); - memcpy(sources.data(),CUDA_EXTRA_DEFINES,sourceIt); - auto filesize = main->getSize(); - main->read(sources.data()+sourceIt,filesize); - sourceIt += filesize; - sources[sourceIt++] = 0; - for (auto it=includesBegin; it!=includesEnd; it++) - { - auto oldpos = it->getPos(); - it->seek(0ull); + const auto filesize = file->getSize(); + std::string source(filesize+1u,'0'); - auto ptr = sources.data()+sourceIt; - headers.push_back(ptr); - filesize = it->getSize(); - it->read(ptr,filesize); - sourceIt += filesize; - sources[sourceIt++] = 0; + system::future bytesRead; + file->read(bytesRead,source.data(),0u,file->getSize()); + source.resize(bytesRead.get()); - it->seek(oldpos); - } - return nvrtc.pnvrtcCreateProgram(prog, sources.data(), main->getFileName().c_str(), numHeaders, headers.data(), includeNames.data()); + return createProgram(prog,std::move(source),file->getFileName().string().c_str(),headerCount,headerContents,includeNames); } -#endif + // - inline nvrtcResult compileProgram(nvrtcProgram prog, const size_t optionCount, const char* const* options) + inline nvrtcResult compileProgram(nvrtcProgram prog, core::SRange options) { - return m_nvrtc.pnvrtcCompileProgram(prog, optionCount, options); - } - template&> - inline nvrtcResult compileProgram(nvrtcProgram prog, OptionsT options) - { - return compileProgram(prog, options.size(), options.begin()); - } - inline nvrtcResult compileProgram(nvrtcProgram prog, const std::vector& options) - { - return compileProgram(prog, options.size(), options.data()); + return m_nvrtc.pnvrtcCompileProgram(prog,options.size(),options.begin()); } // nvrtcResult getProgramLog(nvrtcProgram prog, std::string& log); // - std::pair,nvrtcResult> getPTX(nvrtcProgram prog); + struct ptx_and_nvrtcResult_t + { + core::smart_refctd_ptr ptx; + nvrtcResult result; + }; + ptx_and_nvrtcResult_t getPTX(nvrtcProgram prog); -#if 0 // - template&> - static nvrtcResult compileDirectlyToPTX(std::string& ptx, const char* source, const char* filename, - const char* const* headersBegin = nullptr, const char* const* headersEnd = nullptr, - const char* const* includeNamesBegin = nullptr, const char* const* includeNamesEnd = nullptr, - OptionsT options = { _NBL_DEFAULT_NVRTC_OPTIONS }, - std::string* log = nullptr) + inline ptx_and_nvrtcResult_t compileDirectlyToPTX( + std::string&& source, const char* filename, core::SRange nvrtcOptions, + const int headerCount=0, const char* const* headerContents=nullptr, const char* const* includeNames=nullptr, + std::string* log=nullptr + ) { nvrtcProgram program = nullptr; nvrtcResult result = NVRTC_ERROR_PROGRAM_CREATION_FAILURE; - auto cleanup = core::makeRAIIExiter([&program, &result]() -> void { - if (result != NVRTC_SUCCESS && program) - nvrtc.pnvrtcDestroyProgram(&program); - }); - - result = createProgram(&program, source, filename, headersBegin, headersEnd, includeNamesBegin, includeNamesEnd); - - if (result != NVRTC_SUCCESS) - return result; + auto cleanup = core::makeRAIIExiter([&]() -> void + { + if (result!=NVRTC_SUCCESS && program) + m_nvrtc.pnvrtcDestroyProgram(&program); // TODO: do we need to destroy the program if we successfully get PTX? + }); - return result = compileDirectlyToPTX_helper(ptx, program, std::forward(options), log); + result = createProgram(&program,std::move(source),filename,headerCount,headerContents,includeNames); + return compileDirectlyToPTX_impl(result,program,nvrtcOptions,log); } - - template&> - static nvrtcResult compileDirectlyToPTX(std::string& ptx, nbl::io::IReadFile* main, - const char* const* headersBegin = nullptr, const char* const* headersEnd = nullptr, - const char* const* includeNamesBegin = nullptr, const char* const* includeNamesEnd = nullptr, - OptionsT options = { _NBL_DEFAULT_NVRTC_OPTIONS }, - std::string* log = nullptr) + inline ptx_and_nvrtcResult_t compileDirectlyToPTX( + const char* source, const char* filename, core::SRange nvrtcOptions, + const int headerCount=0, const char* const* headerContents=nullptr, const char* const* includeNames=nullptr, + std::string* log=nullptr + ) { - char* data = new char[main->getSize()+1ull]; - main->read(data, main->getSize()); - data[main->getSize()] = 0; - auto result = compileDirectlyToPTX(ptx, data, main->getFileName().c_str(), headersBegin, headersEnd, std::forward(options), log); - delete[] data; - - return result; + return compileDirectlyToPTX(std::string(source),filename,nvrtcOptions,headerCount,headerContents,includeNames,log); } - - template&> - static nvrtcResult compileDirectlyToPTX(std::string& ptx, nbl::io::IReadFile* main, - CompileArgsT includesBegin, CompileArgsT includesEnd, - OptionsT options={_NBL_DEFAULT_NVRTC_OPTIONS}, - std::string* log=nullptr) + inline ptx_and_nvrtcResult_t compileDirectlyToPTX( + system::IFile* file, core::SRange nvrtcOptions, + const int headerCount=0, const char* const* headerContents=nullptr, const char* const* includeNames=nullptr, + std::string* log=nullptr + ) { nvrtcProgram program = nullptr; nvrtcResult result = NVRTC_ERROR_PROGRAM_CREATION_FAILURE; - auto cleanup = core::makeRAIIExiter([&program,&result]() -> void { + auto cleanup = core::makeRAIIExiter([&]() -> void + { if (result!=NVRTC_SUCCESS && program) - nvrtc.pnvrtcDestroyProgram(&program); + m_nvrtc.pnvrtcDestroyProgram(&program); // TODO: do we need to destroy the program if we successfully get PTX? }); - result = createProgram(&program, main, includesBegin, includesEnd); - if (result!=NVRTC_SUCCESS) - return result; - return result = compileDirectlyToPTX_helper(ptx,program,std::forward(options),log); + result = createProgram(&program,file,headerCount,headerContents,includeNames); + return compileDirectlyToPTX_impl(result,program,nvrtcOptions,log); } -#endif core::smart_refctd_ptr createDevice(core::smart_refctd_ptr&& vulkanConnection, IPhysicalDevice* physicalDevice); protected: - CCUDAHandler( - CUDA&& _cuda, - NVRTC&& _nvrtc, - core::vector>&& _headers, - core::smart_refctd_ptr&& _logger, - int _version - ); + CCUDAHandler(CUDA&& _cuda, NVRTC&& _nvrtc, core::vector>&& _headers, core::smart_refctd_ptr&& _logger, int _version) + : m_cuda(std::move(_cuda)), m_nvrtc(std::move(_nvrtc)), m_headers(std::move(_headers)), m_logger(std::move(_logger)), m_version(_version) + { + for (auto& header : m_headers) + { + m_headerContents.push_back(reinterpret_cast(header->getMappedPointer())); + m_headerNamesStorage.push_back(header->getFileName().string()); + m_headerNames.push_back(m_headerNamesStorage.back().c_str()); + } + } ~CCUDAHandler() = default; - -#if 0 - static core::vector headerContents; - static core::vector headerNames; - -#ifdef _MSC_VER - _NBL_STATIC_INLINE_CONSTEXPR const char* CUDA_EXTRA_DEFINES = "#ifndef _WIN64\n#define _WIN64\n#endif\n"; -#else - _NBL_STATIC_INLINE_CONSTEXPR const char* CUDA_EXTRA_DEFINES = "#ifndef __LP64__\n#define __LP64__\n#endif\n"; -#endif - - template&> - static nvrtcResult compileDirectlyToPTX_helper(std::string& ptx, nvrtcProgram program, OptionsT options, std::string* log=nullptr) + + // + inline ptx_and_nvrtcResult_t compileDirectlyToPTX_impl(nvrtcResult result, nvrtcProgram program, core::SRange nvrtcOptions, std::string* log) { - nvrtcResult result = compileProgram(program,options); - if (log) - getProgramLog(program, *log); if (result!=NVRTC_SUCCESS) - return result; + return {nullptr,result}; - return getPTX(program, ptx); + result = compileProgram(program,nvrtcOptions); + if (log) + getProgramLog(program,*log); + if (result!=NVRTC_SUCCESS) + return {nullptr,result}; + + return getPTX(program); } -#endif + // function tables CUDA m_cuda; NVRTC m_nvrtc; // core::vector> m_headers; + core::vector m_headerContents; + core::vector m_headerNamesStorage; + core::vector m_headerNames; system::logger_opt_smart_ptr m_logger; int m_version; }; diff --git a/src/nbl/video/CCUDAHandler.cpp b/src/nbl/video/CCUDAHandler.cpp index ddddf77c45..183afe6b43 100644 --- a/src/nbl/video/CCUDAHandler.cpp +++ b/src/nbl/video/CCUDAHandler.cpp @@ -402,6 +402,8 @@ core::smart_refctd_ptr CCUDAHandler::create(system::ISystem* syste "nvcuda" #elif defined(_NBL_POSIX_API_) "cuda" + #else + #error "Unsuported Platform" #endif ); @@ -426,6 +428,8 @@ core::smart_refctd_ptr CCUDAHandler::create(system::ISystem* syste #elif defined(_NBL_POSIX_API_) nvrtc = NVRTC("nvrtc"); //nvrtc_builtins = NVRTC("nvrtc-builtins"); + #else + #error "Unsuported Platform" #endif @@ -458,16 +462,34 @@ core::smart_refctd_ptr CCUDAHandler::create(system::ISystem* syste if (nvrtcVersion[0]<9) return nullptr; + // add headers + core::vector> headers; + for (const auto& it : jitify::detail::get_jitsafe_headers_map()) + { + const void* contents = it.second.data(); + headers.push_back(core::make_smart_refctd_ptr>( + core::smart_refctd_ptr(system),it.first.c_str(), + core::bitflag(system::IFile::ECF_READ)|system::IFile::ECF_MAPPABLE, + const_cast(contents),it.second.size()+1u + )); + } + - CCUDAHandler* handler = new CCUDAHandler(std::move(cuda), std::move(nvrtc),/*std::move(headers)*/{}, std::move(_logger), cudaVersion); + CCUDAHandler* handler = new CCUDAHandler(std::move(cuda), std::move(nvrtc),std::move(headers), std::move(_logger), cudaVersion); return core::smart_refctd_ptr(handler,core::dont_grab); } -#if 0 -core::vector > CCUDAHandler::headers; -core::vector CCUDAHandler::headerContents; -core::vector CCUDAHandler::headerNames; +nvrtcResult CCUDAHandler::createProgram(nvrtcProgram* prog, std::string&& source, const char* name, const int headerCount, const char* const* headerContents, const char* const* includeNames) +{ +#if defined(_NBL_WINDOWS_API_) + source.insert(0ull,"#ifndef _WIN64\n#define _WIN64\n#endif\n"); +#elif defined(_NBL_POSIX_API_) + source.insert(0ull,"#ifndef __LP64__\n#define __LP64__\n#endif\n"); +#else +#error "Unsuported Platform" #endif + return m_nvrtc.pnvrtcCreateProgram(prog,source.c_str(),name,headerCount,headerContents,includeNames); +} nvrtcResult CCUDAHandler::getProgramLog(nvrtcProgram prog, std::string& log) { @@ -482,7 +504,7 @@ nvrtcResult CCUDAHandler::getProgramLog(nvrtcProgram prog, std::string& log) return m_nvrtc.pnvrtcGetProgramLog(prog,log.data()); } -std::pair,nvrtcResult> CCUDAHandler::getPTX(nvrtcProgram prog) +CCUDAHandler::ptx_and_nvrtcResult_t CCUDAHandler::getPTX(nvrtcProgram prog) { size_t _size = 0ull; nvrtcResult sizeRes = m_nvrtc.pnvrtcGetPTXSize(prog,&_size); @@ -495,39 +517,6 @@ std::pair,nvrtcResult> CCUDAHandler::g return {std::move(ptx),m_nvrtc.pnvrtcGetPTX(prog,reinterpret_cast(ptx->getPointer()))}; } -#if 0 - const int archVersion[2] = { tmp.attributes[CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR],tmp.attributes[CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR] }; - if (archVersion[0] > 8 || archVersion[0] == 8 && archVersion[1] > 0) - { - assert(strcmp(virtualCUDAArchitectures[13], "-arch=compute_80") == 0); - if (!virtualCUDAArchitecture) - virtualCUDAArchitecture = virtualCUDAArchitectures[13]; - } - else - { - const std::string virtualArchString = "-arch=compute_" + std::to_string(archVersion[0]) + std::to_string(archVersion[1]); - - int32_t i = sizeof(virtualCUDAArchitectures) / sizeof(const char*); - while (i > 0) - if (virtualCUDAArchitecture == virtualCUDAArchitectures[--i] || !virtualCUDAArchitecture) - break; - - if (!virtualCUDAArchitecture || virtualArchString != virtualCUDAArchitecture) - { - i++; - while (i > 0) - if (virtualArchString == virtualCUDAArchitectures[--i]) - { - virtualCUDAArchitecture = virtualCUDAArchitectures[i]; - break; - } - } - } - -if (!virtualCUDAArchitecture) -return result = CUDA_ERROR_INVALID_DEVICE; -#endif - core::smart_refctd_ptr CCUDAHandler::createDevice(core::smart_refctd_ptr&& vulkanConnection, IPhysicalDevice* physicalDevice) { if (!vulkanConnection) From 02610779ac4ad616c4e093c5d61ff21c5e245e86 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 17 Feb 2022 23:17:15 +0100 Subject: [PATCH 19/91] Add `void* getNativeHandle()` to everything except OpenGL logical devices, queues and swapchains --- {src => include}/nbl/video/CEGL.h | 4 +- {src => include}/nbl/video/CEGLCaller.h | 49 ++------------ include/nbl/video/COpenGL_Connection.h | 14 +++- .../nbl/video/CThreadSafeGPUQueueAdapter.h | 5 ++ include/nbl/video/IAPIConnection.h | 2 + include/nbl/video/IGPUBuffer.h | 4 ++ include/nbl/video/IGPUBufferView.h | 4 ++ include/nbl/video/IGPUCommandBuffer.h | 4 ++ include/nbl/video/IGPUCommandPool.h | 4 ++ include/nbl/video/IGPUFence.h | 4 ++ include/nbl/video/IGPUImage.h | 4 ++ include/nbl/video/IGPUImageView.h | 4 ++ include/nbl/video/IGPUQueue.h | 67 ++++++++++--------- include/nbl/video/IGPUSampler.h | 4 ++ include/nbl/video/IGPUSemaphore.h | 4 ++ include/nbl/video/ILogicalDevice.h | 4 ++ include/nbl/video/ISwapchain.h | 4 ++ src/nbl/video/COpenGLBuffer.h | 1 + src/nbl/video/COpenGLBufferView.h | 6 +- src/nbl/video/COpenGLCommandBuffer.h | 2 + src/nbl/video/COpenGLCommandPool.h | 2 + src/nbl/video/COpenGLFence.h | 27 ++++---- src/nbl/video/COpenGLImage.h | 3 +- src/nbl/video/COpenGLImageView.h | 3 +- src/nbl/video/COpenGLSampler.h | 3 +- src/nbl/video/COpenGLSemaphore.h | 7 +- src/nbl/video/COpenGLSync.h | 11 ++- src/nbl/video/COpenGL_Connection.cpp | 7 +- src/nbl/video/COpenGL_Queue.h | 6 +- src/nbl/video/COpenGL_Swapchain.h | 2 + src/nbl/video/CVulkanBuffer.h | 3 +- src/nbl/video/CVulkanBufferView.h | 5 +- src/nbl/video/CVulkanCommandBuffer.h | 7 +- src/nbl/video/CVulkanCommandPool.h | 5 +- src/nbl/video/CVulkanFence.h | 3 +- src/nbl/video/CVulkanImage.h | 3 +- src/nbl/video/CVulkanImageView.h | 3 +- src/nbl/video/CVulkanLogicalDevice.h | 10 +-- src/nbl/video/CVulkanQueue.h | 3 +- src/nbl/video/CVulkanSampler.h | 3 +- src/nbl/video/CVulkanSemaphore.h | 5 +- src/nbl/video/CVulkanSwapchain.h | 7 +- src/nbl/video/IOpenGLSyncPrimitiveBase.h | 4 +- src/nbl/video/IOpenGL_FunctionTable.h | 19 +++--- src/nbl/video/IOpenGL_LogicalDevice.h | 8 ++- src/nbl/video/IOpenGL_PhysicalDeviceBase.h | 33 +++++---- 46 files changed, 224 insertions(+), 162 deletions(-) rename {src => include}/nbl/video/CEGL.h (94%) mode change 100755 => 100644 rename {src => include}/nbl/video/CEGLCaller.h (63%) diff --git a/src/nbl/video/CEGL.h b/include/nbl/video/CEGL.h old mode 100755 new mode 100644 similarity index 94% rename from src/nbl/video/CEGL.h rename to include/nbl/video/CEGL.h index 0bb17d5a5d..b2ae7366d1 --- a/src/nbl/video/CEGL.h +++ b/include/nbl/video/CEGL.h @@ -1,5 +1,5 @@ -#ifndef __NBL_C_EGL_H_INCLUDED__ -#define __NBL_C_EGL_H_INCLUDED__ +#ifndef _NBL_C_EGL_H_INCLUDED_ +#define _NBL_C_EGL_H_INCLUDED_ //#include "nbl/video/CWaylandCaller.h" #include "nbl/video/CEGLCaller.h" diff --git a/src/nbl/video/CEGLCaller.h b/include/nbl/video/CEGLCaller.h similarity index 63% rename from src/nbl/video/CEGLCaller.h rename to include/nbl/video/CEGLCaller.h index 85753df3f1..4a8e38b62c 100644 --- a/src/nbl/video/CEGLCaller.h +++ b/include/nbl/video/CEGLCaller.h @@ -1,5 +1,5 @@ -#ifndef __NBL_C_EGL_CALLER_H_INCLUDED__ -#define __NBL_C_EGL_CALLER_H_INCLUDED__ +#ifndef _NBL_C_EGL_CALLER_H_INCLUDED_ +#define _NBL_C_EGL_CALLER_H_INCLUDED_ #include "EGL/egl.h" #include "nbl/system/DynamicFunctionCaller.h" @@ -59,7 +59,6 @@ namespace nbl::video::egl eglWaitSync,\ eglGetPlatformDependentHandles -#define NBL_IMPL_GET_FUNC_PTR(FUNC_NAME) reinterpret_cast(&::FUNC_NAME) class CEGLLoader : public system::FuncPtrLoader { system::DefaultFuncPtrLoader m_libEGL; @@ -84,56 +83,18 @@ class CEGLLoader : public system::FuncPtrLoader { if (m_libEGL.isLibraryLoaded()) return m_libEGL.loadFuncPtr(funcname); + + #define NBL_IMPL_GET_FUNC_PTR(FUNC_NAME) reinterpret_cast(&::FUNC_NAME) #define LOAD_DYNLIB_FUNCPTR(FUNC_NAME) if (strcmp(funcname, #FUNC_NAME )==0) \ return NBL_IMPL_GET_FUNC_PTR(FUNC_NAME); NBL_FOREACH(LOAD_DYNLIB_FUNCPTR,NBL_EGL_FUNC_LIST) #undef LOAD_DYNLIB_FUNCPTR + #undef NBL_IMPL_GET_FUNC_PTR return nullptr; } }; NBL_SYSTEM_DECLARE_DYNAMIC_FUNCTION_CALLER_CLASS(CEGLCaller,CEGLLoader,NBL_EGL_FUNC_LIST); -/* -class CEGLCaller final : public core::Uncopyable -{ - - - - - public: - #define NBL_IMPL_INIT_EGL_FUNCPTR(FUNC_NAME) ,p ## FUNC_NAME ( NBL_IMPL_GET_FUNC_PTR(FUNC_NAME) ) - #define NBL_IMPL_INIT_EGL_FUNC_PTRS(...)\ - NBL_FOREACH(NBL_IMPL_INIT_EGL_FUNCPTR,__VA_ARGS__) - CEGLCaller() : core::Uncopyable() - NBL_IMPL_INIT_EGL_FUNC_PTRS(NBL_EGL_FUNC_LIST) - { - } - #undef NBL_IMPL_INIT_EGL_FUNC_PTRS - #undef NBL_IMPL_INIT_EGL_FUNCPTR - #undef NBL_IMPL_GET_FUNC_PTR - CEGLCaller(CEGLCaller&& other) - { - operator=(std::move(other)); - } - - CEGLCaller& operator=(CEGLCaller&& other) - { - #define NBL_IMPL_SWAP_EGL_FUNC_PTRS(...)\ - NBL_FOREACH(NBL_SYSTEM_IMPL_SWAP_DYNLIB_FUNCPTR,__VA_ARGS__); - NBL_IMPL_SWAP_EGL_FUNC_PTRS(NBL_EGL_FUNC_LIST); - #undef NBL_IMPL_SWAP_EGL_FUNC_PTRS - - return *this; - } - - #define NBL_IMPL_DECLARE_EGL_FUNC_PTRS(...)\ - NBL_FOREACH(NBL_SYSTEM_DECLARE_DYNLIB_FUNCPTR,__VA_ARGS__); - NBL_IMPL_DECLARE_EGL_FUNC_PTRS(NBL_EGL_FUNC_LIST) - #undef NBL_IMPL_DECLARE_EGL_FUNC_PTRS - -}; -*/ - #undef NBL_EGL_FUNC_LIST } diff --git a/include/nbl/video/COpenGL_Connection.h b/include/nbl/video/COpenGL_Connection.h index bffcfbbdb8..c1e678e7c5 100644 --- a/include/nbl/video/COpenGL_Connection.h +++ b/include/nbl/video/COpenGL_Connection.h @@ -1,10 +1,11 @@ -#ifndef __NBL_C_OPENGL__CONNECTION_H_INCLUDED__ -#define __NBL_C_OPENGL__CONNECTION_H_INCLUDED__ +#ifndef _NBL_C_OPENGL__CONNECTION_H_INCLUDED_ +#define _NBL_C_OPENGL__CONNECTION_H_INCLUDED_ #include "nbl/system/ISystem.h" #include "nbl/video/IAPIConnection.h" #include "nbl/video/debug/COpenGLDebugCallback.h" +#include "nbl/video/CEGL.h" namespace nbl::video { @@ -13,6 +14,13 @@ template class COpenGL_Connection final : public IAPIConnection { public: + // + struct SStuff + { + // to load function pointers, make EGL context current and use `egl->call.peglGetProcAddress("glFuncname")` + }; + + // static core::smart_refctd_ptr> create(core::smart_refctd_ptr&& sys, uint32_t appVer, const char* appName, COpenGLDebugCallback&& dbgCb); E_API_TYPE getAPIType() const override @@ -22,6 +30,8 @@ class COpenGL_Connection final : public IAPIConnection IDebugCallback* getDebugCallback() const override; + const egl::CEGL& getInternalObject() const; + private: COpenGL_Connection() : IAPIConnection() {} diff --git a/include/nbl/video/CThreadSafeGPUQueueAdapter.h b/include/nbl/video/CThreadSafeGPUQueueAdapter.h index ec23270e7f..b12f6179d3 100644 --- a/include/nbl/video/CThreadSafeGPUQueueAdapter.h +++ b/include/nbl/video/CThreadSafeGPUQueueAdapter.h @@ -55,6 +55,11 @@ class CThreadSafeGPUQueueAdapter : public IGPUQueue { return originalQueue; } + + virtual const void* getNativeHandle() const + { + return originalQueue->getNativeHandle(); + } }; } diff --git a/include/nbl/video/IAPIConnection.h b/include/nbl/video/IAPIConnection.h index 4fface5d2b..6c066e0124 100644 --- a/include/nbl/video/IAPIConnection.h +++ b/include/nbl/video/IAPIConnection.h @@ -15,6 +15,7 @@ class IPhysicalDevice; class IAPIConnection : public core::IReferenceCounted { public: + // TODO: are these "instance features" ? enum E_FEATURE { EF_SURFACE = 0, @@ -30,6 +31,7 @@ class IAPIConnection : public core::IReferenceCounted static core::SRange getDependentFeatures(const E_FEATURE feature); protected: + // TODO: move to IAPIConnection.cpp inline IAPIConnection() : m_physicalDevices(), m_rdoc_api(nullptr) { #ifdef _NBL_PLATFORM_WINDOWS_ diff --git a/include/nbl/video/IGPUBuffer.h b/include/nbl/video/IGPUBuffer.h index c2c2c63bcf..2422d83d7b 100644 --- a/include/nbl/video/IGPUBuffer.h +++ b/include/nbl/video/IGPUBuffer.h @@ -41,6 +41,10 @@ class IGPUBuffer : public asset::IBuffer, public IDriverMemoryBacked, public IBa inline uint64_t getSize() const override {return cachedMemoryReqs.vulkanReqs.size;} inline const SCachedCreationParams& getCachedCreationParams() const {return m_cachedCreationParams;} + + // OpenGL: const GLuint* handle of a Buffer + // Vulkan: const VkBuffer* + virtual const void* getNativeHandle() const = 0; protected: IGPUBuffer( diff --git a/include/nbl/video/IGPUBufferView.h b/include/nbl/video/IGPUBufferView.h index 31ea2ce170..07104e065a 100644 --- a/include/nbl/video/IGPUBufferView.h +++ b/include/nbl/video/IGPUBufferView.h @@ -24,6 +24,10 @@ class IGPUBufferView : public asset::IBufferView, public IBackendObj asset::IBufferView(std::move(_buffer), _format, _offset, _size), IBackendObject(std::move(dev)) {} + // OpenGL: const GLuint* handle of GL_TEXTURE_BUFFER + // Vulkan: const VkBufferView* + virtual const void* getNativeHandle() const = 0; + protected: virtual ~IGPUBufferView() = default; }; diff --git a/include/nbl/video/IGPUCommandBuffer.h b/include/nbl/video/IGPUCommandBuffer.h index 3a13338780..b9e00ee0a2 100644 --- a/include/nbl/video/IGPUCommandBuffer.h +++ b/include/nbl/video/IGPUCommandBuffer.h @@ -174,6 +174,10 @@ class IGPUCommandBuffer : return m_cachedInheritanceInfo; } + // OpenGL: nullptr, because commandbuffer doesn't exist in GL (we might expose the linked list command storage in the future) + // Vulkan: const VkCommandBuffer* + virtual const void* getNativeHandle() const = 0; + protected: friend class IGPUQueue; diff --git a/include/nbl/video/IGPUCommandPool.h b/include/nbl/video/IGPUCommandPool.h index 0362763ce2..8b010d9b4c 100644 --- a/include/nbl/video/IGPUCommandPool.h +++ b/include/nbl/video/IGPUCommandPool.h @@ -27,6 +27,10 @@ class IGPUCommandPool : public core::IReferenceCounted, public IBackendObject core::bitflag getCreationFlags() const { return m_flags; } uint32_t getQueueFamilyIndex() const { return m_familyIx; } + // OpenGL: nullptr, because commandpool doesn't exist in GL (we might expose the internal allocator in the future) + // Vulkan: const VkCommandPool* + virtual const void* getNativeHandle() const = 0; + protected: virtual ~IGPUCommandPool() = default; diff --git a/include/nbl/video/IGPUFence.h b/include/nbl/video/IGPUFence.h index c4b7b0fc3d..7f7f595c4c 100644 --- a/include/nbl/video/IGPUFence.h +++ b/include/nbl/video/IGPUFence.h @@ -30,6 +30,10 @@ class IGPUFence : public core::IReferenceCounted, public IBackendObject { } + // OpenGL: core::smart_refctd_ptr* + // Vulkan: const VkFence* + virtual void* getNativeHandle() = 0; + protected: virtual ~IGPUFence() = default; }; diff --git a/include/nbl/video/IGPUImage.h b/include/nbl/video/IGPUImage.h index 2e925eabad..51334edefe 100644 --- a/include/nbl/video/IGPUImage.h +++ b/include/nbl/video/IGPUImage.h @@ -55,6 +55,10 @@ class IGPUImage : public core::impl::ResolveAlignment, public IBackendObject public: const SCreationParams& getCreationParameters() const { return params; } + // OpenGL: const GLuint* handle of GL_TEXTURE_VIEW target + // Vulkan: const VKImageView* + virtual const void* getNativeHandle() const = 0; + protected: IGPUImageView(core::smart_refctd_ptr&& dev, SCreationParams&& _params) : IImageView(std::move(_params)), IBackendObject(std::move(dev)) {} virtual ~IGPUImageView() = default; diff --git a/include/nbl/video/IGPUQueue.h b/include/nbl/video/IGPUQueue.h index 058e6d3e7d..710c44ba4e 100644 --- a/include/nbl/video/IGPUQueue.h +++ b/include/nbl/video/IGPUQueue.h @@ -63,49 +63,52 @@ class IGPUQueue : public core::Interface, public core::Unmovable inline constexpr static float DEFAULT_QUEUE_PRIORITY = 1.f; + // OpenGL: GLsync_ + // Vulkan: const VkQueue* + virtual const void* getNativeHandle() const = 0; + protected: - - inline bool markCommandBuffersAsPending(uint32_t _count, const SSubmitInfo* _submits) - { - if(_submits == nullptr) - return false; - for (uint32_t i = 0u; i < _count; ++i) + inline bool markCommandBuffersAsPending(uint32_t _count, const SSubmitInfo* _submits) { - auto& submit = _submits[i]; - for (uint32_t j = 0u; j < submit.commandBufferCount; ++j) + if(_submits == nullptr) + return false; + for (uint32_t i = 0u; i < _count; ++i) { - auto& cmdbuf = submit.commandBuffers[j]; - if(cmdbuf == nullptr) - return false; - submit.commandBuffers[j]->setState(IGPUCommandBuffer::ES_PENDING); + auto& submit = _submits[i]; + for (uint32_t j = 0u; j < submit.commandBufferCount; ++j) + { + auto& cmdbuf = submit.commandBuffers[j]; + if(cmdbuf == nullptr) + return false; + submit.commandBuffers[j]->setState(IGPUCommandBuffer::ES_PENDING); + } } + return true; } - return true; - } - inline bool markCommandBuffersAsDone(uint32_t _count, const SSubmitInfo* _submits) - { - if(_submits == nullptr) - return false; - for (uint32_t i = 0u; i < _count; ++i) + inline bool markCommandBuffersAsDone(uint32_t _count, const SSubmitInfo* _submits) { - auto& submit = _submits[i]; - for (uint32_t j = 0u; j < submit.commandBufferCount; ++j) + if(_submits == nullptr) + return false; + for (uint32_t i = 0u; i < _count; ++i) { - auto& cmdbuf = submit.commandBuffers[j]; - if(cmdbuf == nullptr) - return false; - - if (cmdbuf->isResettable()) - cmdbuf->setState(IGPUCommandBuffer::ES_EXECUTABLE); - else - cmdbuf->setState(IGPUCommandBuffer::ES_INVALID); + auto& submit = _submits[i]; + for (uint32_t j = 0u; j < submit.commandBufferCount; ++j) + { + auto& cmdbuf = submit.commandBuffers[j]; + if(cmdbuf == nullptr) + return false; + + if (cmdbuf->isResettable()) + cmdbuf->setState(IGPUCommandBuffer::ES_EXECUTABLE); + else + cmdbuf->setState(IGPUCommandBuffer::ES_INVALID); + } } + return true; } - return true; - } - protected: + const uint32_t m_familyIndex; const E_CREATE_FLAGS m_flags; const float m_priority; diff --git a/include/nbl/video/IGPUSampler.h b/include/nbl/video/IGPUSampler.h index 59bc93e5ca..91f5ff6930 100644 --- a/include/nbl/video/IGPUSampler.h +++ b/include/nbl/video/IGPUSampler.h @@ -19,6 +19,10 @@ class IGPUSampler : public asset::ISampler, public IBackendObject public: IGPUSampler(core::smart_refctd_ptr&& dev, const SParams& params) : ISampler(params), IBackendObject(std::move(dev)) {} + + // OpenGL: const GLuint* handle + // Vulkan: const VkSampler + virtual const void* getNativeHandle() const = 0; }; } diff --git a/include/nbl/video/IGPUSemaphore.h b/include/nbl/video/IGPUSemaphore.h index c33b6291f0..9366a353a4 100644 --- a/include/nbl/video/IGPUSemaphore.h +++ b/include/nbl/video/IGPUSemaphore.h @@ -16,6 +16,10 @@ class IGPUSemaphore : public core::IReferenceCounted, public IBackendObject IGPUSemaphore(core::smart_refctd_ptr&& dev) : IBackendObject(std::move(dev)) {} virtual ~IGPUSemaphore() = default; + + // OpenGL: core::smart_refctd_ptr* + // Vulkan: const VkSemaphore* + virtual void* getNativeHandle() = 0; }; } diff --git a/include/nbl/video/ILogicalDevice.h b/include/nbl/video/ILogicalDevice.h index d71b161826..be3634bc3d 100644 --- a/include/nbl/video/ILogicalDevice.h +++ b/include/nbl/video/ILogicalDevice.h @@ -644,6 +644,10 @@ class ILogicalDevice : public core::IReferenceCounted return IGPUAccelerationStructure::BuildSizes{}; } + // OpenGL: EGL + // Vulkan: const VkDevice* + virtual const void* getNativeHandle() const = 0; + protected: ILogicalDevice(core::smart_refctd_ptr&& api, IPhysicalDevice* physicalDevice, const SCreationParams& params) : m_api(api), m_physicalDevice(physicalDevice) diff --git a/include/nbl/video/ISwapchain.h b/include/nbl/video/ISwapchain.h index 2f45940914..a1938fbadf 100644 --- a/include/nbl/video/ISwapchain.h +++ b/include/nbl/video/ISwapchain.h @@ -84,6 +84,10 @@ class ISwapchain : public core::IReferenceCounted, public IBackendObject return m_params; } + // OpenGL: EGL + // Vulkan: const VkSwapchainKHR* + virtual const void* getNativeHandle() const = 0; + protected: virtual ~ISwapchain() = default; diff --git a/src/nbl/video/COpenGLBuffer.h b/src/nbl/video/COpenGLBuffer.h index 6125e1712d..86a1a55a71 100644 --- a/src/nbl/video/COpenGLBuffer.h +++ b/src/nbl/video/COpenGLBuffer.h @@ -45,6 +45,7 @@ class COpenGLBuffer final : public IGPUBuffer, public IDriverMemoryAllocation void setObjectDebugName(const char* label) const override; //! + inline const void* getNativeHandle() const override {return &BufferName;} inline const GLuint& getOpenGLName() const {return BufferName;} //! diff --git a/src/nbl/video/COpenGLBufferView.h b/src/nbl/video/COpenGLBufferView.h index 9360138174..a223c6bb17 100644 --- a/src/nbl/video/COpenGLBufferView.h +++ b/src/nbl/video/COpenGLBufferView.h @@ -34,8 +34,10 @@ class COpenGLBufferView : public IGPUBufferView m_textureSize = m_size / asset::getTexelOrBlockBytesize(m_format); } - GLuint getOpenGLName() const { return m_textureName; } - GLenum getInternalFormat() const { return m_GLformat; } + inline GLuint getOpenGLName() const {return m_textureName;} + inline const void* getNativeHandle() const override {return &m_textureName;} + + inline GLenum getInternalFormat() const { return m_GLformat; } protected: virtual ~COpenGLBufferView(); diff --git a/src/nbl/video/COpenGLCommandBuffer.h b/src/nbl/video/COpenGLCommandBuffer.h index 8b909f3b0e..cc1f2c784c 100644 --- a/src/nbl/video/COpenGLCommandBuffer.h +++ b/src/nbl/video/COpenGLCommandBuffer.h @@ -1320,6 +1320,8 @@ class COpenGLCommandBuffer final : public IGPUCommandBuffer return true; } + + inline const void* getNativeHandle() const override {return nullptr;} }; } diff --git a/src/nbl/video/COpenGLCommandPool.h b/src/nbl/video/COpenGLCommandPool.h index fc0ab13637..ebc8435212 100644 --- a/src/nbl/video/COpenGLCommandPool.h +++ b/src/nbl/video/COpenGLCommandPool.h @@ -39,6 +39,8 @@ class COpenGLCommandPool final : public IGPUCommandPool std::unique_lock lk(mutex); mempool.free_n(const_cast(ptr), n); } + + inline const void* getNativeHandle() const override {return nullptr;} private: std::mutex mutex; diff --git a/src/nbl/video/COpenGLFence.h b/src/nbl/video/COpenGLFence.h index f59dd824a8..03b89bad0c 100644 --- a/src/nbl/video/COpenGLFence.h +++ b/src/nbl/video/COpenGLFence.h @@ -26,21 +26,20 @@ class COpenGLFence final : public IGPUFence, public IOpenGLSyncPrimitiveBase // un-signaled ctor explicit COpenGLFence(core::smart_refctd_ptr&& _dev) : IGPUFence(std::move(_dev), static_cast(0)) { - } - E_STATUS wait(IOpenGL_FunctionTable* _gl, uint64_t timeout) - { - if (!m_sync || !m_sync->isInitialized()) - return ES_NOT_READY; - COpenGLSync::E_STATUS status = m_sync->waitCPU(_gl, timeout); - if (status == COpenGLSync::ES_FAIL) - return ES_ERROR; - else if (status == COpenGLSync::ES_TIMEOUT_EXPIRED) - return ES_TIMEOUT; - else - return ES_SUCCESS; - } + E_STATUS wait(IOpenGL_FunctionTable* _gl, uint64_t timeout) + { + if (!m_sync || !m_sync->isInitialized()) + return ES_NOT_READY; + COpenGLSync::E_STATUS status = m_sync->waitCPU(_gl, timeout); + if (status == COpenGLSync::ES_FAIL) + return ES_ERROR; + else if (status == COpenGLSync::ES_TIMEOUT_EXPIRED) + return ES_TIMEOUT; + else + return ES_SUCCESS; + } E_STATUS getStatus(IOpenGL_FunctionTable* _gl) { @@ -62,6 +61,8 @@ class COpenGLFence final : public IGPUFence, public IOpenGLSyncPrimitiveBase { IOpenGLSyncPrimitiveBase::reset(); } + + void* getNativeHandle() override {return &m_sync;} }; } diff --git a/src/nbl/video/COpenGLImage.h b/src/nbl/video/COpenGLImage.h index 415092f8c7..2b146d8100 100644 --- a/src/nbl/video/COpenGLImage.h +++ b/src/nbl/video/COpenGLImage.h @@ -76,7 +76,8 @@ class COpenGLImage final : public IGPUImage, public IDriverMemoryAllocation inline GLenum getOpenGLTarget() const { return target; } //! returns the opengl texture handle - inline GLuint getOpenGLName() const { return name; } + inline const void* getNativeHandle() const override {return &name;} + inline GLuint getOpenGLName() const {return name;} inline size_t getAllocationSize() const override { return this->getImageDataSizeInBytes(); } diff --git a/src/nbl/video/COpenGLImageView.h b/src/nbl/video/COpenGLImageView.h index 7c2d33dc13..f3a5fb5117 100644 --- a/src/nbl/video/COpenGLImageView.h +++ b/src/nbl/video/COpenGLImageView.h @@ -76,7 +76,8 @@ class COpenGLImageView final : public IGPUImageView gl->extGlTextureParameteriv(name, target, pname[i], swizzle+i); } } - + + inline const void* getNativeHandle() const override {return &name;} inline GLuint getOpenGLName() const { return name; } inline GLenum getInternalFormat() const { return internalFormat; } }; diff --git a/src/nbl/video/COpenGLSampler.h b/src/nbl/video/COpenGLSampler.h index 8a4ec5c1e7..525afa693c 100644 --- a/src/nbl/video/COpenGLSampler.h +++ b/src/nbl/video/COpenGLSampler.h @@ -117,7 +117,8 @@ class COpenGLSampler : public IGPUSampler void setObjectDebugName(const char* label) const override; - GLuint getOpenGLName() const { return m_GLname; } + const void* getNativeHandle() const override {return &m_GLname;} + GLuint getOpenGLName() const {return m_GLname;} private: GLuint m_GLname; diff --git a/src/nbl/video/COpenGLSemaphore.h b/src/nbl/video/COpenGLSemaphore.h index 0e2afdf8b5..5fe60b8ac7 100644 --- a/src/nbl/video/COpenGLSemaphore.h +++ b/src/nbl/video/COpenGLSemaphore.h @@ -15,25 +15,26 @@ class COpenGLSemaphore : public IGPUSemaphore, public IOpenGLSyncPrimitiveBase protected: ~COpenGLSemaphore() { - /*#ifdef _NBL_DEBUG + /*#ifdef _NBL_DEBUG if (m_sync) { auto status = m_sync->waitCPU(0); assert(status == COpenGLSync::ES_CONDITION_SATISFIED || status == COpenGLSync::ES_ALREADY_SIGNALED); } - #endif*/ + #endif*/ } public: explicit COpenGLSemaphore(core::smart_refctd_ptr&& dev) : IGPUSemaphore(std::move(dev)) { - } void wait(IOpenGL_FunctionTable* _gl) { m_sync->waitGPU(_gl); } + + void* getNativeHandle() override {return &m_sync;} }; } diff --git a/src/nbl/video/COpenGLSync.h b/src/nbl/video/COpenGLSync.h index 9d30537d17..613e26186a 100644 --- a/src/nbl/video/COpenGLSync.h +++ b/src/nbl/video/COpenGLSync.h @@ -4,8 +4,7 @@ #include "nbl/video/IOpenGL_FunctionTable.h" #include "nbl/core/IReferenceCounted.h" -namespace nbl { -namespace video +namespace nbl::video { class IOpenGL_LogicalDevice; @@ -113,10 +112,8 @@ class COpenGLSync final : public core::IReferenceCounted } } - inline GLsync getOpenGLName() const - { - return sync; - } + //inline const volatile GLsync* getNativeHandle() const {return &sync;} + inline GLsync getOpenGLName() const {return sync;} bool isInitialized() const { @@ -132,6 +129,6 @@ class COpenGLSync final : public core::IReferenceCounted volatile GLsync sync; }; -}} +} #endif \ No newline at end of file diff --git a/src/nbl/video/COpenGL_Connection.cpp b/src/nbl/video/COpenGL_Connection.cpp index c744b66f3d..a988d2da7c 100644 --- a/src/nbl/video/COpenGL_Connection.cpp +++ b/src/nbl/video/COpenGL_Connection.cpp @@ -2,7 +2,6 @@ #include "nbl/video/COpenGLPhysicalDevice.h" #include "nbl/video/COpenGLESPhysicalDevice.h" -#include "nbl/video/CEGL.h" namespace nbl::video @@ -51,6 +50,12 @@ IDebugCallback* COpenGL_Connection::getDebugCallback() const return static_cast*>(*getPhysicalDevices().begin())->getDebugCallback(); } +template +const egl::CEGL& COpenGL_Connection::getInternalObject() const +{ + return static_cast(m_physicalDevices.front().get())->getInternalObject(); +} + template class COpenGL_Connection; template class COpenGL_Connection; diff --git a/src/nbl/video/COpenGL_Queue.h b/src/nbl/video/COpenGL_Queue.h index 1117bdae75..e8d2ccd2a8 100755 --- a/src/nbl/video/COpenGL_Queue.h +++ b/src/nbl/video/COpenGL_Queue.h @@ -168,9 +168,9 @@ class COpenGL_Queue final : public IGPUQueue //_NBL_DEBUG_BREAK_IF(mcres!=EGL_TRUE); } -#ifndef _NBL_PLATFORM_ANDROID_ + #ifndef _NBL_PLATFORM_ANDROID_ egl->call.peglGetPlatformDependentHandles(&nativeHandles, egl->display, pbuffer, thisCtx); -#endif + #endif new (state_ptr) ThreadInternalStateType(egl,features,core::smart_refctd_ptr(m_dbgCb->getLogger())); auto& gl = state_ptr->gl; auto& ctxlocal = state_ptr->ctxlocal; @@ -556,6 +556,8 @@ class COpenGL_Queue final : public IGPUQueue return true; } + const void* getNativeHandle() const override {return nullptr;} + protected: ~COpenGL_Queue() { diff --git a/src/nbl/video/COpenGL_Swapchain.h b/src/nbl/video/COpenGL_Swapchain.h index ebdb899ef9..d54163255c 100644 --- a/src/nbl/video/COpenGL_Swapchain.h +++ b/src/nbl/video/COpenGL_Swapchain.h @@ -110,6 +110,8 @@ class COpenGL_Swapchain final : public ISwapchain m_threadHandler.waitForInitComplete(); } + virtual const void* getNativeHandle() const override {return nullptr;} + protected: // images will be created in COpenGLLogicalDevice::createSwapchain COpenGL_Swapchain( diff --git a/src/nbl/video/CVulkanBuffer.h b/src/nbl/video/CVulkanBuffer.h index 52782e26b9..9b44c6f947 100644 --- a/src/nbl/video/CVulkanBuffer.h +++ b/src/nbl/video/CVulkanBuffer.h @@ -23,7 +23,8 @@ class CVulkanBuffer : public IGPUBuffer ~CVulkanBuffer(); - inline VkBuffer getInternalObject() const { return m_vkBuffer; }; + inline const void* getNativeHandle() const override {return &m_vkBuffer;} + inline VkBuffer getInternalObject() const {return m_vkBuffer;} IDriverMemoryAllocation* getBoundMemory() override { diff --git a/src/nbl/video/CVulkanBufferView.h b/src/nbl/video/CVulkanBufferView.h index e0185a5137..e0145bd1e1 100644 --- a/src/nbl/video/CVulkanBufferView.h +++ b/src/nbl/video/CVulkanBufferView.h @@ -18,8 +18,9 @@ class CVulkanBufferView : public IGPUBufferView VkBufferView handle) : IGPUBufferView(std::move(dev), buffer, format, offset, size), m_vkBufferView(handle) {} - - inline VkBufferView getInternalObject() const { return m_vkBufferView; } + + inline const void* getNativeHandle() const override {return &m_vkBufferView;} + inline VkBufferView getInternalObject() const {return m_vkBufferView;} ~CVulkanBufferView(); diff --git a/src/nbl/video/CVulkanCommandBuffer.h b/src/nbl/video/CVulkanCommandBuffer.h index 7546bc8b40..7a5d5528ef 100644 --- a/src/nbl/video/CVulkanCommandBuffer.h +++ b/src/nbl/video/CVulkanCommandBuffer.h @@ -39,7 +39,7 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer freeSpaceInCmdPool(); } - bool begin(uint32_t recordingFlags, const SInheritanceInfo* inheritanceInfo = nullptr) override + bool begin(uint32_t recordingFlags, const SInheritanceInfo* inheritanceInfo=nullptr) override { VkCommandBufferBeginInfo beginInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO }; beginInfo.pNext = nullptr; // pNext must be NULL or a pointer to a valid instance of VkDeviceGroupCommandBufferBeginInfo @@ -1335,8 +1335,9 @@ class CVulkanCommandBuffer : public IGPUCommandBuffer bool copyAccelerationStructureToMemory(const IGPUAccelerationStructure::DeviceCopyToMemoryInfo& copyInfo) override; bool copyAccelerationStructureFromMemory(const IGPUAccelerationStructure::DeviceCopyFromMemoryInfo& copyInfo) override; - - VkCommandBuffer getInternalObject() const { return m_cmdbuf; } + + inline const void* getNativeHandle() const override {return &m_cmdbuf;} + VkCommandBuffer getInternalObject() const {return m_cmdbuf;} private: void freeSpaceInCmdPool() diff --git a/src/nbl/video/CVulkanCommandPool.h b/src/nbl/video/CVulkanCommandPool.h index 2970b01c17..39f5552298 100644 --- a/src/nbl/video/CVulkanCommandPool.h +++ b/src/nbl/video/CVulkanCommandPool.h @@ -70,8 +70,9 @@ class CVulkanCommandPool final : public IGPUCommandPool head = next; } } - - VkCommandPool getInternalObject() const { return m_vkCommandPool; } + + inline const void* getNativeHandle() const override {return &m_vkCommandPool;} + VkCommandPool getInternalObject() const {return m_vkCommandPool;} ~CVulkanCommandPool(); diff --git a/src/nbl/video/CVulkanFence.h b/src/nbl/video/CVulkanFence.h index 2b1337a081..36a8337b6e 100644 --- a/src/nbl/video/CVulkanFence.h +++ b/src/nbl/video/CVulkanFence.h @@ -19,7 +19,8 @@ class CVulkanFence final : public IGPUFence ~CVulkanFence(); - VkFence getInternalObject() const { return m_fence; } + inline void* getNativeHandle() override {return &m_fence;} + VkFence getInternalObject() const {return m_fence;} void setObjectDebugName(const char* label) const override; diff --git a/src/nbl/video/CVulkanImage.h b/src/nbl/video/CVulkanImage.h index b1ad049970..a399b279b2 100644 --- a/src/nbl/video/CVulkanImage.h +++ b/src/nbl/video/CVulkanImage.h @@ -23,7 +23,8 @@ class CVulkanImage : public IGPUImage const IDriverMemoryBacked::SDriverMemoryRequirements& reqs = IDriverMemoryBacked::SDriverMemoryRequirements()) : IGPUImage(std::move(_vkdev), std::move(_params), reqs), m_vkImage(_vkimg) {} - + + inline const void* getNativeHandle() const override {return &m_vkImage;} inline VkImage getInternalObject() const { return m_vkImage; } inline IDriverMemoryAllocation* getBoundMemory() override { return m_memory.get(); } diff --git a/src/nbl/video/CVulkanImageView.h b/src/nbl/video/CVulkanImageView.h index 8d9206a344..32eaceb471 100644 --- a/src/nbl/video/CVulkanImageView.h +++ b/src/nbl/video/CVulkanImageView.h @@ -20,7 +20,8 @@ class CVulkanImageView final : public IGPUImageView {} ~CVulkanImageView(); - + + inline const void* getNativeHandle() const override {return &m_vkImageView;} inline VkImageView getInternalObject() const { return m_vkImageView; } void setObjectDebugName(const char* label) const override; diff --git a/src/nbl/video/CVulkanLogicalDevice.h b/src/nbl/video/CVulkanLogicalDevice.h index 6fe413fdfe..2b795d5f26 100644 --- a/src/nbl/video/CVulkanLogicalDevice.h +++ b/src/nbl/video/CVulkanLogicalDevice.h @@ -1,5 +1,5 @@ -#ifndef __NBL_C_VULKAN_LOGICAL_DEVICE_H_INCLUDED__ -#define __NBL_C_VULKAN_LOGICAL_DEVICE_H_INCLUDED__ +#ifndef _NBL_C_VULKAN_LOGICAL_DEVICE_H_INCLUDED_ +#define _NBL_C_VULKAN_LOGICAL_DEVICE_H_INCLUDED_ #include @@ -946,7 +946,8 @@ class CVulkanLogicalDevice final : public ILogicalDevice IGPUAccelerationStructure::BuildSizes getAccelerationStructureBuildSizes(const IGPUAccelerationStructure::DeviceBuildGeometryInfo& pBuildInfo, const uint32_t* pMaxPrimitiveCounts) override; - inline memory_pool_mt_t & getMemoryPoolForDeferredOperations() { + inline memory_pool_mt_t & getMemoryPoolForDeferredOperations() + { return m_deferred_op_mempool; } @@ -1071,7 +1072,8 @@ class CVulkanLogicalDevice final : public ILogicalDevice const CVulkanDeviceFunctionTable* getFunctionTable() const { return &m_devf; } - VkDevice getInternalObject() const { return m_vkdev; } + inline const void* getNativeHandle() const {return &m_vkdev;} + VkDevice getInternalObject() const {return m_vkdev;} protected: bool createCommandBuffers_impl(IGPUCommandPool* cmdPool, IGPUCommandBuffer::E_LEVEL level, diff --git a/src/nbl/video/CVulkanQueue.h b/src/nbl/video/CVulkanQueue.h index 9d32c95a0b..ce897e321c 100644 --- a/src/nbl/video/CVulkanQueue.h +++ b/src/nbl/video/CVulkanQueue.h @@ -21,7 +21,8 @@ class CVulkanQueue final : public IGPUQueue ISwapchain::E_PRESENT_RESULT present(const SPresentInfo& info) override; - inline VkQueue getInternalObject() const { return m_vkQueue; } + inline const void* getNativeHandle() const override {return &m_vkQueue;} + inline VkQueue getInternalObject() const {return m_vkQueue;} bool startCapture() override; bool endCapture() override; diff --git a/src/nbl/video/CVulkanSampler.h b/src/nbl/video/CVulkanSampler.h index bac4b0d923..cd6a1af767 100644 --- a/src/nbl/video/CVulkanSampler.h +++ b/src/nbl/video/CVulkanSampler.h @@ -18,7 +18,8 @@ class CVulkanSampler : public IGPUSampler ~CVulkanSampler(); - inline VkSampler getInternalObject() const { return m_sampler; } + const void* getNativeHandle() const override {return &m_sampler;} + inline VkSampler getInternalObject() const {return m_sampler;} void setObjectDebugName(const char* label) const override; diff --git a/src/nbl/video/CVulkanSemaphore.h b/src/nbl/video/CVulkanSemaphore.h index 4de3a52764..de491c73c5 100644 --- a/src/nbl/video/CVulkanSemaphore.h +++ b/src/nbl/video/CVulkanSemaphore.h @@ -18,8 +18,9 @@ class CVulkanSemaphore final : public IGPUSemaphore {} ~CVulkanSemaphore(); - - VkSemaphore getInternalObject() const { return m_semaphore; } + + inline void* getNativeHandle() override {return &m_semaphore;} + VkSemaphore getInternalObject() const {return m_semaphore;} void setObjectDebugName(const char* label) const override; diff --git a/src/nbl/video/CVulkanSwapchain.h b/src/nbl/video/CVulkanSwapchain.h index 84fc218823..305f76ae58 100644 --- a/src/nbl/video/CVulkanSwapchain.h +++ b/src/nbl/video/CVulkanSwapchain.h @@ -1,5 +1,5 @@ -#ifndef __NBL_C_VULKAN_SWAPCHAIN_H_INCLUDED__ -#define __NBL_C_VULKAN_SWAPCHAIN_H_INCLUDED__ +#ifndef _NBL_C_VULKAN_SWAPCHAIN_H_INCLUDED_ +#define _NBL_C_VULKAN_SWAPCHAIN_H_INCLUDED_ #include "nbl/video/ISwapchain.h" @@ -22,7 +22,8 @@ class CVulkanSwapchain final : public ISwapchain ~CVulkanSwapchain(); - inline VkSwapchainKHR getInternalObject() const { return m_vkSwapchainKHR; } + inline const void* getNativeHandle() const {return &m_vkSwapchainKHR;} + inline VkSwapchainKHR getInternalObject() const {return m_vkSwapchainKHR;} E_ACQUIRE_IMAGE_RESULT acquireNextImage(uint64_t timeout, IGPUSemaphore* semaphore, IGPUFence* fence, uint32_t* out_imgIx) override; diff --git a/src/nbl/video/IOpenGLSyncPrimitiveBase.h b/src/nbl/video/IOpenGLSyncPrimitiveBase.h index badb46d0d4..28f1021afe 100644 --- a/src/nbl/video/IOpenGLSyncPrimitiveBase.h +++ b/src/nbl/video/IOpenGLSyncPrimitiveBase.h @@ -6,8 +6,7 @@ #include #include -namespace nbl { -namespace video +namespace nbl::video { class IOpenGLSyncPrimitiveBase @@ -37,7 +36,6 @@ class IOpenGLSyncPrimitiveBase core::smart_refctd_ptr m_sync; }; -} } #endif diff --git a/src/nbl/video/IOpenGL_FunctionTable.h b/src/nbl/video/IOpenGL_FunctionTable.h index 70e639ff0c..58b1a4b73c 100644 --- a/src/nbl/video/IOpenGL_FunctionTable.h +++ b/src/nbl/video/IOpenGL_FunctionTable.h @@ -37,7 +37,7 @@ extern thread_local char g_NBL_GL_CALL_msg_buffer[4096]; } } -// TODO os::Printer is deprecated but we dont have anything new for logging +// TODO: get rid of sprintf and g_NBL_GL_CALL_msg_buffer # define _NBL_GL_CALL(logger, callname_)\ { \ callname_ ;\ @@ -55,13 +55,13 @@ extern thread_local char g_NBL_GL_CALL_msg_buffer[4096]; # define _NBL_GL_CALL(...) __VA_ARGS__ #endif -namespace nbl { - namespace video { +namespace nbl::video +{ - // This class contains pointers to functions common in GL 4.6 and GLES 3.2 - // And implements (at least a common part) extGl* methods which can be implemented with those pointers - class IOpenGL_FunctionTable - { + // This class contains pointers to functions common in GL 4.6 and GLES 3.2 + // And implements (at least a common part) extGl* methods which can be implemented with those pointers + class IOpenGL_FunctionTable + { static std::atomic_uint32_t s_guidGenerator; public: @@ -610,7 +610,7 @@ namespace nbl { { --s_guidGenerator; } - }; // end of class IOpenGL_FunctionTable + }; // end of class IOpenGL_FunctionTable void IOpenGL_FunctionTable::extGlCreateTextures(GLenum target, GLsizei n, GLuint* textures) { @@ -1255,7 +1255,6 @@ namespace nbl { } - } //namespace video - } //namespace nbl +} //namespace nbl #endif diff --git a/src/nbl/video/IOpenGL_LogicalDevice.h b/src/nbl/video/IOpenGL_LogicalDevice.h index d1708900e7..9f9d4fd7d5 100755 --- a/src/nbl/video/IOpenGL_LogicalDevice.h +++ b/src/nbl/video/IOpenGL_LogicalDevice.h @@ -39,8 +39,8 @@ namespace nbl::video namespace impl { - class IOpenGL_LogicalDeviceBase - { +class IOpenGL_LogicalDeviceBase +{ public: static inline constexpr uint32_t MaxQueueCount = 8u; static inline constexpr uint32_t MaxGlNamesForSingleObject = MaxQueueCount + 1u; @@ -264,7 +264,7 @@ namespace impl static inline constexpr E_REQUEST_TYPE type = ERT_WAIT_IDLE; using retval_t = void; }; - }; +}; /* template <> @@ -971,6 +971,8 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log virtual void destroySync(GLsync sync) = 0; virtual void setObjectDebugName(GLenum id, GLuint object, GLsizei len, const GLchar* label) = 0; virtual void destroyQueryPool(COpenGLQueryPool* qp) = 0; + + const void* getNativeHandle() const override {return nullptr;} }; } diff --git a/src/nbl/video/IOpenGL_PhysicalDeviceBase.h b/src/nbl/video/IOpenGL_PhysicalDeviceBase.h index 25a7fe9f90..40415b974e 100755 --- a/src/nbl/video/IOpenGL_PhysicalDeviceBase.h +++ b/src/nbl/video/IOpenGL_PhysicalDeviceBase.h @@ -21,12 +21,25 @@ namespace nbl::video class IOpenGLPhysicalDeviceBase : public IPhysicalDevice { -public: - static inline constexpr uint32_t MaxQueues = 8u; + public: + static inline constexpr uint32_t MaxQueues = 8u; + + IOpenGLPhysicalDeviceBase( + core::smart_refctd_ptr&& s, + core::smart_refctd_ptr&& glslc, + egl::CEGL&& _egl + ) : IPhysicalDevice(std::move(s),std::move(glslc)), m_egl(std::move(_egl)) + {} + + const egl::CEGL& getInternalObject() const {return m_egl;} + + protected: + virtual ~IOpenGLPhysicalDeviceBase() + { + m_egl.deinitialize(); + } - IOpenGLPhysicalDeviceBase(core::smart_refctd_ptr&& s, core::smart_refctd_ptr&& glslc) - : IPhysicalDevice(std::move(s), std::move(glslc)) - {} + egl::CEGL m_egl; }; template @@ -171,7 +184,7 @@ class IOpenGL_PhysicalDeviceBase : public IOpenGLPhysicalDeviceBase public: IOpenGL_PhysicalDeviceBase(IAPIConnection* api, renderdoc_api_t* rdoc, core::smart_refctd_ptr&& s, egl::CEGL&& _egl, COpenGLDebugCallback&& _dbgCb, EGLConfig _config, EGLContext ctx, EGLint _major, EGLint _minor) - : IOpenGLPhysicalDeviceBase(std::move(s),core::make_smart_refctd_ptr(s.get())), m_api(api), m_rdoc_api(rdoc), m_egl(std::move(_egl)), m_dbgCb(std::move(_dbgCb)), m_config(_config), m_gl_major(_major), m_gl_minor(_minor) + : IOpenGLPhysicalDeviceBase(std::move(s),core::make_smart_refctd_ptr(s.get()),std::move(_egl)), m_api(api), m_rdoc_api(rdoc), m_dbgCb(std::move(_dbgCb)), m_config(_config), m_gl_major(_major), m_gl_minor(_minor) { // OpenGL backend emulates presence of just one queue family with all capabilities (graphics, compute, transfer, ... what about sparse binding?) SQueueFamilyProperties qprops; @@ -529,7 +542,7 @@ class IOpenGL_PhysicalDeviceBase : public IOpenGLPhysicalDeviceBase } finalizeGLSLDefinePool(std::move(pool)); - // we dont need this any more + // we dont need this context any more m_egl.call.peglMakeCurrent(m_egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); m_egl.call.peglDestroyContext(m_egl.display, ctx); m_egl.call.peglDestroySurface(m_egl.display, pbuf); @@ -543,14 +556,8 @@ class IOpenGL_PhysicalDeviceBase : public IOpenGLPhysicalDeviceBase bool isSwapchainSupported() const override { return true; } protected: - virtual ~IOpenGL_PhysicalDeviceBase() - { - m_egl.deinitialize(); - } - IAPIConnection* m_api; // dumb pointer to avoid circ ref renderdoc_api_t* m_rdoc_api; - egl::CEGL m_egl; COpenGLDebugCallback m_dbgCb; EGLConfig m_config; From 84161c818d3e9d7b49fc9860e3ac57f597eb55a2 Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 18 Feb 2022 00:18:20 +0100 Subject: [PATCH 20/91] OpenGL Logical Device, Queue and Swapchain `getNativeHandle` (expose EGL context and surface) --- include/nbl/video/CEGL.h | 11 +++++++ include/nbl/video/COpenGL_Connection.h | 6 ---- include/nbl/video/IGPUImageView.h | 2 +- include/nbl/video/IGPUQueue.h | 2 +- include/nbl/video/ILogicalDevice.h | 2 +- include/nbl/video/ISwapchain.h | 2 +- src/nbl/video/COpenGL_LogicalDevice.h | 14 ++++----- src/nbl/video/COpenGL_Queue.h | 26 ++++++++-------- src/nbl/video/COpenGL_Swapchain.h | 24 +++++++-------- src/nbl/video/IOpenGL_LogicalDevice.h | 42 +++++++------------------- 10 files changed, 57 insertions(+), 74 deletions(-) diff --git a/include/nbl/video/CEGL.h b/include/nbl/video/CEGL.h index b2ae7366d1..46693d7ade 100644 --- a/include/nbl/video/CEGL.h +++ b/include/nbl/video/CEGL.h @@ -7,9 +7,20 @@ namespace nbl::video::egl { +// any EGL handles are not native EGL handles, they come from our EGL over WGL/GLX/EGL implementation! class CEGL { public: + // + struct Context + { + EGLContext ctx = EGL_NO_CONTEXT; + EGLSurface surface = EGL_NO_SURFACE; + + // to load function pointers, make EGL context current and use `egl->call.peglGetProcAddress("glFuncname")` + }; + + // CEGL(const char* eglOptionalPath) : call(eglOptionalPath) {} bool initialize() diff --git a/include/nbl/video/COpenGL_Connection.h b/include/nbl/video/COpenGL_Connection.h index c1e678e7c5..81836a5d2f 100644 --- a/include/nbl/video/COpenGL_Connection.h +++ b/include/nbl/video/COpenGL_Connection.h @@ -14,12 +14,6 @@ template class COpenGL_Connection final : public IAPIConnection { public: - // - struct SStuff - { - // to load function pointers, make EGL context current and use `egl->call.peglGetProcAddress("glFuncname")` - }; - // static core::smart_refctd_ptr> create(core::smart_refctd_ptr&& sys, uint32_t appVer, const char* appName, COpenGLDebugCallback&& dbgCb); diff --git a/include/nbl/video/IGPUImageView.h b/include/nbl/video/IGPUImageView.h index 04083a66f1..b088b24f1e 100644 --- a/include/nbl/video/IGPUImageView.h +++ b/include/nbl/video/IGPUImageView.h @@ -20,7 +20,7 @@ class IGPUImageView : public asset::IImageView, public IBackendObject const SCreationParams& getCreationParameters() const { return params; } // OpenGL: const GLuint* handle of GL_TEXTURE_VIEW target - // Vulkan: const VKImageView* + // Vulkan: const VkImageView* virtual const void* getNativeHandle() const = 0; protected: diff --git a/include/nbl/video/IGPUQueue.h b/include/nbl/video/IGPUQueue.h index 710c44ba4e..d4c0f83d9a 100644 --- a/include/nbl/video/IGPUQueue.h +++ b/include/nbl/video/IGPUQueue.h @@ -63,7 +63,7 @@ class IGPUQueue : public core::Interface, public core::Unmovable inline constexpr static float DEFAULT_QUEUE_PRIORITY = 1.f; - // OpenGL: GLsync_ + // OpenGL: const egl::CEGL::Context* // Vulkan: const VkQueue* virtual const void* getNativeHandle() const = 0; diff --git a/include/nbl/video/ILogicalDevice.h b/include/nbl/video/ILogicalDevice.h index be3634bc3d..d250a73a8d 100644 --- a/include/nbl/video/ILogicalDevice.h +++ b/include/nbl/video/ILogicalDevice.h @@ -644,7 +644,7 @@ class ILogicalDevice : public core::IReferenceCounted return IGPUAccelerationStructure::BuildSizes{}; } - // OpenGL: EGL + // OpenGL: const egl::CEGL::Context* // Vulkan: const VkDevice* virtual const void* getNativeHandle() const = 0; diff --git a/include/nbl/video/ISwapchain.h b/include/nbl/video/ISwapchain.h index a1938fbadf..7816132068 100644 --- a/include/nbl/video/ISwapchain.h +++ b/include/nbl/video/ISwapchain.h @@ -84,7 +84,7 @@ class ISwapchain : public core::IReferenceCounted, public IBackendObject return m_params; } - // OpenGL: EGL + // OpenGL: const egl::CEGL::Context* // Vulkan: const VkSwapchainKHR* virtual const void* getNativeHandle() const = 0; diff --git a/src/nbl/video/COpenGL_LogicalDevice.h b/src/nbl/video/COpenGL_LogicalDevice.h index 0ad25bc648..30196e4233 100644 --- a/src/nbl/video/COpenGL_LogicalDevice.h +++ b/src/nbl/video/COpenGL_LogicalDevice.h @@ -68,8 +68,6 @@ class COpenGL_LogicalDevice : public IOpenGL_LogicalDevice m_config(config), m_gl_ver(major, minor) { - EGLContext master_ctx = m_threadHandler.getContext(); - uint32_t totalQCount = getTotalQueueCount(params); assert(totalQCount <= MaxQueueCount); @@ -84,7 +82,7 @@ class COpenGL_LogicalDevice : public IOpenGL_LogicalDevice { const float priority = qci.priorities[j]; - SGLContext glctx = createWindowlessGLContext(FunctionTableType::EGL_API_TYPE, _egl, major, minor, config, master_ctx); + auto glctx = createWindowlessGLContext(FunctionTableType::EGL_API_TYPE, _egl, major, minor, config, m_threadHandler.glctx.ctx); const uint32_t ix = offset + j; const uint32_t ctxid = 1u + ix; // +1 because one ctx is here, in logical device (consider if it means we have to have another spec shader GL name for it, probably not) -- [TODO] @@ -92,8 +90,8 @@ class COpenGL_LogicalDevice : public IOpenGL_LogicalDevice (*m_queues)[ix] = new CThreadSafeGPUQueueAdapter ( this, - (IGPUQueue*)new QueueType(this, rdoc, _egl, m_glfeatures, ctxid, glctx.ctx, - glctx.pbuffer, famIx, flags, priority, + (IGPUQueue*)new QueueType(this, rdoc, _egl, m_glfeatures, ctxid, + glctx, famIx, flags, priority, static_cast(physicalDevice->getDebugCallback())) ); } @@ -195,13 +193,12 @@ class COpenGL_LogicalDevice : public IOpenGL_LogicalDevice return nullptr; } - EGLContext master_ctx = m_threadHandler.getContext(); EGLConfig fbconfig = m_config; auto glver = m_gl_ver; // master context must not be current while creating a context with whom it will be sharing unbindMasterContext(); - EGLContext ctx = createGLContext(FunctionTableType::EGL_API_TYPE, m_egl, glver.first, glver.second, fbconfig, master_ctx); + EGLContext ctx = createGLContext(FunctionTableType::EGL_API_TYPE, m_egl, glver.first, glver.second, fbconfig, m_threadHandler.glctx.ctx); auto sc = SwapchainType::create(std::move(params),core::smart_refctd_ptr(this),m_egl,std::move(images),m_glfeatures,ctx,fbconfig,static_cast(m_physicalDevice->getDebugCallback())); if (!sc) return nullptr; @@ -665,6 +662,9 @@ class COpenGL_LogicalDevice : public IOpenGL_LogicalDevice openglQueue->destroyQueries(queriesToDestroy); } } + + const void* getNativeHandle() const override { return &m_threadHandler.glctx; } + protected: void bindMasterContext() { diff --git a/src/nbl/video/COpenGL_Queue.h b/src/nbl/video/COpenGL_Queue.h index e8d2ccd2a8..9c0751fed2 100755 --- a/src/nbl/video/COpenGL_Queue.h +++ b/src/nbl/video/COpenGL_Queue.h @@ -128,11 +128,11 @@ class COpenGL_Queue final : public IGPUQueue using base_t = system::IAsyncQueueDispatcher; friend base_t; - CThreadHandler(const egl::CEGL* _egl, renderdoc_api_t* rdoc, IOpenGL_LogicalDevice* dev, const FeaturesType* _features, EGLContext _ctx, EGLSurface _pbuf, uint32_t _ctxid, COpenGLDebugCallback* _dbgCb) : + CThreadHandler(const egl::CEGL* _egl, renderdoc_api_t* rdoc, IOpenGL_LogicalDevice* dev, const FeaturesType* _features, const egl::CEGL::Context& _glctx, uint32_t _ctxid, COpenGLDebugCallback* _dbgCb) : m_rdoc_api(rdoc), egl(_egl), m_device(dev), m_masterContextCallsWaited(0), - thisCtx(_ctx), pbuffer(_pbuf), + glctx(_glctx), features(_features), m_ctxid(_ctxid), m_dbgCb(_dbgCb) @@ -158,7 +158,7 @@ class COpenGL_Queue final : public IGPUQueue EGLBoolean mcres = EGL_FALSE; while (mcres!=EGL_TRUE) { - mcres = egl->call.peglMakeCurrent(egl->display,pbuffer,pbuffer,thisCtx); + mcres = egl->call.peglMakeCurrent(egl->display, glctx.surface, glctx.surface, glctx.ctx); /* * I think Queue context creation has a timing bug * Debug build breaks, context can never be made current @@ -168,9 +168,9 @@ class COpenGL_Queue final : public IGPUQueue //_NBL_DEBUG_BREAK_IF(mcres!=EGL_TRUE); } - #ifndef _NBL_PLATFORM_ANDROID_ - egl->call.peglGetPlatformDependentHandles(&nativeHandles, egl->display, pbuffer, thisCtx); - #endif + #ifndef _NBL_PLATFORM_ANDROID_ + egl->call.peglGetPlatformDependentHandles(&nativeHandles, egl->display, glctx.surface, glctx.ctx); + #endif new (state_ptr) ThreadInternalStateType(egl,features,core::smart_refctd_ptr(m_dbgCb->getLogger())); auto& gl = state_ptr->gl; auto& ctxlocal = state_ptr->ctxlocal; @@ -323,18 +323,17 @@ class COpenGL_Queue final : public IGPUQueue state_ptr->~ThreadInternalStateType(); egl->call.peglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); // detach ctx from thread - egl->call.peglDestroyContext(egl->display, thisCtx); - egl->call.peglDestroySurface(egl->display, pbuffer); + egl->call.peglDestroyContext(egl->display, glctx.ctx); + egl->call.peglDestroySurface(egl->display, glctx.surface); } renderdoc_api_t* m_rdoc_api; + egl::CEGL::Context glctx; private: const egl::CEGL* egl; IOpenGL_LogicalDevice* m_device; uint64_t m_masterContextCallsWaited; - EGLContext thisCtx; - EGLSurface pbuffer; const FeaturesType* features; uint32_t m_ctxid; COpenGLDebugCallback* m_dbgCb; @@ -350,14 +349,13 @@ class COpenGL_Queue final : public IGPUQueue const egl::CEGL* _egl, const FeaturesType* _features, uint32_t _ctxid, - EGLContext _ctx, - EGLSurface _surface, + const egl::CEGL::Context& _glctx, uint32_t _famIx, E_CREATE_FLAGS _flags, float _priority, COpenGLDebugCallback* _dbgCb ) : IGPUQueue(gldev,_famIx,_flags,_priority), - threadHandler(_egl,rdoc,gldev,_features,_ctx,_surface,_ctxid,_dbgCb), + threadHandler(_egl,rdoc,gldev,_features,_glctx,_ctxid,_dbgCb), m_mempool(128u,1u,512u,sizeof(void*)), m_ctxid(_ctxid) { @@ -556,7 +554,7 @@ class COpenGL_Queue final : public IGPUQueue return true; } - const void* getNativeHandle() const override {return nullptr;} + const void* getNativeHandle() const override {return &threadHandler.glctx;} protected: ~COpenGL_Queue() diff --git a/src/nbl/video/COpenGL_Swapchain.h b/src/nbl/video/COpenGL_Swapchain.h index d54163255c..e78e4cca8b 100644 --- a/src/nbl/video/COpenGL_Swapchain.h +++ b/src/nbl/video/COpenGL_Swapchain.h @@ -110,7 +110,7 @@ class COpenGL_Swapchain final : public ISwapchain m_threadHandler.waitForInitComplete(); } - virtual const void* getNativeHandle() const override {return nullptr;} + virtual const void* getNativeHandle() const override {return &m_threadHandler.glctx;} protected: // images will be created in COpenGLLogicalDevice::createSwapchain @@ -149,7 +149,7 @@ class COpenGL_Swapchain final : public ISwapchain ) : m_device(dev), m_masterContextCallsWaited(0), egl(_egl), m_presentMode(presentMode), - thisCtx(_ctx), surface(EGL_NO_SURFACE), + glctx{_ctx,EGL_NO_SURFACE}, features(_features), images(_images), m_dbgCb(_dbgCb) @@ -165,8 +165,8 @@ class COpenGL_Swapchain final : public ISwapchain EGL_NONE }; - surface = _egl->call.peglCreateWindowSurface(_egl->display, _config, (EGLNativeWindowType)_window, surface_attributes); - assert(surface != EGL_NO_SURFACE); + glctx.surface = _egl->call.peglCreateWindowSurface(_egl->display, _config, (EGLNativeWindowType)_window, surface_attributes); + assert(glctx.surface != EGL_NO_SURFACE); base_t::start(); } @@ -195,13 +195,14 @@ class COpenGL_Swapchain final : public ISwapchain return syncs[imgix]; } + egl::CEGL::Context glctx; protected: void init(SThreadHandlerInternalState* state_ptr) { egl->call.peglBindAPI(FunctionTableType::EGL_API_TYPE); - EGLBoolean mcres = egl->call.peglMakeCurrent(egl->display, surface, surface, thisCtx); + EGLBoolean mcres = egl->call.peglMakeCurrent(egl->display, glctx.surface, glctx.surface, glctx.ctx); assert(mcres == EGL_TRUE); m_ctxCreatedCvar.notify_one(); @@ -285,7 +286,7 @@ class COpenGL_Swapchain final : public ISwapchain syncs[imgix]->init(m_device, &gl, false); // swap buffers performs an implicit flush before swapping // https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglSwapBuffers.xhtml - egl->call.peglSwapBuffers(egl->display, surface); + egl->call.peglSwapBuffers(egl->display, glctx.surface); } void exit(SThreadHandlerInternalState* gl) @@ -297,8 +298,8 @@ class COpenGL_Swapchain final : public ISwapchain gl->~SThreadHandlerInternalState(); egl->call.peglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - egl->call.peglDestroyContext(egl->display, thisCtx); - egl->call.peglDestroySurface(egl->display, surface); + egl->call.peglDestroyContext(egl->display, glctx.ctx); + egl->call.peglDestroySurface(egl->display, glctx.surface); } bool wakeupPredicate() const { return needToBlit; } @@ -309,16 +310,15 @@ class COpenGL_Swapchain final : public ISwapchain uint64_t m_masterContextCallsWaited; const egl::CEGL* egl; - EGLContext thisCtx; - EGLSurface surface; ISurface::E_PRESENT_MODE m_presentMode; const COpenGLFeatureMap* features; core::SRange> images; GLuint fbos[MaxImages]{}; core::smart_refctd_ptr syncs[MaxImages]; COpenGLDebugCallback* m_dbgCb; - std::array m_texViews; - struct SRequest { + std::array m_texViews; + struct SRequest + { SRequest() { sems.reserve(50); } uint32_t imgIx = 0u; diff --git a/src/nbl/video/IOpenGL_LogicalDevice.h b/src/nbl/video/IOpenGL_LogicalDevice.h index 9f9d4fd7d5..afcce26b3f 100755 --- a/src/nbl/video/IOpenGL_LogicalDevice.h +++ b/src/nbl/video/IOpenGL_LogicalDevice.h @@ -297,12 +297,6 @@ class IOpenGL_LogicalDeviceBase class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_LogicalDeviceBase { protected: - struct SGLContext - { - EGLContext ctx = EGL_NO_CONTEXT; - EGLSurface pbuffer = EGL_NO_SURFACE; - }; - static EGLContext createGLContext(EGLenum apiType, const egl::CEGL* egl, EGLint major, EGLint minor, EGLConfig config, EGLContext master = EGL_NO_CONTEXT) { egl->call.peglBindAPI(apiType); @@ -328,9 +322,9 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log return ctx; } - static SGLContext createWindowlessGLContext(EGLenum apiType, const egl::CEGL* egl, EGLint major, EGLint minor, EGLConfig config, EGLContext master = EGL_NO_CONTEXT) + static auto createWindowlessGLContext(EGLenum apiType, const egl::CEGL* egl, EGLint major, EGLint minor, EGLConfig config, EGLContext master = EGL_NO_CONTEXT) { - SGLContext retval; + egl::CEGL::Context retval; retval.ctx = createGLContext(apiType, egl, major, minor, config, master); @@ -341,8 +335,8 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log EGL_NONE }; - retval.pbuffer = egl->call.peglCreatePbufferSurface(egl->display, config, pbuffer_attributes); - assert(retval.pbuffer != EGL_NO_SURFACE); + retval.surface = egl->call.peglCreatePbufferSurface(egl->display, config, pbuffer_attributes); + assert(retval.surface != EGL_NO_SURFACE); return retval; } @@ -418,29 +412,19 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log const egl::CEGL* _egl, const FeaturesType* _features, uint32_t _qcount, - const SGLContext& glctx, + const egl::CEGL::Context& _glctx, const COpenGLDebugCallback* _dbgCb) : m_queueCount(_qcount), masterContextSync(_masterContextSync), masterContextCallsReturned(_masterContextCallsReturned), egl(_egl), - thisCtx(glctx.ctx), pbuffer(glctx.pbuffer), + glctx(_glctx), features(_features), device(dev), m_dbgCb(_dbgCb) { } - EGLContext getContext() const - { - return thisCtx; - } - - EGLSurface getSurface() const - { - return pbuffer; - } - uint32_t getQueueCount() const { return m_queueCount; @@ -462,7 +446,7 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log { egl->call.peglBindAPI(FunctionTableType::EGL_API_TYPE); - EGLBoolean mcres = egl->call.peglMakeCurrent(egl->display, pbuffer, pbuffer, thisCtx); + EGLBoolean mcres = egl->call.peglMakeCurrent(egl->display, glctx.surface, glctx.surface, glctx.ctx); assert(mcres == EGL_TRUE); auto logger = m_dbgCb->getLogger(); @@ -674,7 +658,7 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log auto& p = std::get(req.params_variant); EGLBoolean mcres = EGL_FALSE; if (p.bind) - mcres = egl->call.peglMakeCurrent(egl->display, pbuffer, pbuffer, thisCtx); + mcres = egl->call.peglMakeCurrent(egl->display, glctx.surface, glctx.surface, glctx.ctx); else mcres = egl->call.peglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); assert(mcres); @@ -704,10 +688,11 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log gl->~FunctionTableType(); egl->call.peglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); // detach ctx from thread - egl->call.peglDestroyContext(egl->display, thisCtx); - egl->call.peglDestroySurface(egl->display, pbuffer); + egl->call.peglDestroyContext(egl->display, glctx.ctx); + egl->call.peglDestroySurface(egl->display, glctx.surface); } + egl::CEGL::Context glctx; private: core::smart_refctd_ptr createRenderpassIndependentPipeline(IOpenGL_FunctionTable& gl, const IGPURenderpassIndependentPipeline::SCreationParams& params, IGPUPipelineCache* _pipelineCache) { @@ -930,9 +915,6 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log std::atomic* const masterContextCallsReturned; const egl::CEGL* egl; - - EGLContext thisCtx; - EGLSurface pbuffer; const FeaturesType* features; IOpenGL_LogicalDevice* device; @@ -971,8 +953,6 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log virtual void destroySync(GLsync sync) = 0; virtual void setObjectDebugName(GLenum id, GLuint object, GLsizei len, const GLchar* label) = 0; virtual void destroyQueryPool(COpenGLQueryPool* qp) = 0; - - const void* getNativeHandle() const override {return nullptr;} }; } From 11fd16d2e5295cd0f1ea4b2ef3dc553946a086f0 Mon Sep 17 00:00:00 2001 From: Mateusz Kielan Date: Wed, 23 Feb 2022 16:54:47 +0100 Subject: [PATCH 21/91] Create Readme.md for examples Draft Example Table --- examples_tests/Readme.md | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples_tests/Readme.md diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md new file mode 100644 index 0000000000..9d88df7458 --- /dev/null +++ b/examples_tests/Readme.md @@ -0,0 +1,58 @@ +# Examples and Tests + +The Nabla Examples are documentation-by-example and building blocks for our future Continuous Integration GPU Integration Tests. + +## Where can I find the makefiles or IDE projects/solutions? + +Given an example in folder `XY.ExampleName`, CMake will generate either a target or a separate makefile/project/solution called `examplename` (no number, always lowercase). + +Whenever CMake generates separate makefiles/solutions/projects, they will be generated in the `./examples_tests` under the build directory you supplied to CMake. + +**Samples are meant to be built into the `./bin` directory in the source (its git-ignored) and invoked with that Current Working Directory.** + +**WARNING:** If you're using an IDE different than Visual Studio you need to set the CWD correctly for when you start the example for Debugging! + +**WARNING:** Only generation of IDE projects by standalone CMake is supported, we do not use or rely on IDE integrations of CMake. + +## Maintenance Matrix + +In the future we expect this matrix to be kept up to date, live by our CI. + +Y = Already Works +B = Has a known bug +W = Work-In-Progress, sample logic not complete or temporarily modifed +S = Intended to be Supported (requires some work to port after an API change) +N = No support +| | Win32 OpenGL | Win32 OpenGL ES* | Win32 Vulkan | X11** OpenGL | X11** OpenGL ES | X11** Vulkan | Android OpenGL ES | Android Vulkan | Required NBL_* CMake Options | +|---------------------------------|--------------|------------------|--------------|--------------|-----------------|--------------|-------------------|----------------|------------------------------| +| 01.HelloWorld | Y | Y | Y | S | S | S | Y | S | None | +| 02.ComputeShader | B | B | Y | S | S | S | Y | S | None | +| 03.GPU_Mesh | | | | | | | | | | +| 04.Keyframe | | | | | | | | | | +| 05.NablaTutorialExample | | | | | | | | | | +| 06.MeshLoaders | | | | | | | | | | +| 07.SubpassBaking | | | | | | | | | | +| FREE_SLOT | | | | | | | | | | +| 09.ColorSpaceTest | | | | | | | | | | +| 10.AllocatorTest | | | | | | | | | | +| 11.LoDSystem | | | | | | | | | | +| 12.glTF | | | | | | | | | | +| FREE_SLOT | | | | | | | | | | +| 14.ComputeScan | | | | | | | | | | +| FREE_SLOT | | | | | | | | | | +| 16.OrderIndependentTransparency | | | | | | | | | | +| 17.SimpleBulletIntegration | | | | | | | | | | +| 18.MitsubaLoader | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| | | | | | | | | | | +| 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | None | + +* Only Nvidia provides a working GLES 3.1 driver with OES_texture_view on Windows, so we only test there. From 395e3c815fbbcbd3b2b7886a1b807f05295b2c7d Mon Sep 17 00:00:00 2001 From: Mateusz Kielan Date: Wed, 23 Feb 2022 18:47:02 +0100 Subject: [PATCH 22/91] Complete Example Table Names --- examples_tests/Readme.md | 98 +++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 31 deletions(-) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 9d88df7458..f8d417a97b 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -18,41 +18,77 @@ Whenever CMake generates separate makefiles/solutions/projects, they will be gen In the future we expect this matrix to be kept up to date, live by our CI. +_Examples numbered 00 are provisional and are not part of the example suite._ + Y = Already Works B = Has a known bug W = Work-In-Progress, sample logic not complete or temporarily modifed S = Intended to be Supported (requires some work to port after an API change) N = No support -| | Win32 OpenGL | Win32 OpenGL ES* | Win32 Vulkan | X11** OpenGL | X11** OpenGL ES | X11** Vulkan | Android OpenGL ES | Android Vulkan | Required NBL_* CMake Options | -|---------------------------------|--------------|------------------|--------------|--------------|-----------------|--------------|-------------------|----------------|------------------------------| -| 01.HelloWorld | Y | Y | Y | S | S | S | Y | S | None | -| 02.ComputeShader | B | B | Y | S | S | S | Y | S | None | -| 03.GPU_Mesh | | | | | | | | | | -| 04.Keyframe | | | | | | | | | | -| 05.NablaTutorialExample | | | | | | | | | | -| 06.MeshLoaders | | | | | | | | | | -| 07.SubpassBaking | | | | | | | | | | -| FREE_SLOT | | | | | | | | | | -| 09.ColorSpaceTest | | | | | | | | | | -| 10.AllocatorTest | | | | | | | | | | -| 11.LoDSystem | | | | | | | | | | -| 12.glTF | | | | | | | | | | -| FREE_SLOT | | | | | | | | | | -| 14.ComputeScan | | | | | | | | | | -| FREE_SLOT | | | | | | | | | | -| 16.OrderIndependentTransparency | | | | | | | | | | -| 17.SimpleBulletIntegration | | | | | | | | | | -| 18.MitsubaLoader | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| | | | | | | | | | | -| 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | None | +| | Win32 OpenGL | Win32 OpenGL ES* | Win32 Vulkan | X11** OpenGL | X11** OpenGL ES | X11** Vulkan | Android OpenGL ES | Android Vulkan | Required CMake Options**** | +|---------------------------------|--------------|------------------|--------------|--------------|-----------------|--------------|-------------------|----------------|---------------------------------------------------| +| 01.HelloWorld | Y | Y | Y | S | S | S | Y | S | | +| 02.ComputeShader | B | B | Y | B | B | S | B | S | | +| 03.GPU_Mesh | S | S | S | S | S | S | S | S | | +| 04.Keyframe | S | S | S | S | S | S | S | S | | +| 05.NablaTutorialExample | Y | Y | Y | S | S | S | S | S | | +| 06.MeshLoaders | Y | Y | Y | S | S | S | Y | Y | | +| 07.SubpassBaking | S | S | S | S | S | S | S | S | | +| FREE_SLOT | | | | | | | | | | +| 09.ColorSpaceTest | W | W | W | W | W | W | W | W | | +| 10.AllocatorTest | Y | Y | Y | S | S | S | N | N | | +| 11.LoDSystem | Y | S | B | S | S | S | N | S | | +| 12.glTF | W | W | W | W | W | W | W | W | COMPILE_WITH_GLTF_LOADER | +| FREE_SLOT | | | | | | | | | | +| 14.ComputeScan | B | B | B | S | S | S | N | S | | +| FREE_SLOT | | | | | | | | | | +| 16.OrderIndependentTransparency | B | B | B | S | S | S | S | S | | +| 17.SimpleBulletIntegration | Y | Y | Y | S | S | S | N | N | BUILD_BULLET | +| 18.MitsubaLoader | S | S | S | S | S | S | N | N | BUILD_MITSUBA_LOADER | +| FREE_SLOT | | | | | | | | | | +| 20.Megatexture | S | S | S | S | S | S | N | S | | +| 21.DynamicTextureIndexing | S | S | S | S | S | S | N | S | | +| 22.RaytracedAO | W | W | W | W | W | W | W | W | BUILD_MITSUBA_LOADER | +| 23.Autoexposure | | | | | | | | | | +| FREE_SLOT | | | | | | | | | | +| 25.Blur | | | | | | | | | | +| FREE_SLOT | | | | | | | | | | +| 27.PLYSTLDemo | | | | | | | | | COMPILE_WITH_STL_LOADER & COMPILE_WITH_PLY_LOADER | +| FREE_SLOT | | | | | | | | | | +| 29.SpecializationConstants | S | S | S | S | S | S | N | S | | +| FREE_SLOT | | | | | | | | | | +| FREE_SLOT | | | | | | | | | | +| FREE_SLOT | | | | | | | | | | +| 33.Draw3DLine | S | S | S | S | S | S | N | S | | +| 34.LRUCacheUnitTest | S | S | S | S | S | S | N | S | | +| 35.GeometryCreator | S | S | S | S | S | S | N | S | | +| 36.CUDAInterop | S | S | S | S | S | S | N | S | | +| FREE_SLOT | | | | | | | | | | +| 38.EXRSplit | S | S | S | S | S | S | N | S | | +| 39.DenoiserTonemapper | S | S | S | S | S | S | N | S | | +| 40.GLITest | S | S | S | S | S | S | N | S | | +| 41.VisibilityBuffer | S | S | S | S | S | S | N | S | | +| 42.FragmentShaderPathTracer | S | S | S | S | S | S | N | S | | +| 43.SumAndCDFFilters | S | S | S | S | S | S | N | S | | +| 44.LevelCurveExtraction | S | S | S | S | S | S | N | S | | +| 45.BRDFEvalTest | S | S | S | S | S | S | N | S | | +| 46.SamplingValidation | S | S | S | S | S | S | N | S | | +| 47.DerivMapTest | S | S | S | S | S | S | N | S | | +| 48.ArithmeticUnitTest | S | S | S | S | S | S | N | S | | +| 49.ComputeFFT | S | S | S | S | S | S | N | S | | +| 50.ArithmeticUnitTest | S | S | S | S | S | S | N | S | | +| 51.RadixSort | S | S | S | S | S | S | N | S | | +| 52.SystemTest | S | S | S | S | S | S | N | S | | +| 53.ComputeShaders | S | S | S | S | S | S | N | S | | +| 54.Transformations | S | S | S | S | S | S | N | S | | +| 55.RGB18E7S3 | S | S | S | S | S | S | N | S | | +| 56.RayQuery | S | S | S | S | S | S | N | S | | +| 57.AndroidSample | S | S | S | S | S | S | N | S | | +| 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | None | +| FREE_SLOT | | | | | | | | | | +| 60.ClusteredRendering | W | W | W | W | W | W | N | N | | * Only Nvidia provides a working GLES 3.1 driver with OES_texture_view on Windows, so we only test there. +** Needs the Xcb implementation of the `ui::` namespace to be complete. +*** Only x86_64 architecture supported for Android builds, also NBL_BUILD_ANDROID is required. +**** NBL_BUILD_EXAMPLES is needed for any example to build! From a71675254b69bb6929ae83221c822e5f8bfea649 Mon Sep 17 00:00:00 2001 From: Mateusz Kielan Date: Wed, 23 Feb 2022 19:16:51 +0100 Subject: [PATCH 23/91] Update Readme.md : Complete the GLES exclusions --- examples_tests/Readme.md | 65 +++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index f8d417a97b..012ec04098 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -21,10 +21,15 @@ In the future we expect this matrix to be kept up to date, live by our CI. _Examples numbered 00 are provisional and are not part of the example suite._ Y = Already Works + B = Has a known bug + W = Work-In-Progress, sample logic not complete or temporarily modifed + S = Intended to be Supported (requires some work to port after an API change) + N = No support + | | Win32 OpenGL | Win32 OpenGL ES* | Win32 Vulkan | X11** OpenGL | X11** OpenGL ES | X11** Vulkan | Android OpenGL ES | Android Vulkan | Required CMake Options**** | |---------------------------------|--------------|------------------|--------------|--------------|-----------------|--------------|-------------------|----------------|---------------------------------------------------| | 01.HelloWorld | Y | Y | Y | S | S | S | Y | S | | @@ -37,58 +42,58 @@ N = No support | FREE_SLOT | | | | | | | | | | | 09.ColorSpaceTest | W | W | W | W | W | W | W | W | | | 10.AllocatorTest | Y | Y | Y | S | S | S | N | N | | -| 11.LoDSystem | Y | S | B | S | S | S | N | S | | -| 12.glTF | W | W | W | W | W | W | W | W | COMPILE_WITH_GLTF_LOADER | +| 11.LoDSystem | Y | N | B | S | N | S | N | S | | +| 12.glTF | W | N | W | W | N | W | N | W | COMPILE_WITH_GLTF_LOADER | | FREE_SLOT | | | | | | | | | | -| 14.ComputeScan | B | B | B | S | S | S | N | S | | +| 14.ComputeScan | B | N | B | S | N | S | N | S | | | FREE_SLOT | | | | | | | | | | | 16.OrderIndependentTransparency | B | B | B | S | S | S | S | S | | -| 17.SimpleBulletIntegration | Y | Y | Y | S | S | S | N | N | BUILD_BULLET | -| 18.MitsubaLoader | S | S | S | S | S | S | N | N | BUILD_MITSUBA_LOADER | +| 17.SimpleBulletIntegration | Y | N | Y | S | N | S | N | N | BUILD_BULLET | +| 18.MitsubaLoader | S | N | S | S | N | S | N | N | BUILD_MITSUBA_LOADER | | FREE_SLOT | | | | | | | | | | | 20.Megatexture | S | S | S | S | S | S | N | S | | -| 21.DynamicTextureIndexing | S | S | S | S | S | S | N | S | | -| 22.RaytracedAO | W | W | W | W | W | W | W | W | BUILD_MITSUBA_LOADER | -| 23.Autoexposure | | | | | | | | | | +| 21.DynamicTextureIndexing | S | N | S | S | N | S | N | S | | +| 22.RaytracedAO | N | N | W | N | N | W | N | N | BUILD_MITSUBA_LOADER | +| 23.Autoexposure | Y | Y | Y | S | S | S | N | S | | | FREE_SLOT | | | | | | | | | | -| 25.Blur | | | | | | | | | | +| 25.Blur | S | S | S | S | S | S | N | S | | | FREE_SLOT | | | | | | | | | | -| 27.PLYSTLDemo | | | | | | | | | COMPILE_WITH_STL_LOADER & COMPILE_WITH_PLY_LOADER | +| 27.PLYSTLDemo | Y | Y | Y | S | S | S | N | N | COMPILE_WITH_STL_LOADER & COMPILE_WITH_PLY_LOADER | | FREE_SLOT | | | | | | | | | | | 29.SpecializationConstants | S | S | S | S | S | S | N | S | | | FREE_SLOT | | | | | | | | | | | FREE_SLOT | | | | | | | | | | | FREE_SLOT | | | | | | | | | | | 33.Draw3DLine | S | S | S | S | S | S | N | S | | -| 34.LRUCacheUnitTest | S | S | S | S | S | S | N | S | | +| 34.LRUCacheUnitTest | Y | Y | Y | Y | Y | Y | N | N | | | 35.GeometryCreator | S | S | S | S | S | S | N | S | | -| 36.CUDAInterop | S | S | S | S | S | S | N | S | | +| 36.CUDAInterop | N | N | W | N | N | W | N | N | | | FREE_SLOT | | | | | | | | | | -| 38.EXRSplit | S | S | S | S | S | S | N | S | | -| 39.DenoiserTonemapper | S | S | S | S | S | S | N | S | | +| 38.EXRSplit | S | S | S | S | S | S | N | N | | +| 39.DenoiserTonemapper | N | N | S | N | N | S | N | N | | | 40.GLITest | S | S | S | S | S | S | N | S | | -| 41.VisibilityBuffer | S | S | S | S | S | S | N | S | | -| 42.FragmentShaderPathTracer | S | S | S | S | S | S | N | S | | -| 43.SumAndCDFFilters | S | S | S | S | S | S | N | S | | -| 44.LevelCurveExtraction | S | S | S | S | S | S | N | S | | +| 41.VisibilityBuffer | S | S | S | S | S | S | N | N | | +| 42.FragmentShaderPathTracer | S | S | S | S | S | S | S | S | | +| 43.SumAndCDFFilters | S | N | S | S | N | S | N | S | | +| 44.LevelCurveExtraction | S | N | S | S | N | S | N | S | | | 45.BRDFEvalTest | S | S | S | S | S | S | N | S | | | 46.SamplingValidation | S | S | S | S | S | S | N | S | | -| 47.DerivMapTest | S | S | S | S | S | S | N | S | | -| 48.ArithmeticUnitTest | S | S | S | S | S | S | N | S | | -| 49.ComputeFFT | S | S | S | S | S | S | N | S | | -| 50.ArithmeticUnitTest | S | S | S | S | S | S | N | S | | -| 51.RadixSort | S | S | S | S | S | S | N | S | | +| 47.DerivMapTest | S | N | S | S | N | S | N | S | | +| 48.ArithmeticUnitTest | S | N | S | S | N | S | N | S | | +| 49.ComputeFFT | S | N | S | S | N | S | N | S | | +| 50.NewAPITest | S | S | S | S | S | S | S | S | | +| 51.RadixSort | S | N | S | S | N | S | N | S | | | 52.SystemTest | S | S | S | S | S | S | N | S | | | 53.ComputeShaders | S | S | S | S | S | S | N | S | | | 54.Transformations | S | S | S | S | S | S | N | S | | | 55.RGB18E7S3 | S | S | S | S | S | S | N | S | | -| 56.RayQuery | S | S | S | S | S | S | N | S | | -| 57.AndroidSample | S | S | S | S | S | S | N | S | | +| 56.RayQuery | N | N | S | N | N | S | N | S | | +| 57.AndroidSample | N | N | N | N | N | N | S | S | | | 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | None | | FREE_SLOT | | | | | | | | | | -| 60.ClusteredRendering | W | W | W | W | W | W | N | N | | +| 60.ClusteredRendering | W | N | W | W | N | W | N | N | | -* Only Nvidia provides a working GLES 3.1 driver with OES_texture_view on Windows, so we only test there. -** Needs the Xcb implementation of the `ui::` namespace to be complete. -*** Only x86_64 architecture supported for Android builds, also NBL_BUILD_ANDROID is required. -**** NBL_BUILD_EXAMPLES is needed for any example to build! +`*` Only Nvidia provides a working GLES 3.1 driver with OES_texture_view on Windows, so we only test there. +`**` Needs the Xcb implementation of the `ui::` namespace to be complete. +`***` Only x86_64 architecture supported for Android builds, also NBL_BUILD_ANDROID is required. +`****` NBL_BUILD_EXAMPLES is needed for any example to build! From 21f4c096dc033be880d7200381e4877deea19847 Mon Sep 17 00:00:00 2001 From: Mateusz Kielan Date: Wed, 23 Feb 2022 22:45:54 +0100 Subject: [PATCH 24/91] Finish the example support matrix --- examples_tests/Readme.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 012ec04098..ef752aab2d 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -56,7 +56,7 @@ N = No support | 22.RaytracedAO | N | N | W | N | N | W | N | N | BUILD_MITSUBA_LOADER | | 23.Autoexposure | Y | Y | Y | S | S | S | N | S | | | FREE_SLOT | | | | | | | | | | -| 25.Blur | S | S | S | S | S | S | N | S | | +| 25.Blur | S | N | S | S | N | S | N | S | | | FREE_SLOT | | | | | | | | | | | 27.PLYSTLDemo | Y | Y | Y | S | S | S | N | N | COMPILE_WITH_STL_LOADER & COMPILE_WITH_PLY_LOADER | | FREE_SLOT | | | | | | | | | | @@ -64,32 +64,32 @@ N = No support | FREE_SLOT | | | | | | | | | | | FREE_SLOT | | | | | | | | | | | FREE_SLOT | | | | | | | | | | -| 33.Draw3DLine | S | S | S | S | S | S | N | S | | +| 33.Draw3DLine | Y | Y | Y | S | S | S | S | S | | | 34.LRUCacheUnitTest | Y | Y | Y | Y | Y | Y | N | N | | -| 35.GeometryCreator | S | S | S | S | S | S | N | S | | -| 36.CUDAInterop | N | N | W | N | N | W | N | N | | +| 35.GeometryCreator | Y | Y | Y | S | S | S | N | S | | +| 36.CUDAInterop | N | N | W | N | N | W | N | N | COMPILE_WITH_CUDA | | FREE_SLOT | | | | | | | | | | | 38.EXRSplit | S | S | S | S | S | S | N | N | | -| 39.DenoiserTonemapper | N | N | S | N | N | S | N | N | | -| 40.GLITest | S | S | S | S | S | S | N | S | | +| 39.DenoiserTonemapper | N | N | W | N | N | W | N | N | COMPILE_WITH_CUDA & COMPILE_WITH_OPTIX | +| 40.GLITest | S | S | S | S | S | S | N | S | COMPILE_WITH_GLI_LOADER | | 41.VisibilityBuffer | S | S | S | S | S | S | N | N | | -| 42.FragmentShaderPathTracer | S | S | S | S | S | S | S | S | | -| 43.SumAndCDFFilters | S | N | S | S | N | S | N | S | | -| 44.LevelCurveExtraction | S | N | S | S | N | S | N | S | | +| 42.FragmentShaderPathTracer | B | B | Y | S | S | S | S | S | | +| 43.SumAndCDFFilters | S | N | S | S | N | S | N | N | | +| 44.LevelCurveExtraction | S | N | S | S | N | S | N | N | | | 45.BRDFEvalTest | S | S | S | S | S | S | N | S | | | 46.SamplingValidation | S | S | S | S | S | S | N | S | | -| 47.DerivMapTest | S | N | S | S | N | S | N | S | | -| 48.ArithmeticUnitTest | S | N | S | S | N | S | N | S | | -| 49.ComputeFFT | S | N | S | S | N | S | N | S | | +| 47.DerivMapTest | S | N | S | S | N | S | N | N | | +| 48.ArithmeticUnitTest | Y | N | Y | S | N | S | N | S | | +| 49.ComputeFFT | S | N | S | S | N | S | N | N | | | 50.NewAPITest | S | S | S | S | S | S | S | S | | -| 51.RadixSort | S | N | S | S | N | S | N | S | | -| 52.SystemTest | S | S | S | S | S | S | N | S | | -| 53.ComputeShaders | S | S | S | S | S | S | N | S | | -| 54.Transformations | S | S | S | S | S | S | N | S | | -| 55.RGB18E7S3 | S | S | S | S | S | S | N | S | | +| 51.RadixSort | W | N | W | W | N | W | N | W | | +| 52.SystemTest | S | S | S | S | S | S | S | S | | +| 53.ComputeShaders | S | N | S | S | N | S | N | S | | +| 54.Transformations | S | S | S | S | S | S | S | S | | +| 55.RGB18E7S3 | S | S | S | S | S | S | N | N | | | 56.RayQuery | N | N | S | N | N | S | N | S | | | 57.AndroidSample | N | N | N | N | N | N | S | S | | -| 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | None | +| 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | | | FREE_SLOT | | | | | | | | | | | 60.ClusteredRendering | W | N | W | W | N | W | N | N | | From 369bd49cc1fbf91d7fc51c6150d41923628deca1 Mon Sep 17 00:00:00 2001 From: Mateusz Kielan Date: Wed, 23 Feb 2022 22:46:27 +0100 Subject: [PATCH 25/91] Update Readme.md : Formatting --- examples_tests/Readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index ef752aab2d..d90f6fd482 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -94,6 +94,9 @@ N = No support | 60.ClusteredRendering | W | N | W | W | N | W | N | N | | `*` Only Nvidia provides a working GLES 3.1 driver with OES_texture_view on Windows, so we only test there. + `**` Needs the Xcb implementation of the `ui::` namespace to be complete. + `***` Only x86_64 architecture supported for Android builds, also NBL_BUILD_ANDROID is required. + `****` NBL_BUILD_EXAMPLES is needed for any example to build! From c8a9be807a1357397b2e00090960b041fa6cc586 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 24 Feb 2022 16:38:03 +0100 Subject: [PATCH 26/91] remove stb submodule --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 2e719ead35..1484a481cb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -39,9 +39,6 @@ [submodule "3rdparty/bullet3"] path = 3rdparty/bullet3 url = https://github.com/bulletphysics/bullet3.git -[submodule "ext/CEGUI/stb"] - path = ext/CEGUI/stb - url = https://github.com/nothings/stb.git [submodule "3rdparty/portable-file-dialogs"] path = 3rdparty/portable-file-dialogs url = https://github.com/samhocevar/portable-file-dialogs.git From 68277eb1a50539691adb5bcddb5f981a7ce8c035 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 24 Feb 2022 17:41:27 +0100 Subject: [PATCH 27/91] remove an example --- .../CMakeLists.txt | 7 -- .../32.MultiThreadedRefCounting/main.cpp | 72 ------------------- 2 files changed, 79 deletions(-) delete mode 100644 examples_tests/32.MultiThreadedRefCounting/CMakeLists.txt delete mode 100644 examples_tests/32.MultiThreadedRefCounting/main.cpp diff --git a/examples_tests/32.MultiThreadedRefCounting/CMakeLists.txt b/examples_tests/32.MultiThreadedRefCounting/CMakeLists.txt deleted file mode 100644 index 71c002ad52..0000000000 --- a/examples_tests/32.MultiThreadedRefCounting/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ - -include(common RESULT_VARIABLE RES) -if(NOT RES) - message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory") -endif() - -nbl_create_executable_project("" "" "" "") \ No newline at end of file diff --git a/examples_tests/32.MultiThreadedRefCounting/main.cpp b/examples_tests/32.MultiThreadedRefCounting/main.cpp deleted file mode 100644 index 20e605eb0d..0000000000 --- a/examples_tests/32.MultiThreadedRefCounting/main.cpp +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#include -#include -#include -#include - -uint32_t getRandom(uint32_t min, uint32_t max) -{ - static thread_local std::mt19937 generator; - return std::uniform_int_distribution{min,max}(generator); -} -#define RANDOM_MIN (1u<<18) -#define RANDOM_MAX (1u<<19) - -class RefCounted : public nbl::core::IReferenceCounted {}; - -#define TEST_COUNT_AFTER -int main() -{ - auto r = new RefCounted(); - omp_set_num_threads(256); -#pragma omp parallel -{ - #pragma omp for - for (int i = 0; i<256; ++i) - { - r->grab(); - -#ifndef TEST_COUNT_AFTER - if (omp_get_thread_num() == 0) - { - r->drop(); - } -#endif // TEST_COUNT_AFTER - } - - #pragma omp for - for (int i = 0; i < 256; ++i) - { - const size_t cnt = getRandom(RANDOM_MIN, RANDOM_MAX); - size_t ctr[2]{ 0u, 0u }; - while (ctr[0] < cnt || ctr[1] < cnt) - { - switch (getRandom(0u, 1u)) - { - case 0: - if (ctr[0] < cnt) - { - r->grab(); - ctr[0]++; - } - break; - case 1: - if (ctr[1] < ctr[0]) - { - r->drop(); - ctr[1]++; - } - break; - } - } - r->drop(); - } -}//omp parallel -#ifdef TEST_COUNT_AFTER - assert(r->getReferenceCount() == 1); - assert(r->drop()); -#endif -} From 901effb4cc02d5d703d39a3918e17dd641a9a1e4 Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 24 Feb 2022 17:41:59 +0100 Subject: [PATCH 28/91] Make COpenGLSync public, allowing for Interoperation with SDKs also using the OpenGL API --- include/nbl/video/COpenGLSync.h | 73 ++++++++++++++++ src/nbl/video/COpenGLFence.h | 3 +- src/nbl/video/COpenGLSync.cpp | 80 +++++++++++++++++- src/nbl/video/COpenGLSync.h | 134 ------------------------------ src/nbl/video/COpenGL_Queue.h | 2 +- src/nbl/video/COpenGL_Swapchain.h | 4 +- 6 files changed, 156 insertions(+), 140 deletions(-) create mode 100644 include/nbl/video/COpenGLSync.h delete mode 100644 src/nbl/video/COpenGLSync.h diff --git a/include/nbl/video/COpenGLSync.h b/include/nbl/video/COpenGLSync.h new file mode 100644 index 0000000000..f2d5952c00 --- /dev/null +++ b/include/nbl/video/COpenGLSync.h @@ -0,0 +1,73 @@ +#ifndef _NBL_C_OPENGL_SYNC_H_INCLUDED_ +#define _NBL_C_OPENGL_SYNC_H_INCLUDED_ + +#include "nbl/core/IReferenceCounted.h" + +namespace nbl::video +{ + +class IOpenGL_LogicalDevice; +class IOpenGL_FunctionTable; + +class COpenGLSync final : public core::IReferenceCounted +{ + protected: + virtual ~COpenGLSync(); + + public: + enum E_STATUS : uint32_t + { + //! Indicates that an error occurred. Additionally, an OpenGL error will be generated. + ES_FAIL = 0, + //! If it returns GL_TIMEOUT_EXPIRED, then the sync object did not signal within the given timeout period (includes before us calling the func). + ES_TIMEOUT_EXPIRED, + //! Indicates that sync​ was signaled before the timeout expired. + ES_CONDITION_SATISFIED, + //! GPU already completed work before we even asked == THIS IS WHAT WE WANT + ES_ALREADY_SIGNALED + }; + + // External GLsync Import constructor. If you leave the `_dev` parameter null, then you're in charge of deleting the `_sync` by yourself. + inline COpenGLSync(GLsync _sync, core::smart_refctd_ptr&& _dev=nullptr) + : device(std::move(_dev)), lockedTable(nullptr), haveNotWaitedOnQueueMask(~0ull), cachedRetval(ES_TIMEOUT_EXPIRED), sync(_sync) {} + + // + inline GLsync getOpenGLName() const {return sync;} + + // Whether Nabla flushed after placing a fence or not, counting on an implicit flush from waiting on the same context. + // You can still wait on the fence with a different context, but it the context it was placed on needs a flush first. + inline bool initializedWithImplicitFlush() const {return lockedTable;} + + // whether `init` has been called and there is a valid `sync` to wait for + bool isInitialized() const + { + // (!sync && (cachedRetval == ES_ALREADY_SIGNALED)) means initialized as signaled + return static_cast(sync) || cachedRetval == ES_ALREADY_SIGNALED; + } + + + // for internal Nabla usage + void init(core::smart_refctd_ptr&& _dev, IOpenGL_FunctionTable* _gl, bool _lockToQueue = false); + uint64_t prewait() const; + E_STATUS waitCPU(IOpenGL_FunctionTable* _gl, uint64_t timeout); + void waitGPU(IOpenGL_FunctionTable* _gl); + + // Empty (waiting to be made pending a signal) not yet initialized sync constructor + inline COpenGLSync() : COpenGLSync(nullptr,nullptr) {} + // Already signalled constructor (for IGPUFence) + struct signalled_t {}; + constexpr static inline signalled_t signalled = {}; + inline COpenGLSync(core::smart_refctd_ptr&& _dev, IOpenGL_FunctionTable* _gl, signalled_t signalled); + + private: + core::smart_refctd_ptr device; + IOpenGL_FunctionTable* lockedTable; + std::atomic_uint64_t haveNotWaitedOnQueueMask; + E_STATUS cachedRetval; + // maybe atomic instead of volatile would work better? + volatile GLsync sync; +}; + +} + +#endif \ No newline at end of file diff --git a/src/nbl/video/COpenGLFence.h b/src/nbl/video/COpenGLFence.h index 03b89bad0c..905bcc62c2 100644 --- a/src/nbl/video/COpenGLFence.h +++ b/src/nbl/video/COpenGLFence.h @@ -19,8 +19,7 @@ class COpenGLFence final : public IGPUFence, public IOpenGLSyncPrimitiveBase // signaled ctor COpenGLFence(core::smart_refctd_ptr&& dev, IOpenGL_FunctionTable* gl) : IGPUFence(core::smart_refctd_ptr(dev), ECF_SIGNALED_BIT) { - auto sync = core::make_smart_refctd_ptr(); - sync->initSignaled(dev.get(), gl); + auto sync = core::make_smart_refctd_ptr(std::move(dev),gl,COpenGLSync::signalled); associateGLSync(std::move(sync)); } // un-signaled ctor diff --git a/src/nbl/video/COpenGLSync.cpp b/src/nbl/video/COpenGLSync.cpp index 04be84ce3d..667ee76364 100644 --- a/src/nbl/video/COpenGLSync.cpp +++ b/src/nbl/video/COpenGLSync.cpp @@ -4,11 +4,89 @@ namespace nbl::video { + +COpenGLSync::COpenGLSync(core::smart_refctd_ptr&& _dev, IOpenGL_FunctionTable* _gl, signalled_t signalled) + : device(_dev), lockedTable(nullptr), haveNotWaitedOnQueueMask(~(0x1ull<<_gl->getGUID())), cachedRetval(ES_ALREADY_SIGNALED), sync(nullptr) +{ +} COpenGLSync::~COpenGLSync() { - if (sync) + if (device && sync) device->destroySync(sync); } +void COpenGLSync::init(core::smart_refctd_ptr&& _dev, IOpenGL_FunctionTable* _gl, bool _lockToQueue) +{ + device = _dev; + sync = _gl->glSync.pglFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + if (_lockToQueue) + lockedTable = _gl; + else + _gl->glGeneral.pglFlush(); + haveNotWaitedOnQueueMask ^= (1ull << _gl->getGUID()); +} + +uint64_t COpenGLSync::prewait() const +{ + if (sync) + return 0ull; + + using clock_t = std::chrono::high_resolution_clock; + auto start = clock_t::now(); + while (!sync) + { + std::this_thread::yield(); + } + + return std::chrono::duration_cast(clock_t::now() - start).count(); +} + +COpenGLSync::E_STATUS COpenGLSync::waitCPU(IOpenGL_FunctionTable* _gl, uint64_t timeout) +{ + assert(!lockedTable || lockedTable==_gl); + if (cachedRetval != ES_TIMEOUT_EXPIRED) + return cachedRetval; + + const uint64_t spintime = prewait(); + if (spintime > timeout) + return (cachedRetval = ES_TIMEOUT_EXPIRED); + timeout -= spintime; + + GLenum status = _gl->glSync.pglClientWaitSync(sync, lockedTable?GL_SYNC_FLUSH_COMMANDS_BIT:0, timeout); // GL_SYNC_FLUSH_COMMANDS_BIT to flags? + switch (status) + { + case GL_ALREADY_SIGNALED: + return (cachedRetval = ES_ALREADY_SIGNALED); + break; + case GL_TIMEOUT_EXPIRED: + return (cachedRetval = ES_TIMEOUT_EXPIRED); + break; + case GL_CONDITION_SATISFIED:; + return (cachedRetval = ES_CONDITION_SATISFIED); + break; + default: + break; + } + return (cachedRetval = ES_FAIL); +} + +void COpenGLSync::waitGPU(IOpenGL_FunctionTable* _gl) +{ + if (!lockedTable) // OpenGL device does not need to wait on itself within the same context + { + const uint64_t queueMask = 1ull << _gl->getGUID(); + if (haveNotWaitedOnQueueMask.load() & queueMask) + { + prewait(); + _gl->glSync.pglWaitSync(sync, 0, GL_TIMEOUT_IGNORED); + haveNotWaitedOnQueueMask ^= queueMask; + } + } + else + { + assert(lockedTable==_gl); + } +} + } \ No newline at end of file diff --git a/src/nbl/video/COpenGLSync.h b/src/nbl/video/COpenGLSync.h deleted file mode 100644 index 613e26186a..0000000000 --- a/src/nbl/video/COpenGLSync.h +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef __NBL_C_OPENGL_SYNC_H_INCLUDED__ -#define __NBL_C_OPENGL_SYNC_H_INCLUDED__ - -#include "nbl/video/IOpenGL_FunctionTable.h" -#include "nbl/core/IReferenceCounted.h" - -namespace nbl::video -{ - -class IOpenGL_LogicalDevice; - -class COpenGLSync final : public core::IReferenceCounted -{ - protected: - virtual ~COpenGLSync(); - - public: - enum E_STATUS : uint32_t - { - //! Indicates that an error occurred. Additionally, an OpenGL error will be generated. - ES_FAIL = 0, - //! If it returns GL_TIMEOUT_EXPIRED, then the sync object did not signal within the given timeout period (includes before us calling the func). - ES_TIMEOUT_EXPIRED, - //! Indicates that sync​ was signaled before the timeout expired. - ES_CONDITION_SATISFIED, - //! GPU already completed work before we even asked == THIS IS WHAT WE WANT - ES_ALREADY_SIGNALED - }; - - inline COpenGLSync() : device(nullptr), lockedTable(nullptr), haveNotWaitedOnQueueMask(~0ull), cachedRetval(ES_TIMEOUT_EXPIRED), sync(nullptr) - { - - } - - void init(IOpenGL_LogicalDevice* _dev, IOpenGL_FunctionTable* _gl, bool _lockToQueue = false) - { - device = _dev; - sync = _gl->glSync.pglFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); - if (_lockToQueue) - lockedTable = _gl; - else - _gl->glGeneral.pglFlush(); - haveNotWaitedOnQueueMask ^= (1ull << _gl->getGUID()); - } - // for fences - void initSignaled(IOpenGL_LogicalDevice* _dev, IOpenGL_FunctionTable* _gl) - { - device = _dev; - haveNotWaitedOnQueueMask ^= (1ull << _gl->getGUID()); - cachedRetval = ES_ALREADY_SIGNALED; - } - - uint64_t prewait() const - { - if (sync) - return 0ull; - - using clock_t = std::chrono::high_resolution_clock; - auto start = clock_t::now(); - while (!sync) - { - std::this_thread::yield(); - } - - return std::chrono::duration_cast(clock_t::now() - start).count(); - } - - E_STATUS waitCPU(IOpenGL_FunctionTable* _gl, uint64_t timeout) - { - assert(!lockedTable || lockedTable==_gl); - if (cachedRetval != ES_TIMEOUT_EXPIRED) - return cachedRetval; - - const uint64_t spintime = prewait(); - if (spintime > timeout) - return (cachedRetval = ES_TIMEOUT_EXPIRED); - timeout -= spintime; - - GLenum status = _gl->glSync.pglClientWaitSync(sync, lockedTable?GL_SYNC_FLUSH_COMMANDS_BIT:0, timeout); // GL_SYNC_FLUSH_COMMANDS_BIT to flags? - switch (status) - { - case GL_ALREADY_SIGNALED: - return (cachedRetval = ES_ALREADY_SIGNALED); - break; - case GL_TIMEOUT_EXPIRED: - return (cachedRetval = ES_TIMEOUT_EXPIRED); - break; - case GL_CONDITION_SATISFIED:; - return (cachedRetval = ES_CONDITION_SATISFIED); - break; - default: - break; - } - return (cachedRetval = ES_FAIL); - } - - void waitGPU(IOpenGL_FunctionTable* _gl) - { - if (!lockedTable) // OpenGL device does not need to wait on itself within the same context - { - const uint64_t queueMask = 1ull << _gl->getGUID(); - if (haveNotWaitedOnQueueMask.load() & queueMask) - { - prewait(); - _gl->glSync.pglWaitSync(sync, 0, GL_TIMEOUT_IGNORED); - haveNotWaitedOnQueueMask ^= queueMask; - } - } - else - { - assert(lockedTable==_gl); - } - } - - //inline const volatile GLsync* getNativeHandle() const {return &sync;} - inline GLsync getOpenGLName() const {return sync;} - - bool isInitialized() const - { - // (!sync && (cachedRetval == ES_ALREADY_SIGNALED)) means initialized as signaled - return static_cast(sync) || cachedRetval == ES_ALREADY_SIGNALED; - } - - private: - IOpenGL_LogicalDevice* device; - IOpenGL_FunctionTable* lockedTable; - std::atomic_uint64_t haveNotWaitedOnQueueMask; - E_STATUS cachedRetval; - volatile GLsync sync; -}; - -} - -#endif \ No newline at end of file diff --git a/src/nbl/video/COpenGL_Queue.h b/src/nbl/video/COpenGL_Queue.h index 9c0751fed2..0e77134199 100755 --- a/src/nbl/video/COpenGL_Queue.h +++ b/src/nbl/video/COpenGL_Queue.h @@ -263,7 +263,7 @@ class COpenGL_Queue final : public IGPUQueue if (submit.syncToInit) { - submit.syncToInit->init(m_device, &gl); + submit.syncToInit->init(core::smart_refctd_ptr(m_device), &gl); } else // need to flush, otherwise OpenGL goes gaslighting the user with wrong error messages gl.glGeneral.pglFlush(); diff --git a/src/nbl/video/COpenGL_Swapchain.h b/src/nbl/video/COpenGL_Swapchain.h index e78e4cca8b..3f005999b8 100644 --- a/src/nbl/video/COpenGL_Swapchain.h +++ b/src/nbl/video/COpenGL_Swapchain.h @@ -258,7 +258,7 @@ class COpenGL_Swapchain final : public ISwapchain for (uint32_t i = 0u; i < fboCount; ++i) { syncs[i] = core::make_smart_refctd_ptr(); - syncs[i]->init(m_device, &gl, false); + syncs[i]->init(core::smart_refctd_ptr(m_device), &gl, false); } gl.glGeneral.pglFinish(); @@ -283,7 +283,7 @@ class COpenGL_Swapchain final : public ISwapchain gl.extGlBlitNamedFramebuffer(fbos[imgix], 0, 0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST); syncs[imgix] = core::make_smart_refctd_ptr(); - syncs[imgix]->init(m_device, &gl, false); + syncs[imgix]->init(core::smart_refctd_ptr(m_device), &gl, false); // swap buffers performs an implicit flush before swapping // https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglSwapBuffers.xhtml egl->call.peglSwapBuffers(egl->display, glctx.surface); From f770ef0b90096112e8c29e23d51ed536b177159d Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Fri, 25 Feb 2022 19:58:22 +0100 Subject: [PATCH 29/91] add EGL fix for sample targets, linker error left --- cmake/common.cmake | 6 ++++-- src/nbl/CMakeLists.txt | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index b3954a3d87..d62dc9987e 100755 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -47,12 +47,14 @@ macro(nbl_create_executable_project _EXTRA_SOURCES _EXTRA_OPTIONS _EXTRA_INCLUDE # EXTRA_SOURCES is var containing non-common names of sources (if any such sources, then EXTRA_SOURCES must be set before including this cmake code) add_dependencies(${EXECUTABLE_NAME} Nabla) - + get_target_property(NBL_EGL_INCLUDE_DIRECORIES egl INCLUDE_DIRECTORIES) + target_include_directories(${EXECUTABLE_NAME} PUBLIC ../../include PRIVATE ${_EXTRA_INCLUDES} + PRIVATE ${NBL_EGL_INCLUDE_DIRECORIES} ) - target_link_libraries(${EXECUTABLE_NAME} Nabla ${_EXTRA_LIBS}) # see, this is how you should code to resolve github issue 311 + target_link_libraries(${EXECUTABLE_NAME} PUBLIC Nabla ${_EXTRA_LIBS}) # see, this is how you should code to resolve github issue 311 add_compile_options(${_EXTRA_OPTIONS}) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index bda3be1862..25f7166b4e 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -582,6 +582,7 @@ target_include_directories(Nabla PUBLIC "$<$:${OPENGL_EGL_INCLUDE_DIRS}>" "$<$:${WAYLAND_CLIENT_INCLUDE_DIR}>" ) + target_include_directories(Nabla PUBLIC ${NBL_ROOT_PATH}/src ${NBL_ROOT_PATH}/source/Nabla ${NBL_ROOT_PATH}/src/3rdparty) # this should be PRIVATE, but things from /src (or /source) are sometimes included in things in /include and so examples have to put source dirs into theirs Include Path target_include_directories(Nabla PRIVATE ${CMAKE_BINARY_DIR}/include) if (UNIX AND NOT ANDROID AND NOT APPLE) From 27e88f80151ebac3a54a8438302db0440638ea6a Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Fri, 25 Feb 2022 22:09:25 +0100 Subject: [PATCH 30/91] add EGL nbl_create_ext_libra macro + Matt be careful when using inline specifier --- cmake/common.cmake | 2 ++ include/nbl/video/COpenGLSync.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/common.cmake b/cmake/common.cmake index d62dc9987e..ea9644b6d7 100755 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -183,6 +183,7 @@ macro(nbl_create_ext_library_project EXT_NAME LIB_HEADERS LIB_SOURCES LIB_INCLUD add_dependencies(${LIB_NAME} Nabla) get_target_property(_NBL_NABLA_TARGET_BINARY_DIR_ Nabla BINARY_DIR) + get_target_property(NBL_EGL_INCLUDE_DIRECORIES egl INCLUDE_DIRECTORIES) target_include_directories(${LIB_NAME} PUBLIC ${_NBL_NABLA_TARGET_BINARY_DIR_}/build/import @@ -193,6 +194,7 @@ macro(nbl_create_ext_library_project EXT_NAME LIB_HEADERS LIB_SOURCES LIB_INCLUD PUBLIC ${CMAKE_SOURCE_DIR}/src PUBLIC ${CMAKE_SOURCE_DIR}/source/Nabla PRIVATE ${LIB_INCLUDES} + PRIVATE ${NBL_EGL_INCLUDE_DIRECORIES} ) add_dependencies(${LIB_NAME} Nabla) target_link_libraries(${LIB_NAME} PUBLIC Nabla) diff --git a/include/nbl/video/COpenGLSync.h b/include/nbl/video/COpenGLSync.h index f2d5952c00..fd56821424 100644 --- a/include/nbl/video/COpenGLSync.h +++ b/include/nbl/video/COpenGLSync.h @@ -57,7 +57,7 @@ class COpenGLSync final : public core::IReferenceCounted // Already signalled constructor (for IGPUFence) struct signalled_t {}; constexpr static inline signalled_t signalled = {}; - inline COpenGLSync(core::smart_refctd_ptr&& _dev, IOpenGL_FunctionTable* _gl, signalled_t signalled); + COpenGLSync(core::smart_refctd_ptr&& _dev, IOpenGL_FunctionTable* _gl, signalled_t signalled); private: core::smart_refctd_ptr device; From f3f1dba88d492c41c285254aa3c53448137b2880 Mon Sep 17 00:00:00 2001 From: MohammadHasanKargar Date: Mon, 28 Feb 2022 19:33:51 +0330 Subject: [PATCH 31/91] Add Vulkan 1.3 version to Vulkan version validation and Add Spir-v 1.6 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved Signed-off-by: MohammadHasanKargar --- include/nbl/asset/utils/IGLSLCompiler.h | 1 + src/nbl/video/CVulkanPhysicalDevice.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/nbl/asset/utils/IGLSLCompiler.h b/include/nbl/asset/utils/IGLSLCompiler.h index 99c66ec0aa..922fa50f0e 100644 --- a/include/nbl/asset/utils/IGLSLCompiler.h +++ b/include/nbl/asset/utils/IGLSLCompiler.h @@ -31,6 +31,7 @@ class IGLSLCompiler final : public core::IReferenceCounted ESV_1_3 = 0x010300u, ESV_1_4 = 0x010400u, ESV_1_5 = 0x010500u, + ESV_1_6 = 0x010600u, ESV_COUNT = 0x7FFFFFFFu }; diff --git a/src/nbl/video/CVulkanPhysicalDevice.h b/src/nbl/video/CVulkanPhysicalDevice.h index 1fce7e15d5..504595c680 100644 --- a/src/nbl/video/CVulkanPhysicalDevice.h +++ b/src/nbl/video/CVulkanPhysicalDevice.h @@ -86,6 +86,7 @@ class CVulkanPhysicalDevice final : public IPhysicalDevice [NO NABALA SUPPORT] Vulkan 1.0 implementation must support the 1.0 version of SPIR-V and the 1.0 version of the SPIR-V Extended Instructions for GLSL. If the VK_KHR_spirv_1_4 extension is enabled, the implementation must additionally support the 1.4 version of SPIR-V. A Vulkan 1.1 implementation must support the 1.0, 1.1, 1.2, and 1.3 versions of SPIR-V and the 1.0 version of the SPIR-V Extended Instructions for GLSL. A Vulkan 1.2 implementation must support the 1.0, 1.1, 1.2, 1.3, 1.4, and 1.5 versions of SPIR-V and the 1.0 version of the SPIR-V Extended Instructions for GLSL. + A Vulkan 1.3 implementation must support the 1.0, 1.1, 1.2, 1.3, 1.4, and 1.5 versions of SPIR-V and the 1.0 version of the SPIR-V Extended Instructions for GLSL. */ uint32_t apiVersion = std::min(instanceApiVersion, deviceProperties.properties.apiVersion); @@ -104,6 +105,9 @@ class CVulkanPhysicalDevice final : public IPhysicalDevice case 2: m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_5; break; + case 3: + m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_5; // TODO: change this to spirv 1.6 + break; default: _NBL_DEBUG_BREAK_IF("Invalid Vulkan minor version!"); break; From b70d07f788f8407f7931c7ef791998455beabdfe Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 1 Mar 2022 15:24:35 +0100 Subject: [PATCH 32/91] Hide platform dependent details of IAPIConnection Also fix the Vulkan SDK issue once and for all. --- .gitmodules | 4 ++ 3rdparty/CMakeLists.txt | 44 ++++++++++++++------ 3rdparty/Vulkan-Headers | 1 + include/nbl/system/CSystemAndroid.h | 2 + include/nbl/system/CSystemWin32.h | 2 +- include/nbl/video/IAPIConnection.h | 54 +++++++------------------ include/nbl/video/utilities/renderdoc.h | 4 +- src/nbl/CMakeLists.txt | 8 +--- src/nbl/video/IAPIConnection.cpp | 26 ++++++++++++ 9 files changed, 84 insertions(+), 61 deletions(-) create mode 160000 3rdparty/Vulkan-Headers diff --git a/.gitmodules b/.gitmodules index 1484a481cb..3688f3bac4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -89,3 +89,7 @@ [submodule "3rdparty/pstl/oneDPL/oneDPL"] path = 3rdparty/pstl/oneDPL/oneDPL url = https://github.com/Devsh-Graphics-Programming/oneDPL.git +[submodule "3rdparty/Vulkan-Headers"] + path = 3rdparty/Vulkan-Headers + url = git@github.com:KhronosGroup/Vulkan-Headers.git + branch = main diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index ffbfd8a135..a07506d3ad 100755 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -47,29 +47,30 @@ set(BUILD_SHARED_LIBS ${_OLD_BUILD_SHARED_LIBS}) set(BUILD_STATIC_LIBS ${_OLD_BUILD_STATIC_LIBS}) set(BUILD_TESTING ${_OLD_BUILD_TESTING}) + # openssl add_subdirectory(openssl openssl EXCLUDE_FROM_ALL) + # volk -if(DEFINED ENV{VULKAN_SDK}) - # workaround to make sure vulkan library will not be linked in examples - set(VOLK_PULL_IN_VULKAN OFF CACHE INTERNAL "" FORCE) - - if (WIN32) - set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR) - endif() - add_subdirectory(volk volk EXCLUDE_FROM_ALL) +set(VOLK_PULL_IN_VULKAN OFF CACHE INTERNAL "" FORCE) # Needed to make sure vulkan library will not be linked in examples - target_include_directories(volk PUBLIC "$ENV{VULKAN_SDK}/Include") - target_include_directories(volk_headers INTERFACE "$ENV{VULKAN_SDK}/Include") +if (WIN32) + set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR) endif() +add_subdirectory(volk volk EXCLUDE_FROM_ALL) + +target_include_directories(volk PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include") +target_include_directories(volk_headers INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers/include") if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") add_subdirectory(pstl pstl) endif() + +# TODO: redo find_package(OpenGL OPTIONAL_COMPONENTS EGL) -find_package(Wayland) # TODO: remove, do it dynamically +find_package(Wayland) # TODO: remove, load Wayland dynamically #[[if (OpenGL_EGL_FOUND) message(FATAL_ERROR "FOUND EGL!!") else() @@ -85,8 +86,10 @@ if (OpenGL_EGL_FOUND AND UNIX AND NOT APPLE) message(FATAL_ERROR "Using Wayland backend!!!") endif() endif() +# all of the above fuckery can be dismissed add_subdirectory(EGL/EGL) + # zlib (target is zlibstatic) set(_OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) set(_OLD_SKIP_INSTALL_ALL ${SKIP_INSTALL_ALL}) @@ -139,6 +142,7 @@ set(ZLIB_LIBRARY # for PNGLIB purposes $<$:${ZLIB_LIBRARY_RELWITHDEBINFO}> CACHE INTERNAL "" FORCE) + set(SPIRV_HEADERS_SKIP_INSTALL ON CACHE INTERNAL "Skip SPIRV-Headers install") set(SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE INTERNAL "Skip SPIRV-Headers examples") add_subdirectory(SPIRV-Headers SPIRV-Headers EXCLUDE_FROM_ALL) @@ -164,6 +168,7 @@ if (UNIX) endif() add_subdirectory(shaderc shaderc EXCLUDE_FROM_ALL) + # libjpeg-turbo option(WITH_SIMD "libjpeg-turbo" ON) option(WITH_MEM_SRCDST "libjpeg-turbo" ON) @@ -179,6 +184,7 @@ add_subdirectory(libjpeg-turbo libjpeg-turbo EXCLUDE_FROM_ALL) unset(CMAKE_INSTALL_DOCDIR) unset(CMAKE_INSTALL_MANDIR) + #manipulating libpng cmake options from within cmake script set(PNG_BUILD_ZLIB ON CACHE INTERNAL "" FORCE) # get ZLIB from our /3rdparty option(PNG_SHARED "Build shared lib" OFF) @@ -186,6 +192,7 @@ option(PNG_TESTS "Build libpng tests" OFF) add_subdirectory(libpng libpng EXCLUDE_FROM_ALL) add_dependencies(png_static zlibstatic) + #openexr option(_NBL_COMPILE_WITH_OPEN_EXR_ "Build with OpenEXR library" ON) if (_NBL_COMPILE_WITH_OPEN_EXR_) @@ -204,6 +211,7 @@ if (_NBL_COMPILE_WITH_OPEN_EXR_) set(BUILD_TESTING ${_OLD_BUILD_TESTING}) endif() + #gli option(_NBL_COMPILE_WITH_GLI_ "Build with GLI library" ON) if(_NBL_COMPILE_WITH_GLI_) @@ -219,8 +227,10 @@ if(_NBL_COMPILE_WITH_GLI_) set(BUILD_TESTING ${_OLD_BUILD_TESTING}) endif() + nbl_adjust_flags() + add_library(lzma OBJECT lzma/C/Alloc.c lzma/C/LzFind.c @@ -229,6 +239,7 @@ add_library(lzma OBJECT ) target_compile_definitions(lzma PRIVATE _7ZIP_ST) + add_library(lz4 OBJECT lz4/lib/lz4.c lz4/lib/lz4frame.c @@ -236,6 +247,7 @@ add_library(lz4 OBJECT lz4/lib/xxhash.c ) + add_library(bzip2 OBJECT bzip2/blocksort.c bzip2/bzlib.c @@ -256,11 +268,13 @@ add_library(spirv_cross OBJECT ) target_compile_definitions(spirv_cross PUBLIC SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) + # TODO: remove add_library(convert_utf OBJECT convertutf/ConvertUTF.cpp ) + add_library(aesGladman OBJECT aesGladman/aes_ni.c aesGladman/aescrypt.c @@ -279,6 +293,7 @@ option(GLM_TEST_ENABLE "Build unit tests" OFF) set(BUILD_SHARED_LIBS ${_OLD_BUILD_SHARED_LIBS}) set(BUILD_STATIC_LIBS ${_OLD_BUILD_STATIC_LIBS}) + if (NBL_BUILD_MITSUBA_LOADER) if(NBL_UPDATE_GIT_SUBMODULE) update_git_submodule(./libexpat) @@ -304,6 +319,7 @@ if (NBL_BUILD_MITSUBA_LOADER) set(MITSUBA_LOADER_DEPENDENT_LIBS ${MITSUBA_LOADER_DEPENDENT_LIBS} PARENT_SCOPE) endif() + if (NBL_BUILD_BULLET) if(NBL_UPDATE_GIT_SUBMODULE) update_git_submodule(./bullet3) @@ -322,6 +338,8 @@ if (NBL_COMPILE_WITH_CUDA) endif() endif() + +# Final gather set(NBL_3RDPARTY_TARGETS lzma lz4 @@ -376,6 +394,8 @@ endforeach() set(_NBL_3RDPARTY_TARGETS_ ${NBL_3RDPARTY_TARGETS} PARENT_SCOPE) + +## REMINDER / NOTE : This is how we install 3rdparty headers we need ! # parallel hashmap headers install( DIRECTORY ./parallel-hashmap/parallel_hashmap @@ -383,7 +403,7 @@ install( CONFIGURATIONS Release ) install( - DIRECTORY ./parallel-hashmap//parallel_hashmap + DIRECTORY ./parallel-hashmap/parallel_hashmap DESTINATION ./debug/include/parallel-hashmap CONFIGURATIONS Debug ) diff --git a/3rdparty/Vulkan-Headers b/3rdparty/Vulkan-Headers new file mode 160000 index 0000000000..aa18f182eb --- /dev/null +++ b/3rdparty/Vulkan-Headers @@ -0,0 +1 @@ +Subproject commit aa18f182ebba65438b1cfdbd571f020bb2e34d04 diff --git a/include/nbl/system/CSystemAndroid.h b/include/nbl/system/CSystemAndroid.h index a837699404..877151da4e 100644 --- a/include/nbl/system/CSystemAndroid.h +++ b/include/nbl/system/CSystemAndroid.h @@ -1,5 +1,6 @@ #ifndef _NBL_SYSTEM_C_SYSTEM_ANDROID_H_INCLUDED_ #define _NBL_SYSTEM_C_SYSTEM_ANDROID_H_INCLUDED_ + #ifdef _NBL_PLATFORM_ANDROID_ #include "nbl/system/ISystem.h" #include "nbl/system/CAPKResourcesArchive.h" @@ -34,4 +35,5 @@ namespace nbl::system }; } #endif + #endif \ No newline at end of file diff --git a/include/nbl/system/CSystemWin32.h b/include/nbl/system/CSystemWin32.h index 71a1af160d..0489c8097e 100644 --- a/include/nbl/system/CSystemWin32.h +++ b/include/nbl/system/CSystemWin32.h @@ -26,7 +26,7 @@ class CSystemWin32 : public ISystem { public: CSystemWin32(core::smart_refctd_ptr&& caller) : ISystem(std::move(caller)) {} - //LOL the struct definition wasn't added to winapi headers do they ask to declare them yourself (probably in another header?) + //LOL the struct definition wasn't added to winapi headers do they ask to declare them yourself typedef struct _PROCESSOR_POWER_INFORMATION { ULONG Number; ULONG MaxMhz; diff --git a/include/nbl/video/IAPIConnection.h b/include/nbl/video/IAPIConnection.h index 6c066e0124..f90b4c5270 100644 --- a/include/nbl/video/IAPIConnection.h +++ b/include/nbl/video/IAPIConnection.h @@ -14,51 +14,27 @@ class IPhysicalDevice; class IAPIConnection : public core::IReferenceCounted { -public: - // TODO: are these "instance features" ? - enum E_FEATURE - { - EF_SURFACE = 0, - EF_COUNT - }; + public: + // TODO: are these "instance features" ? + enum E_FEATURE + { + EF_SURFACE = 0, + EF_COUNT + }; - virtual E_API_TYPE getAPIType() const = 0; + virtual E_API_TYPE getAPIType() const = 0; - virtual IDebugCallback* getDebugCallback() const = 0; + virtual IDebugCallback* getDebugCallback() const = 0; - core::SRange getPhysicalDevices() const; + core::SRange getPhysicalDevices() const; - static core::SRange getDependentFeatures(const E_FEATURE feature); + static core::SRange getDependentFeatures(const E_FEATURE feature); -protected: - // TODO: move to IAPIConnection.cpp - inline IAPIConnection() : m_physicalDevices(), m_rdoc_api(nullptr) - { -#ifdef _NBL_PLATFORM_WINDOWS_ - if (HMODULE mod = GetModuleHandleA("renderdoc.dll")) -#elif defined(_NBL_PLATFORM_ANDROID_) - if (void* mod = dlopen("libVkLayer_GLES_RenderDoc.so", RTLD_NOW | RTLD_NOLOAD)) -#elif defined(_NBL_PLATFORM_LINUX_) - if (void* mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) -#else - if (false) -#endif - { -#if defined(_NBL_PLATFORM_WINDOWS_) - pRENDERDOC_GetAPI RENDERDOC_GetAPI = - (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI"); - int ret = RENDERDOC_GetAPI(MinRenderdocVersion, (void**)&m_rdoc_api); - assert(ret == 1); -#elif defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_LINUX_) - pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI"); - int ret = RENDERDOC_GetAPI(MinRenderdocVersion, (void**)&m_rdoc_api); - assert(ret == 1); -#endif - } - } + protected: + IAPIConnection(); - std::vector> m_physicalDevices; - renderdoc_api_t* m_rdoc_api; + std::vector> m_physicalDevices; + renderdoc_api_t* m_rdoc_api; }; } diff --git a/include/nbl/video/utilities/renderdoc.h b/include/nbl/video/utilities/renderdoc.h index 67b6f6e23e..b283145aa0 100644 --- a/include/nbl/video/utilities/renderdoc.h +++ b/include/nbl/video/utilities/renderdoc.h @@ -1,5 +1,5 @@ -#ifndef __NBL_VIDEO_UTILITIES_RENDERDOC_H_INCLUDED_ -#define __NBL_VIDEO_UTILITIES_RENDERDOC_H_INCLUDED_ +#ifndef _NBL_VIDEO_UTILITIES_RENDERDOC_H_INCLUDED_ +#define _NBL_VIDEO_UTILITIES_RENDERDOC_H_INCLUDED_ #include "renderdoc/renderdoc_app.h" // renderdoc_app from /3rdparty diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 25f7166b4e..6610a0d006 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -384,10 +384,6 @@ set(COMMON_INCLUDE_DIRS $ #for dynamically generated jconfig.h ) -macro(nbl_target_link_vulkan _trgt) # we don't want to link against library directly - target_include_directories(${_trgt} PUBLIC "$ENV{VULKAN_SDK}/include") -endmacro() - macro(nbl_target_link_utfcpp _trgt) # TODO: remove target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/utfcpp/source) endmacro() @@ -536,9 +532,7 @@ set_property(TARGET Nabla PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$ IAPIConnection::getDependentFeatur } } +IAPIConnection::IAPIConnection() : m_physicalDevices(), m_rdoc_api(nullptr) +{ +#ifdef _NBL_PLATFORM_WINDOWS_ + if (HMODULE mod = GetModuleHandleA("renderdoc.dll")) +#elif defined(_NBL_PLATFORM_ANDROID_) + if (void* mod = dlopen("libVkLayer_GLES_RenderDoc.so", RTLD_NOW | RTLD_NOLOAD)) +#elif defined(_NBL_PLATFORM_LINUX_) + if (void* mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) +#else +#error "Nabla Unsupported Platform!" +#endif + { + #if defined(_NBL_PLATFORM_WINDOWS_) + pRENDERDOC_GetAPI RENDERDOC_GetAPI = + (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI"); + int ret = RENDERDOC_GetAPI(MinRenderdocVersion, (void**)&m_rdoc_api); + assert(ret == 1); + #elif defined(_NBL_PLATFORM_ANDROID_) || defined(_NBL_PLATFORM_LINUX_) + pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI"); + int ret = RENDERDOC_GetAPI(MinRenderdocVersion, (void**)&m_rdoc_api); + assert(ret == 1); + #endif + } +} + } \ No newline at end of file From 33a9d650cb34f08b110d8473ec6afe47e5cb10b7 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 1 Mar 2022 15:52:31 +0100 Subject: [PATCH 33/91] comment and organise 3rdparty cmake a little bit --- src/nbl/CMakeLists.txt | 104 +++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 6610a0d006..53b44d02a1 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -45,6 +45,7 @@ message(FATAL_ERROR "XDDDDDDD") if (NOT ANDROID) find_package(OpenGL REQUIRED OPTIONAL_COMPONENTS EGL) else() + # TODO: @AnastaZluk we have these in our own 3rdparty anyway! find_path(GLES3_INCLUDE_DIR GLES3/gl31.h HINTS ${ANDROID_NDK_ROOT_PATH} REQUIRED) if (${GLES3_INCLUDE_DIR}) set(OpenGL_OpenGL_FOUND True) @@ -56,6 +57,7 @@ else() endif() endif() if(UNIX AND NOT ANDROID) + # TODO: maybe require the `-dev` packages for both? (or ship headers ourselves?) find_package(Wayland) find_package(X11 REQUIRED) set(CMAKE_THREAD_PREFER_PTHREAD 1) @@ -124,7 +126,7 @@ option(_NBL_COMPILE_WITH_GLTF_WRITER_ "Compile with GLTF Writer" ON) if(NBL_BUILD_ANDROID) set(_NBL_COMPILE_WITH_BAW_LOADER_ OFF CACHE BOOL "Off for Android purposes at the moment" FORCE) # TODO - remove when BAW-v4 is done set(_NBL_COMPILE_WITH_BAW_WRITER_ OFF CACHE BOOL "Off for Android purposes at the moment" FORCE) # TODO - remove when BAW-v4 is done - set(NBL_BUILD_MITSUBA_LOADER OFF CACHE BOOL "Off for Android purposes at the moment" FORCE) # TODO - compile/linker errors + set(NBL_BUILD_MITSUBA_LOADER OFF CACHE BOOL "Android doesn't need this loader, if you want it, pay us.'" FORCE) endif() nbl_get_conf_dir(NABLA_CONF_DIR_DEBUG Debug) @@ -147,6 +149,8 @@ endif() set(_NBL_EMBED_BUILTIN_RESOURCES_ ${NBL_EMBED_BUILTIN_RESOURCES}) #set(_NBL_TARGET_ARCH_ARM_ ${NBL_TARGET_ARCH_ARM}) #uncomment in the future + +# TODO: this is a mess and not the right way to about it if (WAYLAND_CLIENT_FOUND AND OpenGL_EGL_FOUND) set(_NBL_BUILD_WITH_WAYLAND 1) #message(FATAL_ERROR "found wayland! ${WAYLAND_CLIENT_LIBRARY}") @@ -154,6 +158,7 @@ else() set(_NBL_BUILD_WITH_WAYLAND 0) #message(FATAL_ERROR "NOT found wayland!") endif() + set(__NBL_FAST_MATH ${NBL_FAST_MATH}) set(_NBL_DEBUG 0) set(_NBL_RELWITHDEBINFO 0) @@ -165,6 +170,8 @@ set(_NBL_DEBUG 1) set(_NBL_RELWITHDEBINFO 0) configure_file("${NBL_ROOT_PATH}/include/nbl/config/BuildConfigOptions.h.in" "${NABLA_CONF_DIR_DEBUG}/BuildConfigOptions.h") + +# a little bit of globbing for headers never hurt anyone file(GLOB_RECURSE TEMP_GLOB_RES "${NBL_ROOT_PATH}/include/*.h") set(NABLA_HEADERS_PUBLIC ${NABLA_HEADERS_PUBLIC} ${TEMP_GLOB_RES}) file(GLOB_RECURSE TEMP_GLOB_RES "${NBL_ROOT_PATH}/include/*.tcc") @@ -175,6 +182,8 @@ file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") # just gather all the header files and later put them into project so it's easy to search for things using IDE set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) + +# set(NBL_CORE_SOURCES ${NBL_ROOT_PATH}/src/nbl/core/IReferenceCounted.cpp ) @@ -234,7 +243,6 @@ set(NBL_ASSET_SOURCES # Mesh writers # ${NBL_ROOT_PATH}/src/nbl/asset/bawformat/CBAWMeshWriter.cpp - ${NBL_ROOT_PATH}/src/nbl/asset/interchange/CPLYMeshWriter.cpp ${NBL_ROOT_PATH}/src/nbl/asset/interchange/CSTLMeshWriter.cpp ${NBL_ROOT_PATH}/src/nbl/asset/interchange/CGLTFWriter.cpp @@ -275,10 +283,6 @@ set(NBL_VIDEO_SOURCES # Allocators ${NBL_ROOT_PATH}/src/nbl/video/alloc/SimpleGPUBufferAllocator.cpp ${NBL_ROOT_PATH}/src/nbl/video/alloc/StreamingGPUBufferAllocator.cpp - -# Shaders - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLShader.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLSpecializedShader.cpp # Utilities ${NBL_ROOT_PATH}/src/nbl/video/utilities/IDescriptorSetCache.cpp @@ -293,31 +297,28 @@ set(NBL_VIDEO_SOURCES ${NBL_ROOT_PATH}/src/nbl/video/ILogicalDevice.cpp ${NBL_ROOT_PATH}/src/nbl/video/IGPUFence.cpp ${NBL_ROOT_PATH}/src/nbl/video/IDriverMemoryAllocation.cpp -) -set(NBL_SCENE_SOURCES - ${NBL_ROOT_PATH}/src/nbl/scene/ITransformTree.cpp -) -set(NABLA_SRCS_COMMON - ${NBL_CORE_SOURCES} - ${NBL_SYSTEM_SOURCES} - ${NBL_ASSET_SOURCES} - ${NBL_VIDEO_SOURCES} - ${NBL_SCENE_SOURCES} - ${NBL_SYSTEM_SOURCES} - ${NBL_UI_SOURCES} -) -if(MSVC) - list(APPEND NABLA_SRCS_COMMON "${PROJECT_SOURCE_DIR}/tools/debug/VisualStudio/DynamicArrayVisualizer.natvis") -endif() - -if (NBL_EMBED_BUILTIN_RESOURCES) - list(APPEND NABLA_SRCS_COMMON "${CMAKE_BINARY_DIR}/src/nbl/builtin/builtinResourceData.cpp") -endif() - - -set(NABLA_SRCS_NORMAL - # Vulkan +# OpenGL + ${NBL_ROOT_PATH}/src/nbl/video/IOpenGL_FunctionTable.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLPipelineCache.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLImage.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLImageView.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLBuffer.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLBufferView.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLSpecializedShader.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLSampler.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLCommandBuffer.cpp + ${NBL_ROOT_PATH}/src/nbl/video/SOpenGLContextLocalCache.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLSync.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLShader.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLRenderpassIndependentPipeline.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLFramebuffer.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGL_Connection.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLComputePipeline.cpp + ${NBL_ROOT_PATH}/src/nbl/video/COpenGLQueryPool.cpp + ${NBL_ROOT_PATH}/src/nbl/video/debug/COpenGLDebugCallback.cpp + +# Vulkan ${NBL_ROOT_PATH}/src/nbl/video/CVulkanSwapchain.cpp ${NBL_ROOT_PATH}/src/nbl/video/CVulkanFence.cpp ${NBL_ROOT_PATH}/src/nbl/video/CVulkanImage.cpp @@ -347,31 +348,33 @@ set(NABLA_SRCS_NORMAL ${NBL_ROOT_PATH}/src/nbl/video/CVulkanGraphicsPipeline.cpp ${NBL_ROOT_PATH}/src/nbl/video/CVulkanEvent.cpp ${NBL_ROOT_PATH}/src/nbl/video/CSurfaceVulkan.cpp - - - #opengl - ${NBL_ROOT_PATH}/src/nbl/video/IOpenGL_FunctionTable.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLPipelineCache.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLImage.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLImageView.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLBuffer.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLBufferView.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLSampler.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLCommandBuffer.cpp - ${NBL_ROOT_PATH}/src/nbl/video/SOpenGLContextLocalCache.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLSync.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLRenderpassIndependentPipeline.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLFramebuffer.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGL_Connection.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLComputePipeline.cpp - ${NBL_ROOT_PATH}/src/nbl/video/COpenGLQueryPool.cpp - ${NBL_ROOT_PATH}/src/nbl/video/debug/COpenGLDebugCallback.cpp - # CUDA +# CUDA ${NBL_ROOT_PATH}/src/nbl/video/CCUDAHandler.cpp ${NBL_ROOT_PATH}/src/nbl/video/CCUDADevice.cpp ) +set(NBL_SCENE_SOURCES + ${NBL_ROOT_PATH}/src/nbl/scene/ITransformTree.cpp +) + +set(NABLA_SRCS_COMMON + ${NBL_CORE_SOURCES} + ${NBL_SYSTEM_SOURCES} + ${NBL_UI_SOURCES} + ${NBL_ASSET_SOURCES} + ${NBL_VIDEO_SOURCES} + ${NBL_SCENE_SOURCES} +) + +if(MSVC) + list(APPEND NABLA_SRCS_COMMON "${PROJECT_SOURCE_DIR}/tools/debug/VisualStudio/DynamicArrayVisualizer.natvis") +endif() + +if (NBL_EMBED_BUILTIN_RESOURCES) + list(APPEND NABLA_SRCS_COMMON "${CMAKE_BINARY_DIR}/src/nbl/builtin/builtinResourceData.cpp") +endif() + set(COMMON_INCLUDE_DIRS ${THIRD_PARTY_SOURCE_DIR}/convertutf # TODO: remove ${THIRD_PARTY_SOURCE_DIR}/utfcpp/source # TODO: remove @@ -499,7 +502,6 @@ endmacro() add_library(Nabla STATIC ${NABLA_SRCS_COMMON} - ${NABLA_SRCS_NORMAL} ${NABLA_HEADERS} $ $ From 1136c15fe1c7f2f59b9330b6e5c19f55dc05b60e Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 1 Mar 2022 16:23:21 +0100 Subject: [PATCH 34/91] Remove UTF submodules --- .gitmodules | 6 ------ 3rdparty/CMakeLists.txt | 9 --------- 3rdparty/convertutf | 1 - 3rdparty/utfcpp | 1 - include/nbl/system/CStdoutLogger.h | 11 ++++++++--- include/nbl/system/CSystemWin32.h | 1 + include/nbl/system/ILogger.h | 18 +++++------------- src/nbl/CMakeLists.txt | 7 ------- 8 files changed, 14 insertions(+), 40 deletions(-) delete mode 160000 3rdparty/convertutf delete mode 160000 3rdparty/utfcpp diff --git a/.gitmodules b/.gitmodules index 3688f3bac4..ddaab00172 100644 --- a/.gitmodules +++ b/.gitmodules @@ -20,12 +20,6 @@ [submodule "3rdparty/zlib"] path = 3rdparty/zlib url = https://github.com/madler/zlib.git -[submodule "3rdparty/utfcpp"] - path = 3rdparty/utfcpp - url = https://github.com/nemtrif/utfcpp.git -[submodule "3rdparty/convertutf"] - path = 3rdparty/convertutf - url = https://github.com/plenluno/convertutf.git [submodule "3rdparty/libpng"] path = 3rdparty/libpng url = https://github.com/glennrp/libpng.git diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index a07506d3ad..8dd53c2af8 100755 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -18,8 +18,6 @@ if(NBL_UPDATE_GIT_SUBMODULE) update_git_submodule(./nbl_spirv_cross) update_git_submodule(./zlib) update_git_submodule(./openexr) - update_git_submodule(./utfcpp) # TODO: remove - update_git_submodule(./convertutf) # TODO: remove update_git_submodule(./libpng) update_git_submodule(./openssl) update_git_submodule(./libjpeg-turbo) @@ -269,12 +267,6 @@ add_library(spirv_cross OBJECT target_compile_definitions(spirv_cross PUBLIC SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS) -# TODO: remove -add_library(convert_utf OBJECT - convertutf/ConvertUTF.cpp -) - - add_library(aesGladman OBJECT aesGladman/aes_ni.c aesGladman/aescrypt.c @@ -350,7 +342,6 @@ set(NBL_3RDPARTY_TARGETS shaderc_util shaderc jpeg-static - convert_utf bzip2 glslang OGLCompiler diff --git a/3rdparty/convertutf b/3rdparty/convertutf deleted file mode 160000 index 19e1e918f4..0000000000 --- a/3rdparty/convertutf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 19e1e918f4cb15bd8b61a26d00286688c6974f3b diff --git a/3rdparty/utfcpp b/3rdparty/utfcpp deleted file mode 160000 index 82c674b7a7..0000000000 --- a/3rdparty/utfcpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 82c674b7a7aff3f2845e8eb17d0d9f790b629799 diff --git a/include/nbl/system/CStdoutLogger.h b/include/nbl/system/CStdoutLogger.h index 6e69d9db64..3538681461 100644 --- a/include/nbl/system/CStdoutLogger.h +++ b/include/nbl/system/CStdoutLogger.h @@ -6,16 +6,21 @@ namespace nbl::system { - class CStdoutLogger : public IThreadsafeLogger - { + +class CStdoutLogger : public IThreadsafeLogger +{ + public: CStdoutLogger(core::bitflag logLevelMask = ILogger::defaultLogMask()) : IThreadsafeLogger(logLevelMask) {} + + protected: virtual void threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override { printf(constructLogString(fmt, logLevel, args).data()); fflush(stdout); } - }; +}; + } #endif \ No newline at end of file diff --git a/include/nbl/system/CSystemWin32.h b/include/nbl/system/CSystemWin32.h index 0489c8097e..0576c8f6cb 100644 --- a/include/nbl/system/CSystemWin32.h +++ b/include/nbl/system/CSystemWin32.h @@ -1,5 +1,6 @@ #ifndef _NBL_SYSTEM_CSYSTEMWIN32_H_INCLUDED_ #define _NBL_SYSTEM_CSYSTEMWIN32_H_INCLUDED_ + #ifdef _NBL_PLATFORM_WINDOWS_ #include #include diff --git a/include/nbl/system/ILogger.h b/include/nbl/system/ILogger.h index ecdd26b3ba..642ccc9e15 100644 --- a/include/nbl/system/ILogger.h +++ b/include/nbl/system/ILogger.h @@ -13,7 +13,6 @@ #include #include #include -#include namespace nbl::system @@ -31,10 +30,6 @@ class ILogger : public core::IReferenceCounted ELL_PERFORMANCE = 8, ELL_ERROR = 16 }; - protected: - static core::bitflag defaultLogMask(); - public: - ILogger(core::bitflag logLevelMask) : m_logLevelMask(logLevelMask) {} void log(const std::string_view& fmtString, E_LOG_LEVEL logLevel = ELL_DEBUG, ...) { @@ -53,6 +48,10 @@ class ILogger : public core::IReferenceCounted } protected: + static core::bitflag defaultLogMask(); + + ILogger(core::bitflag logLevelMask) : m_logLevelMask(logLevelMask) {} + virtual void log_impl(const std::string_view& fmtString, E_LOG_LEVEL logLevel, va_list args) = 0; virtual std::string constructLogString(const std::string_view& fmtString, E_LOG_LEVEL logLevel, va_list l) { @@ -106,14 +105,7 @@ class ILogger : public core::IReferenceCounted return out_str; return ""; } - virtual std::wstring constructLogWstring(const std::wstring_view& fmtString, E_LOG_LEVEL logLevel, va_list l) - { - std::wstring_convert> converter; - std::string narrow = converter.to_bytes(std::wstring(fmtString)); - std::string narrowStr = constructLogString(narrow, logLevel, l); - std::wstring wide = converter.from_bytes(narrowStr); - return wide; - } + private: core::bitflag m_logLevelMask; }; diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 53b44d02a1..f757aea3fc 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -376,8 +376,6 @@ if (NBL_EMBED_BUILTIN_RESOURCES) endif() set(COMMON_INCLUDE_DIRS - ${THIRD_PARTY_SOURCE_DIR}/convertutf # TODO: remove - ${THIRD_PARTY_SOURCE_DIR}/utfcpp/source # TODO: remove ${THIRD_PARTY_SOURCE_DIR}/glm ${THIRD_PARTY_SOURCE_DIR}/renderdoc # for renderdoc api header ${CMAKE_BINARY_DIR}/3rdparty/zlib #for dynamically generated zconf.h @@ -387,10 +385,6 @@ set(COMMON_INCLUDE_DIRS $ #for dynamically generated jconfig.h ) -macro(nbl_target_link_utfcpp _trgt) # TODO: remove - target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/utfcpp/source) -endmacro() - # TODO: Change all MACROS into FUNCTIONS (if possible, need to clarify variable scoping rules) macro(nbl_target_link_zlib _trgt) add_dependencies(zlibstatic zlib_copy) @@ -505,7 +499,6 @@ add_library(Nabla STATIC ${NABLA_HEADERS} $ $ - $ $ $ $ From 99a3cb5ec9ddf8326f2724a754549e0ff5313e30 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 1 Mar 2022 16:51:08 +0100 Subject: [PATCH 35/91] Upgrade SPV default target to 1.6 Also test examples 1-4 and update the example matrix --- examples_tests/Readme.md | 4 ++-- include/nbl/asset/utils/IGLSLCompiler.h | 10 +++++----- src/nbl/video/CVulkanPhysicalDevice.h | 2 +- src/nbl/video/IOpenGL_PhysicalDeviceBase.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index d90f6fd482..47f51420b0 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -33,8 +33,8 @@ N = No support | | Win32 OpenGL | Win32 OpenGL ES* | Win32 Vulkan | X11** OpenGL | X11** OpenGL ES | X11** Vulkan | Android OpenGL ES | Android Vulkan | Required CMake Options**** | |---------------------------------|--------------|------------------|--------------|--------------|-----------------|--------------|-------------------|----------------|---------------------------------------------------| | 01.HelloWorld | Y | Y | Y | S | S | S | Y | S | | -| 02.ComputeShader | B | B | Y | B | B | S | B | S | | -| 03.GPU_Mesh | S | S | S | S | S | S | S | S | | +| 02.ComputeShader | Y | Y | Y | B | B | S | B | S | | +| 03.GPU_Mesh | W | W | W | W | W | W | W | W | | | 04.Keyframe | S | S | S | S | S | S | S | S | | | 05.NablaTutorialExample | Y | Y | Y | S | S | S | S | S | | | 06.MeshLoaders | Y | Y | Y | S | S | S | Y | Y | | diff --git a/include/nbl/asset/utils/IGLSLCompiler.h b/include/nbl/asset/utils/IGLSLCompiler.h index 922fa50f0e..131236b208 100644 --- a/include/nbl/asset/utils/IGLSLCompiler.h +++ b/include/nbl/asset/utils/IGLSLCompiler.h @@ -48,7 +48,7 @@ class IGLSLCompiler final : public core::IReferenceCounted bool _genDebugInfo = true, std::string* _outAssembly = nullptr, system::logger_opt_ptr logger = nullptr, - const E_SPIRV_VERSION targetSpirvVersion = ESV_1_5) const; + const E_SPIRV_VERSION targetSpirvVersion = ESV_1_6) const; /** If _stage is ESS_UNKNOWN, then compiler will try to deduce shader stage from #pragma annotation, i.e.: @@ -80,7 +80,7 @@ class IGLSLCompiler final : public core::IReferenceCounted bool _genDebugInfo = true, std::string* _outAssembly = nullptr, system::logger_opt_ptr logger = nullptr, - const E_SPIRV_VERSION targetSpirvVersion = ESV_1_5) const; + const E_SPIRV_VERSION targetSpirvVersion = ESV_1_6) const; core::smart_refctd_ptr createSPIRVFromGLSL( system::IFile* _sourcefile, @@ -91,7 +91,7 @@ class IGLSLCompiler final : public core::IReferenceCounted bool _genDebugInfo = true, std::string* _outAssembly = nullptr, system::logger_opt_ptr logger = nullptr, - const E_SPIRV_VERSION targetSpirvVersion = ESV_1_5) const; + const E_SPIRV_VERSION targetSpirvVersion = ESV_1_6) const; /** Resolves ALL #include directives regardless of any other preprocessor directive. @@ -113,7 +113,7 @@ class IGLSLCompiler final : public core::IReferenceCounted const char* _originFilepath, uint32_t _maxSelfInclusionCnt = 4u, system::logger_opt_ptr logger = nullptr, - const E_SPIRV_VERSION targetSpirvVersion = ESV_1_5) const; + const E_SPIRV_VERSION targetSpirvVersion = ESV_1_6) const; core::smart_refctd_ptr resolveIncludeDirectives( system::IFile* _sourcefile, @@ -121,7 +121,7 @@ class IGLSLCompiler final : public core::IReferenceCounted const char* _originFilepath, uint32_t _maxSelfInclusionCnt = 4u, system::logger_opt_ptr logger = nullptr, - const E_SPIRV_VERSION targetSpirvVersion = ESV_1_5) const; + const E_SPIRV_VERSION targetSpirvVersion = ESV_1_6) const; /* Creates a formatted copy of the original diff --git a/src/nbl/video/CVulkanPhysicalDevice.h b/src/nbl/video/CVulkanPhysicalDevice.h index 504595c680..7fa7e501b2 100644 --- a/src/nbl/video/CVulkanPhysicalDevice.h +++ b/src/nbl/video/CVulkanPhysicalDevice.h @@ -106,7 +106,7 @@ class CVulkanPhysicalDevice final : public IPhysicalDevice m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_5; break; case 3: - m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_5; // TODO: change this to spirv 1.6 + m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_6; break; default: _NBL_DEBUG_BREAK_IF("Invalid Vulkan minor version!"); diff --git a/src/nbl/video/IOpenGL_PhysicalDeviceBase.h b/src/nbl/video/IOpenGL_PhysicalDeviceBase.h index ee588cb945..0e22d06068 100755 --- a/src/nbl/video/IOpenGL_PhysicalDeviceBase.h +++ b/src/nbl/video/IOpenGL_PhysicalDeviceBase.h @@ -493,7 +493,7 @@ class IOpenGL_PhysicalDeviceBase : public IOpenGLPhysicalDeviceBase m_limits.nonCoherentAtomSize = 256ull; - m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_5; + m_limits.spirvVersion = asset::IGLSLCompiler::ESV_1_6; if (m_glfeatures.isFeatureAvailable(COpenGLFeatureMap::NBL_KHR_shader_subgroup)) { From a5ab3856738f8064bae928892099186b58572178 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 1 Mar 2022 17:21:20 +0100 Subject: [PATCH 36/91] Hide more platform specific implementation details. --- .../system/CFileViewVirtualAllocatorPOSIX.h | 27 +++++----- .../system/CFileViewVirtualAllocatorWin32.h | 25 ++++------ include/nbl/system/CStdoutLoggerAndroid.h | 49 +++---------------- src/nbl/CMakeLists.txt | 3 ++ .../system/CFileViewVirtualAllocatorPOSIX.cpp | 17 +++++++ .../system/CFileViewVirtualAllocatorWin32.cpp | 16 ++++++ src/nbl/system/CStdoutLoggerAndroid.cpp | 34 +++++++++++++ 7 files changed, 99 insertions(+), 72 deletions(-) create mode 100644 src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp create mode 100644 src/nbl/system/CFileViewVirtualAllocatorWin32.cpp create mode 100644 src/nbl/system/CStdoutLoggerAndroid.cpp diff --git a/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h b/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h index 51dc943d14..ec17a11a31 100644 --- a/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h +++ b/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h @@ -1,26 +1,21 @@ -#ifndef __NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_POSIX_H_INCLUDED__ -#define __NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_POSIX_H_INCLUDED__ -#include "IFileViewAllocator.h" -#include +#ifndef _NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_POSIX_H_INCLUDED_ +#define _NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_POSIX_H_INCLUDED_ -#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) +#include "nbl/system/IFileViewAllocator.h" + + +#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) namespace nbl::system { + class CFileViewVirtualAllocatorPOSIX : public IFileViewAllocator { -public: - void* alloc(size_t size) override - { - return mmap((caddr_t)0, size, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - } - bool dealloc(void* data, size_t size) override - { - auto ret = munmap(data, size); - return ret != -1; - } + public: + void* alloc(size_t size) override; + bool dealloc(void* data, size_t size) override; }; -} +} #endif #endif \ No newline at end of file diff --git a/include/nbl/system/CFileViewVirtualAllocatorWin32.h b/include/nbl/system/CFileViewVirtualAllocatorWin32.h index 4d63d57579..9478570db2 100644 --- a/include/nbl/system/CFileViewVirtualAllocatorWin32.h +++ b/include/nbl/system/CFileViewVirtualAllocatorWin32.h @@ -1,25 +1,20 @@ -#ifndef __NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_WIN32_H_INCLUDED__ -#define __NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_WIN32_H_INCLUDED__ -#include "IFileViewAllocator.h" +#ifndef _NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_WIN32_H_INCLUDED_ +#define _NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_WIN32_H_INCLUDED_ + + +#include "nbl/system/IFileViewAllocator.h" -#ifdef _NBL_PLATFORM_WINDOWS_ -#include "Windows.h" namespace nbl::system { +#ifdef _NBL_PLATFORM_WINDOWS_ class CFileViewVirtualAllocatorWin32 : public IFileViewAllocator { -public: - void* alloc(size_t size) override - { - return VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); - } - bool dealloc(void* data, size_t size) override - { - return VirtualFree(data, 0, MEM_RELEASE); - } + public: + void* alloc(size_t size) override; + bool dealloc(void* data, size_t size) override; }; +#endif } -#endif #endif \ No newline at end of file diff --git a/include/nbl/system/CStdoutLoggerAndroid.h b/include/nbl/system/CStdoutLoggerAndroid.h index ecc35814b1..4590b644a9 100644 --- a/include/nbl/system/CStdoutLoggerAndroid.h +++ b/include/nbl/system/CStdoutLoggerAndroid.h @@ -1,54 +1,21 @@ #ifndef _NBL_SYSTEM_C_STDOUT_LOGGER_ANDROID_H_INCLUDED_ #define _NBL_SYSTEM_C_STDOUT_LOGGER_ANDROID_H_INCLUDED_ -#ifdef _NBL_PLATFORM_ANDROID_ -#include "nbl/system/IThreadsafeLogger.h" -#include +#include "nbl/system/IThreadsafeLogger.h" +#ifdef _NBL_PLATFORM_ANDROID_ namespace nbl::system { - class CStdoutLoggerAndroid : public IThreadsafeLogger - { + +class CStdoutLoggerAndroid : public IThreadsafeLogger +{ public: CStdoutLoggerAndroid(core::bitflag logLevelMask = ILogger::defaultLogMask()) : IThreadsafeLogger(logLevelMask) {} private: - auto getNativeLogLevel(E_LOG_LEVEL logLevel) - { - switch (logLevel) - { - case ELL_DEBUG: - { - return ANDROID_LOG_DEBUG; - } - case ELL_INFO: - { - return ANDROID_LOG_INFO; - } - case ELL_WARNING: - { - return ANDROID_LOG_WARN; - } - case ELL_ERROR: - { - return ANDROID_LOG_ERROR; - } - case ELL_PERFORMANCE: - { - return ANDROID_LOG_INFO; - } - default: - { - assert(false); - return ANDROID_LOG_UNKNOWN; - } - } - } - void threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override - { - (void)__android_log_print(getNativeLogLevel(logLevel), "Nabla Engine", "%s", constructLogString(fmt, logLevel, args).c_str()); - } - }; + void threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override; +}; + } #endif diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index f757aea3fc..20e33d260c 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -196,6 +196,9 @@ set(NBL_SYSTEM_SOURCES ${NBL_ROOT_PATH}/src/nbl/system/CArchiveLoaderTar.cpp ${NBL_ROOT_PATH}/src/nbl/system/ISystem.cpp ${NBL_ROOT_PATH}/src/nbl/system/IFileArchive.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CStdoutLoggerAndroid.cpp ) set(NBL_UI_SOURCES ${NBL_ROOT_PATH}/src/nbl/ui/CWindowWin32.cpp diff --git a/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp b/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp new file mode 100644 index 0000000000..3fe17e81f4 --- /dev/null +++ b/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp @@ -0,0 +1,17 @@ +#include "nbl/system/CFileViewVirtualAllocatorPOSIX.h" + +using namespace nbl::system; + +#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) +#include + +void* CFileViewVirtualAllocatorPOSIX::alloc(size_t size) override +{ + return mmap((caddr_t)0, size, PROT_WRITE|PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); +} +bool CFileViewVirtualAllocatorPOSIX::dealloc(void* data, size_t size) override +{ + const auto ret = munmap(data,size); + return ret != -1; +} +#endif \ No newline at end of file diff --git a/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp b/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp new file mode 100644 index 0000000000..f480ef6ddb --- /dev/null +++ b/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp @@ -0,0 +1,16 @@ +#include "nbl/system/CFileViewVirtualAllocatorWin32.h" + +using namespace nbl::system; + +#ifdef _NBL_PLATFORM_WINDOWS_ +#include "Windows.h" + +void* CFileViewVirtualAllocatorWin32::alloc(size_t size) +{ + return VirtualAlloc(nullptr, size, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); // TODO: are these even the right flags? Do we want to commit everything right away? +} +bool CFileViewVirtualAllocatorWin32::dealloc(void* data, size_t size) +{ + return VirtualFree(data, 0, MEM_RELEASE); +} +#endif \ No newline at end of file diff --git a/src/nbl/system/CStdoutLoggerAndroid.cpp b/src/nbl/system/CStdoutLoggerAndroid.cpp new file mode 100644 index 0000000000..65c7e21969 --- /dev/null +++ b/src/nbl/system/CStdoutLoggerAndroid.cpp @@ -0,0 +1,34 @@ +#include "nbl/system/CStdoutLoggerAndroid.h" + +#ifdef _NBL_PLATFORM_ANDROID_ +#include + +using namespace nbl::system; + +void CStdoutLoggerAndroid::threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override +{ + auto nativeLogLevel = ANDROID_LOG_UNKNOWN; + switch (logLevel) + { + case ELL_DEBUG: + nativeLogLevel = ANDROID_LOG_DEBUG; + break; + case ELL_INFO: + nativeLogLevel = ANDROID_LOG_INFO; + break; + case ELL_WARNING: + nativeLogLevel = ANDROID_LOG_WARN; + break; + case ELL_ERROR: + nativeLogLevel = ANDROID_LOG_ERROR; + break; + case ELL_PERFORMANCE: + nativeLogLevel = ANDROID_LOG_INFO; + break; + default: + assert(false); + break; + } + (void)__android_log_print(nativeLogLevel, "Nabla Engine: ", "%s", constructLogString(fmt,logLevel,args).c_str()); +} +#endif \ No newline at end of file From 63df7c618ec044552a37d075f378c8f8dfa9ba64 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 1 Mar 2022 18:49:15 +0100 Subject: [PATCH 37/91] save progress for the day --- include/nbl/system/CFileLogger.h | 37 ++-- include/nbl/system/CFileView.h | 183 ++++++++++--------- include/nbl/system/IFile.h | 38 +++- include/nbl/system/IFileArchive.h | 22 +-- include/nbl/system/IFileViewAllocator.h | 46 +++-- include/nbl/system/ISystem.h | 223 +++++++---------------- src/nbl/system/CArchiveLoaderZip.cpp | 2 +- {include => src}/nbl/system/CFilePOSIX.h | 0 {include => src}/nbl/system/CFileWin32.h | 0 src/nbl/system/ISystem.cpp | 155 +++++++++++++++- 10 files changed, 399 insertions(+), 307 deletions(-) rename {include => src}/nbl/system/CFilePOSIX.h (100%) rename {include => src}/nbl/system/CFileWin32.h (100%) diff --git a/include/nbl/system/CFileLogger.h b/include/nbl/system/CFileLogger.h index e290173d81..95c8c0696d 100644 --- a/include/nbl/system/CFileLogger.h +++ b/include/nbl/system/CFileLogger.h @@ -8,28 +8,29 @@ namespace nbl::system { + class CFileLogger : public IThreadsafeLogger { -public: - static core::smart_refctd_ptr create(const std::filesystem::path& outputFileName) - { - auto ret = core::smart_refctd_ptr(new CFileLogger(outputFileName)); - if (!ret->m_ofs.is_open()) return nullptr; - return ret; - } - ~CFileLogger() - { - } -private: - std::ofstream m_ofs; - CFileLogger(const std::filesystem::path& outputFileName, core::bitflag logLevelMask = ILogger::defaultLogMask()) : IThreadsafeLogger(logLevelMask), m_ofs(outputFileName, std::ios_base::app){} + public: + static core::smart_refctd_ptr create(const std::filesystem::path& outputFileName) + { + auto ret = core::smart_refctd_ptr(new CFileLogger(outputFileName)); + if (!ret->m_ofs.is_open()) return nullptr; + return ret; + } + ~CFileLogger() + { + } + private: + std::ofstream m_ofs; + CFileLogger(const std::filesystem::path& outputFileName, core::bitflag logLevelMask = ILogger::defaultLogMask()) : IThreadsafeLogger(logLevelMask), m_ofs(outputFileName, std::ios_base::app){} - virtual void threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override - { - m_ofs << constructLogString(fmt, logLevel, args).data() << std::flush; - } - + virtual void threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override + { + m_ofs << constructLogString(fmt, logLevel, args).data() << std::flush; + } }; + } #endif \ No newline at end of file diff --git a/include/nbl/system/CFileView.h b/include/nbl/system/CFileView.h index d7014b6f2e..4cae942a62 100644 --- a/include/nbl/system/CFileView.h +++ b/include/nbl/system/CFileView.h @@ -1,111 +1,118 @@ -#ifndef C_MEMORY_FILE_H -#define C_MEMORY_FILE_H +#ifndef _NBL_SYSTEM_C_FILE_VIEW_H_ +#define _NBL_SYSTEM_C_FILE_VIEW_H_ + + #include -//#include + namespace nbl::system { + +class IFileView : public IFile +{ + public: + size_t getSize() const override final + { + return m_size; + } + + protected: + // TODO: do we even need to keep a smartpointer back to the ISystem!? + IFileView(core::smart_refctd_ptr&& sys, const path& _name, const core::bitflag _flags, void* buffer, size_t fileSize) : + IFile(std::move(sys),_name,_flags|ECF_COHERENT), m_buffer((std::byte*)buffer), m_size(fileSize) + { + } + + size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) override final + { + if (offset+sizeToRead > m_size) + sizeToRead = m_size-offset; + memcpy(buffer, m_buffer+offset, sizeToRead); + return sizeToRead; + } + size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) override final + { + if (offset+sizeToWrite > m_size) + sizeToWrite = m_size-offset; + memcpy(m_buffer+offset, buffer, sizeToWrite); + return sizeToWrite; + } + + const void* getMappedPointer_impl() const override final + { + return m_buffer; + } + void* getMappedPointer_impl() override final + { + return m_buffer; + } + + private: + std::byte* m_buffer; + size_t m_size; +}; + template -class CFileView : public IFile +class CFileView : public IFileView { - // Need this friend to write to a fileView in ISystem::loadBuiltinData cause ISystem doesnt know about sustem::future_t - friend class ISystem; - friend class CAPKResourcesArchive; -protected: - allocator_t allocator; - size_t m_size; -public: - CFileView(CFileView&& other) : IFile(std::move(other.m_system), path(other.getFileName()), other.m_flags), m_size(other.m_size), m_buffer(other.m_buffer) - { - other.m_buffer = nullptr; - } - CFileView(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, size_t fileSize) : - IFile(std::move(sys), _name, _flags | ECF_COHERENT | ECF_MAPPABLE), - m_size(fileSize) - { - m_buffer = (std::byte*)allocator.alloc(fileSize); - } - ~CFileView() - { - allocator.dealloc(m_buffer, m_size); - } - - void* getMappedPointer() override final { return m_buffer; } - const void* getMappedPointer() const override final { return m_buffer; } - - size_t getSize() const override final - { - return m_size; - } -protected: - size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) override final - { - if (offset + sizeToRead > m_size) + // what do I even need this "friend" for? + friend class CAPKResourcesArchive; + + public: +#if 0 + CFileView(CFileView&& other) : IFile(std::move(other.m_system), path(other.getFileName()), other.m_flags), m_size(other.m_size), m_buffer(other.m_buffer) + { + other.m_buffer = nullptr; + } +#endif + // constructor for making a file with memory already allocated by the allocator + CFileView(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, void* buffer, size_t fileSize, allocator_t&& _allocator) : + IFileView(std::move(sys),_name,_flags,buffer,fileSize), allocator(std::move(_allocator)) {} + + // + static inline core::smart_refctd_ptr> create(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, size_t fileSize, allocator_t&& _allocator={}) { - return 0u; + auto mem = reintepret_cast(_allocator.alloc(fileSize)); + if (!mem) + return nullptr; + auto retval = new CFileView(std::move(sys),_name,_flags,mem,fileSize,std::move(_allocator)); + return core::smart_refctd_ptr(retval,core::dont_grab); } - memcpy(buffer, m_buffer + offset, sizeToRead); - return sizeToRead; - } - size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) override final - { - if (offset + sizeToWrite > m_size) + protected: + ~CFileView() { - return 0; + if (m_buffer) + allocator.dealloc(m_buffer, m_size); } - memcpy(m_buffer + offset, buffer, sizeToWrite); - return sizeToWrite; - } -protected: - std::byte* m_buffer; + + allocator_t allocator; }; + +// Forward declare the null file allocator callback class CNullAllocator; + +// template<> -class CFileView : public IFile +class CFileView : public IFileView { - size_t m_size; -public: - CFileView(CFileView&& other) : IFile(std::move(other.m_system), path(other.getFileName()), other.m_flags), m_size(other.m_size), m_buffer(other.m_buffer) - { - other.m_buffer = nullptr; - } - CFileView(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, void* buffer, size_t fileSize) : IFile(std::move(sys), _name, _flags | ECF_COHERENT | ECF_MAPPABLE), m_size(fileSize), m_buffer((std::byte*)buffer) - { - } - ~CFileView() = default; - - void* getMappedPointer() override final { return m_buffer; } - const void* getMappedPointer() const override final { return m_buffer; } - - size_t getSize() const override final - { - return m_size; - } -protected: - size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) override final - { - if (offset + sizeToRead > m_size) + public: +#if 0 + CFileView(CFileView&& other) : + IFile(std::move(other.m_system),path(other.getFileName()),other.m_flags|ECF_COHERENT), + m_size(other.m_size), m_buffer(other.m_buffer) { - return 0u; + other.m_buffer = nullptr; } - memcpy(buffer, m_buffer + offset, sizeToRead); - return sizeToRead; - } +#endif + CFileView(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, void* buffer, size_t fileSize) : + IFileView(std::move(sys),_name,_flags,buffer,fileSize) {} - size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) override final - { - if (offset + sizeToWrite > m_size) - { - return 0; - } - memcpy(m_buffer + offset, buffer, sizeToWrite); - return sizeToWrite; - } -private: - std::byte* m_buffer; + protected: + ~CFileView() = default; }; + } #endif \ No newline at end of file diff --git a/include/nbl/system/IFile.h b/include/nbl/system/IFile.h index b9992155ab..bf6d895b6f 100644 --- a/include/nbl/system/IFile.h +++ b/include/nbl/system/IFile.h @@ -1,8 +1,9 @@ -#ifndef __NBL_I_FILE_H_INCLUDED__ -#define __NBL_I_FILE_H_INCLUDED__ +#ifndef _NBL_SYSTEM_I_FILE_H_INCLUDED_ +#define _NBL_SYSTEM_I_FILE_H_INCLUDED_ #include "nbl/core/decl/smart_refctd_ptr.h" #include "nbl/core/util/bitflag.h" + #include "nbl/system/path.h" #include @@ -22,6 +23,7 @@ class future; class IFile : public core::IReferenceCounted { + // TODO: how many of these friends do we actually need? friend class ISystemCaller; friend class ISystem; friend class IFileArchive; @@ -45,18 +47,30 @@ class IFile : public core::IReferenceCounted /** \return File name as zero terminated character string. */ inline const path& getFileName() const { return m_filename; } - E_CREATE_FLAGS getFlags() const { return m_flags.value; } + // + inline E_CREATE_FLAGS getFlags() const { return m_flags.value; } - virtual void* getMappedPointer() = 0; - virtual const void* getMappedPointer() const = 0; + // + inline const void* getMappedPointer() const + { + if (m_flags.value&ECF_READ) + return getMappedPointer_impl(); + return nullptr; + } + void* getMappedPointer() + { + if (m_flags.value&ECF_WRITE) + return getMappedPointer_impl(); + return nullptr; + } - - bool isMappingCoherent() const + // + inline bool isMappingCoherent() const { - return (m_flags & ECF_COHERENT).value == ECF_COHERENT; + return m_flags.value&ECF_COHERENT; } - // TODO: make the `ISystem` methods protected instead + // TODO: make this virtual, so the IFileView does not need to keep ref to ISystem void read(future& fut, void* buffer, size_t offset, size_t sizeToRead); void write(future& fut, const void* buffer, size_t offset, size_t sizeToWrite); @@ -94,10 +108,14 @@ class IFile : public core::IReferenceCounted static path flattenFilename(const path& p); protected: + // TODO: docs virtual size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) = 0; virtual size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) = 0; - // the ISystem is the factory, so this starys protected + virtual void* getMappedPointer_impl() = 0; + virtual const void* getMappedPointer_impl() const = 0; + + // the ISystem is the factory, so this stays protected explicit IFile(core::smart_refctd_ptr&& _system, const path& _filename, core::bitflag _flags); core::smart_refctd_ptr m_system; diff --git a/include/nbl/system/IFileArchive.h b/include/nbl/system/IFileArchive.h index 775112095e..f06363207f 100644 --- a/include/nbl/system/IFileArchive.h +++ b/include/nbl/system/IFileArchive.h @@ -3,18 +3,14 @@ // For conditions of distribution and use, see copyright notice in nabla.h // See the original file in irrlicht source for authors -#ifndef __NBL_I_FILE_ARCHIVE_H_INCLUDED__ -#define __NBL_I_FILE_ARCHIVE_H_INCLUDED__ - +#ifndef _NBL_I_FILE_ARCHIVE_H_INCLUDED_ +#define _NBL_I_FILE_ARCHIVE_H_INCLUDED_ #include "nbl/system/IFile.h" #include "nbl/system/CFileView.h" #include "nbl/system/IFileViewAllocator.h" -#include "nbl/system/CFileViewVirtualAllocatorWin32.h" -namespace nbl -{ -namespace system +namespace nbl::system { template @@ -57,8 +53,8 @@ class CInnerArchiveFile : public CFileView //! The FileArchive manages archives and provides access to files inside them. class IFileArchive : public core::IReferenceCounted { - static inline constexpr size_t SIZEOF_INNER_ARCHIVE_FILE = std::max(sizeof(CInnerArchiveFile), sizeof(CInnerArchiveFile)); - static inline constexpr size_t ALIGNOF_INNER_ARCHIVE_FILE = std::max(alignof(CInnerArchiveFile), alignof(CInnerArchiveFile)); + static inline constexpr size_t SIZEOF_INNER_ARCHIVE_FILE = std::max(sizeof(CInnerArchiveFile), sizeof(CInnerArchiveFile)); + static inline constexpr size_t ALIGNOF_INNER_ARCHIVE_FILE = std::max(alignof(CInnerArchiveFile), alignof(CInnerArchiveFile)); protected: enum E_ALLOCATOR_TYPE @@ -169,7 +165,7 @@ class IFileArchive : public core::IReferenceCounted return getFile_impl(params, index); break; case EAT_VIRTUAL_ALLOC: - return getFile_impl(params, index); + return getFile_impl(params, index); break; } assert(false); @@ -206,7 +202,9 @@ class IFileArchive : public core::IReferenceCounted } const core::vector& getArchivedFiles() const { return m_files; } + IFile* asFile() { return m_file.get(); } + const IFile* asFile() const { return m_file.get(); } protected: void setFlagsVectorSize(size_t fileCount); @@ -270,9 +268,7 @@ class IArchiveLoader : public core::IReferenceCounted virtual core::smart_refctd_ptr createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const = 0; }; - -} // end namespace system -} // end namespace nbl +} // end namespace nbl::system #endif diff --git a/include/nbl/system/IFileViewAllocator.h b/include/nbl/system/IFileViewAllocator.h index 306538c7c1..b2976c4150 100644 --- a/include/nbl/system/IFileViewAllocator.h +++ b/include/nbl/system/IFileViewAllocator.h @@ -1,20 +1,23 @@ -#ifndef __NBL_SYSTEM_I_FILE_ALLOCATOR_H_INCLUDED__ -#define __NBL_SYSTEM_I_FILE_ALLOCATOR_H_INCLUDED__ +#ifndef _NBL_SYSTEM_I_FILE_ALLOCATOR_H_INCLUDED_ +#define _NBL_SYSTEM_I_FILE_ALLOCATOR_H_INCLUDED_ #include #include namespace nbl::system { - class IFileViewAllocator - { + +// This interface class provides the callbacks for `CFileView` which creates a mapped file over some memory +class IFileViewAllocator +{ public: virtual void* alloc(size_t size) = 0; virtual bool dealloc(void* data, size_t size) = 0; - }; +}; - class CPlainHeapAllocator : public IFileViewAllocator - { +// Regular old file in RAM +class CPlainHeapAllocator : public IFileViewAllocator +{ public: void* alloc(size_t size) override { @@ -25,10 +28,12 @@ namespace nbl::system free(data); return true; } - }; +}; - class CNullAllocator : public IFileViewAllocator - { +// This allocator is useful to create an `IFile` over memory that already contains something or is owned by some other component +// e.g. memory mapped IGPUBuffer, string_view or a string, or buffers handed out by other APIs +class CNullAllocator : public IFileViewAllocator +{ public: void* alloc(size_t size) override { @@ -38,13 +43,18 @@ namespace nbl::system { return true; } - }; +}; + } - #ifdef _NBL_PLATFORM_WINDOWS_ - #include - using VirtualAllocator = nbl::system::CFileViewVirtualAllocatorWin32; - #elif defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) - #include - using VirtualAllocator = nbl::system::CFileViewVirtualAllocatorPOSIX; - #endif + +#ifdef _NBL_PLATFORM_WINDOWS_ +#include + using VirtualMemoryAllocator = nbl::system::CFileViewVirtualAllocatorWin32; +#elif defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) +#include + using VirtualMemoryAllocator = nbl::system::CFileViewVirtualAllocatorPOSIX; +#else +#error "Unsupported platform!" +#endif + #endif \ No newline at end of file diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index 3d67a665c0..75d1beee46 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -185,63 +185,48 @@ class ISystem : public core::IReferenceCounted return f; } - protected: - virtual ~ISystem() {} - - struct Loaders - { - core::vector > vector; - //! The key is file extension - core::CMultiObjectCache,std::vector> perFileExt; - - void pushToVector(core::smart_refctd_ptr&& _loader) - { - vector.push_back(std::move(_loader)); - } - void eraseFromVector(decltype(vector)::const_iterator _loaderItr) - { - vector.erase(_loaderItr); - } - } m_loaders; - - core::CMultiObjectCache> m_cachedArchiveFiles; - public: template using future_t = CAsyncQueue::future_t; + // explicit ISystem(core::smart_refctd_ptr&& caller); - uint32_t addArchiveLoader(core::smart_refctd_ptr&& loader) - { - const char** exts = loader->getAssociatedFileExtensions(); - uint32_t i = 0u; - while (const char* e = exts[i++]) - m_loaders.perFileExt.insert(e, core::smart_refctd_ptr(loader)); - m_loaders.pushToVector(std::move(loader)); - - return m_loaders.vector.size() - 1u; - } - // - bool exists(const system::path& filename, core::bitflag flags) const + core::smart_refctd_ptr loadBuiltinData(const std::string& builtinPath); + + //! Compile time resource ID + template + inline core::smart_refctd_ptr loadBuiltinData() { #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - std::pair found = nbl::builtin::get_resource_runtime(filename.string()); - if (found.first && found.second) - return true; + return impl_loadEmbeddedBuiltinData(StringUniqueType::value,nbl::builtin::get_resource()); + #else + return loadBuiltinData(StringUniqueType::value); #endif - // filename too long - if (filename.string().size() >= sizeof(SRequestParams_CREATE_FILE::filename)) - return false; - // archive file - if (flags.value&IFile::ECF_READ) - if (std::get(findFileInArchive(filename))) - return true; - // regular file - return std::filesystem::exists(filename); } + // + void addArchiveLoader(core::smart_refctd_ptr&& loader); + + // `flags` is the intended usage of the file + bool exists(const system::path& filename, core::bitflag flags) const; + + /* + Returns true if the path is writable (e.g. if p is a path inside an archive the function will return true). + The path existence is not checked. + */ + bool isPathReadOnly(const system::path& p); + + // can only perform operations on non-virtual filesystem paths + bool createDirectory(const system::path& p); + + // can only perform operations on non-virtual filesystem paths + bool deleteDirectory(const system::path& p); + + // can only perform operations on non-virtual filesystem paths + std::error_code moveFileOrDirectory(const system::path& oldPath, const system::path& newPath); + // bool createFile(future_t>& future, const std::filesystem::path& filename, core::bitflag flags) { @@ -256,55 +241,9 @@ class ISystem : public core::IReferenceCounted return true; } - - inline core::smart_refctd_ptr loadBuiltinData(const std::string& builtinPath) - { - #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - std::pair found = nbl::builtin::get_resource_runtime(builtinPath); - if (found.first && found.second) - { - auto fileView = core::make_smart_refctd_ptr>(core::smart_refctd_ptr(this), builtinPath, core::bitflag(IFile::ECF_READ) | IFile::ECF_WRITE, found.second); - fileView->write_impl(found.first, 0, found.second); - return fileView; - } - return nullptr; - #else - constexpr auto pathPrefix = "nbl/builtin/"; - auto pos = builtinPath.find(pathPrefix); - std::string path; - if (pos != std::string::npos) - path = builtinResourceDirectory + builtinPath.substr(pos + strlen(pathPrefix)); - else - path = builtinResourceDirectory + builtinPath; - - future_t> fut; - createFile(future, path.c_str(), core::bitflag(IFile::ECF_READ) :: IFile::ECF_MAPPABLE); - auto file = fut.get(); - if (file.get()) - { - return file; - } - return nullptr; - #endif - } - //! Compile time resource ID - template - inline core::smart_refctd_ptr loadBuiltinData() - { - #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - std::pair found = nbl::builtin::get_resource(); - if (found.first && found.second) - { - auto fileView = core::make_smart_refctd_ptr>(core::smart_refctd_ptr(this), StringUniqueType::value, core::bitflag(IFile::ECF_READ) | IFile::ECF_WRITE, found.second); - fileView->write_impl(found.first, 0, found.second); - return fileView; - } - return nullptr; - #else - return loadBuiltinData(StringUniqueType::value); - #endif - } - + + // Create a IFileArchive from a IFile + core::smart_refctd_ptr openFileArchive(core::smart_refctd_ptr&& file, const std::string_view& password=""); //! Warning: blocking call core::smart_refctd_ptr openFileArchive(const std::filesystem::path& filename, const std::string_view& password = "") { @@ -316,72 +255,23 @@ class ISystem : public core::IReferenceCounted if (file.get() == nullptr) return nullptr; return openFileArchive(std::move(file), password); } - core::smart_refctd_ptr openFileArchive(core::smart_refctd_ptr&& file, const std::string_view& password = "") - { - if (file->getFlags() & IFile::ECF_READ == 0) - return nullptr; - - auto ext = system::extension_wo_dot(file->getFileName()); - auto loaders = m_loaders.perFileExt.findRange(ext); - for (auto& loader : loaders) - { - auto arch = loader.second->createArchive(std::move(file), password); - if (arch.get() == nullptr) continue; - return arch; - } - return nullptr; - } - - void mount(core::smart_refctd_ptr&& archive, const system::path& pathAlias = "") - { - auto path = archive->asFile()->getFileName(); - m_cachedArchiveFiles.insert(path, std::move(archive)); - if (!pathAlias.empty()) - { - m_cachedArchiveFiles.insert(pathAlias, std::move(archive)); - } - } - void unmount(const IFileArchive* archive, const system::path& pathAlias) - { - assert(false); // TODO(dan): i swear i'll get to it at some point - } - - /* - Returns true if the path is writable (e.g. if p is a path inside an archive the function will return true). - The path existence is not checked. - */ - bool isPathReadOnly(const system::path& p) - { - auto curPath = p; - while (!curPath.empty() && curPath.parent_path() != curPath) - { - auto archives = m_cachedArchiveFiles.findRange(curPath); - if (!archives.empty()) return true; - - curPath = curPath.parent_path().generic_string(); - } - return false; - } - bool createDirectory(const system::path& p) + inline void mount(core::smart_refctd_ptr&& archive, const system::path& pathAlias="") { - return std::filesystem::create_directories(p); + if (pathAlias.empty()) + m_cachedArchiveFiles.insert(archive->asFile()->getFileName(),std::move(archive)); + else + m_cachedArchiveFiles.insert(pathAlias,std::move(archive)); } - - bool deleteDirectory(const system::path& p) + void unmount(const IFileArchive* archive, const system::path& pathAlias="") { - if (std::filesystem::exists(p)) - return std::filesystem::remove_all(p); + auto dummy = reinterpret_cast&>(archive); + if (pathAlias.empty()) + m_cachedArchiveFiles.removeObject(dummy,archive->asFile()->getFileName()); else - return false; + m_cachedArchiveFiles.removeObject(dummy,pathAlias); } - bool moveFileOrDirectory(const system::path oldPath, const system::path newPath) - { - std::error_code ec; - std::filesystem::rename(oldPath, newPath, ec); - return static_cast(ec); - } /* Recursively lists all files and directories in the directory. */ @@ -533,6 +423,33 @@ class ISystem : public core::IReferenceCounted std::string OSFullName; }; virtual SystemInfo getSystemInfo() const = 0; + + + protected: + virtual ~ISystem() {} + + // + core::smart_refctd_ptr impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found); + + + // + struct Loaders + { + core::vector > vector; + //! The key is file extension + core::CMultiObjectCache,std::vector> perFileExt; + + void pushToVector(core::smart_refctd_ptr&& _loader) + { + vector.push_back(std::move(_loader)); + } + void eraseFromVector(decltype(vector)::const_iterator _loaderItr) + { + vector.erase(_loaderItr); + } + } m_loaders; + // + core::CMultiObjectCache> m_cachedArchiveFiles; }; template diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index 72bd1d1550..e9a8f37380 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -382,7 +382,7 @@ namespace nbl::system delete[] decryptedBuf; return 0; } - decrypted = core::make_smart_refctd_ptr>(core::smart_refctd_ptr(m_system), found->fullName, IFile::ECF_READ_WRITE, decryptedSize);//new io::CMemoryReadFile(decryptedBuf, decryptedSize, found->FullName); + decrypted = core::make_smart_refctd_ptr>(core::smart_refctd_ptr(m_system), found->fullName, IFile::ECF_READ_WRITE, decryptedSize); { write_blocking(decrypted.get(), decryptedBuf, 0, decryptedSize); diff --git a/include/nbl/system/CFilePOSIX.h b/src/nbl/system/CFilePOSIX.h similarity index 100% rename from include/nbl/system/CFilePOSIX.h rename to src/nbl/system/CFilePOSIX.h diff --git a/include/nbl/system/CFileWin32.h b/src/nbl/system/CFileWin32.h similarity index 100% rename from include/nbl/system/CFileWin32.h rename to src/nbl/system/CFileWin32.h diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index faea0cf42c..3b9f97f792 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -7,6 +7,155 @@ using namespace nbl; using namespace nbl::system; +ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatcher(this, std::move(caller)) +{ + addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); + addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); +} + +core::smart_refctd_ptr ISystem::loadBuiltinData(const std::string& builtinPath) +{ +#ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + return impl_loadEmbeddedBuiltinData(builtinPath,nbl::builtin::get_resource_runtime(builtinPath)); +#else + constexpr auto pathPrefix = "nbl/builtin/"; + auto pos = builtinPath.find(pathPrefix); + std::string path; + if (pos != std::string::npos) + path = builtinResourceDirectory + builtinPath.substr(pos + strlen(pathPrefix)); + else + path = builtinResourceDirectory + builtinPath; + + future_t> fut; + createFile(future, path.c_str(), core::bitflag(IFile::ECF_READ) :: IFile::ECF_MAPPABLE); + auto file = fut.get(); + if (file.get()) + { + return file; + } + return nullptr; +#endif +} + +core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) +{ +#ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + if (found.first && found.second) + { + auto fileView = core::make_smart_refctd_ptr>( + core::smart_refctd_ptr(this), + builtinPath, + IFile::ECF_READ, + found.first, + found.second + ); + return fileView; + } +#endif + return nullptr; +} + +void ISystem::addArchiveLoader(core::smart_refctd_ptr&& loader) +{ + const char** exts = loader->getAssociatedFileExtensions(); + uint32_t i = 0u; + while (const char* e = exts[i++]) + m_loaders.perFileExt.insert(e, core::smart_refctd_ptr(loader)); + m_loaders.pushToVector(std::move(loader)); +} + +bool ISystem::exists(const system::path& filename, core::bitflag flags) const +{ + const bool writeUsage = flags.value&IFile::ECF_WRITE; +#ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + std::pair found = nbl::builtin::get_resource_runtime(filename.string()); + if (!writeUsage && found.first && found.second) + return true; +#endif + // filename too long + if (filename.string().size() >= sizeof(SRequestParams_CREATE_FILE::filename)) + return false; + // archive file + if (!writeUsage && std::get(findFileInArchive(filename))) + return true; + // regular file + return std::filesystem::exists(filename); +} + +/* + Returns true if the path is writable (e.g. if p is a path inside an archive the function will return true). + The path existence is not checked. +*/ +bool ISystem::isPathReadOnly(const system::path& p) +{ + // check all parent subpaths + auto curPath = p; + while (!curPath.empty() && curPath.parent_path() != curPath) + { + // first check if its a builtin path + #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + std::pair found = nbl::builtin::get_resource_runtime(curPath.string()); + if (found.first && found.second) + return true; + #endif + + // then check for presence in an archive + auto archives = m_cachedArchiveFiles.findRange(curPath); + if (!archives.empty()) + return true; + + curPath = curPath.parent_path().generic_string(); + } + + return false; +} + +bool ISystem::createDirectory(const system::path& p) +{ + return std::filesystem::create_directories(p); +} + +bool ISystem::deleteDirectory(const system::path& p) +{ + if (std::filesystem::exists(p)) + return std::filesystem::remove_all(p); + else + return false; +} + +std::error_code ISystem::moveFileOrDirectory(const system::path& oldPath, const system::path& newPath) +{ + std::error_code ec; + std::filesystem::rename(oldPath,newPath,ec); + return ec; +} + +core::smart_refctd_ptr ISystem::openFileArchive(core::smart_refctd_ptr&& file, const std::string_view& password) +{ + // the file backing the archive needs to be readable + if (file->getFlags()&IFile::ECF_READ == 0) + return nullptr; + + // try the archive loaders by using the extension first + auto ext = system::extension_wo_dot(file->getFileName()); + auto loaders = m_loaders.perFileExt.findRange(ext); + for (auto& loader : loaders) + { + auto arch = loader.second->createArchive(std::move(file),password); + if (arch) + return arch; + } + // try again, without regard for extension + for (auto& loader : m_loaders.vector) + { + auto arch = loader->createArchive(std::move(file),password); + if (arch) + return arch; + } + return nullptr; +} + + core::smart_refctd_ptr ISystemCaller::createFile(core::smart_refctd_ptr&& sys, const std::filesystem::path& filename, core::bitflag flags) { if (flags.value & IFile::ECF_READ) @@ -22,12 +171,6 @@ core::smart_refctd_ptr ISystemCaller::createFile(core::smart_refctd_ptr&& caller) : m_dispatcher(this, std::move(caller)) -{ - addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); - addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); -} - std::pair ISystem::findFileInArchive(const system::path& _path) const { system::path path = std::filesystem::exists(_path) ? system::path(std::filesystem::canonical(_path.parent_path()).generic_string()) : _path.parent_path(); From effe914646eae9ea41e546a4189e27de62178419 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 2 Mar 2022 18:12:03 +0100 Subject: [PATCH 38/91] fix up file view --- include/nbl/system/CFileView.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/include/nbl/system/CFileView.h b/include/nbl/system/CFileView.h index 4cae942a62..b9e28490eb 100644 --- a/include/nbl/system/CFileView.h +++ b/include/nbl/system/CFileView.h @@ -17,6 +17,10 @@ class IFileView : public IFile } protected: + IFileView(IFileView&& other) : IFile(std::move(other.m_system),other.getFileName(),other.m_flags), m_buffer(other.m_buffer), m_size(other.m_size) + { + other.m_buffer = nullptr; + } // TODO: do we even need to keep a smartpointer back to the ISystem!? IFileView(core::smart_refctd_ptr&& sys, const path& _name, const core::bitflag _flags, void* buffer, size_t fileSize) : IFile(std::move(sys),_name,_flags|ECF_COHERENT), m_buffer((std::byte*)buffer), m_size(fileSize) @@ -47,7 +51,7 @@ class IFileView : public IFile return m_buffer; } - private: + // std::byte* m_buffer; size_t m_size; }; @@ -59,12 +63,6 @@ class CFileView : public IFileView friend class CAPKResourcesArchive; public: -#if 0 - CFileView(CFileView&& other) : IFile(std::move(other.m_system), path(other.getFileName()), other.m_flags), m_size(other.m_size), m_buffer(other.m_buffer) - { - other.m_buffer = nullptr; - } -#endif // constructor for making a file with memory already allocated by the allocator CFileView(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, void* buffer, size_t fileSize, allocator_t&& _allocator) : IFileView(std::move(sys),_name,_flags,buffer,fileSize), allocator(std::move(_allocator)) {} @@ -80,6 +78,7 @@ class CFileView : public IFileView } protected: + CFileView(CFileView&& other) : IFileView(std::move(other)), allocator(std::move(other.allocator)) {} ~CFileView() { if (m_buffer) @@ -98,18 +97,11 @@ template<> class CFileView : public IFileView { public: -#if 0 - CFileView(CFileView&& other) : - IFile(std::move(other.m_system),path(other.getFileName()),other.m_flags|ECF_COHERENT), - m_size(other.m_size), m_buffer(other.m_buffer) - { - other.m_buffer = nullptr; - } -#endif CFileView(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, void* buffer, size_t fileSize) : IFileView(std::move(sys),_name,_flags,buffer,fileSize) {} protected: + CFileView(CFileView&& other) : IFileView(std::move(other)) {} ~CFileView() = default; }; From 94372ef6930bde2aef0f1d2e565262dc6367e12d Mon Sep 17 00:00:00 2001 From: devsh Date: Thu, 3 Mar 2022 13:37:51 +0100 Subject: [PATCH 39/91] welcome to new API land --- examples_tests/01.HelloWorld/main.cpp | 6 +- include/nbl/asset/IAssetManager.h | 15 +- include/nbl/asset/utils/CDirQuantCacheBase.h | 33 +- include/nbl/core/util/bitflag.h | 11 +- include/nbl/system/CFileView.h | 19 +- include/nbl/system/CSystemCallerPOSIX.h | 22 - include/nbl/system/CSystemWin32.h | 58 +-- .../system/ICancellableAsyncQueueDispatcher.h | 1 + include/nbl/system/IFile.h | 101 +---- include/nbl/system/IFileArchive.h | 360 ++++++++-------- include/nbl/system/IFileBase.h | 77 ++++ include/nbl/system/ISystem.h | 408 +++++------------- include/nbl/system/ISystemFile.h | 86 ++++ src/nbl/CMakeLists.txt | 3 +- .../asset/interchange/COBJMeshFileLoader.h | 21 +- src/nbl/asset/interchange/CPLYMeshWriter.h | 2 +- src/nbl/asset/utils/CFilesystemIncluder.h | 69 +-- src/nbl/system/CArchiveLoaderZip.cpp | 4 +- src/nbl/system/CFilePOSIX.cpp | 152 ++----- src/nbl/system/CFilePOSIX.h | 57 +-- src/nbl/system/CFileWin32.cpp | 157 ++----- src/nbl/system/CFileWin32.h | 50 +-- src/nbl/system/CSystemCallerPOSIX.cpp | 76 ++++ src/nbl/system/CSystemCallerPOSIX.h | 22 + src/nbl/system/CSystemWin32.cpp | 103 +++++ src/nbl/system/{IFile.cpp => IFileBase.cpp} | 23 +- src/nbl/system/ISystem.cpp | 265 +++++++++++- src/nbl/system/ISystemFile.cpp | 10 + 28 files changed, 1139 insertions(+), 1072 deletions(-) delete mode 100644 include/nbl/system/CSystemCallerPOSIX.h create mode 100644 include/nbl/system/IFileBase.h create mode 100644 include/nbl/system/ISystemFile.h create mode 100644 src/nbl/system/CSystemCallerPOSIX.cpp create mode 100644 src/nbl/system/CSystemCallerPOSIX.h create mode 100644 src/nbl/system/CSystemWin32.cpp rename src/nbl/system/{IFile.cpp => IFileBase.cpp} (67%) create mode 100644 src/nbl/system/ISystemFile.cpp diff --git a/examples_tests/01.HelloWorld/main.cpp b/examples_tests/01.HelloWorld/main.cpp index 3af8edacf5..9e99711b7d 100644 --- a/examples_tests/01.HelloWorld/main.cpp +++ b/examples_tests/01.HelloWorld/main.cpp @@ -103,12 +103,8 @@ class DemoEventCallback : public ui::IWindow::IEventCallback static core::smart_refctd_ptr createSystem() { - nbl::core::smart_refctd_ptr caller = nullptr; #ifdef _NBL_PLATFORM_WINDOWS_ - caller = nbl::core::make_smart_refctd_ptr(); -#endif -#ifdef _NBL_PLATFORM_WINDOWS_ - return nbl::core::make_smart_refctd_ptr(std::move(caller)); + return nbl::core::make_smart_refctd_ptr(); #endif return nullptr; } diff --git a/include/nbl/asset/IAssetManager.h b/include/nbl/asset/IAssetManager.h index 68dce1c8a6..823a4e297a 100644 --- a/include/nbl/asset/IAssetManager.h +++ b/include/nbl/asset/IAssetManager.h @@ -326,14 +326,12 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin _override->getLoadFilename(filePath, m_system.get(), ctx, _hierarchyLevel); system::ISystem::future_t> future; - bool validInput = m_system->createFile(future, filePath, system::IFile::ECF_READ); - if (!validInput) + m_system->createFile(future, filePath, system::IFile::ECF_READ); + auto file = future.get(); + if (!file) return SAssetBundle(0); - core::smart_refctd_ptr file = future.get(); - SAssetBundle asset = getAssetInHierarchy_impl(file.get(), filePath.string(), ctx.params, _hierarchyLevel, _override); - - return asset; + return getAssetInHierarchy_impl(file.get(), filePath.string(), ctx.params, _hierarchyLevel, _override); } //TODO change name @@ -647,10 +645,9 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin if (!_override) _override = &defOverride; - core::smart_refctd_ptr file; system::ISystem::future_t> future; - bool valid = m_system->createFile(future, (_params.workingDirectory.generic_string() + _filename).c_str(), system::IFile::ECF_WRITE); - if (valid) file = future.get(); + m_system->createFile(future, (_params.workingDirectory.generic_string() + _filename).c_str(), system::IFile::ECF_WRITE); + auto file = future.get(); if (file) // could fail creating file (lack of permissions) { bool res = writeAsset(file.get(), _params, _override); diff --git a/include/nbl/asset/utils/CDirQuantCacheBase.h b/include/nbl/asset/utils/CDirQuantCacheBase.h index 2cccd9cbd1..c0752f996d 100644 --- a/include/nbl/asset/utils/CDirQuantCacheBase.h +++ b/include/nbl/asset/utils/CDirQuantCacheBase.h @@ -298,10 +298,11 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase return false; auto buffer = core::make_smart_refctd_ptr(file->getSize()); - system::future future; - file->read(future, buffer->getPointer(), 0, file->getSize()); - future.get(); + system::IFile::success_t succ; + file->read(succ, buffer->getPointer(), 0, file->getSize()); + if (!succ) + return false; asset::SBufferRange bufferRange; bufferRange.offset = 0; @@ -315,12 +316,11 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase inline bool loadCacheFromFile(nbl::system::ISystem* system, const system::path& path, bool replaceCurrentContents = false) { system::ISystem::future_t> future; - bool validInput = system->createFile(future,path,nbl::system::IFile::ECF_READ); - - if (!validInput) + system->createFile(future,path,nbl::system::IFile::ECF_READ); + auto file = future.get(); + if (!file) return false; - core::smart_refctd_ptr file = future.get(); return loadCacheFromFile(file.get(),replaceCurrentContents); } @@ -340,7 +340,7 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase //! template - inline bool saveCacheToFile(system::IFile* file) + inline system::IFile::success_t saveCacheToFile(system::IFile* file) { if (!file) return false; @@ -352,24 +352,21 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase saveCacheToBuffer(bufferRange); - system::future future; - file->write(future, bufferRange.buffer->getPointer(), 0, bufferRange.buffer->getSize()); - future.get(); // NOTE: should it wait? - - return true; + system::IFile::success_t succ; + file->write(succ,bufferRange.buffer->getPointer(), 0, bufferRange.buffer->getSize()); + return succ; } //! template - inline bool saveCacheToFile(nbl::system::ISystem* system, const system::path& path) + inline system::IFile::success_t saveCacheToFile(nbl::system::ISystem* system, const system::path& path) { system::ISystem::future_t> future; - bool validInput = system->createFile(future, path, nbl::system::IFile::ECF_WRITE); - - if (!validInput) + system->createFile(future, path, nbl::system::IFile::ECF_WRITE); + auto file = future.get(); + if (!file) return false; - core::smart_refctd_ptr file = future.get(); return saveCacheToFile(file.get()); } diff --git a/include/nbl/core/util/bitflag.h b/include/nbl/core/util/bitflag.h index c35b211bfc..a11f6e5078 100644 --- a/include/nbl/core/util/bitflag.h +++ b/include/nbl/core/util/bitflag.h @@ -2,12 +2,10 @@ // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h -#ifndef __NBL_CORE_C_BITFLAG_H_INCLUDED__ -#define __NBL_CORE_C_BITFLAG_H_INCLUDED__ +#ifndef _NBL_CORE_C_BITFLAG_H_INCLUDED_ +#define _NBL_CORE_C_BITFLAG_H_INCLUDED_ -namespace nbl -{ -namespace core +namespace nbl::core { template @@ -18,7 +16,7 @@ struct bitflag final ENUM_TYPE value = static_cast(0); bitflag() = default; - bitflag(ENUM_TYPE value) : value(value) {} + bitflag(const ENUM_TYPE value) : value(value) {} inline bitflag operator~() { return static_cast(~value); } inline bitflag operator|(bitflag rhs) const { return static_cast(value | rhs.value); } @@ -30,7 +28,6 @@ struct bitflag final inline bool hasValue(bitflag val) const { return (value & val.value) != 0; } }; -} } #endif \ No newline at end of file diff --git a/include/nbl/system/CFileView.h b/include/nbl/system/CFileView.h index b9e28490eb..ea08c67d31 100644 --- a/include/nbl/system/CFileView.h +++ b/include/nbl/system/CFileView.h @@ -2,13 +2,13 @@ #define _NBL_SYSTEM_C_FILE_VIEW_H_ -#include +#include "nbl/system/IFile.h" namespace nbl::system { -class IFileView : public IFile +class IFileView : public IFile, private ISystem::IFutureManipulator { public: size_t getSize() const override final @@ -17,29 +17,28 @@ class IFileView : public IFile } protected: - IFileView(IFileView&& other) : IFile(std::move(other.m_system),other.getFileName(),other.m_flags), m_buffer(other.m_buffer), m_size(other.m_size) + IFileView(IFileView&& other) : IFile(other.getFileName(),other.getFlags()), m_buffer(other.m_buffer), m_size(other.m_size) { other.m_buffer = nullptr; } - // TODO: do we even need to keep a smartpointer back to the ISystem!? - IFileView(core::smart_refctd_ptr&& sys, const path& _name, const core::bitflag _flags, void* buffer, size_t fileSize) : - IFile(std::move(sys),_name,_flags|ECF_COHERENT), m_buffer((std::byte*)buffer), m_size(fileSize) + IFileView(const path& _name, const core::bitflag _flags, void* buffer, size_t fileSize) : + IFile(_name,_flags|ECF_COHERENT), m_buffer((std::byte*)buffer), m_size(fileSize) { } - size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) override final + inline void read(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) override final { if (offset+sizeToRead > m_size) sizeToRead = m_size-offset; memcpy(buffer, m_buffer+offset, sizeToRead); - return sizeToRead; + fake_notify(fut,sizeToRead); } - size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) override final + inline void write(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) override final { if (offset+sizeToWrite > m_size) sizeToWrite = m_size-offset; memcpy(m_buffer+offset, buffer, sizeToWrite); - return sizeToWrite; + fake_notify(fut,sizeToWrite); } const void* getMappedPointer_impl() const override final diff --git a/include/nbl/system/CSystemCallerPOSIX.h b/include/nbl/system/CSystemCallerPOSIX.h deleted file mode 100644 index 782c4753b8..0000000000 --- a/include/nbl/system/CSystemCallerPOSIX.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_ -#define _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_ - -#if defined(__unix__) -#include "nbl/system/CFilePOSIX.h" -namespace nbl::system -{ - class CSystemCallerPOSIX final : public ISystemCaller - { - protected: - ~CSystemCallerPOSIX() override = default; - - public: - core::smart_refctd_ptr createFile_impl(core::smart_refctd_ptr&& sys, const std::filesystem::path& filename, core::bitflag flags) override final - { - auto f = core::make_smart_refctd_ptr(std::move(sys), filename, flags); - return f->isOpenedProperly() ? f : nullptr; - } - }; -} -#endif -#endif // ! _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_ diff --git a/include/nbl/system/CSystemWin32.h b/include/nbl/system/CSystemWin32.h index 0576c8f6cb..0f1eb20b46 100644 --- a/include/nbl/system/CSystemWin32.h +++ b/include/nbl/system/CSystemWin32.h @@ -1,58 +1,30 @@ -#ifndef _NBL_SYSTEM_CSYSTEMWIN32_H_INCLUDED_ -#define _NBL_SYSTEM_CSYSTEMWIN32_H_INCLUDED_ +#ifndef _NBL_SYSTEM_C_SYSTEM_WIN32_H_INCLUDED_ +#define _NBL_SYSTEM_C_SYSTEM_WIN32_H_INCLUDED_ -#ifdef _NBL_PLATFORM_WINDOWS_ -#include -#include #include "ISystem.h" -#include "CFileWin32.h" namespace nbl::system { - -class CSystemCallerWin32 final : public ISystemCaller -{ - protected: - ~CSystemCallerWin32() override = default; - - public: - core::smart_refctd_ptr createFile_impl(core::smart_refctd_ptr&& sys, const std::filesystem::path& filename, core::bitflag flags) override final - { - auto f = core::make_smart_refctd_ptr(std::move(sys), filename, flags); - return f->isOpenedProperly() ? f : nullptr; - } -}; +#ifdef _NBL_PLATFORM_WINDOWS_ class CSystemWin32 : public ISystem { -public: - CSystemWin32(core::smart_refctd_ptr&& caller) : ISystem(std::move(caller)) {} - //LOL the struct definition wasn't added to winapi headers do they ask to declare them yourself - typedef struct _PROCESSOR_POWER_INFORMATION { - ULONG Number; - ULONG MaxMhz; - ULONG CurrentMhz; - ULONG MhzLimit; - ULONG MaxIdleState; - ULONG CurrentIdleState; - } PROCESSOR_POWER_INFORMATION, * PPROCESSOR_POWER_INFORMATION; - - SystemInfo getSystemInfo() const override - { - SystemInfo info; - LARGE_INTEGER speed; - QueryPerformanceFrequency(&speed); - - info.cpuFrequency = speed.QuadPart; + protected: + class CCaller final : public ICaller + { + public: + CCaller(ISystem* _system) : ICaller(_system) {} - info.desktopResX = GetSystemMetrics(SM_CXSCREEN); - info.desktopResY = GetSystemMetrics(SM_CYSCREEN); + core::smart_refctd_ptr createFile(const std::filesystem::path& filename, const core::bitflag flags) override final; + }; + + public: + CSystemWin32() : ISystem(core::make_smart_refctd_ptr(this)) {} - return info; - } + SystemInfo getSystemInfo() const override; }; +#endif } -#endif #endif \ No newline at end of file diff --git a/include/nbl/system/ICancellableAsyncQueueDispatcher.h b/include/nbl/system/ICancellableAsyncQueueDispatcher.h index 23866fa160..332d0450d0 100644 --- a/include/nbl/system/ICancellableAsyncQueueDispatcher.h +++ b/include/nbl/system/ICancellableAsyncQueueDispatcher.h @@ -151,6 +151,7 @@ class ICancellableAsyncQueueDispatcher : public IAsyncQueueDispatcher void notify(Args&&... args) diff --git a/include/nbl/system/IFile.h b/include/nbl/system/IFile.h index bf6d895b6f..d70d93ee0e 100644 --- a/include/nbl/system/IFile.h +++ b/include/nbl/system/IFile.h @@ -1,85 +1,24 @@ #ifndef _NBL_SYSTEM_I_FILE_H_INCLUDED_ #define _NBL_SYSTEM_I_FILE_H_INCLUDED_ -#include "nbl/core/decl/smart_refctd_ptr.h" -#include "nbl/core/util/bitflag.h" - -#include "nbl/system/path.h" - -#include -#include +#include "nbl/system/ISystem.h" namespace nbl::system { -class ISystem; - -// TODO: -//namespace impl -//{ -template -class future; -//} - -class IFile : public core::IReferenceCounted +class IFile : public IFileBase { - // TODO: how many of these friends do we actually need? - friend class ISystemCaller; - friend class ISystem; - friend class IFileArchive; - public: - enum E_CREATE_FLAGS : uint32_t - { - ECF_READ = 0b0001, - ECF_WRITE = 0b0010, - ECF_READ_WRITE = 0b0011, - ECF_MAPPABLE = 0b0100, - //! Implies ECF_MAPPABLE - ECF_COHERENT = 0b1100 - }; - - //! Get size of file. - /** \return Size of the file in bytes. */ - virtual size_t getSize() const = 0; - - //! Get name of file. - /** \return File name as zero terminated character string. */ - inline const path& getFileName() const { return m_filename; } - // - inline E_CREATE_FLAGS getFlags() const { return m_flags.value; } + virtual void read(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) = 0; + virtual void write(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) = 0; // - inline const void* getMappedPointer() const - { - if (m_flags.value&ECF_READ) - return getMappedPointer_impl(); - return nullptr; - } - void* getMappedPointer() - { - if (m_flags.value&ECF_WRITE) - return getMappedPointer_impl(); - return nullptr; - } - - // - inline bool isMappingCoherent() const - { - return m_flags.value&ECF_COHERENT; - } - - // TODO: make this virtual, so the IFileView does not need to keep ref to ISystem - void read(future& fut, void* buffer, size_t offset, size_t sizeToRead); - void write(future& fut, const void* buffer, size_t offset, size_t sizeToWrite); - - /* TODO: future utility - struct success + struct success_t { public: - success() = default; - ~success() = default; + success_t() = default; + ~success_t() = default; inline explicit operator bool() { return m_internalFuture.get()==sizeToProcess; @@ -90,39 +29,23 @@ class IFile : public core::IReferenceCounted } private: friend IFile; - future m_internalFuture; + ISystem::future_t m_internalFuture; size_t sizeToProcess; }; - void read(success& fut, void* buffer, size_t offset, size_t sizeToRead) + void read(success_t& fut, void* buffer, size_t offset, size_t sizeToRead) { read(fut.m_internalFuture,buffer,offset,sizeToRead); fut.sizeToProcess = sizeToRead; } - void write(success& fut, const void* buffer, size_t offset, size_t sizeToWrite) + void write(success_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) { write(fut.m_internalFuture,buffer,offset,sizeToWrite); fut.sizeToProcess = sizeToWrite; } - */ - - static path flattenFilename(const path& p); protected: - // TODO: docs - virtual size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) = 0; - virtual size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) = 0; - - virtual void* getMappedPointer_impl() = 0; - virtual const void* getMappedPointer_impl() const = 0; - - // the ISystem is the factory, so this stays protected - explicit IFile(core::smart_refctd_ptr&& _system, const path& _filename, core::bitflag _flags); - - core::smart_refctd_ptr m_system; - core::bitflag m_flags; - - private: - path m_filename; + // this is an abstract interface class so this stays protected + using IFileBase::IFileBase; }; } diff --git a/include/nbl/system/IFileArchive.h b/include/nbl/system/IFileArchive.h index f06363207f..3ef7d6fcaa 100644 --- a/include/nbl/system/IFileArchive.h +++ b/include/nbl/system/IFileArchive.h @@ -3,8 +3,8 @@ // For conditions of distribution and use, see copyright notice in nabla.h // See the original file in irrlicht source for authors -#ifndef _NBL_I_FILE_ARCHIVE_H_INCLUDED_ -#define _NBL_I_FILE_ARCHIVE_H_INCLUDED_ +#ifndef _NBL_SYSTEM_I_FILE_ARCHIVE_H_INCLUDED_ +#define _NBL_SYSTEM_I_FILE_ARCHIVE_H_INCLUDED_ #include "nbl/system/IFile.h" #include "nbl/system/CFileView.h" @@ -13,224 +13,226 @@ namespace nbl::system { +// these files are cached and created "on demand", and their storage is pooled template class CInnerArchiveFile : public CFileView { - std::atomic_flag* alive; -public: - CInnerArchiveFile(CFileView* arch, std::atomic_flag* _flag) : CFileView(std::move(*arch)), alive(_flag) - { - } - ~CInnerArchiveFile() = default; + std::atomic_flag* alive; + public: + CInnerArchiveFile(CFileView* arch, std::atomic_flag* _flag) : CFileView(std::move(*arch)), alive(_flag) + { + } + ~CInnerArchiveFile() = default; - static void* operator new(size_t size) noexcept - { - assert(false); - return nullptr; - } - static void* operator new[](size_t size) noexcept - { - assert(false); - return nullptr; - } - static void* operator new(size_t size, void* ptr, std::atomic_flag* alive) - { - alive->test_and_set(); - return ::operator new(size, ptr); - } - static void operator delete(void* ptr) noexcept - { - static_cast(ptr)->alive->clear(); - static_cast(ptr)->alive->notify_one(); - } - static void operator delete[](void* ptr) noexcept - { - assert(false); - } + static void* operator new(size_t size) noexcept + { + assert(false); + return nullptr; + } + static void* operator new[](size_t size) noexcept + { + assert(false); + return nullptr; + } + static void* operator new(size_t size, void* ptr, std::atomic_flag* alive) + { + alive->test_and_set(); + return ::operator new(size, ptr); + } + static void operator delete(void* ptr) noexcept + { + static_cast(ptr)->alive->clear(); + static_cast(ptr)->alive->notify_one(); + } + static void operator delete[](void* ptr) noexcept + { + assert(false); + } }; //! The FileArchive manages archives and provides access to files inside them. class IFileArchive : public core::IReferenceCounted { - static inline constexpr size_t SIZEOF_INNER_ARCHIVE_FILE = std::max(sizeof(CInnerArchiveFile), sizeof(CInnerArchiveFile)); - static inline constexpr size_t ALIGNOF_INNER_ARCHIVE_FILE = std::max(alignof(CInnerArchiveFile), alignof(CInnerArchiveFile)); - -protected: - enum E_ALLOCATOR_TYPE - { - EAT_NONE = 0, - EAT_NULL, - EAT_VIRTUAL_ALLOC, - EAT_MALLOC - }; - core::smart_refctd_ptr m_file; - system::logger_opt_smart_ptr m_logger; - - // TODO: This one is only required here because CFileView needs ISystem, must be removed when that's fixed - core::smart_refctd_ptr m_system; -public: - IFileArchive(core::smart_refctd_ptr&& file, core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger) : - m_file(std::move(file)), m_system(std::move(system)), m_logger(std::move(logger)) {} - ~IFileArchive() - { - _NBL_ALIGNED_FREE(m_filesBuffer); - _NBL_ALIGNED_FREE(m_fileFlags); - } + static inline constexpr size_t SIZEOF_INNER_ARCHIVE_FILE = std::max(sizeof(CInnerArchiveFile), sizeof(CInnerArchiveFile)); + static inline constexpr size_t ALIGNOF_INNER_ARCHIVE_FILE = std::max(alignof(CInnerArchiveFile), alignof(CInnerArchiveFile)); - // List all files and directories in a specific dir of the archive - virtual core::vector listAssets(const char* asset_path) - { - constexpr auto isSubDir = [](path p, path root) -> bool + protected: + enum E_ALLOCATOR_TYPE { - while (p != path()) { - if (p == root) { - return true; - } - p = p.parent_path(); - } - return false; + EAT_NONE = 0, + EAT_NULL, + EAT_VIRTUAL_ALLOC, + EAT_MALLOC }; - core::vector res; - for (auto& entry : m_files) + core::smart_refctd_ptr m_file; + system::logger_opt_smart_ptr m_logger; + + // TODO: This one is only required here because CFileView needs ISystem, must be removed when that's fixed + core::smart_refctd_ptr m_system; + + public: + IFileArchive(core::smart_refctd_ptr&& file, core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger) : + m_file(std::move(file)), m_system(std::move(system)), m_logger(std::move(logger)) {} + ~IFileArchive() + { + _NBL_ALIGNED_FREE(m_filesBuffer); + _NBL_ALIGNED_FREE(m_fileFlags); + } + + // List all files and directories in a specific dir of the archive + virtual core::vector listAssets(const char* asset_path) { - if (isSubDir(entry.fullName, asset_path)) + constexpr auto isSubDir = [](path p, path root) -> bool + { + while (p != path()) { + if (p == root) { + return true; + } + p = p.parent_path(); + } + return false; + }; + core::vector res; + for (auto& entry : m_files) { - res.push_back(entry.fullName); + if (isSubDir(entry.fullName, asset_path)) + { + res.push_back(entry.fullName); + } } + return res; } - return res; - } - //! An entry in a list of files, can be a folder or a file. - struct SFileListEntry - { - //! The name of the file - /** If this is a file or folder in the virtual filesystem and the archive - was created with the ignoreCase flag then the file name will be lower case. */ - system::path name; + //! An entry in a list of files, can be a folder or a file. + struct SFileListEntry + { + //! The name of the file + /** If this is a file or folder in the virtual filesystem and the archive + was created with the ignoreCase flag then the file name will be lower case. */ + system::path name; - //! The name of the file including the path - /** If this is a file or folder in the virtual filesystem and the archive was - created with the ignoreDirs flag then it will be the same as Name. */ - system::path fullName; + //! The name of the file including the path + /** If this is a file or folder in the virtual filesystem and the archive was + created with the ignoreDirs flag then it will be the same as Name. */ + system::path fullName; - //! The size of the file in bytes - uint32_t size; + //! The size of the file in bytes + uint32_t size; - //! The ID of the file in an archive - /** This is used to link the FileList entry to extra info held about this - file in an archive, which can hold things like data offset and CRC. */ - uint32_t ID; + //! The ID of the file in an archive + /** This is used to link the FileList entry to extra info held about this + file in an archive, which can hold things like data offset and CRC. */ + uint32_t ID; - //! FileOffset inside an archive - uint32_t offset; + //! FileOffset inside an archive + uint32_t offset; - E_ALLOCATOR_TYPE allocatorType; + E_ALLOCATOR_TYPE allocatorType; + + //! The == operator is provided so that CFileList can slowly search the list! + inline bool operator ==(const struct SFileListEntry& other) const + { + return core::strcmpi(fullName.string(), other.fullName.string()) == 0; + } - //! The == operator is provided so that CFileList can slowly search the list! - inline bool operator ==(const struct SFileListEntry& other) const + //! The < operator is provided so that CFileList can sort and quickly search the list. + inline bool operator <(const struct SFileListEntry& other) const + { + return fullName < other.fullName; + } + }; + struct SOpenFileParams { - return core::strcmpi(fullName.string(), other.fullName.string()) == 0; - } + std::filesystem::path filename; + std::filesystem::path absolutePath; + std::string_view password; + }; - //! The < operator is provided so that CFileList can sort and quickly search the list. - inline bool operator <(const struct SFileListEntry& other) const + std::mutex fileMutex; + std::atomic_flag* m_fileFlags = nullptr; + std::byte* m_filesBuffer = nullptr; + + core::smart_refctd_ptr readFile(const SOpenFileParams& params) { - return fullName < other.fullName; + auto index = getIndexByPath(params.filename); + if (index == -1) return nullptr; + switch (this->getFileType(index)) + { + case EAT_NULL: + return getFile_impl(params, index); + break; + case EAT_MALLOC: + return getFile_impl(params, index); + break; + case EAT_VIRTUAL_ALLOC: + return getFile_impl(params, index); + break; + } + assert(false); + return nullptr; } - }; - struct SOpenFileParams - { - std::filesystem::path filename; - std::filesystem::path absolutePath; - std::string_view password; - }; - - std::mutex fileMutex; - std::atomic_flag* m_fileFlags = nullptr; - std::byte* m_filesBuffer = nullptr; - - core::smart_refctd_ptr readFile(const SOpenFileParams& params) - { - auto index = getIndexByPath(params.filename); - if (index == -1) return nullptr; - switch (this->getFileType(index)) + virtual core::smart_refctd_ptr readFile_impl(const SOpenFileParams& params) = 0; + int32_t getIndexByPath(const system::path& p) { - case EAT_NULL: - return getFile_impl(params, index); - break; - case EAT_MALLOC: - return getFile_impl(params, index); - break; - case EAT_VIRTUAL_ALLOC: - return getFile_impl(params, index); - break; + for (int i = 0; i < m_files.size(); ++i) + { + if (p == m_files[i].fullName) return i; + } + return -1; } - assert(false); - return nullptr; - } - virtual core::smart_refctd_ptr readFile_impl(const SOpenFileParams& params) = 0; - int32_t getIndexByPath(const system::path& p) - { - for (int i = 0; i < m_files.size(); ++i) + E_ALLOCATOR_TYPE getFileType(uint32_t index) { - if (p == m_files[i].fullName) return i; + return m_files[index].allocatorType; } - return -1; - } - E_ALLOCATOR_TYPE getFileType(uint32_t index) - { - return m_files[index].allocatorType; - } - template - core::smart_refctd_ptr> getFile_impl(const SOpenFileParams& params, const uint32_t index) - { - std::unique_lock lock(fileMutex); + template + core::smart_refctd_ptr> getFile_impl(const SOpenFileParams& params, const uint32_t index) + { + std::unique_lock lock(fileMutex); - auto* file = reinterpret_cast*>(m_filesBuffer + index * SIZEOF_INNER_ARCHIVE_FILE); - // intentionally calling grab() on maybe-not-existing object - const auto oldRefcount = file->grab(); + auto* file = reinterpret_cast*>(m_filesBuffer + index * SIZEOF_INNER_ARCHIVE_FILE); + // intentionally calling grab() on maybe-not-existing object + const auto oldRefcount = file->grab(); - if (oldRefcount == 0) // need to construct - { - m_fileFlags[index].wait(true); //what should the param of wait be? - new (file, &m_fileFlags[index]) CInnerArchiveFile(static_cast*>(readFile_impl(params).get()), &m_fileFlags[index]); + if (oldRefcount == 0) // need to construct + { + m_fileFlags[index].wait(true); //what should the param of wait be? + new (file, &m_fileFlags[index]) CInnerArchiveFile(static_cast*>(readFile_impl(params).get()), &m_fileFlags[index]); + } + return core::smart_refctd_ptr>(file, core::dont_grab); } - return core::smart_refctd_ptr>(file, core::dont_grab); - } - const core::vector& getArchivedFiles() const { return m_files; } + const core::vector& getArchivedFiles() const { return m_files; } - IFile* asFile() { return m_file.get(); } - const IFile* asFile() const { return m_file.get(); } -protected: - void setFlagsVectorSize(size_t fileCount); + IFile* asFile() { return m_file.get(); } + const IFile* asFile() const { return m_file.get(); } + protected: + void setFlagsVectorSize(size_t fileCount); - virtual void addItem(const system::path& fullPath, uint32_t offset, uint32_t size, E_ALLOCATOR_TYPE allocatorType, uint32_t id = 0) - { - SFileListEntry entry; - entry.ID = id ? id : m_files.size(); - entry.offset = offset; - entry.size = size; - entry.name = fullPath; - entry.allocatorType = allocatorType; - entry.fullName = entry.name; + virtual void addItem(const system::path& fullPath, uint32_t offset, uint32_t size, E_ALLOCATOR_TYPE allocatorType, uint32_t id = 0) + { + SFileListEntry entry; + entry.ID = id ? id : m_files.size(); + entry.offset = offset; + entry.size = size; + entry.name = fullPath; + entry.allocatorType = allocatorType; + entry.fullName = entry.name; - core::deletePathFromFilename(entry.name); + core::deletePathFromFilename(entry.name); - m_files.insert(std::lower_bound(m_files.begin(), m_files.end(), entry), entry); - } - size_t read_blocking(system::IFile* file, void* buffer, size_t offset, size_t size) - { - return file->read_impl(buffer, offset, size); - } - size_t write_blocking(system::IFile* file, void* buffer, size_t offset, size_t size) - { - return file->write_impl(buffer, offset, size); - } - core::vector m_files; + m_files.insert(std::lower_bound(m_files.begin(), m_files.end(), entry), entry); + } + size_t read_blocking(system::IFile* file, void* buffer, size_t offset, size_t size) + { + return file->read_impl(buffer, offset, size); + } + size_t write_blocking(system::IFile* file, void* buffer, size_t offset, size_t size) + { + return file->write_impl(buffer, offset, size); + } + core::vector m_files; }; diff --git a/include/nbl/system/IFileBase.h b/include/nbl/system/IFileBase.h new file mode 100644 index 0000000000..2e521166cb --- /dev/null +++ b/include/nbl/system/IFileBase.h @@ -0,0 +1,77 @@ +#ifndef _NBL_SYSTEM_I_FILE_BASE_H_INCLUDED_ +#define _NBL_SYSTEM_I_FILE_BASE_H_INCLUDED_ + +#include "nbl/core/decl/smart_refctd_ptr.h" +#include "nbl/core/util/bitflag.h" + +#include +#include + +#include "nbl/system/path.h" + +namespace nbl::system +{ + +class IFileBase : public core::IReferenceCounted +{ + public: + enum E_CREATE_FLAGS : uint32_t + { + ECF_READ = 0b0001, + ECF_WRITE = 0b0010, + ECF_READ_WRITE = 0b0011, + ECF_MAPPABLE = 0b0100, + //! Implies ECF_MAPPABLE + ECF_COHERENT = 0b1100 + }; + + //! Get size of file. + /** \return Size of the file in bytes. */ + virtual size_t getSize() const = 0; + + //! Get name of file. + /** \return File name as zero terminated character string. */ + inline const path& getFileName() const { return m_filename; } + + // + inline E_CREATE_FLAGS getFlags() const { return m_flags.value; } + + // + inline const void* getMappedPointer() const + { + if (m_flags.value&ECF_READ) + return getMappedPointer_impl(); + return nullptr; + } + void* getMappedPointer() + { + if (m_flags.value&ECF_WRITE) + return getMappedPointer_impl(); + return nullptr; + } + + // + inline bool isMappingCoherent() const + { + return m_flags.value&ECF_COHERENT; + } + + // static utility, needed because std::filesystem won't flatten virtual paths (those that don't exist) + static path flattenFilename(const path& p); + + protected: + virtual void* getMappedPointer_impl() = 0; + virtual const void* getMappedPointer_impl() const = 0; + + // this is an abstract interface class so this stays protected + explicit IFileBase(path&& _filename, const core::bitflag _flags) : m_filename(std::move(_filename)), m_flags(_flags) {} + explicit IFileBase(const path& _filename, const core::bitflag _flags) : m_filename(_filename), m_flags(_flags) {} + + private: + path m_filename; + core::bitflag m_flags; +}; + +} + +#endif diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index 75d1beee46..d16a3015cc 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -1,61 +1,32 @@ -#ifndef __NBL_I_SYSTEM_H_INCLUDED__ -#define __NBL_I_SYSTEM_H_INCLUDED__ +#ifndef _NBL_SYSTEM_I_SYSTEM_H_INCLUDED_ +#define _NBL_SYSTEM_I_SYSTEM_H_INCLUDED_ + -#include "nbl/core/declarations.h" #include "nbl/builtin/common.h" +#include "nbl/core/declarations.h" +#include "nbl/core/util/bitflag.h" + #include #include "nbl/system/ICancellableAsyncQueueDispatcher.h" -#include "nbl/system/IFileArchive.h" -#include "nbl/system/IFile.h" -#include "nbl/system/CFileView.h" -#include "nbl/core/util/bitflag.h" +#include "nbl/system/IFileBase.h" -#if defined(_NBL_PLATFORM_LINUX_) // TODO: platform specific includes shouldn't be in global interface headers -#include -#endif namespace nbl::system { -class ISystemCaller : public core::IReferenceCounted // why does `ISystemCaller` need to be public? -{ -protected: - virtual ~ISystemCaller() = default; - -public: - - core::smart_refctd_ptr createFile(core::smart_refctd_ptr&& sys, const std::filesystem::path& filename, core::bitflag flags); - - size_t read(IFile* file, void* buffer, size_t offset, size_t size) - { - return file->read_impl(buffer, offset, size); - } - size_t write(IFile* file, const void* buffer, size_t offset, size_t size) - { - return file->write_impl(buffer, offset, size); - } - bool invalidateMapping(IFile* file, size_t offset, size_t size) - { - return false; - } - bool flushMapping(IFile* file, size_t offset, size_t size) - { - return false; - } -protected: - virtual core::smart_refctd_ptr createFile_impl(core::smart_refctd_ptr&& sys, const std::filesystem::path& filename, core::bitflag flags) = 0; -}; +class IFile; +class ISystemFile; +class IFileArchive; +class IArchiveLoader; class ISystem : public core::IReferenceCounted { + protected: + class ICaller; private: - friend class IFile; - friend class ISystemCaller; - static inline constexpr uint32_t CircularBufferSize = 256u; - - // @sadiuk add more request types if needed + // add more request types if needed enum E_REQUEST_TYPE { ERT_CREATE_FILE, @@ -72,18 +43,18 @@ class ISystem : public core::IReferenceCounted inline static constexpr uint32_t MAX_FILENAME_LENGTH = 4096; char filename[MAX_FILENAME_LENGTH] {}; - core::bitflag flags; + IFileBase::E_CREATE_FLAGS flags; }; struct SRequestParams_READ : SRequestParamsBase { - IFile* file; + ISystemFile* file; void* buffer; size_t offset; size_t size; }; struct SRequestParams_WRITE : SRequestParamsBase { - IFile* file; + ISystemFile* file; const void* buffer; size_t offset; size_t size; @@ -97,14 +68,14 @@ class ISystem : public core::IReferenceCounted SRequestParams_WRITE > params; }; - + static inline constexpr uint32_t CircularBufferSize = 256u; class CAsyncQueue : public ICancellableAsyncQueueDispatcher { using base_t = ICancellableAsyncQueueDispatcher; - friend base_t; + //friend base_t; public: - CAsyncQueue(ISystem* owner, core::smart_refctd_ptr&& caller) : base_t(base_t::start_on_construction), m_owner(owner), m_caller(std::move(caller)) {} + CAsyncQueue(core::smart_refctd_ptr&& caller) : base_t(base_t::start_on_construction), m_caller(std::move(caller)) {} template void request_impl(SRequestType& req, FutureType& future, RequestParams&& params) @@ -114,90 +85,40 @@ class ISystem : public core::IReferenceCounted base_t::associate_request_with_future(req, future); } - void process_request(SRequestType& req) - { - switch (req.type) - { - case ERT_CREATE_FILE: - { - auto& p = std::get(req.params); - base_t::notify_future>(req, m_caller->createFile(core::smart_refctd_ptr(m_owner), p.filename, p.flags)); - } - break; - case ERT_READ: - { - auto& p = std::get(req.params); - base_t::notify_future(req, m_caller->read(p.file, p.buffer, p.offset, p.size)); - } - break; - case ERT_WRITE: - { - auto& p = std::get(req.params); - base_t::notify_future(req, m_caller->write(p.file, p.buffer, p.offset, p.size)); - } - break; - } - } + void process_request(SRequestType& req); void init() {} private: - core::smart_refctd_ptr m_owner; - core::smart_refctd_ptr m_caller; + core::smart_refctd_ptr m_caller; }; + friend class ISystemFile; CAsyncQueue m_dispatcher; - // TODO: files shall have public read/write methods, and these should be protected, then the `IFile` implementations should call these behind the scenes via a friendship - bool readFile(future& future, IFile* file, void* buffer, size_t offset, size_t size) - { - SRequestParams_READ params; - params.buffer = buffer; - params.file = file; - params.offset = offset; - params.size = size; - m_dispatcher.request(future, params); - return true; - } - - bool writeFile(future& future, IFile* file, const void* buffer, size_t offset, size_t size) - { - SRequestParams_WRITE params; - params.buffer = buffer; - params.file = file; - params.offset = offset; - params.size = size; - m_dispatcher.request(future, params); - return true; - } - - std::pair findFileInArchive(const system::path& path) const; - core::smart_refctd_ptr getFileFromArchive(const system::path& path) - { - auto found = findFileInArchive(path); - auto archive = std::get(found); - if (!archive) - return nullptr; - - auto& params = std::get(found); - // TODO: support passwords - auto f = archive->readFile(params); - //assert(f.get()); // cannot fail - return f; - } - public: template - using future_t = CAsyncQueue::future_t; - - // - explicit ISystem(core::smart_refctd_ptr&& caller); + struct future_t : public CAsyncQueue::future_t + { + friend class ISystem; + friend class IFutureManipulator; + }; + class IFutureManipulator + { + protected: + //template + //inline void fake_notify(future_t& future, T&& value) const + inline void fake_notify(future_t& future, const size_t value) const + { + future.notify(value); + } + }; - // - core::smart_refctd_ptr loadBuiltinData(const std::string& builtinPath); + // [[deprecated]] use `createFile` instead + core::smart_refctd_ptr loadBuiltinData(const std::string& builtinPath) const; //! Compile time resource ID template - inline core::smart_refctd_ptr loadBuiltinData() + inline core::smart_refctd_ptr loadBuiltinData() const { #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ return impl_loadEmbeddedBuiltinData(StringUniqueType::value,nbl::builtin::get_resource()); @@ -210,13 +131,27 @@ class ISystem : public core::IReferenceCounted void addArchiveLoader(core::smart_refctd_ptr&& loader); // `flags` is the intended usage of the file - bool exists(const system::path& filename, core::bitflag flags) const; + bool exists(const system::path& filename, const core::bitflag flags) const; /* Returns true if the path is writable (e.g. if p is a path inside an archive the function will return true). The path existence is not checked. */ - bool isPathReadOnly(const system::path& p); + bool isPathReadOnly(const system::path& p) const; + + // + virtual bool isDirectory(const system::path& p) const + { + if (isPathReadOnly(p)) + return p.extension()==""; // TODO: this is a temporary decision until we figure out how to check if a file is directory in android APK + else + return std::filesystem::is_directory(p); + } + + /* + Recursively lists all files and directories in the directory. + */ + core::vector listFilesInDirectory(const system::path& p) const; // can only perform operations on non-virtual filesystem paths bool createDirectory(const system::path& p); @@ -227,209 +162,84 @@ class ISystem : public core::IReferenceCounted // can only perform operations on non-virtual filesystem paths std::error_code moveFileOrDirectory(const system::path& oldPath, const system::path& newPath); - // - bool createFile(future_t>& future, const std::filesystem::path& filename, core::bitflag flags) - { - SRequestParams_CREATE_FILE params; - if (filename.string().size() >= sizeof(params.filename)) - return false; - - strcpy(params.filename, filename.string().c_str()); - params.flags = flags; - - m_dispatcher.request(future, params); + /* + Recursively copy a directory or a file from one place to another. + from - a path to the source file or directory. Must exist. Can be both readonly and mutable path. + to - a path to the destination file or directory. Must be mutable path (isPathReadonly(to) must be false). + */ + bool copy(const system::path& from, const system::path& to); - return true; - } + // + void createFile(future_t>& future, std::filesystem::path filename, const core::bitflag flags); // Create a IFileArchive from a IFile core::smart_refctd_ptr openFileArchive(core::smart_refctd_ptr&& file, const std::string_view& password=""); - //! Warning: blocking call + //! A utility method. Warning: blocking call core::smart_refctd_ptr openFileArchive(const std::filesystem::path& filename, const std::string_view& password = "") { future_t> future; - if (!createFile(future, filename, core::bitflag(IFile::ECF_READ) | IFile::ECF_MAPPABLE)) - return nullptr; + createFile(future, filename, core::bitflag(IFileBase::ECF_READ)|IFileBase::ECF_MAPPABLE); auto file = future.get(); - if (file.get() == nullptr) return nullptr; - return openFileArchive(std::move(file), password); - } - - inline void mount(core::smart_refctd_ptr&& archive, const system::path& pathAlias="") - { - if (pathAlias.empty()) - m_cachedArchiveFiles.insert(archive->asFile()->getFileName(),std::move(archive)); - else - m_cachedArchiveFiles.insert(pathAlias,std::move(archive)); - } - void unmount(const IFileArchive* archive, const system::path& pathAlias="") - { - auto dummy = reinterpret_cast&>(archive); - if (pathAlias.empty()) - m_cachedArchiveFiles.removeObject(dummy,archive->asFile()->getFileName()); - else - m_cachedArchiveFiles.removeObject(dummy,pathAlias); - } + if (!file) + return nullptr; - /* - Recursively lists all files and directories in the directory. - */ - core::vector listFilesInDirectory(const system::path& p) - { - if (isPathReadOnly(p)) - { - auto curPath = p; - while (!curPath.empty() && curPath.parent_path() != curPath) - { - auto archives = m_cachedArchiveFiles.findRange(curPath); - for (auto& arch : archives) - { - auto rel = std::filesystem::relative(p, arch.first); - auto res = arch.second->listAssets(rel.generic_string().c_str()); - std::for_each(res.begin(), res.end(), [&arch](system::path& p) {p = arch.first / p; }); - return res; - } - - curPath = curPath.parent_path().generic_string(); - } - return {}; - } - else - { - uint32_t fileCount = std::distance(std::filesystem::recursive_directory_iterator(p), std::filesystem::recursive_directory_iterator{}); - core::vector res; - res.reserve(fileCount); - for (auto entry : std::filesystem::recursive_directory_iterator(p)) - { - res.push_back(entry.path()); - } - return res; - } + return openFileArchive(std::move(file),password); } + // After opening and archive, you must mount it if you want the global path lookup to work seamlessly. + void mount(core::smart_refctd_ptr&& archive, const system::path& pathAlias=""); + void unmount(const IFileArchive* archive, const system::path& pathAlias=""); - bool isDirectory(const system::path& p) - { - if (isPathReadOnly(p)) - { - return p.extension() == ""; // TODO: this is a temporary decision until i figure out how to check if a file is directory in androi APK - } - else - { - return std::filesystem::is_directory(p); - } - } - - /* - Recursively copy a directory or a file from one place to another. - from - a path to the source file or directory. Must exist. Can be both readonly and mutable path. - to - a path to the destination file or directory. Must be mutable path (isPathReadonly(to) must be false). - */ - bool copy(const system::path& from, const system::path& to) + // + struct SystemInfo { - auto copyFile = [this](const system::path& from, const system::path& to) - { - future_t> readFileFut, writeFileFut; - - createFile(readFileFut, from, IFile::ECF_READ); - createFile(writeFileFut, to, IFile::ECF_WRITE); - auto readF = readFileFut.get(); - auto writeF = writeFileFut.get(); + uint64_t cpuFrequencyHz = 0u; - char* fileData = (char*)malloc(readF->getSize()); - readF->read_impl(fileData, 0, readF->getSize()); + // in bytes + uint64_t totalMemory = 0u; + uint64_t availableMemory = 0u; - writeF->write_impl(fileData, 0, readF->getSize()); - - free(fileData); - }; - if (isPathReadOnly(from)) - { - if (isPathReadOnly(to)) return false; - if (isDirectory(from)) - { - auto allFiles = listFilesInDirectory(from); - for (const auto& file : allFiles) - { - auto relative = std::filesystem::relative(file, from); - system::path targetName = (to / relative).generic_string(); - std::filesystem::create_directories(targetName.parent_path()); - if (!isDirectory(targetName)) - { - copyFile(file, targetName); - } - } - } - else - { - copyFile(from, to); - } - return true; - } - else - { - const auto copyOptions = std::filesystem::copy_options::recursive | std::filesystem::copy_options::overwrite_existing; - std::error_code error; - std::filesystem::copy(from, to, copyOptions, error); - return static_cast(error); - } - } + uint32_t desktopResX = 0u; + uint32_t desktopResY = 0u; - // TODO: Merge SystemMemory into SystemInfo - struct SystemMemory - { - uint32_t totalMemory = {}; - uint32_t availableMemory = {}; + std::string OSFullName = "Unknown"; }; + virtual SystemInfo getSystemInfo() const = 0; + - // TODO: integrate `getSystemMemory()` into `getSystemInfo()` - static inline SystemMemory getSystemMemory() + protected: + // all file operations take place serially on a dedicated thread (to make fibers possible in the future) + class ICaller : public core::IReferenceCounted { - SystemMemory systemMemory; - - #if defined(_NBL_PLATFORM_WINDOWS_) - MEMORYSTATUS memoryStatus; - memoryStatus.dwLength = sizeof(MEMORYSTATUS); - - GlobalMemoryStatus(&memoryStatus); - - systemMemory.totalMemory = (uint32_t)(memoryStatus.dwTotalPhys >> 10); - systemMemory.availableMemory = (uint32_t)(memoryStatus.dwAvailPhys >> 10); - #elif defined(_NBL_PLATFORM_LINUX_) - #if defined(_SC_PHYS_PAGES) && defined(_SC_AVPHYS_PAGES) - sysinfo linuxSystemInfo; - assert(sysinfo(&linuxSystemInfo)); - - systemMemory.totalMemory = linuxSystemInfo.totalram; - systemMemory.availableMemory = linuxSystemInfo.freeram; - #endif - #elif defined(_NBL_PLATFORM_ANDROID_) // Also TODO: for POSIX/LINUX - // @sadiuk TODO - #elif defined(_NBL_PLATFORM_OSX_) - // TODO: implement for OSX - #endif - - return systemMemory; - } + public: + // each per-platform backend must override this function + virtual core::smart_refctd_ptr createFile(const std::filesystem::path& filename, const core::bitflag flags) = 0; - struct SystemInfo - { - uint64_t cpuFrequency; - //TODO others + // these contain some hoisted common sense checks + bool invalidateMapping(IFile* file, size_t offset, size_t size); + bool flushMapping(IFile* file, size_t offset, size_t size); + + protected: + ICaller(ISystem* _system) : m_system(_system) {} + virtual ~ICaller() = default; - uint32_t desktopResX; - uint32_t desktopResY; - std::string OSFullName; + // TODO: maybe change the file type to `ISystemFile` ? + virtual bool invalidateMapping_impl(IFile* file, size_t offset, size_t size) { assert(false); return false; } // TODO + virtual bool flushMapping_impl(IFile* file, size_t offset, size_t size) { assert(false); return false; } // TODO + + ISystem* m_system; }; - virtual SystemInfo getSystemInfo() const = 0; - - protected: + // + explicit ISystem(core::smart_refctd_ptr&& caller); virtual ~ISystem() {} // - core::smart_refctd_ptr impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found); + core::smart_refctd_ptr impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const; + + // + core::smart_refctd_ptr getFileFromArchive(const system::path& path); // @@ -452,8 +262,6 @@ class ISystem : public core::IReferenceCounted core::CMultiObjectCache> m_cachedArchiveFiles; }; -template -class future : public ISystem::future_t {}; } #endif diff --git a/include/nbl/system/ISystemFile.h b/include/nbl/system/ISystemFile.h new file mode 100644 index 0000000000..402c1b9930 --- /dev/null +++ b/include/nbl/system/ISystemFile.h @@ -0,0 +1,86 @@ +#ifndef _NBL_SYSTEM_I_SYSTEM_FILE_H_INCLUDED_ +#define _NBL_SYSTEM_I_SYSTEM_FILE_H_INCLUDED_ + + +#include "nbl/system/IFile.h" + + +namespace nbl::system +{ + +class ISystemFile : public IFile, private ISystem::IFutureManipulator +{ + public: + // + inline void read(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) final override + { + if (getFlags()&ECF_MAPPABLE) + { + const size_t size = getSize(); + if (offset+sizeToRead>size) + sizeToRead = size-offset; + memcpy(buffer,reinterpret_cast(m_mappedPtr)+offset,sizeToRead); + fake_notify(fut,sizeToRead); + } + else + { + ISystem::SRequestParams_READ params; + params.buffer = buffer; + params.file = this; + params.offset = offset; + params.size = sizeToRead; + m_system->m_dispatcher.request(fut,params); + } + } + inline void write(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) final override + { + if (getFlags()&ECF_MAPPABLE) + { + // TODO: growable mappings + if (offset+sizeToWrite>getSize()) + sizeToWrite = getSize()-offset; + memcpy(reinterpret_cast(m_mappedPtr)+offset,buffer,sizeToWrite); + fake_notify(fut,sizeToWrite); + } + else + { + ISystem::SRequestParams_WRITE params; + params.buffer = buffer; + params.file = this; + params.offset = offset; + params.size = sizeToWrite; + m_system->m_dispatcher.request(fut,params); + } + } + + protected: + // the ISystem is the factory, so this stays protected + explicit ISystemFile( + core::smart_refctd_ptr&& _system, + path&& _filename, + const core::bitflag _flags, + void* const _mappedPtr + ) : IFile(std::move(_filename),_flags), m_system(std::move(_system)), m_mappedPtr(_mappedPtr) {} + explicit ISystemFile( + core::smart_refctd_ptr&& _system, + const path& _filename, + const core::bitflag _flags, + void* const _mappedPtr + ) : IFile(std::move(_filename),_flags), m_system(_system), m_mappedPtr(_mappedPtr) {} + + // + inline void* getMappedPointer_impl() override {return m_mappedPtr;} + inline const void* getMappedPointer_impl() const override {return m_mappedPtr;} + + // + //friend class ISystem::ICaller; + virtual size_t asyncRead(void* buffer, size_t offset, size_t sizeToRead) = 0; + virtual size_t asyncWrite(const void* buffer, size_t offset, size_t sizeToWrite) = 0; + + core::smart_refctd_ptr m_system; + void* m_mappedPtr; +}; + +} + +#endif diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 20e33d260c..b8f9f27a0b 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -188,7 +188,8 @@ set(NBL_CORE_SOURCES ${NBL_ROOT_PATH}/src/nbl/core/IReferenceCounted.cpp ) set(NBL_SYSTEM_SOURCES - ${NBL_ROOT_PATH}/src/nbl/system/IFile.cpp + ${NBL_ROOT_PATH}/src/nbl/system/IFileBase.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CSystemWin32.cpp ${NBL_ROOT_PATH}/src/nbl/system/CFileWin32.cpp ${NBL_ROOT_PATH}/src/nbl/system/CFilePOSIX.cpp ${NBL_ROOT_PATH}/src/nbl/system/ILogger.cpp diff --git a/src/nbl/asset/interchange/COBJMeshFileLoader.h b/src/nbl/asset/interchange/COBJMeshFileLoader.h index 1321b9772a..47d7683997 100644 --- a/src/nbl/asset/interchange/COBJMeshFileLoader.h +++ b/src/nbl/asset/interchange/COBJMeshFileLoader.h @@ -11,14 +11,7 @@ #include "nbl/asset/interchange/IAssetLoader.h" #include "nbl/asset/metadata/CMTLMetadata.h" -namespace nbl -{ -namespace io -{ - class IFileSystem; -} - -namespace asset +namespace nbl::asset { #include "nbl/nblpack.h" @@ -83,14 +76,13 @@ class COBJMeshFileLoader : public asset::IAssetLoader //! Constructor COBJMeshFileLoader(IAssetManager* _manager); - virtual bool isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger) const override + inline bool isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger) const override { // OBJ doesn't really have any header but usually starts with a comment - system::future future; + system::IFile::success_t succ; char firstChar = 0; - _file->read(future, &firstChar, 0, 1); - future.get(); - return firstChar =='#' || firstChar =='v'; + _file->read(succ, &firstChar, 0, sizeof(firstChar)); + return succ && (firstChar =='#' || firstChar =='v'); } virtual const char** getAssociatedFileExtensions() const override @@ -142,7 +134,6 @@ class COBJMeshFileLoader : public asset::IAssetLoader } }; -} // end namespace asset -} // end namespace nbl +} // end namespace nbl::asset #endif diff --git a/src/nbl/asset/interchange/CPLYMeshWriter.h b/src/nbl/asset/interchange/CPLYMeshWriter.h index b00c0c8991..1617c5dfee 100644 --- a/src/nbl/asset/interchange/CPLYMeshWriter.h +++ b/src/nbl/asset/interchange/CPLYMeshWriter.h @@ -73,7 +73,7 @@ class CPLYMeshWriter : public asset::IAssetWriter } auto str = ss.str(); - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, str.c_str(), context.fileOffset, str.size()); { const auto bytesWritten = future.get(); diff --git a/src/nbl/asset/utils/CFilesystemIncluder.h b/src/nbl/asset/utils/CFilesystemIncluder.h index be3455bf53..e14318540c 100644 --- a/src/nbl/asset/utils/CFilesystemIncluder.h +++ b/src/nbl/asset/utils/CFilesystemIncluder.h @@ -2,51 +2,54 @@ // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h -#ifndef __NBL_ASSET_C_INCLUDER_H_INCLUDED__ -#define __NBL_ASSET_C_INCLUDER_H_INCLUDED__ +#ifndef _NBL_ASSET_C_FILESYSTEM_INCLUDER_H_INCLUDED_ +#define _NBL_ASSET_C_FILESYSTEM_INCLUDER_H_INCLUDED_ #include "nbl/asset/utils/IIncluder.h" -#include "nbl/system/ISystem.h" -namespace nbl { namespace asset +#include "nbl/system/IFile.h" + +namespace nbl::asset { class CFilesystemIncluder : public IIncluder { -public: - CFilesystemIncluder(system::ISystem* _sys) : m_system{_sys} - { - } - - void addSearchDirectory(const system::path& _searchDir) override - { - std::filesystem::path absPath = std::filesystem::absolute(_searchDir); - IIncluder::addSearchDirectory(absPath.string()); - } - - std::string getInclude_internal(const system::path& _path) const override - { - core::smart_refctd_ptr f; + public: + CFilesystemIncluder(system::ISystem* _sys) : m_system{_sys} + { + } + + void addSearchDirectory(const system::path& _searchDir) override { - system::ISystem::future_t> future; - bool valid = m_system->createFile(future, _path.c_str(), system::IFile::ECF_READ); - if (valid) f = future.get(); - if (!f) - return {}; + std::filesystem::path absPath = std::filesystem::absolute(_searchDir); + IIncluder::addSearchDirectory(absPath.string()); } - size_t size = f->getSize(); - std::string contents(size, '\0'); - system::future future; - f->read(future, contents.data(), 0, size); - future.get(); - return contents; - } + std::string getInclude_internal(const system::path& _path) const override + { + core::smart_refctd_ptr f; + { + system::ISystem::future_t> future; + m_system->createFile(future,_path.c_str(),system::IFile::ECF_READ); + f = future.get(); + if (!f) + return {}; + } + const size_t size = f->getSize(); + + std::string contents(size,'\0'); + system::IFile::success_t succ; + f->read(succ, contents.data(), 0, size); + const bool success = bool(succ); + assert(success); + + return contents; + } -private: - system::ISystem* m_system; + private: + system::ISystem* m_system; }; -}} +} #endif \ No newline at end of file diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index e9a8f37380..42aed5296c 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -5,6 +5,7 @@ #include #include +#if 0 namespace nbl::system { bool CFileArchiveZip::scanGZipHeader(size_t& offset) @@ -659,4 +660,5 @@ namespace nbl::system }; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/nbl/system/CFilePOSIX.cpp b/src/nbl/system/CFilePOSIX.cpp index ecd215e27b..89640df118 100644 --- a/src/nbl/system/CFilePOSIX.cpp +++ b/src/nbl/system/CFilePOSIX.cpp @@ -1,132 +1,38 @@ +#include "nbl/system/CFilePOSIX.h" + +using namespace nbl::system; + #ifdef __unix__ // WTF: can it be `defined(_NBL_PLATFORM_ANDROID_) | defined(_NBL_PLATFORM_LINUX_)` instead? -#include #include #include -#include -#include - -#include "nbl/system/CFilePOSIX.h" - -namespace nbl::system +CFilePOSIX::CFilePOSIX( + core::smart_refctd_ptr&& sys, + path&& _filename, + const core::bitflag _flags, + void* const _mappedPtr, + const size_t _size, + const native_file_handle_t _native +) : IFile(std::move(sys),std::move(_filename),_flags,_mappedPtr), + m_size(_size), m_native(_native) { - CFilePOSIX::CFilePOSIX(core::smart_refctd_ptr&& sys, const std::filesystem::path& _filename, core::bitflag _flags) : - base_t(std::move(sys), _filename, _flags) - { - auto filenameStream = _filename.string(); - const char* name_c_str = filenameStream.c_str(); - int createFlags = O_LARGEFILE; - int mappingFlags; - if ((_flags.value & ECF_READ_WRITE) == ECF_READ_WRITE) - { - createFlags |= O_CREAT; - createFlags |= O_RDWR; - mappingFlags = PROT_WRITE | PROT_READ; - } - else if (_flags.value & ECF_WRITE) - { - createFlags |= O_CREAT; - createFlags |= O_WRONLY; - mappingFlags = PROT_WRITE; - } - else if (_flags.value & ECF_READ) - { - createFlags |= O_RDONLY; - mappingFlags = PROT_READ; - } - if ((m_flags & ECF_READ).value == ECF_READ) - { - if (std::filesystem::exists(_filename)) - { - m_native = open(name_c_str, createFlags); - } - else m_openedProperly = false; - } - else - { - if (std::filesystem::exists(_filename.parent_path())) - { - m_native = creat(name_c_str, S_IRUSR | S_IRGRP | S_IROTH);//open(name_c_str, createFlags, S_IRUSR | S_IRGRP | S_IROTH); - } - else - m_openedProperly = false; - } - std::string error = strerror(errno); - m_openedProperly = m_native >= 0; - if(m_openedProperly) - { - struct stat sb; - if (stat(name_c_str, &sb) == -1) { - m_openedProperly = false; - } - else - { - m_size = sb.st_size; - } - } - - if (_flags.value & ECF_MAPPABLE && m_openedProperly) - { - m_memoryMappedObj = mmap((caddr_t)0, m_size, mappingFlags, MAP_PRIVATE, m_native, 0); - if (m_memoryMappedObj == MAP_FAILED) m_openedProperly = false; - } - } - - CFilePOSIX::~CFilePOSIX() - { - if (m_memoryMappedObj) - { - munmap(m_memoryMappedObj, m_size); - } - if (m_native != -1) - { - close(m_native); - } - } - - size_t CFilePOSIX::getSize() const - { - return m_size; - } - - - void* CFilePOSIX::getMappedPointer() - { - return m_memoryMappedObj; - } - - const void* CFilePOSIX::getMappedPointer() const - { - return m_memoryMappedObj; - } - - size_t CFilePOSIX::read_impl(void* buffer, size_t offset, size_t sizeToRead) - { - if (m_flags.value & ECF_MAPPABLE) - { - memcpy(buffer, (std::byte*)m_memoryMappedObj + offset, sizeToRead); - } - else - { - lseek(m_native, offset, SEEK_SET); - ::read(m_native, buffer, sizeToRead); - } - return sizeToRead; - } +} - size_t CFilePOSIX::write_impl(const void* buffer, size_t offset, size_t sizeToWrite) - { - if (m_flags.value & ECF_MAPPABLE) - { - memcpy((std::byte*)buffer + offset, m_memoryMappedObj, sizeToWrite); - } - else - { - lseek(m_native, offset, SEEK_SET); - ::write(m_native, buffer, sizeToWrite); - } - return sizeToWrite; - } +CFilePOSIX::~CFilePOSIX() +{ + if (m_mappedPtr) + munmap(m_mappedPtr,m_size); + close(m_native); +} +size_t CFilePOSIX::asyncRead(void* buffer, size_t offset, size_t sizeToRead) +{ + lseek(m_native, offset, SEEK_SET); + return ::read(m_native, buffer, sizeToRead); } +size_t CFilePOSIX::asyncWrite(const void* buffer, size_t offset, size_t sizeToWrite) +{ + lseek(m_native, offset, SEEK_SET); + return ::write(m_native, buffer, sizeToWrite); +} #endif \ No newline at end of file diff --git a/src/nbl/system/CFilePOSIX.h b/src/nbl/system/CFilePOSIX.h index e42c1ef24b..c8bf42511f 100644 --- a/src/nbl/system/CFilePOSIX.h +++ b/src/nbl/system/CFilePOSIX.h @@ -1,34 +1,43 @@ #ifndef _NBL_SYSTEM_C_FILE_POSIX_H_INCLUDED_ #define _NBL_SYSTEM_C_FILE_POSIX_H_INCLUDED_ -#if defined(_NBL_PLATFORM_ANDROID_) | defined(_NBL_PLATFORM_LINUX_) -#include "IFile.h" + +#include "nbl/system/ISystemFile.h" namespace nbl::system { - class CFilePOSIX : public IFile - { - using base_t = IFile; - using native_file_handle_t = int; - using native_file_mapping_handle_t = void*; - private: - bool m_openedProperly = true; // TODO: @sadiuk remove - size_t m_size = 0; - native_file_handle_t m_native = -1; - native_file_mapping_handle_t m_memoryMappedObj; + +#if defined(_NBL_PLATFORM_ANDROID_) | defined(_NBL_PLATFORM_LINUX_) +class CFilePOSIX : public ISystemFile +{ public: - CFilePOSIX(core::smart_refctd_ptr&& sys, const std::filesystem::path& _filename, core::bitflag _flags); + using native_file_handle_t = int; + CFilePOSIX( + core::smart_refctd_ptr&& sys, + path&& _filename, + const core::bitflag _flags, + void* const _mappedPtr, + const size_t _size, + const native_file_handle_t _native + ); + + // + inline size_t getSize() const override {return m_size;} + + protected: ~CFilePOSIX(); - // Inherited via IFile - virtual size_t getSize() const override; - virtual void* getMappedPointer() override; - virtual const void* getMappedPointer() const override; - bool isOpenedProperly() const { return m_openedProperly; } // TODO: @sadiuk remove + + // + size_t asyncRead(void* buffer, size_t offset, size_t sizeToRead) override; + size_t asyncWrite(const void* buffer, size_t offset, size_t sizeToWrite) override; + private: - virtual size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) override; - virtual size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) override; + void seek(const size_t bytesFromBeginningOfFile); - void seek(size_t bytesFromBeginningOfFile); - }; -} -#endif // _NBL_SYSTEM_C_FILE_POSIX_H_INCLUDED + const size_t m_size; + const native_file_handle_t m_native; +}; #endif + +} + +#endif // _NBL_SYSTEM_C_FILE_POSIX_H_INCLUDED \ No newline at end of file diff --git a/src/nbl/system/CFileWin32.cpp b/src/nbl/system/CFileWin32.cpp index 778f8fa134..ac9a7ca49e 100644 --- a/src/nbl/system/CFileWin32.cpp +++ b/src/nbl/system/CFileWin32.cpp @@ -1,150 +1,57 @@ -#ifdef _NBL_PLATFORM_WINDOWS_ - #include "nbl/system/CFileWin32.h" +#ifdef _NBL_PLATFORM_WINDOWS_ + #ifndef LODWORD # define LODWORD(_qw) ((DWORD)(_qw)) #endif #ifndef HIDWORD -# define HIDWORD(_qw) ((DWORD)(((_qw) >> 32) & 0xffffffff)) +# define HIDWORD(_qw) ((DWORD)(((_qw) >> 32u) & 0xffffffffu)) #endif -nbl::system::CFileWin32::CFileWin32(core::smart_refctd_ptr&& sys, const std::filesystem::path& _filename, core::bitflag _flags) : base_t(std::move(sys), _filename, _flags) -{ - SYSTEM_INFO info; - GetSystemInfo(&info); - m_allocGranularity = info.dwAllocationGranularity; - - auto k = FILE_GENERIC_READ; - auto r = FILE_GENERIC_WRITE; - auto rw = FILE_GENERIC_READ | - FILE_GENERIC_WRITE; - - DWORD access = (m_flags.value & ECF_READ_WRITE) == ECF_READ_WRITE ? FILE_GENERIC_READ | FILE_GENERIC_WRITE : - (m_flags.value & ECF_READ ? FILE_GENERIC_READ : (m_flags.value & ECF_WRITE ? FILE_GENERIC_WRITE : 0)); - SECURITY_ATTRIBUTES secAttribs{ sizeof(SECURITY_ATTRIBUTES), nullptr, FALSE }; - - system::path p = getFileName(); - - if (p.is_absolute()) - p.make_preferred(); // Replace "/" separators with "\" - - if (std::bit_cast(m_flags & ECF_READ_WRITE) != ECF_READ_WRITE && std::bit_cast(m_flags & ECF_READ)) - { - m_native = CreateFileA(p.string().data(), access, FILE_SHARE_READ, &secAttribs, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); - if (m_native == INVALID_HANDLE_VALUE) - { - auto e = GetLastError(); - m_openedProperly = false; - } - } - else - { - m_native = CreateFileA(p.string().data(), access, FILE_SHARE_READ, &secAttribs, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - } - - if (m_native != INVALID_HANDLE_VALUE) [[likely]] // let this idle here until c++20 :) - { - m_size = GetFileSize(m_native, nullptr); - } - else [[unlikely]] - { - m_openedProperly = false; - } - if (m_flags.value & ECF_MAPPABLE) - { - DWORD access = ((m_flags.value & ECF_READ_WRITE) == ECF_READ_WRITE | m_flags.value & ECF_WRITE) ? PAGE_READWRITE : - (m_flags.value | ECF_READ ? PAGE_READONLY : 0); - m_openedProperly &= access != 0; - /* - TODO: should think of a better way to cope with the max size of a file mapping object (those two zeroes after `access`). - For now it equals the size of a file so it'll work fine for archive reading, but if we try to - write outside those boungs, things will go bad. - */ - m_fileMappingObj = CreateFileMappingA(m_native, nullptr, access, 0, 0, _filename.string().c_str()); - m_openedProperly &= m_fileMappingObj != nullptr; - } - +using namespace nbl::system; -} - -nbl::system::CFileWin32::~CFileWin32() -{ - for (void* view : m_openedFileViews) - { - UnmapViewOfFile(view); - } - CloseHandle(m_native); - CloseHandle(m_fileMappingObj); -} - -size_t nbl::system::CFileWin32::getSize() const +CFileWin32::CFileWin32( + core::smart_refctd_ptr&& sys, + path&& _filename, + const core::bitflag _flags, + void* const _mappedPtr, + const size_t _size, + HANDLE _native, + HANDLE _fileMappingObj +) : ISystemFile(std::move(sys),std::move(_filename),_flags,_mappedPtr), + m_size(_size), m_native(_native), m_fileMappingObj(_fileMappingObj) { - return m_size; } -void* nbl::system::CFileWin32::getMappedPointer() +CFileWin32::~CFileWin32() { - void* view = MapViewOfFile(m_fileMappingObj, FILE_MAP_READ, 0, 0, m_size); - m_openedFileViews.push_back(view); - return view; + if (m_mappedPtr) + UnmapViewOfFile(m_mappedPtr); + if (m_fileMappingObj) + CloseHandle(m_fileMappingObj); + CloseHandle(m_native); } -const void* nbl::system::CFileWin32::getMappedPointer() const +size_t CFileWin32::asyncRead(void* buffer, size_t offset, size_t sizeToRead) { - void* view = MapViewOfFile(m_fileMappingObj, FILE_MAP_READ, 0, 0, m_size); - m_openedFileViews.push_back(view); - return view; + seek(offset); + DWORD numOfBytesRead; + ReadFile(m_native, buffer, sizeToRead, &numOfBytesRead, nullptr); + return numOfBytesRead; } - -size_t nbl::system::CFileWin32::read_impl(void* buffer, size_t offset, size_t sizeToRead) +size_t CFileWin32::asyncWrite(const void* buffer, size_t offset, size_t sizeToWrite) { - if (m_flags.value & ECF_MAPPABLE) - { - auto viewOffset = (offset / m_allocGranularity) * m_allocGranularity; - offset = offset % m_allocGranularity; - DWORD l = LODWORD(viewOffset), h = HIDWORD(viewOffset); - std::byte* fileView = (std::byte*)MapViewOfFile(m_fileMappingObj, FILE_MAP_READ, h, l, offset + sizeToRead); - m_openedFileViews.push_back(fileView); - if (fileView == nullptr) - { - assert(false); - return 0; - } - std::copy(fileView + offset, (std::byte*)fileView + offset + sizeToRead, (std::byte*)buffer); - return sizeToRead; - } - else - { - seek(offset); - DWORD numOfBytesRead; - ReadFile(m_native, buffer, sizeToRead, &numOfBytesRead, nullptr); - return numOfBytesRead; - } + seek(offset); + DWORD numOfBytesWritten; + WriteFile(m_native, buffer, sizeToWrite, &numOfBytesWritten, nullptr); + return numOfBytesWritten; } -size_t nbl::system::CFileWin32::write_impl(const void* buffer, size_t offset, size_t sizeToWrite) -{ - if (m_flags.value & ECF_MAPPABLE) - { - auto viewOffset = (offset / m_allocGranularity) * m_allocGranularity; - offset += offset % m_allocGranularity; - std::byte* fileView = (std::byte*)MapViewOfFile(m_fileMappingObj, FILE_MAP_WRITE, HIWORD((DWORD)viewOffset), LOWORD((DWORD)viewOffset), sizeToWrite); - std::copy((std::byte*)buffer, (std::byte*)buffer + sizeToWrite, fileView); - return sizeToWrite; - } - else - { - seek(offset); - DWORD numOfBytesWritten; - WriteFile(m_native, buffer, sizeToWrite, &numOfBytesWritten, nullptr); - return numOfBytesWritten; - } -} -void nbl::system::CFileWin32::seek(size_t position) +void CFileWin32::seek(size_t position) { LONG hiDword = HIDWORD(position); - SetFilePointer(m_native, position, &hiDword, FILE_BEGIN); + SetFilePointer(m_native,position,&hiDword,FILE_BEGIN); } #endif \ No newline at end of file diff --git a/src/nbl/system/CFileWin32.h b/src/nbl/system/CFileWin32.h index 84a2614337..45cc6ee279 100644 --- a/src/nbl/system/CFileWin32.h +++ b/src/nbl/system/CFileWin32.h @@ -1,41 +1,43 @@ #ifndef _NBL_SYSTEM_CFILEWIN32_H_INCLUDED_ #define _NBL_SYSTEM_CFILEWIN32_H_INCLUDED_ -#include "IFile.h" - -#include "nbl/system/DefaultFuncPtrLoader.h" -#ifdef _NBL_PLATFORM_WINDOWS_ +#include "nbl/system/ISystemFile.h" namespace nbl::system { -class CFileWin32 : public IFile +#ifdef _NBL_PLATFORM_WINDOWS_ +class CFileWin32 : public ISystemFile { - using base_t = IFile; - using native_file_handle_t = HANDLE; - private: - DWORD m_allocGranularity; - bool m_openedProperly = true; // TODO: @sadiuk remove - size_t m_size = 0; - native_file_handle_t m_native = nullptr; - HANDLE m_fileMappingObj = nullptr; - mutable core::vector m_openedFileViews; public: - CFileWin32(core::smart_refctd_ptr&& sys, const std::filesystem::path& _filename, core::bitflag _flags); + CFileWin32( + core::smart_refctd_ptr&& sys, + path&& _filename, + const core::bitflag _flags, + void* const _mappedPtr, + const size_t _size, + HANDLE _native, + HANDLE _fileMappingObj + ); + + // + inline size_t getSize() const override {return m_size;} + + protected: ~CFileWin32(); - // Inherited via IFile - virtual size_t getSize() const override; - virtual void* getMappedPointer() override; - virtual const void* getMappedPointer() const override; - bool isOpenedProperly() const { return m_openedProperly; } // TODO: @sadiuk remove + + size_t asyncRead(void* buffer, size_t offset, size_t sizeToRead) override; + size_t asyncWrite(const void* buffer, size_t offset, size_t sizeToWrite) override; + private: - virtual size_t read_impl(void* buffer, size_t offset, size_t sizeToRead) override; - virtual size_t write_impl(const void* buffer, size_t offset, size_t sizeToWrite) override; + void seek(const size_t bytesFromBeginningOfFile); - void seek(size_t bytesFromBeginningOfFile); + HANDLE m_native; + HANDLE m_fileMappingObj; + size_t m_size; }; +#endif } -#endif #endif \ No newline at end of file diff --git a/src/nbl/system/CSystemCallerPOSIX.cpp b/src/nbl/system/CSystemCallerPOSIX.cpp new file mode 100644 index 0000000000..b05634a647 --- /dev/null +++ b/src/nbl/system/CSystemCallerPOSIX.cpp @@ -0,0 +1,76 @@ +#include "nbl/system/CSystemCallerPOSIX.h" +#include "nbl/system/CFilePOSIX.h" + +using namespace nbl; +using namespace nbl::system; + +#if defined(__unix__) +#include +#include +#include + +core::smart_refctd_ptr ISystemPOSIX::CCaller::createFile_impl(const std::filesystem::path& filename, const core::bitflag flags) +{ + const bool writeAccess = flags.value&IFile::ECF_WRITE; + int createFlags = O_LARGEFILE|(writeAccess ? O_CREAT:0); + switch (_flags.value&IFile::ECF_READ_WRITE)) + { + case IFile::ECF_READ: + createFlags |= O_RDONLY; + break; + case IFile::ECF_WRITE: + createFlags |= O_WRONLY; + break; + case IFile::ECF_READ_WRITE: + createFlags |= O_RDWR; + break; + default: + assert(false); + break; + } + + CFilePOSIX::native_file_handle_t _native = -1; + auto filenameStream = _filename.string(); + const char* name_c_str = filenameStream.c_str(); + // only create a new file if we're going to be writing + if (writeAccess) + { + _native = creat(name_c_str, S_IRUSR | S_IRGRP | S_IROTH);//open(name_c_str, createFlags, S_IRUSR | S_IRGRP | S_IROTH); + } + else if (std::filesystem::exists(filename)) + { + _native = open(name_c_str,createFlags); + } + else + return nullptr; + + if (_native<0) + return nullptr; + + // get size + size_t _size; + struct stat sb; + if (stat(name_c_str,&sb) == -1) + { + close(_native); + return nullptr; + } + else + _size = sb.st_size; + + // map if needed + void* _mappedPtr = nullptr; + if (_flags.value & ECF_MAPPABLE) + { + const int mappingFlags = ((flags.value&IFile::ECF_READ) ? PROT_READ:0)|(writeAccess ? PROT_WRITE:0); + _mappedPtr = mmap((caddr_t)0, _size, mappingFlags, MAP_PRIVATE, _native, 0); + if (_mappedPtr==MAP_FAILED) + { + close(_native); + return nullptr; + } + } + + return core::make_smart_refctd_ptr(core::smart_refctd_ptr(m_system),filename,flags,_mappedPtr,_size,_native); +} +#endif diff --git a/src/nbl/system/CSystemCallerPOSIX.h b/src/nbl/system/CSystemCallerPOSIX.h new file mode 100644 index 0000000000..ec03051d0d --- /dev/null +++ b/src/nbl/system/CSystemCallerPOSIX.h @@ -0,0 +1,22 @@ +#ifndef _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_ +#define _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_ + +#include "ISystem.h" + +namespace nbl::system +{ + +#if defined(__unix__) +class ISystemPOSIX : public ISystem +{ + protected: + class CCaller final : public ISystem::ICaller + { + public: + core::smart_refctd_ptr createFile_impl(const std::filesystem::path& filename, core::bitflag flags) override final; + }; +}; +#endif + +} +#endif // ! _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_ diff --git a/src/nbl/system/CSystemWin32.cpp b/src/nbl/system/CSystemWin32.cpp new file mode 100644 index 0000000000..866c5820f5 --- /dev/null +++ b/src/nbl/system/CSystemWin32.cpp @@ -0,0 +1,103 @@ +#include "nbl/system/CSystemWin32.h" +#include "nbl/system/CFileWin32.h" + +using namespace nbl; +using namespace nbl::system; + +#ifdef _NBL_PLATFORM_WINDOWS_ +#include +#include + +//LOL the struct definition wasn't added to winapi headers do they ask to declare them yourself +typedef struct _PROCESSOR_POWER_INFORMATION { + ULONG Number; + ULONG MaxMhz; + ULONG CurrentMhz; + ULONG MhzLimit; + ULONG MaxIdleState; + ULONG CurrentIdleState; +} PROCESSOR_POWER_INFORMATION, * PPROCESSOR_POWER_INFORMATION; + +ISystem::SystemInfo CSystemWin32::getSystemInfo() const +{ + SystemInfo info; + + // TODO: improve https://forums.codeguru.com/showthread.php?519933-Windows-SDK-How-to-get-the-processor-frequency + LARGE_INTEGER speed; + QueryPerformanceFrequency(&speed); + info.cpuFrequencyHz = speed.QuadPart; + + MEMORYSTATUS memoryStatus; + memoryStatus.dwLength = sizeof(MEMORYSTATUS); + GlobalMemoryStatus(&memoryStatus); + info.totalMemory = memoryStatus.dwTotalPhys; + info.availableMemory = memoryStatus.dwAvailPhys; + + info.desktopResX = GetSystemMetrics(SM_CXSCREEN); + info.desktopResY = GetSystemMetrics(SM_CYSCREEN); + + return info; +} + + +core::smart_refctd_ptr CSystemWin32::CCaller::createFile(const std::filesystem::path& filename, const core::bitflag flags) +{ + const bool writeAccess = flags.value&IFile::ECF_WRITE; + const DWORD fileAccess = ((flags.value&IFile::ECF_READ) ? FILE_GENERIC_READ:0)|(writeAccess ? FILE_GENERIC_WRITE:0); + + SECURITY_ATTRIBUTES secAttribs{ sizeof(SECURITY_ATTRIBUTES), nullptr, FALSE }; + + system::path p = filename; + if (p.is_absolute()) + p.make_preferred(); // Replace "/" separators with "\" + + // only write access should create new files if they don't exist + const auto creationDisposition = writeAccess ? OPEN_ALWAYS:OPEN_EXISTING; + HANDLE _native = CreateFileA(p.string().data(), fileAccess, FILE_SHARE_READ, &secAttribs, creationDisposition, FILE_ATTRIBUTE_NORMAL, nullptr); + if (_native==INVALID_HANDLE_VALUE) + { + auto e = GetLastError(); + return nullptr; + } + const auto _size = GetFileSize(_native,nullptr); + + HANDLE _fileMappingObj = nullptr; + void* _mappedPtr = nullptr; + if ((flags.value&IFile::ECF_MAPPABLE) && (flags.value&IFile::ECF_READ_WRITE)) + { + /* + TODO: should think of a better way to cope with the max size of a file mapping object (those two zeroes after `access`). + For now it equals the size of a file so it'll work fine for archive reading, but if we try to + write outside those boungs, things will go bad. + */ + _fileMappingObj = CreateFileMappingA(_native,nullptr,writeAccess ? PAGE_READWRITE:PAGE_READONLY, 0, 0, filename.string().c_str()); + if (!_fileMappingObj) + { + CloseHandle(_native); + return nullptr; + } + switch (flags.value&IFile::ECF_READ_WRITE) + { + case IFile::ECF_READ: + _mappedPtr = MapViewOfFile(_fileMappingObj,FILE_MAP_READ,0,0,_size); + break; + case IFile::ECF_WRITE: + _mappedPtr = MapViewOfFile(_fileMappingObj,FILE_MAP_WRITE,0,0,_size); + break; + case IFile::ECF_READ_WRITE: + _mappedPtr = MapViewOfFile(_fileMappingObj,FILE_MAP_ALL_ACCESS,0,0,_size); + break; + default: + assert(false); // should never happen + break; + } + if (!_mappedPtr) + { + CloseHandle(_native); + CloseHandle(_fileMappingObj); + return nullptr; + } + } + return core::make_smart_refctd_ptr(core::smart_refctd_ptr(m_system),filename,flags,_native,_fileMappingObj,_mappedPtr,_size); +} +#endif \ No newline at end of file diff --git a/src/nbl/system/IFile.cpp b/src/nbl/system/IFileBase.cpp similarity index 67% rename from src/nbl/system/IFile.cpp rename to src/nbl/system/IFileBase.cpp index 11bc964636..55c3a7da59 100644 --- a/src/nbl/system/IFile.cpp +++ b/src/nbl/system/IFileBase.cpp @@ -1,30 +1,11 @@ // Copyright (C) 2021 - DevSH Graphics Programming Sp. z O.O. // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h - -#include "nbl/system/IFile.h" -#include "nbl/system/ISystem.h" +#include "nbl/system/IFileBase.h" using namespace nbl::system; -IFile::IFile(core::smart_refctd_ptr&& _system, const path& _filename, core::bitflag _flags) : - m_system(std::move(_system)), - m_flags(_flags), - m_filename(flattenFilename(_filename)) -{ -} - -void IFile::read(future& fut, void* buffer, size_t offset, size_t sizeToRead) -{ - m_system->readFile(fut, this, buffer, offset, sizeToRead); -} - -void IFile::write(future& fut, const void* buffer, size_t offset, size_t sizeToWrite) -{ - m_system->writeFile(fut, this, buffer, offset, sizeToWrite); -} - -static std::string deletePathFromPath(const std::string& filename, int32_t pathcount) +std::string deletePathFromPath(const std::string& filename, int32_t pathcount) { auto str = filename; diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index 3b9f97f792..63f4383c4c 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -1,4 +1,6 @@ #include "nbl/system/ISystem.h" +#include "nbl/system/IFileArchive.h" + #include "nbl/system/CArchiveLoaderZip.h" #include "nbl/system/CArchiveLoaderTar.h" @@ -7,13 +9,13 @@ using namespace nbl; using namespace nbl::system; -ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatcher(this, std::move(caller)) +ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatcher(std::move(caller)) { addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); } -core::smart_refctd_ptr ISystem::loadBuiltinData(const std::string& builtinPath) +core::smart_refctd_ptr ISystem::loadBuiltinData(const std::string& builtinPath) const { #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ return impl_loadEmbeddedBuiltinData(builtinPath,nbl::builtin::get_resource_runtime(builtinPath)); @@ -30,14 +32,14 @@ core::smart_refctd_ptr ISystem::loadBuiltinData(const std::string& builti createFile(future, path.c_str(), core::bitflag(IFile::ECF_READ) :: IFile::ECF_MAPPABLE); auto file = fut.get(); if (file.get()) - { + { return file; } return nullptr; #endif } -core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) +core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const { #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ if (found.first && found.second) @@ -64,7 +66,7 @@ void ISystem::addArchiveLoader(core::smart_refctd_ptr&& loader) m_loaders.pushToVector(std::move(loader)); } -bool ISystem::exists(const system::path& filename, core::bitflag flags) const +bool ISystem::exists(const system::path& filename, const core::bitflag flags) const { const bool writeUsage = flags.value&IFile::ECF_WRITE; #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ @@ -86,7 +88,7 @@ bool ISystem::exists(const system::path& filename, core::bitflag ISystem::listFilesInDirectory(const system::path& p) const +{ + core::vector res; + res.reserve(128u); + + // TODO: check for path being a builtin + if (isPathReadOnly(p)) // TODO: better check for archives + { + auto curPath = p; + while (!curPath.empty() && curPath.parent_path() != curPath) + { + auto archives = m_cachedArchiveFiles.findRange(curPath); + for (auto& arch : archives) + { + auto rel = std::filesystem::relative(p, arch.first); + auto res = arch.second->listAssets(rel.generic_string().c_str()); + std::for_each(res.begin(), res.end(), [&arch](system::path& p) {p = arch.first / p; }); + return res; + } + + curPath = curPath.parent_path().generic_string(); + } + } + else + { + uint32_t fileCount = std::distance(std::filesystem::recursive_directory_iterator(p), std::filesystem::recursive_directory_iterator{}); + for (auto entry : std::filesystem::recursive_directory_iterator(p)) + res.push_back(entry.path()); + } + // TODO: recurse into any archives which could have been found! + return res; +} + bool ISystem::createDirectory(const system::path& p) { return std::filesystem::create_directories(p); @@ -130,6 +165,94 @@ std::error_code ISystem::moveFileOrDirectory(const system::path& oldPath, const return ec; } +bool ISystem::copy(const system::path& from, const system::path& to) +{ + if (isPathReadOnly(to)) + return false; + + auto copyFile = [this](const system::path& from, const system::path& to) -> bool + { + future_t> readFileFut, writeFileFut; + createFile(readFileFut,from,core::bitflag(IFile::ECF_READ)|IFile::ECF_COHERENT); + createFile(writeFileFut,to,IFile::ECF_WRITE); + auto readF = readFileFut.get(); + auto writeF = writeFileFut.get(); + if (!readF || !readF->getMappedPointer() || !writeF) + return false; + + IFile::success bytesWritten; + writeF->write(bytesWritten,readF->getMappedPointer(),0,readF->getSize()); + return bool(bytesWritten); + }; + if (isPathReadOnly(from)) + { + if (isDirectory(from)) + { + auto allFiles = listFilesInDirectory(from); + for (const auto& file : allFiles) + { + auto relative = std::filesystem::relative(file,from); + system::path targetName = (to/relative).generic_string(); + std::filesystem::create_directories(targetName.parent_path()); + if (!isDirectory(targetName)) + { + if (!copyFile(file,targetName)) + return false; + } + } + return true; + } + else + return copyFile(from,to); + } + else + { + const auto copyOptions = std::filesystem::copy_options::recursive|std::filesystem::copy_options::overwrite_existing; + std::error_code error; + std::filesystem::copy(from, to, copyOptions, error); + return static_cast(error); + } +} + +void ISystem::createFile(future_t>& future, std::filesystem::path filename, const core::bitflag flags) +{ + // try builtins + if (!(flags.value&IFile::ECF_WRITE)) + { + auto file = loadBuiltinData(filename.string()); + if (file) + { + future.notify(std::move(file)); + return; + } + } + // try archives + if (flags.value&IFile::ECF_READ) + { + auto file = getFileFromArchive(filename); + if (file) + { + future.notify(std::move(file)); + return; + } + } + + // + if (std::filesystem::exists(filename)) + filename = std::filesystem::absolute(filename).generic_string(); + if (filename.string().size()>=SRequestParams_CREATE_FILE::MAX_FILENAME_LENGTH) + { + future.notify(nullptr); + return; + } + + SRequestParams_CREATE_FILE params; + strcpy(params.filename,filename.string().c_str()); + params.flags = flags; + + m_dispatcher.request(future,params); +} + core::smart_refctd_ptr ISystem::openFileArchive(core::smart_refctd_ptr&& file, const std::string_view& password) { // the file backing the archive needs to be readable @@ -155,28 +278,106 @@ core::smart_refctd_ptr ISystem::openFileArchive(core::smart_refctd return nullptr; } +void ISystem::mount(core::smart_refctd_ptr&& archive, const system::path& pathAlias) +{ + if (pathAlias.empty()) + m_cachedArchiveFiles.insert(archive->asFile()->getFileName(),std::move(archive)); + else + m_cachedArchiveFiles.insert(pathAlias,std::move(archive)); +} +void ISystem::unmount(const IFileArchive* archive, const system::path& pathAlias) +{ + auto dummy = reinterpret_cast&>(archive); + if (pathAlias.empty()) + m_cachedArchiveFiles.removeObject(dummy,archive->asFile()->getFileName()); + else + m_cachedArchiveFiles.removeObject(dummy,pathAlias); +} -core::smart_refctd_ptr ISystemCaller::createFile(core::smart_refctd_ptr&& sys, const std::filesystem::path& filename, core::bitflag flags) +core::smart_refctd_ptr ISystem::getFileFromArchive(const system::path& path) { - if (flags.value & IFile::ECF_READ) - { - auto a = sys->getFileFromArchive(filename); - if (a.get() != nullptr) return a; + // given an absolute `path` find the archive it belongs to + std::pair found = {nullptr,{}}; + system::path path = std::filesystem::exists(path) ? std::filesystem::canonical(path.parent_path()):path.parent_path(); + // going up the directory tree + while (!path.empty() && path.parent_path() != path) + { + system::path realPath = std::filesystem::exists(path) ? system::path(std::filesystem::canonical(path).generic_string()) : path; + auto archives = m_cachedArchiveFiles.findRange(realPath); + + for (auto& archive : archives) + { + auto relative = std::filesystem::relative(_path, path); + auto files = archive.second->getArchivedFiles(); + auto itemToFind = IFileArchive::SFileListEntry{ relative, relative, 0 }; + bool hasFile = std::binary_search(files.begin(), files.end(), itemToFind, [](const IFileArchive::SFileListEntry& l, const IFileArchive::SFileListEntry& r) { return l.fullName == r.fullName; }); + auto f = archive.second->asFile(); + if (f) + { + auto realPath = f->getFileName(); + auto absolute = (realPath / relative).generic_string(); + if (hasFile) + { + auto f = archive.second; + return { f.get(),{relative,_path,""} }; + } + } + else + { + if (hasFile) + { + auto f = archive.second; + return { f.get(),{relative,_path,""} }; + } + } + } + path = path.parent_path(); } - system::path realname = filename; - if (std::filesystem::exists(filename)) + + auto archive = std::get(found); + if (!archive) + return nullptr; + + auto& params = std::get(found); + // TODO: support passwords + return archive->readFile(params); +} + + +void ISystem::CAsyncQueue::process_request(SRequestType& req) +{ + switch (req.type) { - realname = std::filesystem::absolute(filename).generic_string(); + case ERT_CREATE_FILE: + { + auto& p = std::get(req.params); + base_t::notify_future>(req,m_caller->createFile(p.filename,p.flags)); + } + break; + case ERT_READ: + { + auto& p = std::get(req.params); + base_t::notify_future(req, m_caller->read(p.file, p.buffer, p.offset, p.size)); + } + break; + case ERT_WRITE: + { + auto& p = std::get(req.params); + base_t::notify_future(req, m_caller->write(p.file, p.buffer, p.offset, p.size)); + } + break; } - return createFile_impl(std::move(sys), realname, flags); } -std::pair ISystem::findFileInArchive(const system::path& _path) const +#if 0 + +// given an absolute `path` find the archive it belongs to +std::pair ISystem::findFileInArchive(const system::path& _path) const { system::path path = std::filesystem::exists(_path) ? system::path(std::filesystem::canonical(_path.parent_path()).generic_string()) : _path.parent_path(); - - while (!path.empty() && path.parent_path() != path) // going up the directory tree + // going up the directory tree + while (!path.empty() && path.parent_path() != path) { system::path realPath = std::filesystem::exists(path) ? system::path(std::filesystem::canonical(path).generic_string()) : path; auto archives = m_cachedArchiveFiles.findRange(realPath); @@ -194,7 +395,7 @@ std::pair ISystem::findFileInArchiv auto absolute = (realPath / relative).generic_string(); if (hasFile) { - auto f = archive.second;// ->readFile({ relative, absolute, "" }); + auto f = archive.second; return { f.get(),{relative,_path,""} }; } } @@ -202,12 +403,32 @@ std::pair ISystem::findFileInArchiv { if (hasFile) { - auto f = archive.second;// ->readFile({ relative, _path, "" }); + auto f = archive.second; return { f.get(),{relative,_path,""} }; } } } - path = path.parent_path(); + path = path.parent_path(); } - return {nullptr,{}}; + return { nullptr,{} }; } +#endif + +bool ISystem::ICaller::invalidateMapping(IFile* file, size_t offset, size_t size) +{ + const auto flags = file->getFlags(); + if (!file || !(flags&IFile::ECF_MAPPABLE)) + return false; + else if (flags&IFile::ECF_COHERENT) + return true; + return invalidateMapping_impl(file,offset,size); +} +bool ISystem::ICaller::flushMapping(IFile* file, size_t offset, size_t size) +{ + const auto flags = file->getFlags(); + if (!file || !(flags&IFile::ECF_MAPPABLE)) + return false; + else if (flags&IFile::ECF_COHERENT) + return true; + return flushMapping_impl(file,offset,size); +} \ No newline at end of file diff --git a/src/nbl/system/ISystemFile.cpp b/src/nbl/system/ISystemFile.cpp new file mode 100644 index 0000000000..ce526ca18d --- /dev/null +++ b/src/nbl/system/ISystemFile.cpp @@ -0,0 +1,10 @@ +// Copyright (C) 2021 - DevSH Graphics Programming Sp. z O.O. +// This file is part of the "Nabla Engine". +// For conditions of distribution and use, see copyright notice in nabla.h +#include "nbl/system/ISystemFile.h" + +using namespace nbl::system; + + + +#include "nbl/core/definitions.h" \ No newline at end of file From 5883f047304c1f8da0a16d3f3815cf044d9e7142 Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 4 Mar 2022 12:42:43 +0100 Subject: [PATCH 40/91] adjust the new API --- include/nbl/system/CFileArchive.h | 125 ++++++++++++++ include/nbl/system/CFileView.h | 37 ++-- include/nbl/system/IFile.h | 42 ++++- include/nbl/system/IFileArchive.h | 215 +++++++----------------- include/nbl/system/IFileBase.h | 1 - include/nbl/system/IFileViewAllocator.h | 33 ++-- include/nbl/system/ISystem.h | 25 ++- include/nbl/system/ISystemFile.h | 74 +++----- src/nbl/system/ISystem.cpp | 115 ++++++------- src/nbl/system/ISystemFile.cpp | 10 -- 10 files changed, 340 insertions(+), 337 deletions(-) create mode 100644 include/nbl/system/CFileArchive.h delete mode 100644 src/nbl/system/ISystemFile.cpp diff --git a/include/nbl/system/CFileArchive.h b/include/nbl/system/CFileArchive.h new file mode 100644 index 0000000000..21e4407580 --- /dev/null +++ b/include/nbl/system/CFileArchive.h @@ -0,0 +1,125 @@ +// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O. +// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" +// For conditions of distribution and use, see copyright notice in nabla.h +// See the original file in irrlicht source for authors + +#ifndef _NBL_SYSTEM_C_FILE_ARCHIVE_H_INCLUDED_ +#define _NBL_SYSTEM_C_FILE_ARCHIVE_H_INCLUDED_ + +#include "nbl/system/IFileArchive.h" +#include "nbl/system/CFileView.h" +#include "nbl/system/IFileViewAllocator.h" + +namespace nbl::system +{ + +// these files are cached and created "on demand", and their storage is pooled +template +class CInnerArchiveFile : public CFileView +{ + std::atomic_flag* alive; + public: + CInnerArchiveFile(CFileView* arch, std::atomic_flag* _flag) : CFileView(std::move(*arch)), alive(_flag) + { + } + ~CInnerArchiveFile() = default; + + static void* operator new(size_t size) noexcept + { + assert(false); + return nullptr; + } + static void* operator new[](size_t size) noexcept + { + assert(false); + return nullptr; + } + static void* operator new(size_t size, void* ptr, std::atomic_flag* alive) + { + alive->test_and_set(); + return ::operator new(size, ptr); + } + static void operator delete(void* ptr) noexcept + { + static_cast(ptr)->alive->clear(); + static_cast(ptr)->alive->notify_one(); + } + static void operator delete[](void* ptr) noexcept + { + assert(false); + } +}; + + +//! +class CFileArchive : public IFileArchive +{ + static inline constexpr size_t SIZEOF_INNER_ARCHIVE_FILE = std::max(sizeof(CInnerArchiveFile), sizeof(CInnerArchiveFile)); + static inline constexpr size_t ALIGNOF_INNER_ARCHIVE_FILE = std::max(alignof(CInnerArchiveFile), alignof(CInnerArchiveFile)); + + public: + core::smart_refctd_ptr readFile(const SOpenFileParams& params) + { + auto index = getIndexByPath(params.filename); + if (index == -1) return nullptr; + switch (listAssets()[index].allocatorType) + { + case EAT_NULL: + return getFile_impl(params, index); + break; + case EAT_MALLOC: + return getFile_impl(params, index); + break; + case EAT_VIRTUAL_ALLOC: + return getFile_impl(params, index); + break; + } + assert(false); + return nullptr; + } + virtual core::smart_refctd_ptr readFile_impl(const SOpenFileParams& params) = 0; + int32_t getIndexByPath(const system::path& p) + { + for (int i = 0; i < m_files.size(); ++i) + { + if (p == m_files[i].fullName) return i; + } + return -1; + } + template + core::smart_refctd_ptr> getFile_impl(const SOpenFileParams& params, const uint32_t index) + { + std::unique_lock lock(fileMutex); + + auto* file = reinterpret_cast*>(m_filesBuffer + index * SIZEOF_INNER_ARCHIVE_FILE); + // intentionally calling grab() on maybe-not-existing object + const auto oldRefcount = file->grab(); + + if (oldRefcount == 0) // need to construct + { + m_fileFlags[index].wait(true); //what should the param of wait be? + new (file, &m_fileFlags[index]) CInnerArchiveFile(static_cast*>(readFile_impl(params).get()), &m_fileFlags[index]); + } + return core::smart_refctd_ptr>(file, core::dont_grab); + } + + protected: + CFileArchive(core::smart_refctd_ptr&& file, system::logger_opt_smart_ptr&& logger) : IFileArchive(std::move(file),std::move(logger)) {} + ~CFileArchive() + { + _NBL_ALIGNED_FREE(m_filesBuffer); + _NBL_ALIGNED_FREE(m_fileFlags); + } + + void setFlagsVectorSize(size_t fileCount); + + std::mutex fileMutex; + std::atomic_flag* m_fileFlags = nullptr; + std::byte* m_filesBuffer = nullptr; +}; + + +} // end namespace nbl::system + +#endif + diff --git a/include/nbl/system/CFileView.h b/include/nbl/system/CFileView.h index ea08c67d31..63789d9f88 100644 --- a/include/nbl/system/CFileView.h +++ b/include/nbl/system/CFileView.h @@ -8,7 +8,7 @@ namespace nbl::system { -class IFileView : public IFile, private ISystem::IFutureManipulator +class IFileView : public IFile { public: size_t getSize() const override final @@ -17,29 +17,12 @@ class IFileView : public IFile, private ISystem::IFutureManipulator } protected: - IFileView(IFileView&& other) : IFile(other.getFileName(),other.getFlags()), m_buffer(other.m_buffer), m_size(other.m_size) + IFileView(IFileView&& other) : IFile(path(other.getFileName()),other.getFlags()), m_buffer(other.m_buffer), m_size(other.m_size) { other.m_buffer = nullptr; } - IFileView(const path& _name, const core::bitflag _flags, void* buffer, size_t fileSize) : - IFile(_name,_flags|ECF_COHERENT), m_buffer((std::byte*)buffer), m_size(fileSize) - { - } - - inline void read(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) override final - { - if (offset+sizeToRead > m_size) - sizeToRead = m_size-offset; - memcpy(buffer, m_buffer+offset, sizeToRead); - fake_notify(fut,sizeToRead); - } - inline void write(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) override final - { - if (offset+sizeToWrite > m_size) - sizeToWrite = m_size-offset; - memcpy(m_buffer+offset, buffer, sizeToWrite); - fake_notify(fut,sizeToWrite); - } + IFileView(path&& _name, const core::bitflag _flags, void* buffer, size_t fileSize) : + IFile(std::move(_name),_flags), m_buffer(buffer), m_size(fileSize) {} const void* getMappedPointer_impl() const override final { @@ -51,7 +34,7 @@ class IFileView : public IFile, private ISystem::IFutureManipulator } // - std::byte* m_buffer; + void* m_buffer; size_t m_size; }; @@ -63,11 +46,11 @@ class CFileView : public IFileView public: // constructor for making a file with memory already allocated by the allocator - CFileView(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, void* buffer, size_t fileSize, allocator_t&& _allocator) : - IFileView(std::move(sys),_name,_flags,buffer,fileSize), allocator(std::move(_allocator)) {} + CFileView(path&& _name, const core::bitflag _flags, void* buffer, const size_t fileSize, allocator_t&& _allocator) : + IFileView(std::move(sys),std::move(_name),_flags,buffer,fileSize), allocator(std::move(_allocator)) {} // - static inline core::smart_refctd_ptr> create(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, size_t fileSize, allocator_t&& _allocator={}) + static inline core::smart_refctd_ptr> create(path&& _name, const core::bitflag _flags, size_t fileSize, allocator_t&& _allocator={}) { auto mem = reintepret_cast(_allocator.alloc(fileSize)); if (!mem) @@ -96,8 +79,8 @@ template<> class CFileView : public IFileView { public: - CFileView(core::smart_refctd_ptr&& sys, const path& _name, core::bitflag _flags, void* buffer, size_t fileSize) : - IFileView(std::move(sys),_name,_flags,buffer,fileSize) {} + CFileView(path&& _name, const core::bitflag _flags, void* buffer, const size_t fileSize) : + IFileView(std::move(_name),_flags,buffer,fileSize) {} protected: CFileView(CFileView&& other) : IFileView(std::move(other)) {} diff --git a/include/nbl/system/IFile.h b/include/nbl/system/IFile.h index d70d93ee0e..90a4923995 100644 --- a/include/nbl/system/IFile.h +++ b/include/nbl/system/IFile.h @@ -6,12 +6,38 @@ namespace nbl::system { -class IFile : public IFileBase +class IFile : public IFileBase, private ISystem::IFutureManipulator { public: // - virtual void read(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) = 0; - virtual void write(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) = 0; + inline void read(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) + { + const auto* ptr = reinterpret_cast(getMappedPointer()); + if (ptr) + { + const size_t size = getSize(); + if (offset+sizeToRead>size) + sizeToRead = size-offset; + memcpy(buffer,ptr+offset,sizeToRead); + fake_notify(fut,sizeToRead); + } + else + unmappedRead(fut,buffer,offset,sizeToRead); + } + inline void write(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) + { + auto* ptr = reinterpret_cast(getMappedPointer()); + if (ptr) + { + // TODO: growable mappings + if (offset+sizeToWrite>getSize()) + sizeToWrite = getSize()-offset; + memcpy(ptr+offset,buffer,sizeToWrite); + fake_notify(fut,sizeToWrite); + } + else + unmappedWrite(fut,buffer,offset,sizeToWrite); + } // struct success_t @@ -46,6 +72,16 @@ class IFile : public IFileBase protected: // this is an abstract interface class so this stays protected using IFileBase::IFileBase; + + // + virtual void unmappedRead(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) + { + fake_notify(fut,0ull); + } + virtual void unmappedWrite(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) + { + fake_notify(fut,0ull); + } }; } diff --git a/include/nbl/system/IFileArchive.h b/include/nbl/system/IFileArchive.h index 3ef7d6fcaa..8a9fbd879c 100644 --- a/include/nbl/system/IFileArchive.h +++ b/include/nbl/system/IFileArchive.h @@ -6,58 +6,22 @@ #ifndef _NBL_SYSTEM_I_FILE_ARCHIVE_H_INCLUDED_ #define _NBL_SYSTEM_I_FILE_ARCHIVE_H_INCLUDED_ -#include "nbl/system/IFile.h" -#include "nbl/system/CFileView.h" -#include "nbl/system/IFileViewAllocator.h" +#include "nbl/system/path.h" +#include "nbl/system/ILogger.h" +#include "nbl/system/IFileBase.h" -namespace nbl::system -{ +#include +#include -// these files are cached and created "on demand", and their storage is pooled -template -class CInnerArchiveFile : public CFileView +namespace nbl::system { - std::atomic_flag* alive; - public: - CInnerArchiveFile(CFileView* arch, std::atomic_flag* _flag) : CFileView(std::move(*arch)), alive(_flag) - { - } - ~CInnerArchiveFile() = default; - - static void* operator new(size_t size) noexcept - { - assert(false); - return nullptr; - } - static void* operator new[](size_t size) noexcept - { - assert(false); - return nullptr; - } - static void* operator new(size_t size, void* ptr, std::atomic_flag* alive) - { - alive->test_and_set(); - return ::operator new(size, ptr); - } - static void operator delete(void* ptr) noexcept - { - static_cast(ptr)->alive->clear(); - static_cast(ptr)->alive->notify_one(); - } - static void operator delete[](void* ptr) noexcept - { - assert(false); - } -}; +class IFile; //! The FileArchive manages archives and provides access to files inside them. class IFileArchive : public core::IReferenceCounted { - static inline constexpr size_t SIZEOF_INNER_ARCHIVE_FILE = std::max(sizeof(CInnerArchiveFile), sizeof(CInnerArchiveFile)); - static inline constexpr size_t ALIGNOF_INNER_ARCHIVE_FILE = std::max(alignof(CInnerArchiveFile), alignof(CInnerArchiveFile)); - - protected: + public: enum E_ALLOCATOR_TYPE { EAT_NONE = 0, @@ -65,60 +29,22 @@ class IFileArchive : public core::IReferenceCounted EAT_VIRTUAL_ALLOC, EAT_MALLOC }; - core::smart_refctd_ptr m_file; - system::logger_opt_smart_ptr m_logger; - - // TODO: This one is only required here because CFileView needs ISystem, must be removed when that's fixed - core::smart_refctd_ptr m_system; - - public: - IFileArchive(core::smart_refctd_ptr&& file, core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger) : - m_file(std::move(file)), m_system(std::move(system)), m_logger(std::move(logger)) {} - ~IFileArchive() - { - _NBL_ALIGNED_FREE(m_filesBuffer); - _NBL_ALIGNED_FREE(m_fileFlags); - } - - // List all files and directories in a specific dir of the archive - virtual core::vector listAssets(const char* asset_path) - { - constexpr auto isSubDir = [](path p, path root) -> bool - { - while (p != path()) { - if (p == root) { - return true; - } - p = p.parent_path(); - } - return false; - }; - core::vector res; - for (auto& entry : m_files) - { - if (isSubDir(entry.fullName, asset_path)) - { - res.push_back(entry.fullName); - } - } - return res; - } - - //! An entry in a list of files, can be a folder or a file. - struct SFileListEntry + //! An entry in a list of items, can be a folder or a file. + struct SListEntry { +#if 0 //! The name of the file /** If this is a file or folder in the virtual filesystem and the archive was created with the ignoreCase flag then the file name will be lower case. */ system::path name; - +#endif //! The name of the file including the path /** If this is a file or folder in the virtual filesystem and the archive was created with the ignoreDirs flag then it will be the same as Name. */ system::path fullName; //! The size of the file in bytes - uint32_t size; + size_t size; //! The ID of the file in an archive /** This is used to link the FileList entry to extra info held about this @@ -128,37 +54,40 @@ class IFileArchive : public core::IReferenceCounted //! FileOffset inside an archive uint32_t offset; - + // `EAT_NONE` for directories E_ALLOCATOR_TYPE allocatorType; //! The == operator is provided so that CFileList can slowly search the list! - inline bool operator ==(const struct SFileListEntry& other) const + inline bool operator ==(const struct SListEntry& other) const { - return core::strcmpi(fullName.string(), other.fullName.string()) == 0; + return fullName.string()==other.fullName.string(); } //! The < operator is provided so that CFileList can sort and quickly search the list. - inline bool operator <(const struct SFileListEntry& other) const + inline bool operator<(const struct SListEntry& other) const { - return fullName < other.fullName; + return fullName listAssets() const {return {m_items.data(),m_items.data()+m_items.size()};} + + // List all files and directories in a specific dir of the archive + core::SRange listAssets(const path& asset_path) const; + struct SOpenFileParams { - std::filesystem::path filename; - std::filesystem::path absolutePath; + path filename; + path absolutePath; std::string_view password; }; - - std::mutex fileMutex; - std::atomic_flag* m_fileFlags = nullptr; - std::byte* m_filesBuffer = nullptr; - +#if 0 core::smart_refctd_ptr readFile(const SOpenFileParams& params) { auto index = getIndexByPath(params.filename); if (index == -1) return nullptr; - switch (this->getFileType(index)) + switch (this->listAssets(index)) { case EAT_NULL: return getFile_impl(params, index); @@ -186,34 +115,23 @@ class IFileArchive : public core::IReferenceCounted { return m_files[index].allocatorType; } - template - core::smart_refctd_ptr> getFile_impl(const SOpenFileParams& params, const uint32_t index) - { - std::unique_lock lock(fileMutex); - - auto* file = reinterpret_cast*>(m_filesBuffer + index * SIZEOF_INNER_ARCHIVE_FILE); - // intentionally calling grab() on maybe-not-existing object - const auto oldRefcount = file->grab(); - - if (oldRefcount == 0) // need to construct - { - m_fileFlags[index].wait(true); //what should the param of wait be? - new (file, &m_fileFlags[index]) CInnerArchiveFile(static_cast*>(readFile_impl(params).get()), &m_fileFlags[index]); - } - return core::smart_refctd_ptr>(file, core::dont_grab); - } - const core::vector& getArchivedFiles() const { return m_files; } +#endif + // IFile* asFile() { return m_file.get(); } const IFile* asFile() const { return m_file.get(); } - protected: - void setFlagsVectorSize(size_t fileCount); + protected: + IFileArchive(core::smart_refctd_ptr&& file, system::logger_opt_smart_ptr&& logger) : + m_file(std::move(file)), m_logger(std::move(logger)) + { + } +/* virtual void addItem(const system::path& fullPath, uint32_t offset, uint32_t size, E_ALLOCATOR_TYPE allocatorType, uint32_t id = 0) { SFileListEntry entry; - entry.ID = id ? id : m_files.size(); + entry.ID = id ? id : m_items.size(); entry.offset = offset; entry.size = size; entry.name = fullPath; @@ -222,52 +140,39 @@ class IFileArchive : public core::IReferenceCounted core::deletePathFromFilename(entry.name); - m_files.insert(std::lower_bound(m_files.begin(), m_files.end(), entry), entry); - } - size_t read_blocking(system::IFile* file, void* buffer, size_t offset, size_t size) - { - return file->read_impl(buffer, offset, size); + m_items.insert(std::lower_bound(m_items.begin(), m_items.end(), entry), entry); } - size_t write_blocking(system::IFile* file, void* buffer, size_t offset, size_t size) - { - return file->write_impl(buffer, offset, size); - } - core::vector m_files; +*/ + // files and directories + core::vector m_items; + core::smart_refctd_ptr m_file; + system::logger_opt_smart_ptr m_logger; }; class IArchiveLoader : public core::IReferenceCounted { -protected: - system::logger_opt_smart_ptr m_logger; + public: + IArchiveLoader(system::logger_opt_smart_ptr&& logger) : m_logger(std::move(logger)) {} - // TODO: This one is only required here because CFileView needs ISystem, must be removed when that's fixed - core::smart_refctd_ptr m_system; -public: - IArchiveLoader(core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger) : - m_logger(std::move(logger)), m_system(std::move(system)) {} - //! Check if the file might be loaded by this class - /** This check may look into the file. - \param file File handle to check. - \return True if file seems to be loadable. */ - virtual bool isALoadableFileFormat(IFile* file) const = 0; + //! Check if the file might be loaded by this class + /** This check may look into the file. + \param file File handle to check. + \return True if file seems to be loadable. */ + virtual bool isALoadableFileFormat(IFile* file) const = 0; - //! Returns an array of string literals terminated by nullptr - virtual const char** getAssociatedFileExtensions() const = 0; + //! Returns an array of string literals terminated by nullptr + virtual const char** getAssociatedFileExtensions() const = 0; - //! Creates an archive from the file - /** \param file File handle to use. - \return Pointer to newly created archive, or 0 upon error. */ - core::smart_refctd_ptr createArchive(core::smart_refctd_ptr&& file, const std::string_view& password = "") const - { - if (!(file->getFlags() & IFile::ECF_READ)) - return nullptr; + //! Creates an archive from the file + /** \param file File handle to use. + \return Pointer to newly created archive, or 0 upon error. */ + core::smart_refctd_ptr createArchive(core::smart_refctd_ptr&& file, const std::string_view& password = "") const; - return createArchive_impl(std::move(file), password); - } + protected: + virtual core::smart_refctd_ptr createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const = 0; -protected: - virtual core::smart_refctd_ptr createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const = 0; + system::logger_opt_smart_ptr m_logger; }; } // end namespace nbl::system diff --git a/include/nbl/system/IFileBase.h b/include/nbl/system/IFileBase.h index 2e521166cb..f4ac33a560 100644 --- a/include/nbl/system/IFileBase.h +++ b/include/nbl/system/IFileBase.h @@ -65,7 +65,6 @@ class IFileBase : public core::IReferenceCounted // this is an abstract interface class so this stays protected explicit IFileBase(path&& _filename, const core::bitflag _flags) : m_filename(std::move(_filename)), m_flags(_flags) {} - explicit IFileBase(const path& _filename, const core::bitflag _flags) : m_filename(_filename), m_flags(_flags) {} private: path m_filename; diff --git a/include/nbl/system/IFileViewAllocator.h b/include/nbl/system/IFileViewAllocator.h index b2976c4150..a1fcb6bb7a 100644 --- a/include/nbl/system/IFileViewAllocator.h +++ b/include/nbl/system/IFileViewAllocator.h @@ -7,17 +7,17 @@ namespace nbl::system { -// This interface class provides the callbacks for `CFileView` which creates a mapped file over some memory -class IFileViewAllocator -{ + // This interface class provides the callbacks for `CFileView` which creates a mapped file over some memory + class IFileViewAllocator + { public: virtual void* alloc(size_t size) = 0; virtual bool dealloc(void* data, size_t size) = 0; -}; + }; -// Regular old file in RAM -class CPlainHeapAllocator : public IFileViewAllocator -{ + // Regular old file in RAM + class CPlainHeapAllocator : public IFileViewAllocator + { public: void* alloc(size_t size) override { @@ -28,12 +28,12 @@ class CPlainHeapAllocator : public IFileViewAllocator free(data); return true; } -}; + }; -// This allocator is useful to create an `IFile` over memory that already contains something or is owned by some other component -// e.g. memory mapped IGPUBuffer, string_view or a string, or buffers handed out by other APIs -class CNullAllocator : public IFileViewAllocator -{ + // This allocator is useful to create an `IFile` over memory that already contains something or is owned by some other component + // e.g. memory mapped IGPUBuffer, string_view or a string, or buffers handed out by other APIs + class CNullAllocator : public IFileViewAllocator + { public: void* alloc(size_t size) override { @@ -43,18 +43,17 @@ class CNullAllocator : public IFileViewAllocator { return true; } -}; - -} + }; #ifdef _NBL_PLATFORM_WINDOWS_ #include - using VirtualMemoryAllocator = nbl::system::CFileViewVirtualAllocatorWin32; + using VirtualMemoryAllocator = CFileViewVirtualAllocatorWin32; #elif defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) #include - using VirtualMemoryAllocator = nbl::system::CFileViewVirtualAllocatorPOSIX; + using VirtualMemoryAllocator = CFileViewVirtualAllocatorPOSIX; #else #error "Unsupported platform!" #endif +} #endif \ No newline at end of file diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index d16a3015cc..6432c47cb6 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -10,7 +10,7 @@ #include #include "nbl/system/ICancellableAsyncQueueDispatcher.h" -#include "nbl/system/IFileBase.h" +#include "nbl/system/IFileArchive.h" namespace nbl::system @@ -18,8 +18,6 @@ namespace nbl::system class IFile; class ISystemFile; -class IFileArchive; -class IArchiveLoader; class ISystem : public core::IReferenceCounted { @@ -128,7 +126,14 @@ class ISystem : public core::IReferenceCounted } // - void addArchiveLoader(core::smart_refctd_ptr&& loader); + inline void addArchiveLoader(core::smart_refctd_ptr&& loader) + { + const char** exts = loader->getAssociatedFileExtensions(); + uint32_t i = 0u; + while (const char* e = exts[i++]) + m_loaders.perFileExt.insert(e, core::smart_refctd_ptr(loader)); + m_loaders.vector.push_back(std::move(loader)); + } // `flags` is the intended usage of the file bool exists(const system::path& filename, const core::bitflag flags) const; @@ -238,6 +243,9 @@ class ISystem : public core::IReferenceCounted // core::smart_refctd_ptr impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const; + // given an absolute `path` find the archive it belongs to + std::pair findFileInArchive(const system::path& _path) const; + // core::smart_refctd_ptr getFileFromArchive(const system::path& path); @@ -248,15 +256,6 @@ class ISystem : public core::IReferenceCounted core::vector > vector; //! The key is file extension core::CMultiObjectCache,std::vector> perFileExt; - - void pushToVector(core::smart_refctd_ptr&& _loader) - { - vector.push_back(std::move(_loader)); - } - void eraseFromVector(decltype(vector)::const_iterator _loaderItr) - { - vector.erase(_loaderItr); - } } m_loaders; // core::CMultiObjectCache> m_cachedArchiveFiles; diff --git a/include/nbl/system/ISystemFile.h b/include/nbl/system/ISystemFile.h index 402c1b9930..5b366d4a9e 100644 --- a/include/nbl/system/ISystemFile.h +++ b/include/nbl/system/ISystemFile.h @@ -8,51 +8,8 @@ namespace nbl::system { -class ISystemFile : public IFile, private ISystem::IFutureManipulator +class ISystemFile : public IFile { - public: - // - inline void read(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) final override - { - if (getFlags()&ECF_MAPPABLE) - { - const size_t size = getSize(); - if (offset+sizeToRead>size) - sizeToRead = size-offset; - memcpy(buffer,reinterpret_cast(m_mappedPtr)+offset,sizeToRead); - fake_notify(fut,sizeToRead); - } - else - { - ISystem::SRequestParams_READ params; - params.buffer = buffer; - params.file = this; - params.offset = offset; - params.size = sizeToRead; - m_system->m_dispatcher.request(fut,params); - } - } - inline void write(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) final override - { - if (getFlags()&ECF_MAPPABLE) - { - // TODO: growable mappings - if (offset+sizeToWrite>getSize()) - sizeToWrite = getSize()-offset; - memcpy(reinterpret_cast(m_mappedPtr)+offset,buffer,sizeToWrite); - fake_notify(fut,sizeToWrite); - } - else - { - ISystem::SRequestParams_WRITE params; - params.buffer = buffer; - params.file = this; - params.offset = offset; - params.size = sizeToWrite; - m_system->m_dispatcher.request(fut,params); - } - } - protected: // the ISystem is the factory, so this stays protected explicit ISystemFile( @@ -61,22 +18,37 @@ class ISystemFile : public IFile, private ISystem::IFutureManipulator const core::bitflag _flags, void* const _mappedPtr ) : IFile(std::move(_filename),_flags), m_system(std::move(_system)), m_mappedPtr(_mappedPtr) {} - explicit ISystemFile( - core::smart_refctd_ptr&& _system, - const path& _filename, - const core::bitflag _flags, - void* const _mappedPtr - ) : IFile(std::move(_filename),_flags), m_system(_system), m_mappedPtr(_mappedPtr) {} // inline void* getMappedPointer_impl() override {return m_mappedPtr;} inline const void* getMappedPointer_impl() const override {return m_mappedPtr;} + + // + inline void unmappedRead(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) override final + { + ISystem::SRequestParams_READ params; + params.buffer = buffer; + params.file = this; + params.offset = offset; + params.size = sizeToRead; + m_system->m_dispatcher.request(fut,params); + } + inline void unmappedWrite(ISystem::future_t& fut, const void* buffer, size_t offset, size_t sizeToWrite) override final + { + ISystem::SRequestParams_WRITE params; + params.buffer = buffer; + params.file = this; + params.offset = offset; + params.size = sizeToWrite; + m_system->m_dispatcher.request(fut,params); + } // - //friend class ISystem::ICaller; + //friend class ISystem::CAsyncQueue; virtual size_t asyncRead(void* buffer, size_t offset, size_t sizeToRead) = 0; virtual size_t asyncWrite(const void* buffer, size_t offset, size_t sizeToWrite) = 0; + core::smart_refctd_ptr m_system; void* m_mappedPtr; }; diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index 63f4383c4c..aab2e3e234 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -1,5 +1,5 @@ #include "nbl/system/ISystem.h" -#include "nbl/system/IFileArchive.h" +#include "nbl/system/ISystemFile.h" #include "nbl/system/CArchiveLoaderZip.h" #include "nbl/system/CArchiveLoaderTar.h" @@ -11,8 +11,10 @@ using namespace nbl::system; ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatcher(std::move(caller)) { - addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); - addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); +#if 0 + addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this),nullptr)); + addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this),nullptr)); +#endif } core::smart_refctd_ptr ISystem::loadBuiltinData(const std::string& builtinPath) const @@ -57,15 +59,6 @@ core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::s return nullptr; } -void ISystem::addArchiveLoader(core::smart_refctd_ptr&& loader) -{ - const char** exts = loader->getAssociatedFileExtensions(); - uint32_t i = 0u; - while (const char* e = exts[i++]) - m_loaders.perFileExt.insert(e, core::smart_refctd_ptr(loader)); - m_loaders.pushToVector(std::move(loader)); -} - bool ISystem::exists(const system::path& filename, const core::bitflag flags) const { const bool writeUsage = flags.value&IFile::ECF_WRITE; @@ -180,7 +173,7 @@ bool ISystem::copy(const system::path& from, const system::path& to) if (!readF || !readF->getMappedPointer() || !writeF) return false; - IFile::success bytesWritten; + IFile::success_t bytesWritten; writeF->write(bytesWritten,readF->getMappedPointer(),0,readF->getSize()); return bool(bytesWritten); }; @@ -294,8 +287,53 @@ void ISystem::unmount(const IFileArchive* archive, const system::path& pathAlias m_cachedArchiveFiles.removeObject(dummy,pathAlias); } +std::pair ISystem::findFileInArchive(const system::path& _path) const +{ + system::path path = std::filesystem::exists(_path) ? system::path(std::filesystem::canonical(_path.parent_path()).generic_string()) : _path.parent_path(); + + // going up the directory tree + while (!path.empty() && path.parent_path() != path) + { + system::path realPath = std::filesystem::exists(path) ? system::path(std::filesystem::canonical(path).generic_string()) : path; + auto archives = m_cachedArchiveFiles.findRange(realPath); + + for (auto& archive : archives) + { +#if 0 + auto relative = std::filesystem::relative(_path, path); + auto files = archive.second->listAssets(); + + const auto itemToFind = IFileArchive::SListEntry{ relative, relative, 0 }; + bool hasFile = std::binary_search(files.begin(), files.end(), itemToFind, [](const IFileArchive::SFileListEntry& l, const IFileArchive::SFileListEntry& r) { return l.fullName == r.fullName; }); + auto f = archive.second->asFile(); + if (f) + { + auto realPath = f->getFileName(); + auto absolute = (realPath / relative).generic_string(); + if (hasFile) + { + auto f = archive.second; + return { f.get(),{relative,_path,""} }; + } + } + else + { + if (hasFile) + { + auto f = archive.second; + return { f.get(),{relative,_path,""} }; + } + } +#endif + } + path = path.parent_path(); + } + return { nullptr,{} }; +} + core::smart_refctd_ptr ISystem::getFileFromArchive(const system::path& path) { +#if 0 // given an absolute `path` find the archive it belongs to std::pair found = {nullptr,{}}; system::path path = std::filesystem::exists(path) ? std::filesystem::canonical(path.parent_path()):path.parent_path(); @@ -341,6 +379,8 @@ core::smart_refctd_ptr ISystem::getFileFromArchive(const system::path& pa auto& params = std::get(found); // TODO: support passwords return archive->readFile(params); +#endif + return nullptr; } @@ -357,63 +397,18 @@ void ISystem::CAsyncQueue::process_request(SRequestType& req) case ERT_READ: { auto& p = std::get(req.params); - base_t::notify_future(req, m_caller->read(p.file, p.buffer, p.offset, p.size)); + base_t::notify_future(req,p.file->asyncRead(p.buffer, p.offset, p.size)); } break; case ERT_WRITE: { auto& p = std::get(req.params); - base_t::notify_future(req, m_caller->write(p.file, p.buffer, p.offset, p.size)); + base_t::notify_future(req,p.file->asyncWrite(p.buffer, p.offset, p.size)); } break; } } -#if 0 - -// given an absolute `path` find the archive it belongs to -std::pair ISystem::findFileInArchive(const system::path& _path) const -{ - system::path path = std::filesystem::exists(_path) ? system::path(std::filesystem::canonical(_path.parent_path()).generic_string()) : _path.parent_path(); - - // going up the directory tree - while (!path.empty() && path.parent_path() != path) - { - system::path realPath = std::filesystem::exists(path) ? system::path(std::filesystem::canonical(path).generic_string()) : path; - auto archives = m_cachedArchiveFiles.findRange(realPath); - - for (auto& archive : archives) - { - auto relative = std::filesystem::relative(_path, path); - auto files = archive.second->getArchivedFiles(); - auto itemToFind = IFileArchive::SFileListEntry{ relative, relative, 0 }; - bool hasFile = std::binary_search(files.begin(), files.end(), itemToFind, [](const IFileArchive::SFileListEntry& l, const IFileArchive::SFileListEntry& r) { return l.fullName == r.fullName; }); - auto f = archive.second->asFile(); - if (f) - { - auto realPath = f->getFileName(); - auto absolute = (realPath / relative).generic_string(); - if (hasFile) - { - auto f = archive.second; - return { f.get(),{relative,_path,""} }; - } - } - else - { - if (hasFile) - { - auto f = archive.second; - return { f.get(),{relative,_path,""} }; - } - } - } - path = path.parent_path(); - } - return { nullptr,{} }; -} -#endif - bool ISystem::ICaller::invalidateMapping(IFile* file, size_t offset, size_t size) { const auto flags = file->getFlags(); diff --git a/src/nbl/system/ISystemFile.cpp b/src/nbl/system/ISystemFile.cpp deleted file mode 100644 index ce526ca18d..0000000000 --- a/src/nbl/system/ISystemFile.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (C) 2021 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h -#include "nbl/system/ISystemFile.h" - -using namespace nbl::system; - - - -#include "nbl/core/definitions.h" \ No newline at end of file From 704d8921b6b18a755b3de214a9ad0d0736316d36 Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 4 Mar 2022 13:20:42 +0100 Subject: [PATCH 41/91] make the file logger work with Nabla files --- include/nbl/system/CFileLogger.h | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/include/nbl/system/CFileLogger.h b/include/nbl/system/CFileLogger.h index 95c8c0696d..85629d0b2d 100644 --- a/include/nbl/system/CFileLogger.h +++ b/include/nbl/system/CFileLogger.h @@ -1,10 +1,8 @@ #ifndef _NBL_SYSTEM_C_FILE_LOGGER_INCLUDED_ #define _NBL_SYSTEM_C_FILE_LOGGER_INCLUDED_ -#include -#include - -#include "IThreadsafeLogger.h" +#include "nbl/system/IThreadsafeLogger.h" +#include "nbl/system/IFile.h" namespace nbl::system { @@ -12,23 +10,22 @@ namespace nbl::system class CFileLogger : public IThreadsafeLogger { public: - static core::smart_refctd_ptr create(const std::filesystem::path& outputFileName) - { - auto ret = core::smart_refctd_ptr(new CFileLogger(outputFileName)); - if (!ret->m_ofs.is_open()) return nullptr; - return ret; - } - ~CFileLogger() + CFileLogger(core::smart_refctd_ptr&& _file, const core::bitflag logLevelMask=ILogger::defaultLogMask()) + : IThreadsafeLogger(logLevelMask), m_file(std::move(_file)) { } - private: - std::ofstream m_ofs; - CFileLogger(const std::filesystem::path& outputFileName, core::bitflag logLevelMask = ILogger::defaultLogMask()) : IThreadsafeLogger(logLevelMask), m_ofs(outputFileName, std::ios_base::app){} + + protected: + ~CFileLogger() = default; virtual void threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override { - m_ofs << constructLogString(fmt, logLevel, args).data() << std::flush; + const auto str = constructLogString(fmt, logLevel, args); + ISystem::future_t future; + m_file->write(future,str.data(),m_file->getSize(),str.length()); } + + core::smart_refctd_ptr m_file; }; } From 22cc5e3acae802530eba7116462a4d8e021d45e7 Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 4 Mar 2022 13:21:31 +0100 Subject: [PATCH 42/91] fix horrible circular references and self namespace nesting --- .../system/CFileViewVirtualAllocatorPOSIX.h | 13 ++----- .../system/CFileViewVirtualAllocatorWin32.h | 4 -- include/nbl/system/IFileViewAllocator.h | 39 ++++++++++--------- .../system/CFileViewVirtualAllocatorPOSIX.cpp | 2 +- .../system/CFileViewVirtualAllocatorWin32.cpp | 2 +- 5 files changed, 27 insertions(+), 33 deletions(-) diff --git a/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h b/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h index ec17a11a31..2100612884 100644 --- a/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h +++ b/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h @@ -1,21 +1,16 @@ #ifndef _NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_POSIX_H_INCLUDED_ #define _NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_POSIX_H_INCLUDED_ - -#include "nbl/system/IFileViewAllocator.h" - - -#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) -namespace nbl::system +namespace nbl::system { - +#if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) class CFileViewVirtualAllocatorPOSIX : public IFileViewAllocator { public: void* alloc(size_t size) override; bool dealloc(void* data, size_t size) override; }; - -} #endif +} + #endif \ No newline at end of file diff --git a/include/nbl/system/CFileViewVirtualAllocatorWin32.h b/include/nbl/system/CFileViewVirtualAllocatorWin32.h index 9478570db2..dda0733f26 100644 --- a/include/nbl/system/CFileViewVirtualAllocatorWin32.h +++ b/include/nbl/system/CFileViewVirtualAllocatorWin32.h @@ -1,10 +1,6 @@ #ifndef _NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_WIN32_H_INCLUDED_ #define _NBL_SYSTEM_C_FILE_VIEW_VIRTUAL_ALLOCATOR_WIN32_H_INCLUDED_ - -#include "nbl/system/IFileViewAllocator.h" - - namespace nbl::system { #ifdef _NBL_PLATFORM_WINDOWS_ diff --git a/include/nbl/system/IFileViewAllocator.h b/include/nbl/system/IFileViewAllocator.h index a1fcb6bb7a..99e312fcb7 100644 --- a/include/nbl/system/IFileViewAllocator.h +++ b/include/nbl/system/IFileViewAllocator.h @@ -1,23 +1,25 @@ #ifndef _NBL_SYSTEM_I_FILE_ALLOCATOR_H_INCLUDED_ #define _NBL_SYSTEM_I_FILE_ALLOCATOR_H_INCLUDED_ +#include "nbl/core/declarations.h" + #include #include namespace nbl::system { - // This interface class provides the callbacks for `CFileView` which creates a mapped file over some memory - class IFileViewAllocator - { +// This interface class provides the callbacks for `CFileView` which creates a mapped file over some memory +class IFileViewAllocator +{ public: virtual void* alloc(size_t size) = 0; virtual bool dealloc(void* data, size_t size) = 0; - }; +}; - // Regular old file in RAM - class CPlainHeapAllocator : public IFileViewAllocator - { +// Regular old file in RAM +class CPlainHeapAllocator : public IFileViewAllocator +{ public: void* alloc(size_t size) override { @@ -28,12 +30,12 @@ namespace nbl::system free(data); return true; } - }; +}; - // This allocator is useful to create an `IFile` over memory that already contains something or is owned by some other component - // e.g. memory mapped IGPUBuffer, string_view or a string, or buffers handed out by other APIs - class CNullAllocator : public IFileViewAllocator - { +// This allocator is useful to create an `IFile` over memory that already contains something or is owned by some other component +// e.g. memory mapped IGPUBuffer, string_view or a string, or buffers handed out by other APIs +class CNullAllocator : public IFileViewAllocator +{ public: void* alloc(size_t size) override { @@ -43,17 +45,18 @@ namespace nbl::system { return true; } - }; +}; + +} #ifdef _NBL_PLATFORM_WINDOWS_ -#include - using VirtualMemoryAllocator = CFileViewVirtualAllocatorWin32; +#include "nbl/system/CFileViewVirtualAllocatorWin32.h" + using VirtualMemoryAllocator = nbl::system::CFileViewVirtualAllocatorWin32; #elif defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) -#include - using VirtualMemoryAllocator = CFileViewVirtualAllocatorPOSIX; +#include "nbl/system/CFileViewVirtualAllocatorPOSIX.h" + using VirtualMemoryAllocator = nbl::system::CFileViewVirtualAllocatorPOSIX; #else #error "Unsupported platform!" #endif -} #endif \ No newline at end of file diff --git a/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp b/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp index 3fe17e81f4..867ff8f958 100644 --- a/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp +++ b/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp @@ -1,4 +1,4 @@ -#include "nbl/system/CFileViewVirtualAllocatorPOSIX.h" +#include "nbl/system/IFileViewAllocator.h" using namespace nbl::system; diff --git a/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp b/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp index f480ef6ddb..fca7763fe2 100644 --- a/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp +++ b/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp @@ -1,4 +1,4 @@ -#include "nbl/system/CFileViewVirtualAllocatorWin32.h" +#include "nbl/system/IFileViewAllocator.h" using namespace nbl::system; From 079334a6a0934daa8b5ac812afd103ae72046da4 Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 4 Mar 2022 14:05:49 +0100 Subject: [PATCH 43/91] reorganise Android and Linux Also integrate most of 9d86c03edf73e8aed0bbcaaf7d09433baae62282 --- include/nbl/system/CSystemAndroid.h | 49 +++++++---------- include/nbl/system/CSystemLinux.h | 19 +++++-- .../nbl/system/ISystemPOSIX.h | 4 +- src/nbl/CMakeLists.txt | 10 ++-- src/nbl/system/CSystemAndroid.cpp | 52 +++++++++++++++++++ src/nbl/system/CSystemLinux.cpp | 27 ++++++++++ ...SystemCallerPOSIX.cpp => ISystemPOSIX.cpp} | 4 +- 7 files changed, 124 insertions(+), 41 deletions(-) rename src/nbl/system/CSystemCallerPOSIX.h => include/nbl/system/ISystemPOSIX.h (82%) create mode 100644 src/nbl/system/CSystemAndroid.cpp create mode 100644 src/nbl/system/CSystemLinux.cpp rename src/nbl/system/{CSystemCallerPOSIX.cpp => ISystemPOSIX.cpp} (89%) diff --git a/include/nbl/system/CSystemAndroid.h b/include/nbl/system/CSystemAndroid.h index 877151da4e..0dfcd71c89 100644 --- a/include/nbl/system/CSystemAndroid.h +++ b/include/nbl/system/CSystemAndroid.h @@ -1,39 +1,30 @@ #ifndef _NBL_SYSTEM_C_SYSTEM_ANDROID_H_INCLUDED_ #define _NBL_SYSTEM_C_SYSTEM_ANDROID_H_INCLUDED_ -#ifdef _NBL_PLATFORM_ANDROID_ + #include "nbl/system/ISystem.h" -#include "nbl/system/CAPKResourcesArchive.h" -#include -#include + + namespace nbl::system { - class CSystemAndroid final : public ISystem - { - ANativeActivity* nativeActivity = nullptr; - core::smart_refctd_ptr androidAssetArchive = nullptr; - JNIEnv* env; +#ifdef _NBL_PLATFORM_ANDROID_ +#include "nbl/system/ISystemPOSIX.h" + +struct ANativeActivity; +struct JNIEnv; + +class CSystemAndroid final : public ISystemPOSIX +{ + ANativeActivity* m_nativeActivity; + JNIEnv* m_jniEnv; public: - CSystemAndroid(core::smart_refctd_ptr&& caller, ANativeActivity* activity, JNIEnv* jni, const system::path& APKResourcesPath) : - ISystem(std::move(caller)), nativeActivity(activity), env(jni) - { - auto archive = core::make_smart_refctd_ptr( - core::smart_refctd_ptr(this), - nullptr, - activity->assetManager, - nativeActivity, - env - ); - m_cachedArchiveFiles.insert(APKResourcesPath, std::move(archive)); - - } - SystemInfo getSystemInfo() const override - { - assert(false); // TODO: @sadiuk - return SystemInfo(); - } - }; -} + CSystemAndroid(ANativeActivity* activity, JNIEnv* jni, const system::path& APKResourcesPath); + + // + SystemInfo getSystemInfo() const override; +}; + #endif +} #endif \ No newline at end of file diff --git a/include/nbl/system/CSystemLinux.h b/include/nbl/system/CSystemLinux.h index 884d75ab74..2acf5e3fc4 100644 --- a/include/nbl/system/CSystemLinux.h +++ b/include/nbl/system/CSystemLinux.h @@ -1,13 +1,22 @@ #ifndef _NBL_SYSTEM_C_SYSTEM_LINUX_H_INCLUDED_ #define _NBL_SYSTEM_C_SYSTEM_LINUX_H_INCLUDED_ -#ifdef _NBL_PLATFORM_LINUX_ + + #include "nbl/system/ISystem.h" + namespace nbl::system { - class CSystemLinux : public ISystem - { +#ifdef _NBL_PLATFORM_LINUX_ +#include "nbl/system/ISystemPOSIX.h" + +class CSystemLinux final : public ISystemPOSIX +{ + public: + CSystemLinux() : ISystemPOSIX() {} - }; -} + SystemInfo getSystemInfo() const override; +}; #endif +} + #endif \ No newline at end of file diff --git a/src/nbl/system/CSystemCallerPOSIX.h b/include/nbl/system/ISystemPOSIX.h similarity index 82% rename from src/nbl/system/CSystemCallerPOSIX.h rename to include/nbl/system/ISystemPOSIX.h index ec03051d0d..0968d21b92 100644 --- a/src/nbl/system/CSystemCallerPOSIX.h +++ b/include/nbl/system/ISystemPOSIX.h @@ -1,7 +1,7 @@ #ifndef _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_ #define _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_ -#include "ISystem.h" +#include "nbl/system/ISystem.h" namespace nbl::system { @@ -15,6 +15,8 @@ class ISystemPOSIX : public ISystem public: core::smart_refctd_ptr createFile_impl(const std::filesystem::path& filename, core::bitflag flags) override final; }; + + ISystemPOSIX() : ISystem(core::make_smart_refctd_ptr(this)) {} }; #endif diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index b8f9f27a0b..51800ce982 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -189,17 +189,19 @@ set(NBL_CORE_SOURCES ) set(NBL_SYSTEM_SOURCES ${NBL_ROOT_PATH}/src/nbl/system/IFileBase.cpp - ${NBL_ROOT_PATH}/src/nbl/system/CSystemWin32.cpp - ${NBL_ROOT_PATH}/src/nbl/system/CFileWin32.cpp - ${NBL_ROOT_PATH}/src/nbl/system/CFilePOSIX.cpp ${NBL_ROOT_PATH}/src/nbl/system/ILogger.cpp ${NBL_ROOT_PATH}/src/nbl/system/CArchiveLoaderZip.cpp ${NBL_ROOT_PATH}/src/nbl/system/CArchiveLoaderTar.cpp ${NBL_ROOT_PATH}/src/nbl/system/ISystem.cpp ${NBL_ROOT_PATH}/src/nbl/system/IFileArchive.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CStdoutLoggerAndroid.cpp ${NBL_ROOT_PATH}/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp ${NBL_ROOT_PATH}/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp - ${NBL_ROOT_PATH}/src/nbl/system/CStdoutLoggerAndroid.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CFileWin32.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CFilePOSIX.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CSystemWin32.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CSystemAndroid.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CSystemLinux.cpp ) set(NBL_UI_SOURCES ${NBL_ROOT_PATH}/src/nbl/ui/CWindowWin32.cpp diff --git a/src/nbl/system/CSystemAndroid.cpp b/src/nbl/system/CSystemAndroid.cpp new file mode 100644 index 0000000000..4bce37c980 --- /dev/null +++ b/src/nbl/system/CSystemAndroid.cpp @@ -0,0 +1,52 @@ +#include "nbl/system/CSystemAndroid.h" + +using namespace nbl::system; + +#ifdef _NBL_PLATFORM_ANDROID_ +#include "nbl/system/CAPKResourcesArchive.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +CSystemAndroid::CSystemAndroid(ANativeActivity* activity, JNIEnv* jni, const system::path& APKResourcesPath) : + ISystemPOSIX(), m_nativeActivity(activity), m_jniEnv(jni) +{ + addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); + m_cachedArchiveFiles.insert(APKResourcesPath,core::make_smart_refctd_ptr( + core::smart_refctd_ptr(this), + nullptr, + activity->assetManager, + nativeActivity, + env + )); +} + +ISystem::SystemInfo CSystemAndroid::getSystemInfo() const +{ + SystemInfo info; + // TODO: hardcoded + info.cpuFrequency = 1100; + info.totalMemory = 4ull<<30ull; + info.availableMemory = 2ull<<30ull; + + struct fb_var_screeninfo fb_var; + int fd = open("/dev/graphics/fb0", O_RDONLY); + ioctl(fd, FBIOGET_VSCREENINFO, &fb_var); + close(fd); + info.desktopResX = fb_var.width; + info.desktopResY = fb_var.height; + + char sdk_ver_str[92]; + __system_property_get("ro.build.version.sdk", sdk_ver_str); + info.OSFullName = std::string("Android ") + sdk_ver_str; + + return info; +} + +#endif \ No newline at end of file diff --git a/src/nbl/system/CSystemLinux.cpp b/src/nbl/system/CSystemLinux.cpp new file mode 100644 index 0000000000..aed6ea2cf9 --- /dev/null +++ b/src/nbl/system/CSystemLinux.cpp @@ -0,0 +1,27 @@ +#include "nbl/system/CSystemLinux.h" + +using namespace nbl; +using namespace nbl::system; + +#ifdef _NBL_PLATFORM_LINUX_ +ISystem::SystemInfo CSystemLinux::getSystemInfo() const +{ + SystemInfo info; + + // TODO + info.cpuFrequencyHz = 3000000000u; + + sysinfo linuxSystemInfo; + sysinfo(&linuxSystemInfo); + info.totalMemory = linuxSystemInfo.totalram; + info.availableMemory = linuxSystemInfo.freeram; + info.totalMemory *= linuxSystemInfo.mem_unit; + info.availableMemory *= linuxSystemInfo.mem_unit; + + // TODO + info.desktopResX = 0xdeadbeefu; + info.desktopResY = 0xdeadbeefu; + + return info; +} +#endif \ No newline at end of file diff --git a/src/nbl/system/CSystemCallerPOSIX.cpp b/src/nbl/system/ISystemPOSIX.cpp similarity index 89% rename from src/nbl/system/CSystemCallerPOSIX.cpp rename to src/nbl/system/ISystemPOSIX.cpp index b05634a647..3ff3217b3f 100644 --- a/src/nbl/system/CSystemCallerPOSIX.cpp +++ b/src/nbl/system/ISystemPOSIX.cpp @@ -1,4 +1,4 @@ -#include "nbl/system/CSystemCallerPOSIX.h" +#include "nbl/system/ISystemPOSIX.h" #include "nbl/system/CFilePOSIX.h" using namespace nbl; @@ -9,7 +9,7 @@ using namespace nbl::system; #include #include -core::smart_refctd_ptr ISystemPOSIX::CCaller::createFile_impl(const std::filesystem::path& filename, const core::bitflag flags) +core::smart_refctd_ptr ISystemPOSIX::CCaller::createFile_impl(const std::filesystem::path& filename, const core::bitflag flags) { const bool writeAccess = flags.value&IFile::ECF_WRITE; int createFlags = O_LARGEFILE|(writeAccess ? O_CREAT:0); From 9d07cc9c72bbc5effe7d34d099027817c548126d Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 4 Mar 2022 15:16:18 +0100 Subject: [PATCH 44/91] first example of proper CFileView usage --- include/nbl/system/CFileView.h | 6 +-- .../CGraphicsPipelineLoaderMTL.cpp | 41 +++++++++---------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/include/nbl/system/CFileView.h b/include/nbl/system/CFileView.h index 63789d9f88..003cf90895 100644 --- a/include/nbl/system/CFileView.h +++ b/include/nbl/system/CFileView.h @@ -46,8 +46,8 @@ class CFileView : public IFileView public: // constructor for making a file with memory already allocated by the allocator - CFileView(path&& _name, const core::bitflag _flags, void* buffer, const size_t fileSize, allocator_t&& _allocator) : - IFileView(std::move(sys),std::move(_name),_flags,buffer,fileSize), allocator(std::move(_allocator)) {} + CFileView(path&& _name, const core::bitflag _flags, void* buffer, const size_t fileSize, allocator_t&& _allocator={}) : + IFileView(std::move(_name),_flags,buffer,fileSize), allocator(std::move(_allocator)) {} // static inline core::smart_refctd_ptr> create(path&& _name, const core::bitflag _flags, size_t fileSize, allocator_t&& _allocator={}) @@ -55,7 +55,7 @@ class CFileView : public IFileView auto mem = reintepret_cast(_allocator.alloc(fileSize)); if (!mem) return nullptr; - auto retval = new CFileView(std::move(sys),_name,_flags,mem,fileSize,std::move(_allocator)); + auto retval = new CFileView(std::move(_name),_flags,mem,fileSize,std::move(_allocator)); return core::smart_refctd_ptr(retval,core::dont_grab); } diff --git a/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp b/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp index 76eb22e4b1..2b07ac70d3 100644 --- a/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp +++ b/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp @@ -3,16 +3,15 @@ // For conditions of distribution and use, see copyright notice in nabla.h #include "nbl/asset/asset.h" +#include "nbl/asset/interchange/CGraphicsPipelineLoaderMTL.h" +#include "nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h" +#include "nbl/asset/utils/CDerivativeMapCreator.h" #include #include #include -#include "nbl/asset/asset.h" -#include "nbl/asset/interchange/CGraphicsPipelineLoaderMTL.h" -#include "nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h" -#include "nbl/asset/utils/CDerivativeMapCreator.h" -#include "nbl/system/IFileViewAllocator.h" +#include "nbl/system/CFileView.h" #include "nbl/builtin/MTLdefaults.h" @@ -84,13 +83,12 @@ void CGraphicsPipelineLoaderMTL::initialize() } // default pipelines - constexpr std::string_view filename = "Nabla default MTL material"; - - auto default_mtl_file = core::make_smart_refctd_ptr>(core::smart_refctd_ptr(m_system), filename, system::IFile::ECF_READ_WRITE, strlen(DUMMY_MTL_CONTENT)); - - system::future future; - default_mtl_file->write(future, DUMMY_MTL_CONTENT, 0, strlen(DUMMY_MTL_CONTENT)); - future.get(); + auto default_mtl_file = core::make_smart_refctd_ptr>( + system::path("Nabla default MTL material"), + system::IFile::ECF_READ, + const_cast(DUMMY_MTL_CONTENT), + strlen(DUMMY_MTL_CONTENT) + ); SAssetLoadParams assetLoadParams; auto bundle = loadAsset(default_mtl_file.get(), assetLoadParams, &dfltOver); @@ -105,11 +103,9 @@ bool CGraphicsPipelineLoaderMTL::isALoadableFileFormat(system::IFile* _file, con std::string mtl; mtl.resize(_file->getSize()); - system::future future; - _file->read(future, mtl.data(), 0, _file->getSize()); - future.get(); - - return mtl.find("newmtl") != std::string::npos; + system::IFile::success_t success; + _file->read(success, mtl.data(), 0, _file->getSize()); + return success && mtl.find("newmtl")!=std::string::npos; } SAssetBundle CGraphicsPipelineLoaderMTL::loadAsset(system::IFile* _file, const IAssetLoader::SAssetLoadParams& _params, IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel) @@ -726,10 +722,11 @@ auto CGraphicsPipelineLoaderMTL::readMaterials(system::IFile* _file, const syste std::string mtl; size_t fileSize = _file->getSize(); mtl.resize(fileSize); - system::future fut; - - _file->read(fut, mtl.data(), 0, fileSize); - fut.get(); + + system::IFile::success_t success; + _file->read(success, mtl.data(), 0, fileSize); + if (!success) + return {}; const char* bufPtr = mtl.c_str(); const char* const bufEnd = mtl.c_str()+mtl.size(); @@ -868,7 +865,7 @@ auto CGraphicsPipelineLoaderMTL::readMaterials(system::IFile* _file, const syste { case 'f': // Tf - Transmitivity currMaterial->params.transmissionFilter = readRGB(); - sprintf(tmpbuf, "%s, %s: Detected Tf parameter, it won't be used in generated shader - fallback to alpha=0.5 instead", _file->getFileName().c_str(), currMaterial->name.c_str()); + sprintf(tmpbuf, "%s, %s: Detected Tf parameter, it won't be used in generated shader - fallback to alpha=0.5 instead", _file->getFileName().string().c_str(), currMaterial->name.c_str()); logger.log(tmpbuf, system::ILogger::ELL_WARNING); break; case 'r': // Tr, transparency = 1.0-d From e198a8e06c277e32060997787a8edbff38da22bb Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 4 Mar 2022 16:22:48 +0100 Subject: [PATCH 45/91] all loaders (importers) and writers (exporters) adjusted to the new API --- include/nbl/system/ISystemFile.h | 2 +- .../asset/interchange/CBufferLoaderBIN.cpp | 38 +- src/nbl/asset/interchange/CGLILoader.cpp | 40 +-- src/nbl/asset/interchange/CGLIWriter.cpp | 7 +- src/nbl/asset/interchange/CGLSLLoader.cpp | 10 +- src/nbl/asset/interchange/CGLSLLoader.h | 21 +- src/nbl/asset/interchange/CGLTFLoader.cpp | 25 +- src/nbl/asset/interchange/CImageLoaderJPG.cpp | 14 +- .../asset/interchange/CImageLoaderOpenEXR.cpp | 14 +- src/nbl/asset/interchange/CImageLoaderPNG.cpp | 17 +- src/nbl/asset/interchange/CImageLoaderTGA.cpp | 71 ++-- src/nbl/asset/interchange/CImageWriterJPG.cpp | 12 +- .../asset/interchange/CImageWriterOpenEXR.cpp | 340 +++++++++--------- src/nbl/asset/interchange/CImageWriterPNG.cpp | 11 +- src/nbl/asset/interchange/CImageWriterTGA.cpp | 36 +- .../asset/interchange/COBJMeshFileLoader.cpp | 10 +- .../asset/interchange/CPLYMeshFileLoader.cpp | 11 +- src/nbl/asset/interchange/CPLYMeshWriter.cpp | 28 +- src/nbl/asset/interchange/CSPVLoader.cpp | 7 +- src/nbl/asset/interchange/CSPVLoader.h | 16 +- .../asset/interchange/CSTLMeshFileLoader.cpp | 48 +-- src/nbl/asset/interchange/CSTLMeshWriter.cpp | 77 ++-- src/nbl/asset/utils/IGLSLCompiler.cpp | 41 +-- src/nbl/system/CSystemWin32.cpp | 2 +- src/nbl/system/IFileBase.cpp | 2 +- 25 files changed, 440 insertions(+), 460 deletions(-) diff --git a/include/nbl/system/ISystemFile.h b/include/nbl/system/ISystemFile.h index 5b366d4a9e..85f994d25f 100644 --- a/include/nbl/system/ISystemFile.h +++ b/include/nbl/system/ISystemFile.h @@ -44,7 +44,7 @@ class ISystemFile : public IFile } // - //friend class ISystem::CAsyncQueue; + friend class ISystem::CAsyncQueue; virtual size_t asyncRead(void* buffer, size_t offset, size_t sizeToRead) = 0; virtual size_t asyncWrite(const void* buffer, size_t offset, size_t sizeToWrite) = 0; diff --git a/src/nbl/asset/interchange/CBufferLoaderBIN.cpp b/src/nbl/asset/interchange/CBufferLoaderBIN.cpp index d63e41c8aa..0a4784e05f 100644 --- a/src/nbl/asset/interchange/CBufferLoaderBIN.cpp +++ b/src/nbl/asset/interchange/CBufferLoaderBIN.cpp @@ -1,30 +1,28 @@ // Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h - #include "CBufferLoaderBIN.h" -namespace nbl +using namespace nbl; +using namespace nbl::asset; + +asset::SAssetBundle CBufferLoaderBIN::loadAsset(system::IFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel) { - namespace asset - { - asset::SAssetBundle CBufferLoaderBIN::loadAsset(system::IFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel) - { - if (!_file) - return {}; + if (!_file) + return {}; - SContext ctx(_file->getSize()); - ctx.file = _file; - system::future read_future; - ctx.file->read(read_future, ctx.sourceCodeBuffer->getPointer(), 0u, ctx.sourceCodeBuffer->getSize()); - read_future.get(); + SContext ctx(_file->getSize()); + ctx.file = _file; - return SAssetBundle(nullptr,{std::move(ctx.sourceCodeBuffer)}); - } + system::IFile::success_t success; + ctx.file->read(success, ctx.sourceCodeBuffer->getPointer(), 0u, ctx.sourceCodeBuffer->getSize()); + if (success) + return {}; - bool CBufferLoaderBIN::isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger) const - { - return true; // validation if needed - } - } + return SAssetBundle(nullptr,{std::move(ctx.sourceCodeBuffer)}); +} + +bool CBufferLoaderBIN::isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger) const +{ + return true; // validation if needed } \ No newline at end of file diff --git a/src/nbl/asset/interchange/CGLILoader.cpp b/src/nbl/asset/interchange/CGLILoader.cpp index ae2a2961a0..6cbce54d91 100644 --- a/src/nbl/asset/interchange/CGLILoader.cpp +++ b/src/nbl/asset/interchange/CGLILoader.cpp @@ -230,9 +230,10 @@ namespace nbl const auto sizeOfData = memory.size(); - system::future future; - file->read(future, memory.data(), 0, sizeOfData); - future.get(); + system::IFile::success_t success; + file->read(success, memory.data(), 0, sizeOfData); + if (!success) + return false; if (fileName.rfind(".dds") != std::string::npos) texture = gli::load_dds(memory.data(), sizeOfData); @@ -246,7 +247,6 @@ namespace nbl else { logger.log("LOADING GLI: failed to load the file %s", system::ILogger::ELL_ERROR, file->getFileName().string().c_str()); - return false; } } @@ -259,50 +259,34 @@ namespace nbl constexpr std::array ktxMagic = { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A }; constexpr std::array kmgMagic = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 }; - system::future future; + // TODO: try to read the headers regardless of extension + system::IFile::success_t success; if (fileName.rfind(".dds") != std::string::npos) { std::remove_const::type tmpBuffer; - _file->read(future, &tmpBuffer, 0, sizeof(ddsMagic)); - future.get(); - if (*reinterpret_cast(&tmpBuffer) == ddsMagic) - { + _file->read(success, &tmpBuffer, 0, sizeof(ddsMagic)); + if (success && *reinterpret_cast(&tmpBuffer) == ddsMagic) return true; - } else - { logger.log("LOAD GLI: Invalid (non-DDS) file!", system::ILogger::ELL_ERROR); - } } else if (fileName.rfind(".kmg") != std::string::npos) { std::remove_const::type tmpBuffer; - _file->read(future, tmpBuffer.data(), 0, sizeof(kmgMagic[0]) * kmgMagic.size()); - future.get(); - if (tmpBuffer == kmgMagic) - { + _file->read(success, tmpBuffer.data(), 0, sizeof(kmgMagic[0]) * kmgMagic.size()); + if (success && tmpBuffer==kmgMagic) return true; - } else - { logger.log("LOAD GLI: Invalid (non-KMG) file!", system::ILogger::ELL_ERROR); - } - } else if (fileName.rfind(".ktx") != std::string::npos) { std::remove_const::type tmpBuffer; - _file->read(future, tmpBuffer.data(), 0, sizeof(ktxMagic[0]) * ktxMagic.size()); - - future.get(); - if (tmpBuffer == ktxMagic) - { + _file->read(success, tmpBuffer.data(), 0, sizeof(ktxMagic[0]) * ktxMagic.size()); + if (success && tmpBuffer==ktxMagic) return true; - } else - { logger.log("LOAD GLI: Invalid (non-KTX) file!", system::ILogger::ELL_ERROR); - } } return false; diff --git a/src/nbl/asset/interchange/CGLIWriter.cpp b/src/nbl/asset/interchange/CGLIWriter.cpp index c0c57ec49e..55c816dbb7 100644 --- a/src/nbl/asset/interchange/CGLIWriter.cpp +++ b/src/nbl/asset/interchange/CGLIWriter.cpp @@ -227,10 +227,9 @@ bool performSavingAsIFile(gli::texture& texture, system::IFile* file, system::IS if (properlyStatus) { - system::future future; - file->write(future, memory.data(), 0, memory.size()); - future.get(); - return true; + system::IFile::success_t success; + file->write(success, memory.data(), 0, memory.size()); + return bool(success); } else { diff --git a/src/nbl/asset/interchange/CGLSLLoader.cpp b/src/nbl/asset/interchange/CGLSLLoader.cpp index 0ce7d93c70..4e056a7c7d 100644 --- a/src/nbl/asset/interchange/CGLSLLoader.cpp +++ b/src/nbl/asset/interchange/CGLSLLoader.cpp @@ -14,12 +14,14 @@ SAssetBundle CGLSLLoader::loadAsset(system::IFile* _file, const IAssetLoader::SA if (!_file) return {}; - auto len = _file->getSize(); void* source = _NBL_ALIGNED_MALLOC(len+1u,_NBL_SIMD_ALIGNMENT); - system::future future; - _file->read(future, source, 0, len); - future.get(); + + system::IFile::success_t success; + _file->read(success, source, 0, len); + if (!success) + return {}; + reinterpret_cast(source)[len] = 0; diff --git a/src/nbl/asset/interchange/CGLSLLoader.h b/src/nbl/asset/interchange/CGLSLLoader.h index 409a6581b4..7a9cc19f6a 100644 --- a/src/nbl/asset/interchange/CGLSLLoader.h +++ b/src/nbl/asset/interchange/CGLSLLoader.h @@ -2,17 +2,15 @@ // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h -#ifndef __NBL_ASSET_C_GLSL_LOADER_H_INCLUDED__ -#define __NBL_ASSET_C_GLSL_LOADER_H_INCLUDED__ +#ifndef _NBL_ASSET_C_GLSL_LOADER_H_INCLUDED_ +#define _NBL_ASSET_C_GLSL_LOADER_H_INCLUDED_ #include #include "nbl/asset/interchange/IAssetLoader.h" #include -namespace nbl -{ -namespace asset +namespace nbl::asset { //! Surface Loader for PNG files @@ -20,6 +18,7 @@ class CGLSLLoader final : public asset::IAssetLoader { public: CGLSLLoader() = default; + bool isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger = nullptr) const override { char tmp[10] = { 0 }; @@ -28,16 +27,17 @@ class CGLSLLoader final : public asset::IAssetLoader size_t readPos = 0; while (readPos+sizeof(tmp) future; - _file->read(future, tmp, readPos, sizeof tmp); - size_t count = future.get(); + system::IFile::success_t success; + _file->read(success, tmp, readPos, sizeof(tmp)); + if (!success) + return false; if (strncmp(tmp,"#version ",9u)==0) return true; auto found = std::find(tmp,end,'#'); if (found==end || found==tmp) { - readPos += count; + readPos += sizeof(tmp); continue; } readPos += found - end; @@ -57,8 +57,7 @@ class CGLSLLoader final : public asset::IAssetLoader asset::SAssetBundle loadAsset(system::IFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) override; }; -} // namespace asset -} // namespace nbl +} // namespace nbl::asset #endif diff --git a/src/nbl/asset/interchange/CGLTFLoader.cpp b/src/nbl/asset/interchange/CGLTFLoader.cpp index 6f62b9a6d4..887eb9e40f 100644 --- a/src/nbl/asset/interchange/CGLTFLoader.cpp +++ b/src/nbl/asset/interchange/CGLTFLoader.cpp @@ -7,15 +7,15 @@ #ifdef _NBL_COMPILE_WITH_GLTF_LOADER_ #include "nbl/asset/utils/CDerivativeMapCreator.h" + #include "simdjson/singleheader/simdjson.h" #include + #include "nbl/core/execution.h" +using namespace nbl; +using namespace nbl::asset; -namespace nbl -{ - namespace asset - { enum WEIGHT_ENCODING { WE_UNORM8, @@ -104,9 +104,10 @@ namespace nbl auto jsonBuffer = core::make_smart_refctd_ptr(_file->getSize()); { - system::future future; - _file->read(future, jsonBuffer->getPointer(), 0u, jsonBuffer->getSize()); - future.get(); + system::IFile::success_t success; + _file->read(success, jsonBuffer->getPointer(), 0u, jsonBuffer->getSize()); + if (!success) + return false; } simdjson::dom::object tweets; @@ -1637,9 +1638,10 @@ namespace nbl auto jsonBuffer = core::make_smart_refctd_ptr(_file->getSize()); { - system::future future; - _file->read(future, jsonBuffer->getPointer(), 0u, jsonBuffer->getSize()); - future.get(); + system::IFile::success_t success; + _file->read(success, jsonBuffer->getPointer(), 0u, jsonBuffer->getSize()); + if (!success) + return false; } simdjson::dom::object tweets = parser.parse(reinterpret_cast(jsonBuffer->getPointer()), jsonBuffer->getSize()); @@ -2429,7 +2431,4 @@ namespace nbl return true; } -} -} - #endif // _NBL_COMPILE_WITH_GLTF_LOADER_ diff --git a/src/nbl/asset/interchange/CImageLoaderJPG.cpp b/src/nbl/asset/interchange/CImageLoaderJPG.cpp index 2f1d23ca67..2b842b0ee3 100644 --- a/src/nbl/asset/interchange/CImageLoaderJPG.cpp +++ b/src/nbl/asset/interchange/CImageLoaderJPG.cpp @@ -157,10 +157,9 @@ bool CImageLoaderJPG::isALoadableFileFormat(system::IFile* _file, const system:: return false; uint32_t header = 0; - system::future future; - _file->read(future, &header, 6, sizeof(uint32_t)); - future.get(); - return (header&0x00FFD8FFu)==0x00FFD8FFu; + system::IFile::success_t success; + _file->read(success, &header, 6, sizeof(uint32_t)); + return success && (header&0x00FFD8FFu)==0x00FFD8FFu; #endif } @@ -178,9 +177,10 @@ asset::SAssetBundle CImageLoaderJPG::loadAsset(system::IFile* _file, const asset uint8_t* input = new uint8_t[_file->getSize()]; - system::future future; - _file->read(future, input, 0, _file->getSize()); - future.get(); + system::IFile::success_t success; + _file->read(success, input, 0, _file->getSize()); + if (!success) + return {}; // allocate and initialize JPEG decompression object struct jpeg_decompress_struct cinfo; diff --git a/src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp b/src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp index c6d9ce388d..582f76b0ae 100644 --- a/src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp +++ b/src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp @@ -72,12 +72,11 @@ namespace nbl virtual bool read(char c[/*n*/], int n) override { - system::future future; + system::ISystem::future_t future; nblFile->read(future, c, fileOffset, n); - const auto bytesRead = future.get(); - fileOffset += bytesRead; + fileOffset += future.get(); - return true; + return future.get()==static_cast(n); } //-------------------------------------------------------- @@ -410,10 +409,9 @@ namespace nbl bool CImageLoaderOpenEXR::isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger) const { char magicNumberBuffer[sizeof(SContext::magicNumber)]; - system::future future; - _file->read(future, magicNumberBuffer, 0, sizeof(SContext::magicNumber)); - future.get(); - return isImfMagic(magicNumberBuffer); + system::IFile::success_t success; + _file->read(success, magicNumberBuffer, 0, sizeof(SContext::magicNumber)); + return success && isImfMagic(magicNumberBuffer); } template diff --git a/src/nbl/asset/interchange/CImageLoaderPNG.cpp b/src/nbl/asset/interchange/CImageLoaderPNG.cpp index dbe4e486d9..8b45d902b0 100644 --- a/src/nbl/asset/interchange/CImageLoaderPNG.cpp +++ b/src/nbl/asset/interchange/CImageLoaderPNG.cpp @@ -61,7 +61,7 @@ void PNGAPI user_read_data_fcn(png_structp png_pt, png_bytep data, png_size_t le system::IFile* file=(system::IFile*)png_get_io_ptr(png_pt); - system::future future; + system::ISystem::future_t future; file->read(future, data, file_pos, length); check = future.get(); file_pos += length; @@ -83,13 +83,12 @@ bool CImageLoaderPng::isALoadableFileFormat(system::IFile* _file, const system:: png_byte buffer[8]; - system::future future; - _file->read(future, buffer, 0, 8); // Read the first few bytes of the PNG _file - if (future.get() != 8) - { + system::IFile::success_t success; + _file->read(success, buffer, 0, sizeof(buffer)); + if (!success) return false; - } + // Check if it really is a PNG _file return !png_sig_cmp(buffer, 0, 8); #else @@ -114,9 +113,9 @@ asset::SAssetBundle CImageLoaderPng::loadAsset(system::IFile* _file, const asset png_byte buffer[8]; // Read the first few bytes of the PNG _file - system::future future; - _file->read(future, buffer, 0, sizeof buffer); - if(future.get() != 8 ) + system::IFile::success_t success; + _file->read(success, buffer, 0, sizeof(buffer)); + if (!success) { _params.logger.log("LOAD PNG: can't read _file\n", system::ILogger::ELL_ERROR, _file->getFileName().string()); return {}; diff --git a/src/nbl/asset/interchange/CImageLoaderTGA.cpp b/src/nbl/asset/interchange/CImageLoaderTGA.cpp index a70b08ef44..eecb7bc97b 100644 --- a/src/nbl/asset/interchange/CImageLoaderTGA.cpp +++ b/src/nbl/asset/interchange/CImageLoaderTGA.cpp @@ -58,17 +58,19 @@ void CImageLoaderTGA::loadCompressedImage(system::IFile *file, const STGAHeader& { uint8_t chunkheader = 0; { - system::future future; - file->read(future, &chunkheader, 0, sizeof(uint8_t)); // Read The Chunk's Header - future.get(); + system::IFile::success_t success; + file->read(success, &chunkheader, 0, sizeof(uint8_t)); // Read The Chunk's Header + if (!success) + return; // TODO: log error } if(chunkheader < 128) // If The Chunk Is A 'RAW' Chunk { chunkheader++; // Add 1 To The Value To Get Total Number Of Raw Pixels - system::future future; - file->read(future, &data[currentByte], 0, bytesPerPixel * chunkheader); - future.get(); + system::IFile::success_t success; + file->read(success, &data[currentByte], 0, bytesPerPixel * chunkheader); + if (!success) + return; // TODO: log currentByte += bytesPerPixel * chunkheader; } else @@ -79,9 +81,10 @@ void CImageLoaderTGA::loadCompressedImage(system::IFile *file, const STGAHeader& chunkheader -= 127; // Subtract 127 To Get Rid Of The ID Bit int32_t dataOffset = currentByte; - system::future future; - file->read(future, &data[currentByte], 0, bytesPerPixel); - future.get(); + system::IFile::success_t success; + file->read(success, &data[currentByte], 0, bytesPerPixel); + if (!success) + return; // TODO: log currentByte += bytesPerPixel; for(int32_t counter = 1; counter < chunkheader; counter++) @@ -104,9 +107,10 @@ bool CImageLoaderTGA::isALoadableFileFormat(system::IFile* _file, const system:: STGAFooter footer; memset(&footer, 0, sizeof(STGAFooter)); { - system::future future; - _file->read(future, &footer, _file->getSize() - sizeof(STGAFooter), sizeof(STGAFooter)); // TODO - future.get(); + system::IFile::success_t success; + _file->read(success, &footer, _file->getSize() - sizeof(STGAFooter), sizeof(STGAFooter)); + if (!success) + return false; } // 16 bytes for "TRUEVISION-XFILE", 17th byte is '.', and the 18th byte contains '\0'. if (strncmp(footer.Signature, "TRUEVISION-XFILE.", 18u) != 0) @@ -115,7 +119,7 @@ bool CImageLoaderTGA::isALoadableFileFormat(system::IFile* _file, const system:: return false; } - float gamma; + float gamma = 0.f; if (footer.ExtensionOffset == 0) { @@ -125,17 +129,15 @@ bool CImageLoaderTGA::isALoadableFileFormat(system::IFile* _file, const system:: else { STGAExtensionArea extension; - { - system::future future; - _file->read(future, &extension, footer.ExtensionOffset, sizeof(STGAExtensionArea)); - future.get(); - } - gamma = extension.Gamma; + system::IFile::success_t success; + _file->read(success, &extension, footer.ExtensionOffset, sizeof(STGAExtensionArea)); + if (success) + gamma = extension.Gamma; if (gamma == 0.0f) { - logger.log("Gamma information is not present! Assuming 2.333333", system::ILogger::ELL_WARNING); - gamma = 2.333333f; + logger.log("Gamma information is not present! Assuming 2.233333", system::ILogger::ELL_WARNING); + gamma = 2.233333f; } // TODO - pass gamma to LoadAsset()? @@ -234,9 +236,12 @@ core::smart_refctd_ptr createAndconvertImageData(ICPUImage::SCreation asset::SAssetBundle CImageLoaderTGA::loadAsset(system::IFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel) { STGAHeader header; - system::future future; - _file->read(future, &header, 0, sizeof header); - future.get(); + { + system::IFile::success_t success; + _file->read(success,&header,0,sizeof(header)); + if (!success) + return {}; + } core::smart_refctd_ptr colorMap; // not used, but it's texel buffer may be useful in future @@ -250,9 +255,12 @@ asset::SAssetBundle CImageLoaderTGA::loadAsset(system::IFile* _file, const asset { auto colorMapEntryByteSize = header.ColorMapEntrySize / 8 * header.ColorMapLength; auto colorMapEntryBuffer = core::make_smart_refctd_ptr(colorMapEntryByteSize); - system::future future; - _file->read(future, colorMapEntryBuffer->getPointer(), offset, header.ColorMapEntrySize / 8 * header.ColorMapLength); - future.get(); + { + system::IFile::success_t success; + _file->read(success, colorMapEntryBuffer->getPointer(), offset, header.ColorMapEntrySize / 8 * header.ColorMapLength); + if (!success) + return {}; + } offset += header.ColorMapEntrySize / 8 * header.ColorMapLength; switch ( header.ColorMapEntrySize ) // convert to 32-bit color map since input is dependend to header.ColorMapEntrySize, so it may be 8, 16, 24 or 32 bits per entity @@ -311,9 +319,12 @@ asset::SAssetBundle CImageLoaderTGA::loadAsset(system::IFile* _file, const asset region.bufferRowLength = calcPitchInBlocks(region.imageExtent.width, getTexelOrBlockBytesize(EF_R8G8B8_SRGB)); const int32_t imageSize = endBufferSize = region.imageExtent.height * region.bufferRowLength * bytesPerTexel; texelBuffer = core::make_smart_refctd_ptr(imageSize); - system::future texelfut; - _file->read(texelfut, texelBuffer->getPointer(), offset, imageSize); - texelfut.get(); + { + system::IFile::success_t success; + _file->read(success, texelBuffer->getPointer(), offset, imageSize); + if (!success) + return {}; + } offset += imageSize; } break; diff --git a/src/nbl/asset/interchange/CImageWriterJPG.cpp b/src/nbl/asset/interchange/CImageWriterJPG.cpp index 0aef44d0d5..8af22d58c7 100644 --- a/src/nbl/asset/interchange/CImageWriterJPG.cpp +++ b/src/nbl/asset/interchange/CImageWriterJPG.cpp @@ -56,9 +56,9 @@ static boolean jpeg_empty_output_buffer(j_compress_ptr cinfo) mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; // for now just exit upon file error - system::future future; - dest->file->write(future, dest->buffer, dest->filePos, OUTPUT_BUF_SIZE); - if (future.get() != OUTPUT_BUF_SIZE) + system::IFile::success_t success; + dest->file->write(success, dest->buffer, dest->filePos, OUTPUT_BUF_SIZE); + if (!success) { ERREXIT (cinfo, JERR_FILE_WRITE); } @@ -75,9 +75,9 @@ static void jpeg_term_destination(j_compress_ptr cinfo) mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; const int32_t datacount = (int32_t)(OUTPUT_BUF_SIZE - dest->pub.free_in_buffer); // for now just exit upon file error - system::future future; - dest->file->write(future, dest->buffer, dest->filePos, datacount); - if (future.get() != datacount) + system::IFile::success_t success; + dest->file->write(success, dest->buffer, dest->filePos, datacount); + if (!success) { ERREXIT (cinfo, JERR_FILE_WRITE); } diff --git a/src/nbl/asset/interchange/CImageWriterOpenEXR.cpp b/src/nbl/asset/interchange/CImageWriterOpenEXR.cpp index 20e60cc227..4308f49f53 100644 --- a/src/nbl/asset/interchange/CImageWriterOpenEXR.cpp +++ b/src/nbl/asset/interchange/CImageWriterOpenEXR.cpp @@ -40,203 +40,199 @@ SOFTWARE. namespace IMF = Imf; namespace IMATH = Imath; -namespace nbl -{ -namespace asset -{ - using namespace IMF; - using namespace IMATH; +using namespace nbl; +using namespace nbl::asset; + +using namespace IMF; +using namespace IMATH; - namespace impl +namespace nbl::asset::impl +{ + class nblOStream : public IMF::OStream { - class nblOStream : public IMF::OStream - { - public: - nblOStream(system::IFile* _nblFile) - : IMF::OStream(getFileName(_nblFile).c_str()), nblFile(_nblFile) {} - virtual ~nblOStream() {} - - //---------------------------------------------------------- - // Write to the stream: - // - // write(c,n) takes n bytes from array c, and stores them - // in the stream. If an I/O error occurs, write(c,n) throws - // an exception. - //---------------------------------------------------------- - - virtual void write(const char c[/*n*/], int n) override - { - system::future future; - nblFile->write(future, c, fileOffset, n); - const auto bytesWritten = future.get(); - fileOffset += bytesWritten; - } - - //--------------------------------------------------------- - // Get the current writing position, in bytes from the - // beginning of the file. If the next call to write() will - // start writing at the beginning of the file, tellp() - // returns 0. - //--------------------------------------------------------- - - virtual IMF::Int64 tellp() override - { - return static_cast(fileOffset); - } - - //------------------------------------------- - // Set the current writing position. - // After calling seekp(i), tellp() returns i. - //------------------------------------------- - - virtual void seekp(IMF::Int64 pos) override - { - fileOffset = static_cast(pos); - } - - void resetFileOffset() - { - fileOffset = 0u; - } - - private: - const std::string getFileName(system::IFile* _nblFile) - { - std::filesystem::path filename, extension; - core::splitFilename(_nblFile->getFileName(), nullptr, &filename, &extension); - return filename.string() + extension.string(); - } - - system::IFile* nblFile; - size_t fileOffset = {}; - }; - } + public: + nblOStream(system::IFile* _nblFile) + : IMF::OStream(getFileName(_nblFile).c_str()), nblFile(_nblFile) {} + virtual ~nblOStream() {} + + //---------------------------------------------------------- + // Write to the stream: + // + // write(c,n) takes n bytes from array c, and stores them + // in the stream. If an I/O error occurs, write(c,n) throws + // an exception. + //---------------------------------------------------------- + + virtual void write(const char c[/*n*/], int n) override + { + system::ISystem::future_t future; + nblFile->write(future, c, fileOffset, n); + const auto bytesWritten = future.get(); + fileOffset += bytesWritten; + } - constexpr uint8_t availableChannels = 4; + //--------------------------------------------------------- + // Get the current writing position, in bytes from the + // beginning of the file. If the next call to write() will + // start writing at the beginning of the file, tellp() + // returns 0. + //--------------------------------------------------------- - template - bool createAndWriteImage(std::array& pixelsArrayIlm, const asset::ICPUImage* image, system::IFile* _file) - { - const auto& creationParams = image->getCreationParameters(); - auto getIlmType = [&creationParams]() - { - if (creationParams.format == EF_R16G16B16A16_SFLOAT) - return PixelType::HALF; - else if (creationParams.format == EF_R32G32B32A32_SFLOAT) - return PixelType::FLOAT; - else if (creationParams.format == EF_R32G32B32A32_UINT) - return PixelType::UINT; - else - return PixelType::NUM_PIXELTYPES; - }; - - const auto width = creationParams.extent.width; - const auto height = creationParams.extent.height; - Header header(width, height); - const PixelType pixelType = getIlmType(); - FrameBuffer frameBuffer; - - if (pixelType == PixelType::NUM_PIXELTYPES || creationParams.type != IImage::E_TYPE::ET_2D) - return false; - - for (auto& channelPixelsPtr : pixelsArrayIlm) - channelPixelsPtr = _NBL_NEW_ARRAY(ilmType, width * height); - - const auto* data = reinterpret_cast(image->getBuffer()->getPointer()); - auto writeTexel = [&creationParams,&data,&pixelsArrayIlm](uint32_t ptrOffset, const core::vectorSIMDu32& texelCoord) -> void - { - assert(texelCoord.w==0u && texelCoord.z==0u); + virtual IMF::Int64 tellp() override + { + return static_cast(fileOffset); + } - const uint8_t* texelPtr = data+ptrOffset; - const uint64_t ptrStyleIlmShiftToDataChannelPixel = (texelCoord.y*creationParams.extent.width)+texelCoord.x; + //------------------------------------------- + // Set the current writing position. + // After calling seekp(i), tellp() returns i. + //------------------------------------------- - for (uint8_t channelIndex=0; channelIndex(texelPtr) + channelIndex); - *(pixelsArrayIlm[channelIndex] + ptrStyleIlmShiftToDataChannelPixel) = channelPixel; + fileOffset = static_cast(pos); } - }; - using StreamToEXR = CRegionBlockFunctorFilter; - typename StreamToEXR::state_type state(writeTexel,image,nullptr); - for (auto rit=image->getRegions().begin(); rit!=image->getRegions().end(); rit++) - { - if (rit->imageSubresource.mipLevel || rit->imageSubresource.baseArrayLayer) - continue; + void resetFileOffset() + { + fileOffset = 0u; + } - state.regionIterator = rit; - StreamToEXR::execute(core::execution::par_unseq,&state); - } + private: + const std::string getFileName(system::IFile* _nblFile) + { + std::filesystem::path filename, extension; + core::splitFilename(_nblFile->getFileName(), nullptr, &filename, &extension); + return filename.string() + extension.string(); + } - constexpr std::array rgbaSignatureAsText = { "R", "G", "B", "A" }; - for (uint8_t channel = 0; channel < rgbaSignatureAsText.size(); ++channel) - { - auto rowPitch = sizeof(*pixelsArrayIlm[channel]) * width; - - header.channels().insert(rgbaSignatureAsText[channel], Channel(pixelType)); - frameBuffer.insert - ( - rgbaSignatureAsText[channel], // name - Slice(pixelType, // type - (char*) pixelsArrayIlm[channel], // base - sizeof(*pixelsArrayIlm[channel]) * 1, // xStride - rowPitch) // yStride - ); - } + system::IFile* nblFile; + size_t fileOffset = {}; + }; +} + +constexpr uint8_t availableChannels = 4; - IMF::OStream* nblOStream = _NBL_NEW(impl::nblOStream, _file); - { // brackets are needed because of OutputFile's destructor - OutputFile file(*nblOStream, header); - file.setFrameBuffer(frameBuffer); - file.writePixels(height); +template +bool createAndWriteImage(std::array& pixelsArrayIlm, const asset::ICPUImage* image, system::IFile* _file) +{ + const auto& creationParams = image->getCreationParameters(); + auto getIlmType = [&creationParams]() + { + if (creationParams.format == EF_R16G16B16A16_SFLOAT) + return PixelType::HALF; + else if (creationParams.format == EF_R32G32B32A32_SFLOAT) + return PixelType::FLOAT; + else if (creationParams.format == EF_R32G32B32A32_UINT) + return PixelType::UINT; + else + return PixelType::NUM_PIXELTYPES; + }; + + const auto width = creationParams.extent.width; + const auto height = creationParams.extent.height; + Header header(width, height); + const PixelType pixelType = getIlmType(); + FrameBuffer frameBuffer; + + if (pixelType == PixelType::NUM_PIXELTYPES || creationParams.type != IImage::E_TYPE::ET_2D) + return false; + + for (auto& channelPixelsPtr : pixelsArrayIlm) + channelPixelsPtr = _NBL_NEW_ARRAY(ilmType, width * height); + + const auto* data = reinterpret_cast(image->getBuffer()->getPointer()); + auto writeTexel = [&creationParams,&data,&pixelsArrayIlm](uint32_t ptrOffset, const core::vectorSIMDu32& texelCoord) -> void + { + assert(texelCoord.w==0u && texelCoord.z==0u); + + const uint8_t* texelPtr = data+ptrOffset; + const uint64_t ptrStyleIlmShiftToDataChannelPixel = (texelCoord.y*creationParams.extent.width)+texelCoord.x; + + for (uint8_t channelIndex=0; channelIndex(texelPtr) + channelIndex); + *(pixelsArrayIlm[channelIndex] + ptrStyleIlmShiftToDataChannelPixel) = channelPixel; } + }; - for (auto channelPixelsPtr : pixelsArrayIlm) - _NBL_DELETE_ARRAY(channelPixelsPtr, width * height); - _NBL_DELETE(nblOStream); + using StreamToEXR = CRegionBlockFunctorFilter; + typename StreamToEXR::state_type state(writeTexel,image,nullptr); + for (auto rit=image->getRegions().begin(); rit!=image->getRegions().end(); rit++) + { + if (rit->imageSubresource.mipLevel || rit->imageSubresource.baseArrayLayer) + continue; - return true; + state.regionIterator = rit; + StreamToEXR::execute(core::execution::par_unseq,&state); } - bool CImageWriterOpenEXR::writeAsset(system::IFile* _file, const SAssetWriteParams& _params, IAssetWriterOverride* _override) + constexpr std::array rgbaSignatureAsText = { "R", "G", "B", "A" }; + for (uint8_t channel = 0; channel < rgbaSignatureAsText.size(); ++channel) { - if (!_override) - getDefaultOverride(_override); + auto rowPitch = sizeof(*pixelsArrayIlm[channel]) * width; + + header.channels().insert(rgbaSignatureAsText[channel], Channel(pixelType)); + frameBuffer.insert + ( + rgbaSignatureAsText[channel], // name + Slice(pixelType, // type + (char*) pixelsArrayIlm[channel], // base + sizeof(*pixelsArrayIlm[channel]) * 1, // xStride + rowPitch) // yStride + ); + } + + IMF::OStream* nblOStream = _NBL_NEW(asset::impl::nblOStream, _file); + { // brackets are needed because of OutputFile's destructor + OutputFile file(*nblOStream, header); + file.setFrameBuffer(frameBuffer); + file.writePixels(height); + } + + for (auto channelPixelsPtr : pixelsArrayIlm) + _NBL_DELETE_ARRAY(channelPixelsPtr, width * height); + _NBL_DELETE(nblOStream); - SAssetWriteContext ctx{ _params, _file }; + return true; +} - auto imageSmart = asset::IImageAssetHandlerBase::createImageDataForCommonWriting(IAsset::castDown(_params.rootAsset), _params.logger); - const asset::ICPUImage* image = imageSmart.get(); +bool CImageWriterOpenEXR::writeAsset(system::IFile* _file, const SAssetWriteParams& _params, IAssetWriterOverride* _override) +{ + if (!_override) + getDefaultOverride(_override); - if (image->getBuffer()->isADummyObjectForCache()) - return false; + SAssetWriteContext ctx{ _params, _file }; - system::IFile* file = _override->getOutputFile(_file, ctx, { image, 0u }); + auto imageSmart = asset::IImageAssetHandlerBase::createImageDataForCommonWriting(IAsset::castDown(_params.rootAsset), _params.logger); + const asset::ICPUImage* image = imageSmart.get(); - if (!file) - return false; + if (image->getBuffer()->isADummyObjectForCache()) + return false; - return writeImageBinary(file, image); - } + system::IFile* file = _override->getOutputFile(_file, ctx, { image, 0u }); - bool CImageWriterOpenEXR::writeImageBinary(system::IFile* file, const asset::ICPUImage* image) - { - const auto& params = image->getCreationParameters(); - - std::array halfPixelMapArray = {nullptr, nullptr, nullptr, nullptr}; - std::array fullFloatPixelMapArray = { nullptr, nullptr, nullptr, nullptr }; - std::array uint32_tPixelMapArray = { nullptr, nullptr, nullptr, nullptr }; - - if (params.format == EF_R16G16B16A16_SFLOAT) - createAndWriteImage(halfPixelMapArray, image, file); - else if (params.format == EF_R32G32B32A32_SFLOAT) - createAndWriteImage(fullFloatPixelMapArray, image, file); - else if (params.format == EF_R32G32B32A32_UINT) - createAndWriteImage(uint32_tPixelMapArray, image, file); - - return true; - } -} + if (!file) + return false; + + return writeImageBinary(file, image); } +bool CImageWriterOpenEXR::writeImageBinary(system::IFile* file, const asset::ICPUImage* image) +{ + const auto& params = image->getCreationParameters(); + + std::array halfPixelMapArray = {nullptr, nullptr, nullptr, nullptr}; + std::array fullFloatPixelMapArray = { nullptr, nullptr, nullptr, nullptr }; + std::array uint32_tPixelMapArray = { nullptr, nullptr, nullptr, nullptr }; + + if (params.format == EF_R16G16B16A16_SFLOAT) + createAndWriteImage(halfPixelMapArray, image, file); + else if (params.format == EF_R32G32B32A32_SFLOAT) + createAndWriteImage(fullFloatPixelMapArray, image, file); + else if (params.format == EF_R32G32B32A32_UINT) + createAndWriteImage(uint32_tPixelMapArray, image, file); + + return true; +} #endif // _NBL_COMPILE_WITH_OPENEXR_WRITER_ diff --git a/src/nbl/asset/interchange/CImageWriterPNG.cpp b/src/nbl/asset/interchange/CImageWriterPNG.cpp index 705e2fa5ea..5ec524b7d8 100644 --- a/src/nbl/asset/interchange/CImageWriterPNG.cpp +++ b/src/nbl/asset/interchange/CImageWriterPNG.cpp @@ -21,9 +21,7 @@ #include "libpng/png.h" #endif // _NBL_COMPILE_WITH_LIBPNG_ -namespace nbl -{ -namespace asset +namespace nbl::asset { #ifdef _NBL_COMPILE_WITH_LIBPNG_ @@ -54,9 +52,9 @@ void PNGAPI user_write_data_fcn(png_structp png_ptr, png_bytep data, png_size_t //check=(png_size_t) file->write((const void*)data,(uint32_t)length); auto usrData = (CImageWriterPNG::SContext*)png_get_user_chunk_ptr(png_ptr); - system::future future; + system::ISystem::future_t future; file->write(future, data, usrData->file_pos, length); - usrData->file_pos += length; + usrData->file_pos += future.get(); png_set_read_user_chunk_fn(png_ptr, usrData, nullptr); if (future.get() != length) @@ -219,7 +217,6 @@ bool CImageWriterPNG::writeAsset(system::IFile* _file, const SAssetWriteParams& #endif//defined(_NBL_COMPILE_WITH_LIBPNG_) } -} // namespace video -} // namespace nbl +} // namespace nbl::video #endif \ No newline at end of file diff --git a/src/nbl/asset/interchange/CImageWriterTGA.cpp b/src/nbl/asset/interchange/CImageWriterTGA.cpp index 16b9f4843c..9c14cc8292 100644 --- a/src/nbl/asset/interchange/CImageWriterTGA.cpp +++ b/src/nbl/asset/interchange/CImageWriterTGA.cpp @@ -113,11 +113,12 @@ bool CImageWriterTGA::writeAsset(system::IFile* _file, const SAssetWriteParams& } } - system::future future; - file->write(future, &imageHeader, 0, sizeof(imageHeader)); - - if (future.get() != sizeof(imageHeader)) - return false; + { + system::IFile::success_t success; + file->write(success, &imageHeader, 0, sizeof(imageHeader)); + if (!success) + return false; + } uint8_t* scan_lines = (uint8_t*)convertedImage->getBuffer()->getPointer(); if (!scan_lines) @@ -142,9 +143,9 @@ bool CImageWriterTGA::writeAsset(system::IFile* _file, const SAssetWriteParams& { memcpy(row_pointer, &scan_lines[y * row_stride], row_size); - system::future future; - file->write(future, row_pointer, offset, row_size); - if (future.get() != row_size) + system::IFile::success_t success; + file->write(success, row_pointer, offset, row_size); + if (!success) break; offset += row_size; } @@ -152,13 +153,13 @@ bool CImageWriterTGA::writeAsset(system::IFile* _file, const SAssetWriteParams& STGAExtensionArea extension; extension.ExtensionSize = sizeof(extension); extension.Gamma = isSRGBFormat(convertedFormat) ? ((100.0f / 30.0f) - 1.1f) : 1.0f; - - system::future extFuture; - file->write(extFuture, &extension, offset, sizeof(extension)); - - if (extFuture.get() < (int32_t)sizeof(extension)) - return false; + { + system::IFile::success_t success; + file->write(success, &extension, offset, sizeof(extension)); + if (!success) + return false; + } offset += sizeof extension; STGAFooter imageFooter; @@ -166,10 +167,9 @@ bool CImageWriterTGA::writeAsset(system::IFile* _file, const SAssetWriteParams& imageFooter.DeveloperOffset = 0; strncpy(imageFooter.Signature, "TRUEVISION-XFILE.", 18); - system::future footerFuture; - file->write(footerFuture, &extension, offset, sizeof(extension)); - - if (footerFuture.get() < (int32_t)sizeof(imageFooter)) + system::IFile::success_t success; + file->write(success, &extension, offset, sizeof(extension)); + if (!success) return false; return imageHeader.ImageHeight <= y; diff --git a/src/nbl/asset/interchange/COBJMeshFileLoader.cpp b/src/nbl/asset/interchange/COBJMeshFileLoader.cpp index bcb4ab1c32..ca16b79211 100644 --- a/src/nbl/asset/interchange/COBJMeshFileLoader.cpp +++ b/src/nbl/asset/interchange/COBJMeshFileLoader.cpp @@ -102,11 +102,13 @@ asset::SAssetBundle COBJMeshFileLoader::loadAsset(system::IFile* _file, const as std::string fileContents; fileContents.resize(filesize); char* const buf = fileContents.data(); - system::future future; - _file->read(future, buf, 0, filesize); - future.get(); - const char* const bufEnd = buf+filesize; + system::IFile::success_t success; + _file->read(success, buf, 0, filesize); + if (!success) + return {}; + + const char* const bufEnd = buf+filesize; // Process obj information const char* bufPtr = buf; std::string grpName, mtlName; diff --git a/src/nbl/asset/interchange/CPLYMeshFileLoader.cpp b/src/nbl/asset/interchange/CPLYMeshFileLoader.cpp index f3d1ca3da9..07b87f3542 100644 --- a/src/nbl/asset/interchange/CPLYMeshFileLoader.cpp +++ b/src/nbl/asset/interchange/CPLYMeshFileLoader.cpp @@ -36,10 +36,11 @@ bool CPLYMeshFileLoader::isALoadableFileFormat(system::IFile* _file, const syste }; char buf[40]; - - system::future future; - _file->read(future, buf, 0, sizeof(buf)); - future.get(); + + system::IFile::success_t success; + _file->read(success, buf, 0, sizeof(buf)); + if (!success) + return false; char* header = buf; if (strncmp(header, "ply", 3u) != 0) @@ -753,7 +754,7 @@ void CPLYMeshFileLoader::fillBuffer(SContext& _ctx) else { // read data from the file - system::future future; + system::ISystem::future_t future; _ctx.inner.mainFile->read(future, _ctx.EndPointer, _ctx.fileOffset, PLY_INPUT_BUFFER_SIZE - length); const auto bytesRead = future.get(); diff --git a/src/nbl/asset/interchange/CPLYMeshWriter.cpp b/src/nbl/asset/interchange/CPLYMeshWriter.cpp index e59f80b949..8e97f6aa19 100644 --- a/src/nbl/asset/interchange/CPLYMeshWriter.cpp +++ b/src/nbl/asset/interchange/CPLYMeshWriter.cpp @@ -212,7 +212,7 @@ bool CPLYMeshWriter::writeAsset(system::IFile* _file, const SAssetWriteParams& _ header += "end_header\n"; { - system::future future; + system::ISystem::future_t future; file->write(future, header.c_str(), context.fileOffset, header.size()); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -279,14 +279,14 @@ void CPLYMeshWriter::writeBinary(const asset::ICPUMeshBuffer* _mbuf, size_t _vtx for (size_t i = 0u; i < _fcCount; ++i) { { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, &listSize, context.fileOffset, sizeof(listSize)); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, ind, context.fileOffset, listSize * 4); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -301,14 +301,14 @@ void CPLYMeshWriter::writeBinary(const asset::ICPUMeshBuffer* _mbuf, size_t _vtx for (size_t i = 0u; i < _fcCount; ++i) { { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, &listSize, context.fileOffset, sizeof(listSize)); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, ind, context.fileOffset, listSize * 2); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -379,7 +379,7 @@ void CPLYMeshWriter::writeText(const asset::ICPUMeshBuffer* _mbuf, size_t _vtxCo } { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, "\n", context.fileOffset, 1); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -408,7 +408,7 @@ void CPLYMeshWriter::writeText(const asset::ICPUMeshBuffer* _mbuf, size_t _vtxCo for (size_t i = 0u; i < _fcCount; ++i) { { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, listSize, context.fileOffset, 2); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -417,7 +417,7 @@ void CPLYMeshWriter::writeText(const asset::ICPUMeshBuffer* _mbuf, size_t _vtxCo writeVectorAsText(context, ind, 3); { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, "\n", context.fileOffset, 1); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -432,7 +432,7 @@ void CPLYMeshWriter::writeText(const asset::ICPUMeshBuffer* _mbuf, size_t _vtxCo for (size_t i = 0u; i < _fcCount; ++i) { { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, listSize, context.fileOffset, 2); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -441,7 +441,7 @@ void CPLYMeshWriter::writeText(const asset::ICPUMeshBuffer* _mbuf, size_t _vtxCo writeVectorAsText(context, ind, 3); { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, "\n", context.fileOffset, 1); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -475,7 +475,7 @@ void CPLYMeshWriter::writeAttribBinary(SContext& context, asset::ICPUMeshBuffer* a[k] = ui[k]; { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, a, context.fileOffset, _cpa); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -488,7 +488,7 @@ void CPLYMeshWriter::writeAttribBinary(SContext& context, asset::ICPUMeshBuffer* a[k] = ui[k]; { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, a, context.fileOffset, 2 * _cpa); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -497,7 +497,7 @@ void CPLYMeshWriter::writeAttribBinary(SContext& context, asset::ICPUMeshBuffer* else if (bytesPerCh == 4u) { { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, ui, context.fileOffset, 4 * _cpa); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; @@ -511,7 +511,7 @@ void CPLYMeshWriter::writeAttribBinary(SContext& context, asset::ICPUMeshBuffer* f[0] = -f[0]; { - system::future future; + system::ISystem::future_t future; context.writeContext.outputFile->write(future, f.pointer, context.fileOffset, 4 * _cpa); const auto bytesWritten = future.get(); context.fileOffset += bytesWritten; diff --git a/src/nbl/asset/interchange/CSPVLoader.cpp b/src/nbl/asset/interchange/CSPVLoader.cpp index 76e4ef68c1..1747fcf167 100644 --- a/src/nbl/asset/interchange/CSPVLoader.cpp +++ b/src/nbl/asset/interchange/CSPVLoader.cpp @@ -62,9 +62,10 @@ SAssetBundle CSPVLoader::loadAsset(system::IFile* _file, const IAssetLoader::SAs auto buffer = core::make_smart_refctd_ptr(_file->getSize()); - system::future future; - _file->read(future, buffer->getPointer(), 0, _file->getSize()); - future.get(); + system::IFile::success_t success; + _file->read(success, buffer->getPointer(), 0, _file->getSize()); + if (!success) + return {}; if (reinterpret_cast(buffer->getPointer())[0]!=SPV_MAGIC_NUMBER) return {}; diff --git a/src/nbl/asset/interchange/CSPVLoader.h b/src/nbl/asset/interchange/CSPVLoader.h index 28875b22f3..fb586a1e6c 100644 --- a/src/nbl/asset/interchange/CSPVLoader.h +++ b/src/nbl/asset/interchange/CSPVLoader.h @@ -2,8 +2,8 @@ // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h -#ifndef __NBL_ASSET_C_SPIR_V_LOADER_H_INCLUDED__ -#define __NBL_ASSET_C_SPIR_V_LOADER_H_INCLUDED__ +#ifndef _NBL_ASSET_C_SPIR_V_LOADER_H_INCLUDED_ +#define _NBL_ASSET_C_SPIR_V_LOADER_H_INCLUDED_ #include "nbl/asset/interchange/IAssetLoader.h" @@ -15,15 +15,13 @@ class CSPVLoader final : public asset::IAssetLoader _NBL_STATIC_INLINE_CONSTEXPR uint32_t SPV_MAGIC_NUMBER = 0x07230203u; public: CSPVLoader() = default; - bool isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr) const override + inline bool isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr) const override { uint32_t magicNumber = 0u; - - system::future future; - _file->read(future, &magicNumber, 0, sizeof magicNumber); - future.get(); - return magicNumber==SPV_MAGIC_NUMBER; + system::IFile::success_t success; + _file->read(success, &magicNumber, 0, sizeof magicNumber); + return success && magicNumber==SPV_MAGIC_NUMBER; } const char** getAssociatedFileExtensions() const override @@ -32,7 +30,7 @@ class CSPVLoader final : public asset::IAssetLoader return ext; } - uint64_t getSupportedAssetTypesBitfield() const override { return asset::IAsset::ET_SHADER; } + inline uint64_t getSupportedAssetTypesBitfield() const override { return asset::IAsset::ET_SHADER; } asset::SAssetBundle loadAsset(system::IFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override = nullptr, uint32_t _hierarchyLevel = 0u) override; }; diff --git a/src/nbl/asset/interchange/CSTLMeshFileLoader.cpp b/src/nbl/asset/interchange/CSTLMeshFileLoader.cpp index 3ee4acc76f..6983d32051 100644 --- a/src/nbl/asset/interchange/CSTLMeshFileLoader.cpp +++ b/src/nbl/asset/interchange/CSTLMeshFileLoader.cpp @@ -17,7 +17,6 @@ using namespace nbl; using namespace nbl::asset; -using namespace nbl::io; constexpr auto POSITION_ATTRIBUTE = 0; constexpr auto COLOR_ATTRIBUTE = 1; @@ -174,10 +173,11 @@ SAssetBundle CSTLMeshFileLoader::loadAsset(system::IFile* _file, const IAssetLoa uint32_t vertexCount = 0u; - system::future future; - context.inner.mainFile->read(future, &vertexCount, context.fileOffset, sizeof(vertexCount)); - const auto bytesRead = future.get(); - context.fileOffset += bytesRead; + system::IFile::success_t success; + context.inner.mainFile->read(success, &vertexCount, context.fileOffset, sizeof(vertexCount)); + if (!success) + return {}; + context.fileOffset += sizeof(vertexCount); positions.reserve(3 * vertexCount); normals.reserve(vertexCount); @@ -242,10 +242,11 @@ SAssetBundle CSTLMeshFileLoader::loadAsset(system::IFile* _file, const IAssetLoa } else { - system::future future; - context.inner.mainFile->read(future, &attrib, context.fileOffset, sizeof(attrib)); - const auto bytesRead = future.get(); - context.fileOffset += bytesRead; + system::IFile::success_t success; + context.inner.mainFile->read(success, &attrib, context.fileOffset, sizeof(attrib)); + if (!success) + return {}; + context.fileOffset += sizeof(attrib); } if (hasColor && (attrib & 0x8000u)) // assuming VisCam/SolidView non-standard trick to store color in 2 bytes of extra attribute @@ -320,10 +321,12 @@ bool CSTLMeshFileLoader::isALoadableFileFormat(system::IFile* _file, const syste return false; char header[6]; - - system::future future; - _file->read(future, header, 0, sizeof(header)); - future.get(); + { + system::IFile::success_t success; + _file->read(success, header, 0, sizeof(header)); + if (!success) + return false; + } if (strncmp(header, "solid ", 6u) == 0) return true; @@ -335,9 +338,10 @@ bool CSTLMeshFileLoader::isALoadableFileFormat(system::IFile* _file, const syste uint32_t triangleCount; constexpr size_t readOffset = 80; - system::future future2; - _file->read(future2, &triangleCount, readOffset, sizeof(triangleCount)); - future2.get(); + system::IFile::success_t success; + _file->read(success, &triangleCount, readOffset, sizeof(triangleCount)); + if (!success) + return false; constexpr size_t STL_TRI_SZ = 50u; return _file->getSize() == (STL_TRI_SZ * triangleCount + 84u); @@ -350,7 +354,7 @@ void CSTLMeshFileLoader::getNextVector(SContext* context, core::vectorSIMDf& vec if (binary) { { - system::future future; + system::ISystem::future_t future; context->inner.mainFile->read(future, &vec.X, context->fileOffset, 4); const auto bytesRead = future.get(); @@ -358,7 +362,7 @@ void CSTLMeshFileLoader::getNextVector(SContext* context, core::vectorSIMDf& vec } { - system::future future; + system::ISystem::future_t future; context->inner.mainFile->read(future, &vec.Y, context->fileOffset, 4); const auto bytesRead = future.get(); @@ -366,7 +370,7 @@ void CSTLMeshFileLoader::getNextVector(SContext* context, core::vectorSIMDf& vec } { - system::future future; + system::ISystem::future_t future; context->inner.mainFile->read(future, &vec.Z, context->fileOffset, 4); const auto bytesRead = future.get(); @@ -397,7 +401,7 @@ const std::string& CSTLMeshFileLoader::getNextToken(SContext* context, std::stri while (context->fileOffset != context->inner.mainFile->getSize()) { - system::future future; + system::ISystem::future_t future; context->inner.mainFile->read(future, &c, context->fileOffset, sizeof(c)); const auto bytesRead = future.get(); context->fileOffset += bytesRead; @@ -416,7 +420,7 @@ void CSTLMeshFileLoader::goNextWord(SContext* context) const uint8_t c; while (context->fileOffset != context->inner.mainFile->getSize()) // TODO: check it { - system::future future; + system::ISystem::future_t future; context->inner.mainFile->read(future, &c, context->fileOffset, sizeof(c)); const auto bytesRead = future.get(); context->fileOffset += bytesRead; @@ -437,7 +441,7 @@ void CSTLMeshFileLoader::goNextLine(SContext* context) const // look for newline characters while (context->fileOffset != context->inner.mainFile->getSize()) // TODO: check it { - system::future future; + system::ISystem::future_t future; context->inner.mainFile->read(future, &c, context->fileOffset, sizeof(c)); { const auto bytesRead = future.get(); diff --git a/src/nbl/asset/interchange/CSTLMeshWriter.cpp b/src/nbl/asset/interchange/CSTLMeshWriter.cpp index ba34232a47..3e1ce9ce3a 100644 --- a/src/nbl/asset/interchange/CSTLMeshWriter.cpp +++ b/src/nbl/asset/interchange/CSTLMeshWriter.cpp @@ -2,22 +2,16 @@ // This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" // For conditions of distribution and use, see copyright notice in nabla.h // See the original file in irrlicht source for authors - -#include "CSTLMeshWriter.h" - -#ifdef _NBL_COMPILE_WITH_STL_WRITER_ - #include "nbl/system/ISystem.h" #include "nbl/system/IFile.h" -namespace nbl -{ -namespace asset -{ +#include "CSTLMeshWriter.h" + -using namespace io; -using namespace core; +using namespace nbl; +using namespace nbl::asset; +#ifdef _NBL_COMPILE_WITH_STL_WRITER_ constexpr auto POSITION_ATTRIBUTE = 0; constexpr auto COLOR_ATTRIBUTE = 1; constexpr auto UV_ATTRIBUTE = 2; @@ -137,35 +131,35 @@ inline void writeFacesBinary(const asset::ICPUMeshBuffer* buffer, const bool& no flipVectors(); { - system::future future; + system::ISystem::future_t future; file->write(future, &normal, *fileOffset, 12); const auto bytesWritten = future.get(); *fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; file->write(future, &vertex1, *fileOffset, 12); const auto bytesWritten = future.get(); *fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; file->write(future, &vertex2, *fileOffset, 12); const auto bytesWritten = future.get(); *fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; file->write(future, &vertex3, *fileOffset, 12); const auto bytesWritten = future.get(); *fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; file->write(future, &color, *fileOffset, 2); // saving color using non-standard VisCAM/SolidView trick const auto bytesWritten = future.get(); *fileOffset += bytesWritten; @@ -181,7 +175,7 @@ bool CSTLMeshWriter::writeMeshBinary(const asset::ICPUMesh* mesh, SContext* cont constexpr size_t HEADER_SIZE = 80u; { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, headerTxt, context->fileOffset, sizeof(headerTxt)); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -192,7 +186,7 @@ bool CSTLMeshWriter::writeMeshBinary(const asset::ICPUMesh* mesh, SContext* cont if (sizeleft < 0) { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, name.c_str(), context->fileOffset, HEADER_SIZE - sizeof(headerTxt)); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -202,14 +196,14 @@ bool CSTLMeshWriter::writeMeshBinary(const asset::ICPUMesh* mesh, SContext* cont const char buf[80] = {0}; { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, name.c_str(), context->fileOffset, name.size()); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, buf, context->fileOffset, sizeleft); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -220,7 +214,7 @@ bool CSTLMeshWriter::writeMeshBinary(const asset::ICPUMesh* mesh, SContext* cont for (auto& mb : mesh->getMeshBuffers()) facenum += mb->getIndexCount()/3; { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, &facenum, context->fileOffset, sizeof(facenum)); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -250,7 +244,7 @@ bool CSTLMeshWriter::writeMeshASCII(const asset::ICPUMesh* mesh, SContext* conte const char headerTxt[] = "Irrlicht-baw Engine "; { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, "solid ", context->fileOffset, 6); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -258,7 +252,7 @@ bool CSTLMeshWriter::writeMeshASCII(const asset::ICPUMesh* mesh, SContext* conte { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, headerTxt, context->fileOffset, sizeof(headerTxt) - 1); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -267,7 +261,7 @@ bool CSTLMeshWriter::writeMeshASCII(const asset::ICPUMesh* mesh, SContext* conte const std::string name = context->writeContext.outputFile->getFileName().filename().replace_extension().string(); { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, name.c_str(), context->fileOffset, name.size()); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -275,7 +269,7 @@ bool CSTLMeshWriter::writeMeshASCII(const asset::ICPUMesh* mesh, SContext* conte { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, "\n", context->fileOffset, 1); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -330,7 +324,7 @@ bool CSTLMeshWriter::writeMeshASCII(const asset::ICPUMesh* mesh, SContext* conte } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, "\n", context->fileOffset, 1); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -338,21 +332,21 @@ bool CSTLMeshWriter::writeMeshASCII(const asset::ICPUMesh* mesh, SContext* conte } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, "endsolid ", context->fileOffset, 9); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, headerTxt, context->fileOffset, sizeof(headerTxt) - 1); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, name.c_str(), context->fileOffset, name.size()); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -392,7 +386,7 @@ void CSTLMeshWriter::writeFaceText( flipVectors(); { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, "facet normal ", context->fileOffset, 13); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -401,21 +395,21 @@ void CSTLMeshWriter::writeFaceText( getVectorAsStringLine(normal, tmp); { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, tmp.c_str(), context->fileOffset, tmp.size()); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, " outer loop\n", context->fileOffset, 13); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, " vertex ", context->fileOffset, 11); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -424,14 +418,14 @@ void CSTLMeshWriter::writeFaceText( getVectorAsStringLine(vertex1, tmp); { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, tmp.c_str(), context->fileOffset, tmp.size()); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, " vertex ", context->fileOffset, 11); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -440,14 +434,14 @@ void CSTLMeshWriter::writeFaceText( getVectorAsStringLine(vertex2, tmp); { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, tmp.c_str(), context->fileOffset, tmp.size()); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, " vertex ", context->fileOffset, 11); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; @@ -456,28 +450,25 @@ void CSTLMeshWriter::writeFaceText( getVectorAsStringLine(vertex3, tmp); { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, tmp.c_str(), context->fileOffset, tmp.size()); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, " endloop\n", context->fileOffset, 10); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } { - system::future future; + system::ISystem::future_t future; context->writeContext.outputFile->write(future, "endfacet\n", context->fileOffset, 9); const auto bytesWritten = future.get(); context->fileOffset += bytesWritten; } } -} // end namespace -} // end namespace - #endif diff --git a/src/nbl/asset/utils/IGLSLCompiler.cpp b/src/nbl/asset/utils/IGLSLCompiler.cpp index fbcb50fe24..6806a27417 100644 --- a/src/nbl/asset/utils/IGLSLCompiler.cpp +++ b/src/nbl/asset/utils/IGLSLCompiler.cpp @@ -1,23 +1,20 @@ // Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h - -#include -#include -#include - #include "nbl/asset/utils/IGLSLCompiler.h" #include "nbl/asset/utils/shadercUtils.h" #include "nbl/asset/utils/CIncludeHandler.h" #include "nbl/asset/utils/CGLSLVirtualTexturingBuiltinIncludeLoader.h" +#include +#include +#include + + +using namespace nbl; +using namespace nbl::asset; -namespace nbl -{ -using namespace system; -namespace asset -{ IGLSLCompiler::IGLSLCompiler(system::ISystem* _s) : m_inclHandler(core::make_smart_refctd_ptr(_s)), m_system(_s) @@ -103,13 +100,16 @@ core::smart_refctd_ptr IGLSLCompiler::createSPIRVFromGLSL( { size_t fileSize = _sourcefile->getSize(); std::string glsl(fileSize, '\0'); - system::future future; - _sourcefile->read(future, glsl.data(), 0, fileSize); - future.get(); + + system::IFile::success_t success; + _sourcefile->read(success, glsl.data(), 0, fileSize); + if (!success) + return nullptr; + return createSPIRVFromGLSL(glsl.c_str(), _stage, _entryPoint, _compilationId, _opt, _genDebugInfo, _outAssembly, logger, targetSpirvVersion); } -namespace impl +namespace nbl::asset::impl { //string to be replaced with all "#" except those in "#include" static constexpr const char* PREPROC_DIRECTIVE_DISABLER = "_this_is_a_hash_"; @@ -293,10 +293,11 @@ core::smart_refctd_ptr IGLSLCompiler::resolveIncludeDirectives( const E_SPIRV_VERSION targetSpirvVersion) const { std::string glsl(_sourcefile->getSize(), '\0'); - system::future future; - _sourcefile->read(future, glsl.data(), 0, _sourcefile->getSize()); - future.get(); - return resolveIncludeDirectives(std::move(glsl), _stage, _originFilepath, _maxSelfInclusionCnt, logger, targetSpirvVersion); -} -}} + system::IFile::success_t success; + _sourcefile->read(success, glsl.data(), 0, _sourcefile->getSize()); + if (!success) + return nullptr; + + return resolveIncludeDirectives(std::move(glsl), _stage, _originFilepath, _maxSelfInclusionCnt, logger, targetSpirvVersion); +} \ No newline at end of file diff --git a/src/nbl/system/CSystemWin32.cpp b/src/nbl/system/CSystemWin32.cpp index 866c5820f5..80af74668d 100644 --- a/src/nbl/system/CSystemWin32.cpp +++ b/src/nbl/system/CSystemWin32.cpp @@ -98,6 +98,6 @@ core::smart_refctd_ptr CSystemWin32::CCaller::createFile(const std: return nullptr; } } - return core::make_smart_refctd_ptr(core::smart_refctd_ptr(m_system),filename,flags,_native,_fileMappingObj,_mappedPtr,_size); + return core::make_smart_refctd_ptr(core::smart_refctd_ptr(m_system),path(filename),flags,_mappedPtr,_size,_native,_fileMappingObj); } #endif \ No newline at end of file diff --git a/src/nbl/system/IFileBase.cpp b/src/nbl/system/IFileBase.cpp index 55c3a7da59..16a9358f4e 100644 --- a/src/nbl/system/IFileBase.cpp +++ b/src/nbl/system/IFileBase.cpp @@ -33,7 +33,7 @@ std::string deletePathFromPath(const std::string& filename, int32_t pathcount) return str.c_str(); } -path IFile::flattenFilename(const path& p) +path IFileBase::flattenFilename(const path& p) { if (p.empty()) return p; From bd74b8c93c73dd4c2aef2d4047ec872a6b631fa4 Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 4 Mar 2022 18:54:18 +0100 Subject: [PATCH 46/91] fix braindead design of archives --- include/nbl/system/IFileArchive.h | 79 ++++----------- include/nbl/system/ISystem.h | 40 ++++++-- src/nbl/system/ISystem.cpp | 155 +++++++----------------------- 3 files changed, 82 insertions(+), 192 deletions(-) diff --git a/include/nbl/system/IFileArchive.h b/include/nbl/system/IFileArchive.h index 8a9fbd879c..4d19746de5 100644 --- a/include/nbl/system/IFileArchive.h +++ b/include/nbl/system/IFileArchive.h @@ -32,16 +32,8 @@ class IFileArchive : public core::IReferenceCounted //! An entry in a list of items, can be a folder or a file. struct SListEntry { -#if 0 - //! The name of the file - /** If this is a file or folder in the virtual filesystem and the archive - was created with the ignoreCase flag then the file name will be lower case. */ - system::path name; -#endif - //! The name of the file including the path - /** If this is a file or folder in the virtual filesystem and the archive was - created with the ignoreDirs flag then it will be the same as Name. */ - system::path fullName; + //! The name of the file including the path relative to archive root + system::path pathRelativeToArchive; //! The size of the file in bytes size_t size; @@ -58,15 +50,15 @@ class IFileArchive : public core::IReferenceCounted E_ALLOCATOR_TYPE allocatorType; //! The == operator is provided so that CFileList can slowly search the list! - inline bool operator ==(const struct SListEntry& other) const + inline bool operator==(const struct SListEntry& other) const { - return fullName.string()==other.fullName.string(); + return pathRelativeToArchive.string()==other.pathRelativeToArchive.string(); } //! The < operator is provided so that CFileList can sort and quickly search the list. inline bool operator<(const struct SListEntry& other) const { - return fullName listAssets(const path& asset_path) const; - struct SOpenFileParams - { - path filename; - path absolutePath; - std::string_view password; - }; -#if 0 - core::smart_refctd_ptr readFile(const SOpenFileParams& params) - { - auto index = getIndexByPath(params.filename); - if (index == -1) return nullptr; - switch (this->listAssets(index)) - { - case EAT_NULL: - return getFile_impl(params, index); - break; - case EAT_MALLOC: - return getFile_impl(params, index); - break; - case EAT_VIRTUAL_ALLOC: - return getFile_impl(params, index); - break; - } - assert(false); - return nullptr; - } - virtual core::smart_refctd_ptr readFile_impl(const SOpenFileParams& params) = 0; - int32_t getIndexByPath(const system::path& p) - { - for (int i = 0; i < m_files.size(); ++i) - { - if (p == m_files[i].fullName) return i; - } - return -1; - } - E_ALLOCATOR_TYPE getFileType(uint32_t index) - { - return m_files[index].allocatorType; - } - -#endif + // + virtual core::smart_refctd_ptr getFile(const path& pathRelativeToArchive, const std::string_view& password) = 0; // - IFile* asFile() { return m_file.get(); } - const IFile* asFile() const { return m_file.get(); } + const path& getDefaultAbsolutePath() const {return m_defaultAbsolutePath;} protected: - IFileArchive(core::smart_refctd_ptr&& file, system::logger_opt_smart_ptr&& logger) : - m_file(std::move(file)), m_logger(std::move(logger)) - { - } + IFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger) : + m_defaultAbsolutePath(std::move(_defaultAbsolutePath)), m_logger(std::move(logger)) {} /* virtual void addItem(const system::path& fullPath, uint32_t offset, uint32_t size, E_ALLOCATOR_TYPE allocatorType, uint32_t id = 0) { @@ -143,9 +93,16 @@ class IFileArchive : public core::IReferenceCounted m_items.insert(std::lower_bound(m_items.begin(), m_items.end(), entry), entry); } */ + inline uint32_t getIndexFromPath(const system::path& pathRelativeToArchive) const + { + const IFileArchive::SListEntry itemToFind = { pathRelativeToArchive }; + return std::distance(m_items.begin(),std::lower_bound(m_items.begin(),m_items.end(),itemToFind)); + } + + path m_defaultAbsolutePath; // files and directories core::vector m_items; - core::smart_refctd_ptr m_file; + // system::logger_opt_smart_ptr m_logger; }; diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index 6432c47cb6..8a43056576 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -156,7 +156,7 @@ class ISystem : public core::IReferenceCounted /* Recursively lists all files and directories in the directory. */ - core::vector listFilesInDirectory(const system::path& p) const; + core::vector listItemsInDirectory(const system::path& p) const; // can only perform operations on non-virtual filesystem paths bool createDirectory(const system::path& p); @@ -175,7 +175,12 @@ class ISystem : public core::IReferenceCounted bool copy(const system::path& from, const system::path& to); // - void createFile(future_t>& future, std::filesystem::path filename, const core::bitflag flags); + void createFile( + future_t>& future, // creation may happen on a dedicated thread, so its async + std::filesystem::path filename, // absolute path within our virtual filesystem + const core::bitflag flags, // access flags (IMPORTANT: files from most archives wont open with ECF_WRITE bit) + const std::string_view& accessToken="" // usually password for archives, but should be SSH key for URL downloads + ); // Create a IFileArchive from a IFile core::smart_refctd_ptr openFileArchive(core::smart_refctd_ptr&& file, const std::string_view& password=""); @@ -193,8 +198,23 @@ class ISystem : public core::IReferenceCounted } // After opening and archive, you must mount it if you want the global path lookup to work seamlessly. - void mount(core::smart_refctd_ptr&& archive, const system::path& pathAlias=""); - void unmount(const IFileArchive* archive, const system::path& pathAlias=""); + inline void mount(core::smart_refctd_ptr&& archive, const system::path& pathAlias="") + { + if (pathAlias.empty()) + m_cachedArchiveFiles.insert(archive->getDefaultAbsolutePath(),std::move(archive)); + else + m_cachedArchiveFiles.insert(pathAlias,std::move(archive)); + } + + // + inline void unmount(const IFileArchive* archive, const system::path& pathAlias = "") + { + auto dummy = reinterpret_cast&>(archive); + if (pathAlias.empty()) + m_cachedArchiveFiles.removeObject(dummy,archive->getDefaultAbsolutePath()); + else + m_cachedArchiveFiles.removeObject(dummy,pathAlias); + } // struct SystemInfo @@ -243,11 +263,13 @@ class ISystem : public core::IReferenceCounted // core::smart_refctd_ptr impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const; - // given an absolute `path` find the archive it belongs to - std::pair findFileInArchive(const system::path& _path) const; - - // - core::smart_refctd_ptr getFileFromArchive(const system::path& path); + // given an `absolutePath` find the archive it belongs to + struct FoundArchiveFile + { + IFileArchive* archive; + path pathRelativeToArchive; + }; + FoundArchiveFile findFileInArchive(const system::path& absolutePath) const; // diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index aab2e3e234..ad163b11da 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -1,8 +1,9 @@ #include "nbl/system/ISystem.h" #include "nbl/system/ISystemFile.h" +#include "nbl/system/CFileView.h" -#include "nbl/system/CArchiveLoaderZip.h" -#include "nbl/system/CArchiveLoaderTar.h" +//#include "nbl/system/CArchiveLoaderZip.h" +//#include "nbl/system/CArchiveLoaderTar.h" using namespace nbl; @@ -11,10 +12,8 @@ using namespace nbl::system; ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatcher(std::move(caller)) { -#if 0 - addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this),nullptr)); - addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this),nullptr)); -#endif + //addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); + //addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); } core::smart_refctd_ptr ISystem::loadBuiltinData(const std::string& builtinPath) const @@ -71,16 +70,12 @@ bool ISystem::exists(const system::path& filename, const core::bitflag= sizeof(SRequestParams_CREATE_FILE::filename)) return false; // archive file - if (!writeUsage && std::get(findFileInArchive(filename))) + if (!writeUsage && findFileInArchive(filename).archive) return true; // regular file return std::filesystem::exists(filename); } -/* - Returns true if the path is writable (e.g. if p is a path inside an archive the function will return true). - The path existence is not checked. -*/ bool ISystem::isPathReadOnly(const system::path& p) const { // check all parent subpaths @@ -105,7 +100,7 @@ bool ISystem::isPathReadOnly(const system::path& p) const return false; } -core::vector ISystem::listFilesInDirectory(const system::path& p) const +core::vector ISystem::listItemsInDirectory(const system::path& p) const { core::vector res; res.reserve(128u); @@ -181,15 +176,15 @@ bool ISystem::copy(const system::path& from, const system::path& to) { if (isDirectory(from)) { - auto allFiles = listFilesInDirectory(from); - for (const auto& file : allFiles) + const auto allItems = listItemsInDirectory(from); + for (const auto& item : allItems) { - auto relative = std::filesystem::relative(file,from); + auto relative = std::filesystem::relative(item,from); system::path targetName = (to/relative).generic_string(); std::filesystem::create_directories(targetName.parent_path()); if (!isDirectory(targetName)) { - if (!copyFile(file,targetName)) + if (!copyFile(item,targetName)) return false; } } @@ -207,7 +202,7 @@ bool ISystem::copy(const system::path& from, const system::path& to) } } -void ISystem::createFile(future_t>& future, std::filesystem::path filename, const core::bitflag flags) +void ISystem::createFile(future_t>& future, std::filesystem::path filename, const core::bitflag flags, const std::string_view& accessToken) { // try builtins if (!(flags.value&IFile::ECF_WRITE)) @@ -222,11 +217,15 @@ void ISystem::createFile(future_t>& future, std::f // try archives if (flags.value&IFile::ECF_READ) { - auto file = getFileFromArchive(filename); - if (file) + const auto found = findFileInArchive(filename); + if (found.archive) { - future.notify(std::move(file)); - return; + auto file = found.archive->getFile(found.pathRelativeToArchive,accessToken); + if (file) + { + future.notify(std::move(file)); + return; + } } } @@ -241,7 +240,7 @@ void ISystem::createFile(future_t>& future, std::f SRequestParams_CREATE_FILE params; strcpy(params.filename,filename.string().c_str()); - params.flags = flags; + params.flags = flags.value; m_dispatcher.request(future,params); } @@ -271,116 +270,28 @@ core::smart_refctd_ptr ISystem::openFileArchive(core::smart_refctd return nullptr; } -void ISystem::mount(core::smart_refctd_ptr&& archive, const system::path& pathAlias) -{ - if (pathAlias.empty()) - m_cachedArchiveFiles.insert(archive->asFile()->getFileName(),std::move(archive)); - else - m_cachedArchiveFiles.insert(pathAlias,std::move(archive)); -} -void ISystem::unmount(const IFileArchive* archive, const system::path& pathAlias) -{ - auto dummy = reinterpret_cast&>(archive); - if (pathAlias.empty()) - m_cachedArchiveFiles.removeObject(dummy,archive->asFile()->getFileName()); - else - m_cachedArchiveFiles.removeObject(dummy,pathAlias); -} - -std::pair ISystem::findFileInArchive(const system::path& _path) const +ISystem::FoundArchiveFile ISystem::findFileInArchive(const system::path& absolutePath) const { - system::path path = std::filesystem::exists(_path) ? system::path(std::filesystem::canonical(_path.parent_path()).generic_string()) : _path.parent_path(); - + system::path path = std::filesystem::exists(absolutePath) ? std::filesystem::canonical(absolutePath.parent_path()):absolutePath.parent_path(); // going up the directory tree - while (!path.empty() && path.parent_path() != path) + while (!path.empty() && path.parent_path()!=path) { - system::path realPath = std::filesystem::exists(path) ? system::path(std::filesystem::canonical(path).generic_string()) : path; - auto archives = m_cachedArchiveFiles.findRange(realPath); + path = std::filesystem::exists(path) ? std::filesystem::canonical(path):path; + const auto archives = m_cachedArchiveFiles.findRange(path); for (auto& archive : archives) { -#if 0 - auto relative = std::filesystem::relative(_path, path); - auto files = archive.second->listAssets(); - - const auto itemToFind = IFileArchive::SListEntry{ relative, relative, 0 }; - bool hasFile = std::binary_search(files.begin(), files.end(), itemToFind, [](const IFileArchive::SFileListEntry& l, const IFileArchive::SFileListEntry& r) { return l.fullName == r.fullName; }); - auto f = archive.second->asFile(); - if (f) - { - auto realPath = f->getFileName(); - auto absolute = (realPath / relative).generic_string(); - if (hasFile) - { - auto f = archive.second; - return { f.get(),{relative,_path,""} }; - } - } - else - { - if (hasFile) - { - auto f = archive.second; - return { f.get(),{relative,_path,""} }; - } - } -#endif - } - path = path.parent_path(); - } - return { nullptr,{} }; -} - -core::smart_refctd_ptr ISystem::getFileFromArchive(const system::path& path) -{ -#if 0 - // given an absolute `path` find the archive it belongs to - std::pair found = {nullptr,{}}; - system::path path = std::filesystem::exists(path) ? std::filesystem::canonical(path.parent_path()):path.parent_path(); - // going up the directory tree - while (!path.empty() && path.parent_path() != path) - { - system::path realPath = std::filesystem::exists(path) ? system::path(std::filesystem::canonical(path).generic_string()) : path; - auto archives = m_cachedArchiveFiles.findRange(realPath); + const auto relative = std::filesystem::relative(absolutePath,path); + const auto items = archive.second->listAssets(); - for (auto& archive : archives) - { - auto relative = std::filesystem::relative(_path, path); - auto files = archive.second->getArchivedFiles(); - auto itemToFind = IFileArchive::SFileListEntry{ relative, relative, 0 }; - bool hasFile = std::binary_search(files.begin(), files.end(), itemToFind, [](const IFileArchive::SFileListEntry& l, const IFileArchive::SFileListEntry& r) { return l.fullName == r.fullName; }); - auto f = archive.second->asFile(); - if (f) - { - auto realPath = f->getFileName(); - auto absolute = (realPath / relative).generic_string(); - if (hasFile) - { - auto f = archive.second; - return { f.get(),{relative,_path,""} }; - } - } - else - { - if (hasFile) - { - auto f = archive.second; - return { f.get(),{relative,_path,""} }; - } - } + const IFileArchive::SListEntry itemToFind = { relative }; + auto found = std::lower_bound(items.begin(), items.end(), itemToFind); + if (found!=items.end() && found->pathRelativeToArchive==relative) + return {archive.second.get(),relative}; } path = path.parent_path(); } - - auto archive = std::get(found); - if (!archive) - return nullptr; - - auto& params = std::get(found); - // TODO: support passwords - return archive->readFile(params); -#endif - return nullptr; + return { nullptr,{} }; } From 4b17133e7f5e5007a42a4e2df57712ff19a8c242 Mon Sep 17 00:00:00 2001 From: devsh Date: Fri, 4 Mar 2022 19:16:35 +0100 Subject: [PATCH 47/91] mostly stylistic fixes --- .../nbl/system/CColoredStdoutLoggerWin32.h | 9 ++- .../system/ICancellableAsyncQueueDispatcher.h | 4 +- .../utilities/IGPUObjectFromAssetConverter.h | 2 +- src/nbl/system/IFileArchive.cpp | 60 ++++++++++++++++--- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/include/nbl/system/CColoredStdoutLoggerWin32.h b/include/nbl/system/CColoredStdoutLoggerWin32.h index 80d4d8b246..e255425bd7 100644 --- a/include/nbl/system/CColoredStdoutLoggerWin32.h +++ b/include/nbl/system/CColoredStdoutLoggerWin32.h @@ -2,13 +2,12 @@ #define _NBL_SYSTEM_C_COLORFUL_STDOUT_LOGGER_WIN32_INCLUDED_ #include "nbl/system/IThreadsafeLogger.h" -//instead of #include -#include "nbl/system/DefaultFuncPtrLoader.h" - -#ifdef _NBL_PLATFORM_WINDOWS_ namespace nbl::system { +#ifdef _NBL_PLATFORM_WINDOWS_ +//instead of #include +#include "nbl/system/DefaultFuncPtrLoader.h" class CColoredStdoutLoggerWin32 : public IThreadsafeLogger { @@ -62,7 +61,7 @@ class CColoredStdoutLoggerWin32 : public IThreadsafeLogger } }; -} #endif +} #endif \ No newline at end of file diff --git a/include/nbl/system/ICancellableAsyncQueueDispatcher.h b/include/nbl/system/ICancellableAsyncQueueDispatcher.h index 332d0450d0..db68361814 100644 --- a/include/nbl/system/ICancellableAsyncQueueDispatcher.h +++ b/include/nbl/system/ICancellableAsyncQueueDispatcher.h @@ -1,5 +1,5 @@ -#ifndef __NBL_I_CANCELLABLE_ASYNC_QUEUE_DISPATCHER_H_INCLUDED__ -#define __NBL_I_CANCELLABLE_ASYNC_QUEUE_DISPATCHER_H_INCLUDED__ +#ifndef _NBL_I_CANCELLABLE_ASYNC_QUEUE_DISPATCHER_H_INCLUDED_ +#define _NBL_I_CANCELLABLE_ASYNC_QUEUE_DISPATCHER_H_INCLUDED_ #include "nbl/system/IAsyncQueueDispatcher.h" #include "nbl/system/SReadWriteSpinLock.h" diff --git a/include/nbl/video/utilities/IGPUObjectFromAssetConverter.h b/include/nbl/video/utilities/IGPUObjectFromAssetConverter.h index cd7696ee3e..27fcf2af7f 100644 --- a/include/nbl/video/utilities/IGPUObjectFromAssetConverter.h +++ b/include/nbl/video/utilities/IGPUObjectFromAssetConverter.h @@ -1801,7 +1801,7 @@ inline created_gpu_object_array IGPUObjectFromAssetCon auto gpuImgViews = getGPUObjectsFromAssets(cpuImgViews.data(), cpuImgViews.data()+cpuImgViews.size(), _params); auto gpuSamplers = getGPUObjectsFromAssets(cpuSamplers.data(), cpuSamplers.data()+cpuSamplers.size(), _params); - uint32_t dsCounts[] = { assetCount }; + uint32_t dsCounts[] = {static_cast(assetCount)}; auto dsPool = _params.device->createDescriptorPoolForDSLayouts(IDescriptorPool::ECF_NONE,&gpuLayouts->begin()->get(),&gpuLayouts->end()->get(), dsCounts); core::vector writes(maxWriteCount); diff --git a/src/nbl/system/IFileArchive.cpp b/src/nbl/system/IFileArchive.cpp index 7148a5b8de..1a9d5dcc2e 100644 --- a/src/nbl/system/IFileArchive.cpp +++ b/src/nbl/system/IFileArchive.cpp @@ -1,16 +1,58 @@ #include "nbl/system/IFileArchive.h" -#include "nbl/system/IFileViewAllocator.h" -namespace nbl::system + + +using namespace nbl; +using namespace nbl::system; + + +core::SRange IFileArchive::listAssets(const path& asset_path) const { - void IFileArchive::setFlagsVectorSize(size_t fileCount) + // TODO: use something from ISystem for this? + constexpr auto isSubDir = [](path p, path root) -> bool { - assert(!m_filesBuffer && !m_fileFlags); - m_filesBuffer = (std::byte*)_NBL_ALIGNED_MALLOC(fileCount * SIZEOF_INNER_ARCHIVE_FILE, ALIGNOF_INNER_ARCHIVE_FILE); - m_fileFlags = (std::atomic_flag*)_NBL_ALIGNED_MALLOC(fileCount * sizeof(std::atomic_flag), alignof(std::atomic_flag)); - for (int i = 0; i < fileCount; i++) + while (p != path()) { - m_fileFlags[i].clear(); + if (p==root) + return true; + p = p.parent_path(); } - memset(m_filesBuffer, 0, fileCount * SIZEOF_INNER_ARCHIVE_FILE); + return false; + }; + + const IFileArchive::SListEntry* begin = nullptr; + const IFileArchive::SListEntry* end = nullptr; + for (auto& entry : m_items) + { + if (isSubDir(entry.pathRelativeToArchive, asset_path)) + { + if (begin) + end = &entry; + else + begin = &entry; + } + else if (end) + break; } + return {begin,end}; + + /* + // future, cause lower/upper bound don't work like that + auto begin = std::lower_bound(m_items.begin(), m_items.end(),asset_path); + if (begin!=m_items.end()) + { + auto end = std::upper_bound(begin,m_items.end(),asset_path); + if (begin==end) + return {&(*begin),&(*end)}; + } + return {nullptr,nullptr}; + */ +} + + +core::smart_refctd_ptr IArchiveLoader::createArchive(core::smart_refctd_ptr&& file, const std::string_view& password) const +{ + if (!(file->getFlags()&IFile::ECF_READ)) + return nullptr; + + return createArchive_impl(std::move(file),password); } \ No newline at end of file From c11bafdc6ef9cc96888b0599f96fe97d5ef3ad6e Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 16:25:19 +0100 Subject: [PATCH 48/91] add GLSL files (and other builtins) to Visual Studio Nabla project so that they're searchable --- src/nbl/CMakeLists.txt | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 570000ed65..c1e7c1d630 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -190,11 +190,6 @@ endforeach() unset(NABLA_HEADERS_PUBLIC2 ${NBL_TMP_FULL_PATHS}) -file(GLOB_RECURSE NABLA_HEADERS_PRIV1 "*.h") -file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") -# just gather all the header files and later put them into project so it's easy to search for things using IDE -set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) - # set(NBL_CORE_SOURCES @@ -513,9 +508,21 @@ macro(nbl_target_link_simdjson _trgt) set_target_properties(simdjson PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endmacro() +# just gather all the header files and later put them into project so it's easy to search for things using IDE +file(GLOB_RECURSE NABLA_HEADERS_PRIV1 "*.h") +file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") +set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) + +#always install builtins (some may be included in cpp regardless if embedded or not) +foreach(X IN LISTS nbl_resources_to_embed) + list(APPEND NABLA_HEADERS_PUBLIC ${NBL_ROOT_PATH}/include/${X}) +endforeach() + +# declare the library! add_library(Nabla STATIC ${NABLA_SRCS_COMMON} ${NABLA_HEADERS} + ${nbl_resources_to_embed} $ $ $ @@ -644,37 +651,18 @@ if(NBL_PCH) endif() if(NBL_EMBED_BUILTIN_RESOURCES) - add_custom_target(builtin_resources - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/builtin/builtinResourceData.cpp) - add_dependencies(Nabla builtin_resources) + add_custom_target(builtin_resources DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/builtin/builtinResourceData.cpp) + add_dependencies(Nabla builtin_resources) endif() -#always install builtins (some may be included in cpp regardless if embedded or not) -foreach(X IN LISTS nbl_resources_to_embed) - list(APPEND NABLA_HEADERS_PUBLIC ${NBL_ROOT_PATH}/include/${X}) -endforeach() - # extensions start_tracking_variables_for_propagation_to_parent() add_subdirectory(ext) propagate_changed_variables_to_parent_scope() -set(NABLA_HEADERS_TO_INSTALL - ${NABLA_HEADERS_PUBLIC} -) - -set(NABLA_HEADERS_TO_INSTALL_SOURCE_REFACTOR - # Junk to refactor - ${NBL_ROOT_PATH}/source/Nabla/CMountPointReader.h - ${NBL_ROOT_PATH}/source/Nabla/CPakReader.h - ${NBL_ROOT_PATH}/source/Nabla/CTarReader.h - ${NBL_ROOT_PATH}/source/Nabla/CZipReader.h -) - nbl_install_headers("${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" "${CMAKE_CURRENT_BINARY_DIR}/include") -nbl_install_headers("${NABLA_HEADERS_TO_INSTALL}" "${NBL_ROOT_PATH}/include") -nbl_install_headers("${NABLA_HEADERS_TO_INSTALL_SOURCE_REFACTOR}" "${NBL_ROOT_PATH}/source/Nabla") +nbl_install_headers("${NABLA_HEADERS_PUBLIC}" "${NBL_ROOT_PATH}/include") nbl_install_config_header(BuildConfigOptions.h) macro(nbl_install_program _TRGT) From 2725d9ba3c2406090ded67732c6ec5a1c8ba0738 Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 16:47:03 +0100 Subject: [PATCH 49/91] Rewrite `ISystem::listItemsInDirectory` remove deprecated `ISystem::loadBuiltinData` function --- include/nbl/system/ISystem.h | 9 +- .../asset/utils/IGLSLEmbeddedIncludeLoader.h | 4 +- src/nbl/system/ISystem.cpp | 139 ++++++++++-------- 3 files changed, 81 insertions(+), 71 deletions(-) diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index 8a43056576..66eee88e0c 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -111,9 +111,6 @@ class ISystem : public core::IReferenceCounted } }; - // [[deprecated]] use `createFile` instead - core::smart_refctd_ptr loadBuiltinData(const std::string& builtinPath) const; - //! Compile time resource ID template inline core::smart_refctd_ptr loadBuiltinData() const @@ -121,7 +118,9 @@ class ISystem : public core::IReferenceCounted #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ return impl_loadEmbeddedBuiltinData(StringUniqueType::value,nbl::builtin::get_resource()); #else - return loadBuiltinData(StringUniqueType::value); + future_t> future; + createFile(future,StringUniqueType::value,core::bitflag(IFileBase::ECF_READ)|IFileBase::ECF_MAPPABLE); + return future.get(); #endif } @@ -177,7 +176,7 @@ class ISystem : public core::IReferenceCounted // void createFile( future_t>& future, // creation may happen on a dedicated thread, so its async - std::filesystem::path filename, // absolute path within our virtual filesystem + path filename, // absolute path within our virtual filesystem const core::bitflag flags, // access flags (IMPORTANT: files from most archives wont open with ECF_WRITE bit) const std::string_view& accessToken="" // usually password for archives, but should be SSH key for URL downloads ); diff --git a/src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h b/src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h index c409c498ec..ef250e15cc 100644 --- a/src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h +++ b/src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h @@ -50,8 +50,10 @@ class IGLSLEmbeddedIncludeLoader : public IBuiltinIncludeLoader // inline std::string getFromDiskOrEmbedding(const std::string& _name) const { + system::ISystem::future_t> future; auto path = "nbl/builtin/" + _name; - auto data = s->loadBuiltinData(path); + s->createFile(future,path,core::bitflag(system::IFileBase::ECF_READ)|system::IFileBase::ECF_MAPPABLE); + auto data = future.get(); if (!data) return ""; auto begin = reinterpret_cast(data->getMappedPointer()); diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index ad163b11da..ca32e8f9ff 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -16,40 +16,15 @@ ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatch //addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); } -core::smart_refctd_ptr ISystem::loadBuiltinData(const std::string& builtinPath) const -{ -#ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - return impl_loadEmbeddedBuiltinData(builtinPath,nbl::builtin::get_resource_runtime(builtinPath)); -#else - constexpr auto pathPrefix = "nbl/builtin/"; - auto pos = builtinPath.find(pathPrefix); - std::string path; - if (pos != std::string::npos) - path = builtinResourceDirectory + builtinPath.substr(pos + strlen(pathPrefix)); - else - path = builtinResourceDirectory + builtinPath; - - future_t> fut; - createFile(future, path.c_str(), core::bitflag(IFile::ECF_READ) :: IFile::ECF_MAPPABLE); - auto file = fut.get(); - if (file.get()) - { - return file; - } - return nullptr; -#endif -} - core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const { #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ if (found.first && found.second) { auto fileView = core::make_smart_refctd_ptr>( - core::smart_refctd_ptr(this), builtinPath, IFile::ECF_READ, - found.first, + const_cast(found.first), found.second ); return fileView; @@ -58,14 +33,21 @@ core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::s return nullptr; } +constexpr const char* builtinPathPrefix = "nbl/builtin/"; bool ISystem::exists(const system::path& filename, const core::bitflag flags) const { const bool writeUsage = flags.value&IFile::ECF_WRITE; -#ifdef _NBL_EMBED_BUILTIN_RESOURCES_ - std::pair found = nbl::builtin::get_resource_runtime(filename.string()); - if (!writeUsage && found.first && found.second) - return true; -#endif + if (!writeUsage && filename.string().find(builtinPathPrefix)==0) + { + #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + std::pair found = nbl::builtin::get_resource_runtime(filename.string()); + if (found.first && found.second) + return true; + #else + if (exists(builtinResourceDirectory/filename)) + return true; + #endif + } // filename too long if (filename.string().size() >= sizeof(SRequestParams_CREATE_FILE::filename)) return false; @@ -78,17 +60,14 @@ bool ISystem::exists(const system::path& filename, const core::bitflag found = nbl::builtin::get_resource_runtime(curPath.string()); - if (found.first && found.second) - return true; - #endif - // then check for presence in an archive auto archives = m_cachedArchiveFiles.findRange(curPath); if (!archives.empty()) @@ -103,33 +82,55 @@ bool ISystem::isPathReadOnly(const system::path& p) const core::vector ISystem::listItemsInDirectory(const system::path& p) const { core::vector res; - res.reserve(128u); + res.reserve(512u); - // TODO: check for path being a builtin - if (isPathReadOnly(p)) // TODO: better check for archives + auto addArchiveItems = [this,&res](const path& archPath) -> void { - auto curPath = p; - while (!curPath.empty() && curPath.parent_path() != curPath) + const auto archives = m_cachedArchiveFiles.findRange(archPath); + for (auto& arch : archives) { - auto archives = m_cachedArchiveFiles.findRange(curPath); - for (auto& arch : archives) - { - auto rel = std::filesystem::relative(p, arch.first); - auto res = arch.second->listAssets(rel.generic_string().c_str()); - std::for_each(res.begin(), res.end(), [&arch](system::path& p) {p = arch.first / p; }); - return res; - } - - curPath = curPath.parent_path().generic_string(); + const auto assets = arch.second->listAssets(); + for (auto& item : assets) + res.push_back(archPath/item.pathRelativeToArchive); } + }; + + std::error_code err; + const auto directories = std::filesystem::recursive_directory_iterator(p,err); + if (!err) + for (auto entry : directories) + { + res.push_back(entry.path()); + // entry could have been an archive + addArchiveItems(entry.path()); } else { - uint32_t fileCount = std::distance(std::filesystem::recursive_directory_iterator(p), std::filesystem::recursive_directory_iterator{}); - for (auto entry : std::filesystem::recursive_directory_iterator(p)) - res.push_back(entry.path()); + #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + // TODO: Change the python generator and make builtinResourceData.cpp's `resourcesByFilename` a nicely named `extern` variable + // then in ISystem precompute a [unordered] multimap with keys being builtin subpaths and values being full paths they contain + // find all the values here and iterate over them, adding to `res + #else + err.clear(); + // check root path is prefixed with "nbl/builtin/" + if (p.string().find(builtinPathPrefix) == 0) + { + const auto subdirs = std::filesystem::recursive_directory_iterator(builtinResourceDirectory/p,err); + if (!err) + for (auto entry : subdirs) // there are never any archives inside builtins + res.push_back(entry.path()); + } + #endif + // check for part of subpath being an archive + system::path path = std::filesystem::exists(p) ? std::filesystem::canonical(p.parent_path()):p.parent_path(); + // going up the directory tree + while (!path.empty() && path.parent_path()!=path) + { + path = std::filesystem::exists(path) ? std::filesystem::canonical(path):path; + addArchiveItems(path); + path = path.parent_path(); + } } - // TODO: recurse into any archives which could have been found! return res; } @@ -204,18 +205,26 @@ bool ISystem::copy(const system::path& from, const system::path& to) void ISystem::createFile(future_t>& future, std::filesystem::path filename, const core::bitflag flags, const std::string_view& accessToken) { + // canonicalize + if (std::filesystem::exists(filename)) + filename = std::filesystem::canonical(filename); // try builtins - if (!(flags.value&IFile::ECF_WRITE)) + if (!(flags.value&IFile::ECF_WRITE) && filename.string().find(builtinPathPrefix)==0) { - auto file = loadBuiltinData(filename.string()); - if (file) - { - future.notify(std::move(file)); + #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ + auto file = impl_loadEmbeddedBuiltinData(filename.string(),nbl::builtin::get_resource_runtime(filename.string())); + if (file) + { + future.notify(std::move(file)); + return; + } + #else + createFile(future,builtinResourceDirectory/filename,flags); return; - } + #endif } - // try archives - if (flags.value&IFile::ECF_READ) + // try archives (readonly, for now) + if (!(flags.value&IFile::ECF_WRITE)) { const auto found = findFileInArchive(filename); if (found.archive) From f9d4ec92876e21881a5be54070d6f6d7783d1ba8 Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 17:50:52 +0100 Subject: [PATCH 50/91] fix up the GLSL inclusion into IDE projects some more --- src/nbl/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index c1e7c1d630..4021197bd7 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -511,18 +511,18 @@ endmacro() # just gather all the header files and later put them into project so it's easy to search for things using IDE file(GLOB_RECURSE NABLA_HEADERS_PRIV1 "*.h") file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") -set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) #always install builtins (some may be included in cpp regardless if embedded or not) foreach(X IN LISTS nbl_resources_to_embed) list(APPEND NABLA_HEADERS_PUBLIC ${NBL_ROOT_PATH}/include/${X}) endforeach() +set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) + # declare the library! add_library(Nabla STATIC ${NABLA_SRCS_COMMON} ${NABLA_HEADERS} - ${nbl_resources_to_embed} $ $ $ From 4243db2357d20d8d71e85ee3dea7c77c15428b38 Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 17:52:11 +0100 Subject: [PATCH 51/91] finalize what `IFileArchive` will look like --- include/nbl/system/CArchiveLoaderTar.h | 91 -------------------------- include/nbl/system/IFileArchive.h | 39 ++++------- src/nbl/system/CArchiveLoaderTar.h | 42 ++++++++++++ 3 files changed, 55 insertions(+), 117 deletions(-) delete mode 100644 include/nbl/system/CArchiveLoaderTar.h create mode 100644 src/nbl/system/CArchiveLoaderTar.h diff --git a/include/nbl/system/CArchiveLoaderTar.h b/include/nbl/system/CArchiveLoaderTar.h deleted file mode 100644 index d859fbff76..0000000000 --- a/include/nbl/system/CArchiveLoaderTar.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef __NBL_SYSTEM_C_ARCHIVE_LOADER_TAR_H_INCLUDED__ -#define __NBL_SYSTEM_C_ARCHIVE_LOADER_TAR_H_INCLUDED__ -#include "IFileArchive.h" - -namespace nbl::system -{ - enum E_TAR_LINK_INDICATOR - { - ETLI_REGULAR_FILE_OLD = 0, - ETLI_REGULAR_FILE = '0', - ETLI_LINK_TO_ARCHIVED_FILE = '1', // Hard link - ETLI_SYMBOLIC_LINK = '2', - ETLI_CHAR_SPECIAL_DEVICE = '3', - ETLI_BLOCK_SPECIAL_DEVICE = '4', - ETLI_DIRECTORY = '5', - ETLI_FIFO_SPECIAL_FILE = '6', - ETLI_CONTIGUOUS_FILE = '7' - }; - - // byte-align structures -#include "nbl/nblpack.h" - - struct STarHeader - { - char FileName[100]; - char FileMode[8]; - char UserID[8]; - char GroupID[8]; - char Size[12]; - char ModifiedTime[12]; - char Checksum[8]; - char Link; - char LinkName[100]; - char Magic[6]; - char USTARVersion[2]; - char UserName[32]; - char GroupName[32]; - char DeviceMajor[8]; - char DeviceMinor[8]; - char FileNamePrefix[155]; - } PACK_STRUCT; - - // Default alignment -#include "nbl/nblunpack.h" - - class CFileArchiveTar : public IFileArchive - { - public: - CFileArchiveTar(core::smart_refctd_ptr&& file, core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger = nullptr) : - IFileArchive(std::move(file), std::move(system), std::move(logger)) - { - if (m_file.get()) - { - populateFileList(); - } - setFlagsVectorSize(m_files.size()); - } - virtual core::smart_refctd_ptr readFile_impl(const SOpenFileParams& params) override; - private: - uint32_t populateFileList(); - }; - - class CArchiveLoaderTar : public IArchiveLoader - { - public: - CArchiveLoaderTar(core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(system), std::move(logger)) {} - virtual bool isALoadableFileFormat(IFile* file) const override - { - return file->getFileName().extension() == ".tar"; // TODO: ekhm, check the old CTarReader - } - - virtual const char** getAssociatedFileExtensions() const override - { - static const char* ext[]{ "tar", nullptr }; - return ext; - } - - private: - virtual core::smart_refctd_ptr createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const override - { - core::smart_refctd_ptr archive = nullptr; - if (file.get()) - { - archive = core::make_smart_refctd_ptr(std::move(file), core::smart_refctd_ptr(m_system)); - } - return archive; - } - }; -} - -#endif \ No newline at end of file diff --git a/include/nbl/system/IFileArchive.h b/include/nbl/system/IFileArchive.h index 4d19746de5..9dbe5b2e02 100644 --- a/include/nbl/system/IFileArchive.h +++ b/include/nbl/system/IFileArchive.h @@ -25,9 +25,9 @@ class IFileArchive : public core::IReferenceCounted enum E_ALLOCATOR_TYPE { EAT_NONE = 0, - EAT_NULL, - EAT_VIRTUAL_ALLOC, - EAT_MALLOC + EAT_NULL, // read directly from archive's underlying mapped file + EAT_VIRTUAL_ALLOC, // decompress to RAM (with sparse paging) + EAT_MALLOC // decompress to RAM }; //! An entry in a list of items, can be a folder or a file. struct SListEntry @@ -38,13 +38,11 @@ class IFileArchive : public core::IReferenceCounted //! The size of the file in bytes size_t size; - //! The ID of the file in an archive - /** This is used to link the FileList entry to extra info held about this - file in an archive, which can hold things like data offset and CRC. */ - uint32_t ID; - //! FileOffset inside an archive - uint32_t offset; + size_t offset; + + //! The ID of the file in an archive, it maps it to a memory pool entry for CFileView + uint32_t ID; // `EAT_NONE` for directories E_ALLOCATOR_TYPE allocatorType; @@ -77,28 +75,17 @@ class IFileArchive : public core::IReferenceCounted protected: IFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger) : m_defaultAbsolutePath(std::move(_defaultAbsolutePath)), m_logger(std::move(logger)) {} -/* - virtual void addItem(const system::path& fullPath, uint32_t offset, uint32_t size, E_ALLOCATOR_TYPE allocatorType, uint32_t id = 0) - { - SFileListEntry entry; - entry.ID = id ? id : m_items.size(); - entry.offset = offset; - entry.size = size; - entry.name = fullPath; - entry.allocatorType = allocatorType; - entry.fullName = entry.name; - - core::deletePathFromFilename(entry.name); - m_items.insert(std::lower_bound(m_items.begin(), m_items.end(), entry), entry); - } -*/ - inline uint32_t getIndexFromPath(const system::path& pathRelativeToArchive) const + inline const SListEntry* getItemFromPath(const system::path& pathRelativeToArchive) const { const IFileArchive::SListEntry itemToFind = { pathRelativeToArchive }; - return std::distance(m_items.begin(),std::lower_bound(m_items.begin(),m_items.end(),itemToFind)); + const auto found = std::lower_bound(m_items.begin(),m_items.end(),itemToFind); + if (found!=m_items.end() || found->pathRelativeToArchive!=pathRelativeToArchive) + return nullptr; + return &(*found); } + std::mutex itemMutex; // TODO: update to readers writer lock path m_defaultAbsolutePath; // files and directories core::vector m_items; diff --git a/src/nbl/system/CArchiveLoaderTar.h b/src/nbl/system/CArchiveLoaderTar.h new file mode 100644 index 0000000000..1a3aac9138 --- /dev/null +++ b/src/nbl/system/CArchiveLoaderTar.h @@ -0,0 +1,42 @@ +#ifndef _NBL_SYSTEM_C_ARCHIVE_LOADER_TAR_H_INCLUDED_ +#define _NBL_SYSTEM_C_ARCHIVE_LOADER_TAR_H_INCLUDED_ + + +#include "nbl/system/CFileArchive.h" + + +namespace nbl::system +{ + +class CArchiveLoaderTar final : public IArchiveLoader +{ + public: + class CArchive : public CFileArchive + { + public: + CArchive(core::smart_refctd_ptr&& _file, system::logger_opt_smart_ptr&& logger, core::vector&& _items) : + CFileArchive(path(_file->getFileName()),std::move(logger),std::move(_items)), m_file(std::move(_file)) {} + + // + protected: + core::smart_refctd_ptr m_file; + }; + + CArchiveLoaderTar(system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(logger)) {} + virtual bool isALoadableFileFormat(IFile* file) const override + { + return !!createArchive_impl(core::smart_refctd_ptr(file),""); + } + + const char** getAssociatedFileExtensions() const override + { + static const char* ext[]{ "tar", nullptr }; + return ext; + } + + private: + core::smart_refctd_ptr createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const override; +}; + +} +#endif \ No newline at end of file From 9654a0dbb07dd5e01a4a4ad36109c2a95ba63688 Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 17:59:01 +0100 Subject: [PATCH 52/91] HelloWorld works --- include/nbl/system/CArchiveLoaderZip.h | 205 ----- include/nbl/system/CFileArchive.h | 97 +- src/nbl/system/CArchiveLoaderTar.cpp | 130 ++- src/nbl/system/CArchiveLoaderZip.cpp | 1163 +++++++++++++----------- src/nbl/system/CArchiveLoaderZip.h | 109 +++ src/nbl/system/ISystem.cpp | 8 +- 6 files changed, 890 insertions(+), 822 deletions(-) delete mode 100644 include/nbl/system/CArchiveLoaderZip.h create mode 100644 src/nbl/system/CArchiveLoaderZip.h diff --git a/include/nbl/system/CArchiveLoaderZip.h b/include/nbl/system/CArchiveLoaderZip.h deleted file mode 100644 index 7a8bc402b3..0000000000 --- a/include/nbl/system/CArchiveLoaderZip.h +++ /dev/null @@ -1,205 +0,0 @@ -#ifndef __NBL_SYSTEM_C_ARCHIVE_LOADER_ZIP_H_INCLUDED__ -#define __NBL_SYSTEM_C_ARCHIVE_LOADER_ZIP_H_INCLUDED__ -#include "IFileArchive.h" -#include "nbl/system/path.h" -#include "nbl/system/ISystem.h" - -namespace nbl::system -{ -// set if the file is encrypted -constexpr int16_t ZIP_FILE_ENCRYPTED = 0x0001; -// the fields crc-32, compressed size and uncompressed size are set to -// zero in the local header -constexpr int16_t ZIP_INFO_IN_DATA_DESCRIPTOR = 0x0008; - -// byte-align structures -#include "nbl/nblpack.h" - -struct SZIPFileDataDescriptor -{ - uint32_t CRC32; - uint32_t CompressedSize; - uint32_t UncompressedSize; -} PACK_STRUCT; - -struct SZIPFileHeader -{ - uint32_t Sig; // 'PK0304' little endian (0x04034b50) - int16_t VersionToExtract; - int16_t GeneralBitFlag; - int16_t CompressionMethod; - int16_t LastModFileTime; - int16_t LastModFileDate; - SZIPFileDataDescriptor DataDescriptor; - int16_t FilenameLength; - int16_t ExtraFieldLength; - // filename (variable size) - // extra field (variable size ) -} PACK_STRUCT; - -struct SZIPFileCentralDirFileHeader -{ - uint32_t Sig; // 'PK0102' (0x02014b50) - uint16_t VersionMadeBy; - uint16_t VersionToExtract; - uint16_t GeneralBitFlag; - uint16_t CompressionMethod; - uint16_t LastModFileTime; - uint16_t LastModFileDate; - uint32_t CRC32; - uint32_t CompressedSize; - uint32_t UncompressedSize; - uint16_t FilenameLength; - uint16_t ExtraFieldLength; - uint16_t FileCommentLength; - uint16_t DiskNumberStart; - uint16_t InternalFileAttributes; - uint32_t ExternalFileAttributes; - uint32_t RelativeOffsetOfLocalHeader; - - // filename (variable size) - // extra field (variable size) - // file comment (variable size) - -} PACK_STRUCT; - -struct SZIPFileCentralDirEnd -{ - uint32_t Sig; // 'PK0506' end_of central dir signature // (0x06054b50) - uint16_t NumberDisk; // number of this disk - uint16_t NumberStart; // number of the disk with the start of the central directory - uint16_t TotalDisk; // total number of entries in the central dir on this disk - uint16_t TotalEntries; // total number of entries in the central dir - uint32_t Size; // size of the central directory - uint32_t Offset; // offset of start of centraldirectory with respect to the starting disk number - uint16_t CommentLength; // zipfile comment length - // zipfile comment (variable size) -} PACK_STRUCT; - -struct SZipFileExtraHeader -{ - int16_t ID; - int16_t Size; -} PACK_STRUCT; - -struct SZipFileAESExtraData -{ - int16_t Version; - uint8_t Vendor[2]; - uint8_t EncryptionStrength; - int16_t CompressionMode; -} PACK_STRUCT; - -enum E_GZIP_FLAGS -{ - EGZF_TEXT_DAT = 1, - EGZF_CRC16 = 2, - EGZF_EXTRA_FIELDS = 4, - EGZF_FILE_NAME = 8, - EGZF_COMMENT = 16 -}; - -struct SGZIPMemberHeader -{ - uint16_t sig; // 0x8b1f - uint8_t compressionMethod; // 8 = deflate - uint8_t flags; - uint32_t time; - uint8_t extraFlags; // slow compress = 2, fast compress = 4 - uint8_t operatingSystem; -} PACK_STRUCT; - -// Default alignment -#include "nbl/nblunpack.h" - -//! Contains extended info about zip files in the archive -struct SZipFileEntry -{ - //! Position of data in the archive file - int32_t Offset; - - //! The header for this file containing compression info etc - SZIPFileHeader header; -}; - -class CFileArchiveZip : public IFileArchive -{ -private: - bool m_isGZip; - core::vector m_fileInfo; - std::string m_password = ""; // TODO password -public: - CFileArchiveZip(core::smart_refctd_ptr&& file, core::smart_refctd_ptr&& system, bool isGZip, const std::string_view& password, system::logger_opt_smart_ptr&& logger = nullptr) : - IFileArchive(std::move(file), std::move(system), std::move(logger)), m_isGZip(isGZip), m_password(password) - { - size_t offset = 0; - if (m_file.get()) - { - // load file entries - if (m_isGZip) - while (scanGZipHeader(offset)) {} - else - while (scanZipHeader(offset)) {} - - setFlagsVectorSize(m_files.size()); - } - } - virtual core::smart_refctd_ptr readFile_impl(const SOpenFileParams& params) override; -private: - bool scanGZipHeader(size_t& offset); - bool scanZipHeader(size_t& offset, bool ignoreGPBits = false); - bool scanCentralDirectoryHeader(size_t& offset); - E_ALLOCATOR_TYPE getAllocatorType(uint32_t compressionType) - { - switch (compressionType) - { - case 0: return EAT_NULL; - default: return EAT_VIRTUAL_ALLOC; - } - } -}; - -class CArchiveLoaderZip : public IArchiveLoader -{ -public: - CArchiveLoaderZip(core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(system), std::move(logger)) {} - virtual bool isALoadableFileFormat(IFile* file) const override - { - SZIPFileHeader header; - system::future fut; - file->read(fut, &header.Sig, 0, 4); - fut.get(); - - return header.Sig == 0x04034b50 || // ZIP - (header.Sig & 0xffff) == 0x8b1f; // gzip - } - - virtual const char** getAssociatedFileExtensions() const override - { - static const char* ext[]{ "zip", "pk3", "tgz", "gz", nullptr}; - return ext; - } - -private: - virtual core::smart_refctd_ptr createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const override - { - core::smart_refctd_ptr archive = nullptr; - if (file.get()) - { - uint16_t sig; - { - system::future fut; - file->read(fut, &sig, 0, 2); - fut.get(); - } - bool isGZip = (sig == 0x8b1f); - - archive = core::make_smart_refctd_ptr(std::move(file), core::smart_refctd_ptr(m_system), isGZip, password); - } - return archive; - } -}; - -} - -#endif \ No newline at end of file diff --git a/include/nbl/system/CFileArchive.h b/include/nbl/system/CFileArchive.h index 21e4407580..6a837ca054 100644 --- a/include/nbl/system/CFileArchive.h +++ b/include/nbl/system/CFileArchive.h @@ -2,14 +2,15 @@ // This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" // For conditions of distribution and use, see copyright notice in nabla.h // See the original file in irrlicht source for authors - #ifndef _NBL_SYSTEM_C_FILE_ARCHIVE_H_INCLUDED_ #define _NBL_SYSTEM_C_FILE_ARCHIVE_H_INCLUDED_ + #include "nbl/system/IFileArchive.h" #include "nbl/system/CFileView.h" #include "nbl/system/IFileViewAllocator.h" + namespace nbl::system { @@ -58,62 +59,74 @@ class CFileArchive : public IFileArchive static inline constexpr size_t ALIGNOF_INNER_ARCHIVE_FILE = std::max(alignof(CInnerArchiveFile), alignof(CInnerArchiveFile)); public: - core::smart_refctd_ptr readFile(const SOpenFileParams& params) + inline core::smart_refctd_ptr getFile(const path& pathRelativeToArchive, const std::string_view& password) override { - auto index = getIndexByPath(params.filename); - if (index == -1) return nullptr; - switch (listAssets()[index].allocatorType) + std::unique_lock lock(itemMutex); + + const auto* item = getItemFromPath(pathRelativeToArchive); + if (!item) + return nullptr; + /* + switch (item->allocatorType) { - case EAT_NULL: - return getFile_impl(params, index); - break; - case EAT_MALLOC: - return getFile_impl(params, index); - break; - case EAT_VIRTUAL_ALLOC: - return getFile_impl(params, index); - break; + case EAT_NULL: + return getFile_impl(item); + break; + case EAT_MALLOC: + return getFile_impl(item); + break; + case EAT_VIRTUAL_ALLOC: + return getFile_impl(item); + break; + default: // directory or something + break; } - assert(false); + */ return nullptr; } - virtual core::smart_refctd_ptr readFile_impl(const SOpenFileParams& params) = 0; - int32_t getIndexByPath(const system::path& p) + + protected: + CFileArchive(path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger, core::vector _items) : + IFileArchive(std::move(_defaultAbsolutePath),std::move(logger)) { - for (int i = 0; i < m_files.size(); ++i) - { - if (p == m_files[i].fullName) return i; - } - return -1; + m_items = std::move(_items); + std::sort(m_items.begin(),m_items.end()); + + const auto fileCount = m_items.size(); + m_filesBuffer = (std::byte*)_NBL_ALIGNED_MALLOC(fileCount*SIZEOF_INNER_ARCHIVE_FILE, ALIGNOF_INNER_ARCHIVE_FILE); + m_fileFlags = (std::atomic_flag*)_NBL_ALIGNED_MALLOC(fileCount*sizeof(std::atomic_flag), alignof(std::atomic_flag)); + for (size_t i=0u; i - core::smart_refctd_ptr> getFile_impl(const SOpenFileParams& params, const uint32_t index) + core::smart_refctd_ptr> getFile_impl(const IFileArchive::SListEntry* item) { - std::unique_lock lock(fileMutex); - - auto* file = reinterpret_cast*>(m_filesBuffer + index * SIZEOF_INNER_ARCHIVE_FILE); - // intentionally calling grab() on maybe-not-existing object + auto* file = reinterpret_cast*>(m_filesBuffer+item->ID*SIZEOF_INNER_ARCHIVE_FILE); + // NOTE: Intentionally calling grab() on maybe-not-existing object! const auto oldRefcount = file->grab(); - if (oldRefcount == 0) // need to construct + if (oldRefcount==0) // need to construct (previous refcount was 0) { - m_fileFlags[index].wait(true); //what should the param of wait be? - new (file, &m_fileFlags[index]) CInnerArchiveFile(static_cast*>(readFile_impl(params).get()), &m_fileFlags[index]); + // Might have barged inbetween a refctr drop and finish of a destructor + delete, + // need to wait for the "alive" flag to become `false` which tells us `operator delete` has finished. + m_fileFlags[item->ID].wait(true); + // coast is clear, do placement new + new (file, &m_fileFlags[item->ID]) CInnerArchiveFile( + static_cast*>(readFile_impl(params).get()), + &m_fileFlags[item->ID] + ); } - return core::smart_refctd_ptr>(file, core::dont_grab); + return core::smart_refctd_ptr>(file,core::dont_grab); } + */ - protected: - CFileArchive(core::smart_refctd_ptr&& file, system::logger_opt_smart_ptr&& logger) : IFileArchive(std::move(file),std::move(logger)) {} - ~CFileArchive() - { - _NBL_ALIGNED_FREE(m_filesBuffer); - _NBL_ALIGNED_FREE(m_fileFlags); - } - - void setFlagsVectorSize(size_t fileCount); - - std::mutex fileMutex; std::atomic_flag* m_fileFlags = nullptr; std::byte* m_filesBuffer = nullptr; }; diff --git a/src/nbl/system/CArchiveLoaderTar.cpp b/src/nbl/system/CArchiveLoaderTar.cpp index 9f45defabb..6f893a9250 100644 --- a/src/nbl/system/CArchiveLoaderTar.cpp +++ b/src/nbl/system/CArchiveLoaderTar.cpp @@ -1,44 +1,84 @@ #include "nbl/system/CArchiveLoaderTar.h" -namespace nbl::system + +enum E_TAR_LINK_INDICATOR { - core::smart_refctd_ptr CFileArchiveTar::readFile_impl(const SOpenFileParams& params) - { - auto found = std::find_if(m_files.begin(), m_files.end(), [¶ms](const SFileListEntry& entry) { return params.filename == entry.fullName; }); + ETLI_REGULAR_FILE_OLD = 0, + ETLI_REGULAR_FILE = '0', + ETLI_LINK_TO_ARCHIVED_FILE = '1', // Hard link + ETLI_SYMBOLIC_LINK = '2', + ETLI_CHAR_SPECIAL_DEVICE = '3', + ETLI_BLOCK_SPECIAL_DEVICE = '4', + ETLI_DIRECTORY = '5', + ETLI_FIFO_SPECIAL_FILE = '6', + ETLI_CONTIGUOUS_FILE = '7' +}; - if (found != m_files.end()) - { - uint8_t* buff = (uint8_t*)m_file->getMappedPointer() + found->offset; - auto a = core::make_smart_refctd_ptr>( - core::smart_refctd_ptr(m_system), - params.absolutePath, - IFile::ECF_READ_WRITE, // TODO: this file cannot grow, unsure whether we should allow write access! - buff, - found->size); - return a; - } +// byte-align structures +#include "nbl/nblpack.h" +struct STarHeader +{ + char FileName[100]; + char FileMode[8]; + char UserID[8]; + char GroupID[8]; + char Size[12]; + char ModifiedTime[12]; + char Checksum[8]; + char Link; + char LinkName[100]; + char Magic[6]; + char USTARVersion[2]; + char UserName[32]; + char GroupName[32]; + char DeviceMajor[8]; + char DeviceMinor[8]; + char FileNamePrefix[155]; +} PACK_STRUCT; +#include "nbl/nblunpack.h" + + +using namespace nbl; +using namespace nbl::system; + +/* +core::smart_refctd_ptr CArchiveLoaderTar::CArchive::readFile_impl(const SListEntry* item) +{ + uint8_t* buff = reinterpret_cast(m_file->getMappedPointer())+item->offset; + auto a = core::make_smart_refctd_ptr>( + core::smart_refctd_ptr(m_system), + params.absolutePath, + IFile::ECF_READ_WRITE, // TODO: this file cannot grow, unsure whether we should allow write access! + buff, + found->size); + return a; +} +*/ + +core::smart_refctd_ptr CArchiveLoaderTar::createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const +{ + if (!file || !(file->getFlags()&IFileBase::ECF_MAPPABLE)) return nullptr; - } - uint32_t CFileArchiveTar::populateFileList() + + core::vector items; + for (size_t pos=0ull; true; ) { - size_t readOffset; STarHeader fHead; - m_files.clear(); - - uint32_t pos = 0; - while (pos + sizeof(STarHeader) < m_file->getSize()) { - // seek to next file header - readOffset = pos; - - // read the header - read_blocking(m_file.get(), &fHead, readOffset, sizeof fHead); - - // only add standard files for now - if (fHead.Link == ETLI_REGULAR_FILE || ETLI_REGULAR_FILE_OLD) + IFile::success_t success; + file->read(success,&fHead,pos,sizeof(fHead)); + if (!success) + break; + } + // only add standard files for now + switch (fHead.Link) + { + case ETLI_REGULAR_FILE: + [[fallthrough]]; + case ETLI_REGULAR_FILE_OLD: { std::string fullPath = ""; - fullPath.reserve(255); + fullPath.reserve(256); // USTAR archives have a filename prefix // may not be null terminated, copy carefully! @@ -68,29 +108,35 @@ namespace nbl::system np++; } - uint32_t size = strtoul(sSize.c_str(), NULL, 8); + // TODO: this is horrible, replace + const size_t size = strtoul(sSize.c_str(), NULL, 8); if (errno == ERANGE) m_logger.log("File %s is too large", ILogger::ELL_WARNING, fullPath.c_str()); // save start position - uint32_t offset = pos + 512; + const uint32_t offset = pos + 512; // move to next file header block pos = offset + (size / 512) * 512 + ((size % 512) ? 512 : 0); // add file to list - addItem(fullPath, offset, size, EAT_NULL); + auto& item = items.emplace_back(); + item.pathRelativeToArchive = fullPath; + item.size = size; + item.offset = offset; + item.ID = items.size()-1u; + item.allocatorType = IFileArchive::EAT_NULL; + break; } - else - { - // todo: ETLI_DIRECTORY, ETLI_LINK_TO_ARCHIVED_FILE - + // TODO: ETLI_DIRECTORY, ETLI_LINK_TO_ARCHIVED_FILE + default: // move to next block pos += 512; - } - + break; } - - return m_files.size(); } + if (items.empty()) + return nullptr; + + return core::make_smart_refctd_ptr(std::move(file),core::smart_refctd_ptr(m_logger.get()),std::move(items)); } \ No newline at end of file diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index 42aed5296c..1ff11425ec 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -1,664 +1,769 @@ #include "nbl/system/CArchiveLoaderZip.h" -#include "nbl/system/IFileViewAllocator.h" + + #include + #include #include + #include + +#include "nbl/nblpack.h" +struct SZIPFileCentralDirFileHeader +{ + uint32_t Sig; // 'PK0102' (0x02014b50) + uint16_t VersionMadeBy; + uint16_t VersionToExtract; + uint16_t GeneralBitFlag; + uint16_t CompressionMethod; + uint16_t LastModFileTime; + uint16_t LastModFileDate; + uint32_t CRC32; + uint32_t CompressedSize; + uint32_t UncompressedSize; + uint16_t FilenameLength; + uint16_t ExtraFieldLength; + uint16_t FileCommentLength; + uint16_t DiskNumberStart; + uint16_t InternalFileAttributes; + uint32_t ExternalFileAttributes; + uint32_t RelativeOffsetOfLocalHeader; + + // filename (variable size) + // extra field (variable size) + // file comment (variable size) + +} PACK_STRUCT; +struct SZIPFileCentralDirEnd +{ + uint32_t Sig; // 'PK0506' end_of central dir signature // (0x06054b50) + uint16_t NumberDisk; // number of this disk + uint16_t NumberStart; // number of the disk with the start of the central directory + uint16_t TotalDisk; // total number of entries in the central dir on this disk + uint16_t TotalEntries; // total number of entries in the central dir + uint32_t Size; // size of the central directory + uint32_t Offset; // offset of start of centraldirectory with respect to the starting disk number + uint16_t CommentLength; // zipfile comment length + // zipfile comment (variable size) +} PACK_STRUCT; +struct SZipFileAESExtraData +{ + int16_t Version; + uint8_t Vendor[2]; + uint8_t EncryptionStrength; + int16_t CompressionMode; +} PACK_STRUCT; +struct SGZIPMemberHeader +{ + uint16_t sig; // 0x8b1f + uint8_t compressionMethod; // 8 = deflate + uint8_t flags; + uint32_t time; + uint8_t extraFlags; // slow compress = 2, fast compress = 4 + uint8_t operatingSystem; +} PACK_STRUCT; +#include "nbl/nblunpack.h" + +enum E_GZIP_FLAGS +{ + EGZF_TEXT_DAT = 1, + EGZF_CRC16 = 2, + EGZF_EXTRA_FIELDS = 4, + EGZF_FILE_NAME = 8, + EGZF_COMMENT = 16 +}; +struct SZipFileExtraHeader +{ + int16_t ID; + int16_t Size; +}; + +// set if the file is encrypted +constexpr int16_t ZIP_FILE_ENCRYPTED = 0x0001; +// the fields crc-32, compressed size and uncompressed size are set to +// zero in the local header +constexpr int16_t ZIP_INFO_IN_DATA_DESCRIPTOR = 0x0008; + + +using namespace nbl; +using namespace nbl::system; + + +core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const +{ + if (!file) + return nullptr; +/* + core::smart_refctd_ptr archive = nullptr; + if (file.get()) + { + uint16_t sig; + { + system::future fut; + file->read(fut, &sig, 0, 2); + fut.get(); + } + bool isGZip = (sig == 0x8b1f); + + archive = core::make_smart_refctd_ptr(std::move(file), core::smart_refctd_ptr(m_system), isGZip, password); + } + return archive; +*/ + return nullptr; +} + #if 0 -namespace nbl::system +bool CFileArchiveZip::scanGZipHeader(size_t& offset) { - bool CFileArchiveZip::scanGZipHeader(size_t& offset) + SZipFileEntry entry; + entry.Offset = 0; + memset(&entry.header, 0, sizeof(SZIPFileHeader)); + + SGZIPMemberHeader header; + system::future headerFuture; + m_file->read(headerFuture, &header, offset, sizeof(SGZIPMemberHeader)); + headerFuture.get(); + offset += sizeof(SGZIPMemberHeader); + if (headerFuture.get() == sizeof(SGZIPMemberHeader)) { - SZipFileEntry entry; - entry.Offset = 0; - memset(&entry.header, 0, sizeof(SZIPFileHeader)); - - SGZIPMemberHeader header; - system::future headerFuture; - m_file->read(headerFuture, &header, offset, sizeof(SGZIPMemberHeader)); - headerFuture.get(); - offset += sizeof(SGZIPMemberHeader); - if (headerFuture.get() == sizeof(SGZIPMemberHeader)) + // check header value + if (header.sig != 0x8b1f) + return false; + // now get the file info + if (header.flags & EGZF_EXTRA_FIELDS) { - // check header value - if (header.sig != 0x8b1f) - return false; - // now get the file info - if (header.flags & EGZF_EXTRA_FIELDS) - { - // read lenth of extra data - uint16_t dataLen; + // read lenth of extra data + uint16_t dataLen; - system::future lenFuture; - m_file->read(lenFuture, &dataLen, offset, 2); - lenFuture.get(); - offset += 2; // TODO: I think it should be `+= dataLen;` - } - std::filesystem::path zipFileName = ""; - if (header.flags & EGZF_FILE_NAME) + system::future lenFuture; + m_file->read(lenFuture, &dataLen, offset, 2); + lenFuture.get(); + offset += 2; // TODO: I think it should be `+= dataLen;` + } + std::filesystem::path zipFileName = ""; + if (header.flags & EGZF_FILE_NAME) + { + char c; { - char c; - { - system::future fut; - m_file->read(fut, &c, offset++, 1); - fut.get(); - } - while (c) - { - zipFileName += c; - system::future fut; - m_file->read(fut, &c, offset++, 1); - fut.get(); - } + system::future fut; + m_file->read(fut, &c, offset++, 1); + fut.get(); } - else + while (c) { - // no file name? - zipFileName = m_file->getFileName().filename(); - - // rename tgz to tar or remove gz extension - if (zipFileName.extension() == ".tgz") - { - zipFileName.string()[zipFileName.string().size() - 2] = 'a'; - zipFileName.string()[zipFileName.string().size() - 1] = 'r'; - } - else if (zipFileName.extension() == ".gz") - { - zipFileName.string()[zipFileName.string().size() - 3] = 0; - } + zipFileName += c; + system::future fut; + m_file->read(fut, &c, offset++, 1); + fut.get(); } - if (header.flags & EGZF_COMMENT) + } + else + { + // no file name? + zipFileName = m_file->getFileName().filename(); + + // rename tgz to tar or remove gz extension + if (zipFileName.extension() == ".tgz") { - char c = 'a'; - while (c) - { - system::future fut; - m_file->read(fut, &c, offset++, 1); - fut.get(); - } + zipFileName.string()[zipFileName.string().size() - 2] = 'a'; + zipFileName.string()[zipFileName.string().size() - 1] = 'r'; } - if (header.flags & EGZF_CRC16) - offset += 2; - - entry.Offset = offset; - entry.header.FilenameLength = zipFileName.native().length(); - entry.header.CompressionMethod = header.compressionMethod; - entry.header.DataDescriptor.CompressedSize = (m_file->getSize() - 8) - offset; - - offset += entry.header.DataDescriptor.CompressedSize; - - // read CRC + else if (zipFileName.extension() == ".gz") { - system::future fut; - m_file->read(fut, &entry.header.DataDescriptor.CRC32, offset, 4); - fut.get(); - offset += 4; + zipFileName.string()[zipFileName.string().size() - 3] = 0; } - // read uncompressed size + } + if (header.flags & EGZF_COMMENT) + { + char c = 'a'; + while (c) { system::future fut; - m_file->read(fut, &entry.header.DataDescriptor.UncompressedSize, offset, 4); + m_file->read(fut, &c, offset++, 1); fut.get(); - offset += 4; } + } + if (header.flags & EGZF_CRC16) + offset += 2; + + entry.Offset = offset; + entry.header.FilenameLength = zipFileName.native().length(); + entry.header.CompressionMethod = header.compressionMethod; + entry.header.DataDescriptor.CompressedSize = (m_file->getSize() - 8) - offset; + + offset += entry.header.DataDescriptor.CompressedSize; - addItem(zipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, getAllocatorType(entry.header.CompressionMethod), 0); - m_fileInfo.push_back(entry); + // read CRC + { + system::future fut; + m_file->read(fut, &entry.header.DataDescriptor.CRC32, offset, 4); + fut.get(); + offset += 4; } - return false; + // read uncompressed size + { + system::future fut; + m_file->read(fut, &entry.header.DataDescriptor.UncompressedSize, offset, 4); + fut.get(); + offset += 4; + } + + addItem(zipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, getAllocatorType(entry.header.CompressionMethod), 0); + m_fileInfo.push_back(entry); } + return false; +} + +bool CFileArchiveZip::scanZipHeader(size_t& offset, bool ignoreGPBits) +{ + std::filesystem::path ZipFileName = ""; + SZipFileEntry entry; + entry.Offset = 0; + memset(&entry.header, 0, sizeof(SZIPFileHeader)); - bool CFileArchiveZip::scanZipHeader(size_t& offset, bool ignoreGPBits) { - std::filesystem::path ZipFileName = ""; - SZipFileEntry entry; - entry.Offset = 0; - memset(&entry.header, 0, sizeof(SZIPFileHeader)); + system::future fut; + m_file->read(fut, &entry.header, offset, sizeof(SZIPFileHeader)); + fut.get(); + offset += sizeof(SZIPFileHeader); + } + if (entry.header.Sig != 0x04034b50) + return false; // local file headers end here. + + // read filename + { + char* tmp = new char[entry.header.FilenameLength + 2]; { system::future fut; - m_file->read(fut, &entry.header, offset, sizeof(SZIPFileHeader)); + m_file->read(fut, tmp, offset, entry.header.FilenameLength); fut.get(); - offset += sizeof(SZIPFileHeader); + offset += entry.header.FilenameLength; } + tmp[entry.header.FilenameLength] = 0; + ZipFileName = tmp; + delete[] tmp; + } - if (entry.header.Sig != 0x04034b50) - return false; // local file headers end here. - - // read filename +#ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ + // AES encryption + if ((entry.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (entry.header.CompressionMethod == 99)) + { + int16_t restSize = entry.header.ExtraFieldLength; + SZipFileExtraHeader extraHeader; + while (restSize) { - char* tmp = new char[entry.header.FilenameLength + 2]; { system::future fut; - m_file->read(fut, tmp, offset, entry.header.FilenameLength); + m_file->read(fut, &extraHeader, offset, sizeof(extraHeader)); fut.get(); - offset += entry.header.FilenameLength; + offset += sizeof(extraHeader); } - tmp[entry.header.FilenameLength] = 0; - ZipFileName = tmp; - delete[] tmp; - } - -#ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ - // AES encryption - if ((entry.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (entry.header.CompressionMethod == 99)) - { - int16_t restSize = entry.header.ExtraFieldLength; - SZipFileExtraHeader extraHeader; - while (restSize) + restSize -= sizeof(extraHeader); + if (extraHeader.ID == (int16_t)0x9901) { + SZipFileAESExtraData data; { system::future fut; - m_file->read(fut, &extraHeader, offset, sizeof(extraHeader)); + m_file->read(fut, &data, offset, sizeof(data)); fut.get(); - offset += sizeof(extraHeader); + offset += sizeof(data); } - restSize -= sizeof(extraHeader); - if (extraHeader.ID == (int16_t)0x9901) + + restSize -= sizeof(data); + if (data.Vendor[0] == 'A' && data.Vendor[1] == 'E') { - SZipFileAESExtraData data; - { - system::future fut; - m_file->read(fut, &data, offset, sizeof(data)); - fut.get(); - offset += sizeof(data); - } - - restSize -= sizeof(data); - if (data.Vendor[0] == 'A' && data.Vendor[1] == 'E') - { - // encode values into Sig - // AE-Version | Strength | ActualMode - entry.header.Sig = - ((data.Version & 0xff) << 24) | - (data.EncryptionStrength << 16) | - (data.CompressionMode); - offset += restSize; - break; - } + // encode values into Sig + // AE-Version | Strength | ActualMode + entry.header.Sig = + ((data.Version & 0xff) << 24) | + (data.EncryptionStrength << 16) | + (data.CompressionMode); + offset += restSize; + break; } } } - // move forward length of extra field. - else + } + // move forward length of extra field. + else #endif - if (entry.header.ExtraFieldLength) - offset += entry.header.ExtraFieldLength; + if (entry.header.ExtraFieldLength) + offset += entry.header.ExtraFieldLength; - // if bit 3 was set, use CentralDirectory for setup - if (!ignoreGPBits && entry.header.GeneralBitFlag & ZIP_INFO_IN_DATA_DESCRIPTOR) + // if bit 3 was set, use CentralDirectory for setup + if (!ignoreGPBits && entry.header.GeneralBitFlag & ZIP_INFO_IN_DATA_DESCRIPTOR) + { + SZIPFileCentralDirEnd dirEnd; + m_fileInfo.clear(); + m_files.clear(); + // First place where the end record could be stored + offset = m_file->getSize() - 22; + const char endID[] = { 0x50, 0x4b, 0x05, 0x06, 0x0 }; + char tmp[5] = { '\0' }; + bool found = false; + // search for the end record ID + while (!found && offset > 0) { - SZIPFileCentralDirEnd dirEnd; - m_fileInfo.clear(); - m_files.clear(); - // First place where the end record could be stored - offset = m_file->getSize() - 22; - const char endID[] = { 0x50, 0x4b, 0x05, 0x06, 0x0 }; - char tmp[5] = { '\0' }; - bool found = false; - // search for the end record ID - while (!found && offset > 0) - { - int seek = 8; - { - system::future fut; - m_file->read(fut, tmp, offset, 4); - fut.get(); - offset += 4; - } - switch (tmp[0]) - { - case 0x50: - if (!strcmp(endID, tmp)) - { - seek = 4; - found = true; - } - break; - case 0x4b: - seek = 5; - break; - case 0x05: - seek = 6; - break; - case 0x06: - seek = 7; - break; - } - offset -= seek; - } + int seek = 8; { system::future fut; - m_file->read(fut, &dirEnd, offset, sizeof(dirEnd)); + m_file->read(fut, tmp, offset, 4); fut.get(); - offset += sizeof(dirEnd); + offset += 4; } - m_fileInfo.reserve(dirEnd.TotalEntries); - offset = dirEnd.Offset; - while (scanCentralDirectoryHeader(offset)) {} - return false; + switch (tmp[0]) + { + case 0x50: + if (!strcmp(endID, tmp)) + { + seek = 4; + found = true; + } + break; + case 0x4b: + seek = 5; + break; + case 0x05: + seek = 6; + break; + case 0x06: + seek = 7; + break; + } + offset -= seek; } - entry.Offset = offset; - // move forward length of data - offset += entry.header.DataDescriptor.CompressedSize; - - addItem(ZipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, getAllocatorType(entry.header.CompressionMethod), m_fileInfo.size()); - m_fileInfo.push_back(entry); - return true; - } - - bool CFileArchiveZip::scanCentralDirectoryHeader(size_t& offset) - { - std::filesystem::path ZipFileName = ""; - SZIPFileCentralDirFileHeader entry; { system::future fut; - m_file->read(fut, &entry, offset, sizeof(SZIPFileCentralDirFileHeader)); + m_file->read(fut, &dirEnd, offset, sizeof(dirEnd)); fut.get(); - offset += sizeof(SZIPFileCentralDirFileHeader); + offset += sizeof(dirEnd); } - - if (entry.Sig != 0x02014b50) - return false; // central dir headers end here. - - const long pos = offset; - offset = entry.RelativeOffsetOfLocalHeader; - scanZipHeader(offset, true); - offset = pos + entry.FilenameLength + entry.ExtraFieldLength + entry.FileCommentLength; - m_fileInfo.back().header.DataDescriptor.CompressedSize = entry.CompressedSize; - m_fileInfo.back().header.DataDescriptor.UncompressedSize = entry.UncompressedSize; - m_fileInfo.back().header.DataDescriptor.CRC32 = entry.CRC32; - m_files.back().size = entry.UncompressedSize; - return true; + m_fileInfo.reserve(dirEnd.TotalEntries); + offset = dirEnd.Offset; + while (scanCentralDirectoryHeader(offset)) {} + return false; } + entry.Offset = offset; + // move forward length of data + offset += entry.header.DataDescriptor.CompressedSize; + + addItem(ZipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, getAllocatorType(entry.header.CompressionMethod), m_fileInfo.size()); + m_fileInfo.push_back(entry); + return true; +} - core::smart_refctd_ptr CFileArchiveZip::readFile_impl(const SOpenFileParams& params) +bool CFileArchiveZip::scanCentralDirectoryHeader(size_t& offset) +{ + std::filesystem::path ZipFileName = ""; + SZIPFileCentralDirFileHeader entry; { - size_t readOffset; - auto found = std::find_if(m_files.begin(), m_files.end(), [¶ms](const SFileListEntry& entry) { return params.filename == entry.fullName; }); + system::future fut; + m_file->read(fut, &entry, offset, sizeof(SZIPFileCentralDirFileHeader)); + fut.get(); + offset += sizeof(SZIPFileCentralDirFileHeader); + } - if (found != m_files.end()) - { - const SZipFileEntry& e = m_fileInfo[found->ID]; - wchar_t buf[64]; - // Nabla supports 0, 8, 12, 14, 99 - //0 - The file is stored (no compression) - //1 - The file is Shrunk - //2 - The file is Reduced with compression factor 1 - //3 - The file is Reduced with compression factor 2 - //4 - The file is Reduced with compression factor 3 - //5 - The file is Reduced with compression factor 4 - //6 - The file is Imploded - //7 - Reserved for Tokenizing compression algorithm - //8 - The file is Deflated - //9 - Reserved for enhanced Deflating - //10 - PKWARE Date Compression Library Imploding - //12 - bzip2 - Compression Method from libbz2, WinZip 10 - //14 - LZMA - Compression Method, WinZip 12 - //96 - Jpeg compression - Compression Method, WinZip 12 - //97 - WavPack - Compression Method, WinZip 11 - //98 - PPMd - Compression Method, WinZip 10 - //99 - AES encryption, WinZip 9 - int16_t actualCompressionMethod = e.header.CompressionMethod; - //TODO: CFileView factory - // CFileViewVirtualAllocatorWin32 - // @sadiuk WTF!? You hand out a new file every time!? - core::smart_refctd_ptr> decrypted = nullptr; - uint8_t* decryptedBuf = 0; - uint32_t decryptedSize = e.header.DataDescriptor.CompressedSize; + if (entry.Sig != 0x02014b50) + return false; // central dir headers end here. + + const long pos = offset; + offset = entry.RelativeOffsetOfLocalHeader; + scanZipHeader(offset, true); + offset = pos + entry.FilenameLength + entry.ExtraFieldLength + entry.FileCommentLength; + m_fileInfo.back().header.DataDescriptor.CompressedSize = entry.CompressedSize; + m_fileInfo.back().header.DataDescriptor.UncompressedSize = entry.UncompressedSize; + m_fileInfo.back().header.DataDescriptor.CRC32 = entry.CRC32; + m_files.back().size = entry.UncompressedSize; + return true; +} + +core::smart_refctd_ptr CFileArchiveZip::readFile_impl(const SOpenFileParams& params) +{ + size_t readOffset; + auto found = std::find_if(m_files.begin(), m_files.end(), [¶ms](const SFileListEntry& entry) { return params.filename == entry.fullName; }); + + if (found != m_files.end()) + { + const SZipFileEntry& e = m_fileInfo[found->ID]; + wchar_t buf[64]; + // Nabla supports 0, 8, 12, 14, 99 + //0 - The file is stored (no compression) + //1 - The file is Shrunk + //2 - The file is Reduced with compression factor 1 + //3 - The file is Reduced with compression factor 2 + //4 - The file is Reduced with compression factor 3 + //5 - The file is Reduced with compression factor 4 + //6 - The file is Imploded + //7 - Reserved for Tokenizing compression algorithm + //8 - The file is Deflated + //9 - Reserved for enhanced Deflating + //10 - PKWARE Date Compression Library Imploding + //12 - bzip2 - Compression Method from libbz2, WinZip 10 + //14 - LZMA - Compression Method, WinZip 12 + //96 - Jpeg compression - Compression Method, WinZip 12 + //97 - WavPack - Compression Method, WinZip 11 + //98 - PPMd - Compression Method, WinZip 10 + //99 - AES encryption, WinZip 9 + int16_t actualCompressionMethod = e.header.CompressionMethod; + //TODO: CFileView factory + // CFileViewVirtualAllocatorWin32 + // @sadiuk WTF!? You hand out a new file every time!? + core::smart_refctd_ptr> decrypted = nullptr; + uint8_t* decryptedBuf = 0; + uint32_t decryptedSize = e.header.DataDescriptor.CompressedSize; #ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ - if ((e.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (e.header.CompressionMethod == 99)) + if ((e.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (e.header.CompressionMethod == 99)) + { + uint8_t salt[16] = { 0 }; + const uint16_t saltSize = (((e.header.Sig & 0x00ff0000) >> 16) + 1) * 4; + { + readOffset = e.Offset; + read_blocking(m_file.get(), salt, readOffset, saltSize); + readOffset += saltSize; + } + char pwVerification[2]; + char pwVerificationFile[2]; + { + read_blocking(m_file.get(), pwVerification, readOffset, 2); + readOffset += 2; + } + fcrypt_ctx zctx; // the encryption context + int rc = fcrypt_init( + (e.header.Sig & 0x00ff0000) >> 16, + (const unsigned char*)m_password.c_str(), // the password + m_password.size(), // number of bytes in password + salt, // the salt + (unsigned char*)pwVerificationFile, // on return contains password verifier + &zctx); // encryption context + if (strncmp(pwVerificationFile, pwVerification, 2)) + { + m_logger.log("Wrong password", ILogger::ELL_ERROR); + return 0; + } + decryptedSize = e.header.DataDescriptor.CompressedSize - saltSize - 12; + decryptedBuf = new uint8_t[decryptedSize]; + // + constexpr uint32_t kChunkSize = 0x8000u; + uint32_t c = 0; + while ((c + kChunkSize) <= decryptedSize) { - uint8_t salt[16] = { 0 }; - const uint16_t saltSize = (((e.header.Sig & 0x00ff0000) >> 16) + 1) * 4; - { - readOffset = e.Offset; - read_blocking(m_file.get(), salt, readOffset, saltSize); - readOffset += saltSize; - } - char pwVerification[2]; - char pwVerificationFile[2]; - { - read_blocking(m_file.get(), pwVerification, readOffset, 2); - readOffset += 2; - } - fcrypt_ctx zctx; // the encryption context - int rc = fcrypt_init( - (e.header.Sig & 0x00ff0000) >> 16, - (const unsigned char*)m_password.c_str(), // the password - m_password.size(), // number of bytes in password - salt, // the salt - (unsigned char*)pwVerificationFile, // on return contains password verifier - &zctx); // encryption context - if (strncmp(pwVerificationFile, pwVerification, 2)) - { - m_logger.log("Wrong password", ILogger::ELL_ERROR); - return 0; - } - decryptedSize = e.header.DataDescriptor.CompressedSize - saltSize - 12; - decryptedBuf = new uint8_t[decryptedSize]; - // - constexpr uint32_t kChunkSize = 0x8000u; - uint32_t c = 0; - while ((c + kChunkSize) <= decryptedSize) - { - { - read_blocking(m_file.get(), decryptedBuf + c, readOffset, kChunkSize); - readOffset += kChunkSize; - } - fcrypt_decrypt( - decryptedBuf + c, // pointer to the data to decrypt - kChunkSize, // how many bytes to decrypt - &zctx); // decryption context - c += kChunkSize; - } { - read_blocking(m_file.get(), decryptedBuf + c, readOffset, decryptedSize - c); - readOffset += decryptedSize - c; + read_blocking(m_file.get(), decryptedBuf + c, readOffset, kChunkSize); + readOffset += kChunkSize; } fcrypt_decrypt( decryptedBuf + c, // pointer to the data to decrypt - decryptedSize - c, // how many bytes to decrypt + kChunkSize, // how many bytes to decrypt &zctx); // decryption context + c += kChunkSize; + } + { + read_blocking(m_file.get(), decryptedBuf + c, readOffset, decryptedSize - c); + readOffset += decryptedSize - c; + } + fcrypt_decrypt( + decryptedBuf + c, // pointer to the data to decrypt + decryptedSize - c, // how many bytes to decrypt + &zctx); // decryption context + + char fileMAC[10]; + char resMAC[10]; + rc = fcrypt_end( + (unsigned char*)resMAC, // on return contains the authentication code + &zctx); // encryption context + if (rc != 10) + { + m_logger.log("Error on encryption closing", ILogger::ELL_ERROR); + delete[] decryptedBuf; + return 0; + } + { + read_blocking(m_file.get(), fileMAC, readOffset, 10); + readOffset += 10; + } + if (strncmp(fileMAC, resMAC, 10)) + { + m_logger.log("Error on encryption check", ILogger::ELL_ERROR); + delete[] decryptedBuf; + return 0; + } + decrypted = core::make_smart_refctd_ptr>(core::smart_refctd_ptr(m_system), found->fullName, IFile::ECF_READ_WRITE, decryptedSize); - char fileMAC[10]; - char resMAC[10]; - rc = fcrypt_end( - (unsigned char*)resMAC, // on return contains the authentication code - &zctx); // encryption context - if (rc != 10) - { - m_logger.log("Error on encryption closing", ILogger::ELL_ERROR); - delete[] decryptedBuf; - return 0; - } - { - read_blocking(m_file.get(), fileMAC, readOffset, 10); - readOffset += 10; - } - if (strncmp(fileMAC, resMAC, 10)) - { - m_logger.log("Error on encryption check", ILogger::ELL_ERROR); - delete[] decryptedBuf; - return 0; - } - decrypted = core::make_smart_refctd_ptr>(core::smart_refctd_ptr(m_system), found->fullName, IFile::ECF_READ_WRITE, decryptedSize); - - { - write_blocking(decrypted.get(), decryptedBuf, 0, decryptedSize); - } - actualCompressionMethod = (e.header.Sig & 0xffff); + { + write_blocking(decrypted.get(), decryptedBuf, 0, decryptedSize); + } + actualCompressionMethod = (e.header.Sig & 0xffff); #if 0 - if ((e.header.Sig & 0xff000000) == 0x01000000) - { - } - else if ((e.header.Sig & 0xff000000) == 0x02000000) - { - } - else - { - m_logger.log("Unknown encryption method", ILogger::ELL_ERROR); - return 0; - } -#endif + if ((e.header.Sig & 0xff000000) == 0x01000000) + { } -#endif - switch (actualCompressionMethod) + else if ((e.header.Sig & 0xff000000) == 0x02000000) { - case 0: // no compression + } + else { - delete[] decryptedBuf; - if (decrypted) - return decrypted; - else - { - uint8_t* buff = (uint8_t*)m_file->getMappedPointer() + e.Offset; - auto a = core::make_smart_refctd_ptr>( - core::smart_refctd_ptr(m_system), - params.absolutePath, - IFile::ECF_READ_WRITE, // TODO: should be READONLY - buff, - decryptedSize); - return a; - } + m_logger.log("Unknown encryption method", ILogger::ELL_ERROR); + return 0; } - case 8: +#endif + } +#endif + switch (actualCompressionMethod) + { + case 0: // no compression + { + delete[] decryptedBuf; + if (decrypted) + return decrypted; + else { + uint8_t* buff = (uint8_t*)m_file->getMappedPointer() + e.Offset; + auto a = core::make_smart_refctd_ptr>( + core::smart_refctd_ptr(m_system), + params.absolutePath, + IFile::ECF_READ_WRITE, // TODO: should be READONLY + buff, + decryptedSize); + return a; + } + } + case 8: + { #ifdef _NBL_COMPILE_WITH_ZLIB_ - const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[uncompressedSize]; - if (!pBuf) + const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; + char* pBuf = new char[uncompressedSize]; + if (!pBuf) + { + delete[] decryptedBuf; + // TODO: log error + return 0; + } + + uint8_t* pcData = decryptedBuf; + if (!pcData) + { + pcData = new uint8_t[decryptedSize]; + if (!pcData) { delete[] decryptedBuf; + delete[] pBuf; // TODO: log error return 0; } - uint8_t* pcData = decryptedBuf; - if (!pcData) + //memset(pcData, 0, decryptedSize); + readOffset = e.Offset; { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - delete[] decryptedBuf; - delete[] pBuf; - // TODO: log error - return 0; - } - - //memset(pcData, 0, decryptedSize); - readOffset = e.Offset; - { - read_blocking(m_file.get(), pcData, readOffset, decryptedSize); - readOffset += decryptedSize; - } + read_blocking(m_file.get(), pcData, readOffset, decryptedSize); + readOffset += decryptedSize; } + } - // Setup the inflate stream. - z_stream stream; - int32_t err; + // Setup the inflate stream. + z_stream stream; + int32_t err; - stream.next_in = (Bytef*)pcData; - stream.avail_in = (uInt)decryptedSize; - stream.next_out = (Bytef*)pBuf; - stream.avail_out = uncompressedSize; - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; + stream.next_in = (Bytef*)pcData; + stream.avail_in = (uInt)decryptedSize; + stream.next_out = (Bytef*)pBuf; + stream.avail_out = uncompressedSize; + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; - // Perform inflation. wbits < 0 indicates no zlib header inside the data. - err = inflateInit2(&stream, -MAX_WBITS); - if (err == Z_OK) - { - err = inflate(&stream, Z_FINISH); - inflateEnd(&stream); - if (err == Z_STREAM_END) - err = Z_OK; + // Perform inflation. wbits < 0 indicates no zlib header inside the data. + err = inflateInit2(&stream, -MAX_WBITS); + if (err == Z_OK) + { + err = inflate(&stream, Z_FINISH); + inflateEnd(&stream); + if (err == Z_STREAM_END) err = Z_OK; - inflateEnd(&stream); - } + err = Z_OK; + inflateEnd(&stream); + } - if (!decrypted) - delete[] pcData; + if (!decrypted) + delete[] pcData; - delete[] decryptedBuf; - if (err != Z_OK) - { - delete[] pBuf; - // TODO: log error - return 0; - } - else + delete[] decryptedBuf; + if (err != Z_OK) + { + delete[] pBuf; + // TODO: log error + return 0; + } + else + { + auto ret = core::make_smart_refctd_ptr>( + core::smart_refctd_ptr(m_system), + params.absolutePath, + IFile::ECF_READ_WRITE, // TODO: readonly! + uncompressedSize); { - auto ret = core::make_smart_refctd_ptr>( - core::smart_refctd_ptr(m_system), - params.absolutePath, - IFile::ECF_READ_WRITE, // TODO: readonly! - uncompressedSize); - { - write_blocking(ret.get(), pBuf, 0, uncompressedSize); - } - delete[] pBuf; - return ret; + write_blocking(ret.get(), pBuf, 0, uncompressedSize); } + delete[] pBuf; + return ret; + } #else - return 0; // zlib not compiled, we cannot decompress the data. + return 0; // zlib not compiled, we cannot decompress the data. #endif - } - case 12: - { + } + case 12: + { #ifdef _NBL_COMPILE_WITH_BZIP2_ - const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[uncompressedSize]; - if (!pBuf) + const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; + char* pBuf = new char[uncompressedSize]; + if (!pBuf) + { + m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); + delete[] decryptedBuf; + return 0; + } + + uint8_t* pcData = decryptedBuf; + if (!pcData) + { + pcData = new uint8_t[decryptedSize]; + if (!pcData) { m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); + delete[] pBuf; delete[] decryptedBuf; return 0; } - uint8_t* pcData = decryptedBuf; - if (!pcData) { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] pBuf; - delete[] decryptedBuf; - return 0; - } - - { - readOffset = e.Offset; - read_blocking(m_file.get(), pcData, readOffset, decryptedSize); - readOffset += decryptedSize; - } + readOffset = e.Offset; + read_blocking(m_file.get(), pcData, readOffset, decryptedSize); + readOffset += decryptedSize; } + } - bz_stream bz_ctx = { 0 }; - /* use BZIP2's default memory allocation - bz_ctx->bzalloc = NULL; - bz_ctx->bzfree = NULL; - bz_ctx->opaque = NULL; - */ - int err = BZ2_bzDecompressInit(&bz_ctx, 0, 0); /* decompression */ - if (err != BZ_OK) - { - m_logger.log("bzip2 decompression failed. File cannot be read.", ILogger::ELL_ERROR); - delete[] decryptedBuf; - return 0; - } - bz_ctx.next_in = (char*)pcData; - bz_ctx.avail_in = decryptedSize; - /* pass all input to decompressor */ - bz_ctx.next_out = pBuf; - bz_ctx.avail_out = uncompressedSize; - err = BZ2_bzDecompress(&bz_ctx); - err = BZ2_bzDecompressEnd(&bz_ctx); - - if (!decrypted) - delete[] pcData; - - if (err != BZ_OK) - { - m_logger.log("Error decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] pBuf; - delete[] decryptedBuf; - return 0; - } - else + bz_stream bz_ctx = { 0 }; + /* use BZIP2's default memory allocation + bz_ctx->bzalloc = NULL; + bz_ctx->bzfree = NULL; + bz_ctx->opaque = NULL; + */ + int err = BZ2_bzDecompressInit(&bz_ctx, 0, 0); /* decompression */ + if (err != BZ_OK) + { + m_logger.log("bzip2 decompression failed. File cannot be read.", ILogger::ELL_ERROR); + delete[] decryptedBuf; + return 0; + } + bz_ctx.next_in = (char*)pcData; + bz_ctx.avail_in = decryptedSize; + /* pass all input to decompressor */ + bz_ctx.next_out = pBuf; + bz_ctx.avail_out = uncompressedSize; + err = BZ2_bzDecompress(&bz_ctx); + err = BZ2_bzDecompressEnd(&bz_ctx); + + if (!decrypted) + delete[] pcData; + + if (err != BZ_OK) + { + m_logger.log("Error decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); + delete[] pBuf; + delete[] decryptedBuf; + return 0; + } + else + { + auto ret = core::make_smart_refctd_ptr>(std::move(m_system), found->fullName, IFile::ECF_READ_WRITE, uncompressedSize); // TODO: readonly { - auto ret = core::make_smart_refctd_ptr>(std::move(m_system), found->fullName, IFile::ECF_READ_WRITE, uncompressedSize); // TODO: readonly - { - write_blocking(decrypted.get(), pBuf, 0, uncompressedSize); // huh!? - } - delete[] pBuf; - return ret; + write_blocking(decrypted.get(), pBuf, 0, uncompressedSize); // huh!? } + delete[] pBuf; + return ret; + } #else + delete[] decryptedBuf; + m_logger.log("bzip2 decompression not supported. File cannot be read.", ILogger::ELL_ERROR); + return 0; +#endif + } + case 14: + { +#ifdef _NBL_COMPILE_WITH_LZMA_ + uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; + char* pBuf = new char[uncompressedSize]; + if (!pBuf) + { + m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.c_str()); delete[] decryptedBuf; - m_logger.log("bzip2 decompression not supported. File cannot be read.", ILogger::ELL_ERROR); return 0; -#endif } - case 14: + + uint8_t* pcData = decryptedBuf; + if (!pcData) { -#ifdef _NBL_COMPILE_WITH_LZMA_ - uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[uncompressedSize]; - if (!pBuf) + pcData = new uint8_t[decryptedSize]; + if (!pcData) { - m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.c_str()); - delete[] decryptedBuf; + m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); + delete[] pBuf; return 0; } - uint8_t* pcData = decryptedBuf; - if (!pcData) + //memset(pcData, 0, decryptedSize); + readOffset = e.Offset; { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] pBuf; - return 0; - } - - //memset(pcData, 0, decryptedSize); - readOffset = e.Offset; - { - read_blocking(m_file.get(), pcData, readOffset, decryptedSize); - readOffset += decryptedSize; - } + read_blocking(m_file.get(), pcData, readOffset, decryptedSize); + readOffset += decryptedSize; } + } - ELzmaStatus status; - SizeT tmpDstSize = uncompressedSize; - SizeT tmpSrcSize = decryptedSize; + ELzmaStatus status; + SizeT tmpDstSize = uncompressedSize; + SizeT tmpSrcSize = decryptedSize; - unsigned int propSize = (pcData[3] << 8) + pcData[2]; - int err = LzmaDecode((Byte*)pBuf, &tmpDstSize, - pcData + 4 + propSize, &tmpSrcSize, - pcData + 4, propSize, - e.header.GeneralBitFlag & 0x1 ? LZMA_FINISH_END : LZMA_FINISH_ANY, &status, - &lzmaAlloc); - uncompressedSize = tmpDstSize; // may be different to expected value + unsigned int propSize = (pcData[3] << 8) + pcData[2]; + int err = LzmaDecode((Byte*)pBuf, &tmpDstSize, + pcData + 4 + propSize, &tmpSrcSize, + pcData + 4, propSize, + e.header.GeneralBitFlag & 0x1 ? LZMA_FINISH_END : LZMA_FINISH_ANY, &status, + &lzmaAlloc); + uncompressedSize = tmpDstSize; // may be different to expected value - if (!decrypted) - delete[] pcData; + if (!decrypted) + delete[] pcData; - delete[] decryptedBuf; - if (err != SZ_OK) - { - m_logger.log("Error decompressing %s", ELL_ERROR, params.absolutePath.string().c_str()); - delete[] pBuf; - return 0; - } - else - return io::createMemoryReadFile(pBuf, uncompressedSize, params.absolutePath, true); + delete[] decryptedBuf; + if (err != SZ_OK) + { + m_logger.log("Error decompressing %s", ELL_ERROR, params.absolutePath.string().c_str()); + delete[] pBuf; + return 0; + } + else + return io::createMemoryReadFile(pBuf, uncompressedSize, params.absolutePath, true); #else - delete[] decryptedBuf; - m_logger.log("lzma decompression not supported. File cannot be read.", ILogger::ELL_ERROR); - return 0; + delete[] decryptedBuf; + m_logger.log("lzma decompression not supported. File cannot be read.", ILogger::ELL_ERROR); + return 0; #endif - } - case 99: - // If we come here with an encrypted file, decryption support is missing - m_logger.log("Decryption support not enabled. File cannot be read.", ILogger::ELL_ERROR); - delete[] decryptedBuf; - return 0; - default: - m_logger.log("file has unsupported compression method. %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] decryptedBuf; - return 0; - }; } + case 99: + // If we come here with an encrypted file, decryption support is missing + m_logger.log("Decryption support not enabled. File cannot be read.", ILogger::ELL_ERROR); + delete[] decryptedBuf; + return 0; + default: + m_logger.log("file has unsupported compression method. %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); + delete[] decryptedBuf; + return 0; + }; } } #endif \ No newline at end of file diff --git a/src/nbl/system/CArchiveLoaderZip.h b/src/nbl/system/CArchiveLoaderZip.h new file mode 100644 index 0000000000..5e637c697e --- /dev/null +++ b/src/nbl/system/CArchiveLoaderZip.h @@ -0,0 +1,109 @@ +#ifndef _NBL_SYSTEM_C_ARCHIVE_LOADER_ZIP_H_INCLUDED_ +#define _NBL_SYSTEM_C_ARCHIVE_LOADER_ZIP_H_INCLUDED_ + + +#include "nbl/system/CFileArchive.h" + + +namespace nbl::system +{ + +#if 0 + CFileArchiveZip(core::smart_refctd_ptr&& file, core::smart_refctd_ptr&& system, bool isGZip, const std::string_view& password, system::logger_opt_smart_ptr&& logger = nullptr) : + IFileArchive(std::move(file), std::move(system), std::move(logger)), m_isGZip(isGZip), m_password(password) + { + size_t offset = 0; + if (m_file.get()) + { + // load file entries + if (m_isGZip) + while (scanGZipHeader(offset)) {} + else + while (scanZipHeader(offset)) {} + + setFlagsVectorSize(m_files.size()); + } + } + + bool scanGZipHeader(size_t& offset); + bool scanZipHeader(size_t& offset, bool ignoreGPBits = false); + bool scanCentralDirectoryHeader(size_t& offset); + E_ALLOCATOR_TYPE getAllocatorType(uint32_t compressionType) + { + switch (compressionType) + { + case 0: return EAT_NULL; + default: return EAT_VIRTUAL_ALLOC; + } + } +#endif + +class CArchiveLoaderZip final : public IArchiveLoader +{ + public: + struct SZIPFileDataDescriptor + { + uint32_t CRC32; + uint32_t CompressedSize; + uint32_t UncompressedSize; + }; + #include "nbl/nblpack.h" + struct SZIPFileHeader + { + uint32_t Sig; // 'PK0304' little endian (0x04034b50) + int16_t VersionToExtract; + int16_t GeneralBitFlag; + int16_t CompressionMethod; + int16_t LastModFileTime; + int16_t LastModFileDate; + SZIPFileDataDescriptor DataDescriptor; + int16_t FilenameLength; + int16_t ExtraFieldLength; + // filename (variable size) + // extra field (variable size ) + } PACK_STRUCT; + #include "nbl/nblunpack.h" + class CArchive : public CFileArchive + { + public: + private: + //! Contains extended info about zip files in the archive + struct SZipFileEntry + { + //! Position of data in the archive file + int32_t Offset; + //! The header for this file containing compression info etc + SZIPFileHeader header; + }; + + const bool m_isGZip; + core::vector m_fileInfo; + const std::string m_password; // TODO password + }; + + CArchiveLoaderZip(system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(logger)) {} + + inline bool isALoadableFileFormat(IFile* file) const override + { + SZIPFileHeader header; + + IFile::success_t succ; + file->read(succ,&header,0,sizeof(header)); + + return bool(succ) || + (header.Sig == 0x04034b50) || // ZIP + (header.Sig & 0xffff) == 0x8b1f; // gzip + } + + inline const char** getAssociatedFileExtensions() const override + { + static const char* ext[]{ "zip", "pk3", "tgz", "gz", nullptr}; + return ext; + } + + private: + core::smart_refctd_ptr createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const override; +}; + +} +#endif \ No newline at end of file diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index ca32e8f9ff..2ef8d4375c 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -2,8 +2,8 @@ #include "nbl/system/ISystemFile.h" #include "nbl/system/CFileView.h" -//#include "nbl/system/CArchiveLoaderZip.h" -//#include "nbl/system/CArchiveLoaderTar.h" +#include "nbl/system/CArchiveLoaderZip.h" +#include "nbl/system/CArchiveLoaderTar.h" using namespace nbl; @@ -12,8 +12,8 @@ using namespace nbl::system; ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatcher(std::move(caller)) { - //addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); - //addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); + addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); + addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); } core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const From 38b8a81c2c02fb3d64dbf60fc394fff34a1db78b Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 18:27:33 +0100 Subject: [PATCH 53/91] fix a few compiler warnings --- include/nbl/system/CColoredStdoutLoggerWin32.h | 5 +++-- src/nbl/asset/interchange/CGLTFLoader.h | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/nbl/system/CColoredStdoutLoggerWin32.h b/include/nbl/system/CColoredStdoutLoggerWin32.h index e255425bd7..5bd2fe41a6 100644 --- a/include/nbl/system/CColoredStdoutLoggerWin32.h +++ b/include/nbl/system/CColoredStdoutLoggerWin32.h @@ -54,10 +54,11 @@ class CColoredStdoutLoggerWin32 : public IThreadsafeLogger } case ELL_NONE: { - assert(false); // how did this happen?? Btw, do we even need this log level? - return 0; + assert(false); // how did this happen?? Btw, do we even need this log level? + break; } } + return 0; } }; diff --git a/src/nbl/asset/interchange/CGLTFLoader.h b/src/nbl/asset/interchange/CGLTFLoader.h index 07d3015b02..50cd25ddd0 100644 --- a/src/nbl/asset/interchange/CGLTFLoader.h +++ b/src/nbl/asset/interchange/CGLTFLoader.h @@ -383,8 +383,7 @@ class CGLTFLoader final : public IRenderpassIndependentPipelineLoader if (!count.has_value()) return false; - else - if (count.has_value() < 1) + else if (count.value() < 1) return false; if (!type.has_value()) From 300078b5bb306b0b22c4dd3b544b5e8290d7d243 Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 18:30:37 +0100 Subject: [PATCH 54/91] fixes for const correctness, Example 2 works --- examples_tests/common/CommonAPI.h | 6 +----- include/nbl/system/IFile.h | 3 ++- include/nbl/system/ISystem.h | 4 ++-- src/nbl/asset/IAssetManager.cpp | 2 +- src/nbl/asset/interchange/CGLTFLoader.cpp | 2 +- src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp | 2 +- src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h | 2 +- src/nbl/system/ISystem.cpp | 4 ++-- src/nbl/video/utilities/CScanner.cpp | 2 +- 9 files changed, 12 insertions(+), 15 deletions(-) diff --git a/examples_tests/common/CommonAPI.h b/examples_tests/common/CommonAPI.h index 39915ea7f5..0c15546d30 100644 --- a/examples_tests/common/CommonAPI.h +++ b/examples_tests/common/CommonAPI.h @@ -388,12 +388,8 @@ class CommonAPI { using namespace nbl; using namespace system; - nbl::core::smart_refctd_ptr caller = nullptr; #ifdef _NBL_PLATFORM_WINDOWS_ - caller = nbl::core::make_smart_refctd_ptr(); -#endif -#ifdef _NBL_PLATFORM_WINDOWS_ - return nbl::core::make_smart_refctd_ptr(std::move(caller)); + return nbl::core::make_smart_refctd_ptr(); #elif defined(_NBL_PLATFORM_ANDROID_) #if 0 return nbl::core::make_smart_refctd_ptr(std::move(caller)); diff --git a/include/nbl/system/IFile.h b/include/nbl/system/IFile.h index 90a4923995..6f4c9ea9fe 100644 --- a/include/nbl/system/IFile.h +++ b/include/nbl/system/IFile.h @@ -12,7 +12,8 @@ class IFile : public IFileBase, private ISystem::IFutureManipulator // inline void read(ISystem::future_t& fut, void* buffer, size_t offset, size_t sizeToRead) { - const auto* ptr = reinterpret_cast(getMappedPointer()); + const IFileBase* constThis = this; + const auto* ptr = reinterpret_cast(constThis->getMappedPointer()); if (ptr) { const size_t size = getSize(); diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index 66eee88e0c..98278babd7 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -113,7 +113,7 @@ class ISystem : public core::IReferenceCounted //! Compile time resource ID template - inline core::smart_refctd_ptr loadBuiltinData() const + inline core::smart_refctd_ptr loadBuiltinData() const { #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ return impl_loadEmbeddedBuiltinData(StringUniqueType::value,nbl::builtin::get_resource()); @@ -260,7 +260,7 @@ class ISystem : public core::IReferenceCounted virtual ~ISystem() {} // - core::smart_refctd_ptr impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const; + core::smart_refctd_ptr impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const; // given an `absolutePath` find the archive it belongs to struct FoundArchiveFile diff --git a/src/nbl/asset/IAssetManager.cpp b/src/nbl/asset/IAssetManager.cpp index ddc549cbbb..b995f92883 100644 --- a/src/nbl/asset/IAssetManager.cpp +++ b/src/nbl/asset/IAssetManager.cpp @@ -220,7 +220,7 @@ void IAssetManager::insertBuiltinAssets() // materials { // - auto buildInGLSLShader = [&]( core::smart_refctd_ptr&& data, + auto buildInGLSLShader = [&]( core::smart_refctd_ptr&& data, asset::IShader::E_SHADER_STAGE type, std::initializer_list paths) -> void { diff --git a/src/nbl/asset/interchange/CGLTFLoader.cpp b/src/nbl/asset/interchange/CGLTFLoader.cpp index 887eb9e40f..f32fe76eb0 100644 --- a/src/nbl/asset/interchange/CGLTFLoader.cpp +++ b/src/nbl/asset/interchange/CGLTFLoader.cpp @@ -45,7 +45,7 @@ using namespace nbl::asset; { auto registerShader = [&](auto constexprStringType, IShader::E_SHADER_STAGE stage, const char* extraDefine=nullptr) -> void { - auto glslFile = assetManager->getSystem()->loadBuiltinData(); + core::smart_refctd_ptr glslFile = assetManager->getSystem()->loadBuiltinData(); auto glsl = core::make_smart_refctd_ptr(glslFile->getSize()); memcpy(glsl->getPointer(),glslFile->getMappedPointer(),glsl->getSize()); diff --git a/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp b/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp index 2b07ac70d3..5a504dd834 100644 --- a/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp +++ b/src/nbl/asset/interchange/CGraphicsPipelineLoaderMTL.cpp @@ -31,7 +31,7 @@ CGraphicsPipelineLoaderMTL::CGraphicsPipelineLoaderMTL(IAssetManager* _am, core: //create vertex shaders and insert them into cache auto registerShader = [&](auto constexprStringType, ICPUShader::E_SHADER_STAGE stage) -> void { - auto data = m_assetMgr->getSystem()->loadBuiltinData(); + core::smart_refctd_ptr data = m_assetMgr->getSystem()->loadBuiltinData(); auto buffer = core::make_smart_refctd_ptr(data->getSize()); memcpy(buffer->getPointer(), data->getMappedPointer(), data->getSize()); auto unspecializedShader = core::make_smart_refctd_ptr( diff --git a/src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h b/src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h index ef250e15cc..e976fd5697 100644 --- a/src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h +++ b/src/nbl/asset/utils/IGLSLEmbeddedIncludeLoader.h @@ -53,7 +53,7 @@ class IGLSLEmbeddedIncludeLoader : public IBuiltinIncludeLoader system::ISystem::future_t> future; auto path = "nbl/builtin/" + _name; s->createFile(future,path,core::bitflag(system::IFileBase::ECF_READ)|system::IFileBase::ECF_MAPPABLE); - auto data = future.get(); + core::smart_refctd_ptr data = future.get(); if (!data) return ""; auto begin = reinterpret_cast(data->getMappedPointer()); diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index 2ef8d4375c..593e742677 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -16,7 +16,7 @@ ISystem::ISystem(core::smart_refctd_ptr&& caller) : m_dispatch addArchiveLoader(core::make_smart_refctd_ptr(nullptr)); } -core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const +core::smart_refctd_ptr ISystem::impl_loadEmbeddedBuiltinData(const std::string& builtinPath, const std::pair& found) const { #ifdef _NBL_EMBED_BUILTIN_RESOURCES_ if (found.first && found.second) @@ -215,7 +215,7 @@ void ISystem::createFile(future_t>& future, std::f auto file = impl_loadEmbeddedBuiltinData(filename.string(),nbl::builtin::get_resource_runtime(filename.string())); if (file) { - future.notify(std::move(file)); + future.notify(core::smart_refctd_ptr(const_cast(file.get()))); return; } #else diff --git a/src/nbl/video/utilities/CScanner.cpp b/src/nbl/video/utilities/CScanner.cpp index 078b89fc34..a682cc6922 100644 --- a/src/nbl/video/utilities/CScanner.cpp +++ b/src/nbl/video/utilities/CScanner.cpp @@ -6,7 +6,7 @@ using namespace video; core::smart_refctd_ptr CScanner::createShader(const bool indirect, const E_SCAN_TYPE scanType, const E_DATA_TYPE dataType, const E_OPERATOR op) const { auto system = m_device->getPhysicalDevice()->getSystem(); - core::smart_refctd_ptr glsl; + core::smart_refctd_ptr glsl; { if(indirect) glsl = system->loadBuiltinData(); From 98c701af7623af277456324eca43d862ccd976cf Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 21:12:38 +0100 Subject: [PATCH 55/91] Fixed Example 5 even under Vulkan! (still gives validation error about fences) Plus a small vulkan fix. --- .../05.NablaTutorialExample/main.cpp | 35 ++++++++++++++----- include/nbl/asset/IImageView.h | 1 + src/nbl/video/CVulkanLogicalDevice.h | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/examples_tests/05.NablaTutorialExample/main.cpp b/examples_tests/05.NablaTutorialExample/main.cpp index e742fa30db..50d20fb567 100644 --- a/examples_tests/05.NablaTutorialExample/main.cpp +++ b/examples_tests/05.NablaTutorialExample/main.cpp @@ -167,7 +167,7 @@ class NablaTutorialExampleApp : public ApplicationBase const auto swapchainImageUsage = static_cast(asset::IImage::EUF_COLOR_ATTACHMENT_BIT); const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN); - CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "NablaTutorialExample", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); + CommonAPI::InitWithDefaultExt(initOutput, video::EAT_VULKAN, "NablaTutorialExample", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); window = std::move(initOutput.window); windowCb = std::move(initOutput.windowCb); apiConnection = std::move(initOutput.apiConnection); @@ -202,13 +202,19 @@ class NablaTutorialExampleApp : public ApplicationBase Loading an asset bundle. You can specify some flags and parameters to have an impact on extraordinary tasks while loading for example. - */ + */ asset::IAssetLoader::SAssetLoadParams loadingParams; auto images_bundle = assetManager->getAsset("../../media/color_space_test/R8G8B8A8_1.png", loadingParams); assert(!images_bundle.getContents().empty()); auto image = images_bundle.getContents().begin()[0]; + + /* + By default an image that comes out of an image loader will only have the TRANSFER_DST usage flag. + We need to add more usages, as only we know what we'll do with the image farther along in the pipeline. + */ auto image_raw = static_cast(image.get()); + image_raw->addImageUsageFlags(asset::IImage::EUF_SAMPLED_BIT); /* Specifing gpu image view parameters to create a gpu @@ -220,7 +226,16 @@ class NablaTutorialExampleApp : public ApplicationBase cpu2gpuParams.waitForCreationToComplete(); auto& gpuParams = gpuImage->getCreationParameters(); - IImageView::SCreationParams gpuImageViewParams = { static_cast(0), gpuImage, IImageView::ET_2D, gpuParams.format, {}, {static_cast(0u), 0, gpuParams.mipLevels, 0, gpuParams.arrayLayers} }; + IImageView::SCreationParams gpuImageViewParams = { + IGPUImageView::ECF_NONE, + gpuImage, + IImageView::ET_2D, + gpuParams.format, + {}, + { + IImage::EAF_COLOR_BIT, 0, gpuParams.mipLevels, 0, gpuParams.arrayLayers + } + }; auto gpuImageView = logicalDevice->createGPUImageView(std::move(gpuImageViewParams)); /* @@ -279,15 +294,18 @@ class NablaTutorialExampleApp : public ApplicationBase We know ahead of time that `SBasicViewParameters` struct is the expected structure of the only UBO block in the descriptor set nr. 1 of the shader. */ - IGPUBuffer::SCreationParams creationParams; + IGPUBuffer::SCreationParams creationParams = {}; creationParams.canUpdateSubRange = true; creationParams.usage = asset::IBuffer::EUF_UNIFORM_BUFFER_BIT; - creationParams.sharingMode = asset::E_SHARING_MODE::ESM_CONCURRENT; - creationParams.queueFamilyIndexCount = 0u; - creationParams.queueFamilyIndices = nullptr; IDriverMemoryBacked::SDriverMemoryRequirements memReq; memReq.vulkanReqs.size = sizeof(SBasicViewParameters); - gpuubo = logicalDevice->createGPUBufferOnDedMem(creationParams, memReq); + memReq.vulkanReqs.alignment = physicalDevice->getLimits().UBOAlignment; + memReq.vulkanReqs.memoryTypeBits = 0xffffffffu; + memReq.memoryHeapLocation = IDriverMemoryAllocation::ESMT_DEVICE_LOCAL; + memReq.mappingCapability = IDriverMemoryAllocation::EMAF_NONE; + memReq.prefersDedicatedAllocation = true; + memReq.requiresDedicatedAllocation = true; + gpuubo = logicalDevice->createGPUBufferOnDedMem(creationParams,memReq); /* Creating descriptor sets - texture (sampler) and basic view parameters (UBO). @@ -380,6 +398,7 @@ class NablaTutorialExampleApp : public ApplicationBase if (cpuindexbuffer) cpubuffers.push_back(cpuindexbuffer); + cpu2gpuParams.beginCommandBuffers(); auto gpubuffers = cpu2gpu.getGPUObjectsFromAssets(cpubuffers.data(), cpubuffers.data() + cpubuffers.size(), cpu2gpuParams); cpu2gpuParams.waitForCreationToComplete(); diff --git a/include/nbl/asset/IImageView.h b/include/nbl/asset/IImageView.h index 6cff08d7be..f76c1cb8cd 100644 --- a/include/nbl/asset/IImageView.h +++ b/include/nbl/asset/IImageView.h @@ -22,6 +22,7 @@ class IImageView : public IDescriptor // no flags for now, yet enum E_CREATE_FLAGS { + ECF_NONE = 0 }; enum E_TYPE { diff --git a/src/nbl/video/CVulkanLogicalDevice.h b/src/nbl/video/CVulkanLogicalDevice.h index 2b795d5f26..a7634e64ca 100644 --- a/src/nbl/video/CVulkanLogicalDevice.h +++ b/src/nbl/video/CVulkanLogicalDevice.h @@ -1276,7 +1276,7 @@ class CVulkanLogicalDevice final : public ILogicalDevice vkDescSetLayoutBinding.stageFlags = static_cast(binding->stageFlags); vkDescSetLayoutBinding.pImmutableSamplers = nullptr; - if (binding->samplers && binding->count > 0u) + if (binding->type==asset::ESRT_SAMPLED_IMAGE && binding->samplers && binding->count > 0u) { // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount is not 0 and pImmutableSamplers is not NULL: // pImmutableSamplers must be a valid pointer to an array of descriptorCount valid VkSampler handles. From cadcee5b2b5e72805246ef973bba32d24331e70b Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 21:23:35 +0100 Subject: [PATCH 56/91] shoot down more errors and warnings about return types --- include/nbl/asset/ICPUShader.h | 2 ++ include/nbl/asset/utils/CDirQuantCacheBase.h | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/nbl/asset/ICPUShader.h b/include/nbl/asset/ICPUShader.h index e53d8f1eca..07403462b1 100644 --- a/include/nbl/asset/ICPUShader.h +++ b/include/nbl/asset/ICPUShader.h @@ -95,6 +95,7 @@ class ICPUShader : public IAsset, public IShader if(isImmutable_debug()) return m_shaderStage == stage; m_shaderStage = stage; + return true; } bool setFilePathHint(std::string&& filepathHint) @@ -102,6 +103,7 @@ class ICPUShader : public IAsset, public IShader if(isImmutable_debug()) return false; m_filepathHint = std::move(filepathHint); + return true; } bool canBeRestoredFrom(const IAsset* _other) const override diff --git a/include/nbl/asset/utils/CDirQuantCacheBase.h b/include/nbl/asset/utils/CDirQuantCacheBase.h index c0752f996d..25a7078af9 100644 --- a/include/nbl/asset/utils/CDirQuantCacheBase.h +++ b/include/nbl/asset/utils/CDirQuantCacheBase.h @@ -340,7 +340,7 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase //! template - inline system::IFile::success_t saveCacheToFile(system::IFile* file) + inline bool saveCacheToFile(system::IFile* file) { if (!file) return false; @@ -354,12 +354,12 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase system::IFile::success_t succ; file->write(succ,bufferRange.buffer->getPointer(), 0, bufferRange.buffer->getSize()); - return succ; + return bool(succ); } //! template - inline system::IFile::success_t saveCacheToFile(nbl::system::ISystem* system, const system::path& path) + inline bool saveCacheToFile(nbl::system::ISystem* system, const system::path& path) { system::ISystem::future_t> future; system->createFile(future, path, nbl::system::IFile::ECF_WRITE); @@ -367,7 +367,7 @@ class CDirQuantCacheBase : public impl::CDirQuantCacheBase if (!file) return false; - return saveCacheToFile(file.get()); + return bool(saveCacheToFile(file.get())); } //! From a6667178ea25dd23d54b3358cf592856458fd0fa Mon Sep 17 00:00:00 2001 From: devsh Date: Mon, 7 Mar 2022 21:42:33 +0100 Subject: [PATCH 57/91] tick off implemented stuff --- source/Nabla/CIrrDeviceLinux.h | 10 - source/Nabla/CIrrDeviceWin32.h | 4 - source/Nabla/CMeshSceneNodeInstanced.cpp | 579 ----------------------- source/Nabla/CMeshSceneNodeInstanced.h | 179 ------- source/Nabla/CSceneManager.cpp | 21 - source/Nabla/CSceneManager.h | 32 -- 6 files changed, 825 deletions(-) delete mode 100644 source/Nabla/CMeshSceneNodeInstanced.cpp delete mode 100644 source/Nabla/CMeshSceneNodeInstanced.h diff --git a/source/Nabla/CIrrDeviceLinux.h b/source/Nabla/CIrrDeviceLinux.h index 2a8962a87e..e8bbfa271a 100644 --- a/source/Nabla/CIrrDeviceLinux.h +++ b/source/Nabla/CIrrDeviceLinux.h @@ -49,9 +49,6 @@ namespace nbl //! runs the device. Returns false if device wants to be deleted virtual bool run(); - //! Cause the device to temporarily pause execution and let other processes to run - // This should bring down processor usage without major performance loss for Irrlicht - virtual void yield(); //! Pause execution and let other processes to run for a specified amount of time. virtual void sleep(uint32_t timeMs, bool pauseTimer); @@ -100,13 +97,6 @@ namespace nbl //! Remove all messages pending in the system message loop virtual void clearSystemMessages(); - //! Get the device type - virtual E_DEVICE_TYPE getType() const - { - return EIDT_X11; - } - - private: bool createWindow(); diff --git a/source/Nabla/CIrrDeviceWin32.h b/source/Nabla/CIrrDeviceWin32.h index 54b4072477..07a787aa30 100644 --- a/source/Nabla/CIrrDeviceWin32.h +++ b/source/Nabla/CIrrDeviceWin32.h @@ -25,10 +25,6 @@ namespace nbl //! runs the device. Returns false if device wants to be deleted virtual bool run(); - //! Cause the device to temporarily pause execution and let other processes to run - // This should bring down processor usage without major performance loss for Irrlicht - virtual void yield(); - //! Pause execution and let other processes to run for a specified amount of time. virtual void sleep(uint32_t timeMs, bool pauseTimer); diff --git a/source/Nabla/CMeshSceneNodeInstanced.cpp b/source/Nabla/CMeshSceneNodeInstanced.cpp deleted file mode 100644 index 0fdfaa61bf..0000000000 --- a/source/Nabla/CMeshSceneNodeInstanced.cpp +++ /dev/null @@ -1,579 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#include "CMeshSceneNodeInstanced.h" -#include "IVideoDriver.h" -#include "COpenGLDriver.h" -#include "ISceneManager.h" -#include "ICameraSceneNode.h" -#include "IMaterialRenderer.h" -#include "nbl_os.h" -#include "nbl/video/CGPUMesh.h" - -#include "nbl/static_if.h" - -namespace nbl -{ -namespace scene -{ - - -uint32_t CMeshSceneNodeInstanced::recullOrder; - -//!constructor -CMeshSceneNodeInstanced::CMeshSceneNodeInstanced(IDummyTransformationSceneNode* parent, ISceneManager* mgr, int32_t id, - const core::vector3df& position, const core::vector3df& rotation, const core::vector3df& scale) - : IMeshSceneNodeInstanced(parent, mgr, id, position, rotation, scale), - instanceBBoxes(nullptr), instanceBBoxesCount(0), flagQueryForRetrieval(false), - gpuCulledLodInstanceDataBuffer(), dataPerInstanceOutputSize(0), - extraDataInstanceSize(0), dataPerInstanceInputSize(0) -{ - #ifdef _NBL_DEBUG - setDebugName("CMeshSceneNodeInstanced"); - #endif - - - renderPriority = 0x80000000u; - - lodCullingPointMesh = core::make_smart_refctd_ptr(); - lodCullingPointMesh->setPrimitiveType(asset::EPT_POINTS); -} - -//! destructor -CMeshSceneNodeInstanced::~CMeshSceneNodeInstanced() -{ - if (instanceBBoxes) - _NBL_ALIGNED_FREE(instanceBBoxes); -} - - -//! Sets a new meshbuffer -bool CMeshSceneNodeInstanced::setLoDMeshes(const core::vector& levelsOfDetail, const size_t& dataSizePerInstanceOutput, const video::SGPUMaterial& lodSelectionShader, VaoSetupOverrideFunc vaoSetupOverride, const size_t shaderLoDsPerPass, void* overrideUserData, const size_t& extraDataSizePerInstanceInput) -{ - LoD.clear(); - xfb.clear(); - - if (instanceBBoxes) - _NBL_ALIGNED_FREE(instanceBBoxes); - instanceDataAllocator = nullptr; - instanceBBoxes = nullptr; - gpuCulledLodInstanceDataBuffer = nullptr; - extraDataInstanceSize = 0; - - lodCullingPointMesh->setMeshDataAndFormat(nullptr); - lodCullingPointMesh->setIndexCount(0); - - if (levelsOfDetail.size()==0||!vaoSetupOverride) - return false; - - if (!levelsOfDetail[0].mesh||levelsOfDetail[0].lodDistance<=0.f) - return false; - - for (size_t j=1; jvideo::COpenGLExtensionHandler::MaxVertexStreams) - return false; -#endif // _NBL_COMPILE_WITH_OPENGL_ - gpuLoDsPerPass = shaderLoDsPerPass; - - extraDataInstanceSize = extraDataSizePerInstanceInput; - auto visibilityPadding = 4u-(extraDataInstanceSize&0x3u); - - video::IVideoDriver* driver = SceneManager->getVideoDriver(); - - dataPerInstanceInputSize = extraDataInstanceSize+visibilityPadding+48+36; - auto buffSize = dataPerInstanceInputSize*512u; - instanceDataAllocator = core::make_smart_refctd_ptr(driver,core::allocator(),0u,0u,core::roundDownToPoT(dataPerInstanceInputSize),buffSize,dataPerInstanceInputSize,nullptr); - instanceBBoxesCount = getCurrentInstanceCapacity(); - instanceBBoxes = (core::aabbox3df*)_NBL_ALIGNED_MALLOC(instanceBBoxesCount*sizeof(core::aabbox3df),_NBL_SIMD_ALIGNMENT); - for (size_t i=0; i(SceneManager->getVideoDriver()->createDeviceLocalGPUBufferOnDedMem(dataSizePerInstanceOutput*instanceBBoxesCount*gpuLoDsPerPass*xfb.size()),core::dont_grab); // TODO: fix - - - dataPerInstanceOutputSize = dataSizePerInstanceOutput; - { - auto buff = core::smart_refctd_ptr(instanceDataAllocator->getFrontBuffer()); - - auto vao = SceneManager->getVideoDriver()->createGPUMeshDataFormatDesc(); - - uint32_t floatComponents = extraDataInstanceSize+1; - floatComponents /= 4; - floatComponents += 12+9; - if (floatComponents>asset::EVAI_COUNT*4) - { - for (uint32_t i=0; isetVertexAttrBuffer(core::smart_refctd_ptr(buff),(asset::E_VERTEX_ATTRIBUTE_ID)i,asset::EF_R32G32B32A32_SFLOAT,dataPerInstanceInputSize,i*16); - } - else - { - size_t memoryUsed = 0; - uint32_t attr = 0; - for (; attr*4+3setVertexAttrBuffer(core::smart_refctd_ptr(buff),(asset::E_VERTEX_ATTRIBUTE_ID)attr,asset::EF_R32G32B32A32_SFLOAT,dataPerInstanceInputSize,attr*16); // we should really use uints for these - memoryUsed+=16; - } - memoryUsed -= (12+9)*4; - - size_t leftOverMemory = extraDataInstanceSize+1-memoryUsed; - - auto convertFunc = [](size_t x) { // rename this? What's this for actually? - switch (x) - { - case 1ull: return asset::EF_R32_UINT; - case 2ull: return asset::EF_R32G32_UINT; - case 3ull: return asset::EF_R32G32B32_UINT; - default: return asset::EF_R32G32B32A32_UINT; - } - }; - - //assume a padding of 4 at the end - vao->setVertexAttrBuffer(core::smart_refctd_ptr(buff),(asset::E_VERTEX_ATTRIBUTE_ID)attr,convertFunc(((leftOverMemory+3)/4)),dataPerInstanceInputSize,attr*16); - } - lodCullingPointMesh->setMeshDataAndFormat(std::move(vao)); - } - - - for (size_t i=0; i(); - for (size_t j=0; jgetMeshBufferCount(); j++) - { - video::IGPUMeshBuffer* origBuff = levelsOfDetail[i].mesh->getMeshBuffer(j); - - auto meshBuff = core::make_smart_refctd_ptr(); - meshBuff->setBaseVertex(origBuff->getBaseVertex()); - meshBuff->setIndexCount(origBuff->getIndexCount()); - meshBuff->setIndexBufferOffset(origBuff->getIndexBufferOffset()); - meshBuff->setIndexType(origBuff->getIndexType()); - meshBuff->setPrimitiveType(origBuff->getPrimitiveType()); - - { - auto vao = vaoSetupOverride(SceneManager,gpuCulledLodInstanceDataBuffer.get(),dataSizePerInstanceOutput,origBuff->getMeshDataAndFormat(),overrideUserData); - meshBuff->setMeshDataAndFormat(std::move(vao)); - } - - meshBuff->getMaterial() = origBuff->getMaterial(); - meshBuff->setBoundingBox(origBuff->getBoundingBox()); - tmp.mesh->addMeshBuffer(std::move(meshBuff)); - } - tmp.mesh->setBoundingBox(levelsOfDetail[i].mesh->getBoundingBox()); - if (i) - LoDInvariantBox.addInternalBox(levelsOfDetail[i].mesh->getBoundingBox()); - else - LoDInvariantBox = levelsOfDetail[i].mesh->getBoundingBox(); - - tmp.query = core::smart_refctd_ptr(SceneManager->getVideoDriver()->createXFormFeedbackPrimitiveQuery(),core::dont_grab); - LoD.push_back(std::move(tmp)); - } - - for (size_t i=0; i(SceneManager->getVideoDriver()->createTransformFeedback(),core::dont_grab); - - for (size_t j=0; jbindOutputBuffer(j,gpuCulledLodInstanceDataBuffer.get(),(i*gpuLoDsPerPass+j)*dataSizePerInstanceOutput*instanceBBoxesCount,dataSizePerInstanceOutput*instanceBBoxesCount); - } - - lodCullingPointMesh->getMaterial() = lodSelectionShader; - - return true; -} - -uint32_t CMeshSceneNodeInstanced::addInstance(const core::matrix3x4SIMD& relativeTransform, const void* extraData) -{ - uint32_t ix; - if (!addInstances(&ix,1,&relativeTransform,extraData)) - return kInvalidInstanceID; - - return ix; -} - -bool CMeshSceneNodeInstanced::addInstances(uint32_t* instanceIDs, const size_t& instanceCount, const core::matrix3x4SIMD* relativeTransforms, const void* extraData) -{ - {//dummyBytes, aligns scope - core::vector dummyBytes_(instanceCount); - core::vector aligns_(instanceCount); - uint32_t* const dummyBytes = dummyBytes_.data(); - uint32_t* const aligns = aligns_.data(); - for (size_t i=0; imulti_alloc_addr(instanceCount,instanceIDs,static_cast(dummyBytes),static_cast(aligns)); - bool success = true; - for (size_t i=0; imulti_free_addr(1u,instanceIDs+i,dummyBytes+i); - instanceIDs[i] = kInvalidInstanceID; - } - return false; - } - }// end of arbitrary scope - - if (getCurrentInstanceCapacity()!=instanceBBoxesCount) - { - size_t newCount = getCurrentInstanceCapacity(); - // kind-of realloc - { - size_t newSize = newCount*sizeof(core::aabbox3df); - void* newPtr = _NBL_ALIGNED_MALLOC(newSize,_NBL_SIMD_ALIGNMENT); - memcpy(newPtr,instanceBBoxes,std::min(instanceBBoxesCount*sizeof(core::aabbox3df),newSize)); - _NBL_ALIGNED_FREE(instanceBBoxes); - instanceBBoxes = (core::aabbox3df*)newPtr; - } - for (size_t i=instanceBBoxesCount; i(instanceDataAllocator->getBackBufferPointer()); - for (size_t i=0; igetAddressAllocator().get_real_addr(instanceIDs[i]); - instanceDataAllocator->markRangeForPush(redirect,redirect+dataPerInstanceInputSize); - uint8_t* ptr = base_pointer+redirect; - memcpy(ptr,relativeTransforms+i,48); - - core::matrix3x4SIMD instanceInverse; - relativeTransforms[i].getInverse(instanceInverse); - float* instance3x3TranposeInverse = reinterpret_cast(ptr+48); - instance3x3TranposeInverse[0] = instanceInverse(0,0); - instance3x3TranposeInverse[1] = instanceInverse(0,1); - instance3x3TranposeInverse[2] = instanceInverse(0,2); - instance3x3TranposeInverse[3] = instanceInverse(1,0); - instance3x3TranposeInverse[4] = instanceInverse(1,1); - instance3x3TranposeInverse[5] = instanceInverse(1,2); - instance3x3TranposeInverse[6] = instanceInverse(2,0); - instance3x3TranposeInverse[7] = instanceInverse(2,1); - instance3x3TranposeInverse[8] = instanceInverse(2,2); - if (extraData&&extraDataInstanceSize) - memcpy(ptr+48+36,reinterpret_cast(extraData)+extraDataInstanceSize*i,extraDataInstanceSize); - ptr[48+36+extraDataInstanceSize] = 0xffu; - } - - lodCullingPointMesh->setIndexCount(lodCullingPointMesh->getIndexCount()+instanceCount); - - return true; -} - -void CMeshSceneNodeInstanced::setInstanceTransform(const uint32_t& instanceID, const core::matrix3x4SIMD& relativeTransform) -{ - { - uint32_t blockID = getBlockIDFromAddr(instanceID); - instanceBBoxes[blockID] = core::transformBoxEx(LoDInvariantBox,relativeTransform); - } - - size_t redirect = instanceDataAllocator->getAddressAllocator().get_real_addr(instanceID); - instanceDataAllocator->markRangeForPush(redirect,redirect+48+36); - uint8_t* ptr = reinterpret_cast(instanceDataAllocator->getBackBufferPointer())+redirect; - memcpy(ptr,relativeTransform.rows[0].pointer,48); - - core::matrix3x4SIMD instanceInverse; - relativeTransform.getInverse(instanceInverse); - float* instance3x3TranposeInverse = reinterpret_cast(ptr+48); - instance3x3TranposeInverse[0] = instanceInverse(0,0); - instance3x3TranposeInverse[1] = instanceInverse(0,1); - instance3x3TranposeInverse[2] = instanceInverse(0,2); - instance3x3TranposeInverse[3] = instanceInverse(1,0); - instance3x3TranposeInverse[4] = instanceInverse(1,1); - instance3x3TranposeInverse[5] = instanceInverse(1,2); - instance3x3TranposeInverse[6] = instanceInverse(2,0); - instance3x3TranposeInverse[7] = instanceInverse(2,1); - instance3x3TranposeInverse[8] = instanceInverse(2,2); - - needsBBoxRecompute = true; -} - -core::matrix3x4SIMD CMeshSceneNodeInstanced::getInstanceTransform(const uint32_t& instanceID) -{ - core::matrix3x4SIMD retval; - size_t redir = instanceDataAllocator->getAddressAllocator().get_real_addr(instanceID); - if (redir==kInvalidInstanceID) - { - _NBL_BREAK_IF(true); - memset(retval.rows[0].pointer,0,48); - } - else - memcpy(retval.rows[0].pointer,reinterpret_cast(instanceDataAllocator->getBackBufferPointer())+redir,sizeof(core::matrix3x4SIMD)); - - return retval; -} - -void CMeshSceneNodeInstanced::setInstanceVisible(const uint32_t& instanceID, const bool& visible) -{ - size_t redirect = instanceDataAllocator->getAddressAllocator().get_real_addr(instanceID)+36+48+extraDataInstanceSize; - instanceDataAllocator->markRangeForPush(redirect,redirect+1u); - reinterpret_cast(instanceDataAllocator->getBackBufferPointer())[redirect] = visible; - /// update BBox? -} - -void CMeshSceneNodeInstanced::setInstanceData(const uint32_t& instanceID, const void* data) -{ - if (extraDataInstanceSize==0) - return; - - size_t redirect = instanceDataAllocator->getAddressAllocator().get_real_addr(instanceID)+36+48; - instanceDataAllocator->markRangeForPush(redirect,redirect+extraDataInstanceSize); - uint8_t* ptr = reinterpret_cast(instanceDataAllocator->getBackBufferPointer())+redirect; - memcpy(ptr,data,extraDataInstanceSize); -} - -void CMeshSceneNodeInstanced::removeInstance(const uint32_t& instanceID) -{ - removeInstances(1,&instanceID); -} - -void CMeshSceneNodeInstanced::removeInstances(const size_t& instanceCount, const uint32_t* instanceIDs) -{ - constexpr bool usesContiguousAddrAllocator = std::is_same,InstanceDataAddressAllocator>::value; - - uint32_t minRedirect = kInvalidInstanceID; - for (size_t i=0; igetAddressAllocator().get_real_addr(instanceIDs[i]); - if (redirect dummyBytes_(instanceCount,dataPerInstanceInputSize); - uint32_t* const dummyBytes = dummyBytes_.data(); - - instanceDataAllocator->multi_free_addr(instanceCount,instanceIDs,static_cast(dummyBytes)); - } - - NBL_PSEUDO_IF_CONSTEXPR_BEGIN(usesContiguousAddrAllocator) - { - // everything got shifted down by 1 so mark dirty - instanceDataAllocator->markRangeForPush(minRedirect,core::address_allocator_traits::get_allocated_size(instanceDataAllocator->getAddressAllocator())); - } - NBL_PSEUDO_IF_CONSTEXPR_END - - if (getCurrentInstanceCapacity()!=instanceBBoxesCount) - { - size_t newCount = getCurrentInstanceCapacity(); - { // kind-of realloc - size_t newSize = newCount*sizeof(core::aabbox3df); - void* newPtr = _NBL_ALIGNED_MALLOC(newSize,_NBL_SIMD_ALIGNMENT); - memcpy(newPtr,instanceBBoxes,newSize); - _NBL_ALIGNED_FREE(instanceBBoxes); - instanceBBoxes = (core::aabbox3df*)newPtr; - } - for (size_t i=instanceBBoxesCount; isetIndexCount(lodCullingPointMesh->getIndexCount()-instanceCount); -} - -void CMeshSceneNodeInstanced::RecullInstances() -{ - if (LoD.size()==0||!instanceDataAllocator||getInstanceCount()==0||!SceneManager) - { - for (size_t i=0; igetMeshBufferCount(); j++) - { - LoD[i].mesh->getMeshBuffer(j)->setInstanceCount(0); - LoD[i].mesh->getMeshBuffer(j)->setBaseInstance(0); - } - Box.MinEdge = Box.MaxEdge = core::vector3df(0.f); - return; - } - - video::IVideoDriver* driver = SceneManager->getVideoDriver(); - - { - //can swap before or after, but defubuteky before tform feedback shadeur - instanceDataAllocator->pushBuffer(driver->getDefaultUpStreamingBuffer()); - - size_t outputSizePerLoD = dataPerInstanceOutputSize*getCurrentInstanceCapacity(); - if (gpuCulledLodInstanceDataBuffer->getSize()!=xfb.size()*gpuLoDsPerPass*outputSizePerLoD) - { - video::IDriverMemoryBacked::SDriverMemoryRequirements reqs = gpuCulledLodInstanceDataBuffer->getMemoryReqs(); - reqs.vulkanReqs.size = xfb.size()*gpuLoDsPerPass*outputSizePerLoD; - {auto rep = SceneManager->getVideoDriver()->createGPUBufferOnDedMem(reqs,gpuCulledLodInstanceDataBuffer->canUpdateSubRange()); gpuCulledLodInstanceDataBuffer->pseudoMoveAssign(rep); rep->drop();} - for (size_t i=0; ibindOutputBuffer(j,gpuCulledLodInstanceDataBuffer.get(),(i*gpuLoDsPerPass+j)*outputSizePerLoD,outputSizePerLoD); - } - } - - driver->setTransform(video::E4X3TS_WORLD,core::matrix3x4SIMD().set(AbsoluteTransformation)); - for (size_t i=0; i(lodCullingPointMesh->getMaterial().MaterialTypeParam) = i*gpuLoDsPerPass; - reinterpret_cast(lodCullingPointMesh->getMaterial().MaterialTypeParam2) = i*gpuLoDsPerPass+gpuLoDsPerPass-1; - driver->setMaterial(lodCullingPointMesh->getMaterial()); - driver->beginTransformFeedback(xfb[i].get(),lodCullingPointMesh->getMaterial().MaterialType,asset::EPT_POINTS); - for (size_t j=0; jbeginQuery(LoD[i*gpuLoDsPerPass+j].query.get(),j); - driver->drawMeshBuffer(lodCullingPointMesh.get()); - for (size_t j=0; jendQuery(LoD[i*gpuLoDsPerPass+j].query.get(),j); - driver->endTransformFeedback(); - } - - renderPriority = 0x80000000u-(++recullOrder); - flagQueryForRetrieval = true; - } -} - -//! frame -void CMeshSceneNodeInstanced::OnRegisterSceneNode() -{ - ISceneNode::OnRegisterSceneNode(); - - if (IsVisible&&LoD.size()&&instanceDataAllocator&&getInstanceCount()&&canProceedPastFence()) - { - // because this node supports rendering of mixed mode meshes consisting of - // transparent and solid material at the same time, we need to go through all - // materials, check of what type they are and register this node for the right - // render pass according to that. - - video::IVideoDriver* driver = SceneManager->getVideoDriver(); - - PassCount = 0; - int transparentCount = 0; - int solidCount = 0; - - for (size_t i=0; igetMeshBufferCount(); j++) - { - video::IGPUMeshBuffer* mb = LoD[i].mesh->getMeshBuffer(j); - if (!mb || mb->getIndexCount()<1) - continue; - - video::IMaterialRenderer* rnd = driver->getMaterialRenderer(mb->getMaterial().MaterialType); - - if (rnd && rnd->isTransparent()) - ++transparentCount; - else - ++solidCount; - - if (solidCount && transparentCount) - break; - } - - // register according to material types counted - uint32_t taken = 0; - if (solidCount) - taken |= SceneManager->registerNodeForRendering(this, scene::ESNRP_SOLID); - - if (transparentCount) - taken |= SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT); - - if (taken) - RecullInstances(); - } -} - - -//! renders the node. -void CMeshSceneNodeInstanced::render() -{ - video::IVideoDriver* driver = SceneManager->getVideoDriver(); - - if (LoD.size()==0 || !driver) - return; - - bool isTransparentPass = - SceneManager->getSceneNodeRenderPass() == scene::ESNRP_TRANSPARENT; - - ++PassCount; - - driver->setTransform(video::E4X3TS_WORLD, core::matrix3x4SIMD().set(AbsoluteTransformation)); - - - if (flagQueryForRetrieval) - { -/*#ifdef _NBL_DEBUG - if (!LoD[LoD.size()-1].query->isQueryReady()) - os::Printer::log("GPU Culling Feedback Transform Instance Count Query Not Ready yet, STALLING CPU!\n",ELL_WARNING); -#endif // _NBL_DEBUG*/ - for (size_t j=0; jgetQueryResult(&tmp); - for (size_t i=0; igetMeshBufferCount(); i++) - { - LoD[j].mesh->getMeshBuffer(i)->setInstanceCount(tmp); - LoD[j].mesh->getMeshBuffer(i)->setBaseInstance(xfb[j/gpuLoDsPerPass]->getOutputBufferOffset(j%gpuLoDsPerPass)/dataPerInstanceOutputSize); - } - } - flagQueryForRetrieval = false; - } - - for (uint32_t i=0; igetMeshBufferCount(); j++) - { - const video::SGPUMaterial& material = LoD[i].mesh->getMeshBuffer(j)->getMaterial(); - - video::IMaterialRenderer* rnd = driver->getMaterialRenderer(material.MaterialType); - bool transparent = (rnd && rnd->isTransparent()); - - // only render transparent buffer if this is the transparent render pass - // and solid only in solid pass - if (transparent == isTransparentPass) - { - driver->setMaterial(material); - driver->drawMeshBuffer(LoD[i].mesh->getMeshBuffer(j)); - } - } - } -} - - -} // end namespace scene -} // end namespace nbl - - diff --git a/source/Nabla/CMeshSceneNodeInstanced.h b/source/Nabla/CMeshSceneNodeInstanced.h deleted file mode 100644 index dd8773bd2f..0000000000 --- a/source/Nabla/CMeshSceneNodeInstanced.h +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#ifndef __NBL_C_MESH_SCENE_NODE_INSTANCED_H_INCLUDED__ -#define __NBL_C_MESH_SCENE_NODE_INSTANCED_H_INCLUDED__ - -#include "ESceneNodeTypes.h" -#include "IMeshSceneNodeInstanced.h" -#include "ITransformFeedback.h" -#include "IQueryObject.h" -#include "ISceneManager.h" - - -namespace nbl -{ -namespace video -{ -class SGPUMesh; -} -namespace scene -{ - -class CMeshSceneNodeInstanced; - - -//! A scene node displaying a static mesh -//! default instance data is interleaved -class CMeshSceneNodeInstanced : public IMeshSceneNodeInstanced -{ - protected: - virtual ~CMeshSceneNodeInstanced(); - - public: - static uint32_t recullOrder; - - //! Constructor - /** Use setMesh() to set the mesh to display. - */ - CMeshSceneNodeInstanced(IDummyTransformationSceneNode* parent, ISceneManager* mgr, int32_t id, - const core::vector3df& position = core::vector3df(0,0,0), - const core::vector3df& rotation = core::vector3df(0,0,0), - const core::vector3df& scale = core::vector3df(1,1,1)); - - //! - virtual bool supportsDriverFence() const {return true;} - - //! Sets a new mesh to display - /** \param mesh Mesh to display. */ - virtual bool setLoDMeshes( const core::vector& levelsOfDetail, const size_t& dataSizePerInstanceOutput, - const video::SGPUMaterial& lodSelectionShader, VaoSetupOverrideFunc vaoSetupOverride, - const size_t shaderLoDsPerPass=1, void* overrideUserData=nullptr, - const size_t& extraDataSizePerInstanceInput=0) override; - - //! Get the currently defined mesh for display. - /** \return Pointer to mesh which is displayed by this node. */ - virtual video::CGPUMesh* getLoDMesh(const size_t &lod) override {return LoD[lod].mesh.get();} - - virtual const core::aabbox3df& getLoDInvariantBBox() const {return LoDInvariantBox;} - - - virtual size_t getInstanceCount() const { return core::address_allocator_traits::get_allocated_size(instanceDataAllocator->getAddressAllocator())/dataPerInstanceInputSize; } - - - virtual uint32_t addInstance(const core::matrix3x4SIMD& relativeTransform, const void* extraData=NULL) override; - - virtual bool addInstances(uint32_t* instanceIDs, const size_t& instanceCount, const core::matrix3x4SIMD* relativeTransforms, const void* extraData) override; - - virtual void setInstanceTransform(const uint32_t& instanceID, const core::matrix3x4SIMD& relativeTransform) override; - - virtual core::matrix3x4SIMD getInstanceTransform(const uint32_t& instanceID) override; - - virtual void setInstanceVisible(const uint32_t& instanceID, const bool& visible) override; - - virtual void setInstanceData(const uint32_t& instanceID, const void* data) override; - - virtual void removeInstance(const uint32_t& instanceID) override; - - virtual void removeInstances(const size_t& instanceCount, const uint32_t* instanceIDs) override; - - - //! frame - virtual void OnRegisterSceneNode(); - - //! renders the node. - virtual void render(); - - //! returns the axis aligned bounding box of this node - virtual const core::aabbox3d& getBoundingBox() - { - if (wantBBoxUpdate&&needsBBoxRecompute) - { - Box.reset(0,0,0); - size_t instanceCount = getInstanceCount(); - size_t allocCapacity = getCurrentInstanceCapacity(); - - size_t optimCount = 0; - for (size_t i=0; optimCountinstanceBBoxes[i].MaxEdge.X) - continue; - - size_t tmp = optimCount++; - if (tmp) - { - for (size_t j=0; j<3; j++) - { - if (reinterpret_cast(&instanceBBoxes[i].MinEdge)[j](&Box.MinEdge)[j]) - reinterpret_cast(&Box.MinEdge)[j] = reinterpret_cast(&instanceBBoxes[i].MinEdge)[j]; - } - for (size_t j=0; j<3; j++) - { - if (reinterpret_cast(&instanceBBoxes[i].MaxEdge)[j]>reinterpret_cast(&Box.MaxEdge)[j]) - reinterpret_cast(&Box.MaxEdge)[j] = reinterpret_cast(&instanceBBoxes[i].MaxEdge)[j]; - } - } - else - Box = instanceBBoxes[i]; - } - needsBBoxRecompute = false; - } - return Box; - } - - //! Returns type of the scene node - virtual ESCENE_NODE_TYPE getType() const { return ESNT_MESH_INSTANCED; } - - //! Creates a clone of this scene node and its children. - virtual ISceneNode* clone(IDummyTransformationSceneNode* newParent=0, ISceneManager* newManager=0) { assert(false); return nullptr; } - - protected: - void RecullInstances(); - core::aabbox3d Box; - core::aabbox3d LoDInvariantBox; - - struct LoDData - { - core::smart_refctd_ptr mesh; - core::smart_refctd_ptr query; - float distanceSQ; - size_t instancesToDraw; - }; - core::vector LoD; - core::vector< core::smart_refctd_ptr> xfb; - size_t gpuLoDsPerPass; - - bool needsBBoxRecompute; - size_t instanceBBoxesCount; - core::aabbox3df* instanceBBoxes; - bool flagQueryForRetrieval; - core::smart_refctd_ptr lodCullingPointMesh; - core::smart_refctd_ptr gpuCulledLodInstanceDataBuffer; - - size_t dataPerInstanceOutputSize; - size_t extraDataInstanceSize; - size_t dataPerInstanceInputSize; - - int32_t PassCount; - - inline size_t getCurrentInstanceCapacity() const - { - return getBlockIDFromAddr(core::address_allocator_traits::get_total_size(instanceDataAllocator->getAddressAllocator())); - } - - inline size_t getBlockIDFromAddr(uint32_t instanceID) const - { - return instanceDataAllocator->getAddressAllocator().addressToBlockID(instanceID); - } -}; - - -} // end namespace scene -} // end namespace nbl - - -#endif - - - diff --git a/source/Nabla/CSceneManager.cpp b/source/Nabla/CSceneManager.cpp index f254d49ba2..0258ab1b8f 100644 --- a/source/Nabla/CSceneManager.cpp +++ b/source/Nabla/CSceneManager.cpp @@ -109,27 +109,6 @@ ICameraSceneNode* CSceneManager::addCameraSceneNodeFPS(IDummyTransformationScene } -//! Returns the current active camera. -//! \return The active camera is returned. Note that this can be NULL, if there -//! was no camera created yet. -ICameraSceneNode* CSceneManager::getActiveCamera() const -{ - return ActiveCamera; -} - - -//! Sets the active camera. The previous active camera will be deactivated. -//! \param camera: The new camera which should be active. -void CSceneManager::setActiveCamera(ICameraSceneNode* camera) -{ - if (camera) - camera->grab(); - if (ActiveCamera) - ActiveCamera->drop(); - - ActiveCamera = camera; -} - //! void CSceneManager::OnAnimate(uint32_t timeMs) { diff --git a/source/Nabla/CSceneManager.h b/source/Nabla/CSceneManager.h index f3aa4f2a68..1e5e8bd042 100644 --- a/source/Nabla/CSceneManager.h +++ b/source/Nabla/CSceneManager.h @@ -58,38 +58,6 @@ class CSceneManager : public ISceneManager, public ISceneNode SKeyMap* keyMapArray=0, int32_t keyMapSize=0, bool noVerticalMovement=false, float jumpSpeed = 0.f, bool invertMouseY=false, bool makeActive=true); - - //! Returns the current active camera. - //! \return The active camera is returned. Note that this can be NULL, if there - //! was no camera created yet. - virtual ICameraSceneNode* getActiveCamera() const; - - //! Sets the active camera. The previous active camera will be deactivated. - //! \param camera: The new camera which should be active. - virtual void setActiveCamera(ICameraSceneNode* camera); - - //! Clears the whole scene. All scene nodes are removed. - virtual void clear(); - - //! Removes all children of this scene node - virtual void removeAll(); - - protected: - - //! clears the deletion list - void clearDeletionList(); - - //! video driver - video::IVideoDriver* Driver; - - //! timer - nbl::ITimer* Timer; - - //! parent device - IrrlichtDevice* Device; - - //! current active camera - ICameraSceneNode* ActiveCamera; }; } // end namespace video From 11df95b0404c8c8d6748fbb5a72157142b2aabd7 Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Mon, 7 Mar 2022 21:54:11 +0100 Subject: [PATCH 58/91] Filter resources to embed to make sure they are listed in nice way --- src/nbl/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 4021197bd7..62817c1635 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -514,8 +514,10 @@ file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") #always install builtins (some may be included in cpp regardless if embedded or not) foreach(X IN LISTS nbl_resources_to_embed) - list(APPEND NABLA_HEADERS_PUBLIC ${NBL_ROOT_PATH}/include/${X}) + list(APPEND NABLA_RESOURCES_TO_EMBED_PUBLIC ${NBL_ROOT_PATH}/include/${X}) endforeach() +list(APPEND NABLA_HEADERS_PUBLIC ${NABLA_RESOURCES_TO_EMBED_PUBLIC}) +source_group("Resources to embed" FILES ${NABLA_RESOURCES_TO_EMBED_PUBLIC}) set(NABLA_HEADERS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" ${NABLA_HEADERS_PUBLIC} ${NABLA_HEADERS_PIRV1} ${NABLA_HEADERS_PRIV2}) From 0752520f611d5789d9389c18619277aa21a5cc44 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 8 Mar 2022 09:56:36 +0100 Subject: [PATCH 59/91] small template fix, lets see if android compiles --- include/nbl/video/surface/CSurfaceGL.h | 45 ++++++++++++-------------- include/nbl/video/surface/ISurface.h | 6 ++-- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/include/nbl/video/surface/CSurfaceGL.h b/include/nbl/video/surface/CSurfaceGL.h index f7f2b01783..d8a30f3c9b 100644 --- a/include/nbl/video/surface/CSurfaceGL.h +++ b/include/nbl/video/surface/CSurfaceGL.h @@ -12,12 +12,12 @@ namespace nbl::video { -template typename Base, class CRTP = void> -class CSurfaceGLImpl : public Base +template typename Base, class CRTP = void> +class CSurfaceGLImpl : public Base { public: using this_t = std::conditional_t,CSurfaceGLImpl,CRTP>; - using base_t = Base; + using base_t = Base; template static inline core::smart_refctd_ptr create(core::smart_refctd_ptr>&& api, core::smart_refctd_ptr&& window) @@ -96,24 +96,24 @@ using CSurfaceNativeGL = CSurfaceGLImpl; // TODO: conditional defines #ifdef _NBL_PLATFORM_WINDOWS_ using CSurfaceGLWin32 = CSurfaceGL; -class CSurfaceNativeGLWin32 : public CSurfaceNativeGL +class CSurfaceNativeGLWin32 : public CSurfaceNativeGL { -protected: - using base_t = CSurfaceNativeGL; - using base_t::base_t; - - uint32_t getWidth() const override - { - RECT wr; - GetWindowRect(m_handle, &wr); - return wr.right - wr.left; - } - uint32_t getHeight() const override - { - RECT wr; - GetWindowRect(m_handle, &wr); - return wr.top - wr.bottom; - } + protected: + using base_t = CSurfaceNativeGL; + using base_t::base_t; + + uint32_t getWidth() const override + { + RECT wr; + GetWindowRect(m_handle, &wr); + return wr.right - wr.left; + } + uint32_t getHeight() const override + { + RECT wr; + GetWindowRect(m_handle, &wr); + return wr.top - wr.bottom; + } }; #elif defined(_NBL_PLATFORM_LINUX_) using CSurfaceGLX11 = CSurfaceGL; @@ -121,11 +121,6 @@ using CSurfaceGLX11 = CSurfaceGL; using CSurfaceGLAndroid = CSurfaceGL; #endif - -//using CSurfaceGLAndroid = CSurfaceGL; -//using CSurfaceGLX11 = CSurfaceGL; -//using CSurfaceGLWayland = CSurfaceGL; - } #endif \ No newline at end of file diff --git a/include/nbl/video/surface/ISurface.h b/include/nbl/video/surface/ISurface.h index bdd3e45346..25e0543616 100644 --- a/include/nbl/video/surface/ISurface.h +++ b/include/nbl/video/surface/ISurface.h @@ -109,7 +109,8 @@ class ISurface : public core::IReferenceCounted virtual const void* getNativeWindowHandle() const = 0; }; -template +// Base for use with Nabla's window wrappers +template class CSurface : public ImmediateBase { public: @@ -129,7 +130,8 @@ class CSurface : public ImmediateBase core::smart_refctd_ptr m_window; }; -template +// Base to make surfaces directly from Native OS window handles +template class CSurfaceNative : public ImmediateBase { public: From 164cbf628d85438a2fc61c2e2b09de7cfd80e9e1 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 8 Mar 2022 10:00:28 +0100 Subject: [PATCH 60/91] fix all Vulkan validation errors in example 5, except the ImageView dying. --- .../05.NablaTutorialExample/main.cpp | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/examples_tests/05.NablaTutorialExample/main.cpp b/examples_tests/05.NablaTutorialExample/main.cpp index 50d20fb567..d66a3dd2e8 100644 --- a/examples_tests/05.NablaTutorialExample/main.cpp +++ b/examples_tests/05.NablaTutorialExample/main.cpp @@ -296,7 +296,7 @@ class NablaTutorialExampleApp : public ApplicationBase IGPUBuffer::SCreationParams creationParams = {}; creationParams.canUpdateSubRange = true; - creationParams.usage = asset::IBuffer::EUF_UNIFORM_BUFFER_BIT; + creationParams.usage = core::bitflag(asset::IBuffer::EUF_UNIFORM_BUFFER_BIT)|asset::IBuffer::EUF_TRANSFER_DST_BIT; IDriverMemoryBacked::SDriverMemoryRequirements memReq; memReq.vulkanReqs.size = sizeof(SBasicViewParameters); memReq.vulkanReqs.alignment = physicalDevice->getLimits().UBOAlignment; @@ -459,7 +459,10 @@ class NablaTutorialExampleApp : public ApplicationBase auto& fence = frameComplete[resourceIx]; if (fence) - while (logicalDevice->waitForFences(1u, &fence.get(), false, MAX_TIMEOUT) == video::IGPUFence::ES_TIMEOUT) {} + { + logicalDevice->blockForFences(1u,&fence.get()); + logicalDevice->resetFences(1u,&fence.get()); + } else fence = logicalDevice->createFence(static_cast(0)); @@ -510,6 +513,31 @@ class NablaTutorialExampleApp : public ApplicationBase viewport.width = WIN_W; viewport.height = WIN_H; commandBuffer->setViewport(0u, 1u, &viewport); + VkRect2D scissor; + scissor.offset = {0u,0u}; + scissor.extent = {WIN_W,WIN_H}; + commandBuffer->setScissor(0u,1u,&scissor); + + const auto viewProjection = camera.getConcatenatedMatrix(); + core::matrix3x4SIMD modelMatrix; + modelMatrix.setRotation(nbl::core::quaternion(0, 1, 0)); + + auto mv = core::concatenateBFollowedByA(camera.getViewMatrix(), modelMatrix); + auto mvp = core::concatenateBFollowedByA(viewProjection, modelMatrix); + core::matrix3x4SIMD normalMat; + mv.getSub3x3InverseTranspose(normalMat); + + /* + Updating UBO for basic view parameters and sending + updated data to staging buffer that will redirect + the data to graphics card - to vertex shader. + */ + + SBasicViewParameters uboData; + memcpy(uboData.MV, mv.pointer(), sizeof(mv)); + memcpy(uboData.MVP, mvp.pointer(), sizeof(mvp)); + memcpy(uboData.NormalMat, normalMat.pointer(), sizeof(normalMat)); + commandBuffer->updateBuffer(gpuubo.get(), 0ull, gpuubo->getSize(), &uboData); swapchain->acquireNextImage(MAX_TIMEOUT, imageAcquire[resourceIx].get(), nullptr, &acquiredNextFBO); @@ -531,30 +559,8 @@ class NablaTutorialExampleApp : public ApplicationBase beginInfo.renderArea = area; beginInfo.clearValues = clear; } - commandBuffer->beginRenderPass(&beginInfo, nbl::asset::ESC_INLINE); - const auto viewProjection = camera.getConcatenatedMatrix(); - core::matrix3x4SIMD modelMatrix; - modelMatrix.setRotation(nbl::core::quaternion(0, 1, 0)); - - auto mv = core::concatenateBFollowedByA(camera.getViewMatrix(), modelMatrix); - auto mvp = core::concatenateBFollowedByA(viewProjection, modelMatrix); - core::matrix3x4SIMD normalMat; - mv.getSub3x3InverseTranspose(normalMat); - - /* - Updating UBO for basic view parameters and sending - updated data to staging buffer that will redirect - the data to graphics card - to vertex shader. - */ - - SBasicViewParameters uboData; - memcpy(uboData.MV, mv.pointer(), sizeof(mv)); - memcpy(uboData.MVP, mvp.pointer(), sizeof(mvp)); - memcpy(uboData.NormalMat, normalMat.pointer(), sizeof(normalMat)); - commandBuffer->updateBuffer(gpuubo.get(), 0ull, gpuubo->getSize(), &uboData); - /* Binding the most important objects needed to render anything on the screen with textures: From c38173ab4e4dd1ce4b8b388c0a393f32fcba4e10 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 8 Mar 2022 12:07:00 +0100 Subject: [PATCH 61/91] remove as many cmake macros as I could, also fix a few small Android issues --- include/nbl/nblpack.h | 4 +- include/nbl/system/CStdoutLoggerAndroid.h | 4 +- src/nbl/CMakeLists.txt | 253 +++++++++------------- src/nbl/system/CStdoutLoggerAndroid.cpp | 6 +- 4 files changed, 107 insertions(+), 160 deletions(-) diff --git a/include/nbl/nblpack.h b/include/nbl/nblpack.h index 7c0ebd986e..78e558e64c 100644 --- a/include/nbl/nblpack.h +++ b/include/nbl/nblpack.h @@ -9,9 +9,11 @@ // in between! // byte-align structures -#if defined(_MSC_VER) || defined(__GNUC__) || defined (__clang__) +#if defined(_MSC_VER) || defined(__GNUC__) || defined(__clang__) # ifdef _MSC_VER # pragma warning(disable: 4103) +# elif defined(__clang__) +# pragma clang diagnostic ignored "-Wpragma-pack" # endif # pragma pack( push, packing ) # pragma pack( 1 ) diff --git a/include/nbl/system/CStdoutLoggerAndroid.h b/include/nbl/system/CStdoutLoggerAndroid.h index 4590b644a9..f451b9b418 100644 --- a/include/nbl/system/CStdoutLoggerAndroid.h +++ b/include/nbl/system/CStdoutLoggerAndroid.h @@ -3,10 +3,10 @@ #include "nbl/system/IThreadsafeLogger.h" -#ifdef _NBL_PLATFORM_ANDROID_ namespace nbl::system { +#ifdef _NBL_PLATFORM_ANDROID_ class CStdoutLoggerAndroid : public IThreadsafeLogger { public: @@ -15,8 +15,8 @@ class CStdoutLoggerAndroid : public IThreadsafeLogger private: void threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override; }; +#endif } -#endif #endif \ No newline at end of file diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index 62817c1635..ee7b224fa4 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -399,115 +399,6 @@ set(COMMON_INCLUDE_DIRS $ #for dynamically generated jconfig.h ) -# TODO: Change all MACROS into FUNCTIONS (if possible, need to clarify variable scoping rules) -macro(nbl_target_link_zlib _trgt) - add_dependencies(zlibstatic zlib_copy) - add_dependencies(${_trgt} zlibstatic) - target_link_libraries(${_trgt} INTERFACE zlibstatic) - - target_link_libraries(${_trgt} INTERFACE - $<$:${ZLIB_LIBRARY_DEBUG}> - $<$:${ZLIB_LIBRARY_RELEASE}> - $<$:${ZLIB_LIBRARY_RELWITHDEBINFO}> - ) - - target_include_directories(${_trgt} PUBLIC $/copy_source) -endmacro() - -# PSTL -macro(nbl_target_link_oneDPL _trgt) - add_dependencies(${_trgt} oneDPL) - target_include_directories(${_trgt} PUBLIC ${ONETBB_INSTALL_DIR}/include) - target_include_directories(${_trgt} PUBLIC ${ONEDPL_INSTALL_DIR}/include) - - target_link_libraries(${_trgt} INTERFACE - tbb tbbmalloc tbbmalloc_proxy - ) -endmacro() - -#Parallel hashmap -macro(nbl_target_include_parallel_hashmap _trgt) - target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/parallel-hashmap/parallel_hashmap) -endmacro() - -macro(nbl_target_link_openssl _trgt) - if(ANDROID AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") # OpenSSL can't be built for Android platform using windows OS host - target_link_libraries(${_trgt} INTERFACE - "$" - ) - - target_include_directories(${_trgt} PUBLIC "$/build/include") - endif() -endmacro() -macro(nbl_target_link_shaderc _trgt) - add_dependencies(${_trgt} shaderc) - target_link_libraries(${_trgt} INTERFACE - shaderc - ) - target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/shaderc/libshaderc/include) -endmacro() -macro(nbl_target_link_libjpeg_turbo _trgt) - add_dependencies(${_trgt} jpeg-static) - target_link_libraries(${_trgt} INTERFACE - jpeg-static - ) - target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/libjpeg-turbo) -endmacro() -macro(nbl_target_link_libpng _trgt) - add_dependencies(${_trgt} png_static) - target_link_libraries(${_trgt} INTERFACE - png_static - ) - target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/libpng) -endmacro() -macro(nbl_target_link_openexr _trgt) - add_dependencies(${_trgt} OpenEXR::IlmImf) - target_link_libraries(${_trgt} INTERFACE - OpenEXR::IlmImf - ) - target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/OpenEXR/IlmImf - ${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/Half - ${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/Iex - ${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/IexMath - ${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/Imath - ${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/IlmThread - ) -endmacro() -macro(nbl_target_link_gli _trgt) - add_dependencies(${_trgt} gli) - target_link_libraries(${_trgt} INTERFACE - gli - ) - target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/gli) -endmacro() -macro(nbl_target_link_spirv_tools _trgt) - add_dependencies(${_trgt} SPIRV) - add_dependencies(${_trgt} SPIRV-Tools) - add_dependencies(${_trgt} SPIRV-Tools-opt) - target_link_libraries(${_trgt} INTERFACE - SPIRV SPIRV-Tools SPIRV-Tools-opt - ) - target_include_directories(${_trgt} PUBLIC BEFORE - ${THIRD_PARTY_SOURCE_DIR}/SPIRV-Tools/include - ) -endmacro() -macro(nbl_target_link_volk _trgt) - target_link_libraries(${_trgt} PUBLIC volk) -endmacro() -macro(nbl_target_link_EGL _trgt) - target_link_libraries(${_trgt} PRIVATE egl) -endmacro() - -# simdjson -macro(nbl_target_link_simdjson _trgt) - add_dependencies(${_trgt} simdjson) - target_link_libraries(${_trgt} INTERFACE - simdjson - ) - target_include_directories(${_trgt} PUBLIC ${THIRD_PARTY_SOURCE_DIR}/simdjson) - set_target_properties(simdjson PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -endmacro() - # just gather all the header files and later put them into project so it's easy to search for things using IDE file(GLOB_RECURSE NABLA_HEADERS_PRIV1 "*.h") file(GLOB_RECURSE NABLA_HEADERS_PRIV2 "${NBL_ROOT_PATH}/src/nbl/*.h") @@ -549,44 +440,113 @@ if (ANDROID) ) endif() -#TODO maybe make a macro to do this (note: it's also used in common.cmake) +#TODO maybe make a macro/function to do this (note: it's also used in common.cmake) set_property(TARGET Nabla PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + +## Set up 3rdparty deps +# Parallel Hashmap +target_include_directories(Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/parallel-hashmap/parallel_hashmap) +# oneDPL for clang C++17 parallelism +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_dependencies(Nabla oneDPL) + target_include_directories(Nabla PUBLIC ${ONETBB_INSTALL_DIR}/include) + target_include_directories(Nabla PUBLIC ${ONEDPL_INSTALL_DIR}/include) + target_link_libraries(Nabla INTERFACE tbb tbbmalloc tbbmalloc_proxy) +endif() + +if (UNIX) + target_link_libraries(Nabla INTERFACE + ${CMAKE_THREAD_LIBS_INIT} + ${CMAKE_DL_LIBS} + ) +endif() +# OpenSSL if(ANDROID AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") # OpenSSL can't be built for Android platform using windows OS host add_dependencies(Nabla openssl_build) + target_link_libraries(Nabla INTERFACE "$") + target_include_directories(Nabla PUBLIC "$/build/include") endif() -target_include_directories(Nabla PUBLIC "${THIRD_PARTY_SOURCE_DIR}/Vulkan-Headers/include") -nbl_target_link_openssl(Nabla) -nbl_target_link_zlib(Nabla) -nbl_target_link_shaderc(Nabla) -nbl_target_link_libjpeg_turbo(Nabla) -nbl_target_link_libpng(Nabla) +# zlib +add_dependencies(zlibstatic zlib_copy) +add_dependencies(Nabla zlibstatic) +target_link_libraries(Nabla INTERFACE zlibstatic) +target_link_libraries(Nabla INTERFACE + $<$:${ZLIB_LIBRARY_DEBUG}> + $<$:${ZLIB_LIBRARY_RELEASE}> + $<$:${ZLIB_LIBRARY_RELWITHDEBINFO}> +) +target_include_directories(Nabla PUBLIC $/copy_source) + +# shaderc +add_dependencies(Nabla shaderc) +target_link_libraries(Nabla INTERFACE shaderc) +target_include_directories(Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/shaderc/libshaderc/include) +# spirv tools +add_dependencies(Nabla SPIRV) +add_dependencies(Nabla SPIRV-Tools) +add_dependencies(Nabla SPIRV-Tools-opt) +target_link_libraries(Nabla INTERFACE SPIRV SPIRV-Tools SPIRV-Tools-opt) +target_include_directories(Nabla PUBLIC BEFORE ${THIRD_PARTY_SOURCE_DIR}/SPIRV-Tools/include) +# simdjson +add_dependencies(Nabla simdjson) +target_link_libraries(Nabla INTERFACE simdjson) +target_include_directories(Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/simdjson) +set_target_properties(simdjson PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +# libjpeg +add_dependencies(Nabla jpeg-static) +target_link_libraries(Nabla INTERFACE jpeg-static) +target_include_directories(Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/libjpeg-turbo) +# libpng +add_dependencies(Nabla png_static) +target_link_libraries(Nabla INTERFACE png_static) +target_include_directories(Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/libpng) +# OpenEXR if (_NBL_COMPILE_WITH_OPEN_EXR_) - nbl_target_link_openexr(Nabla) + add_dependencies(Nabla OpenEXR::IlmImf) + target_link_libraries(Nabla INTERFACE OpenEXR::IlmImf) + target_include_directories( + Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/OpenEXR/IlmImf + Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/Half + Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/Iex + Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/IexMath + Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/Imath + Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/openexr/IlmBase/IlmThread + ) endif() if(_NBL_COMPILE_WITH_GLI_) - nbl_target_link_gli(Nabla) -endif() -nbl_target_include_parallel_hashmap(Nabla) -nbl_target_link_spirv_tools(Nabla) -nbl_target_link_volk(Nabla) -nbl_target_link_EGL(Nabla) -nbl_target_link_simdjson(Nabla) -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - nbl_target_link_oneDPL(Nabla) + add_dependencies(Nabla gli) + target_link_libraries(Nabla INTERFACE gli) + target_include_directories(Nabla PUBLIC ${THIRD_PARTY_SOURCE_DIR}/gli) endif() -#target_link_libraries(Nabla INTERFACE ${OPENGL_gl_LIBRARY}) -if (UNIX) - target_link_libraries(Nabla INTERFACE - ${CMAKE_THREAD_LIBS_INIT} - ${CMAKE_DL_LIBS} +# Linux Display Systems +if (UNIX AND NOT ANDROID AND NOT APPLE) + target_include_directories(Nabla PUBLIC + ${X11_INCLUDE_DIR} + X11_Xrandr_INCLUDE_PATH + ${X11_xf86vmode_INCLUDE_PATH} ) - if (NOT ANDROID) - target_link_libraries(Nabla INTERFACE $<$:-lunwind>) - endif() endif() +# Vulkan +target_include_directories(Nabla PUBLIC "${THIRD_PARTY_SOURCE_DIR}/Vulkan-Headers/include") +target_link_libraries(Nabla PUBLIC volk) +if(WIN32) + target_compile_definitions(Nabla PRIVATE VK_USE_PLATFORM_WIN32_KHR) +endif() +# CUDA +if (NBL_COMPILE_WITH_CUDA) + target_include_directories(Nabla PUBLIC ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) +endif() +# OpenGL (EGL) +target_link_libraries(Nabla PRIVATE egl) +if (ANDROID) + target_compile_definitions(Nabla PUBLIC $<$:WL_EGL_PLATFORM>) +endif() + + +# Include dirs for self target_include_directories(Nabla PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include ${NBL_ROOT_PATH}/include @@ -602,31 +562,14 @@ target_include_directories(Nabla PUBLIC target_include_directories(Nabla PUBLIC ${NBL_ROOT_PATH}/src ${NBL_ROOT_PATH}/source/Nabla ${NBL_ROOT_PATH}/src/3rdparty) # this should be PRIVATE, but things from /src (or /source) are sometimes included in things in /include and so examples have to put source dirs into theirs Include Path target_include_directories(Nabla PRIVATE ${CMAKE_BINARY_DIR}/include) -if (UNIX AND NOT ANDROID AND NOT APPLE) - target_include_directories(Nabla PUBLIC - ${X11_INCLUDE_DIR} - X11_Xrandr_INCLUDE_PATH - ${X11_xf86vmode_INCLUDE_PATH}) -endif() -if (NBL_COMPILE_WITH_CUDA) - target_include_directories(Nabla PUBLIC ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) -endif() target_compile_definitions(Nabla PRIVATE _NBL_STATIC_LIB_ EGL_STATIC SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS - PUBLIC UNW_LOCAL_ONLY INTERFACE _NBL_PCH_IGNORE_PRIVATE_HEADERS ) -if(WIN32) - target_compile_definitions(Nabla PRIVATE VK_USE_PLATFORM_WIN32_KHR) -endif() - -if (ANDROID) - target_compile_definitions(Nabla PUBLIC $<$:WL_EGL_PLATFORM>) -endif() - +# generate definitions out to a header glue_source_definitions(Nabla _NBL_SOURCE_DEFINITIONS_) set(_NBL_DEFINE_FILE_WRAPPER_ ${CMAKE_CURRENT_BINARY_DIR}/include/define.h) @@ -643,7 +586,8 @@ add_custom_command( add_custom_target(generate_nabla_header DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h") add_dependencies(Nabla generate_nabla_header) -if (MSVC) #on MSVC it won't compile without this option! +#on MSVC it won't compile without this option! +if (MSVC) target_compile_options(Nabla PUBLIC /bigobj) endif() @@ -667,17 +611,18 @@ nbl_install_headers("${CMAKE_CURRENT_BINARY_DIR}/include/nabla.h" "${CMAKE_CURRE nbl_install_headers("${NABLA_HEADERS_PUBLIC}" "${NBL_ROOT_PATH}/include") nbl_install_config_header(BuildConfigOptions.h) +# TODO: @AnastazIuk change macros to functions! https://github.com/buildaworldnet/IrrlichtBAW/issues/311 macro(nbl_install_program _TRGT) install(PROGRAMS $ DESTINATION lib CONFIGURATIONS Release) install(PROGRAMS $ DESTINATION debug/lib CONFIGURATIONS Debug) install(PROGRAMS $ DESTINATION relwithdebinfo/lib CONFIGURATIONS RelWithDebInfo) endmacro() - macro(nbl_install_lib _TRGT) install(TARGETS ${_TRGT} ARCHIVE DESTINATION lib CONFIGURATIONS Release) install(TARGETS ${_TRGT} ARCHIVE DESTINATION debug/lib CONFIGURATIONS Debug) install(TARGETS ${_TRGT} ARCHIVE DESTINATION relwithdebinfo/lib CONFIGURATIONS RelWithDebInfo) endmacro() + # Install main lib set_target_properties(Nabla PROPERTIES DEBUG_POSTFIX _debug) set_target_properties(Nabla PROPERTIES RELWITHDEBINFO_POSTFIX _relwithdebinfo) diff --git a/src/nbl/system/CStdoutLoggerAndroid.cpp b/src/nbl/system/CStdoutLoggerAndroid.cpp index 65c7e21969..a76885ee78 100644 --- a/src/nbl/system/CStdoutLoggerAndroid.cpp +++ b/src/nbl/system/CStdoutLoggerAndroid.cpp @@ -1,11 +1,11 @@ #include "nbl/system/CStdoutLoggerAndroid.h" +using namespace nbl::system; + #ifdef _NBL_PLATFORM_ANDROID_ #include -using namespace nbl::system; - -void CStdoutLoggerAndroid::threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) override +void CStdoutLoggerAndroid::threadsafeLog_impl(const std::string_view& fmt, E_LOG_LEVEL logLevel, va_list args) { auto nativeLogLevel = ANDROID_LOG_UNKNOWN; switch (logLevel) From 06112d29bc6536faa3be3e39f800d8f52331bda2 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 8 Mar 2022 12:23:02 +0100 Subject: [PATCH 62/91] More Android fixes --- src/nbl/system/CFilePOSIX.cpp | 2 ++ src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp | 4 ++-- src/nbl/system/ISystem.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nbl/system/CFilePOSIX.cpp b/src/nbl/system/CFilePOSIX.cpp index 89640df118..01bebccbf8 100644 --- a/src/nbl/system/CFilePOSIX.cpp +++ b/src/nbl/system/CFilePOSIX.cpp @@ -4,7 +4,9 @@ using namespace nbl::system; #ifdef __unix__ // WTF: can it be `defined(_NBL_PLATFORM_ANDROID_) | defined(_NBL_PLATFORM_LINUX_)` instead? #include +#include #include + CFilePOSIX::CFilePOSIX( core::smart_refctd_ptr&& sys, path&& _filename, diff --git a/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp b/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp index 867ff8f958..0f5175976e 100644 --- a/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp +++ b/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp @@ -5,11 +5,11 @@ using namespace nbl::system; #if defined(_NBL_PLATFORM_LINUX_) || defined(_NBL_PLATFORM_ANDROID_) #include -void* CFileViewVirtualAllocatorPOSIX::alloc(size_t size) override +void* CFileViewVirtualAllocatorPOSIX::alloc(size_t size) { return mmap((caddr_t)0, size, PROT_WRITE|PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); } -bool CFileViewVirtualAllocatorPOSIX::dealloc(void* data, size_t size) override +bool CFileViewVirtualAllocatorPOSIX::dealloc(void* data, size_t size) { const auto ret = munmap(data,size); return ret != -1; diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index 593e742677..12607777de 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -257,7 +257,7 @@ void ISystem::createFile(future_t>& future, std::f core::smart_refctd_ptr ISystem::openFileArchive(core::smart_refctd_ptr&& file, const std::string_view& password) { // the file backing the archive needs to be readable - if (file->getFlags()&IFile::ECF_READ == 0) + if ((file->getFlags()&IFile::ECF_READ) == 0) return nullptr; // try the archive loaders by using the extension first From 08d1eb18fafb7128be231b01f769331254cf56e3 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 8 Mar 2022 19:50:48 +0100 Subject: [PATCH 63/91] POSIX File and System fixes --- include/nbl/system/ISystemPOSIX.h | 2 +- src/nbl/system/CFilePOSIX.cpp | 2 +- src/nbl/system/ISystemPOSIX.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/nbl/system/ISystemPOSIX.h b/include/nbl/system/ISystemPOSIX.h index 0968d21b92..dfa86a2c93 100644 --- a/include/nbl/system/ISystemPOSIX.h +++ b/include/nbl/system/ISystemPOSIX.h @@ -13,7 +13,7 @@ class ISystemPOSIX : public ISystem class CCaller final : public ISystem::ICaller { public: - core::smart_refctd_ptr createFile_impl(const std::filesystem::path& filename, core::bitflag flags) override final; + core::smart_refctd_ptr createFile(const std::filesystem::path& filename, const core::bitflag flags) override; }; ISystemPOSIX() : ISystem(core::make_smart_refctd_ptr(this)) {} diff --git a/src/nbl/system/CFilePOSIX.cpp b/src/nbl/system/CFilePOSIX.cpp index 01bebccbf8..1f78d5befa 100644 --- a/src/nbl/system/CFilePOSIX.cpp +++ b/src/nbl/system/CFilePOSIX.cpp @@ -14,7 +14,7 @@ CFilePOSIX::CFilePOSIX( void* const _mappedPtr, const size_t _size, const native_file_handle_t _native -) : IFile(std::move(sys),std::move(_filename),_flags,_mappedPtr), +) : ISystemFile(std::move(sys),std::move(_filename),_flags,_mappedPtr), m_size(_size), m_native(_native) { } diff --git a/src/nbl/system/ISystemPOSIX.cpp b/src/nbl/system/ISystemPOSIX.cpp index 3ff3217b3f..c9daf97d15 100644 --- a/src/nbl/system/ISystemPOSIX.cpp +++ b/src/nbl/system/ISystemPOSIX.cpp @@ -9,7 +9,7 @@ using namespace nbl::system; #include #include -core::smart_refctd_ptr ISystemPOSIX::CCaller::createFile_impl(const std::filesystem::path& filename, const core::bitflag flags) +core::smart_refctd_ptr ISystemPOSIX::CCaller::createFile(const std::filesystem::path& filename, const core::bitflag flags) { const bool writeAccess = flags.value&IFile::ECF_WRITE; int createFlags = O_LARGEFILE|(writeAccess ? O_CREAT:0); From c3cad8885558991c3f130d3a75fbee72eb0d702c Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 08:43:10 +0100 Subject: [PATCH 64/91] Finally show the juniors what placement new should look like. Shut up compiler warnings about matching operator delete. Make TAR archive work. --- include/nbl/system/CAPKResourcesArchive.h | 85 ----------------------- include/nbl/system/CApplicationAndroid.h | 3 + include/nbl/system/CFileArchive.h | 39 ++++++++--- include/nbl/system/CFileView.h | 9 +-- src/nbl/system/CAPKResourcesArchive.h | 40 +++++++++++ src/nbl/system/CArchiveLoaderTar.cpp | 14 +--- src/nbl/system/CArchiveLoaderTar.h | 10 +-- 7 files changed, 84 insertions(+), 116 deletions(-) delete mode 100644 include/nbl/system/CAPKResourcesArchive.h create mode 100644 src/nbl/system/CAPKResourcesArchive.h diff --git a/include/nbl/system/CAPKResourcesArchive.h b/include/nbl/system/CAPKResourcesArchive.h deleted file mode 100644 index 203555c590..0000000000 --- a/include/nbl/system/CAPKResourcesArchive.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _NBL_SYSTEM_C_APK_RESOURCES_ARCHIVE_LOADER_H_INCLUDED_ -#define _NBL_SYSTEM_C_APK_RESOURCES_ARCHIVE_LOADER_H_INCLUDED_ -#ifdef _NBL_PLATFORM_ANDROID_ -#include "nbl/system/IFileArchive.h" -#include - -namespace nbl::system -{ -class CAPKResourcesArchive : public IFileArchive -{ - using base_t = IFileArchive; - AAssetManager* mgr; - JNIEnv* env; - ANativeActivity* activity; -public: - CAPKResourcesArchive(core::smart_refctd_ptr&& system, system::logger_opt_smart_ptr&& logger, AAssetManager* _mgr, ANativeActivity* act, JNIEnv* jni) : - base_t(nullptr, std::move(system), std::move(logger)), mgr(_mgr), activity(act), env(jni) - { - auto assets = listAssets(""); - uint32_t index = 0; - for (auto& a : assets) - { - addItem(a, index, 0, EAT_VIRTUAL_ALLOC); - index++; - } - setFlagsVectorSize(m_files.size()); - } - core::smart_refctd_ptr readFile_impl(const SOpenFileParams& params) override - { - auto filename = params.filename; - AAsset* asset = AAssetManager_open(mgr, filename.c_str(), AASSET_MODE_BUFFER); - if (asset == nullptr) return nullptr; - const void* buffer = AAsset_getBuffer(asset); - size_t assetSize = AAsset_getLength(asset); - auto fileView = make_smart_refctd_ptr >(core::smart_refctd_ptr(m_system), params.absolutePath, IFile::ECF_READ, assetSize); - - fileView->write_impl(buffer, 0, assetSize); - AAsset_close(asset); - return fileView; - } - core::vector listAssets(const char* asset_path) override - { - core::vector result; - - auto context_object = activity->clazz; - auto getAssets_method = env->GetMethodID(env->GetObjectClass(context_object), "getAssets", "()Landroid/content/res/AssetManager;"); - auto assetManager_object = env->CallObjectMethod(context_object, getAssets_method); - auto list_method = env->GetMethodID(env->GetObjectClass(assetManager_object), "list", "(Ljava/lang/String;)[Ljava/lang/String;"); - - jstring path_object = env->NewStringUTF(asset_path); - - auto files_object = (jobjectArray)env->CallObjectMethod(assetManager_object, list_method, path_object); - - env->DeleteLocalRef(path_object); - - auto length = env->GetArrayLength(files_object); - - for (int i = 0; i < length; i++) - { - jstring jstr = (jstring)env->GetObjectArrayElement(files_object, i); - - const char* filename = env->GetStringUTFChars(jstr, nullptr); - - if (filename != nullptr) - { - if (std::string(asset_path) == "") - result.push_back(std::string(filename)); - else - result.push_back((std::filesystem::path(asset_path) / filename).generic_string()); - - env->ReleaseStringUTFChars(jstr, filename); - } - - env->DeleteLocalRef(jstr); - } - - return result; -} - -}; -} - - -#endif -#endif \ No newline at end of file diff --git a/include/nbl/system/CApplicationAndroid.h b/include/nbl/system/CApplicationAndroid.h index adbfe130f1..1075113b35 100644 --- a/include/nbl/system/CApplicationAndroid.h +++ b/include/nbl/system/CApplicationAndroid.h @@ -1,6 +1,8 @@ #ifndef _NBL_SYSTEM_C_APPLICATION_FRAMEWORK_ANDROID_H_INCLUDED_ #define _NBL_SYSTEM_C_APPLICATION_FRAMEWORK_ANDROID_H_INCLUDED_ + #ifdef _NBL_PLATFORM_ANDROID_ + #include "nbl/core/declarations.h" #include "nbl/system/CStdoutLoggerAndroid.h" #include "nbl/system/IApplicationFramework.h" @@ -135,4 +137,5 @@ namespace nbl::system } #endif + #endif \ No newline at end of file diff --git a/include/nbl/system/CFileArchive.h b/include/nbl/system/CFileArchive.h index 6a837ca054..fab1e48675 100644 --- a/include/nbl/system/CFileArchive.h +++ b/include/nbl/system/CFileArchive.h @@ -20,7 +20,8 @@ class CInnerArchiveFile : public CFileView { std::atomic_flag* alive; public: - CInnerArchiveFile(CFileView* arch, std::atomic_flag* _flag) : CFileView(std::move(*arch)), alive(_flag) + template + CInnerArchiveFile(std::atomic_flag* _flag, Args&&... args) : CFileView(std::forward(args)...), alive(_flag) { } ~CInnerArchiveFile() = default; @@ -28,18 +29,22 @@ class CInnerArchiveFile : public CFileView static void* operator new(size_t size) noexcept { assert(false); + exit(-0x45); return nullptr; } static void* operator new[](size_t size) noexcept { assert(false); + exit(-0x45); return nullptr; } - static void* operator new(size_t size, void* ptr, std::atomic_flag* alive) + static void* operator new(size_t size, void* ptr, std::atomic_flag* alive) noexcept { alive->test_and_set(); - return ::operator new(size, ptr); + return ::operator new(size,ptr); } + + // static void operator delete(void* ptr) noexcept { static_cast(ptr)->alive->clear(); @@ -48,6 +53,13 @@ class CInnerArchiveFile : public CFileView static void operator delete[](void* ptr) noexcept { assert(false); + exit(-0x45); + } + + // make compiler shut up about initizaliation throwing exceptions + static void operator delete(void* dummy, void* ptr, std::atomic_flag* alive) noexcept + { + ::operator delete(ptr); } }; @@ -66,7 +78,7 @@ class CFileArchive : public IFileArchive const auto* item = getItemFromPath(pathRelativeToArchive); if (!item) return nullptr; - /* + switch (item->allocatorType) { case EAT_NULL: @@ -81,7 +93,6 @@ class CFileArchive : public IFileArchive default: // directory or something break; } - */ return nullptr; } @@ -104,9 +115,9 @@ class CFileArchive : public IFileArchive _NBL_ALIGNED_FREE(m_filesBuffer); _NBL_ALIGNED_FREE(m_fileFlags); } - /* + template - core::smart_refctd_ptr> getFile_impl(const IFileArchive::SListEntry* item) + inline core::smart_refctd_ptr> getFile_impl(const IFileArchive::SListEntry* item) { auto* file = reinterpret_cast*>(m_filesBuffer+item->ID*SIZEOF_INNER_ARCHIVE_FILE); // NOTE: Intentionally calling grab() on maybe-not-existing object! @@ -114,18 +125,26 @@ class CFileArchive : public IFileArchive if (oldRefcount==0) // need to construct (previous refcount was 0) { + const auto fileBuffer = getFileBuffer(item); // Might have barged inbetween a refctr drop and finish of a destructor + delete, // need to wait for the "alive" flag to become `false` which tells us `operator delete` has finished. m_fileFlags[item->ID].wait(true); // coast is clear, do placement new new (file, &m_fileFlags[item->ID]) CInnerArchiveFile( - static_cast*>(readFile_impl(params).get()), - &m_fileFlags[item->ID] + m_fileFlags+item->ID, + getDefaultAbsolutePath()/item->pathRelativeToArchive, + IFile::ECF_READ, // TODO: stay like this until we allow write access to archived files + std::get(fileBuffer), + std::get(fileBuffer), + Allocator() // no archive uses stateful allocators yet ); } + // don't grab because we've already grabbed return core::smart_refctd_ptr>(file,core::dont_grab); } - */ + + // this function will return a buffer that needs to be deallocated with an allocator matching `item->allocatorType` + virtual std::pair getFileBuffer(const IFileArchive::SListEntry* item) = 0; std::atomic_flag* m_fileFlags = nullptr; std::byte* m_filesBuffer = nullptr; diff --git a/include/nbl/system/CFileView.h b/include/nbl/system/CFileView.h index 003cf90895..a66812c688 100644 --- a/include/nbl/system/CFileView.h +++ b/include/nbl/system/CFileView.h @@ -17,10 +17,6 @@ class IFileView : public IFile } protected: - IFileView(IFileView&& other) : IFile(path(other.getFileName()),other.getFlags()), m_buffer(other.m_buffer), m_size(other.m_size) - { - other.m_buffer = nullptr; - } IFileView(path&& _name, const core::bitflag _flags, void* buffer, size_t fileSize) : IFile(std::move(_name),_flags), m_buffer(buffer), m_size(fileSize) {} @@ -60,7 +56,6 @@ class CFileView : public IFileView } protected: - CFileView(CFileView&& other) : IFileView(std::move(other)), allocator(std::move(other.allocator)) {} ~CFileView() { if (m_buffer) @@ -81,9 +76,11 @@ class CFileView : public IFileView public: CFileView(path&& _name, const core::bitflag _flags, void* buffer, const size_t fileSize) : IFileView(std::move(_name),_flags,buffer,fileSize) {} + // the `_allocator` parameter is useless and unused but its necessary to have a uniform constructor signature across all specializations (saves us headaches in `CFileArchive`) + CFileView(path&& _name, const core::bitflag _flags, void* buffer, const size_t fileSize, CNullAllocator&& _allocator) : + CFileView(std::move(_name),_flags,buffer,fileSize) {} protected: - CFileView(CFileView&& other) : IFileView(std::move(other)) {} ~CFileView() = default; }; diff --git a/src/nbl/system/CAPKResourcesArchive.h b/src/nbl/system/CAPKResourcesArchive.h new file mode 100644 index 0000000000..c3af250ecf --- /dev/null +++ b/src/nbl/system/CAPKResourcesArchive.h @@ -0,0 +1,40 @@ +#ifndef _NBL_SYSTEM_C_APK_RESOURCES_ARCHIVE_LOADER_H_INCLUDED_ +#define _NBL_SYSTEM_C_APK_RESOURCES_ARCHIVE_LOADER_H_INCLUDED_ + + +#include "nbl/system/IFileArchive.h" + + +#ifdef _NBL_PLATFORM_ANDROID_ +struct AAssetManager; +struct JNIEnv; +struct ANativeActivity; + +namespace nbl::system +{ + +class CAPKResourcesArchive final : public CFileArchive +{ + public: + static core::smart_refctd_ptr create(); + + protected: + CAPKResourcesArchive( + path&& _path, system::logger_opt_smart_ptr&& logger, + AAssetManager* _mgr, ANativeActivity* act, JNIEnv* jni + ) : CFileArchive(std::move(_path),std::move(logger),std::move(_items)), + m_mgr(_mgr), m_activity(act), m_jniEnv(jni) + {} + + std::pair getFileBuffer(const IFileArchive::SListEntry* item) override; + + + AAssetManager* m_mgr; + JNIEnv* m_jniEnv; + ANativeActivity* m_activity; +}; + +} +#endif + +#endif \ No newline at end of file diff --git a/src/nbl/system/CArchiveLoaderTar.cpp b/src/nbl/system/CArchiveLoaderTar.cpp index 6f893a9250..9a21f018b0 100644 --- a/src/nbl/system/CArchiveLoaderTar.cpp +++ b/src/nbl/system/CArchiveLoaderTar.cpp @@ -41,19 +41,11 @@ struct STarHeader using namespace nbl; using namespace nbl::system; -/* -core::smart_refctd_ptr CArchiveLoaderTar::CArchive::readFile_impl(const SListEntry* item) +std::pair CArchiveLoaderTar::CArchive::getFileBuffer(const IFileArchive::SListEntry* item) { - uint8_t* buff = reinterpret_cast(m_file->getMappedPointer())+item->offset; - auto a = core::make_smart_refctd_ptr>( - core::smart_refctd_ptr(m_system), - params.absolutePath, - IFile::ECF_READ_WRITE, // TODO: this file cannot grow, unsure whether we should allow write access! - buff, - found->size); - return a; + assert(item->allocatorType==EAT_NULL); + return {reinterpret_cast(m_file->getMappedPointer())+item->offset,item->size}; } -*/ core::smart_refctd_ptr CArchiveLoaderTar::createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const { diff --git a/src/nbl/system/CArchiveLoaderTar.h b/src/nbl/system/CArchiveLoaderTar.h index 1a3aac9138..1336b61410 100644 --- a/src/nbl/system/CArchiveLoaderTar.h +++ b/src/nbl/system/CArchiveLoaderTar.h @@ -11,24 +11,26 @@ namespace nbl::system class CArchiveLoaderTar final : public IArchiveLoader { public: - class CArchive : public CFileArchive + class CArchive final : public CFileArchive { public: CArchive(core::smart_refctd_ptr&& _file, system::logger_opt_smart_ptr&& logger, core::vector&& _items) : CFileArchive(path(_file->getFileName()),std::move(logger),std::move(_items)), m_file(std::move(_file)) {} - // protected: + std::pair getFileBuffer(const IFileArchive::SListEntry* item) override; + core::smart_refctd_ptr m_file; }; CArchiveLoaderTar(system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(logger)) {} - virtual bool isALoadableFileFormat(IFile* file) const override + + inline bool isALoadableFileFormat(IFile* file) const override { return !!createArchive_impl(core::smart_refctd_ptr(file),""); } - const char** getAssociatedFileExtensions() const override + inline const char** getAssociatedFileExtensions() const override { static const char* ext[]{ "tar", nullptr }; return ext; From 6af9621995d9756bb84b518762ab7a8ec809e92d Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 09:41:35 +0100 Subject: [PATCH 65/91] allow stateful allocators to implement APK Archive file views Also bring TAR archive reader up to par with old impl. --- include/nbl/system/CFileArchive.h | 24 +++++-- include/nbl/system/CFileViewAPKAllocator.h | 23 +++++++ .../system/CFileViewVirtualAllocatorPOSIX.h | 2 + .../system/CFileViewVirtualAllocatorWin32.h | 2 + include/nbl/system/CSystemAndroid.h | 16 ++--- include/nbl/system/IFileArchive.h | 1 + include/nbl/system/IFileViewAllocator.h | 9 +++ source/Nabla/CTarReader.cpp | 50 --------------- src/nbl/CMakeLists.txt | 2 + src/nbl/system/CAPKResourcesArchive.cpp | 62 +++++++++++++++++++ src/nbl/system/CAPKResourcesArchive.h | 15 ++--- src/nbl/system/CArchiveLoaderTar.cpp | 56 +++++++++++++++-- src/nbl/system/CArchiveLoaderTar.h | 9 ++- src/nbl/system/CArchiveLoaderZip.h | 29 +++++---- src/nbl/system/CFileViewAPKAllocator.cpp | 21 +++++++ src/nbl/system/CSystemAndroid.cpp | 12 ++-- 16 files changed, 232 insertions(+), 101 deletions(-) create mode 100644 include/nbl/system/CFileViewAPKAllocator.h delete mode 100644 source/Nabla/CTarReader.cpp create mode 100644 src/nbl/system/CAPKResourcesArchive.cpp create mode 100644 src/nbl/system/CFileViewAPKAllocator.cpp diff --git a/include/nbl/system/CFileArchive.h b/include/nbl/system/CFileArchive.h index fab1e48675..fd19198c09 100644 --- a/include/nbl/system/CFileArchive.h +++ b/include/nbl/system/CFileArchive.h @@ -10,6 +10,9 @@ #include "nbl/system/CFileView.h" #include "nbl/system/IFileViewAllocator.h" +#ifdef _NBL_PLATFORM_ANDROID_ +#include "nbl/system/CFileViewAPKAllocator.h" +#endif namespace nbl::system { @@ -90,6 +93,13 @@ class CFileArchive : public IFileArchive case EAT_VIRTUAL_ALLOC: return getFile_impl(item); break; + case EAT_APK_ALLOCATOR: + #ifdef _NBL_PLATFORM_ANDROID_ + return getFile_impl(item); + #else + assert(false); + #endif + break; default: // directory or something break; } @@ -134,9 +144,9 @@ class CFileArchive : public IFileArchive m_fileFlags+item->ID, getDefaultAbsolutePath()/item->pathRelativeToArchive, IFile::ECF_READ, // TODO: stay like this until we allow write access to archived files - std::get(fileBuffer), - std::get(fileBuffer), - Allocator() // no archive uses stateful allocators yet + fileBuffer.buffer, + fileBuffer.size, + Allocator(fileBuffer.allocatorState) // no archive uses stateful allocators yet ); } // don't grab because we've already grabbed @@ -144,7 +154,13 @@ class CFileArchive : public IFileArchive } // this function will return a buffer that needs to be deallocated with an allocator matching `item->allocatorType` - virtual std::pair getFileBuffer(const IFileArchive::SListEntry* item) = 0; + struct file_buffer_t + { + void* buffer; + size_t size; + void* allocatorState; + }; + virtual file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) = 0; std::atomic_flag* m_fileFlags = nullptr; std::byte* m_filesBuffer = nullptr; diff --git a/include/nbl/system/CFileViewAPKAllocator.h b/include/nbl/system/CFileViewAPKAllocator.h new file mode 100644 index 0000000000..d62db72667 --- /dev/null +++ b/include/nbl/system/CFileViewAPKAllocator.h @@ -0,0 +1,23 @@ +#ifndef _NBL_SYSTEM_C_FILE_VIEW_APK_ALLOCATOR_H_INCLUDED_ +#define _NBL_SYSTEM_C_FILE_VIEW_APK_ALLOCATOR_H_INCLUDED_ + + +#include "nbl/system/IFileViewAllocator.h" + + +namespace nbl::system +{ +#ifdef _NBL_PLATFORM_ANDROID_ +class CFileViewAPKAllocator : public IFileViewAllocator +{ + public: + using IFileViewAllocator::IFileViewAllocator; + + // should never be called + void* alloc(size_t size) override; + bool dealloc(void* data, size_t size) override; +}; +#endif +} + +#endif \ No newline at end of file diff --git a/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h b/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h index 2100612884..8b0bf51e2e 100644 --- a/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h +++ b/include/nbl/system/CFileViewVirtualAllocatorPOSIX.h @@ -7,6 +7,8 @@ namespace nbl::system class CFileViewVirtualAllocatorPOSIX : public IFileViewAllocator { public: + using IFileViewAllocator::IFileViewAllocator; + void* alloc(size_t size) override; bool dealloc(void* data, size_t size) override; }; diff --git a/include/nbl/system/CFileViewVirtualAllocatorWin32.h b/include/nbl/system/CFileViewVirtualAllocatorWin32.h index dda0733f26..36b2366b82 100644 --- a/include/nbl/system/CFileViewVirtualAllocatorWin32.h +++ b/include/nbl/system/CFileViewVirtualAllocatorWin32.h @@ -7,6 +7,8 @@ namespace nbl::system class CFileViewVirtualAllocatorWin32 : public IFileViewAllocator { public: + using IFileViewAllocator::IFileViewAllocator; + void* alloc(size_t size) override; bool dealloc(void* data, size_t size) override; }; diff --git a/include/nbl/system/CSystemAndroid.h b/include/nbl/system/CSystemAndroid.h index 0dfcd71c89..8fc80064b3 100644 --- a/include/nbl/system/CSystemAndroid.h +++ b/include/nbl/system/CSystemAndroid.h @@ -4,27 +4,29 @@ #include "nbl/system/ISystem.h" - -namespace nbl::system -{ #ifdef _NBL_PLATFORM_ANDROID_ #include "nbl/system/ISystemPOSIX.h" struct ANativeActivity; struct JNIEnv; +namespace nbl::system +{ + class CSystemAndroid final : public ISystemPOSIX { - ANativeActivity* m_nativeActivity; - JNIEnv* m_jniEnv; public: - CSystemAndroid(ANativeActivity* activity, JNIEnv* jni, const system::path& APKResourcesPath); + CSystemAndroid(ANativeActivity* activity, JNIEnv* jni, const path& APKResourcesPath); // SystemInfo getSystemInfo() const override; + + protected: + ANativeActivity* m_nativeActivity; + JNIEnv* m_jniEnv; }; -#endif } +#endif #endif \ No newline at end of file diff --git a/include/nbl/system/IFileArchive.h b/include/nbl/system/IFileArchive.h index 9dbe5b2e02..68dbc02773 100644 --- a/include/nbl/system/IFileArchive.h +++ b/include/nbl/system/IFileArchive.h @@ -27,6 +27,7 @@ class IFileArchive : public core::IReferenceCounted EAT_NONE = 0, EAT_NULL, // read directly from archive's underlying mapped file EAT_VIRTUAL_ALLOC, // decompress to RAM (with sparse paging) + EAT_APK_ALLOCATOR, // specialization to be able to call `AAsset_close` EAT_MALLOC // decompress to RAM }; //! An entry in a list of items, can be a folder or a file. diff --git a/include/nbl/system/IFileViewAllocator.h b/include/nbl/system/IFileViewAllocator.h index 99e312fcb7..aedeb6320b 100644 --- a/include/nbl/system/IFileViewAllocator.h +++ b/include/nbl/system/IFileViewAllocator.h @@ -13,14 +13,21 @@ namespace nbl::system class IFileViewAllocator { public: + IFileViewAllocator(void* _state) : m_state(_state) {} + virtual void* alloc(size_t size) = 0; virtual bool dealloc(void* data, size_t size) = 0; + + protected: + void* m_state; }; // Regular old file in RAM class CPlainHeapAllocator : public IFileViewAllocator { public: + using IFileViewAllocator::IFileViewAllocator; + void* alloc(size_t size) override { return malloc(size); @@ -37,6 +44,8 @@ class CPlainHeapAllocator : public IFileViewAllocator class CNullAllocator : public IFileViewAllocator { public: + using IFileViewAllocator::IFileViewAllocator; + void* alloc(size_t size) override { return nullptr; diff --git a/source/Nabla/CTarReader.cpp b/source/Nabla/CTarReader.cpp deleted file mode 100644 index 76f1b9ab28..0000000000 --- a/source/Nabla/CTarReader.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//! Check if the file might be loaded by this class -/** Check might look into the file. -\param file File handle to check. -\return True if file seems to be loadable. */ -bool CArchiveLoaderTAR::isALoadableFileFormat(io::IReadFile* file) const -{ - // TAR files consist of blocks of 512 bytes - // if it isn't a multiple of 512 then it's not a TAR file. - if (file->getSize() % 512) - return false; - - const size_t prevPos = file->getPos(); - file->seek(0u); - - // read header of first file - STarHeader fHead; - file->read(&fHead, sizeof(STarHeader)); - file->seek(prevPos); - - uint32_t checksum = 0; - sscanf(fHead.Checksum, "%o", &checksum); - - // verify checksum - - // some old TAR writers assume that chars are signed, others assume unsigned - // USTAR archives have a longer header, old TAR archives end after linkname - - uint32_t checksum1=0; - int32_t checksum2=0; - - // remember to blank the checksum field! - memset(fHead.Checksum, ' ', 8); - - // old header - for (uint8_t* p = (uint8_t*)(&fHead); p < (uint8_t*)(&fHead.Magic[0]); ++p) - { - checksum1 += *p; - checksum2 += char(*p); - } - - if (!strncmp(fHead.Magic, "ustar", 5)) - { - for (uint8_t* p = (uint8_t*)(&fHead.Magic[0]); p < (uint8_t*)(&fHead) + sizeof(fHead); ++p) - { - checksum1 += *p; - checksum2 += char(*p); - } - } - return checksum1 == checksum || checksum2 == (int32_t)checksum; -} \ No newline at end of file diff --git a/src/nbl/CMakeLists.txt b/src/nbl/CMakeLists.txt index ee7b224fa4..4e96a42d27 100755 --- a/src/nbl/CMakeLists.txt +++ b/src/nbl/CMakeLists.txt @@ -200,11 +200,13 @@ set(NBL_SYSTEM_SOURCES ${NBL_ROOT_PATH}/src/nbl/system/ILogger.cpp ${NBL_ROOT_PATH}/src/nbl/system/CArchiveLoaderZip.cpp ${NBL_ROOT_PATH}/src/nbl/system/CArchiveLoaderTar.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CAPKResourcesArchive.cpp ${NBL_ROOT_PATH}/src/nbl/system/ISystem.cpp ${NBL_ROOT_PATH}/src/nbl/system/IFileArchive.cpp ${NBL_ROOT_PATH}/src/nbl/system/CStdoutLoggerAndroid.cpp ${NBL_ROOT_PATH}/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp ${NBL_ROOT_PATH}/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp + ${NBL_ROOT_PATH}/src/nbl/system/CFileViewAPKAllocator.cpp ${NBL_ROOT_PATH}/src/nbl/system/CFileWin32.cpp ${NBL_ROOT_PATH}/src/nbl/system/CFilePOSIX.cpp ${NBL_ROOT_PATH}/src/nbl/system/CSystemWin32.cpp diff --git a/src/nbl/system/CAPKResourcesArchive.cpp b/src/nbl/system/CAPKResourcesArchive.cpp new file mode 100644 index 0000000000..0d296fb4c6 --- /dev/null +++ b/src/nbl/system/CAPKResourcesArchive.cpp @@ -0,0 +1,62 @@ +#include "nbl/system/CAPKResourcesArchive.h" + +using namespace nbl; +using namespace nbl::system; + +#ifdef _NBL_PLATFORM_ANDROID_ +#include +#include + +CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jni) + : CFileArchive(path(_path),std::move(logger),computeItems(_path.string())), m_mgr(act->assetManager), m_activity(act), m_jniEnv(jni) +{ +} + +core::vector CAPKResourcesArchive::computeItems(const std::string& asset_path) +{ + auto context_object = activity->clazz; + auto getAssets_method = env->GetMethodID(env->GetObjectClass(context_object), "getAssets", "()Landroid/content/res/AssetManager;"); + auto assetManager_object = env->CallObjectMethod(context_object,getAssets_method); + auto list_method = env->GetMethodID(env->GetObjectClass(assetManager_object), "list", "(Ljava/lang/String;)[Ljava/lang/String;"); + + jstring path_object = env->NewStringUTF(asset_path.c_str()); + + auto files_object = (jobjectArray)env->CallObjectMethod(assetManager_object, list_method, path_object); + + env->DeleteLocalRef(path_object); + + auto length = env->GetArrayLength(files_object); + + core::vector result; + for (decltype(length) i=0; iGetObjectArrayElement(files_object,i); + + const char* filename = env->GetStringUTFChars(jstr,nullptr); + if (filename != nullptr) + { + auto& item = result.emplace_back(); + item.pathRelativeToArchive = filename; + { + AAsset* asset = AAssetManager_open(m_mgr,filename,AASSET_MODE_STREAMING); + item.size = AAsset_getLength(asset); + AAsset_close(asset); + } + item.offset = 0xdeadbeefu; + item.ID = i; + item.allocatorType = EAT_APK_ALLOCATOR; + + env->ReleaseStringUTFChars(jstr,filename); + } + + env->DeleteLocalRef(jstr); + } +} + +CFileArchive::file_buffer_t CAPKResourcesArchive::getFileBuffer(const IFileArchive::SListEntry* item) +{ + AAsset* asset = AAssetManager_open(m_mgr,item->pathRelativeToArchive.string().c_str(),AASSET_MODE_BUFFER); + return {AAsset_getBuffer(asset),AAsset_getLength(asset),asset}; +} + +#endif \ No newline at end of file diff --git a/src/nbl/system/CAPKResourcesArchive.h b/src/nbl/system/CAPKResourcesArchive.h index c3af250ecf..ea295b962e 100644 --- a/src/nbl/system/CAPKResourcesArchive.h +++ b/src/nbl/system/CAPKResourcesArchive.h @@ -16,17 +16,12 @@ namespace nbl::system class CAPKResourcesArchive final : public CFileArchive { public: - static core::smart_refctd_ptr create(); - - protected: - CAPKResourcesArchive( - path&& _path, system::logger_opt_smart_ptr&& logger, - AAssetManager* _mgr, ANativeActivity* act, JNIEnv* jni - ) : CFileArchive(std::move(_path),std::move(logger),std::move(_items)), - m_mgr(_mgr), m_activity(act), m_jniEnv(jni) - {} + CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jni); - std::pair getFileBuffer(const IFileArchive::SListEntry* item) override; + protected: + static core::vector computeItems(const std::string& asset_path); + + file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) override; AAssetManager* m_mgr; diff --git a/src/nbl/system/CArchiveLoaderTar.cpp b/src/nbl/system/CArchiveLoaderTar.cpp index 9a21f018b0..917a3bd543 100644 --- a/src/nbl/system/CArchiveLoaderTar.cpp +++ b/src/nbl/system/CArchiveLoaderTar.cpp @@ -41,10 +41,56 @@ struct STarHeader using namespace nbl; using namespace nbl::system; -std::pair CArchiveLoaderTar::CArchive::getFileBuffer(const IFileArchive::SListEntry* item) +CFileArchive::file_buffer_t CArchiveLoaderTar::CArchive::getFileBuffer(const IFileArchive::SListEntry* item) { assert(item->allocatorType==EAT_NULL); - return {reinterpret_cast(m_file->getMappedPointer())+item->offset,item->size}; + return {reinterpret_cast(m_file->getMappedPointer())+item->offset,item->size,nullptr}; +} + + +bool CArchiveLoaderTar::isALoadableFileFormat(IFile* file) const +{ + // TAR files consist of blocks of 512 bytes + // if it isn't a multiple of 512 then it's not a TAR file. + if (file->getSize()%BlockSize) + return false; + + STarHeader fHead; + IFile::success_t success; + file->read(success,&fHead,0ull,sizeof(fHead)); + if (!success) + return false; + + uint32_t checksum = 0; + sscanf(fHead.Checksum,"%o",&checksum); + + // verify checksum + + // some old TAR writers assume that chars are signed, others assume unsigned + // USTAR archives have a longer header, old TAR archives end after linkname + + uint32_t checksum1=0; + int32_t checksum2=0; + + // remember to blank the checksum field! + memset(fHead.Checksum, ' ', 8); + + // old header + for (uint8_t* p = (uint8_t*)(&fHead); p < (uint8_t*)(&fHead.Magic[0]); ++p) + { + checksum1 += *p; + checksum2 += char(*p); + } + + if (!strncmp(fHead.Magic, "ustar", 5)) + { + for (uint8_t* p = (uint8_t*)(&fHead.Magic[0]); p < (uint8_t*)(&fHead) + sizeof(fHead); ++p) + { + checksum1 += *p; + checksum2 += char(*p); + } + } + return checksum1 == checksum || checksum2 == (int32_t)checksum; } core::smart_refctd_ptr CArchiveLoaderTar::createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const @@ -106,10 +152,10 @@ core::smart_refctd_ptr CArchiveLoaderTar::createArchive_impl(core: m_logger.log("File %s is too large", ILogger::ELL_WARNING, fullPath.c_str()); // save start position - const uint32_t offset = pos + 512; + const uint32_t offset = pos + BlockSize; // move to next file header block - pos = offset + (size / 512) * 512 + ((size % 512) ? 512 : 0); + pos = offset + core::roundUp(size,BlockSize); // add file to list auto& item = items.emplace_back(); @@ -123,7 +169,7 @@ core::smart_refctd_ptr CArchiveLoaderTar::createArchive_impl(core: // TODO: ETLI_DIRECTORY, ETLI_LINK_TO_ARCHIVED_FILE default: // move to next block - pos += 512; + pos += BlockSize; break; } } diff --git a/src/nbl/system/CArchiveLoaderTar.h b/src/nbl/system/CArchiveLoaderTar.h index 1336b61410..c6b70829c9 100644 --- a/src/nbl/system/CArchiveLoaderTar.h +++ b/src/nbl/system/CArchiveLoaderTar.h @@ -18,17 +18,14 @@ class CArchiveLoaderTar final : public IArchiveLoader CFileArchive(path(_file->getFileName()),std::move(logger),std::move(_items)), m_file(std::move(_file)) {} protected: - std::pair getFileBuffer(const IFileArchive::SListEntry* item) override; + file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) override; core::smart_refctd_ptr m_file; }; CArchiveLoaderTar(system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(logger)) {} - inline bool isALoadableFileFormat(IFile* file) const override - { - return !!createArchive_impl(core::smart_refctd_ptr(file),""); - } + bool isALoadableFileFormat(IFile* file) const override; inline const char** getAssociatedFileExtensions() const override { @@ -37,6 +34,8 @@ class CArchiveLoaderTar final : public IArchiveLoader } private: + static constexpr size_t BlockSize = 512ull; + core::smart_refctd_ptr createArchive_impl(core::smart_refctd_ptr&& file, const std::string_view& password) const override; }; diff --git a/src/nbl/system/CArchiveLoaderZip.h b/src/nbl/system/CArchiveLoaderZip.h index 5e637c697e..5cc00c385d 100644 --- a/src/nbl/system/CArchiveLoaderZip.h +++ b/src/nbl/system/CArchiveLoaderZip.h @@ -20,8 +20,6 @@ namespace nbl::system while (scanGZipHeader(offset)) {} else while (scanZipHeader(offset)) {} - - setFlagsVectorSize(m_files.size()); } } @@ -63,22 +61,27 @@ class CArchiveLoaderZip final : public IArchiveLoader // extra field (variable size ) } PACK_STRUCT; #include "nbl/nblunpack.h" - class CArchive : public CFileArchive + class CArchive final : public CFileArchive { public: + CArchive( + core::smart_refctd_ptr&& _file, + system::logger_opt_smart_ptr&& logger, + core::vector&& _items, + core::vector&& _itemsMetadata, + const bool _isGZip + ) : CFileArchive(path(_file->getFileName()),std::move(logger),std::move(_items)), + m_file(std::move(_file)), m_itemsMetadata(std::move(_itemsMetadata)), + m_password(""), m_isGZip(_isGZip) + {} + private: - //! Contains extended info about zip files in the archive - struct SZipFileEntry - { - //! Position of data in the archive file - int32_t Offset; - //! The header for this file containing compression info etc - SZIPFileHeader header; - }; + file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) override; - const bool m_isGZip; - core::vector m_fileInfo; + core::smart_refctd_ptr m_file; + core::vector m_itemsMetadata; const std::string m_password; // TODO password + const bool m_isGZip; }; CArchiveLoaderZip(system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(logger)) {} diff --git a/src/nbl/system/CFileViewAPKAllocator.cpp b/src/nbl/system/CFileViewAPKAllocator.cpp new file mode 100644 index 0000000000..bb7c6bbaf5 --- /dev/null +++ b/src/nbl/system/CFileViewAPKAllocator.cpp @@ -0,0 +1,21 @@ +#include "nbl/system/CFileViewAPKAllocator.h" + +using namespace nbl::system; + +#ifdef _NBL_PLATFORM_ANDROID_ +#include +#include + +void* CFileViewAPKAllocator::alloc(size_t size) +{ + assert(false); + exit(-0x45); + return nullptr; +} + +bool CFileViewAPKAllocator::dealloc(void* data, size_t size) +{ + AAsset_close(reinterpret_cast(m_state)); + return true; +} +#endif \ No newline at end of file diff --git a/src/nbl/system/CSystemAndroid.cpp b/src/nbl/system/CSystemAndroid.cpp index 4bce37c980..6f269eff4f 100644 --- a/src/nbl/system/CSystemAndroid.cpp +++ b/src/nbl/system/CSystemAndroid.cpp @@ -14,16 +14,14 @@ using namespace nbl::system; #include #include -CSystemAndroid::CSystemAndroid(ANativeActivity* activity, JNIEnv* jni, const system::path& APKResourcesPath) : +CSystemAndroid::CSystemAndroid(ANativeActivity* activity, JNIEnv* jni, const path& APKResourcesPath) : ISystemPOSIX(), m_nativeActivity(activity), m_jniEnv(jni) { - addArchiveLoader(core::make_smart_refctd_ptr(core::smart_refctd_ptr(this), nullptr)); m_cachedArchiveFiles.insert(APKResourcesPath,core::make_smart_refctd_ptr( - core::smart_refctd_ptr(this), - nullptr, - activity->assetManager, - nativeActivity, - env + path(APKResourcesPath), + nullptr, // for now no logger + m_nativeActivity, + m_jniEnv )); } From 69e5092714537d018ceb91ad2c3eb2a1594c513d Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 10:02:17 +0100 Subject: [PATCH 66/91] small fixes for Android --- include/nbl/system/CSystemAndroid.h | 4 +++- src/nbl/system/CAPKResourcesArchive.h | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/nbl/system/CSystemAndroid.h b/include/nbl/system/CSystemAndroid.h index 8fc80064b3..5564409501 100644 --- a/include/nbl/system/CSystemAndroid.h +++ b/include/nbl/system/CSystemAndroid.h @@ -7,8 +7,10 @@ #ifdef _NBL_PLATFORM_ANDROID_ #include "nbl/system/ISystemPOSIX.h" +#include + + struct ANativeActivity; -struct JNIEnv; namespace nbl::system { diff --git a/src/nbl/system/CAPKResourcesArchive.h b/src/nbl/system/CAPKResourcesArchive.h index ea295b962e..4160b8ce29 100644 --- a/src/nbl/system/CAPKResourcesArchive.h +++ b/src/nbl/system/CAPKResourcesArchive.h @@ -2,12 +2,13 @@ #define _NBL_SYSTEM_C_APK_RESOURCES_ARCHIVE_LOADER_H_INCLUDED_ -#include "nbl/system/IFileArchive.h" - +#include "nbl/system/CFileArchive.h" #ifdef _NBL_PLATFORM_ANDROID_ +#include + + struct AAssetManager; -struct JNIEnv; struct ANativeActivity; namespace nbl::system From 30be602221cacf4bd0dafdb12cabc3dcb474cd3b Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 12:27:08 +0100 Subject: [PATCH 67/91] ZIP Loader rewrite is painful, but figured out what `CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFileArchive::SListEntry* item)` should look like --- include/nbl/system/IFile.h | 4 + include/nbl/system/ISystem.h | 4 +- source/Nabla/CZipReader.cpp | 104 ---- src/nbl/system/CAPKResourcesArchive.cpp | 2 +- src/nbl/system/CArchiveLoaderZip.cpp | 726 +++++++++++------------- src/nbl/system/CArchiveLoaderZip.h | 35 +- src/nbl/system/CSystemAndroid.cpp | 1 - src/nbl/system/ISystem.cpp | 2 +- 8 files changed, 333 insertions(+), 545 deletions(-) delete mode 100644 source/Nabla/CZipReader.cpp diff --git a/include/nbl/system/IFile.h b/include/nbl/system/IFile.h index 6f4c9ea9fe..378a39bd9e 100644 --- a/include/nbl/system/IFile.h +++ b/include/nbl/system/IFile.h @@ -46,6 +46,7 @@ class IFile : public IFileBase, private ISystem::IFutureManipulator public: success_t() = default; ~success_t() = default; + inline explicit operator bool() { return m_internalFuture.get()==sizeToProcess; @@ -54,6 +55,9 @@ class IFile : public IFileBase, private ISystem::IFutureManipulator { return m_internalFuture.get()!=sizeToProcess; } + + inline size_t getSizeToProcess() const {return sizeToProcess;} + private: friend IFile; ISystem::future_t m_internalFuture; diff --git a/include/nbl/system/ISystem.h b/include/nbl/system/ISystem.h index 98278babd7..afebfafbe7 100644 --- a/include/nbl/system/ISystem.h +++ b/include/nbl/system/ISystem.h @@ -21,6 +21,8 @@ class ISystemFile; class ISystem : public core::IReferenceCounted { + public: + inline static constexpr uint32_t MAX_FILENAME_LENGTH = 4096; protected: class ICaller; private: @@ -38,8 +40,6 @@ class ISystem : public core::IReferenceCounted }; struct SRequestParams_CREATE_FILE : SRequestParamsBase { - inline static constexpr uint32_t MAX_FILENAME_LENGTH = 4096; - char filename[MAX_FILENAME_LENGTH] {}; IFileBase::E_CREATE_FLAGS flags; }; diff --git a/source/Nabla/CZipReader.cpp b/source/Nabla/CZipReader.cpp deleted file mode 100644 index 53a0b95b18..0000000000 --- a/source/Nabla/CZipReader.cpp +++ /dev/null @@ -1,104 +0,0 @@ -//! scans for a local header, returns false if there is no more local file header. -//! The gzip file format seems to think that there can be multiple files in a gzip file -//! but none -bool CZipReader::scanGZipHeader() -{ - SZipFileEntry entry; - entry.Offset = 0; - memset(&entry.header, 0, sizeof(SZIPFileHeader)); - - // read header - SGZIPMemberHeader header; - if (File->read(&header, sizeof(SGZIPMemberHeader)) == sizeof(SGZIPMemberHeader)) - { - // check header value - if (header.sig != 0x8b1f) - return false; - - // now get the file info - if (header.flags & EGZF_EXTRA_FIELDS) - { - // read lenth of extra data - uint16_t dataLen; - - File->read(&dataLen, 2); - - // skip it - File->seek(dataLen, true); - } - - std::filesystem::path ZipFileName = ""; - - if (header.flags & EGZF_FILE_NAME) - { - char c; - File->read(&c, 1); - while (c) - { - ZipFileName += c; - File->read(&c, 1); - } - } - else - { - // no file name? - ZipFileName = Path; - core::deletePathFromFilename(ZipFileName); - - // rename tgz to tar or remove gz extension - if (core::hasFileExtension(ZipFileName, "tgz")) - { - ZipFileName.string()[ ZipFileName.string().size() - 2] = 'a'; - ZipFileName.string()[ ZipFileName.string().size() - 1] = 'r'; - } - else if (core::hasFileExtension(ZipFileName, "gz")) - { - ZipFileName.string()[ ZipFileName.string().size() - 3] = 0; - } - } - - if (header.flags & EGZF_COMMENT) - { - char c='a'; - while (c) - File->read(&c, 1); - } - - if (header.flags & EGZF_CRC16) - File->seek(2, true); - - // we are now at the start of the data blocks - entry.Offset = File->getPos(); - - entry.header.FilenameLength = ZipFileName.string().length(); - - entry.header.CompressionMethod = header.compressionMethod; - entry.header.DataDescriptor.CompressedSize = (File->getSize() - 8) - File->getPos(); - - // seek to file end - File->seek(entry.header.DataDescriptor.CompressedSize, true); - - // read CRC - File->read(&entry.header.DataDescriptor.CRC32, 4); - // read uncompressed size - File->read(&entry.header.DataDescriptor.UncompressedSize, 4); - - // now we've filled all the fields, this is just a standard deflate block - addItem(ZipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, false, 0); - FileInfo.push_back(entry); - } - - // there's only one block of data in a gzip file - return false; -} - - -#ifdef _NBL_COMPILE_WITH_LZMA_ -//! Used for LZMA decompression. The lib has no default memory management -namespace -{ - void *SzAlloc(void *p, size_t size) { p = p; return _NBL_ALIGNED_MALLOC(size,_NBL_SIMD_ALIGNMENT); } - void SzFree(void *p, void *address) { p = p; _NBL_ALIGNED_FREE(address); } - ISzAlloc lzmaAlloc = { SzAlloc, SzFree }; -} -#endif \ No newline at end of file diff --git a/src/nbl/system/CAPKResourcesArchive.cpp b/src/nbl/system/CAPKResourcesArchive.cpp index 0d296fb4c6..13fb9f79a8 100644 --- a/src/nbl/system/CAPKResourcesArchive.cpp +++ b/src/nbl/system/CAPKResourcesArchive.cpp @@ -5,7 +5,7 @@ using namespace nbl::system; #ifdef _NBL_PLATFORM_ANDROID_ #include -#include +#include CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jni) : CFileArchive(path(_path),std::move(logger),computeItems(_path.string())), m_mgr(act->assetManager), m_activity(act), m_jniEnv(jni) diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index 1ff11425ec..367c49df3d 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -1,3 +1,4 @@ +#include "nbl/system/IFileViewAllocator.h" #include "nbl/system/CArchiveLoaderZip.h" @@ -94,162 +95,140 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: { if (!file) return nullptr; -/* - core::smart_refctd_ptr archive = nullptr; - if (file.get()) - { - uint16_t sig; - { - system::future fut; - file->read(fut, &sig, 0, 2); - fut.get(); - } - bool isGZip = (sig == 0x8b1f); - archive = core::make_smart_refctd_ptr(std::move(file), core::smart_refctd_ptr(m_system), isGZip, password); + uint16_t sig; + { + IFile::success_t success; + file->read(success,&sig,0,sizeof(sig)); + if (!success) + return nullptr; } - return archive; -*/ - return nullptr; -} -#if 0 -bool CFileArchiveZip::scanGZipHeader(size_t& offset) -{ - SZipFileEntry entry; - entry.Offset = 0; - memset(&entry.header, 0, sizeof(SZIPFileHeader)); - - SGZIPMemberHeader header; - system::future headerFuture; - m_file->read(headerFuture, &header, offset, sizeof(SGZIPMemberHeader)); - headerFuture.get(); - offset += sizeof(SGZIPMemberHeader); - if (headerFuture.get() == sizeof(SGZIPMemberHeader)) + core::vector items; + core::vector itemsMetadata; + // load file entries { - // check header value - if (header.sig != 0x8b1f) - return false; - // now get the file info - if (header.flags & EGZF_EXTRA_FIELDS) + const bool isGZip = sig==0x8b1fu; + size_t offset = 0ull; + std::string filename; + filename.reserve(ISystem::MAX_FILENAME_LENGTH); + while (true) { - // read lenth of extra data - uint16_t dataLen; + SZIPFileHeader header; + memset(&header,0,sizeof(SZIPFileHeader)); - system::future lenFuture; - m_file->read(lenFuture, &dataLen, offset, 2); - lenFuture.get(); - offset += 2; // TODO: I think it should be `+= dataLen;` - } - std::filesystem::path zipFileName = ""; - if (header.flags & EGZF_FILE_NAME) - { - char c; - { - system::future fut; - m_file->read(fut, &c, offset++, 1); - fut.get(); - } - while (c) - { - zipFileName += c; - system::future fut; - m_file->read(fut, &c, offset++, 1); - fut.get(); - } - } - else - { - // no file name? - zipFileName = m_file->getFileName().filename(); + const auto& zipHeader = header; + static_assert(sizeof(SGZIPMemberHeader)(header); - // rename tgz to tar or remove gz extension - if (zipFileName.extension() == ".tgz") - { - zipFileName.string()[zipFileName.string().size() - 2] = 'a'; - zipFileName.string()[zipFileName.string().size() - 1] = 'r'; - } - else if (zipFileName.extension() == ".gz") - { - zipFileName.string()[zipFileName.string().size() - 3] = 0; - } - } - if (header.flags & EGZF_COMMENT) - { - char c = 'a'; - while (c) + IFile::success_t headerReadSuccess; + file->read(headerReadSuccess,&header,offset,isGZip ? sizeof(SGZIPMemberHeader):sizeof(header)); + if (!headerReadSuccess) + break; + offset += headerReadSuccess.getSizeToProcess(); + + IFileArchive::SListEntry item; + if (isGZip) { - system::future fut; - m_file->read(fut, &c, offset++, 1); - fut.get(); + //! The gzip file format seems to think that there can be multiple files in a gzip file + //! TODO: But OLD Irrlicht Impl doesn't honor it!? + if (gzipHeader.sig!=0x8b1fu) + break; + + // now get the file info + if (gzipHeader.flags&EGZF_EXTRA_FIELDS) + { + // read lenth of extra data + uint16_t dataLen; + IFile::success_t success; + file->read(success,&dataLen,offset,sizeof(dataLen)); + if (!success) + break; + offset += success.getSizeToProcess(); + // skip the extra data + offset += dataLen; + } + // + filename.clear(); + if (gzipHeader.flags&EGZF_FILE_NAME) + { + char c = 0x45; // make sure we start with non-zero char + while (c) + { + IFile::success_t success; + file->read(success,&c,offset,sizeof(c)); + if (!success) + break; + offset += success.getSizeToProcess(); + filename.push_back(c); + } + // if string is not null terminated, something went wrong reading the file + if (c) + break; + } + // + if (gzipHeader.flags&EGZF_COMMENT) + { + char c = 0x45; // make sure we start with non-zero char + while (c) + { + IFile::success_t success; + file->read(success,&c,offset,sizeof(c)); + if (!success) + break; + offset += success.getSizeToProcess(); + } + // if string is not null terminated, something went wrong reading the file + if (c) + break; + } + // skip crc16 + if (gzipHeader.flags&EGZF_CRC16) + offset += 2; + + header.FilenameLength = filename.length(); + header.CompressionMethod = gzipHeader.compressionMethod; + header.DataDescriptor.CompressedSize = file->getSize()-(offset+sizeof(uint64_t)); + + item.offset = offset; + + offset += header.DataDescriptor.CompressedSize; + // read CRC + { + IFile::success_t success; + file->read(success,&header.DataDescriptor.CRC32,offset,sizeof(header.DataDescriptor.CRC32)); + if (!success) + break; + offset += success.getSizeToProcess(); + } + // read uncompressed size + { + IFile::success_t success; + file->read(success,&header.DataDescriptor.UncompressedSize,offset,sizeof(header.DataDescriptor.UncompressedSize)); + if (!success) + break; + offset += success.getSizeToProcess(); + item.size = header.DataDescriptor.UncompressedSize; + } } - } - if (header.flags & EGZF_CRC16) - offset += 2; - - entry.Offset = offset; - entry.header.FilenameLength = zipFileName.native().length(); - entry.header.CompressionMethod = header.compressionMethod; - entry.header.DataDescriptor.CompressedSize = (m_file->getSize() - 8) - offset; - - offset += entry.header.DataDescriptor.CompressedSize; - - // read CRC - { - system::future fut; - m_file->read(fut, &entry.header.DataDescriptor.CRC32, offset, 4); - fut.get(); - offset += 4; - } - // read uncompressed size - { - system::future fut; - m_file->read(fut, &entry.header.DataDescriptor.UncompressedSize, offset, 4); - fut.get(); - offset += 4; - } - - addItem(zipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, getAllocatorType(entry.header.CompressionMethod), 0); - m_fileInfo.push_back(entry); - } - return false; -} - -bool CFileArchiveZip::scanZipHeader(size_t& offset, bool ignoreGPBits) -{ - std::filesystem::path ZipFileName = ""; - SZipFileEntry entry; - entry.Offset = 0; - memset(&entry.header, 0, sizeof(SZIPFileHeader)); - - { - system::future fut; - m_file->read(fut, &entry.header, offset, sizeof(SZIPFileHeader)); - fut.get(); - offset += sizeof(SZIPFileHeader); - } - - if (entry.header.Sig != 0x04034b50) - return false; // local file headers end here. + else + { if (zipHeader.Sig!=0x04034b50u) + break; - // read filename - { - char* tmp = new char[entry.header.FilenameLength + 2]; - { - system::future fut; - m_file->read(fut, tmp, offset, entry.header.FilenameLength); - fut.get(); - offset += entry.header.FilenameLength; - } - tmp[entry.header.FilenameLength] = 0; - ZipFileName = tmp; - delete[] tmp; - } + filename.resize(zipHeader.FilenameLength); + { + IFile::success_t success; + file->read(success,filename.data(),offset,zipHeader.FilenameLength); + if (!success) + break; + offset += success.getSizeToProcess(); + } -#ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ - // AES encryption - if ((entry.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (entry.header.CompressionMethod == 99)) - { + // AES encryption + if ((header.GeneralBitFlag&ZIP_FILE_ENCRYPTED) && (header.CompressionMethod==99)) + { +/*/ + #ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ int16_t restSize = entry.header.ExtraFieldLength; SZipFileExtraHeader extraHeader; while (restSize) @@ -284,13 +263,47 @@ bool CFileArchiveZip::scanZipHeader(size_t& offset, bool ignoreGPBits) break; } } + } + #else +*/ + break; // no support, can't decrypt +// #endif + } + else + offset += header.ExtraFieldLength; + + + + + + + item.offset = offset; + // move forward length of data + offset += zipHeader.DataDescriptor.CompressedSize; + } + + // we need to have a filename or we skip + if (filename.empty()) + continue; + + item.pathRelativeToArchive = filename; + item.ID = items.size(); + item.allocatorType = header.CompressionMethod ? IFileArchive::EAT_VIRTUAL_ALLOC:IFileArchive::EAT_NULL; + items.push_back(item); + itemsMetadata.push_back(header); } } - // move forward length of extra field. - else -#endif - if (entry.header.ExtraFieldLength) - offset += entry.header.ExtraFieldLength; + + assert(items.size()==itemsMetadata.size()); + if (items.empty()) + return nullptr; + + return core::make_smart_refctd_ptr(std::move(file),core::smart_refctd_ptr(m_logger.get()),std::move(items),std::move(itemsMetadata)); +} + +#if 0 +bool CFileArchiveZip::scanZipHeader(size_t& offset, bool ignoreGPBits) +{ // if bit 3 was set, use CentralDirectory for setup if (!ignoreGPBits && entry.header.GeneralBitFlag & ZIP_INFO_IN_DATA_DESCRIPTOR) @@ -345,13 +358,6 @@ bool CFileArchiveZip::scanZipHeader(size_t& offset, bool ignoreGPBits) while (scanCentralDirectoryHeader(offset)) {} return false; } - entry.Offset = offset; - // move forward length of data - offset += entry.header.DataDescriptor.CompressedSize; - - addItem(ZipFileName, entry.Offset, entry.header.DataDescriptor.UncompressedSize, getAllocatorType(entry.header.CompressionMethod), m_fileInfo.size()); - m_fileInfo.push_back(entry); - return true; } bool CFileArchiveZip::scanCentralDirectoryHeader(size_t& offset) @@ -381,41 +387,17 @@ bool CFileArchiveZip::scanCentralDirectoryHeader(size_t& offset) core::smart_refctd_ptr CFileArchiveZip::readFile_impl(const SOpenFileParams& params) { - size_t readOffset; - auto found = std::find_if(m_files.begin(), m_files.end(), [¶ms](const SFileListEntry& entry) { return params.filename == entry.fullName; }); - if (found != m_files.end()) - { const SZipFileEntry& e = m_fileInfo[found->ID]; wchar_t buf[64]; - // Nabla supports 0, 8, 12, 14, 99 - //0 - The file is stored (no compression) - //1 - The file is Shrunk - //2 - The file is Reduced with compression factor 1 - //3 - The file is Reduced with compression factor 2 - //4 - The file is Reduced with compression factor 3 - //5 - The file is Reduced with compression factor 4 - //6 - The file is Imploded - //7 - Reserved for Tokenizing compression algorithm - //8 - The file is Deflated - //9 - Reserved for enhanced Deflating - //10 - PKWARE Date Compression Library Imploding - //12 - bzip2 - Compression Method from libbz2, WinZip 10 - //14 - LZMA - Compression Method, WinZip 12 - //96 - Jpeg compression - Compression Method, WinZip 12 - //97 - WavPack - Compression Method, WinZip 11 - //98 - PPMd - Compression Method, WinZip 10 - //99 - AES encryption, WinZip 9 - int16_t actualCompressionMethod = e.header.CompressionMethod; - //TODO: CFileView factory - // CFileViewVirtualAllocatorWin32 - // @sadiuk WTF!? You hand out a new file every time!? - core::smart_refctd_ptr> decrypted = nullptr; + uint8_t* decryptedBuf = 0; uint32_t decryptedSize = e.header.DataDescriptor.CompressedSize; #ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ if ((e.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (e.header.CompressionMethod == 99)) { + size_t readOffset; + uint8_t salt[16] = { 0 }; const uint16_t saltSize = (((e.header.Sig & 0x00ff0000) >> 16) + 1) * 4; { @@ -510,260 +492,198 @@ core::smart_refctd_ptr CFileArchiveZip::readFile_impl(const SOpenFilePara #endif } #endif - switch (actualCompressionMethod) +} +#endif + +CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFileArchive::SListEntry* item) +{ + CFileArchive::file_buffer_t retval = {nullptr,item->size,nullptr}; + + // Nabla supports 0, 8, 12, 14, 99 + //0 - The file is stored (no compression) + //1 - The file is Shrunk + //2 - The file is Reduced with compression factor 1 + //3 - The file is Reduced with compression factor 2 + //4 - The file is Reduced with compression factor 3 + //5 - The file is Reduced with compression factor 4 + //6 - The file is Imploded + //7 - Reserved for Tokenizing compression algorithm + //8 - The file is Deflated + //9 - Reserved for enhanced Deflating + //10 - PKWARE Date Compression Library Imploding + //12 - bzip2 - Compression Method from libbz2, WinZip 10 + //14 - LZMA - Compression Method, WinZip 12 + //96 - Jpeg compression - Compression Method, WinZip 12 + //97 - WavPack - Compression Method, WinZip 11 + //98 - PPMd - Compression Method, WinZip 10 + //99 - AES encryption, WinZip 9 + int16_t actualCompressionMethod = m_itemsMetadata[item->ID].CompressionMethod; + + // + void* decrypted = nullptr; + size_t decryptedSize = 0ull; + auto freeOnFail = core::makeRAIIExiter([&actualCompressionMethod,&retval,&decrypted,&decryptedSize](){ + if (decrypted && retval.buffer!=decrypted) { - case 0: // no compression + if (actualCompressionMethod) + CPlainHeapAllocator(nullptr).dealloc(decrypted,decryptedSize); + else + VirtualMemoryAllocator(nullptr).dealloc(decrypted,decryptedSize); + } + }); + // + void* decompressed = nullptr; + auto freeMMappedOnFail = core::makeRAIIExiter([item,&retval,&decompressed](){ + if (decompressed && retval.buffer!=decompressed) + VirtualMemoryAllocator(nullptr).dealloc(decompressed,item->size); + }); + + const auto* const cFile = m_file.get(); + void* const filePtr = const_cast(cFile->getMappedPointer()); + std::byte* const mmapPtr = reinterpret_cast(filePtr)+item->offset; + + // decrypt + if (false) + { + if (actualCompressionMethod) + decrypted = CPlainHeapAllocator(nullptr).alloc(decryptedSize); + else + decrypted = VirtualMemoryAllocator(nullptr).alloc(decryptedSize); + } + // + if (actualCompressionMethod) + { + // TODO + //const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; + decompressed = VirtualMemoryAllocator(nullptr).alloc(item->size); + if (!decompressed) { - delete[] decryptedBuf; + m_logger.log("Not enough memory for decompressing %s",ILogger::ELL_ERROR,item->pathRelativeToArchive.string().c_str()); + return retval; + } + } + switch (actualCompressionMethod) + { + case 0: // no compression if (decrypted) - return decrypted; + retval.buffer = decrypted; else - { - uint8_t* buff = (uint8_t*)m_file->getMappedPointer() + e.Offset; - auto a = core::make_smart_refctd_ptr>( - core::smart_refctd_ptr(m_system), - params.absolutePath, - IFile::ECF_READ_WRITE, // TODO: should be READONLY - buff, - decryptedSize); - return a; - } - } + retval.buffer = mmapPtr; + break; case 8: { -#ifdef _NBL_COMPILE_WITH_ZLIB_ - - const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[uncompressedSize]; - if (!pBuf) - { - delete[] decryptedBuf; - // TODO: log error - return 0; - } - - uint8_t* pcData = decryptedBuf; - if (!pcData) - { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - delete[] decryptedBuf; - delete[] pBuf; - // TODO: log error - return 0; - } - - //memset(pcData, 0, decryptedSize); - readOffset = e.Offset; - { - read_blocking(m_file.get(), pcData, readOffset, decryptedSize); - readOffset += decryptedSize; - } - } - + #ifdef _NBL_COMPILE_WITH_ZLIB_ // Setup the inflate stream. z_stream stream; - int32_t err; - - stream.next_in = (Bytef*)pcData; + stream.next_in = (Bytef*)(decrypted ? decrypted:mmapPtr); stream.avail_in = (uInt)decryptedSize; - stream.next_out = (Bytef*)pBuf; - stream.avail_out = uncompressedSize; + stream.next_out = (Bytef*)decompressed; + stream.avail_out = item->size; stream.zalloc = (alloc_func)0; stream.zfree = (free_func)0; // Perform inflation. wbits < 0 indicates no zlib header inside the data. - err = inflateInit2(&stream, -MAX_WBITS); - if (err == Z_OK) + int32_t err = inflateInit2(&stream, -MAX_WBITS); + if (err==Z_OK) { - err = inflate(&stream, Z_FINISH); + err = inflate(&stream,Z_FINISH); inflateEnd(&stream); - if (err == Z_STREAM_END) + if (err==Z_STREAM_END) err = Z_OK; err = Z_OK; inflateEnd(&stream); } - if (!decrypted) - delete[] pcData; - - delete[] decryptedBuf; - if (err != Z_OK) - { - delete[] pBuf; - // TODO: log error - return 0; - } - else - { - auto ret = core::make_smart_refctd_ptr>( - core::smart_refctd_ptr(m_system), - params.absolutePath, - IFile::ECF_READ_WRITE, // TODO: readonly! - uncompressedSize); - { - write_blocking(ret.get(), pBuf, 0, uncompressedSize); - } - delete[] pBuf; - return ret; - } - -#else - return 0; // zlib not compiled, we cannot decompress the data. -#endif + if (err==Z_OK) + retval.buffer = decompressed; + #else + m_logger.log("ZLIB decompression not supported. File cannot be read.",ILogger::ELL_ERROR); + #endif + break; } case 12: { -#ifdef _NBL_COMPILE_WITH_BZIP2_ - - const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[uncompressedSize]; - if (!pBuf) - { - m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] decryptedBuf; - return 0; - } - - uint8_t* pcData = decryptedBuf; - if (!pcData) - { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] pBuf; - delete[] decryptedBuf; - return 0; - } - - { - readOffset = e.Offset; - read_blocking(m_file.get(), pcData, readOffset, decryptedSize); - readOffset += decryptedSize; - } - } - + #ifdef _NBL_COMPILE_WITH_BZIP2_ bz_stream bz_ctx = { 0 }; - /* use BZIP2's default memory allocation - bz_ctx->bzalloc = NULL; - bz_ctx->bzfree = NULL; - bz_ctx->opaque = NULL; - */ - int err = BZ2_bzDecompressInit(&bz_ctx, 0, 0); /* decompression */ - if (err != BZ_OK) - { - m_logger.log("bzip2 decompression failed. File cannot be read.", ILogger::ELL_ERROR); - delete[] decryptedBuf; - return 0; - } - bz_ctx.next_in = (char*)pcData; - bz_ctx.avail_in = decryptedSize; - /* pass all input to decompressor */ - bz_ctx.next_out = pBuf; - bz_ctx.avail_out = uncompressedSize; - err = BZ2_bzDecompress(&bz_ctx); - err = BZ2_bzDecompressEnd(&bz_ctx); - - if (!decrypted) - delete[] pcData; - - if (err != BZ_OK) - { - m_logger.log("Error decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] pBuf; - delete[] decryptedBuf; - return 0; - } - else - { - auto ret = core::make_smart_refctd_ptr>(std::move(m_system), found->fullName, IFile::ECF_READ_WRITE, uncompressedSize); // TODO: readonly - { - write_blocking(decrypted.get(), pBuf, 0, uncompressedSize); // huh!? - } - delete[] pBuf; - return ret; - } - -#else - delete[] decryptedBuf; + // use BZIP2's default memory allocation + //bz_ctx->bzalloc = NULL; + //bz_ctx->bzfree = NULL; + //bz_ctx->opaque = NULL; + int err = BZ2_bzDecompressInit(&bz_ctx, 0, 0); + if (err==BZ_OK) + { + bz_ctx.next_in = (char*)(decrypted ? decrypted:mmapPtr); + bz_ctx.avail_in = decryptedSize; + bz_ctx.next_out = (char*)decompressed; + bz_ctx.avail_out = item->size; + err = BZ2_bzDecompress(&bz_ctx); + err = BZ2_bzDecompressEnd(&bz_ctx); + } + + if (err==BZ_OK) + retval.buffer = decompressed; + #else m_logger.log("bzip2 decompression not supported. File cannot be read.", ILogger::ELL_ERROR); - return 0; -#endif + #endif + break; } case 14: { -#ifdef _NBL_COMPILE_WITH_LZMA_ - uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; - char* pBuf = new char[uncompressedSize]; - if (!pBuf) - { - m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.c_str()); - delete[] decryptedBuf; - return 0; - } - - uint8_t* pcData = decryptedBuf; - if (!pcData) - { - pcData = new uint8_t[decryptedSize]; - if (!pcData) - { - m_logger.log("Not enough memory for decompressing %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] pBuf; - return 0; - } - - //memset(pcData, 0, decryptedSize); - readOffset = e.Offset; - { - read_blocking(m_file.get(), pcData, readOffset, decryptedSize); - readOffset += decryptedSize; - } - } - + #ifdef _NBL_COMPILE_WITH_LZMA_ ELzmaStatus status; - SizeT tmpDstSize = uncompressedSize; + SizeT tmpDstSize = item->size; SizeT tmpSrcSize = decryptedSize; - unsigned int propSize = (pcData[3] << 8) + pcData[2]; - int err = LzmaDecode((Byte*)pBuf, &tmpDstSize, - pcData + 4 + propSize, &tmpSrcSize, - pcData + 4, propSize, - e.header.GeneralBitFlag & 0x1 ? LZMA_FINISH_END : LZMA_FINISH_ANY, &status, - &lzmaAlloc); - uncompressedSize = tmpDstSize; // may be different to expected value - - if (!decrypted) - delete[] pcData; - - delete[] decryptedBuf; - if (err != SZ_OK) - { - m_logger.log("Error decompressing %s", ELL_ERROR, params.absolutePath.string().c_str()); - delete[] pBuf; - return 0; - } - else - return io::createMemoryReadFile(pBuf, uncompressedSize, params.absolutePath, true); - -#else - delete[] decryptedBuf; - m_logger.log("lzma decompression not supported. File cannot be read.", ILogger::ELL_ERROR); - return 0; -#endif + const Byte* pcData = decrypted ? reinterpret_cast(decrypted):mmapPtr; + const uint32_t propSize = (uint32_t(pcData[3])<<8)+pcData[2]; + int err = LzmaDecode( + (Byte*)decompressed, + &tmpDstSize, + pcData + sizeof(uint32_t) + propSize, + &tmpSrcSize, + pcData + sizeof(uint32_t), propSize, + (m_itemsMetadata[item->ID].GeneralBitFlag&0x1u) ? LZMA_FINISH_END:LZMA_FINISH_ANY, &status, + &lzmaAlloc + ); + + if (err==SZ_OK) + { + retval.buffer = decompressed; + retval.size = tmpDstSize; // may be different to expected value + } + #else + m_logger.log("lzma decompression not supported. File cannot be read.", ILogger::ELL_ERROR); + #endif + break; } case 99: // If we come here with an encrypted file, decryption support is missing - m_logger.log("Decryption support not enabled. File cannot be read.", ILogger::ELL_ERROR); - delete[] decryptedBuf; - return 0; + m_logger.log("Decryption support not enabled. File cannot be read.",ILogger::ELL_ERROR); + break; default: - m_logger.log("file has unsupported compression method. %s", ILogger::ELL_ERROR, params.absolutePath.string().c_str()); - delete[] decryptedBuf; - return 0; - }; + m_logger.log("File has unsupported compression method.",ILogger::ELL_ERROR); + break; } + + if (!retval.buffer) + { + if (actualCompressionMethod) + m_logger.log("Error decompressing %s",ILogger::ELL_ERROR,item->pathRelativeToArchive.string().c_str()); + else + m_logger.log("Unknown error opening file %s from ZIP archive",ILogger::ELL_ERROR,item->pathRelativeToArchive.string().c_str()); + } + + return retval; +} + + + +#ifdef _NBL_COMPILE_WITH_LZMA_ +//! Used for LZMA decompression. The lib has no default memory management +namespace +{ + void *SzAlloc(void *p, size_t size) { p = p; return _NBL_ALIGNED_MALLOC(size,_NBL_SIMD_ALIGNMENT); } + void SzFree(void *p, void *address) { p = p; _NBL_ALIGNED_FREE(address); } + ISzAlloc lzmaAlloc = { SzAlloc, SzFree }; } #endif \ No newline at end of file diff --git a/src/nbl/system/CArchiveLoaderZip.h b/src/nbl/system/CArchiveLoaderZip.h index 5cc00c385d..1baecf300e 100644 --- a/src/nbl/system/CArchiveLoaderZip.h +++ b/src/nbl/system/CArchiveLoaderZip.h @@ -8,34 +8,6 @@ namespace nbl::system { -#if 0 - CFileArchiveZip(core::smart_refctd_ptr&& file, core::smart_refctd_ptr&& system, bool isGZip, const std::string_view& password, system::logger_opt_smart_ptr&& logger = nullptr) : - IFileArchive(std::move(file), std::move(system), std::move(logger)), m_isGZip(isGZip), m_password(password) - { - size_t offset = 0; - if (m_file.get()) - { - // load file entries - if (m_isGZip) - while (scanGZipHeader(offset)) {} - else - while (scanZipHeader(offset)) {} - } - } - - bool scanGZipHeader(size_t& offset); - bool scanZipHeader(size_t& offset, bool ignoreGPBits = false); - bool scanCentralDirectoryHeader(size_t& offset); - E_ALLOCATOR_TYPE getAllocatorType(uint32_t compressionType) - { - switch (compressionType) - { - case 0: return EAT_NULL; - default: return EAT_VIRTUAL_ALLOC; - } - } -#endif - class CArchiveLoaderZip final : public IArchiveLoader { public: @@ -68,11 +40,9 @@ class CArchiveLoaderZip final : public IArchiveLoader core::smart_refctd_ptr&& _file, system::logger_opt_smart_ptr&& logger, core::vector&& _items, - core::vector&& _itemsMetadata, - const bool _isGZip + core::vector&& _itemsMetadata ) : CFileArchive(path(_file->getFileName()),std::move(logger),std::move(_items)), - m_file(std::move(_file)), m_itemsMetadata(std::move(_itemsMetadata)), - m_password(""), m_isGZip(_isGZip) + m_file(std::move(_file)), m_itemsMetadata(std::move(_itemsMetadata)), m_password("") {} private: @@ -81,7 +51,6 @@ class CArchiveLoaderZip final : public IArchiveLoader core::smart_refctd_ptr m_file; core::vector m_itemsMetadata; const std::string m_password; // TODO password - const bool m_isGZip; }; CArchiveLoaderZip(system::logger_opt_smart_ptr&& logger) : IArchiveLoader(std::move(logger)) {} diff --git a/src/nbl/system/CSystemAndroid.cpp b/src/nbl/system/CSystemAndroid.cpp index 6f269eff4f..c42d4a08be 100644 --- a/src/nbl/system/CSystemAndroid.cpp +++ b/src/nbl/system/CSystemAndroid.cpp @@ -6,7 +6,6 @@ using namespace nbl::system; #include "nbl/system/CAPKResourcesArchive.h" #include -#include #include #include #include diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index 12607777de..cb52465263 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -241,7 +241,7 @@ void ISystem::createFile(future_t>& future, std::f // if (std::filesystem::exists(filename)) filename = std::filesystem::absolute(filename).generic_string(); - if (filename.string().size()>=SRequestParams_CREATE_FILE::MAX_FILENAME_LENGTH) + if (filename.string().size()>=MAX_FILENAME_LENGTH) { future.notify(nullptr); return; From 0ac9082b3789272d0ac1a75e78bf02db0aa272c0 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 12:58:11 +0100 Subject: [PATCH 68/91] Make the compiler shut up with the warnings --- include/nbl/asset/ICPUMeshBuffer.h | 9 ++-- include/nbl/asset/filters/CBlitImageFilter.h | 5 +- include/nbl/core/IReferenceCounted.h | 5 +- include/nbl/core/alloc/AlignedBase.h | 17 +++++- include/nbl/core/containers/dynamic_array.h | 18 ++----- include/nbl/core/decl/smart_refctd_ptr.h | 5 +- include/nbl/core/def/smart_refctd_ptr.h | 4 +- src/nbl/asset/interchange/CGLTFLoader.cpp | 54 ++++++++++---------- src/nbl/asset/interchange/CGLTFLoader.h | 8 +-- 9 files changed, 68 insertions(+), 57 deletions(-) diff --git a/include/nbl/asset/ICPUMeshBuffer.h b/include/nbl/asset/ICPUMeshBuffer.h index c9de8d3f98..e898cef305 100644 --- a/include/nbl/asset/ICPUMeshBuffer.h +++ b/include/nbl/asset/ICPUMeshBuffer.h @@ -422,7 +422,8 @@ class ICPUMeshBuffer final : public IMeshBuffer(format, &src, output64, 0u, 0u); - std::copy(output64, output64+4, output.pointer); + for (auto i=0u; i<4u; i++) + output[i] = static_cast(output64[i]); } else { @@ -430,13 +431,15 @@ class ICPUMeshBuffer final : public IMeshBuffer(impl::getCorrespondingIntegerFmt(format), &src, output64i, 0u, 0u); - std::copy(output64i, output64i+4, output.pointer); + for (auto i=0u; i<4u; i++) + output[i] = static_cast(output64i[i]); } else { uint64_t output64u[4]{ 0u, 0u, 0u, 1u }; decodePixels(impl::getCorrespondingIntegerFmt(format), &src, output64u, 0u, 0u); - std::copy(output64u, output64u+4, output.pointer); + for (auto i=0u; i<4u; i++) + output[i] = static_cast(output64u[i]); } } diff --git a/include/nbl/asset/filters/CBlitImageFilter.h b/include/nbl/asset/filters/CBlitImageFilter.h index afcbdb2006..d73b00dfb2 100644 --- a/include/nbl/asset/filters/CBlitImageFilter.h +++ b/include/nbl/asset/filters/CBlitImageFilter.h @@ -457,7 +457,10 @@ class CBlitImageFilter : public CImageFilter(intermediateExtent[axis][loopCoordID[0]]), + static_cast(intermediateExtent[axis][loopCoordID[1]]) + }; CBasicImageFilterCommon::BlockIterator begin(batchExtent); const uint32_t spaceFillingEnd[batch_dims] = {0u,batchExtent[1]}; CBasicImageFilterCommon::BlockIterator end(begin.getExtentBatches(),spaceFillingEnd); diff --git a/include/nbl/core/IReferenceCounted.h b/include/nbl/core/IReferenceCounted.h index cc2ede2343..70bdbe16d8 100644 --- a/include/nbl/core/IReferenceCounted.h +++ b/include/nbl/core/IReferenceCounted.h @@ -2,9 +2,8 @@ // This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine" // For conditions of distribution and use, see copyright notice in nabla.h // See the original file in irrlicht source for authors - -#ifndef __NBL_CORE_I_IREFERENCE_COUNTED_H_INCLUDED__ -#define __NBL_CORE_I_IREFERENCE_COUNTED_H_INCLUDED__ +#ifndef _NBL_CORE_I_IREFERENCE_COUNTED_H_INCLUDED_ +#define _NBL_CORE_I_IREFERENCE_COUNTED_H_INCLUDED_ #include "nbl/core/decl/Types.h" #include "nbl/core/decl/BaseClasses.h" diff --git a/include/nbl/core/alloc/AlignedBase.h b/include/nbl/core/alloc/AlignedBase.h index 57d663df02..776cafa98f 100644 --- a/include/nbl/core/alloc/AlignedBase.h +++ b/include/nbl/core/alloc/AlignedBase.h @@ -70,6 +70,7 @@ namespace impl template using operator_delete_array_t = decltype(NBL_TYPENAME_4_STTC_MBR U::operator delete[](nullptr)); template using operator_delete_w_size_t = decltype(NBL_TYPENAME_4_STTC_MBR U::operator delete(nullptr,0ull)); template using operator_delete_array_w_size_t = decltype(NBL_TYPENAME_4_STTC_MBR U::operator delete[](nullptr,0ull)); + template using operator_placement_delete_t = decltype(NBL_TYPENAME_4_STTC_MBR U::operator delete(nullptr,nullptr)); template struct has_new_operator : std::false_type {}; template struct has_new_array_operator : std::false_type {}; @@ -79,6 +80,7 @@ namespace impl template struct has_delete_array_operator : std::false_type {}; template struct has_delete_operator_w_size : std::false_type {}; template struct has_delete_array_operator_w_size : std::false_type {}; + template struct has_placement_delete_operator : std::false_type {}; template struct has_new_operator > > : std::is_same,void*> {}; template struct has_new_array_operator > > : std::is_same,void*> {}; template struct has_placement_new_operator > > : std::is_same,void*> {}; @@ -87,6 +89,7 @@ namespace impl template struct has_delete_array_operator > > : std::is_same,void> {}; template struct has_delete_operator_w_size > > : std::is_same,void> {}; template struct has_delete_array_operator_w_size > > : std::is_same,void> {}; + template struct has_placement_delete_operator > > : std::is_same,void> {}; public: /** Now we could override the new and delete operators always with the same thing, and allocate aligned to `std::alignment_of::value`, however we want to call the most aligned class' new and delete operators (if such exist) so its overrides actually matter. @@ -124,6 +127,10 @@ namespace impl { std::conditional::value,most_aligned_type,DefaultAlignedAllocationOverriden>::type::operator delete[](ptr,size); } + static inline void operator delete(void* dummy, void* ptr) noexcept + { + std::conditional::value,most_aligned_type,DefaultAlignedAllocationOverriden>::type::operator delete(dummy,ptr); + } }; @@ -171,6 +178,13 @@ namespace impl static inline void operator delete(void* ptr, size_t size) noexcept {operator delete(ptr);} //roll back to own operator with no size static inline void operator delete[](void* ptr, size_t size) noexcept {operator delete[](ptr);} //roll back to own operator with no size + // make the compiler shut up about memory not being freed if there is an exception + static inline void operator delete(void* dummy, void* ptr) noexcept + { + assert(false); + exit(-0x45); + } + static inline bool isPtrAlignedForThisType(const void* ptr) noexcept { return is_aligned_to(ptr,object_alignment); @@ -199,7 +213,8 @@ static_assert(sizeof(AllocationOverrideDefault)==_NBL_SIMD_ALIGNMENT,"This compi static inline void operator delete(void* ptr) noexcept {nbl::core::impl::ResolveAlignment<__VA_ARGS__>::operator delete(ptr);} \ static inline void operator delete[](void* ptr) noexcept {nbl::core::impl::ResolveAlignment<__VA_ARGS__>::operator delete[](ptr);} \ static inline void operator delete(void* ptr, size_t size) noexcept {nbl::core::impl::ResolveAlignment<__VA_ARGS__>::operator delete(ptr,size);} \ - static inline void operator delete[](void* ptr, size_t size) noexcept {nbl::core::impl::ResolveAlignment<__VA_ARGS__>::operator delete[](ptr,size);} + static inline void operator delete[](void* ptr, size_t size) noexcept {nbl::core::impl::ResolveAlignment<__VA_ARGS__>::operator delete[](ptr,size);} \ + static inline void operator delete(void* dummy, void* ptr) noexcept {nbl::core::impl::ResolveAlignment<__VA_ARGS__>::operator delete(dummy,ptr);} #else struct NBL_FORCE_EBO AllocationOverrideDefault {}; diff --git a/include/nbl/core/containers/dynamic_array.h b/include/nbl/core/containers/dynamic_array.h index 562a3c774b..b59e04939a 100644 --- a/include/nbl/core/containers/dynamic_array.h +++ b/include/nbl/core/containers/dynamic_array.h @@ -1,16 +1,13 @@ // Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. // This file is part of the "Nabla Engine". // For conditions of distribution and use, see copyright notice in nabla.h - -#ifndef __NBL_CORE_DYNAMIC_ARRAY_H_INCLUDED__ -#define __NBL_CORE_DYNAMIC_ARRAY_H_INCLUDED__ +#ifndef _NBL_CORE_DYNAMIC_ARRAY_H_INCLUDED_ +#define _NBL_CORE_DYNAMIC_ARRAY_H_INCLUDED_ #include "nbl/macros.h" #include "nbl/core/decl/Types.h" //for core::allocator -namespace nbl -{ -namespace core +namespace nbl::core { namespace impl @@ -166,6 +163,8 @@ class NBL_FORCE_EBO dynamic_array : public impl::dynamic_array_base(ptr)); } + + // size hint is ill-formed static void operator delete(void* ptr, std::size_t sz) = delete; // no arrays @@ -180,12 +179,6 @@ class NBL_FORCE_EBO dynamic_array : public impl::dynamic_array_base* ptr, std::destroying_delete_t) = delete; - static void operator delete(dynamic_array* ptr, std::destroying_delete_t, std::align_val_t al) = delete; - static void operator delete(dynamic_array* ptr, std::destroying_delete_t, std::size_t sz) = delete; - static void operator delete(dynamic_array* ptr, std::destroying_delete_t, std::size_t sz, std::align_val_t al) = delete; -#endif inline bool operator!=(const this_real_type& _other) const { @@ -232,7 +225,6 @@ class NBL_FORCE_EBO dynamic_array : public impl::dynamic_array_base(scene.get_uint64()); if (scenes.error() != simdjson::error_code::NO_SUCH_FIELD) { @@ -1724,7 +1724,7 @@ using namespace nbl::asset; const auto& extras = jsonBufferView.at_key("extras"); if (buffer.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFBufferView.buffer = buffer.get_uint64().value(); + glTFBufferView.buffer = static_cast(buffer.get_uint64().value()); if (byteOffset.error() != simdjson::error_code::NO_SUCH_FIELD) glTFBufferView.byteOffset = byteOffset.get_uint64().value(); @@ -1733,10 +1733,10 @@ using namespace nbl::asset; glTFBufferView.byteLength = byteLength.get_uint64().value(); if (byteStride.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFBufferView.byteStride = byteStride.get_uint64().value(); + glTFBufferView.byteStride = static_cast(byteStride.get_uint64().value()); if (target.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFBufferView.target = target.get_uint64().value(); + glTFBufferView.target = static_cast(target.get_uint64().value()); if (name.error() != simdjson::error_code::NO_SUCH_FIELD) glTFBufferView.name = name.get_string().value(); @@ -1815,10 +1815,10 @@ using namespace nbl::asset; const auto& name = texture.at_key("name"); if (sampler.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFTexture.sampler = sampler.get_uint64().value(); + glTFTexture.sampler = static_cast(sampler.get_uint64().value()); if (source.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFTexture.source = source.get_uint64().value(); + glTFTexture.source = static_cast(source.get_uint64().value()); if (name.error() != simdjson::error_code::NO_SUCH_FIELD) glTFTexture.name = name.get_string().value(); @@ -1874,10 +1874,10 @@ using namespace nbl::asset; const auto& texCoord = bctData.at_key("texCoord"); if (index.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFBaseColorTexture.index = index.get_uint64().value(); + glTFBaseColorTexture.index = static_cast(index.get_uint64().value()); if (texCoord.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFBaseColorTexture.texCoord = texCoord.get_uint64().value(); + glTFBaseColorTexture.texCoord = static_cast(texCoord.get_uint64().value()); } if (metallicFactor.error() != simdjson::error_code::NO_SUCH_FIELD) @@ -1895,27 +1895,27 @@ using namespace nbl::asset; const auto& texCoord = mrtData.at_key("texCoord"); if (index.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFMetallicRoughnessTexture.index = index.get_uint64().value(); + glTFMetallicRoughnessTexture.index = static_cast(index.get_uint64().value()); if (texCoord.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFMetallicRoughnessTexture.texCoord = texCoord.get_uint64().value(); + glTFMetallicRoughnessTexture.texCoord = static_cast(texCoord.get_uint64().value()); } } if (normalTexture.error() != simdjson::error_code::NO_SUCH_FIELD) { auto& glTFNormalTexture = glTFMaterial.normalTexture.emplace(); - const const auto& normalTextureData = normalTexture.get_object(); + const auto& normalTextureData = normalTexture.get_object(); const auto& index = normalTextureData.at_key("index"); const auto& texCoord = normalTextureData.at_key("texCoord"); const auto& scale = normalTextureData.at_key("scale"); if (index.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFNormalTexture.index = index.get_uint64().value(); + glTFNormalTexture.index = static_cast(index.get_uint64().value()); if (texCoord.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFNormalTexture.texCoord = texCoord.get_uint64().value(); + glTFNormalTexture.texCoord = static_cast(texCoord.get_uint64().value()); if (scale.error() != simdjson::error_code::NO_SUCH_FIELD) glTFNormalTexture.scale = texCoord.get_double().value(); @@ -1931,10 +1931,10 @@ using namespace nbl::asset; const auto& strength = occlusionTextureData.at_key("strength"); if (index.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFOcclusionTexture.index = index.get_uint64().value(); + glTFOcclusionTexture.index = static_cast(texCoord.get_uint64().value()); if (texCoord.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFOcclusionTexture.texCoord = texCoord.get_uint64().value(); + glTFOcclusionTexture.texCoord = static_cast(texCoord.get_uint64().value()); if (strength.error() != simdjson::error_code::NO_SUCH_FIELD) glTFOcclusionTexture.strength = texCoord.get_double().value(); @@ -1949,10 +1949,10 @@ using namespace nbl::asset; const auto& texCoord = emissiveTextureData.at_key("texCoord"); if (index.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFEmissiveTexture.index = index.get_uint64().value(); + glTFEmissiveTexture.index = static_cast(texCoord.get_uint64().value()); if (texCoord.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFEmissiveTexture.texCoord = texCoord.get_uint64().value(); + glTFEmissiveTexture.texCoord = static_cast(texCoord.get_uint64().value()); } if (emissiveFactor.error() != simdjson::error_code::NO_SUCH_FIELD) @@ -2137,7 +2137,7 @@ using namespace nbl::asset; const auto& extras = accessor.at_key("extras"); if (bufferView.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFAccessor.bufferView = bufferView.get_uint64().value(); + glTFAccessor.bufferView = static_cast(bufferView.get_uint64().value()); if (byteOffset.error() != simdjson::error_code::NO_SUCH_FIELD) glTFAccessor.byteOffset = byteOffset.get_uint64().value(); @@ -2149,7 +2149,7 @@ using namespace nbl::asset; glTFAccessor.normalized = normalized.get_bool().value(); if (count.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFAccessor.count = count.get_uint64().value(); + glTFAccessor.count = static_cast(count.get_uint64().value()); if (type.error() != simdjson::error_code::NO_SUCH_FIELD) { @@ -2236,25 +2236,25 @@ using namespace nbl::asset; const auto& extras = primitive.at_key("extras"); if (indices.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFPrimitive.indices = indices.get_uint64().value(); + glTFPrimitive.indices = static_cast(indices.get_uint64().value()); if (material.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFPrimitive.material = material.get_uint64().value(); + glTFPrimitive.material = static_cast(material.get_uint64().value()); if (mode.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFPrimitive.mode = mode.get_uint64().value(); + glTFPrimitive.mode = static_cast(mode.get_uint64().value()); else glTFPrimitive.mode = 4; if (targets.error() != simdjson::error_code::NO_SUCH_FIELD) for (const auto& [targetKey, targetID] : targets.get_object()) - glTFPrimitive.targets.emplace()[targetKey.data()] = targetID.get_uint64().value(); + glTFPrimitive.targets.emplace()[targetKey.data()] = static_cast(targetID.get_uint64().value()); if (attributes.error() != simdjson::error_code::NO_SUCH_FIELD) { for (const auto& [attributeKey, accessorID] : attributes.get_object()) { - const auto& requestedAccessor = accessorID.get_uint64().value(); + const auto requestedAccessor = accessorID.get_uint64().value(); std::pair attributeMap; { @@ -2351,14 +2351,14 @@ using namespace nbl::asset; const auto& extras = jsonNode.at_key("extras"); if (camera.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFnode.camera = camera.get_uint64().value(); + glTFnode.camera = static_cast(camera.get_uint64().value()); if (children.error() != simdjson::error_code::NO_SUCH_FIELD) for (const auto& child : children) glTFnode.children.push_back(child.get_uint64().value()); if (skin.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFnode.skin = skin.get_uint64().value(); + glTFnode.skin = static_cast(skin.get_uint64().value()); if (matrix.error() != simdjson::error_code::NO_SUCH_FIELD) { @@ -2410,7 +2410,7 @@ using namespace nbl::asset; } if (mesh.error() != simdjson::error_code::NO_SUCH_FIELD) - glTFnode.mesh = mesh.get_uint64().value(); + glTFnode.mesh = static_cast(mesh.get_uint64().value()); if (name.error() != simdjson::error_code::NO_SUCH_FIELD) glTFnode.name = name.get_string().value(); diff --git a/src/nbl/asset/interchange/CGLTFLoader.h b/src/nbl/asset/interchange/CGLTFLoader.h index 50cd25ddd0..fa1d1f42de 100644 --- a/src/nbl/asset/interchange/CGLTFLoader.h +++ b/src/nbl/asset/interchange/CGLTFLoader.h @@ -355,7 +355,7 @@ class CGLTFLoader final : public IRenderpassIndependentPipelineLoader }; std::optional bufferView; - std::optional byteOffset; + std::optional byteOffset; std::optional componentType; std::optional normalized; std::optional count; @@ -508,8 +508,8 @@ class CGLTFLoader final : public IRenderpassIndependentPipelineLoader struct SGLTFBufferView { std::optional buffer; - std::optional byteOffset; - std::optional byteLength; + std::optional byteOffset; + std::optional byteLength; std::optional byteStride; std::optional target; std::optional name; @@ -536,7 +536,7 @@ class CGLTFLoader final : public IRenderpassIndependentPipelineLoader { std::optional uri; std::optional mimeType; - std::optional bufferView; + std::optional bufferView; std::optional name; struct SMIMEType From c13abd661bbbf02c03ac6f95b376176d0a17b541 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 12:59:59 +0100 Subject: [PATCH 69/91] more APK archive fixes --- src/nbl/system/CAPKResourcesArchive.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nbl/system/CAPKResourcesArchive.cpp b/src/nbl/system/CAPKResourcesArchive.cpp index 13fb9f79a8..90c5e3be51 100644 --- a/src/nbl/system/CAPKResourcesArchive.cpp +++ b/src/nbl/system/CAPKResourcesArchive.cpp @@ -5,6 +5,7 @@ using namespace nbl::system; #ifdef _NBL_PLATFORM_ANDROID_ #include +#include #include CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jni) @@ -56,7 +57,7 @@ core::vector CAPKResourcesArchive::computeItems(const CFileArchive::file_buffer_t CAPKResourcesArchive::getFileBuffer(const IFileArchive::SListEntry* item) { AAsset* asset = AAssetManager_open(m_mgr,item->pathRelativeToArchive.string().c_str(),AASSET_MODE_BUFFER); - return {AAsset_getBuffer(asset),AAsset_getLength(asset),asset}; + return {const_cast(AAsset_getBuffer(asset)),AAsset_getLength(asset),asset}; } #endif \ No newline at end of file From 5f1dae0f549e55b62f534bd579a0c809e23203f2 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 13:56:52 +0100 Subject: [PATCH 70/91] seems APK archive doesn't need to hang onto JNI --- src/nbl/system/CAPKResourcesArchive.cpp | 11 +++++------ src/nbl/system/CAPKResourcesArchive.h | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/nbl/system/CAPKResourcesArchive.cpp b/src/nbl/system/CAPKResourcesArchive.cpp index 90c5e3be51..802d3bc10d 100644 --- a/src/nbl/system/CAPKResourcesArchive.cpp +++ b/src/nbl/system/CAPKResourcesArchive.cpp @@ -4,16 +4,15 @@ using namespace nbl; using namespace nbl::system; #ifdef _NBL_PLATFORM_ANDROID_ -#include #include #include -CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jni) - : CFileArchive(path(_path),std::move(logger),computeItems(_path.string())), m_mgr(act->assetManager), m_activity(act), m_jniEnv(jni) +CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jniEnv) + : CFileArchive(path(_path),std::move(logger),computeItems(_path.string(),act->assetManager,jniEnv)), m_mgr(act->assetManager), m_activity(act) { } -core::vector CAPKResourcesArchive::computeItems(const std::string& asset_path) +core::vector CAPKResourcesArchive::computeItems(const std::string& asset_path, AAssetManager* mgr, JNIEnv* env) { auto context_object = activity->clazz; auto getAssets_method = env->GetMethodID(env->GetObjectClass(context_object), "getAssets", "()Landroid/content/res/AssetManager;"); @@ -39,7 +38,7 @@ core::vector CAPKResourcesArchive::computeItems(const auto& item = result.emplace_back(); item.pathRelativeToArchive = filename; { - AAsset* asset = AAssetManager_open(m_mgr,filename,AASSET_MODE_STREAMING); + AAsset* asset = AAssetManager_open(mgr,filename,AASSET_MODE_STREAMING); item.size = AAsset_getLength(asset); AAsset_close(asset); } @@ -57,7 +56,7 @@ core::vector CAPKResourcesArchive::computeItems(const CFileArchive::file_buffer_t CAPKResourcesArchive::getFileBuffer(const IFileArchive::SListEntry* item) { AAsset* asset = AAssetManager_open(m_mgr,item->pathRelativeToArchive.string().c_str(),AASSET_MODE_BUFFER); - return {const_cast(AAsset_getBuffer(asset)),AAsset_getLength(asset),asset}; + return {const_cast(AAsset_getBuffer(asset)),static_cast(AAsset_getLength(asset)),asset}; } #endif \ No newline at end of file diff --git a/src/nbl/system/CAPKResourcesArchive.h b/src/nbl/system/CAPKResourcesArchive.h index 4160b8ce29..3d37adedbd 100644 --- a/src/nbl/system/CAPKResourcesArchive.h +++ b/src/nbl/system/CAPKResourcesArchive.h @@ -17,7 +17,7 @@ namespace nbl::system class CAPKResourcesArchive final : public CFileArchive { public: - CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jni); + CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jniEnv); protected: static core::vector computeItems(const std::string& asset_path); @@ -26,7 +26,6 @@ class CAPKResourcesArchive final : public CFileArchive AAssetManager* m_mgr; - JNIEnv* m_jniEnv; ANativeActivity* m_activity; }; From a50553bccfd9d3f635e19f00d37e96f62c7e305e Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 14:06:38 +0100 Subject: [PATCH 71/91] Android dev-by-CI is very iterative --- src/nbl/system/CAPKResourcesArchive.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nbl/system/CAPKResourcesArchive.h b/src/nbl/system/CAPKResourcesArchive.h index 3d37adedbd..dd35c460f2 100644 --- a/src/nbl/system/CAPKResourcesArchive.h +++ b/src/nbl/system/CAPKResourcesArchive.h @@ -20,7 +20,7 @@ class CAPKResourcesArchive final : public CFileArchive CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jniEnv); protected: - static core::vector computeItems(const std::string& asset_path); + static core::vector computeItems(const std::string& asset_path, AAssetManager* mgr, JNIEnv* env); file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) override; From d2779c7c2ae643052af48e5e75c747c417b353cc Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 14:09:05 +0100 Subject: [PATCH 72/91] APK refactor --- src/nbl/system/CAPKResourcesArchive.cpp | 8 ++++---- src/nbl/system/CAPKResourcesArchive.h | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/nbl/system/CAPKResourcesArchive.cpp b/src/nbl/system/CAPKResourcesArchive.cpp index 802d3bc10d..24c2315d74 100644 --- a/src/nbl/system/CAPKResourcesArchive.cpp +++ b/src/nbl/system/CAPKResourcesArchive.cpp @@ -7,12 +7,12 @@ using namespace nbl::system; #include #include -CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jniEnv) - : CFileArchive(path(_path),std::move(logger),computeItems(_path.string(),act->assetManager,jniEnv)), m_mgr(act->assetManager), m_activity(act) +CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* activity, JNIEnv* jniEnv) + : CFileArchive(path(_path),std::move(logger),computeItems(_path.string(),activity,jniEnv)), m_mgr(activity->assetManager) { } -core::vector CAPKResourcesArchive::computeItems(const std::string& asset_path, AAssetManager* mgr, JNIEnv* env) +core::vector CAPKResourcesArchive::computeItems(const std::string& asset_path, ANativeActivity* activity, JNIEnv* jniEnv) { auto context_object = activity->clazz; auto getAssets_method = env->GetMethodID(env->GetObjectClass(context_object), "getAssets", "()Landroid/content/res/AssetManager;"); @@ -38,7 +38,7 @@ core::vector CAPKResourcesArchive::computeItems(const auto& item = result.emplace_back(); item.pathRelativeToArchive = filename; { - AAsset* asset = AAssetManager_open(mgr,filename,AASSET_MODE_STREAMING); + AAsset* asset = AAssetManager_open(activity->assetManager,filename,AASSET_MODE_STREAMING); item.size = AAsset_getLength(asset); AAsset_close(asset); } diff --git a/src/nbl/system/CAPKResourcesArchive.h b/src/nbl/system/CAPKResourcesArchive.h index dd35c460f2..3ea1c9b757 100644 --- a/src/nbl/system/CAPKResourcesArchive.h +++ b/src/nbl/system/CAPKResourcesArchive.h @@ -17,16 +17,15 @@ namespace nbl::system class CAPKResourcesArchive final : public CFileArchive { public: - CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* act, JNIEnv* jniEnv); + CAPKResourcesArchive(const path& _path, system::logger_opt_smart_ptr&& logger, ANativeActivity* activity, JNIEnv* jniEnv); protected: - static core::vector computeItems(const std::string& asset_path, AAssetManager* mgr, JNIEnv* env); + static core::vector computeItems(const std::string& asset_path, ANativeActivity* activity, JNIEnv* jniEnv); file_buffer_t getFileBuffer(const IFileArchive::SListEntry* item) override; AAssetManager* m_mgr; - ANativeActivity* m_activity; }; } From 12b82906bc8b788c15e883b1629aecb7fe6eb230 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 17:42:20 +0100 Subject: [PATCH 73/91] Android and indentation --- include/nbl/system/CApplicationAndroid.h | 19 ++++++------- include/nbl/system/IApplicationFramework.h | 2 +- src/nbl/system/CAPKResourcesArchive.cpp | 22 +++++++-------- src/nbl/ui/CGraphicalApplicationAndroid.cpp | 30 +++++++++++---------- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/include/nbl/system/CApplicationAndroid.h b/include/nbl/system/CApplicationAndroid.h index 1075113b35..ef9f2020e8 100644 --- a/include/nbl/system/CApplicationAndroid.h +++ b/include/nbl/system/CApplicationAndroid.h @@ -1,19 +1,21 @@ #ifndef _NBL_SYSTEM_C_APPLICATION_FRAMEWORK_ANDROID_H_INCLUDED_ #define _NBL_SYSTEM_C_APPLICATION_FRAMEWORK_ANDROID_H_INCLUDED_ -#ifdef _NBL_PLATFORM_ANDROID_ - #include "nbl/core/declarations.h" -#include "nbl/system/CStdoutLoggerAndroid.h" + #include "nbl/system/IApplicationFramework.h" +#include "nbl/system/CStdoutLoggerAndroid.h" + + +namespace nbl::system +{ +#ifdef _NBL_PLATFORM_ANDROID_ #include #include #include -namespace nbl::system -{ class CApplicationAndroid : public IApplicationFramework - { +{ public: void onStateSaved(android_app* params) { @@ -132,10 +134,9 @@ namespace nbl::system }; CEventPoller eventPoller; bool keepPolling() const { return eventPoller.continuePredicate(); } - }; - -} +}; #endif +} #endif \ No newline at end of file diff --git a/include/nbl/system/IApplicationFramework.h b/include/nbl/system/IApplicationFramework.h index 946dd86d9a..11114a4ef1 100644 --- a/include/nbl/system/IApplicationFramework.h +++ b/include/nbl/system/IApplicationFramework.h @@ -2,8 +2,8 @@ #define _NBL_SYSTEM_I_APPLICATION_FRAMEWORK_H_INCLUDED_ #include "nbl/core/declarations.h" -#include "nbl/system/declarations.h" +#include "nbl/system/declarations.h" #include "nbl/system/definitions.h" namespace nbl::system diff --git a/src/nbl/system/CAPKResourcesArchive.cpp b/src/nbl/system/CAPKResourcesArchive.cpp index 24c2315d74..4ac11e52ee 100644 --- a/src/nbl/system/CAPKResourcesArchive.cpp +++ b/src/nbl/system/CAPKResourcesArchive.cpp @@ -15,24 +15,24 @@ CAPKResourcesArchive::CAPKResourcesArchive(const path& _path, system::logger_opt core::vector CAPKResourcesArchive::computeItems(const std::string& asset_path, ANativeActivity* activity, JNIEnv* jniEnv) { auto context_object = activity->clazz; - auto getAssets_method = env->GetMethodID(env->GetObjectClass(context_object), "getAssets", "()Landroid/content/res/AssetManager;"); - auto assetManager_object = env->CallObjectMethod(context_object,getAssets_method); - auto list_method = env->GetMethodID(env->GetObjectClass(assetManager_object), "list", "(Ljava/lang/String;)[Ljava/lang/String;"); + auto getAssets_method = jniEnv->GetMethodID(jniEnv->GetObjectClass(context_object), "getAssets", "()Landroid/content/res/AssetManager;"); + auto assetManager_object = jniEnv->CallObjectMethod(context_object,getAssets_method); + auto list_method = jniEnv->GetMethodID(jniEnv->GetObjectClass(assetManager_object), "list", "(Ljava/lang/String;)[Ljava/lang/String;"); - jstring path_object = env->NewStringUTF(asset_path.c_str()); + jstring path_object = jniEnv->NewStringUTF(asset_path.c_str()); - auto files_object = (jobjectArray)env->CallObjectMethod(assetManager_object, list_method, path_object); + auto files_object = (jobjectArray)jniEnv->CallObjectMethod(assetManager_object, list_method, path_object); - env->DeleteLocalRef(path_object); + jniEnv->DeleteLocalRef(path_object); - auto length = env->GetArrayLength(files_object); + auto length = jniEnv->GetArrayLength(files_object); core::vector result; for (decltype(length) i=0; iGetObjectArrayElement(files_object,i); + jstring jstr = (jstring)jniEnv->GetObjectArrayElement(files_object,i); - const char* filename = env->GetStringUTFChars(jstr,nullptr); + const char* filename = jniEnv->GetStringUTFChars(jstr,nullptr); if (filename != nullptr) { auto& item = result.emplace_back(); @@ -46,10 +46,10 @@ core::vector CAPKResourcesArchive::computeItems(const item.ID = i; item.allocatorType = EAT_APK_ALLOCATOR; - env->ReleaseStringUTFChars(jstr,filename); + jniEnv->ReleaseStringUTFChars(jstr,filename); } - env->DeleteLocalRef(jstr); + jniEnv->DeleteLocalRef(jstr); } } diff --git a/src/nbl/ui/CGraphicalApplicationAndroid.cpp b/src/nbl/ui/CGraphicalApplicationAndroid.cpp index 858d9d7820..35018fa163 100644 --- a/src/nbl/ui/CGraphicalApplicationAndroid.cpp +++ b/src/nbl/ui/CGraphicalApplicationAndroid.cpp @@ -4,22 +4,24 @@ namespace nbl::ui { - system::path CGraphicalApplicationAndroid::getSharedResourcesPath(JNIEnv* env) - { - // Get File object for the external storage directory. - jclass classEnvironment = env->FindClass("android/os/Environment"); - jmethodID methodIDgetExternalStorageDirectory = env->GetStaticMethodID(classEnvironment, "getExternalStorageDirectory", "()Ljava/io/File;"); // public static File getExternalStorageDirectory () - jobject objectFile = env->CallStaticObjectMethod(classEnvironment, methodIDgetExternalStorageDirectory); - // Call method on File object to retrieve String object. - jclass classFile = env->GetObjectClass(objectFile); - jmethodID methodIDgetAbsolutePath = env->GetMethodID(classFile, "getAbsolutePath", "()Ljava/lang/String;"); - jstring stringPath = (jstring)env->CallObjectMethod(objectFile, methodIDgetAbsolutePath); +system::path CGraphicalApplicationAndroid::getSharedResourcesPath(JNIEnv* env) +{ + // Get File object for the external storage directory. + jclass classEnvironment = env->FindClass("android/os/Environment"); + jmethodID methodIDgetExternalStorageDirectory = env->GetStaticMethodID(classEnvironment, "getExternalStorageDirectory", "()Ljava/io/File;"); // public static File getExternalStorageDirectory () + jobject objectFile = env->CallStaticObjectMethod(classEnvironment, methodIDgetExternalStorageDirectory); + + // Call method on File object to retrieve String object. + jclass classFile = env->GetObjectClass(objectFile); + jmethodID methodIDgetAbsolutePath = env->GetMethodID(classFile, "getAbsolutePath", "()Ljava/lang/String;"); + jstring stringPath = (jstring)env->CallObjectMethod(objectFile, methodIDgetAbsolutePath); + + // Extract a C string from the String object, and chdir() to it. + const char* sharedPath = env->GetStringUTFChars(stringPath, NULL); + return system::path(sharedPath); +} - // Extract a C string from the String object, and chdir() to it. - const char* sharedPath = env->GetStringUTFChars(stringPath, NULL); - return system::path(sharedPath); - } } #endif \ No newline at end of file From 17afb7c41666cd538bb99edcc23f7f622e4db7e5 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 9 Mar 2022 18:55:32 +0100 Subject: [PATCH 74/91] rewrote ZIP archive, it did not bring joy P.S. Weird footer specced ZIPs won't work, cba. --- src/nbl/system/CAPKResourcesArchive.cpp | 1 + src/nbl/system/CArchiveLoaderZip.cpp | 574 ++++++++++------------- src/nbl/system/CFileViewAPKAllocator.cpp | 2 +- 3 files changed, 256 insertions(+), 321 deletions(-) diff --git a/src/nbl/system/CAPKResourcesArchive.cpp b/src/nbl/system/CAPKResourcesArchive.cpp index 4ac11e52ee..011a9ff85f 100644 --- a/src/nbl/system/CAPKResourcesArchive.cpp +++ b/src/nbl/system/CAPKResourcesArchive.cpp @@ -51,6 +51,7 @@ core::vector CAPKResourcesArchive::computeItems(const jniEnv->DeleteLocalRef(jstr); } + return result; } CFileArchive::file_buffer_t CAPKResourcesArchive::getFileBuffer(const IFileArchive::SListEntry* item) diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index 367c49df3d..0442d66be3 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -38,6 +38,8 @@ struct SZIPFileCentralDirFileHeader } PACK_STRUCT; struct SZIPFileCentralDirEnd { + static inline constexpr uint32_t ExpectedSig = 0x06054b50u; + uint32_t Sig; // 'PK0506' end_of central dir signature // (0x06054b50) uint16_t NumberDisk; // number of this disk uint16_t NumberStart; // number of the disk with the start of the central directory @@ -109,110 +111,134 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: // load file entries { const bool isGZip = sig==0x8b1fu; + + // + auto addItem = [&items,&itemsMetadata](const std::string& _path, const size_t offset, const SZIPFileHeader& meta) -> void + { + // we need to have a filename or we skip + if (_path.empty()) + return; + + auto& item = items.emplace_back(); + item.pathRelativeToArchive = _path; + item.size = meta.DataDescriptor.UncompressedSize; + item.offset = offset; + item.ID = items.size(); + item.allocatorType = meta.CompressionMethod ? IFileArchive::EAT_VIRTUAL_ALLOC:IFileArchive::EAT_NULL; + itemsMetadata.push_back(meta); + }; + + // size_t offset = 0ull; + auto readStringFromFile = [&file,&offset](auto charCallback) -> bool + { + char c = 0x45; // make sure we start with non-zero char + while (c) + { + IFile::success_t success; + file->read(success,&c,offset,sizeof(c)); + if (!success) + return false; + offset += success.getSizeToProcess(); + charCallback(c); + } + // if string is not null terminated, something went wrong reading the file + return !c; + }; + + // std::string filename; filename.reserve(ISystem::MAX_FILENAME_LENGTH); - while (true) + if (isGZip) { - SZIPFileHeader header; - memset(&header,0,sizeof(SZIPFileHeader)); - - const auto& zipHeader = header; - static_assert(sizeof(SGZIPMemberHeader)(header); - - IFile::success_t headerReadSuccess; - file->read(headerReadSuccess,&header,offset,isGZip ? sizeof(SGZIPMemberHeader):sizeof(header)); - if (!headerReadSuccess) - break; - offset += headerReadSuccess.getSizeToProcess(); - - IFileArchive::SListEntry item; - if (isGZip) + SGZIPMemberHeader gzipHeader; { - //! The gzip file format seems to think that there can be multiple files in a gzip file - //! TODO: But OLD Irrlicht Impl doesn't honor it!? - if (gzipHeader.sig!=0x8b1fu) - break; + IFile::success_t success; + file->read(success,&gzipHeader,0ull,sizeof(gzipHeader)); + if (!success) + return nullptr; + offset += success.getSizeToProcess(); + } + + //! The gzip file format seems to think that there can be multiple files in a gzip file + //! TODO: But OLD Irrlicht Impl doesn't honor it!? + if (gzipHeader.sig!=0x8b1fu) + return nullptr; - // now get the file info - if (gzipHeader.flags&EGZF_EXTRA_FIELDS) - { - // read lenth of extra data - uint16_t dataLen; - IFile::success_t success; - file->read(success,&dataLen,offset,sizeof(dataLen)); - if (!success) - break; - offset += success.getSizeToProcess(); - // skip the extra data - offset += dataLen; - } - // + // now get the file info + if (gzipHeader.flags&EGZF_EXTRA_FIELDS) + { + // read lenth of extra data + uint16_t dataLen; + IFile::success_t success; + file->read(success,&dataLen,offset,sizeof(dataLen)); + if (!success) + return nullptr; + offset += success.getSizeToProcess(); + // skip the extra data + offset += dataLen; + } + // + if (gzipHeader.flags&EGZF_FILE_NAME) + { filename.clear(); - if (gzipHeader.flags&EGZF_FILE_NAME) - { - char c = 0x45; // make sure we start with non-zero char - while (c) - { - IFile::success_t success; - file->read(success,&c,offset,sizeof(c)); - if (!success) - break; - offset += success.getSizeToProcess(); - filename.push_back(c); - } - // if string is not null terminated, something went wrong reading the file - if (c) - break; - } - // - if (gzipHeader.flags&EGZF_COMMENT) - { - char c = 0x45; // make sure we start with non-zero char - while (c) - { - IFile::success_t success; - file->read(success,&c,offset,sizeof(c)); - if (!success) - break; - offset += success.getSizeToProcess(); - } - // if string is not null terminated, something went wrong reading the file - if (c) - break; - } - // skip crc16 - if (gzipHeader.flags&EGZF_CRC16) - offset += 2; + if (!readStringFromFile([&](const char c){filename.push_back(c);})) + return nullptr; + } + // + if (gzipHeader.flags&EGZF_COMMENT) + { + if (!readStringFromFile([](const char c){})) + return nullptr; + } + // skip crc16 + if (gzipHeader.flags&EGZF_CRC16) + offset += 2; - header.FilenameLength = filename.length(); - header.CompressionMethod = gzipHeader.compressionMethod; - header.DataDescriptor.CompressedSize = file->getSize()-(offset+sizeof(uint64_t)); - item.offset = offset; + SZIPFileHeader header; + memset(&header,0,sizeof(SZIPFileHeader)); + header.FilenameLength = filename.length(); + header.CompressionMethod = gzipHeader.compressionMethod; + header.DataDescriptor.CompressedSize = file->getSize()-(offset+sizeof(uint64_t)); + + const size_t itemOffset = offset; - offset += header.DataDescriptor.CompressedSize; - // read CRC - { - IFile::success_t success; - file->read(success,&header.DataDescriptor.CRC32,offset,sizeof(header.DataDescriptor.CRC32)); - if (!success) - break; - offset += success.getSizeToProcess(); - } - // read uncompressed size + offset += header.DataDescriptor.CompressedSize; + // read CRC + { + IFile::success_t success; + file->read(success,&header.DataDescriptor.CRC32,offset,sizeof(header.DataDescriptor.CRC32)); + if (!success) + return nullptr; + offset += success.getSizeToProcess(); + } + // read uncompressed size + { + IFile::success_t success; + file->read(success,&header.DataDescriptor.UncompressedSize,offset,sizeof(header.DataDescriptor.UncompressedSize)); + if (!success) + return nullptr; + offset += success.getSizeToProcess(); + } + + // + addItem(filename,itemOffset,header); + } + else + { + while (true) + { + SZIPFileHeader zipHeader; { IFile::success_t success; - file->read(success,&header.DataDescriptor.UncompressedSize,offset,sizeof(header.DataDescriptor.UncompressedSize)); + file->read(success,&zipHeader,0ull,sizeof(zipHeader)); if (!success) break; offset += success.getSizeToProcess(); - item.size = header.DataDescriptor.UncompressedSize; } - } - else - { if (zipHeader.Sig!=0x04034b50u) + + if (zipHeader.Sig!=0x04034b50u) break; filename.resize(zipHeader.FilenameLength); @@ -225,72 +251,85 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: } // AES encryption - if ((header.GeneralBitFlag&ZIP_FILE_ENCRYPTED) && (header.CompressionMethod==99)) + if ((zipHeader.GeneralBitFlag&ZIP_FILE_ENCRYPTED) && (zipHeader.CompressionMethod==99)) { -/*/ - #ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ - int16_t restSize = entry.header.ExtraFieldLength; - SZipFileExtraHeader extraHeader; - while (restSize) - { - { - system::future fut; - m_file->read(fut, &extraHeader, offset, sizeof(extraHeader)); - fut.get(); - offset += sizeof(extraHeader); - } - restSize -= sizeof(extraHeader); - if (extraHeader.ID == (int16_t)0x9901) - { - SZipFileAESExtraData data; - { - system::future fut; - m_file->read(fut, &data, offset, sizeof(data)); - fut.get(); - offset += sizeof(data); - } + SZipFileExtraHeader extraHeader; + SZipFileAESExtraData data; - restSize -= sizeof(data); - if (data.Vendor[0] == 'A' && data.Vendor[1] == 'E') - { - // encode values into Sig - // AE-Version | Strength | ActualMode - entry.header.Sig = - ((data.Version & 0xff) << 24) | - (data.EncryptionStrength << 16) | - (data.CompressionMode); - offset += restSize; - break; - } - } - } - #else -*/ - break; // no support, can't decrypt -// #endif + size_t localOffset = offset; + offset += zipHeader.ExtraFieldLength; + while (true) + { + { + IFile::success_t success; + file->read(success,&extraHeader,localOffset,sizeof(extraHeader)); + if (!success) + break; + localOffset += success.getSizeToProcess(); + if (localOffset>offset) + break; + } + + if (extraHeader.ID!=0x9901u) + continue; + + { + IFile::success_t success; + file->read(success,&data,localOffset,sizeof(data)); + if (!success) + break; + localOffset += success.getSizeToProcess(); + if (localOffset>offset) + break; + } + if (data.Vendor[0]=='A' && data.Vendor[1]=='E') + { + #ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ + // encode values into Sig + // AE-Version | Strength | ActualMode + zipHeader.Sig = + ((data.Version & 0xff) << 24) | + (data.EncryptionStrength << 16) | + (data.CompressionMode); + break; + #else + filename.clear(); // no support, can't decrypt + #endif + } + } } else - offset += header.ExtraFieldLength; - - - - + offset += zipHeader.ExtraFieldLength; + // if bit 3 was set, use CentralDirectory for setup + if (zipHeader.GeneralBitFlag&ZIP_INFO_IN_DATA_DESCRIPTOR) + { + SZIPFileCentralDirEnd dirEnd; + dirEnd.Sig = 0u; - item.offset = offset; + // First place where the end record could be stored + offset = file->getSize()-sizeof(SZIPFileCentralDirEnd)+1ull; + while (dirEnd.Sig!=SZIPFileCentralDirEnd::ExpectedSig) + { + IFile::success_t success; + file->read(success,&dirEnd,--offset,sizeof(dirEnd)); + if (!success) + return nullptr; + } + items.reserve(dirEnd.TotalEntries); + itemsMetadata.reserve(dirEnd.TotalEntries); + offset = dirEnd.Offset; + #if 0 + while (scanCentralDirectoryHeader(offset)) {} + #endif + assert(false); // if you ever hit this, msg @devsh + break; + } + + addItem(filename,offset,zipHeader); // move forward length of data offset += zipHeader.DataDescriptor.CompressedSize; } - - // we need to have a filename or we skip - if (filename.empty()) - continue; - - item.pathRelativeToArchive = filename; - item.ID = items.size(); - item.allocatorType = header.CompressionMethod ? IFileArchive::EAT_VIRTUAL_ALLOC:IFileArchive::EAT_NULL; - items.push_back(item); - itemsMetadata.push_back(header); } } @@ -302,64 +341,6 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: } #if 0 -bool CFileArchiveZip::scanZipHeader(size_t& offset, bool ignoreGPBits) -{ - - // if bit 3 was set, use CentralDirectory for setup - if (!ignoreGPBits && entry.header.GeneralBitFlag & ZIP_INFO_IN_DATA_DESCRIPTOR) - { - SZIPFileCentralDirEnd dirEnd; - m_fileInfo.clear(); - m_files.clear(); - // First place where the end record could be stored - offset = m_file->getSize() - 22; - const char endID[] = { 0x50, 0x4b, 0x05, 0x06, 0x0 }; - char tmp[5] = { '\0' }; - bool found = false; - // search for the end record ID - while (!found && offset > 0) - { - int seek = 8; - { - system::future fut; - m_file->read(fut, tmp, offset, 4); - fut.get(); - offset += 4; - } - switch (tmp[0]) - { - case 0x50: - if (!strcmp(endID, tmp)) - { - seek = 4; - found = true; - } - break; - case 0x4b: - seek = 5; - break; - case 0x05: - seek = 6; - break; - case 0x06: - seek = 7; - break; - } - offset -= seek; - } - { - system::future fut; - m_file->read(fut, &dirEnd, offset, sizeof(dirEnd)); - fut.get(); - offset += sizeof(dirEnd); - } - m_fileInfo.reserve(dirEnd.TotalEntries); - offset = dirEnd.Offset; - while (scanCentralDirectoryHeader(offset)) {} - return false; - } -} - bool CFileArchiveZip::scanCentralDirectoryHeader(size_t& offset) { std::filesystem::path ZipFileName = ""; @@ -384,121 +365,11 @@ bool CFileArchiveZip::scanCentralDirectoryHeader(size_t& offset) m_files.back().size = entry.UncompressedSize; return true; } - -core::smart_refctd_ptr CFileArchiveZip::readFile_impl(const SOpenFileParams& params) -{ - - const SZipFileEntry& e = m_fileInfo[found->ID]; - wchar_t buf[64]; - - uint8_t* decryptedBuf = 0; - uint32_t decryptedSize = e.header.DataDescriptor.CompressedSize; -#ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ - if ((e.header.GeneralBitFlag & ZIP_FILE_ENCRYPTED) && (e.header.CompressionMethod == 99)) - { - size_t readOffset; - - uint8_t salt[16] = { 0 }; - const uint16_t saltSize = (((e.header.Sig & 0x00ff0000) >> 16) + 1) * 4; - { - readOffset = e.Offset; - read_blocking(m_file.get(), salt, readOffset, saltSize); - readOffset += saltSize; - } - char pwVerification[2]; - char pwVerificationFile[2]; - { - read_blocking(m_file.get(), pwVerification, readOffset, 2); - readOffset += 2; - } - fcrypt_ctx zctx; // the encryption context - int rc = fcrypt_init( - (e.header.Sig & 0x00ff0000) >> 16, - (const unsigned char*)m_password.c_str(), // the password - m_password.size(), // number of bytes in password - salt, // the salt - (unsigned char*)pwVerificationFile, // on return contains password verifier - &zctx); // encryption context - if (strncmp(pwVerificationFile, pwVerification, 2)) - { - m_logger.log("Wrong password", ILogger::ELL_ERROR); - return 0; - } - decryptedSize = e.header.DataDescriptor.CompressedSize - saltSize - 12; - decryptedBuf = new uint8_t[decryptedSize]; - // - constexpr uint32_t kChunkSize = 0x8000u; - uint32_t c = 0; - while ((c + kChunkSize) <= decryptedSize) - { - { - read_blocking(m_file.get(), decryptedBuf + c, readOffset, kChunkSize); - readOffset += kChunkSize; - } - fcrypt_decrypt( - decryptedBuf + c, // pointer to the data to decrypt - kChunkSize, // how many bytes to decrypt - &zctx); // decryption context - c += kChunkSize; - } - { - read_blocking(m_file.get(), decryptedBuf + c, readOffset, decryptedSize - c); - readOffset += decryptedSize - c; - } - fcrypt_decrypt( - decryptedBuf + c, // pointer to the data to decrypt - decryptedSize - c, // how many bytes to decrypt - &zctx); // decryption context - - char fileMAC[10]; - char resMAC[10]; - rc = fcrypt_end( - (unsigned char*)resMAC, // on return contains the authentication code - &zctx); // encryption context - if (rc != 10) - { - m_logger.log("Error on encryption closing", ILogger::ELL_ERROR); - delete[] decryptedBuf; - return 0; - } - { - read_blocking(m_file.get(), fileMAC, readOffset, 10); - readOffset += 10; - } - if (strncmp(fileMAC, resMAC, 10)) - { - m_logger.log("Error on encryption check", ILogger::ELL_ERROR); - delete[] decryptedBuf; - return 0; - } - decrypted = core::make_smart_refctd_ptr>(core::smart_refctd_ptr(m_system), found->fullName, IFile::ECF_READ_WRITE, decryptedSize); - - { - write_blocking(decrypted.get(), decryptedBuf, 0, decryptedSize); - } - actualCompressionMethod = (e.header.Sig & 0xffff); -#if 0 - if ((e.header.Sig & 0xff000000) == 0x01000000) - { - } - else if ((e.header.Sig & 0xff000000) == 0x02000000) - { - } - else - { - m_logger.log("Unknown encryption method", ILogger::ELL_ERROR); - return 0; - } -#endif - } -#endif -} #endif CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFileArchive::SListEntry* item) { - CFileArchive::file_buffer_t retval = {nullptr,item->size,nullptr}; - + const auto& header = m_itemsMetadata[item->ID]; // Nabla supports 0, 8, 12, 14, 99 //0 - The file is stored (no compression) //1 - The file is Shrunk @@ -517,8 +388,9 @@ CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFi //97 - WavPack - Compression Method, WinZip 11 //98 - PPMd - Compression Method, WinZip 10 //99 - AES encryption, WinZip 9 - int16_t actualCompressionMethod = m_itemsMetadata[item->ID].CompressionMethod; + int16_t actualCompressionMethod = header.CompressionMethod; + CFileArchive::file_buffer_t retval = { nullptr,item->size,nullptr }; // void* decrypted = nullptr; size_t decryptedSize = 0ull; @@ -540,21 +412,83 @@ CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFi const auto* const cFile = m_file.get(); void* const filePtr = const_cast(cFile->getMappedPointer()); - std::byte* const mmapPtr = reinterpret_cast(filePtr)+item->offset; + std::byte* mmapPtr = reinterpret_cast(filePtr)+item->offset; // decrypt - if (false) + if ((header.GeneralBitFlag&ZIP_FILE_ENCRYPTED) && (header.CompressionMethod==99)) { + const uint8_t* salt = reinterpret_cast(mmapPtr); + #ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ + const uint16_t saltSize = ((header.Sig>>14u)&0x3fcu)+4u; + { + const size_t reduction = saltSize+12u; + if (header.DataDescriptor.CompressedSize<=reduction) + return retval; + decryptedSize = header.DataDescriptor.CompressedSize-reduction; + } + mmapPtr += saltSize; + uint16_t& pwVerification = *reinterpret_cast(mmapPtr); + mmapPtr += 2u; + uint16_t pwVerificationFile; + + fcrypt_ctx zctx; // the encryption context + int rc = fcrypt_init( + (header.Sig>>16u)&0xffu, + (const unsigned char*)m_password.c_str(), // the password + m_password.size(), // number of bytes in password + salt, // the salt + (unsigned char*)&pwVerificationFile, // on return contains password verifier + &zctx + ); // encryption context + if (pwVerification!=pwVerificationFile) + { + m_logger.log("Wrong password for ZIP Archive.",ILogger::ELL_ERROR); + return retval; + } + if (actualCompressionMethod) decrypted = CPlainHeapAllocator(nullptr).alloc(decryptedSize); else decrypted = VirtualMemoryAllocator(nullptr).alloc(decryptedSize); + if (!decrypted) + #endif + return retval; + #ifdef _NBL_COMPILE_WITH_ZIP_ENCRYPTION_ + constexpr uint32_t kChunkSize = 0x8000u; + for (size_t offset=0u; offset(decryptedSize-offset,kChunkSize); + fcrypt_decrypt( + reinterpret_cast(decrypted)+offset, // pointer to the data to decrypt + size, // how many bytes to decrypt + &zctx // decryption context + ); + mmapPtr += size; + } + char resMAC[10]; + rc = fcrypt_end( + (unsigned char*)resMAC, // on return contains the authentication code + &zctx // encryption context + ); + if (rc != 10) + { + m_logger.log("Error on encryption closing",ILogger::ELL_ERROR); + return retval; + } + const char* fileMAC = reinterpret_cast(mmapPtr); + mmapPtr += 10; + if (strncmp(fileMAC,resMAC,10)) + { + m_logger.log("Error on encryption check", ILogger::ELL_ERROR); + return retval; + } + + actualCompressionMethod = (header.Sig & 0xffff); + #endif } // if (actualCompressionMethod) { - // TODO - //const uint32_t uncompressedSize = e.header.DataDescriptor.UncompressedSize; decompressed = VirtualMemoryAllocator(nullptr).alloc(item->size); if (!decompressed) { @@ -642,7 +576,7 @@ CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFi pcData + sizeof(uint32_t) + propSize, &tmpSrcSize, pcData + sizeof(uint32_t), propSize, - (m_itemsMetadata[item->ID].GeneralBitFlag&0x1u) ? LZMA_FINISH_END:LZMA_FINISH_ANY, &status, + (header.GeneralBitFlag&0x1u) ? LZMA_FINISH_END:LZMA_FINISH_ANY, &status, &lzmaAlloc ); diff --git a/src/nbl/system/CFileViewAPKAllocator.cpp b/src/nbl/system/CFileViewAPKAllocator.cpp index bb7c6bbaf5..7ca9c163b2 100644 --- a/src/nbl/system/CFileViewAPKAllocator.cpp +++ b/src/nbl/system/CFileViewAPKAllocator.cpp @@ -4,7 +4,7 @@ using namespace nbl::system; #ifdef _NBL_PLATFORM_ANDROID_ #include -#include +#include void* CFileViewAPKAllocator::alloc(size_t size) { From 8ea64c975e06bbd119816344eff567127976f593 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 11:39:20 +0100 Subject: [PATCH 75/91] Fix PNG writer, and signed/unsigned comparison with ZIP archives. P.S. Also android fixes. --- .../nbl/system/ICancellableAsyncQueueDispatcher.h | 1 + include/nbl/system/ISystemPOSIX.h | 2 ++ src/nbl/asset/interchange/CImageWriterPNG.cpp | 12 ++++++------ src/nbl/system/CArchiveLoaderZip.cpp | 2 +- src/nbl/system/CSystemAndroid.cpp | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/nbl/system/ICancellableAsyncQueueDispatcher.h b/include/nbl/system/ICancellableAsyncQueueDispatcher.h index db68361814..594dd7af16 100644 --- a/include/nbl/system/ICancellableAsyncQueueDispatcher.h +++ b/include/nbl/system/ICancellableAsyncQueueDispatcher.h @@ -186,6 +186,7 @@ class ICancellableAsyncQueueDispatcher : public IAsyncQueueDispatcher createFile(const std::filesystem::path& filename, const core::bitflag flags) override; }; diff --git a/src/nbl/asset/interchange/CImageWriterPNG.cpp b/src/nbl/asset/interchange/CImageWriterPNG.cpp index 5ec524b7d8..0c3296344b 100644 --- a/src/nbl/asset/interchange/CImageWriterPNG.cpp +++ b/src/nbl/asset/interchange/CImageWriterPNG.cpp @@ -52,13 +52,13 @@ void PNGAPI user_write_data_fcn(png_structp png_ptr, png_bytep data, png_size_t //check=(png_size_t) file->write((const void*)data,(uint32_t)length); auto usrData = (CImageWriterPNG::SContext*)png_get_user_chunk_ptr(png_ptr); - system::ISystem::future_t future; - file->write(future, data, usrData->file_pos, length); - usrData->file_pos += future.get(); - png_set_read_user_chunk_fn(png_ptr, usrData, nullptr); - - if (future.get() != length) + system::IFile::success_t success; + file->write(success, data, usrData->file_pos, length); + if (!success) png_error(png_ptr, "Write Error"); + + usrData->file_pos += success.getSizeToProcess(); + png_set_read_user_chunk_fn(png_ptr, usrData, nullptr); } #endif // _NBL_COMPILE_WITH_LIBPNG_ diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index 0442d66be3..9702694c11 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -78,7 +78,7 @@ enum E_GZIP_FLAGS }; struct SZipFileExtraHeader { - int16_t ID; + uint16_t ID; int16_t Size; }; diff --git a/src/nbl/system/CSystemAndroid.cpp b/src/nbl/system/CSystemAndroid.cpp index c42d4a08be..65d84c8b1a 100644 --- a/src/nbl/system/CSystemAndroid.cpp +++ b/src/nbl/system/CSystemAndroid.cpp @@ -28,7 +28,7 @@ ISystem::SystemInfo CSystemAndroid::getSystemInfo() const { SystemInfo info; // TODO: hardcoded - info.cpuFrequency = 1100; + info.cpuFrequencyHz = 1100000000; info.totalMemory = 4ull<<30ull; info.availableMemory = 2ull<<30ull; From ccc026f00d60b7995cda187fce03f11a1d62408b Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 17:14:43 +0100 Subject: [PATCH 76/91] Bullet example has a bug, remove ex 19 --- examples_tests/14.ComputeScan/main.cpp | 2 +- .../17.SimpleBulletIntegration/main.cpp | 3 + .../CMakeLists.txt | 7 - .../19.SIMDmatrixMultiplication/main.cpp | 491 ------------------ examples_tests/CMakeLists.txt | 2 +- examples_tests/Readme.md | 4 +- src/nbl/asset/interchange/CGLSLLoader.h | 2 +- 7 files changed, 8 insertions(+), 503 deletions(-) delete mode 100644 examples_tests/19.SIMDmatrixMultiplication/CMakeLists.txt delete mode 100644 examples_tests/19.SIMDmatrixMultiplication/main.cpp diff --git a/examples_tests/14.ComputeScan/main.cpp b/examples_tests/14.ComputeScan/main.cpp index 1b76d19381..3872d66075 100644 --- a/examples_tests/14.ComputeScan/main.cpp +++ b/examples_tests/14.ComputeScan/main.cpp @@ -22,7 +22,7 @@ class ComputeScanApp : public NonGraphicalApplicationBase { CommonAPI::InitOutput initOutput; initOutput.system = core::smart_refctd_ptr(system); - CommonAPI::InitWithNoExt(initOutput, video::EAT_OPENGL_ES, "Subgroup Arithmetic Test"); + CommonAPI::InitWithNoExt(initOutput, video::EAT_OPENGL, "Subgroup Arithmetic Test"); system = std::move(initOutput.system); auto gl = std::move(initOutput.apiConnection); auto logger = std::move(initOutput.logger); diff --git a/examples_tests/17.SimpleBulletIntegration/main.cpp b/examples_tests/17.SimpleBulletIntegration/main.cpp index 972fcb9ea5..c2fc745e0d 100644 --- a/examples_tests/17.SimpleBulletIntegration/main.cpp +++ b/examples_tests/17.SimpleBulletIntegration/main.cpp @@ -520,6 +520,7 @@ class BulletSampleApp : public ApplicationBase asset::SPushConstantRange range[1] = { asset::IShader::ESS_VERTEX,0u,sizeof(core::matrix4SIMD) }; cpuLayout = core::make_smart_refctd_ptr(range, range + 1u, std::move(dsLayout)); } + cpu2gpuParams.beginCommandBuffers(); m_gpuLayout = CPU2GPU.getGPUObjectsFromAssets(&cpuLayout.get(), &cpuLayout.get() + 1, cpu2gpuParams)->front(); { @@ -648,6 +649,8 @@ class BulletSampleApp : public ApplicationBase GPUObject ret = {}; ret.pool = pool; + cpu2gpuParams.waitForCreationToComplete(true); + cpu2gpuParams.beginCommandBuffers(); // get the mesh ret.gpuMesh = CPU2GPU.getGPUObjectsFromAssets(&cpuMesh, &cpuMesh + 1, cpu2gpuParams)->front(); asset::SBufferBinding instanceRedirectBufBnd; diff --git a/examples_tests/19.SIMDmatrixMultiplication/CMakeLists.txt b/examples_tests/19.SIMDmatrixMultiplication/CMakeLists.txt deleted file mode 100644 index 71c002ad52..0000000000 --- a/examples_tests/19.SIMDmatrixMultiplication/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ - -include(common RESULT_VARIABLE RES) -if(NOT RES) - message(FATAL_ERROR "common.cmake not found. Should be in {repo_root}/cmake directory") -endif() - -nbl_create_executable_project("" "" "" "") \ No newline at end of file diff --git a/examples_tests/19.SIMDmatrixMultiplication/main.cpp b/examples_tests/19.SIMDmatrixMultiplication/main.cpp deleted file mode 100644 index b54186f911..0000000000 --- a/examples_tests/19.SIMDmatrixMultiplication/main.cpp +++ /dev/null @@ -1,491 +0,0 @@ -// Copyright (C) 2018-2020 - DevSH Graphics Programming Sp. z O.O. -// This file is part of the "Nabla Engine". -// For conditions of distribution and use, see copyright notice in nabla.h - -#define _NBL_STATIC_LIB_ -#include -//#include -#include -#include "../common/CommonAPI.h" - -#include -#include -#include -#include -#include - -using namespace nbl; - -// _mm256_extractf128_ps for extracting hi part -// _mm256_castps256_ps128 for extracting lo part (no cycles!) - -#define EXEC_CNT (1e6) -#define BROADCAST32(fpx) _MM_SHUFFLE(fpx, fpx, fpx, fpx) - -#define AVX 0 // set to 0 or 1 (sse3/avx), set appropriate compiler flags and run -#define COL_MAJOR 0 // set to 0 or 1 (col-major/row-major) -#define VERIFY 0 - -#if AVX -#define ALIGN 32 -namespace avx -{ - - struct alignas(ALIGN) matrix4x3_row - { - float m[4][4]; - - matrix4x3_row(const float* _data = 0) - { - if (!_data) - return; - memcpy(m, _data, 16 * 4); - } - - inline matrix4x3_row concatenate(const matrix4x3_row& _other) - { - __m256 A01 = _mm256_load_ps(&m[0][0]); - __m256 A23 = _mm256_load_ps(&m[2][0]); - - matrix4x3_row out; - - _mm256_store_ps(&out.m[0][0], doJob(A01, _other)); - _mm256_store_ps(&out.m[2][0], doJob(A23, _other));//do special AVX 128bit ops to only load, calculate and store only one row - - return out; - } - - float& operator()(size_t _i, size_t _j) { return m[_i][_j]; } - const float& operator()(size_t _i, size_t _j) const { return m[_i][_j]; } - - private: - static inline __m256 doJob(__m256 _A01, const matrix4x3_row& _mtx) - { - const __m256 mask = _mm256_castsi256_ps(_mm256_setr_epi32(0, 0, 0, 0xffffffff, 0, 0, 0, 0xffffffff)); - - __m256 res; - res = _mm256_mul_ps(_mm256_shuffle_ps(_A01, _A01, BROADCAST32(0)), _mm256_broadcast_ps(reinterpret_cast(&_mtx.m[0][0]))); - res = _mm256_add_ps(res, _mm256_mul_ps(_mm256_shuffle_ps(_A01, _A01, BROADCAST32(1)), _mm256_broadcast_ps(reinterpret_cast(&_mtx.m[1][0])))); - res = _mm256_add_ps(res, _mm256_mul_ps(_mm256_shuffle_ps(_A01, _A01, BROADCAST32(2)), _mm256_broadcast_ps(reinterpret_cast(&_mtx.m[2][0])))); - res = _mm256_add_ps(res, _mm256_and_ps(_A01, mask)); - return res; - } - }; - - struct alignas(ALIGN) matrix4x3_col - { - float m[4][4]; - - matrix4x3_col(const float* _data = 0) - { - if (!_data) - return; - //printf("avx col ctor:\n"); - //for (size_t i = 0; i < 16; ++i) - // printf("%f ", _data[i]); - //printf("\n"); - memcpy(m, _data, 16 * 4); - } - - inline matrix4x3_col concatenate(const matrix4x3_col& _other) - { - __m256 A01 = _mm256_load_ps(&_other.m[0][0]); - __m256 A23 = _mm256_load_ps(&_other.m[2][0]); - - matrix4x3_col out; - - _mm256_store_ps(&out.m[0][0], doJob(A01, 0, *this)); - _mm256_store_ps(&out.m[2][0], doJob(A23, 2, *this)); - - return out; - } - - float& operator()(size_t _i, size_t _j) { return m[_j][_i]; } - const float& operator()(size_t _i, size_t _j) const { return m[_j][_i]; } - - private: - static inline __m256 doJob(__m256 _A01, size_t j, const matrix4x3_col& _mtx) - { - __m256 res; - res = _mm256_mul_ps(_mm256_shuffle_ps(_A01, _A01, BROADCAST32(0)), _mm256_broadcast_ps(reinterpret_cast(&_mtx.m[0][0]))); - res = _mm256_add_ps(res, _mm256_mul_ps(_mm256_shuffle_ps(_A01, _A01, BROADCAST32(1)), _mm256_broadcast_ps(reinterpret_cast(&_mtx.m[1][0])))); - res = _mm256_add_ps(res, _mm256_mul_ps(_mm256_shuffle_ps(_A01, _A01, BROADCAST32(2)), _mm256_broadcast_ps(reinterpret_cast(&_mtx.m[2][0])))); - if (j) - { - const __m256 mask = _mm256_castsi256_ps(_mm256_setr_epi32(0, 0, 0, 0, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff)); - res = _mm256_add_ps(res, _mm256_and_ps(mask, _mm256_broadcast_ps(reinterpret_cast(&_mtx.m[3][0])))); - } - return res; - } - }; - -} // avx -#endif - -#if !AVX -#define ALIGN 16 -namespace sse3 -{ - struct alignas(ALIGN) matrix4x3_row - { - float m[4][4]; - - matrix4x3_row(const float* _data = 0) - { - if (!_data) - return; - memcpy(m, _data, 16 * 4); - } - - inline matrix4x3_row concatenate(const matrix4x3_row& _other) - { - matrix4x3_row out; - - __m128 r0 = _mm_load_ps(m[0]); - __m128 r1 = _mm_load_ps(m[1]); - __m128 r2 = _mm_load_ps(m[2]); - __m128 r3 = _mm_load_ps(m[3]); - - _mm_store_ps(out.m[0], doJob(r0, _other)); - _mm_store_ps(out.m[1], doJob(r1, _other)); - _mm_store_ps(out.m[2], doJob(r2, _other)); - _mm_store_ps(out.m[3], r3); // 0 0 0 1 - - return out; - } - - float& operator()(size_t _i, size_t _j) { return m[_i][_j]; } - const float& operator()(size_t _i, size_t _j) const { return m[_i][_j]; } - - private: - static inline __m128 doJob(const __m128& a, const matrix4x3_row& _mtx) - { - __m128 res; - - __m128 r0 = _mm_load_ps(_mtx.m[0]); - __m128 r1 = _mm_load_ps(_mtx.m[1]); - __m128 r2 = _mm_load_ps(_mtx.m[2]); - __m128 r3 = _mm_load_ps(_mtx.m[3]); - - __m128 mask = _mm_castsi128_ps(_mm_setr_epi32(0, 0, 0, 0xffffffff)); - - res = _mm_mul_ps(_mm_shuffle_ps(a, a, BROADCAST32(0)), r0); - res = _mm_add_ps(res, _mm_mul_ps(_mm_shuffle_ps(a, a, BROADCAST32(1)), r1)); - res = _mm_add_ps(res, _mm_mul_ps(_mm_shuffle_ps(a, a, BROADCAST32(2)), r2)); - res = _mm_add_ps(res, _mm_and_ps(a, mask)); // always 0 0 0 a3 -- no shuffle needed - return res; - } - }; - - struct alignas(ALIGN) matrix4x3_col - { - float m[4][4]; - - matrix4x3_col(const float* _data = 0) - { - if (!_data) - return; - memcpy(m, _data, 16 * 4); - } - - inline matrix4x3_col concatenate(const matrix4x3_col& _other) - { - matrix4x3_col out; - - __m128 c0 = _mm_load_ps(_other.m[0]); - __m128 c1 = _mm_load_ps(_other.m[1]); - __m128 c2 = _mm_load_ps(_other.m[2]); - __m128 c3 = _mm_load_ps(_other.m[3]); - - _mm_store_ps(out.m[0], doJob(c0, 0, *this)); - _mm_store_ps(out.m[1], doJob(c1, 1, *this)); - _mm_store_ps(out.m[2], doJob(c2, 2, *this)); - _mm_store_ps(out.m[3], doJob(c3, 3, *this)); - - return out; - } - - float& operator()(size_t _i, size_t _j) { return m[_j][_i]; } - const float& operator()(size_t _i, size_t _j) const { return m[_j][_i]; } - - private: - static inline __m128 doJob(__m128 a, size_t j, const matrix4x3_col& _mtx) - { - __m128 res; - - __m128 c0 = _mm_load_ps(_mtx.m[0]); - __m128 c1 = _mm_load_ps(_mtx.m[1]); - __m128 c2 = _mm_load_ps(_mtx.m[2]); - __m128 c3 = _mm_load_ps(_mtx.m[3]); - - res = _mm_mul_ps(_mm_shuffle_ps(a, a, BROADCAST32(0)), c0); - res = _mm_add_ps(res, _mm_mul_ps(_mm_shuffle_ps(a, a, BROADCAST32(1)), c1)); - res = _mm_add_ps(res, _mm_mul_ps(_mm_shuffle_ps(a, a, BROADCAST32(2)), c2)); - if (j == 3) // w of every column except last one is 0; in the last one it's 1 - res = _mm_add_ps(res, c3); - return res; - } - }; // matrix4x3_col -} // sse3 -#endif - -struct matrix4x3_col_nosimd -{ - float m[4][4]; - - matrix4x3_col_nosimd(const float* _data = 0) - { - if (!_data) - return; - //printf("nosimd col ctor:\n"); - //for (size_t i = 0; i < 16; ++i) - // printf("%f ", _data[i]); - //printf("\n"); - memcpy(m, _data, 16*4); - } - - inline matrix4x3_col_nosimd concatenate(const matrix4x3_col_nosimd& _other) - { - matrix4x3_col_nosimd ret; - memset(ret.m, 0, 15*4); - ret.m[3][3] = 1.f; - for (int j = 0; j < 4; j++) - { - for (int i = 0; i < 3; i++) - { - float sum = 0; - for (int e = 0; e < 3; e++) - sum += (*this)(i, e) * _other(e, j); - if (j == 3) - sum += (*this)(i, 3); - ret(i, j) = sum; - } - } - return ret; - } - - float& operator()(size_t _i, size_t _j) { return m[_j][_i]; } - const float& operator()(size_t _i, size_t _j) const { return m[_j][_i]; } -}; - -struct matrix4x3_row_nosimd -{ - float m[4][4]; - - matrix4x3_row_nosimd(const float* _data = 0) - { - if (!_data) - return; - //printf("nosimd row ctor:\n"); - //for (size_t i = 0; i < 16; ++i) - // printf("%f ", _data[i]); - //printf("\n"); - memcpy(m, _data, 16 * 4); - } - - inline matrix4x3_row_nosimd concatenate(const matrix4x3_row_nosimd& _other) - { - matrix4x3_row_nosimd ret; - for (size_t i = 0; i < 4; i++) - { - for (size_t j = 0; j < 4; j++) - { - float sum = 0.f; - for (size_t e = 0; e < 4; e++) - { - sum += m[i][e] * _other.m[e][j]; - } - ret.m[i][j] = sum; - } - } - return ret; - } - - float& operator()(size_t _i, size_t _j) { return m[_i][_j]; } - const float& operator()(size_t _i, size_t _j) const { return m[_i][_j]; } -}; - -namespace measure -{ - using Clock = std::chrono::high_resolution_clock; - using TimePoint = std::chrono::time_point; - using Duration = std::chrono::duration; -} - -template -static bool compare(T* _m1, T* _m2); -template -static double run(void*, void*, void*); - -class SIMDMatrixMultiplicationSampleApp : public ApplicationBase -{ - core::smart_refctd_ptr system; - -public: - void setWindow(core::smart_refctd_ptr&& wnd) override - { - assert(false && "This example shouldn't have a window!"); - } - nbl::ui::IWindow* getWindow() override - { - assert(false && "This example shouldn't have a window!"); - return nullptr; - } - void setSystem(core::smart_refctd_ptr&& system) override - { - system = std::move(system); - } - - APP_CONSTRUCTOR(SIMDMatrixMultiplicationSampleApp); - - void onAppInitialized_impl() override - { - void* data = malloc(16 * 4 * (size_t)EXEC_CNT * 3 + ALIGN); - - uint8_t* alignedData = reinterpret_cast(data); - size_t offset = reinterpret_cast(alignedData) % ALIGN; - alignedData += ALIGN - offset; - - { - size_t i = 1; - for (float* p = (float*)alignedData; (void*)p != (void*)(alignedData + (size_t)EXEC_CNT * 16 * 4); ++p, ++i) - { -#if COL_MAJOR - if (i % 16 == 0) - *p = 1.f; - else if (i % 4 == 0) - *p = 0.f; - else - *p = rand(); -#else - size_t mod = i % 16; - if (mod == 0) - *p = 1.f; - else if (mod >= 13 && mod <= 15) - *p = 0.f; - else - *p = rand(); -#endif - } - } - - void* dataOut = alignedData + (16 * 4 * (size_t)EXEC_CNT); - void* nosimdOut = alignedData + 2 * (16 * 4 * (size_t)EXEC_CNT); - - double nosimdtime = 0.0; - double simdtime = 0.0; - - for (size_t i = 0; i < 100; ++i) - { -#if COL_MAJOR - nosimdtime += run(alignedData, nosimdOut, 0); -#else - nosimdtime += run(alignedData, nosimdOut, 0); -#endif - } - - for (size_t i = 0; i < 100; ++i) - { -#if AVX -#if COL_MAJOR - simdtime += run(alignedData, dataOut, nosimdOut); -#else - simdtime += run(alignedData, dataOut, nosimdOut); -#endif -#else -#if COL_MAJOR - simdtime += run(alignedData, dataOut, nosimdOut); -#else - simdtime += run(alignedData, dataOut, nosimdOut); -#endif -#endif - } - - printf("nosimd : %f\n", nosimdtime); -#if VERIFY - printf("SIMD time distorted by comparisons!\n"); -#endif -#if AVX -#if COL_MAJOR - printf("avx col: %f\n", simdtime); -#else - printf("avx row: %f\n", simdtime); -#endif -#else -#if COL_MAJOR - printf("sse3 col: %f\n", simdtime); -#else - printf("sse3 row: %f\n", simdtime); -#endif -#endif - free(data); - } - - void onAppTerminated_impl() override - { - } - - void workLoopBody() override - { - } - - bool keepRunning() override - { - return false; - } -}; - -NBL_COMMON_API_MAIN(SIMDMatrixMultiplicationSampleApp) - -template -static bool compare(T* _m1, T* _m2) -{ - const float size_thresh = 0.000001f; - - for (size_t i=0; i<4; i++) - for (size_t j=0; j<4; j++) - { - const float a = (*_m1)(i,j); - const float b = (*_m2)(i,j); - const uint32_t& aAsInt = reinterpret_cast(a); - const uint32_t& bAsInt = reinterpret_cast(b); - - if (abs(b)>size_thresh) - { - if (abs(1.f-abs(a/b))>0.001f) - { - //printf("%f,%f\n",a,b); - return false; - } - } - else if ( (aAsInt&0x80000000ull)!=(bAsInt&0x80000000ull) || abs(a)>size_thresh) - { - //printf("ZERO %f,%f\n",a,b); - return false; - } - } - return true; -} - -template -static double run(void* _data, void* _out, void* _cmp) -{ - const measure::TimePoint start = measure::Clock::now(); - - const float* const mtx = (float*)_data; - T* out = (T*)_out; - for (size_t i = 0; i < (size_t)EXEC_CNT-1; ++i) - { - T* m1 = (T*)(mtx+16*i), *m2 = (T*)(mtx+16*(i+1)); - out[i] = m1->concatenate(*m2); -#if VERIFY - if (_cmp && !compare(out+i, ((T*)_cmp)+i)) - { - printf("Matrices don't match!\n"); - } -#endif - } - - const measure::Duration dt = measure::Clock::now() - start; - return dt.count(); -} diff --git a/examples_tests/CMakeLists.txt b/examples_tests/CMakeLists.txt index d698e2d03b..3c2d7cd142 100644 --- a/examples_tests/CMakeLists.txt +++ b/examples_tests/CMakeLists.txt @@ -28,7 +28,7 @@ endif() if (NBL_BUILD_MITSUBA_LOADER) add_subdirectory(18.MitsubaLoader EXCLUDE_FROM_ALL) endif() -add_subdirectory(19.SIMDmatrixMultiplication EXCLUDE_FROM_ALL) +#REUSE 19 add_subdirectory(20.Megatexture EXCLUDE_FROM_ALL) add_subdirectory(21.DynamicTextureIndexing EXCLUDE_FROM_ALL) # TODO: revive if (NBL_BUILD_MITSUBA_LOADER) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 47f51420b0..473edff5da 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -45,10 +45,10 @@ N = No support | 11.LoDSystem | Y | N | B | S | N | S | N | S | | | 12.glTF | W | N | W | W | N | W | N | W | COMPILE_WITH_GLTF_LOADER | | FREE_SLOT | | | | | | | | | | -| 14.ComputeScan | B | N | B | S | N | S | N | S | | +| 14.ComputeScan | Y | Y | B | S | S | S | S | S | | | FREE_SLOT | | | | | | | | | | | 16.OrderIndependentTransparency | B | B | B | S | S | S | S | S | | -| 17.SimpleBulletIntegration | Y | N | Y | S | N | S | N | N | BUILD_BULLET | +| 17.SimpleBulletIntegration | B | N | B | S | N | S | N | N | BUILD_BULLET | | 18.MitsubaLoader | S | N | S | S | N | S | N | N | BUILD_MITSUBA_LOADER | | FREE_SLOT | | | | | | | | | | | 20.Megatexture | S | S | S | S | S | S | N | S | | diff --git a/src/nbl/asset/interchange/CGLSLLoader.h b/src/nbl/asset/interchange/CGLSLLoader.h index 7a9cc19f6a..f357832a88 100644 --- a/src/nbl/asset/interchange/CGLSLLoader.h +++ b/src/nbl/asset/interchange/CGLSLLoader.h @@ -40,7 +40,7 @@ class CGLSLLoader final : public asset::IAssetLoader readPos += sizeof(tmp); continue; } - readPos += found - end; + readPos += found-tmp; } return false; From 0dbb22f5532f6c6604b0956a44030f5060f0eee0 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 17:35:41 +0100 Subject: [PATCH 77/91] Fix example 27, but Vulkan still has errors --- examples_tests/27.PLYSTLDemo/main.cpp | 26 ++++++++++++------- examples_tests/Readme.md | 2 +- .../utilities/IGPUObjectFromAssetConverter.h | 9 ++++--- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/examples_tests/27.PLYSTLDemo/main.cpp b/examples_tests/27.PLYSTLDemo/main.cpp index c381bcfe20..cc54f9eba3 100644 --- a/examples_tests/27.PLYSTLDemo/main.cpp +++ b/examples_tests/27.PLYSTLDemo/main.cpp @@ -149,7 +149,7 @@ APP_CONSTRUCTOR(PLYSTLDemo) const auto swapchainImageUsage = static_cast(asset::IImage::EUF_COLOR_ATTACHMENT_BIT); const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN); - CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "plystldemo", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); + CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL/*Vulkan doesn't work yet*/, "plystldemo", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); window = std::move(initOutput.window); gl = std::move(initOutput.apiConnection); surface = std::move(initOutput.surface); @@ -194,19 +194,23 @@ APP_CONSTRUCTOR(PLYSTLDemo) gpuComputeFence = logicalDevice->createFence(static_cast(0)); gpuComputeSemaphore = logicalDevice->createSemaphore(); - cpu2gpuParams.assetManager = assetManager.get(); + cpu2gpuParams.utilities = utilities.get(); cpu2gpuParams.device = logicalDevice.get(); - cpu2gpuParams.finalQueueFamIx = queues[decltype(initOutput)::EQT_GRAPHICS]->getFamilyIndex(); - cpu2gpuParams.limits = gpuPhysicalDevice->getLimits(); + cpu2gpuParams.assetManager = assetManager.get(); cpu2gpuParams.pipelineCache = nullptr; - cpu2gpuParams.sharingMode = nbl::asset::ESM_CONCURRENT; - cpu2gpuParams.utilities = utilities.get(); + cpu2gpuParams.limits = gpuPhysicalDevice->getLimits(); + cpu2gpuParams.finalQueueFamIx = queues[decltype(initOutput)::EQT_GRAPHICS]->getFamilyIndex(); + cpu2gpuParams.sharingMode = nbl::asset::ESM_EXCLUSIVE; - cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].semaphore = &gpuTransferSemaphore; + logicalDevice->createCommandBuffers(commandPools[CommonAPI::InitOutput::EQT_TRANSFER_UP].get(),video::IGPUCommandBuffer::EL_PRIMARY,1u,&cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].cmdbuf); cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].queue = queues[decltype(initOutput)::EQT_TRANSFER_UP]; - - cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].semaphore = &gpuComputeSemaphore; + cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].semaphore = &gpuTransferSemaphore; + + logicalDevice->createCommandBuffers(commandPools[CommonAPI::InitOutput::EQT_COMPUTE].get(),video::IGPUCommandBuffer::EL_PRIMARY,1u,&cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].cmdbuf); cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].queue = queues[decltype(initOutput)::EQT_COMPUTE]; + cpu2gpuParams.perQueue[nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].semaphore = &gpuComputeSemaphore; + + cpu2gpuParams.beginCommandBuffers(); } auto loadAndGetCpuMesh = [&](system::path path) -> std::pair, const asset::IAssetMetadata*> @@ -336,6 +340,8 @@ APP_CONSTRUCTOR(PLYSTLDemo) core::smart_refctd_ptr gpumesh; { auto gpu_array = cpu2gpu.getGPUObjectsFromAssets(&cpuMesh.get(), &cpuMesh.get() + 1, cpu2gpuParams); + cpu2gpuParams.waitForCreationToComplete(true); + cpu2gpuParams.beginCommandBuffers(); if (!gpu_array || gpu_array->size() < 1u || !(*gpu_array)[0]) assert(false); @@ -370,7 +376,7 @@ APP_CONSTRUCTOR(PLYSTLDemo) core::vectorSIMDf cameraPosition(0, 5, -10); matrix4SIMD projectionMatrix = matrix4SIMD::buildProjectionMatrixPerspectiveFovLH(core::radians(60.0f), float(WIN_W) / WIN_H, 0.001, 1000); - camera = Camera(cameraPosition, core::vectorSIMDf(0, 0, 0), projectionMatrix, 10.f, 1.f); + camera = Camera(cameraPosition, core::vectorSIMDf(0, 0, 0), projectionMatrix, 0.01f, 1.f); lastTime = std::chrono::system_clock::now(); for (size_t i = 0ull; i < NBL_FRAMES_TO_AVERAGE; ++i) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 473edff5da..0f9e52b057 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -58,7 +58,7 @@ N = No support | FREE_SLOT | | | | | | | | | | | 25.Blur | S | N | S | S | N | S | N | S | | | FREE_SLOT | | | | | | | | | | -| 27.PLYSTLDemo | Y | Y | Y | S | S | S | N | N | COMPILE_WITH_STL_LOADER & COMPILE_WITH_PLY_LOADER | +| 27.PLYSTLDemo | Y | Y | B | S | S | S | N | N | COMPILE_WITH_STL_LOADER & COMPILE_WITH_PLY_LOADER | | FREE_SLOT | | | | | | | | | | | 29.SpecializationConstants | S | S | S | S | S | S | N | S | | | FREE_SLOT | | | | | | | | | | diff --git a/include/nbl/video/utilities/IGPUObjectFromAssetConverter.h b/include/nbl/video/utilities/IGPUObjectFromAssetConverter.h index 27fcf2af7f..b2b822c239 100644 --- a/include/nbl/video/utilities/IGPUObjectFromAssetConverter.h +++ b/include/nbl/video/utilities/IGPUObjectFromAssetConverter.h @@ -157,10 +157,13 @@ class IGPUObjectFromAssetConverter if (pFence && pFence.get()) // user wanted, and something actually got submitted fence_ptrs[count++] = pFence.get(); } - device->blockForFences(count,fence_ptrs); - if(resetFencesAfterWait) + if (count) { - device->resetFences(count, fence_ptrs); + device->blockForFences(count,fence_ptrs); + if(resetFencesAfterWait) + { + device->resetFences(count, fence_ptrs); + } } setFencesToNull(); resetCommandBuffers(); From 07c2ff8b78b998f96139e4e0516ab8db8aef274b Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 17:44:56 +0100 Subject: [PATCH 78/91] Fix IFileArchive and check that ex 29 is bugged --- examples_tests/29.SpecializationConstants/main.cpp | 3 +-- examples_tests/Readme.md | 2 +- include/nbl/system/IFileArchive.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/examples_tests/29.SpecializationConstants/main.cpp b/examples_tests/29.SpecializationConstants/main.cpp index 8c3c8d87d1..be122653e3 100644 --- a/examples_tests/29.SpecializationConstants/main.cpp +++ b/examples_tests/29.SpecializationConstants/main.cpp @@ -6,7 +6,6 @@ #include #include "../common/CommonAPI.h" -// #include "CFileSystem.h" using namespace nbl; using namespace core; using namespace ui; @@ -155,7 +154,7 @@ class SpecializationConstantsSampleApp : public ApplicationBase initOutp.system = system; CommonAPI::Init( initOutp, - video::EAT_OPENGL, + video::EAT_VULKAN, "29.SpecializationConstants", requiredInstanceFeatures, optionalInstanceFeatures, diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 0f9e52b057..10f68b43e0 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -60,7 +60,7 @@ N = No support | FREE_SLOT | | | | | | | | | | | 27.PLYSTLDemo | Y | Y | B | S | S | S | N | N | COMPILE_WITH_STL_LOADER & COMPILE_WITH_PLY_LOADER | | FREE_SLOT | | | | | | | | | | -| 29.SpecializationConstants | S | S | S | S | S | S | N | S | | +| 29.SpecializationConstants | B | B | B | S | S | S | N | S | | | FREE_SLOT | | | | | | | | | | | FREE_SLOT | | | | | | | | | | | FREE_SLOT | | | | | | | | | | diff --git a/include/nbl/system/IFileArchive.h b/include/nbl/system/IFileArchive.h index 68dbc02773..5ed485f1a1 100644 --- a/include/nbl/system/IFileArchive.h +++ b/include/nbl/system/IFileArchive.h @@ -81,7 +81,7 @@ class IFileArchive : public core::IReferenceCounted { const IFileArchive::SListEntry itemToFind = { pathRelativeToArchive }; const auto found = std::lower_bound(m_items.begin(),m_items.end(),itemToFind); - if (found!=m_items.end() || found->pathRelativeToArchive!=pathRelativeToArchive) + if (found==m_items.end() || found->pathRelativeToArchive!=pathRelativeToArchive) return nullptr; return &(*found); } From 125f21dff2f3ff3a36907d78856297d23fb020c5 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 17:59:46 +0100 Subject: [PATCH 79/91] Fixed EXR Loader --- examples_tests/CMakeLists.txt | 8 +- examples_tests/Readme.md | 2 +- .../asset/interchange/CImageLoaderOpenEXR.cpp | 979 +++++++++--------- 3 files changed, 496 insertions(+), 493 deletions(-) diff --git a/examples_tests/CMakeLists.txt b/examples_tests/CMakeLists.txt index 3c2d7cd142..d93d3ad3b0 100644 --- a/examples_tests/CMakeLists.txt +++ b/examples_tests/CMakeLists.txt @@ -59,17 +59,17 @@ add_subdirectory(45.BRDFEvalTest EXCLUDE_FROM_ALL) add_subdirectory(46.SamplingValidation EXCLUDE_FROM_ALL) add_subdirectory(47.DerivMapTest EXCLUDE_FROM_ALL) add_subdirectory(48.ArithmeticUnitTest EXCLUDE_FROM_ALL) - add_subdirectory(49.ComputeFFT EXCLUDE_FROM_ALL) add_subdirectory(50.NewAPITest EXCLUDE_FROM_ALL) add_subdirectory(51.RadixSort EXCLUDE_FROM_ALL) add_subdirectory(52.SystemTest EXCLUDE_FROM_ALL) - add_subdirectory(53.ComputeShaders EXCLUDE_FROM_ALL) add_subdirectory(54.Transformations EXCLUDE_FROM_ALL) add_subdirectory(55.RGB18E7S3 EXCLUDE_FROM_ALL) add_subdirectory(56.RayQuery EXCLUDE_FROM_ALL) -add_subdirectory(57.AndroidSample EXCLUDE_FROM_ALL) -add_subdirectory(58.MediaUnpackingOnAndroid EXCLUDE_FROM_ALL) +if (NOT NBL_BUILD_ANDROID) + add_subdirectory(57.AndroidSample EXCLUDE_FROM_ALL) + add_subdirectory(58.MediaUnpackingOnAndroid EXCLUDE_FROM_ALL) +endif() add_subdirectory(60.ClusteredRendering EXCLUDE_FROM_ALL) add_subdirectory(0.ImportanceSamplingEnvMaps EXCLUDE_FROM_ALL) #TODO: integrate back into 42 diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 10f68b43e0..a5af2a006f 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -87,7 +87,7 @@ N = No support | 53.ComputeShaders | S | N | S | S | N | S | N | S | | | 54.Transformations | S | S | S | S | S | S | S | S | | | 55.RGB18E7S3 | S | S | S | S | S | S | N | N | | -| 56.RayQuery | N | N | S | N | N | S | N | S | | +| 56.RayQuery | N | N | Y | N | N | S | N | S | | | 57.AndroidSample | N | N | N | N | N | N | S | S | | | 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | | | FREE_SLOT | | | | | | | | | | diff --git a/src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp b/src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp index 582f76b0ae..37ec567d4c 100644 --- a/src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp +++ b/src/nbl/asset/interchange/CImageLoaderOpenEXR.cpp @@ -44,566 +44,569 @@ SOFTWARE. namespace IMF = Imf; namespace IMATH = Imath; -namespace nbl +namespace nbl::asset +{ +using namespace IMF; +using namespace IMATH; + +namespace impl { - namespace asset - { - using namespace IMF; - using namespace IMATH; - namespace impl +class nblIStream : public IMF::IStream +{ + public: + nblIStream(system::IFile* _nblFile) + : IMF::IStream(getFileName(_nblFile).c_str()), nblFile(_nblFile) {} + virtual ~nblIStream() {} + + //------------------------------------------------------ + // Read from the stream: + // + // read(c,n) reads n bytes from the stream, and stores + // them in array c. If the stream contains less than n + // bytes, or if an I/O error occurs, read(c,n) throws + // an exception. If read(c,n) reads the last byte from + // the file it returns false, otherwise it returns true. + //------------------------------------------------------ + + virtual bool read(char c[/*n*/], int n) override { - class nblIStream : public IMF::IStream - { - public: - nblIStream(system::IFile* _nblFile) - : IMF::IStream(getFileName(_nblFile).c_str()), nblFile(_nblFile) {} - virtual ~nblIStream() {} - - //------------------------------------------------------ - // Read from the stream: - // - // read(c,n) reads n bytes from the stream, and stores - // them in array c. If the stream contains less than n - // bytes, or if an I/O error occurs, read(c,n) throws - // an exception. If read(c,n) reads the last byte from - // the file it returns false, otherwise it returns true. - //------------------------------------------------------ - - virtual bool read(char c[/*n*/], int n) override - { - system::ISystem::future_t future; - nblFile->read(future, c, fileOffset, n); - fileOffset += future.get(); + system::ISystem::future_t future; + system::IFile::success_t success; + nblFile->read(future, c, fileOffset, n); + const auto bytesRead = future.get(); + fileOffset += bytesRead; - return future.get()==static_cast(n); - } - - //-------------------------------------------------------- - // Get the current reading position, in bytes from the - // beginning of the file. If the next call to read() will - // read the first byte in the file, tellg() returns 0. - //-------------------------------------------------------- - - virtual IMF::Int64 tellg() override - { - return static_cast(fileOffset); - } - - //------------------------------------------- - // Set the current reading position. - // After calling seekg(i), tellg() returns i. - //------------------------------------------- - - virtual void seekg(IMF::Int64 pos) override - { - fileOffset = static_cast(pos); - } - - //------------------------------------------------------ - // Clear error conditions after an operation has failed. - //------------------------------------------------------ - - virtual void clear() override - { - /* - Probably we don't want to investigate in system::IFile - and change the stream error state flags, leaving this - function empty - */ - } - - void resetFileOffset() - { - fileOffset = 0u; - } - - private: - - const std::string getFileName(system::IFile* _nblFile) - { - std::filesystem::path filename, extension; - core::splitFilename(_nblFile->getFileName(), nullptr, &filename, &extension); - return filename.string() + extension.string(); - } - - system::IFile* nblFile; - size_t fileOffset = {}; - }; + return bytesRead==static_cast(n); } - using suffixOfChannelBundle = std::string; - using channelName = std::string; // sytnax if as follows - using mapOfChannels = std::unordered_map; // suffix.channel, where channel are "R", "G", "B", "A" + //-------------------------------------------------------- + // Get the current reading position, in bytes from the + // beginning of the file. If the next call to read() will + // read the first byte in the file, tellg() returns 0. + //-------------------------------------------------------- - class SContext; - bool readVersionField(IMF::IStream* nblIStream, SContext& ctx, const system::logger_opt_ptr); - bool readHeader(IMF::IStream* nblIStream, SContext& ctx); - template - void readRgba(InputFile& file, std::array, 4>& pixelRgbaMapArray, int& width, int& height, E_FORMAT& format, const suffixOfChannelBundle suffixOfChannels); - E_FORMAT specifyIrrlichtEndFormat(const mapOfChannels& mapOfChannels, const suffixOfChannelBundle suffixName, const std::string fileName, const system::logger_opt_ptr logger); - - //! A helpful struct for handling OpenEXR layout - /* - The latest OpenEXR file consists of the following components: - - magic number - - version field - - header - - line offset table - - scan line blocks - */ - - struct SContext + virtual IMF::Int64 tellg() override { - constexpr static uint32_t magicNumber = 20000630ul; // 0x76, 0x2f, 0x31, 0x01 + return static_cast(fileOffset); + } - struct VersionField - { - uint32_t mainDataRegisterField = 0ul; // treated as 2 seperate bit fields, contains some usefull data - uint8_t fileFormatVersionNumber = 0; // contains current OpenEXR version. It has to be 0 upon initialization! - bool doesFileContainLongNames; // if set, the maximum length of attribute names, attribute type names and channel names is 255 bytes. Otherwise 31 bytes - bool doesItSupportDeepData; // if set, there is at least one part which is not a regular scan line image or regular tiled image, so it is a deep format - - struct Compoment - { - enum CompomentType - { - SINGLE_PART_FILE, - MULTI_PART_FILE - }; - - enum SinglePartFileCompoments - { - NONE, - SCAN_LINES, - TILES, - SCAN_LINES_OR_TILES - }; - - CompomentType type; - SinglePartFileCompoments singlePartFileCompomentSubTypes; - - } Compoment; - - } versionField; - - struct Attributes - { - // The header of every OpenEXR file must contain at least the following attributes - //according to https://www.openexr.com/documentation/openexrfilelayout.pdf (page 8) - const Channel* channels = nullptr; - const Compression* compression = nullptr; - const Box2i* dataWindow = nullptr; - const Box2i* displayWindow = nullptr; - const LineOrder* lineOrder = nullptr; - const float* pixelAspectRatio = nullptr; - const V2f* screenWindowCenter = nullptr; - const float* screenWindowWidth = nullptr; + //------------------------------------------- + // Set the current reading position. + // After calling seekg(i), tellg() returns i. + //------------------------------------------- - // These attributes are required in the header for all multi - part and /or deep data OpenEXR files - const std::string* name = nullptr; - const std::string* type = nullptr; - const int* version = nullptr; - const int* chunkCount = nullptr; + virtual void seekg(IMF::Int64 pos) override + { + fileOffset = static_cast(pos); + } - // This attribute is required in the header for all files which contain deep data (deepscanline or deeptile) - const int* maxSamplesPerPixel = nullptr; + //------------------------------------------------------ + // Clear error conditions after an operation has failed. + //------------------------------------------------------ - // This attribute is required in the header for all files which contain one or more tiles - const TileDescription* tiles = nullptr; + virtual void clear() override + { + /* + Probably we don't want to investigate in system::IFile + and change the stream error state flags, leaving this + function empty + */ + } - // This attribute can be used in the header for multi-part files - const std::string* view = nullptr; + void resetFileOffset() + { + fileOffset = 0u; + } - // Others not required that can be used by metadata - // - none at the moment + private: - } attributes; + const std::string getFileName(system::IFile* _nblFile) + { + std::filesystem::path filename, extension; + core::splitFilename(_nblFile->getFileName(), nullptr, &filename, &extension); + return filename.string() + extension.string(); + } - // core::smart_refctd_dynamic_array offsetTable; + system::IFile* nblFile; + size_t fileOffset = {}; +}; - // scan line blocks - }; +} - constexpr uint8_t availableChannels = 4; - struct PerImageData - { - ICPUImage::SCreationParams params; - std::array, availableChannels> halfPixelMapArray; - std::array, availableChannels> fullFloatPixelMapArray; - std::array, availableChannels> uint32_tPixelMapArray; - }; - template - struct ReadTexels - { - ReadTexels(ICPUImage* image, const std::array, availableChannels>& _pixelMapArray) : - data(reinterpret_cast(image->getBuffer()->getPointer())), pixelMapArray(_pixelMapArray) - { - using StreamFromEXR = CRegionBlockFunctorFilter,false>; - typename StreamFromEXR::state_type state(*this,image,image->getRegions().begin()); - StreamFromEXR::execute(core::execution::par_unseq,&state); - } - - inline void operator()(uint32_t ptrOffset, const core::vectorSIMDu32& texelCoord) - { - assert(texelCoord.w==0u && texelCoord.z==0u); - - uint8_t* texelPtr = data+ptrOffset; - for (auto channelIndex=0; channelIndex::type*>(texelPtr)[channelIndex] = element; - } - } - - private: - uint8_t* const data; - const std::array, availableChannels>& pixelMapArray; - }; - - auto getChannels(const InputFile& file) - { - std::unordered_map irrChannels; // example: G, albedo.R, color.space.B - { - auto channels = file.header().channels(); - for (auto mapItr = channels.begin(); mapItr != channels.end(); ++mapItr) - { - std::string fetchedChannelName = mapItr.name(); - const bool isThereAnySuffix = fetchedChannelName.size() > 1; - - if (isThereAnySuffix) - { - const auto endPositionOfChannelName = fetchedChannelName.find_last_of("."); - auto suffix = fetchedChannelName.substr(0, endPositionOfChannelName); - auto channel = fetchedChannelName.substr(endPositionOfChannelName + 1); - if (channel == "R" || channel == "G" || channel == "B" || channel == "A") - (irrChannels[suffix])[channel] = mapItr.channel(); - } - else - (irrChannels[""])[fetchedChannelName] = mapItr.channel(); - } - } - return irrChannels; - } +using suffixOfChannelBundle = std::string; +using channelName = std::string; // sytnax if as follows +using mapOfChannels = std::unordered_map; // suffix.channel, where channel are "R", "G", "B", "A" - auto doesTheChannelExist(const std::string channelName, const mapOfChannels& mapOfChannels) - { - auto foundPosition = mapOfChannels.find(channelName); - if (foundPosition != mapOfChannels.end()) - return true; - else - return false; - } +class SContext; +bool readVersionField(IMF::IStream* nblIStream, SContext& ctx, const system::logger_opt_ptr); +bool readHeader(IMF::IStream* nblIStream, SContext& ctx); +template +void readRgba(InputFile& file, std::array, 4>& pixelRgbaMapArray, int& width, int& height, E_FORMAT& format, const suffixOfChannelBundle suffixOfChannels); +E_FORMAT specifyIrrlichtEndFormat(const mapOfChannels& mapOfChannels, const suffixOfChannelBundle suffixName, const std::string fileName, const system::logger_opt_ptr logger); - SAssetBundle CImageLoaderOpenEXR::loadAsset(system::IFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel) - { - if (!_file) - return {}; +//! A helpful struct for handling OpenEXR layout +/* + The latest OpenEXR file consists of the following components: + - magic number + - version field + - header + - line offset table + - scan line blocks +*/ - SContext ctx; +struct SContext +{ + constexpr static uint32_t magicNumber = 20000630ul; // 0x76, 0x2f, 0x31, 0x01 - IMF::IStream* nblIStream = _NBL_NEW(impl::nblIStream, _file); // TODO: THIS NEEDS TESTING - InputFile file(*nblIStream); + struct VersionField + { + uint32_t mainDataRegisterField = 0ul; // treated as 2 seperate bit fields, contains some usefull data + uint8_t fileFormatVersionNumber = 0; // contains current OpenEXR version. It has to be 0 upon initialization! + bool doesFileContainLongNames; // if set, the maximum length of attribute names, attribute type names and channel names is 255 bytes. Otherwise 31 bytes + bool doesItSupportDeepData; // if set, there is at least one part which is not a regular scan line image or regular tiled image, so it is a deep format - if (file.isComplete()) - static_cast(nblIStream)->resetFileOffset(); - else + struct Compoment + { + enum CompomentType { - _NBL_DELETE(nblIStream); - return {}; - } + SINGLE_PART_FILE, + MULTI_PART_FILE + }; - if (readVersionField(nblIStream, ctx, _params.logger)) - static_cast(nblIStream)->resetFileOffset(); - else + enum SinglePartFileCompoments { - _NBL_DELETE(nblIStream); - return {}; - } + NONE, + SCAN_LINES, + TILES, + SCAN_LINES_OR_TILES + }; - if (readHeader(nblIStream, ctx)) - static_cast(nblIStream)->resetFileOffset(); - else - { - _NBL_DELETE(nblIStream); - return {}; - } + CompomentType type; + SinglePartFileCompoments singlePartFileCompomentSubTypes; - core::vector> images; - const auto channelsData = getChannels(file); - auto meta = core::make_smart_refctd_ptr(channelsData.size()); - { - uint32_t metaOffset = 0u; - for (const auto& data : channelsData) - { - const auto suffixOfChannels = data.first; - const auto mapOfChannels = data.second; - PerImageData perImageData; - - int width; - int height; - - auto params = perImageData.params; - params.format = specifyIrrlichtEndFormat(mapOfChannels, suffixOfChannels, file.fileName(), _params.logger); - params.type = ICPUImage::ET_2D;; - params.flags = static_cast(0u); - params.samples = ICPUImage::ESCF_1_BIT; - params.extent.depth = 1u; - params.mipLevels = 1u; - params.arrayLayers = 1u; - - if (params.format == EF_UNKNOWN) - { - #ifndef _NBL_PLATFORM_ANDROID_ - _params.logger.log("LOAD EXR: incorrect format specified for " + suffixOfChannels + " channels - skipping the file %s", system::ILogger::ELL_INFO, file.fileName()); - #endif // ! _NBL_PLATFORM_ANDROID_ - continue; - } - - if (params.format == EF_R16G16B16A16_SFLOAT) - readRgba(file, perImageData.halfPixelMapArray, width, height, params.format, suffixOfChannels); - else if (params.format == EF_R32G32B32A32_SFLOAT) - readRgba(file, perImageData.fullFloatPixelMapArray, width, height, params.format, suffixOfChannels); - else if (params.format == EF_R32G32B32A32_UINT) - readRgba(file, perImageData.uint32_tPixelMapArray, width, height, params.format, suffixOfChannels); - - params.extent.width = width; - params.extent.height = height; - - auto image = ICPUImage::create(std::move(params)); - { // create image and buffer that backs it - const uint32_t texelFormatByteSize = getTexelOrBlockBytesize(image->getCreationParameters().format); - auto texelBuffer = core::make_smart_refctd_ptr(image->getImageDataSizeInBytes()); - auto regions = core::make_refctd_dynamic_array>(1u); - ICPUImage::SBufferCopy& region = regions->front(); - region.imageSubresource.aspectMask = IImage::E_ASPECT_FLAGS::EAF_COLOR_BIT; - region.imageSubresource.mipLevel = 0u; - region.imageSubresource.baseArrayLayer = 0u; - region.imageSubresource.layerCount = 1u; - region.bufferOffset = 0u; - region.bufferRowLength = calcPitchInBlocks(width, texelFormatByteSize); - region.bufferImageHeight = 0u; - region.imageOffset = { 0u, 0u, 0u }; - region.imageExtent = image->getCreationParameters().extent; - - image->setBufferAndRegions(std::move(texelBuffer), regions); - } - - if (params.format == EF_R16G16B16A16_SFLOAT) - ReadTexels(image.get(),perImageData.halfPixelMapArray); - else if (params.format == EF_R32G32B32A32_SFLOAT) - ReadTexels(image.get(), perImageData.fullFloatPixelMapArray); - else if (params.format == EF_R32G32B32A32_UINT) - ReadTexels(image.get(), perImageData.uint32_tPixelMapArray); - - meta->placeMeta(metaOffset++,image.get(),std::string(suffixOfChannels),IImageMetadata::ColorSemantic{ ECP_SRGB,EOTF_IDENTITY }); - - images.push_back(std::move(image)); - } - } - _NBL_DELETE(nblIStream); - return SAssetBundle(std::move(meta),std::move(images)); - } + } Compoment; - bool CImageLoaderOpenEXR::isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger) const - { - char magicNumberBuffer[sizeof(SContext::magicNumber)]; - system::IFile::success_t success; - _file->read(success, magicNumberBuffer, 0, sizeof(SContext::magicNumber)); - return success && isImfMagic(magicNumberBuffer); - } + } versionField; - template - void readRgba(InputFile& file, std::array, 4>& pixelRgbaMapArray, int& width, int& height, E_FORMAT& format, const suffixOfChannelBundle suffixOfChannels) - { - Box2i dw = file.header().dataWindow(); - width = dw.max.x - dw.min.x + 1; - height = dw.max.y - dw.min.y + 1; + struct Attributes + { + // The header of every OpenEXR file must contain at least the following attributes + //according to https://www.openexr.com/documentation/openexrfilelayout.pdf (page 8) + const Channel* channels = nullptr; + const Compression* compression = nullptr; + const Box2i* dataWindow = nullptr; + const Box2i* displayWindow = nullptr; + const LineOrder* lineOrder = nullptr; + const float* pixelAspectRatio = nullptr; + const V2f* screenWindowCenter = nullptr; + const float* screenWindowWidth = nullptr; - constexpr const char* rgbaSignatureAsText[] = {"R", "G", "B", "A"}; - for (auto& pixelChannelBuffer : pixelRgbaMapArray) - pixelChannelBuffer.resizeErase(height, width); + // These attributes are required in the header for all multi - part and /or deep data OpenEXR files + const std::string* name = nullptr; + const std::string* type = nullptr; + const int* version = nullptr; + const int* chunkCount = nullptr; - FrameBuffer frameBuffer; - PixelType pixelType; + // This attribute is required in the header for all files which contain deep data (deepscanline or deeptile) + const int* maxSamplesPerPixel = nullptr; - if (format == EF_R16G16B16A16_SFLOAT) - pixelType = PixelType::HALF; - else if (format == EF_R32G32B32A32_SFLOAT) - pixelType = PixelType::FLOAT; - else if (format == EF_R32G32B32A32_UINT) - pixelType = PixelType::UINT; + // This attribute is required in the header for all files which contain one or more tiles + const TileDescription* tiles = nullptr; - for (uint8_t rgbaChannelIndex = 0; rgbaChannelIndex < availableChannels; ++rgbaChannelIndex) - { - std::string name = suffixOfChannels.empty() ? rgbaSignatureAsText[rgbaChannelIndex] : suffixOfChannels + "." + rgbaSignatureAsText[rgbaChannelIndex]; - frameBuffer.insert - ( - name.c_str(), // name - Slice(pixelType, // type - (char*)(&(pixelRgbaMapArray[rgbaChannelIndex])[0][0] - dw.min.x - dw.min.y * width), // base - sizeof((pixelRgbaMapArray[rgbaChannelIndex])[0][0]) * 1, // xStride - sizeof((pixelRgbaMapArray[rgbaChannelIndex])[0][0]) * width, // yStride - 1, 1, // x/y sampling - rgbaChannelIndex == 3 ? 1 : 0 // default fillValue for channels that aren't present in file - 1 for alpha, otherwise 0 - )); - } + // This attribute can be used in the header for multi-part files + const std::string* view = nullptr; - file.setFrameBuffer(frameBuffer); - file.readPixels(dw.min.y, dw.max.y); + // Others not required that can be used by metadata + // - none at the moment + + } attributes; + + // core::smart_refctd_dynamic_array offsetTable; + + // scan line blocks +}; + +constexpr uint8_t availableChannels = 4; +struct PerImageData +{ + ICPUImage::SCreationParams params; + std::array, availableChannels> halfPixelMapArray; + std::array, availableChannels> fullFloatPixelMapArray; + std::array, availableChannels> uint32_tPixelMapArray; +}; +template +struct ReadTexels +{ + ReadTexels(ICPUImage* image, const std::array, availableChannels>& _pixelMapArray) : + data(reinterpret_cast(image->getBuffer()->getPointer())), pixelMapArray(_pixelMapArray) + { + using StreamFromEXR = CRegionBlockFunctorFilter,false>; + typename StreamFromEXR::state_type state(*this,image,image->getRegions().begin()); + StreamFromEXR::execute(core::execution::par_unseq,&state); } - E_FORMAT specifyIrrlichtEndFormat(const mapOfChannels& mapOfChannels, const suffixOfChannelBundle suffixName, const std::string fileName, const system::logger_opt_ptr logger) + inline void operator()(uint32_t ptrOffset, const core::vectorSIMDu32& texelCoord) { - E_FORMAT retVal; + assert(texelCoord.w==0u && texelCoord.z==0u); - const auto rChannel = doesTheChannelExist("R", mapOfChannels); - const auto gChannel = doesTheChannelExist("G", mapOfChannels); - const auto bChannel = doesTheChannelExist("B", mapOfChannels); - const auto aChannel = doesTheChannelExist("A", mapOfChannels); - - #ifndef _NBL_PLATFORM_ANDROID_ - if (rChannel && gChannel && bChannel && aChannel) - logger.log("LOAD EXR: loading " + suffixName + " RGBA file %s", system::ILogger::ELL_INFO, fileName.c_str()); - else if (rChannel && gChannel && bChannel) - logger.log("LOAD EXR: loading " + suffixName + " RGB file %s", system::ILogger::ELL_INFO, fileName.c_str()); - else if(rChannel && gChannel) - logger.log("LOAD EXR: loading " + suffixName + " RG file %s", system::ILogger::ELL_INFO, fileName.c_str()); - else if(rChannel) - logger.log("LOAD EXR: loading " + suffixName + " R file %s", system::ILogger::ELL_INFO, fileName.c_str()); - else - logger.log("LOAD EXR: the file's channels are invalid to load %s", system::ILogger::ELL_ERROR, fileName.c_str()); - #endif // ! _NBL_PLATFORM_ANDROID_ - - auto doesMapOfChannelsFormatHaveTheSameFormatLikePassedToIt = [&](const PixelType ImfTypeToCompare) + uint8_t* texelPtr = data+ptrOffset; + for (auto channelIndex=0; channelIndex::type*>(texelPtr)[channelIndex] = element; + } + } - if (doesMapOfChannelsFormatHaveTheSameFormatLikePassedToIt(PixelType::HALF)) - retVal = EF_R16G16B16A16_SFLOAT; - else if (doesMapOfChannelsFormatHaveTheSameFormatLikePassedToIt(PixelType::FLOAT)) - retVal = EF_R32G32B32A32_SFLOAT; - else if (doesMapOfChannelsFormatHaveTheSameFormatLikePassedToIt(PixelType::UINT)) - retVal = EF_R32G32B32A32_UINT; - else - return EF_UNKNOWN; + private: + uint8_t* const data; + const std::array, availableChannels>& pixelMapArray; +}; - return retVal; +auto getChannels(const InputFile& file) +{ + std::unordered_map irrChannels; // example: G, albedo.R, color.space.B + { + auto channels = file.header().channels(); + for (auto mapItr = channels.begin(); mapItr != channels.end(); ++mapItr) + { + std::string fetchedChannelName = mapItr.name(); + const bool isThereAnySuffix = fetchedChannelName.size() > 1; + + if (isThereAnySuffix) + { + const auto endPositionOfChannelName = fetchedChannelName.find_last_of("."); + auto suffix = fetchedChannelName.substr(0, endPositionOfChannelName); + auto channel = fetchedChannelName.substr(endPositionOfChannelName + 1); + if (channel == "R" || channel == "G" || channel == "B" || channel == "A") + (irrChannels[suffix])[channel] = mapItr.channel(); + } + else + (irrChannels[""])[fetchedChannelName] = mapItr.channel(); } + } - bool readVersionField(IMF::IStream* nblIStream, SContext& ctx, const system::logger_opt_ptr logger) - { - RgbaInputFile file(*nblIStream); + return irrChannels; +} - if (!file.isComplete()) - return false; +auto doesTheChannelExist(const std::string channelName, const mapOfChannels& mapOfChannels) +{ + auto foundPosition = mapOfChannels.find(channelName); + if (foundPosition != mapOfChannels.end()) + return true; + else + return false; +} - auto& versionField = ctx.versionField; - - versionField.mainDataRegisterField = file.version(); +SAssetBundle CImageLoaderOpenEXR::loadAsset(system::IFile* _file, const asset::IAssetLoader::SAssetLoadParams& _params, asset::IAssetLoader::IAssetLoaderOverride* _override, uint32_t _hierarchyLevel) +{ + if (!_file) + return {}; - auto isTheBitActive = [&](uint16_t bitToCheck) - { - bool readVersionField(IMF::IStream* nblIStream, SContext& ctx); - bool readHeader(IMF::IStream* nblIStream, SContext& ctx); - return (versionField.mainDataRegisterField & (1 << (bitToCheck - 1))); - }; + SContext ctx; - versionField.fileFormatVersionNumber |= isTheBitActive(1) | isTheBitActive(2) | isTheBitActive(3) | isTheBitActive(4) | isTheBitActive(5) | isTheBitActive(6) | isTheBitActive(7) | isTheBitActive(8); + IMF::IStream* nblIStream = _NBL_NEW(impl::nblIStream, _file); // TODO: THIS NEEDS TESTING + InputFile file(*nblIStream); - if (!isTheBitActive(11) && !isTheBitActive(12)) - { - versionField.Compoment.type = SContext::VersionField::Compoment::SINGLE_PART_FILE; - - if (isTheBitActive(9)) - { - versionField.Compoment.singlePartFileCompomentSubTypes = SContext::VersionField::Compoment::TILES; - #ifndef _NBL_PLATFORM_ANDROID_ - logger.log("LOAD EXR: the file consist of not supported tiles %s", system::ILogger::ELL_ERROR, file.fileName()); - #endif // !_NBL_PLATFORM_ANDROID_ - return false; - } - else - versionField.Compoment.singlePartFileCompomentSubTypes = SContext::VersionField::Compoment::SCAN_LINES; - } - else if (!isTheBitActive(9) && !isTheBitActive(11) && isTheBitActive(12)) + if (file.isComplete()) + static_cast(nblIStream)->resetFileOffset(); + else + { + _NBL_DELETE(nblIStream); + return {}; + } + + if (readVersionField(nblIStream, ctx, _params.logger)) + static_cast(nblIStream)->resetFileOffset(); + else + { + _NBL_DELETE(nblIStream); + return {}; + } + + if (readHeader(nblIStream, ctx)) + static_cast(nblIStream)->resetFileOffset(); + else + { + _NBL_DELETE(nblIStream); + return {}; + } + + core::vector> images; + const auto channelsData = getChannels(file); + auto meta = core::make_smart_refctd_ptr(channelsData.size()); + { + uint32_t metaOffset = 0u; + for (const auto& data : channelsData) + { + const auto suffixOfChannels = data.first; + const auto mapOfChannels = data.second; + PerImageData perImageData; + + int width; + int height; + + auto params = perImageData.params; + params.format = specifyIrrlichtEndFormat(mapOfChannels, suffixOfChannels, file.fileName(), _params.logger); + params.type = ICPUImage::ET_2D;; + params.flags = static_cast(0u); + params.samples = ICPUImage::ESCF_1_BIT; + params.extent.depth = 1u; + params.mipLevels = 1u; + params.arrayLayers = 1u; + + if (params.format == EF_UNKNOWN) { - versionField.Compoment.type = SContext::VersionField::Compoment::MULTI_PART_FILE; - versionField.Compoment.singlePartFileCompomentSubTypes = SContext::VersionField::Compoment::SCAN_LINES_OR_TILES; #ifndef _NBL_PLATFORM_ANDROID_ - logger.log("LOAD EXR: the file is a not supported multi part file %s", system::ILogger::ELL_ERROR, file.fileName()); + _params.logger.log("LOAD EXR: incorrect format specified for " + suffixOfChannels + " channels - skipping the file %s", system::ILogger::ELL_INFO, file.fileName()); #endif // ! _NBL_PLATFORM_ANDROID_ - return false; + continue; } - if (!isTheBitActive(9) && isTheBitActive(11) && isTheBitActive(12)) - { - versionField.doesItSupportDeepData = true; - #ifndef _NBL_PLATFORM_ANDROID_ - logger.log("LOAD EXR: the file consist of not supported deep data%s", system::ILogger::ELL_ERROR, file.fileName()); - #endif // ! _NBL_PLATFORM_ANDROID_ - return false; + if (params.format == EF_R16G16B16A16_SFLOAT) + readRgba(file, perImageData.halfPixelMapArray, width, height, params.format, suffixOfChannels); + else if (params.format == EF_R32G32B32A32_SFLOAT) + readRgba(file, perImageData.fullFloatPixelMapArray, width, height, params.format, suffixOfChannels); + else if (params.format == EF_R32G32B32A32_UINT) + readRgba(file, perImageData.uint32_tPixelMapArray, width, height, params.format, suffixOfChannels); + + params.extent.width = width; + params.extent.height = height; + + auto image = ICPUImage::create(std::move(params)); + { // create image and buffer that backs it + const uint32_t texelFormatByteSize = getTexelOrBlockBytesize(image->getCreationParameters().format); + auto texelBuffer = core::make_smart_refctd_ptr(image->getImageDataSizeInBytes()); + auto regions = core::make_refctd_dynamic_array>(1u); + ICPUImage::SBufferCopy& region = regions->front(); + region.imageSubresource.aspectMask = IImage::E_ASPECT_FLAGS::EAF_COLOR_BIT; + region.imageSubresource.mipLevel = 0u; + region.imageSubresource.baseArrayLayer = 0u; + region.imageSubresource.layerCount = 1u; + region.bufferOffset = 0u; + region.bufferRowLength = calcPitchInBlocks(width, texelFormatByteSize); + region.bufferImageHeight = 0u; + region.imageOffset = { 0u, 0u, 0u }; + region.imageExtent = image->getCreationParameters().extent; + + image->setBufferAndRegions(std::move(texelBuffer), regions); } - else - versionField.doesItSupportDeepData = false; - if (isTheBitActive(10)) - versionField.doesFileContainLongNames = true; - else - versionField.doesFileContainLongNames = false; + if (params.format == EF_R16G16B16A16_SFLOAT) + ReadTexels(image.get(),perImageData.halfPixelMapArray); + else if (params.format == EF_R32G32B32A32_SFLOAT) + ReadTexels(image.get(), perImageData.fullFloatPixelMapArray); + else if (params.format == EF_R32G32B32A32_UINT) + ReadTexels(image.get(), perImageData.uint32_tPixelMapArray); - return true; + meta->placeMeta(metaOffset++,image.get(),std::string(suffixOfChannels),IImageMetadata::ColorSemantic{ ECP_SRGB,EOTF_IDENTITY }); + + images.push_back(std::move(image)); } + } + _NBL_DELETE(nblIStream); + return SAssetBundle(std::move(meta),std::move(images)); +} - bool readHeader(IMF::IStream* nblIStream, SContext& ctx) - { - RgbaInputFile file(*nblIStream); +bool CImageLoaderOpenEXR::isALoadableFileFormat(system::IFile* _file, const system::logger_opt_ptr logger) const +{ + char magicNumberBuffer[sizeof(SContext::magicNumber)]; + system::IFile::success_t success; + _file->read(success, magicNumberBuffer, 0, sizeof(SContext::magicNumber)); + return success && isImfMagic(magicNumberBuffer); +} - if (!file.isComplete()) - return false; +template +void readRgba(InputFile& file, std::array, 4>& pixelRgbaMapArray, int& width, int& height, E_FORMAT& format, const suffixOfChannelBundle suffixOfChannels) +{ + Box2i dw = file.header().dataWindow(); + width = dw.max.x - dw.min.x + 1; + height = dw.max.y - dw.min.y + 1; - auto& attribs = ctx.attributes; - auto& versionField = ctx.versionField; + constexpr const char* rgbaSignatureAsText[] = {"R", "G", "B", "A"}; + for (auto& pixelChannelBuffer : pixelRgbaMapArray) + pixelChannelBuffer.resizeErase(height, width); - /* + FrameBuffer frameBuffer; + PixelType pixelType; - // There is an OpenEXR library implementation error associated with dynamic_cast<> probably - // Since OpenEXR loader only cares about RGB and RGBA, there is no need for bellow at the moment + if (format == EF_R16G16B16A16_SFLOAT) + pixelType = PixelType::HALF; + else if (format == EF_R32G32B32A32_SFLOAT) + pixelType = PixelType::FLOAT; + else if (format == EF_R32G32B32A32_UINT) + pixelType = PixelType::UINT; - attribs.channels = file.header().findTypedAttribute("channels"); - attribs.compression = file.header().findTypedAttribute("compression"); - attribs.dataWindow = file.header().findTypedAttribute("dataWindow"); - attribs.displayWindow = file.header().findTypedAttribute("displayWindow"); - attribs.lineOrder = file.header().findTypedAttribute("lineOrder"); - attribs.pixelAspectRatio = file.header().findTypedAttribute("pixelAspectRatio"); - attribs.screenWindowCenter = file.header().findTypedAttribute("screenWindowCenter"); - attribs.screenWindowWidth = file.header().findTypedAttribute("screenWindowWidth"); + for (uint8_t rgbaChannelIndex = 0; rgbaChannelIndex < availableChannels; ++rgbaChannelIndex) + { + std::string name = suffixOfChannels.empty() ? rgbaSignatureAsText[rgbaChannelIndex] : suffixOfChannels + "." + rgbaSignatureAsText[rgbaChannelIndex]; + frameBuffer.insert + ( + name.c_str(), // name + Slice(pixelType, // type + (char*)(&(pixelRgbaMapArray[rgbaChannelIndex])[0][0] - dw.min.x - dw.min.y * width), // base + sizeof((pixelRgbaMapArray[rgbaChannelIndex])[0][0]) * 1, // xStride + sizeof((pixelRgbaMapArray[rgbaChannelIndex])[0][0]) * width, // yStride + 1, 1, // x/y sampling + rgbaChannelIndex == 3 ? 1 : 0 // default fillValue for channels that aren't present in file - 1 for alpha, otherwise 0 + )); + } - if (versionField.Compoment.singlePartFileCompomentSubTypes == SContext::VersionField::Compoment::TILES) - attribs.tiles = file.header().findTypedAttribute("tiles"); + file.setFrameBuffer(frameBuffer); + file.readPixels(dw.min.y, dw.max.y); +} - if (versionField.Compoment.type == SContext::VersionField::Compoment::MULTI_PART_FILE) - attribs.view = file.header().findTypedAttribute("view"); +E_FORMAT specifyIrrlichtEndFormat(const mapOfChannels& mapOfChannels, const suffixOfChannelBundle suffixName, const std::string fileName, const system::logger_opt_ptr logger) +{ + E_FORMAT retVal; - if (versionField.Compoment.type == SContext::VersionField::Compoment::MULTI_PART_FILE || versionField.doesItSupportDeepData) - { - attribs.name = file.header().findTypedAttribute("name"); - attribs.type = file.header().findTypedAttribute("type"); - attribs.version = file.header().findTypedAttribute("version"); - attribs.chunkCount = file.header().findTypedAttribute("chunkCount"); - attribs.maxSamplesPerPixel = file.header().findTypedAttribute("maxSamplesPerPixel"); - } + const auto rChannel = doesTheChannelExist("R", mapOfChannels); + const auto gChannel = doesTheChannelExist("G", mapOfChannels); + const auto bChannel = doesTheChannelExist("B", mapOfChannels); + const auto aChannel = doesTheChannelExist("A", mapOfChannels); + + #ifndef _NBL_PLATFORM_ANDROID_ + if (rChannel && gChannel && bChannel && aChannel) + logger.log("LOAD EXR: loading " + suffixName + " RGBA file %s", system::ILogger::ELL_INFO, fileName.c_str()); + else if (rChannel && gChannel && bChannel) + logger.log("LOAD EXR: loading " + suffixName + " RGB file %s", system::ILogger::ELL_INFO, fileName.c_str()); + else if(rChannel && gChannel) + logger.log("LOAD EXR: loading " + suffixName + " RG file %s", system::ILogger::ELL_INFO, fileName.c_str()); + else if(rChannel) + logger.log("LOAD EXR: loading " + suffixName + " R file %s", system::ILogger::ELL_INFO, fileName.c_str()); + else + logger.log("LOAD EXR: the file's channels are invalid to load %s", system::ILogger::ELL_ERROR, fileName.c_str()); + #endif // ! _NBL_PLATFORM_ANDROID_ + + auto doesMapOfChannelsFormatHaveTheSameFormatLikePassedToIt = [&](const PixelType ImfTypeToCompare) + { + for (auto& channel : mapOfChannels) + if (channel.second.type != ImfTypeToCompare) + return false; + return true; + }; + + if (doesMapOfChannelsFormatHaveTheSameFormatLikePassedToIt(PixelType::HALF)) + retVal = EF_R16G16B16A16_SFLOAT; + else if (doesMapOfChannelsFormatHaveTheSameFormatLikePassedToIt(PixelType::FLOAT)) + retVal = EF_R32G32B32A32_SFLOAT; + else if (doesMapOfChannelsFormatHaveTheSameFormatLikePassedToIt(PixelType::UINT)) + retVal = EF_R32G32B32A32_UINT; + else + return EF_UNKNOWN; + + return retVal; +} - */ +bool readVersionField(IMF::IStream* nblIStream, SContext& ctx, const system::logger_opt_ptr logger) +{ + RgbaInputFile file(*nblIStream); + + if (!file.isComplete()) + return false; + + auto& versionField = ctx.versionField; + + versionField.mainDataRegisterField = file.version(); + + auto isTheBitActive = [&](uint16_t bitToCheck) + { + bool readVersionField(IMF::IStream* nblIStream, SContext& ctx); + bool readHeader(IMF::IStream* nblIStream, SContext& ctx); + return (versionField.mainDataRegisterField & (1 << (bitToCheck - 1))); + }; - return true; + versionField.fileFormatVersionNumber |= isTheBitActive(1) | isTheBitActive(2) | isTheBitActive(3) | isTheBitActive(4) | isTheBitActive(5) | isTheBitActive(6) | isTheBitActive(7) | isTheBitActive(8); + + if (!isTheBitActive(11) && !isTheBitActive(12)) + { + versionField.Compoment.type = SContext::VersionField::Compoment::SINGLE_PART_FILE; + + if (isTheBitActive(9)) + { + versionField.Compoment.singlePartFileCompomentSubTypes = SContext::VersionField::Compoment::TILES; + #ifndef _NBL_PLATFORM_ANDROID_ + logger.log("LOAD EXR: the file consist of not supported tiles %s", system::ILogger::ELL_ERROR, file.fileName()); + #endif // !_NBL_PLATFORM_ANDROID_ + return false; } + else + versionField.Compoment.singlePartFileCompomentSubTypes = SContext::VersionField::Compoment::SCAN_LINES; + } + else if (!isTheBitActive(9) && !isTheBitActive(11) && isTheBitActive(12)) + { + versionField.Compoment.type = SContext::VersionField::Compoment::MULTI_PART_FILE; + versionField.Compoment.singlePartFileCompomentSubTypes = SContext::VersionField::Compoment::SCAN_LINES_OR_TILES; + #ifndef _NBL_PLATFORM_ANDROID_ + logger.log("LOAD EXR: the file is a not supported multi part file %s", system::ILogger::ELL_ERROR, file.fileName()); + #endif // ! _NBL_PLATFORM_ANDROID_ + return false; + } + + if (!isTheBitActive(9) && isTheBitActive(11) && isTheBitActive(12)) + { + versionField.doesItSupportDeepData = true; + #ifndef _NBL_PLATFORM_ANDROID_ + logger.log("LOAD EXR: the file consist of not supported deep data%s", system::ILogger::ELL_ERROR, file.fileName()); + #endif // ! _NBL_PLATFORM_ANDROID_ + return false; } + else + versionField.doesItSupportDeepData = false; + + if (isTheBitActive(10)) + versionField.doesFileContainLongNames = true; + else + versionField.doesFileContainLongNames = false; + + return true; } +bool readHeader(IMF::IStream* nblIStream, SContext& ctx) +{ + RgbaInputFile file(*nblIStream); + + if (!file.isComplete()) + return false; + + auto& attribs = ctx.attributes; + auto& versionField = ctx.versionField; + + /* + + // There is an OpenEXR library implementation error associated with dynamic_cast<> probably + // Since OpenEXR loader only cares about RGB and RGBA, there is no need for bellow at the moment + + attribs.channels = file.header().findTypedAttribute("channels"); + attribs.compression = file.header().findTypedAttribute("compression"); + attribs.dataWindow = file.header().findTypedAttribute("dataWindow"); + attribs.displayWindow = file.header().findTypedAttribute("displayWindow"); + attribs.lineOrder = file.header().findTypedAttribute("lineOrder"); + attribs.pixelAspectRatio = file.header().findTypedAttribute("pixelAspectRatio"); + attribs.screenWindowCenter = file.header().findTypedAttribute("screenWindowCenter"); + attribs.screenWindowWidth = file.header().findTypedAttribute("screenWindowWidth"); + + if (versionField.Compoment.singlePartFileCompomentSubTypes == SContext::VersionField::Compoment::TILES) + attribs.tiles = file.header().findTypedAttribute("tiles"); + + if (versionField.Compoment.type == SContext::VersionField::Compoment::MULTI_PART_FILE) + attribs.view = file.header().findTypedAttribute("view"); + + if (versionField.Compoment.type == SContext::VersionField::Compoment::MULTI_PART_FILE || versionField.doesItSupportDeepData) + { + attribs.name = file.header().findTypedAttribute("name"); + attribs.type = file.header().findTypedAttribute("type"); + attribs.version = file.header().findTypedAttribute("version"); + attribs.chunkCount = file.header().findTypedAttribute("chunkCount"); + attribs.maxSamplesPerPixel = file.header().findTypedAttribute("maxSamplesPerPixel"); + } + + */ + + return true; +} +} + + #endif // _NBL_COMPILE_WITH_OPENEXR_LOADER_ From edf099ca38d73d96f5c67b42d10c6dcb19e0eebb Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 18:08:20 +0100 Subject: [PATCH 80/91] Vulkan has validation bugs in ex 54 --- examples_tests/54.Transformations/main.cpp | 4 ++++ examples_tests/Readme.md | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/examples_tests/54.Transformations/main.cpp b/examples_tests/54.Transformations/main.cpp index 65b432e2b8..9678e208ce 100644 --- a/examples_tests/54.Transformations/main.cpp +++ b/examples_tests/54.Transformations/main.cpp @@ -547,13 +547,17 @@ class TransformationApp : public ApplicationBase auto gfxLayout = core::make_smart_refctd_ptr(range,range+1u,scene::ITransformTreeWithNormalMatrices::createRenderDescriptorSetLayout()); pipeline->setLayout(core::smart_refctd_ptr(gfxLayout)); + cpu2gpuParams.beginCommandBuffers(); core::smart_refctd_ptr rpIndependentPipeline = CPU2GPU.getGPUObjectsFromAssets(&pipeline, &pipeline + 1, cpu2gpuParams)->front(); + cpu2gpuParams.waitForCreationToComplete(false); asset::SBufferBinding colorBufBinding; colorBufBinding.offset = colorBufferOffset; colorBufBinding.buffer = colorBuffer; + cpu2gpuParams.beginCommandBuffers(); ret.gpuMesh = CPU2GPU.getGPUObjectsFromAssets(&cpuMesh, &cpuMesh + 1, cpu2gpuParams)->front(); + cpu2gpuParams.waitForCreationToComplete(false); ret.gpuMesh->setVertexBufferBinding(std::move(colorBufBinding), ColorBindingNum); ret.gpuMesh->setInstanceCount(numInstances); diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index a5af2a006f..2abf751998 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -85,7 +85,7 @@ N = No support | 51.RadixSort | W | N | W | W | N | W | N | W | | | 52.SystemTest | S | S | S | S | S | S | S | S | | | 53.ComputeShaders | S | N | S | S | N | S | N | S | | -| 54.Transformations | S | S | S | S | S | S | S | S | | +| 54.Transformations | Y | Y | B | S | S | S | S | S | | | 55.RGB18E7S3 | S | S | S | S | S | S | N | N | | | 56.RayQuery | N | N | Y | N | N | S | N | S | | | 57.AndroidSample | N | N | N | N | N | N | S | S | | From 65a7286c332330beff4e4335dbea261946e8870c Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 18:20:44 +0100 Subject: [PATCH 81/91] fixed bug in BIN loader (and ensured glTF still works) --- examples_tests/Readme.md | 2 +- src/nbl/asset/interchange/CBufferLoaderBIN.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 2abf751998..75bc2fc7b3 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -81,7 +81,7 @@ N = No support | 47.DerivMapTest | S | N | S | S | N | S | N | N | | | 48.ArithmeticUnitTest | Y | N | Y | S | N | S | N | S | | | 49.ComputeFFT | S | N | S | S | N | S | N | N | | -| 50.NewAPITest | S | S | S | S | S | S | S | S | | +| 50.NewAPITest | W | W | W | W | W | W | W | W | | | 51.RadixSort | W | N | W | W | N | W | N | W | | | 52.SystemTest | S | S | S | S | S | S | S | S | | | 53.ComputeShaders | S | N | S | S | N | S | N | S | | diff --git a/src/nbl/asset/interchange/CBufferLoaderBIN.cpp b/src/nbl/asset/interchange/CBufferLoaderBIN.cpp index 0a4784e05f..6cd24e6568 100644 --- a/src/nbl/asset/interchange/CBufferLoaderBIN.cpp +++ b/src/nbl/asset/interchange/CBufferLoaderBIN.cpp @@ -16,7 +16,7 @@ asset::SAssetBundle CBufferLoaderBIN::loadAsset(system::IFile* _file, const asse system::IFile::success_t success; ctx.file->read(success, ctx.sourceCodeBuffer->getPointer(), 0u, ctx.sourceCodeBuffer->getSize()); - if (success) + if (!success) return {}; return SAssetBundle(nullptr,{std::move(ctx.sourceCodeBuffer)}); From f956d791e5a8f9c0e2cbcdaafcccc8c7b9c1d50a Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 19:55:21 +0100 Subject: [PATCH 82/91] Fix up ex 55: - use file logger - remove redundant frames - get rid of Vulkan validation errors --- examples_tests/55.RGB18E7S3/main.cpp | 30 ++++++--------------- include/nbl/builtin/glsl/format/encode.glsl | 1 + include/nbl/system/CFileLogger.h | 1 + 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/examples_tests/55.RGB18E7S3/main.cpp b/examples_tests/55.RGB18E7S3/main.cpp index 4581ef810d..5c66da9b03 100644 --- a/examples_tests/55.RGB18E7S3/main.cpp +++ b/examples_tests/55.RGB18E7S3/main.cpp @@ -13,8 +13,7 @@ using namespace nbl; using namespace core; _NBL_STATIC_INLINE_CONSTEXPR size_t WORK_GROUP_SIZE = 32; //! work-items per work-group -_NBL_STATIC_INLINE_CONSTEXPR size_t MAX_TEST_RGB_VALUES = WORK_GROUP_SIZE * 1; //! total number of rgb values to test -_NBL_STATIC_INLINE_CONSTEXPR size_t FRAMES_IN_FLIGHT = 3u; +_NBL_STATIC_INLINE_CONSTEXPR size_t MAX_TEST_RGB_VALUES = WORK_GROUP_SIZE * 1; //! total number of rgb values to test enum E_SSBO { @@ -45,7 +44,7 @@ int main() constexpr std::string_view APP_NAME = "RGB18E7S3 utility test"; CommonAPI::InitOutput initOutput; - CommonAPI::InitWithNoExt(initOutput, video::EAT_OPENGL, APP_NAME.data()); + CommonAPI::InitWithNoExt(initOutput, video::EAT_VULKAN, APP_NAME.data()); auto system = std::move(initOutput.system); auto gl = std::move(initOutput.apiConnection); auto logger = std::move(initOutput.logger); @@ -81,6 +80,7 @@ int main() { auto cpuComputeShader = core::smart_refctd_ptr_static_cast(computeShaderBundle.getContents().begin()[0]); + cpu2gpuParams.beginCommandBuffers(); auto gpu_array = cpu2gpu.getGPUObjectsFromAssets(&cpuComputeShader, &cpuComputeShader + 1, cpu2gpuParams); if (!gpu_array || gpu_array->size() < 1u || !(*gpu_array)[0]) assert(false); @@ -128,9 +128,9 @@ int main() ssboMemoryReqs.mappingCapability = video::IDriverMemoryAllocation::EMCAF_READ_AND_WRITE; video::IGPUBuffer::SCreationParams ssboCreationParams; - ssboCreationParams.usage = asset::IBuffer::EUF_STORAGE_BUFFER_BIT; + ssboCreationParams.usage = core::bitflag(asset::IBuffer::EUF_STORAGE_BUFFER_BIT)|asset::IBuffer::EUF_TRANSFER_DST_BIT; ssboCreationParams.canUpdateSubRange = true; - ssboCreationParams.sharingMode = asset::E_SHARING_MODE::ESM_CONCURRENT; + ssboCreationParams.sharingMode = asset::E_SHARING_MODE::ESM_EXCLUSIVE; ssboCreationParams.queueFamilyIndexCount = 0u; ssboCreationParams.queueFamilyIndices = nullptr; @@ -182,13 +182,10 @@ int main() auto gpuCPipelineLayout = logicalDevice->createGPUPipelineLayout(nullptr, nullptr, std::move(gpuCDescriptorSetLayout), nullptr, nullptr, nullptr); auto gpuComputePipeline = logicalDevice->createGPUComputePipeline(nullptr, std::move(gpuCPipelineLayout), std::move(gpuComputeShader)); - core::smart_refctd_ptr commandBuffers[FRAMES_IN_FLIGHT]; - logicalDevice->createCommandBuffers(commandPools[CommonAPI::InitOutput::EQT_COMPUTE].get(), video::IGPUCommandBuffer::EL_PRIMARY, FRAMES_IN_FLIGHT, commandBuffers); + core::smart_refctd_ptr commandBuffer; + logicalDevice->createCommandBuffers(commandPools[CommonAPI::InitOutput::EQT_COMPUTE].get(), video::IGPUCommandBuffer::EL_PRIMARY, 1u, &commandBuffer); auto gpuFence = logicalDevice->createFence(static_cast(0)); - - for(size_t i = 0; i < FRAMES_IN_FLIGHT; ++i) { - auto& commandBuffer = commandBuffers[i]; commandBuffer->begin(0); @@ -216,18 +213,7 @@ int main() queues[decltype(initOutput)::EQT_COMPUTE]->submit(1u, &submit, gpuFence.get()); } } - - { - video::IGPUFence::E_STATUS waitStatus = video::IGPUFence::ES_NOT_READY; - while (waitStatus != video::IGPUFence::ES_SUCCESS) - { - waitStatus = logicalDevice->waitForFences(1u, &gpuFence.get(), false, 99999999999ull); - if (waitStatus == video::IGPUFence::ES_ERROR) - assert(false); - else if (waitStatus == video::IGPUFence::ES_TIMEOUT) - break; - } - } + logicalDevice->blockForFences(1u,&gpuFence.get()); video::IDriverMemoryAllocation::MappedMemoryRange mappedMemoryRange(gpuDownloadSSBOmapped->getBoundMemory(), 0u, gpuDownloadSSBOmapped->getSize()); logicalDevice->mapMemory(mappedMemoryRange, video::IDriverMemoryAllocation::EMCAF_READ); diff --git a/include/nbl/builtin/glsl/format/encode.glsl b/include/nbl/builtin/glsl/format/encode.glsl index 6d09b0e433..9a8efd0c36 100644 --- a/include/nbl/builtin/glsl/format/encode.glsl +++ b/include/nbl/builtin/glsl/format/encode.glsl @@ -2,6 +2,7 @@ #define _IRR_BUILTIN_GLSL_FORMAT_ENCODE_INCLUDED_ #include +#include uvec3 nbl_glsl_impl_sharedExponentEncodeCommon(in vec3 clamped, in int newExpBias, in int newMaxExp, in int mantissaBits, out int shared_exp) { diff --git a/include/nbl/system/CFileLogger.h b/include/nbl/system/CFileLogger.h index 85629d0b2d..21cc742b25 100644 --- a/include/nbl/system/CFileLogger.h +++ b/include/nbl/system/CFileLogger.h @@ -23,6 +23,7 @@ class CFileLogger : public IThreadsafeLogger const auto str = constructLogString(fmt, logLevel, args); ISystem::future_t future; m_file->write(future,str.data(),m_file->getSize(),str.length()); + future.get(); // need to use the future to make sure op is actually executed :( } core::smart_refctd_ptr m_file; From 1d7c377ee2cc70e24cc1ff5afc3eff4a1008257e Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 20:01:21 +0100 Subject: [PATCH 83/91] Android fixes --- include/nbl/system/CApplicationAndroid.h | 2 +- include/nbl/ui/CGraphicalApplicationAndroid.h | 7 +- include/nbl/ui/CWindowAndroid.h | 99 ++++++++++--------- include/nbl/ui/CWindowManagerAndroid.h | 15 ++- include/nbl/ui/IWindowAndroid.h | 19 ++-- 5 files changed, 75 insertions(+), 67 deletions(-) diff --git a/include/nbl/system/CApplicationAndroid.h b/include/nbl/system/CApplicationAndroid.h index ef9f2020e8..011a7d8854 100644 --- a/include/nbl/system/CApplicationAndroid.h +++ b/include/nbl/system/CApplicationAndroid.h @@ -14,7 +14,7 @@ namespace nbl::system #include #include - class CApplicationAndroid : public IApplicationFramework +class CApplicationAndroid : public IApplicationFramework { public: void onStateSaved(android_app* params) diff --git a/include/nbl/ui/CGraphicalApplicationAndroid.h b/include/nbl/ui/CGraphicalApplicationAndroid.h index 418ec571c9..6012b666e3 100644 --- a/include/nbl/ui/CGraphicalApplicationAndroid.h +++ b/include/nbl/ui/CGraphicalApplicationAndroid.h @@ -1,13 +1,14 @@ #ifndef _NBL_UI_C_GRAPHICAL_APPLICATION_ANDROID_H_INCLUDED_ #define _NBL_UI_C_GRAPHICAL_APPLICATION_ANDROID_H_INCLUDED_ -#ifdef _NBL_PLATFORM_ANDROID_ + #include "nbl/system/CApplicationAndroid.h" #include "nbl/system/CSystemAndroid.h" -#include "nbl/system/CSystemLinux.h" -#include "nbl/system/CSystemCallerPOSIX.h" + #include "nbl/ui/IGraphicalApplicationFramework.h" #include "nbl/ui/IWindow.h" #include "nbl/ui/CWindowManagerAndroid.h" + +#ifdef _NBL_PLATFORM_ANDROID_ #include #include namespace nbl::ui diff --git a/include/nbl/ui/CWindowAndroid.h b/include/nbl/ui/CWindowAndroid.h index 662b026624..8b550f7954 100755 --- a/include/nbl/ui/CWindowAndroid.h +++ b/include/nbl/ui/CWindowAndroid.h @@ -1,5 +1,5 @@ -#ifndef __NBL_C_WINDOW_ANDROID_H_INCLUDED__ -#define __NBL_C_WINDOW_ANDROID_H_INCLUDED__ +#ifndef _NBL_C_WINDOW_ANDROID_H_INCLUDED_ +#define _NBL_C_WINDOW_ANDROID_H_INCLUDED_ #include "nbl/ui/IWindowAndroid.h" @@ -13,59 +13,60 @@ namespace nbl::ui class CWindowAndroid : public IWindowAndroid { -public: - constexpr static uint32_t CIRCULAR_BUFFER_CAPACITY = 256; - explicit CWindowAndroid(SCreationParams&& params, native_handle_t anw) : m_native(anw), IWindowAndroid(std::move(params)) - { - m_width = ANativeWindow_getWidth(anw); - m_height = ANativeWindow_getHeight(anw); - } + public: + constexpr static uint32_t CIRCULAR_BUFFER_CAPACITY = 256; + explicit CWindowAndroid(SCreationParams&& params, native_handle_t anw) : m_native(anw), IWindowAndroid(std::move(params)) + { + m_width = ANativeWindow_getWidth(anw); + m_height = ANativeWindow_getHeight(anw); + } + + virtual IClipboardManager* getClipboardManager() override { return nullptr; } + virtual ICursorControl* getCursorControl() override { return nullptr; } - virtual IClipboardManager* getClipboardManager() { return nullptr; } - virtual ICursorControl* getCursorControl() { return nullptr; } - const native_handle_t& getNativeHandle() const override { return m_native; } - void setCaption(const std::string_view& caption) override {} - core::map> m_mouseEventChannels; - core::map> m_keyboardEventChannels; - bool hasMouseEventChannel(uint32_t deviceId) - { - return m_mouseEventChannels.find(deviceId) != m_mouseEventChannels.end(); - } - bool hasKeyboardEventChannel(uint32_t deviceId) - { - return m_keyboardEventChannels.find(deviceId) != m_keyboardEventChannels.end(); - } - bool addMouseEventChannel(uint32_t deviceId, const core::smart_refctd_ptr& channel) - { - if (m_mouseEventChannels.find(deviceId) == m_mouseEventChannels.end()) + const native_handle_t& getNativeHandle() const override { return m_native; } + void setCaption(const std::string_view& caption) override {} + core::map> m_mouseEventChannels; + core::map> m_keyboardEventChannels; + bool hasMouseEventChannel(uint32_t deviceId) { - m_mouseEventChannels.emplace(deviceId, channel); - return true; + return m_mouseEventChannels.find(deviceId) != m_mouseEventChannels.end(); } - return false; - } - bool addKeyboardEventChannel(uint32_t deviceId, const core::smart_refctd_ptr& channel) - { - if (m_keyboardEventChannels.find(deviceId) == m_keyboardEventChannels.end()) + bool hasKeyboardEventChannel(uint32_t deviceId) { - m_keyboardEventChannels.emplace(deviceId, channel); - return true; + return m_keyboardEventChannels.find(deviceId) != m_keyboardEventChannels.end(); + } + bool addMouseEventChannel(uint32_t deviceId, const core::smart_refctd_ptr& channel) + { + if (m_mouseEventChannels.find(deviceId) == m_mouseEventChannels.end()) + { + m_mouseEventChannels.emplace(deviceId, channel); + return true; + } + return false; + } + bool addKeyboardEventChannel(uint32_t deviceId, const core::smart_refctd_ptr& channel) + { + if (m_keyboardEventChannels.find(deviceId) == m_keyboardEventChannels.end()) + { + m_keyboardEventChannels.emplace(deviceId, channel); + return true; + } + return false; + } + IMouseEventChannel* getMouseEventChannel(uint32_t deviceId) + { + auto ch = m_mouseEventChannels.find(deviceId); + return m_mouseEventChannels.find(deviceId)->second.get(); } - return false; - } - IMouseEventChannel* getMouseEventChannel(uint32_t deviceId) - { - auto ch = m_mouseEventChannels.find(deviceId); - return m_mouseEventChannels.find(deviceId)->second.get(); - } - IKeyboardEventChannel* getKeyboardEventChannel(uint32_t deviceId) - { - auto ch = m_keyboardEventChannels.find(deviceId); - return m_keyboardEventChannels.find(deviceId)->second.get(); - } -private: - native_handle_t m_native; + IKeyboardEventChannel* getKeyboardEventChannel(uint32_t deviceId) + { + auto ch = m_keyboardEventChannels.find(deviceId); + return m_keyboardEventChannels.find(deviceId)->second.get(); + } + private: + native_handle_t m_native; }; } diff --git a/include/nbl/ui/CWindowManagerAndroid.h b/include/nbl/ui/CWindowManagerAndroid.h index 7d62bd3c08..3fc7a4c0e0 100644 --- a/include/nbl/ui/CWindowManagerAndroid.h +++ b/include/nbl/ui/CWindowManagerAndroid.h @@ -1,14 +1,14 @@ #ifndef _NBL_SYSTEM_C_WINDOW_MANAGER_ANDROID_H_INCLUDED_ #define _NBL_SYSTEM_C_WINDOW_MANAGER_ANDROID_H_INCLUDED_ + #include "nbl/ui/IWindowManager.h" +#include "nbl/ui/CWindowAndroid.h" #ifdef _NBL_PLATFORM_ANDROID_ #include #include #include -#include "nbl/ui/CWindowAndroid.h" - #include #include #include @@ -16,8 +16,9 @@ namespace nbl::ui { - class CWindowManagerAndroid : public IWindowManager - { + +class CWindowManagerAndroid : public IWindowManager +{ android_app* m_app; std::atomic_flag windowIsCreated; constexpr static uint32_t CIRCULAR_BUFFER_CAPACITY = CWindowAndroid::CIRCULAR_BUFFER_CAPACITY; @@ -30,6 +31,7 @@ namespace nbl::ui windowIsCreated.clear(); } ~CWindowManagerAndroid() = default; + core::smart_refctd_ptr createWindow(IWindow::SCreationParams&& creationParams) override final { bool createdBefore = windowIsCreated.test_and_set(); @@ -39,6 +41,7 @@ namespace nbl::ui } return nullptr; } + SDisplayInfo getPrimaryDisplayInfo() const override final { struct fb_var_screeninfo fb_var; @@ -53,14 +56,16 @@ namespace nbl::ui info.y = fb_var.yoffset; return info; } + void destroyWindow(IWindow* wnd) override final { } + void handleInput_impl(android_app* data, AInputEvent* event); void handleCommand_impl(android_app* app, int32_t cmd); static E_KEY_CODE getNablaKeyCodeFromNative(int32_t nativeKeyCode); +}; - }; } #endif diff --git a/include/nbl/ui/IWindowAndroid.h b/include/nbl/ui/IWindowAndroid.h index f7e21e0d8f..457dd16985 100755 --- a/include/nbl/ui/IWindowAndroid.h +++ b/include/nbl/ui/IWindowAndroid.h @@ -1,5 +1,5 @@ -#ifndef __NBL_I_WINDOW_ANDROID_H_INCLUDED__ -#define __NBL_I_WINDOW_ANDROID_H_INCLUDED__ +#ifndef _NBL_I_WINDOW_ANDROID_H_INCLUDED_ +#define _NBL_I_WINDOW_ANDROID_H_INCLUDED_ #include "nbl/ui/IWindow.h" @@ -12,15 +12,16 @@ namespace nbl::ui class IWindowAndroid : public IWindow { -protected: - virtual ~IWindowAndroid() = default; - IWindowAndroid(SCreationParams&& params) : IWindow(std::move(params)) {} -public: - using IWindow::IWindow; + protected: + virtual ~IWindowAndroid() = default; + IWindowAndroid(SCreationParams&& params) : IWindow(std::move(params)) {} - using native_handle_t = struct ANativeWindow*; + public: + using IWindow::IWindow; - virtual const native_handle_t& getNativeHandle() const = 0; + using native_handle_t = struct ANativeWindow*; + + virtual const native_handle_t& getNativeHandle() const = 0; }; } From 322c3535e937c7f7b5f1270cb64250c5ac1bb3d0 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 21:03:59 +0100 Subject: [PATCH 84/91] bunch of important nbl::system fixes --- examples_tests/52.SystemTest/main.cpp | 127 ++++++++++-------- examples_tests/Readme.md | 4 +- include/nbl/asset/IAssetManager.h | 7 +- include/nbl/system/CFileLogger.h | 9 +- src/nbl/asset/interchange/CImageLoaderJPG.cpp | 2 +- src/nbl/system/ISystem.cpp | 19 +-- 6 files changed, 97 insertions(+), 71 deletions(-) diff --git a/examples_tests/52.SystemTest/main.cpp b/examples_tests/52.SystemTest/main.cpp index 2952f2971e..562235cbe2 100644 --- a/examples_tests/52.SystemTest/main.cpp +++ b/examples_tests/52.SystemTest/main.cpp @@ -210,26 +210,25 @@ class WindowEventCallback : public IWindow::IEventCallback int main(int argc, char** argv) { - path CWD = path(argv[0]).parent_path().generic_string() + "/"; - path mediaWD = CWD.generic_string() + "../../media/"; - auto system = CommonAPI::createSystem(); - // *** Select stdout/file logger *** - auto logger = make_smart_refctd_ptr(); - //auto logger = system::CFileLogger::create(logFileName); - // *** If you don't want logging, uncomment this one line*** - // logger = nullptr; - // ************************************************************************************** + const path CWD = path(argv[0]).parent_path().generic_string() + "/"; + const path mediaWD = CWD.generic_string() + "../../media/"; - auto assetManager = core::make_smart_refctd_ptr(smart_refctd_ptr(system)); + auto system = CommonAPI::createSystem(); + // TODO: system->deleteFile("log.txt"); - auto winManager = core::make_smart_refctd_ptr(); - + core::smart_refctd_ptr logger; { system::ISystem::future_t> future; - system->createFile(future, "log.txt", nbl::system::IFile::ECF_READ_WRITE); + system->createFile(future, CWD/"log.txt", nbl::system::IFile::ECF_READ_WRITE); auto file = future.get(); + logger = core::make_smart_refctd_ptr(std::move(file),false); } + auto assetManager = core::make_smart_refctd_ptr(smart_refctd_ptr(system)); + + auto winManager = core::make_smart_refctd_ptr(); + + IWindow::SCreationParams params; params.callback = nullptr; params.width = 720; @@ -240,26 +239,36 @@ int main(int argc, char** argv) params.flags = IWindow::ECF_NONE; params.windowCaption = "Test Window"; - auto input = make_smart_refctd_ptr(system::logger_opt_smart_ptr(logger)); - auto windowCb = make_smart_refctd_ptr(core::smart_refctd_ptr(input),system::logger_opt_smart_ptr(logger)); + auto input = make_smart_refctd_ptr(system::logger_opt_smart_ptr(smart_refctd_ptr(logger))); + auto windowCb = make_smart_refctd_ptr(core::smart_refctd_ptr(input),system::logger_opt_smart_ptr(smart_refctd_ptr(logger))); params.callback = windowCb; // ********************************* auto window = winManager->createWindow(std::move(params)); auto* cursorControl = window->getCursorControl(); system::ISystem::future_t> future; - system->createFile(future, CWD.generic_string() + "testFile.txt", core::bitflag(nbl::system::IFile::ECF_READ_WRITE) | IFile::ECF_MAPPABLE); + system->createFile(future, CWD/"testFile.txt", core::bitflag(nbl::system::IFile::ECF_READ_WRITE)/*Growing mappable files are a TODO |IFile::ECF_MAPPABLE*/); auto file = future.get(); - std::string fileData = "Test file data!"; - system::future writeFuture; - file->write(writeFuture, fileData.data(), 0, fileData.length()); - assert(writeFuture.get() == fileData.length()); + { + const std::string fileData = "Test file data!"; - std::string readStr(fileData.length(), '\0'); - system::future readFuture; - file->read(readFuture, readStr.data(), 0, readStr.length()); - assert(readFuture.get() == fileData.length()); + system::IFile::success_t writeSuccess; + file->write(writeSuccess, fileData.data(), 0, fileData.length()); + { + const bool success = bool(writeSuccess); + assert(success); + } + + std::string readStr(fileData.length(), '\0'); + system::IFile::success_t readSuccess; + file->read(readSuccess, readStr.data(), 0, readStr.length()); + { + const bool success = bool(readSuccess); + assert(success); + } + assert(readStr == fileData); + } // polling for events! InputSystem::ChannelReader mouse; @@ -305,44 +314,19 @@ int main(int argc, char** argv) } } }; - - auto bigarch = system->openFileArchive(CWD.generic_string() + "../../media/sponza.zip"); - system->mount(std::move(bigarch), "sponza"); - - system->copy(CWD.generic_string() + "pngWriteSuccessful.png", "pngCopy.png"); - - system->createDirectory(CWD.generic_string() + "textures1"); - system->copy(CWD.generic_string() + "textures", CWD.generic_string() + "textures1"); - system->copy("sponza/textures", CWD.generic_string() + "textures"); - system->moveFileOrDirectory("file.tar", "movedFile.tar"); - system->listFilesInDirectory(CWD.generic_string() + "textures"); - { - system::future> fut; - system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ); - auto file = fut.get(); - { - system::future> fut; - system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ); - file = fut.get(); - } - std::string str(5, '\0'); - system::future readFut; - file->read(readFut, str.data(), 0, 5); - readFut.get(); - std::cout << str << std::endl; - } IAssetLoader::SAssetLoadParams lp; lp.workingDirectory = mediaWD; //PNG loader test { - auto asset = assetManager->getAsset("cegui_alfisko/screenshot.png", lp); + auto asset = assetManager->getAsset("Cerberus_by_Andrew_Maximov/Textures/Cerberus_H.png", lp); assert(!asset.getContents().empty()); - auto cpuImage = static_cast(asset.getContents().begin()->get()); + auto cpuImage = IAsset::castDown(asset.getContents()[0]); core::smart_refctd_ptr imageView; + ICPUImageView::SCreationParams imgViewParams; imgViewParams.flags = static_cast(0u); - imgViewParams.format = E_FORMAT::EF_R8G8B8_UINT; + imgViewParams.format = cpuImage->getCreationParameters().format; imgViewParams.image = core::smart_refctd_ptr(cpuImage); imgViewParams.viewType = ICPUImageView::ET_2D; imgViewParams.subresourceRange = { static_cast(0u),0u,1u,0u,1u }; @@ -350,7 +334,6 @@ int main(int argc, char** argv) IAssetWriter::SAssetWriteParams wp(imageView.get()); wp.workingDirectory = CWD; - assetManager->writeAsset("pngWriteSuccessful.png", wp); } //TODO OBJ loader test @@ -367,7 +350,7 @@ int main(int argc, char** argv) { auto asset = assetManager->getAsset("dwarf.jpg", lp); assert(!asset.getContents().empty()); - auto cpuImage = static_cast(asset.getContents().begin()->get()); + auto cpuImage = IAsset::castDown(asset.getContents()[0]); core::smart_refctd_ptr imageView; ICPUImageView::SCreationParams imgViewParams; imgViewParams.flags = static_cast(0u); @@ -382,6 +365,40 @@ int main(int argc, char** argv) assetManager->writeAsset("jpgWriteSuccessful.jpg", wp); } + + + auto bigarch = system->openFileArchive(CWD/"../../media/sponza.zip"); + system->mount(std::move(bigarch), "sponza"); + + system->copy(CWD/"pngWriteSuccessful.png", CWD/"pngCopy.png"); + + system->createDirectory(CWD/"textures1"); + system->copy(CWD/"textures", CWD/"textures1"); + system->copy("sponza/textures", CWD/"textures"); + + const auto items = system->listItemsInDirectory(CWD/"textures"); + for (const auto& item : items) + logger->log("%s",system::ILogger::ELL_DEBUG,item.c_str()); + +/* TODO: Tart Archive reader test + system->moveFileOrDirectory("file.tar","movedFile.tar"); + { + system::future> fut; + system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ); + auto file = fut.get(); + { + system::future> fut; + system->createFile(fut, "tarArch/file.txt", IFile::ECF_READ); + file = fut.get(); + } + std::string str(5, '\0'); + system::future readFut; + file->read(readFut, str.data(), 0, 5); + readFut.get(); + std::cout << str << std::endl; + } +*/ + while (windowCb->isWindowOpen()) { input->getDefaultMouse(&mouse); diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 75bc2fc7b3..873ecb7c9b 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -83,10 +83,10 @@ N = No support | 49.ComputeFFT | S | N | S | S | N | S | N | N | | | 50.NewAPITest | W | W | W | W | W | W | W | W | | | 51.RadixSort | W | N | W | W | N | W | N | W | | -| 52.SystemTest | S | S | S | S | S | S | S | S | | +| 52.SystemTest | Y | Y | Y | S | S | S | S | S | | | 53.ComputeShaders | S | N | S | S | N | S | N | S | | | 54.Transformations | Y | Y | B | S | S | S | S | S | | -| 55.RGB18E7S3 | S | S | S | S | S | S | N | N | | +| 55.RGB18E7S3 | Y | Y | Y | S | S | S | N | N | | | 56.RayQuery | N | N | Y | N | N | S | N | S | | | 57.AndroidSample | N | N | N | N | N | N | S | S | | | 58.MediaUnpackingOnAndroid | N | N | N | N | N | N | Y | Y | | diff --git a/include/nbl/asset/IAssetManager.h b/include/nbl/asset/IAssetManager.h index 823a4e297a..235e8b995a 100644 --- a/include/nbl/asset/IAssetManager.h +++ b/include/nbl/asset/IAssetManager.h @@ -321,9 +321,14 @@ class IAssetManager : public core::IReferenceCounted, public core::QuitSignallin SAssetBundle getAssetInHierarchy_impl(const std::string& _filePath, const IAssetLoader::SAssetLoadParams& _params, uint32_t _hierarchyLevel, IAssetLoader::IAssetLoaderOverride* _override) { IAssetLoader::SAssetLoadContext ctx(_params, nullptr); - system::path filePath = _filePath; + system::path filePath = _filePath; _override->getLoadFilename(filePath, m_system.get(), ctx, _hierarchyLevel); + if (!m_system->exists(filePath,system::IFile::ECF_READ)) + { + filePath = _params.workingDirectory/filePath; + _override->getLoadFilename(filePath, m_system.get(), ctx, _hierarchyLevel); + } system::ISystem::future_t> future; m_system->createFile(future, filePath, system::IFile::ECF_READ); diff --git a/include/nbl/system/CFileLogger.h b/include/nbl/system/CFileLogger.h index 21cc742b25..d625761c5e 100644 --- a/include/nbl/system/CFileLogger.h +++ b/include/nbl/system/CFileLogger.h @@ -10,8 +10,8 @@ namespace nbl::system class CFileLogger : public IThreadsafeLogger { public: - CFileLogger(core::smart_refctd_ptr&& _file, const core::bitflag logLevelMask=ILogger::defaultLogMask()) - : IThreadsafeLogger(logLevelMask), m_file(std::move(_file)) + CFileLogger(core::smart_refctd_ptr&& _file, const bool append, const core::bitflag logLevelMask=ILogger::defaultLogMask()) + : IThreadsafeLogger(logLevelMask), m_file(std::move(_file)), m_pos(append ? m_file->getSize():0ull) { } @@ -22,11 +22,12 @@ class CFileLogger : public IThreadsafeLogger { const auto str = constructLogString(fmt, logLevel, args); ISystem::future_t future; - m_file->write(future,str.data(),m_file->getSize(),str.length()); - future.get(); // need to use the future to make sure op is actually executed :( + m_file->write(future,str.data(),m_pos,str.length()); + m_pos += future.get(); // need to use the future to make sure op is actually executed :( } core::smart_refctd_ptr m_file; + size_t m_pos; }; } diff --git a/src/nbl/asset/interchange/CImageLoaderJPG.cpp b/src/nbl/asset/interchange/CImageLoaderJPG.cpp index 2b842b0ee3..e0d5409aa8 100644 --- a/src/nbl/asset/interchange/CImageLoaderJPG.cpp +++ b/src/nbl/asset/interchange/CImageLoaderJPG.cpp @@ -159,7 +159,7 @@ bool CImageLoaderJPG::isALoadableFileFormat(system::IFile* _file, const system:: uint32_t header = 0; system::IFile::success_t success; _file->read(success, &header, 6, sizeof(uint32_t)); - return success && (header&0x00FFD8FFu)==0x00FFD8FFu; + return success && ((header&0x00FFD8FFu)==0x00FFD8FFu || header == 0x4a464946 || header == 0x4649464a || header == 0x66697845u || header == 0x70747468u); // maybe 0x4a464946 can go #endif } diff --git a/src/nbl/system/ISystem.cpp b/src/nbl/system/ISystem.cpp index cb52465263..b11fd104e8 100644 --- a/src/nbl/system/ISystem.cpp +++ b/src/nbl/system/ISystem.cpp @@ -84,12 +84,12 @@ core::vector ISystem::listItemsInDirectory(const system::path& p) core::vector res; res.reserve(512u); - auto addArchiveItems = [this,&res](const path& archPath) -> void + auto addArchiveItems = [this,&res](const path& archPath, const path& dirPath) -> void { const auto archives = m_cachedArchiveFiles.findRange(archPath); for (auto& arch : archives) { - const auto assets = arch.second->listAssets(); + const auto assets = arch.second->listAssets(std::filesystem::relative(dirPath,archPath)); for (auto& item : assets) res.push_back(archPath/item.pathRelativeToArchive); } @@ -102,7 +102,7 @@ core::vector ISystem::listItemsInDirectory(const system::path& p) { res.push_back(entry.path()); // entry could have been an archive - addArchiveItems(entry.path()); + addArchiveItems(entry.path(),p); } else { @@ -122,13 +122,15 @@ core::vector ISystem::listItemsInDirectory(const system::path& p) } #endif // check for part of subpath being an archive - system::path path = std::filesystem::exists(p) ? std::filesystem::canonical(p.parent_path()):p.parent_path(); + auto path = std::filesystem::exists(p) ? std::filesystem::canonical(p):p; // going up the directory tree while (!path.empty() && path.parent_path()!=path) { - path = std::filesystem::exists(path) ? std::filesystem::canonical(path):path; - addArchiveItems(path); + addArchiveItems(path,p); + const bool ex = std::filesystem::exists(path); path = path.parent_path(); + if (ex) + path = std::filesystem::canonical(path); } } return res; @@ -165,12 +167,13 @@ bool ISystem::copy(const system::path& from, const system::path& to) createFile(readFileFut,from,core::bitflag(IFile::ECF_READ)|IFile::ECF_COHERENT); createFile(writeFileFut,to,IFile::ECF_WRITE); auto readF = readFileFut.get(); + const IFile* readFptr = readF.get(); auto writeF = writeFileFut.get(); - if (!readF || !readF->getMappedPointer() || !writeF) + if (!readF || !readFptr->getMappedPointer() || !writeF) return false; IFile::success_t bytesWritten; - writeF->write(bytesWritten,readF->getMappedPointer(),0,readF->getSize()); + writeF->write(bytesWritten,readFptr->getMappedPointer(),0,readF->getSize()); return bool(bytesWritten); }; if (isPathReadOnly(from)) From ff2c72104802e14976d0b055e6e6ac7c436d6f36 Mon Sep 17 00:00:00 2001 From: devsh Date: Tue, 15 Mar 2022 21:06:36 +0100 Subject: [PATCH 85/91] Android fixes --- include/nbl/system/CApplicationAndroid.h | 8 +++++--- include/nbl/ui/CGraphicalApplicationAndroid.h | 6 ++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/nbl/system/CApplicationAndroid.h b/include/nbl/system/CApplicationAndroid.h index 011a7d8854..ed0a47d5e7 100644 --- a/include/nbl/system/CApplicationAndroid.h +++ b/include/nbl/system/CApplicationAndroid.h @@ -6,13 +6,15 @@ #include "nbl/system/IApplicationFramework.h" #include "nbl/system/CStdoutLoggerAndroid.h" - -namespace nbl::system -{ #ifdef _NBL_PLATFORM_ANDROID_ #include #include #include +#endif + +namespace nbl::system +{ +#ifdef _NBL_PLATFORM_ANDROID_ class CApplicationAndroid : public IApplicationFramework { diff --git a/include/nbl/ui/CGraphicalApplicationAndroid.h b/include/nbl/ui/CGraphicalApplicationAndroid.h index 6012b666e3..754368b0d4 100644 --- a/include/nbl/ui/CGraphicalApplicationAndroid.h +++ b/include/nbl/ui/CGraphicalApplicationAndroid.h @@ -64,8 +64,7 @@ namespace nbl::ui ctx.framework = framework.get(); nbl::ui::IWindow::SCreationParams params; params.callback = nullptr; - auto caller = core::make_smart_refctd_ptr(); - auto system = core::make_smart_refctd_ptr(std::move(caller), app->activity, env, APKResourcesPath); + auto system = core::make_smart_refctd_ptr(app->activity, env, APKResourcesPath); framework->setSystem(std::move(system)); //if (app->savedState != nullptr) { // ctx.state = (nbl::system::CApplicationAndroid::SSavedState*)app->savedState; @@ -110,8 +109,7 @@ namespace nbl::ui app->userData = &ctx; auto framework = nbl::core::make_smart_refctd_ptr(app, env, APKResourcesPath, privateOutputCWD, sharedInputCWD, sharedOutputCWD); ctx.framework = framework.get(); - auto caller = core::make_smart_refctd_ptr(); - auto system = core::make_smart_refctd_ptr(std::move(caller), app->activity, env, APKResourcesPath); + auto system = core::make_smart_refctd_ptr(app->activity, env, APKResourcesPath); framework->setSystem(std::move(system)); //if (app->savedState != nullptr) { // ctx.state = (nbl::system::CApplicationAndroid::SSavedState*)app->savedState; From 0f65fba57ecc2252cbcf089520f72aae17ec5b22 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 16 Mar 2022 10:15:35 +0100 Subject: [PATCH 86/91] Fix example 47 and test 43 --- examples_tests/47.DerivMapTest/main.cpp | 46 ++++++++++++++----------- examples_tests/Readme.md | 6 ++-- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/examples_tests/47.DerivMapTest/main.cpp b/examples_tests/47.DerivMapTest/main.cpp index 0a8d3eabcc..ebc65248f6 100644 --- a/examples_tests/47.DerivMapTest/main.cpp +++ b/examples_tests/47.DerivMapTest/main.cpp @@ -393,8 +393,8 @@ class DerivMapTestApp : public ApplicationBase swapchain->acquireNextImage(MAX_TIMEOUT, imageAcquire[resourceIx].get(), nullptr, &acquiredNextFBO); - nbl::video::IGPUCommandBuffer::SRenderpassBeginInfo beginInfo; { + nbl::video::IGPUCommandBuffer::SRenderpassBeginInfo beginInfo; VkRect2D area; area.offset = { 0,0 }; area.extent = { NBL_WINDOW_WIDTH, NBL_WINDOW_HEIGHT }; @@ -408,9 +408,9 @@ class DerivMapTestApp : public ApplicationBase beginInfo.renderpass = renderpass; beginInfo.renderArea = area; beginInfo.clearValues = &clear; + commandBuffer->beginRenderPass(&beginInfo, nbl::asset::ESC_INLINE); } - commandBuffer->beginRenderPass(&beginInfo, nbl::asset::ESC_INLINE); commandBuffer->bindGraphicsPipeline(gpuGraphicsPipeline.get()); commandBuffer->bindDescriptorSets(asset::EPBP_GRAPHICS, gpuGraphicsPipeline->getRenderpassIndependentPipeline()->getLayout(), 3, 1, &gpuSamplerDescriptorSet3.get(), 0u); ext::FullScreenTriangle::recordDrawCalls(commandBuffer.get()); @@ -498,7 +498,7 @@ class DerivMapTestApp : public ApplicationBase const auto swapchainImageUsage = static_cast(asset::IImage::EUF_COLOR_ATTACHMENT_BIT); const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN); - CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "MeshLoaders", NBL_WINDOW_WIDTH, NBL_WINDOW_HEIGHT, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); + CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL, "MeshLoaders", NBL_WINDOW_WIDTH, NBL_WINDOW_HEIGHT, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat); window = std::move(initOutput.window); gl = std::move(initOutput.apiConnection); surface = std::move(initOutput.surface); @@ -541,17 +541,19 @@ class DerivMapTestApp : public ApplicationBase { switch (typeOfImage) { - case nbl::asset::IImageView::ET_2D: - return "../present2D.frag"; - case nbl::asset::IImageView::ET_2D_ARRAY: - return "../present2DArray.frag"; - case nbl::asset::IImageView::ET_CUBE_MAP: - return "../presentCubemap.frag"; - default: - { - assert(false); - } + case nbl::asset::IImageView::ET_2D: + return "../present2D.frag"; + case nbl::asset::IImageView::ET_2D_ARRAY: + return "../present2DArray.frag"; + case nbl::asset::IImageView::ET_CUBE_MAP: + return "../presentCubemap.frag"; + default: + { + assert(false); + break; + } } + return ""; }; auto fs_bundle = assetManager->getAsset(getPathToFragmentShader(), {}); @@ -631,18 +633,21 @@ class DerivMapTestApp : public ApplicationBase auto& captionData = captionTexturesData.emplace_back(); captionData.name = filename.string(); captionData.extension = extension.string(); - captionData.viewType = [&]() + captionData.viewType = [&]() -> std::string { const auto& viewType = newCpuImageViewTexture->getCreationParameters().viewType; if (viewType == nbl::asset::IImageView::ET_2D) - return std::string("ET_2D"); + return "ET_2D"; else if (viewType == nbl::asset::IImageView::ET_2D_ARRAY) - return std::string("ET_2D_ARRAY"); + return "ET_2D_ARRAY"; else if (viewType == nbl::asset::IImageView::ET_CUBE_MAP) - return std::string("ET_CUBE_MAP"); + return "ET_CUBE_MAP"; else + { assert(false); + return ""; + } }(); const std::string finalFileNameWithExtension = captionData.name + captionData.extension; @@ -663,9 +668,10 @@ class DerivMapTestApp : public ApplicationBase } } - gpuImageViews = cpu2gpu.getGPUObjectsFromAssets(cpuImageViews.data(), cpuImageViews.data() + cpuImageViews.size(), cpu2gpuParams); - if (!gpuImageViews || gpuImageViews->size() < cpuImageViews.size()) - assert(false); + cpu2gpuParams.beginCommandBuffers(); + gpuImageViews = cpu2gpu.getGPUObjectsFromAssets(cpuImageViews.data(), cpuImageViews.data()+cpuImageViews.size(), cpu2gpuParams); + cpu2gpuParams.waitForCreationToComplete(false); + assert(gpuImageViews && gpuImageViews->size()==cpuImageViews.size()); } void workLoopBody() override diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 873ecb7c9b..eed58b95db 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -74,12 +74,12 @@ N = No support | 40.GLITest | S | S | S | S | S | S | N | S | COMPILE_WITH_GLI_LOADER | | 41.VisibilityBuffer | S | S | S | S | S | S | N | N | | | 42.FragmentShaderPathTracer | B | B | Y | S | S | S | S | S | | -| 43.SumAndCDFFilters | S | N | S | S | N | S | N | N | | +| 43.SumAndCDFFilters | Y | Y | Y | S | N | S | N | N | | | 44.LevelCurveExtraction | S | N | S | S | N | S | N | N | | | 45.BRDFEvalTest | S | S | S | S | S | S | N | S | | | 46.SamplingValidation | S | S | S | S | S | S | N | S | | -| 47.DerivMapTest | S | N | S | S | N | S | N | N | | -| 48.ArithmeticUnitTest | Y | N | Y | S | N | S | N | S | | +| 47.DerivMapTest | Y | Y | B | S | N | S | N | N | | +| 48.ArithmeticUnitTest | Y | Y | Y | S | N | S | N | S | | | 49.ComputeFFT | S | N | S | S | N | S | N | N | | | 50.NewAPITest | W | W | W | W | W | W | W | W | | | 51.RadixSort | W | N | W | W | N | W | N | W | | From 32a79165db87ac5c6260db32b742ea670e571672 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 16 Mar 2022 11:29:11 +0100 Subject: [PATCH 87/91] Make sure to use steady clock, high resolution was responsible for time going backwards and deadlocks on GLsync waits. GLES backend has a bug where the tests timeout!? Vulkan has a bug because new Buffer API is not ready yet. --- examples_tests/48.ArithmeticUnitTest/main.cpp | 9 +++++---- examples_tests/Readme.md | 2 +- include/nbl/core/EventDeferredHandler.h | 2 +- include/nbl/video/IGPUFence.h | 5 +++-- include/nbl/video/alloc/SubAllocatedDataBuffer.h | 2 +- include/nbl/video/utilities/CPropertyPoolHandler.h | 2 +- include/nbl/video/utilities/IUtilities.h | 2 +- src/nbl/video/COpenGLSync.cpp | 4 ++-- src/nbl/video/IOpenGL_LogicalDevice.h | 7 ++++++- src/nbl/video/utilities/CPropertyPoolHandler.cpp | 2 +- src/nbl/video/utilities/IUtilities.cpp | 2 +- 11 files changed, 23 insertions(+), 16 deletions(-) diff --git a/examples_tests/48.ArithmeticUnitTest/main.cpp b/examples_tests/48.ArithmeticUnitTest/main.cpp index 667b6478e0..45e00e8e81 100644 --- a/examples_tests/48.ArithmeticUnitTest/main.cpp +++ b/examples_tests/48.ArithmeticUnitTest/main.cpp @@ -201,6 +201,7 @@ bool validateResults(ILogicalDevice* device, const uint32_t* inputData, const ui auto dataFromBuffer = reinterpret_cast(mem->getMappedPointer()); const uint32_t subgroupSize = (*dataFromBuffer++); + // TODO: parallel for // now check if the data obtained has valid values uint32_t* tmp = new uint32_t[workgroupSize]; uint32_t* ballotInput = new uint32_t[workgroupSize]; @@ -281,7 +282,7 @@ bool runTest( passed = validateResults(device, inputData, workgroupSize, workgroupCount, buffers[6].get(),logger)&&passed; if(is_workgroup_test) { - passed = validateResults(device, inputData, workgroupSize, workgroupCount, buffers[7].get(),logger) && passed; + passed = validateResults(device, inputData, workgroupSize, workgroupCount, buffers[7].get(),logger)&&passed; } return passed; @@ -300,7 +301,7 @@ class ArythmeticUnitTestApp : public NonGraphicalApplicationBase void onAppInitialized_impl() override { CommonAPI::InitOutput initOutput; - CommonAPI::InitWithNoExt(initOutput, nbl::video::EAT_OPENGL, "Subgroup Arithmetic Test"); + CommonAPI::InitWithNoExt(initOutput, video::EAT_OPENGL, "Subgroup Arithmetic Test"); gl = std::move(initOutput.apiConnection); gpuPhysicalDevice = std::move(initOutput.physicalDevice); logicalDevice = std::move(initOutput.logicalDevice); @@ -335,7 +336,7 @@ class ArythmeticUnitTestApp : public NonGraphicalApplicationBase params.queueFamilyIndexCount = 0; params.queueFamilyIndices = nullptr; params.sharingMode = ESM_CONCURRENT; - params.usage = IGPUBuffer::EUF_STORAGE_BUFFER_BIT; + params.usage = core::bitflag(IGPUBuffer::EUF_STORAGE_BUFFER_BIT)|IGPUBuffer::EUF_TRANSFER_SRC_BIT; IDriverMemoryBacked::SDriverMemoryRequirements reqs; reqs.vulkanReqs.memoryTypeBits = ~0u; reqs.vulkanReqs.alignment = 256u; @@ -424,7 +425,7 @@ class ArythmeticUnitTestApp : public NonGraphicalApplicationBase core::smart_refctd_ptr cmdbuf; logicalDevice->createCommandBuffers(cmdPool.get(), IGPUCommandBuffer::EL_PRIMARY, 1u, &cmdbuf); computeQueue->startCapture(); - for (uint32_t workgroupSize = 1u; workgroupSize <= 1024u; workgroupSize++) + for (uint32_t workgroupSize=45u; workgroupSize<=1024u; workgroupSize++) { core::smart_refctd_ptr pipelines[kTestTypeCount]; for (uint32_t i = 0u; i < kTestTypeCount; i++) diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index eed58b95db..35445dfacb 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -79,7 +79,7 @@ N = No support | 45.BRDFEvalTest | S | S | S | S | S | S | N | S | | | 46.SamplingValidation | S | S | S | S | S | S | N | S | | | 47.DerivMapTest | Y | Y | B | S | N | S | N | N | | -| 48.ArithmeticUnitTest | Y | Y | Y | S | N | S | N | S | | +| 48.ArithmeticUnitTest | Y | B | B | S | S | S | N | S | | | 49.ComputeFFT | S | N | S | S | N | S | N | N | | | 50.NewAPITest | W | W | W | W | W | W | W | W | | | 51.RadixSort | W | N | W | W | N | W | N | W | | diff --git a/include/nbl/core/EventDeferredHandler.h b/include/nbl/core/EventDeferredHandler.h index 8c7323a3bf..c2a2363e3c 100644 --- a/include/nbl/core/EventDeferredHandler.h +++ b/include/nbl/core/EventDeferredHandler.h @@ -105,7 +105,7 @@ class DeferredEventHandlerST auto prev = mEvents.before_begin(); for (auto it = mEvents.begin(); it!=mEvents.end(); ) { - if (it->m_event.wait_until(std::chrono::high_resolution_clock::now()+std::chrono::microseconds(250ull))) + if (it->m_event.wait_until(std::chrono::steady_clock::now()+std::chrono::microseconds(250ull))) { it->m_function(); it = mEvents.erase_after(prev); diff --git a/include/nbl/video/IGPUFence.h b/include/nbl/video/IGPUFence.h index 7f7f595c4c..2838550244 100644 --- a/include/nbl/video/IGPUFence.h +++ b/include/nbl/video/IGPUFence.h @@ -65,10 +65,11 @@ class GPUEventWrapper : public core::Uncopyable return *this; } - template + template inline static std::chrono::time_point default_wait() { - return std::chrono::high_resolution_clock::now()+std::chrono::nanoseconds(50000ull); // 50 us + //return typename Clock::now()+std::chrono::nanoseconds(50000ull); // 50 us + return Clock::now()+std::chrono::nanoseconds(50000ull); // 50 us } IGPUFence::E_STATUS waitFenceWrapper(IGPUFence* fence, uint64_t timeout); diff --git a/include/nbl/video/alloc/SubAllocatedDataBuffer.h b/include/nbl/video/alloc/SubAllocatedDataBuffer.h index d76b7f8451..78724000e1 100644 --- a/include/nbl/video/alloc/SubAllocatedDataBuffer.h +++ b/include/nbl/video/alloc/SubAllocatedDataBuffer.h @@ -227,7 +227,7 @@ class SubAllocatedDataBuffer : protected core::impl::FriendOfHeterogenousMemoryA return multi_alloc(GPUEventWrapper::default_wait(),count,std::forward(args)...); } //! - template + template inline size_type multi_alloc(const std::chrono::time_point& maxWaitPoint, const Args&... args) noexcept { #ifdef _NBL_DEBUG diff --git a/include/nbl/video/utilities/CPropertyPoolHandler.h b/include/nbl/video/utilities/CPropertyPoolHandler.h index d63c70fbd5..008c6a0be7 100644 --- a/include/nbl/video/utilities/CPropertyPoolHandler.h +++ b/include/nbl/video/utilities/CPropertyPoolHandler.h @@ -187,7 +187,7 @@ class CPropertyPoolHandler final : public core::IReferenceCounted, public core:: StreamingTransientDataBufferMT<>* const upBuff, IGPUCommandBuffer* const cmdbuf, IGPUFence* const fence, IGPUQueue* const queue, const asset::SBufferBinding& scratch, UpStreamingRequest*& requests, const uint32_t requestCount, uint32_t& waitSemaphoreCount, IGPUSemaphore* const*& semaphoresToWaitBeforeOverwrite, const asset::E_PIPELINE_STAGE_FLAGS*& stagesToWaitForPerSemaphore, - system::logger_opt_ptr logger, const std::chrono::high_resolution_clock::time_point& maxWaitPoint=std::chrono::high_resolution_clock::now()+std::chrono::microseconds(500u) + system::logger_opt_ptr logger, const std::chrono::steady_clock::time_point& maxWaitPoint=std::chrono::steady_clock::now()+std::chrono::microseconds(500u) ); // utility to help you fill out the tail move scatter request after the free, properly, returns if you actually need to transfer anything diff --git a/include/nbl/video/utilities/IUtilities.h b/include/nbl/video/utilities/IUtilities.h index 211ef74da7..f3d2b6287d 100644 --- a/include/nbl/video/utilities/IUtilities.h +++ b/include/nbl/video/utilities/IUtilities.h @@ -317,7 +317,7 @@ namespace nbl::video const uint32_t subSize = core::min(alllocationSize,size); // cannot use `multi_place` because of the extra padding size we could have added uint32_t localOffset = video::StreamingTransientDataBufferMT<>::invalid_address; - m_defaultUploadBuffer.get()->multi_alloc(std::chrono::high_resolution_clock::now()+std::chrono::microseconds(500u),1u,&localOffset,&alllocationSize,&alignment); + m_defaultUploadBuffer.get()->multi_alloc(std::chrono::steady_clock::now()+std::chrono::microseconds(500u),1u,&localOffset,&alllocationSize,&alignment); // copy only the unpadded part if (localOffset != video::StreamingTransientDataBufferMT<>::invalid_address) { diff --git a/src/nbl/video/COpenGLSync.cpp b/src/nbl/video/COpenGLSync.cpp index 667ee76364..b6b2f74410 100644 --- a/src/nbl/video/COpenGLSync.cpp +++ b/src/nbl/video/COpenGLSync.cpp @@ -32,7 +32,7 @@ uint64_t COpenGLSync::prewait() const if (sync) return 0ull; - using clock_t = std::chrono::high_resolution_clock; + using clock_t = std::chrono::steady_clock; auto start = clock_t::now(); while (!sync) { @@ -53,7 +53,7 @@ COpenGLSync::E_STATUS COpenGLSync::waitCPU(IOpenGL_FunctionTable* _gl, uint64_t return (cachedRetval = ES_TIMEOUT_EXPIRED); timeout -= spintime; - GLenum status = _gl->glSync.pglClientWaitSync(sync, lockedTable?GL_SYNC_FLUSH_COMMANDS_BIT:0, timeout); // GL_SYNC_FLUSH_COMMANDS_BIT to flags? + GLenum status = _gl->glSync.pglClientWaitSync(sync, lockedTable ? GL_SYNC_FLUSH_COMMANDS_BIT:0, timeout); switch (status) { case GL_ALREADY_SIGNALED: diff --git a/src/nbl/video/IOpenGL_LogicalDevice.h b/src/nbl/video/IOpenGL_LogicalDevice.h index afcce26b3f..aac6bfb2ed 100755 --- a/src/nbl/video/IOpenGL_LogicalDevice.h +++ b/src/nbl/video/IOpenGL_LogicalDevice.h @@ -852,7 +852,12 @@ class IOpenGL_LogicalDevice : public ILogicalDevice, protected impl::IOpenGL_Log if(notFirstRun && now>=timeoutPoint) return IGPUFence::ES_TIMEOUT; else if (_waitAll) // all fences have to get signalled anyway so no use round robining - timeout = std::chrono::duration_cast(timeoutPoint-now).count(); + { + if (timeoutPoint>now) + timeout = std::chrono::duration_cast(timeoutPoint-now).count(); + else + timeout = 0ull; + } else if (i==0u) // if we're only looking for one to succeed then poll with increasing timeouts until deadline timeout <<= 1u; } diff --git a/src/nbl/video/utilities/CPropertyPoolHandler.cpp b/src/nbl/video/utilities/CPropertyPoolHandler.cpp index 6255728897..00f942ac1c 100644 --- a/src/nbl/video/utilities/CPropertyPoolHandler.cpp +++ b/src/nbl/video/utilities/CPropertyPoolHandler.cpp @@ -174,7 +174,7 @@ uint32_t CPropertyPoolHandler::transferProperties( StreamingTransientDataBufferMT<>* const upBuff, IGPUCommandBuffer* const cmdbuf, IGPUFence* const fence, IGPUQueue* const queue, const asset::SBufferBinding& scratch, UpStreamingRequest* &requests, const uint32_t requestCount, uint32_t& waitSemaphoreCount, IGPUSemaphore* const*& semaphoresToWaitBeforeOverwrite, const asset::E_PIPELINE_STAGE_FLAGS*& stagesToWaitForPerSemaphore, - system::logger_opt_ptr logger, const std::chrono::high_resolution_clock::time_point& maxWaitPoint + system::logger_opt_ptr logger, const std::chrono::steady_clock::time_point& maxWaitPoint ) { if (!requestCount) diff --git a/src/nbl/video/utilities/IUtilities.cpp b/src/nbl/video/utilities/IUtilities.cpp index 20880adad7..a0e2fb90fe 100644 --- a/src/nbl/video/utilities/IUtilities.cpp +++ b/src/nbl/video/utilities/IUtilities.cpp @@ -151,7 +151,7 @@ void IUtilities::updateImageViaStagingBuffer( subSize = std::max(subSize, memoryLowerBound); const uint32_t uploadBufferSize = core::alignUp(subSize, allocationAlignment); // cannot use `multi_place` because of the extra padding size we could have added - m_defaultUploadBuffer.get()->multi_alloc(std::chrono::high_resolution_clock::now()+std::chrono::microseconds(500u), 1u, &localOffset, &uploadBufferSize, &allocationAlignment); + m_defaultUploadBuffer.get()->multi_alloc(std::chrono::steady_clock::now()+std::chrono::microseconds(500u), 1u, &localOffset, &uploadBufferSize, &allocationAlignment); bool failedAllocation = (localOffset == video::StreamingTransientDataBufferMT<>::invalid_address); // keep trying again From 58e19fcfaec3d86bbf00923a7ec9884cd183ad18 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 16 Mar 2022 11:33:59 +0100 Subject: [PATCH 88/91] Example 53 has bugs (needs fixing) Example 11 works beautifully, but not on Vulkan due to validation errors (mostly due to Buffer API). --- examples_tests/11.LoDSystem/main.cpp | 5 +++-- examples_tests/53.ComputeShaders/main.cpp | 2 +- examples_tests/Readme.md | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples_tests/11.LoDSystem/main.cpp b/examples_tests/11.LoDSystem/main.cpp index 905d99eda5..237962a1a2 100644 --- a/examples_tests/11.LoDSystem/main.cpp +++ b/examples_tests/11.LoDSystem/main.cpp @@ -114,7 +114,8 @@ void addLoDTable( poly <<= 1u; } - auto gpumeshes = video::CAssetPreservingGPUObjectFromAssetConverter().getGPUObjectsFromAssets(cpumeshes, cpumeshes + LoDLevels, cpu2gpuParams); + cpu2gpuParams.beginCommandBuffers(); + auto gpumeshes = video::CAssetPreservingGPUObjectFromAssetConverter().getGPUObjectsFromAssets(cpumeshes, cpumeshes+LoDLevels, cpu2gpuParams); core::smart_refctd_ptr pipeline; { @@ -346,7 +347,7 @@ class LoDSystemApp : public ApplicationBase const auto swapchainImageUsage = static_cast(asset::IImage::EUF_COLOR_ATTACHMENT_BIT | asset::IImage::EUF_TRANSFER_DST_BIT); const video::ISurface::SFormat surfaceFormat(asset::EF_B8G8R8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN); - CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL_ES, "Level of Detail System", WIN_W, WIN_H, FBO_COUNT, swapchainImageUsage, surfaceFormat, asset::EF_D32_SFLOAT); + CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL, "Level of Detail System", WIN_W, WIN_H, FBO_COUNT, swapchainImageUsage, surfaceFormat, asset::EF_D32_SFLOAT); window = std::move(initOutput.window); gl = std::move(initOutput.apiConnection); surface = std::move(initOutput.surface); diff --git a/examples_tests/53.ComputeShaders/main.cpp b/examples_tests/53.ComputeShaders/main.cpp index 71d15f3f73..11a4b22c8f 100644 --- a/examples_tests/53.ComputeShaders/main.cpp +++ b/examples_tests/53.ComputeShaders/main.cpp @@ -236,7 +236,7 @@ APP_CONSTRUCTOR(MeshLoadersApp) const auto swapchainImageUsage = static_cast(asset::IImage::EUF_COLOR_ATTACHMENT_BIT); const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN); - CommonAPI::InitWithDefaultExt(initOutput, video::EAT_VULKAN, "MeshLoaders", WIN_W, WIN_H, FBO_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); + CommonAPI::InitWithDefaultExt(initOutput, video::EAT_VULKAN, "ComputeShaders", WIN_W, WIN_H, FBO_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); window = std::move(initOutput.window); gl = std::move(initOutput.apiConnection); surface = std::move(initOutput.surface); diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 35445dfacb..2095518087 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -42,7 +42,7 @@ N = No support | FREE_SLOT | | | | | | | | | | | 09.ColorSpaceTest | W | W | W | W | W | W | W | W | | | 10.AllocatorTest | Y | Y | Y | S | S | S | N | N | | -| 11.LoDSystem | Y | N | B | S | N | S | N | S | | +| 11.LoDSystem | Y | Y | B | S | N | S | N | S | | | 12.glTF | W | N | W | W | N | W | N | W | COMPILE_WITH_GLTF_LOADER | | FREE_SLOT | | | | | | | | | | | 14.ComputeScan | Y | Y | B | S | S | S | S | S | | @@ -84,7 +84,7 @@ N = No support | 50.NewAPITest | W | W | W | W | W | W | W | W | | | 51.RadixSort | W | N | W | W | N | W | N | W | | | 52.SystemTest | Y | Y | Y | S | S | S | S | S | | -| 53.ComputeShaders | S | N | S | S | N | S | N | S | | +| 53.ComputeShaders | B | B | B | S | N | S | N | S | | | 54.Transformations | Y | Y | B | S | S | S | S | S | | | 55.RGB18E7S3 | Y | Y | Y | S | S | S | N | N | | | 56.RayQuery | N | N | Y | N | N | S | N | S | | From 4b073e1797d66176268409700eea9bc6d399d069 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 16 Mar 2022 11:57:26 +0100 Subject: [PATCH 89/91] Fix ZIP Archive Loader and test examples 06 and 07 --- examples_tests/07.SubpassBaking/main.cpp | 2 +- examples_tests/Readme.md | 2 +- src/nbl/system/CArchiveLoaderZip.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples_tests/07.SubpassBaking/main.cpp b/examples_tests/07.SubpassBaking/main.cpp index 164c86f61b..aec9b0cc86 100644 --- a/examples_tests/07.SubpassBaking/main.cpp +++ b/examples_tests/07.SubpassBaking/main.cpp @@ -146,7 +146,7 @@ class SubpassBaking : public ApplicationBase const auto swapchainImageUsage = static_cast(asset::IImage::EUF_COLOR_ATTACHMENT_BIT); const video::ISurface::SFormat surfaceFormat(asset::EF_R8G8B8A8_SRGB, asset::ECP_SRGB, asset::EOTF_sRGB); - CommonAPI::InitWithDefaultExt(initOutput, video::EAT_OPENGL, "SubpassBaking", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); + CommonAPI::InitWithDefaultExt(initOutput, video::EAT_VULKAN, "SubpassBaking", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT); window = std::move(initOutput.window); apiConnection = std::move(initOutput.apiConnection); surface = std::move(initOutput.surface); diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 2095518087..30920f656e 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -38,7 +38,7 @@ N = No support | 04.Keyframe | S | S | S | S | S | S | S | S | | | 05.NablaTutorialExample | Y | Y | Y | S | S | S | S | S | | | 06.MeshLoaders | Y | Y | Y | S | S | S | Y | Y | | -| 07.SubpassBaking | S | S | S | S | S | S | S | S | | +| 07.SubpassBaking | Y | Y | Y | S | S | S | S | S | | | FREE_SLOT | | | | | | | | | | | 09.ColorSpaceTest | W | W | W | W | W | W | W | W | | | 10.AllocatorTest | Y | Y | Y | S | S | S | N | N | | diff --git a/src/nbl/system/CArchiveLoaderZip.cpp b/src/nbl/system/CArchiveLoaderZip.cpp index 9702694c11..c3c06881b9 100644 --- a/src/nbl/system/CArchiveLoaderZip.cpp +++ b/src/nbl/system/CArchiveLoaderZip.cpp @@ -123,7 +123,7 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: item.pathRelativeToArchive = _path; item.size = meta.DataDescriptor.UncompressedSize; item.offset = offset; - item.ID = items.size(); + item.ID = itemsMetadata.size(); item.allocatorType = meta.CompressionMethod ? IFileArchive::EAT_VIRTUAL_ALLOC:IFileArchive::EAT_NULL; itemsMetadata.push_back(meta); }; @@ -232,7 +232,7 @@ core::smart_refctd_ptr CArchiveLoaderZip::createArchive_impl(core: SZIPFileHeader zipHeader; { IFile::success_t success; - file->read(success,&zipHeader,0ull,sizeof(zipHeader)); + file->read(success,&zipHeader,offset,sizeof(zipHeader)); if (!success) break; offset += success.getSizeToProcess(); @@ -393,7 +393,7 @@ CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFi CFileArchive::file_buffer_t retval = { nullptr,item->size,nullptr }; // void* decrypted = nullptr; - size_t decryptedSize = 0ull; + size_t decryptedSize = header.DataDescriptor.CompressedSize; auto freeOnFail = core::makeRAIIExiter([&actualCompressionMethod,&retval,&decrypted,&decryptedSize](){ if (decrypted && retval.buffer!=decrypted) { @@ -424,7 +424,7 @@ CFileArchive::file_buffer_t CArchiveLoaderZip::CArchive::getFileBuffer(const IFi const size_t reduction = saltSize+12u; if (header.DataDescriptor.CompressedSize<=reduction) return retval; - decryptedSize = header.DataDescriptor.CompressedSize-reduction; + decryptedSize -= reduction; } mmapPtr += saltSize; uint16_t& pwVerification = *reinterpret_cast(mmapPtr); From 862dffce61af7a6e9c7094f758297ebac4020842 Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 16 Mar 2022 12:09:26 +0100 Subject: [PATCH 90/91] Dynamic Texture Indexing is indexing the wrong textures :( --- examples_tests/21.DynamicTextureIndexing/main.cpp | 7 +++++-- examples_tests/Readme.md | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples_tests/21.DynamicTextureIndexing/main.cpp b/examples_tests/21.DynamicTextureIndexing/main.cpp index d99c77ce92..5225768ebb 100644 --- a/examples_tests/21.DynamicTextureIndexing/main.cpp +++ b/examples_tests/21.DynamicTextureIndexing/main.cpp @@ -372,6 +372,9 @@ class DynamicTextureIndexingApp : public ApplicationBase mdiCallParams[i].maxCount = pmbData.mdiParameterCount; } + // + cpu2gpuParams.beginCommandBuffers(); + //create pipeline IAssetLoader::SAssetLoadParams lp; auto vertexShaderBundle = assetManager->getAsset("../mesh.vert", lp); @@ -417,7 +420,6 @@ class DynamicTextureIndexingApp : public ApplicationBase } auto gpuShaders = cpu2gpu.getGPUObjectsFromAssets(shaders, shaders + 2, cpu2gpuParams); - //cpu2gpuParams.waitForCreationToComplete(); IGPUSpecializedShader* shaders[2] = { gpuShaders->operator[](0).get(), gpuShaders->operator[](1).get() }; gpuPipelineLayout = logicalDevice->createGPUPipelineLayout(range, range + 1, core::smart_refctd_ptr(ds0layout), core::smart_refctd_ptr(ds1layout)); @@ -454,7 +456,6 @@ class DynamicTextureIndexingApp : public ApplicationBase auto gpuTexture = cpu2gpu.getGPUObjectsFromAssets(&texture, &texture + 1, cpu2gpuParams)->front(); - cpu2gpuParams.waitForCreationToComplete(); info[bind].image.imageLayout = asset::EIL_UNDEFINED; info[bind].image.sampler = core::smart_refctd_ptr(sampler); @@ -487,6 +488,8 @@ class DynamicTextureIndexingApp : public ApplicationBase } } + cpu2gpuParams.waitForCreationToComplete(); + core::vectorSIMDf cameraPosition(-4, 0, 0); matrix4SIMD projectionMatrix = matrix4SIMD::buildProjectionMatrixPerspectiveFovLH(core::radians(60.0f), float(WIN_W) / WIN_H, 0.1, 100000); camera = Camera(cameraPosition, core::vectorSIMDf(0, 0, 0), projectionMatrix, 1.f, 1.f); diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index 30920f656e..a48afac411 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -52,7 +52,7 @@ N = No support | 18.MitsubaLoader | S | N | S | S | N | S | N | N | BUILD_MITSUBA_LOADER | | FREE_SLOT | | | | | | | | | | | 20.Megatexture | S | S | S | S | S | S | N | S | | -| 21.DynamicTextureIndexing | S | N | S | S | N | S | N | S | | +| 21.DynamicTextureIndexing | B | B | B | S | N | S | N | S | | | 22.RaytracedAO | N | N | W | N | N | W | N | N | BUILD_MITSUBA_LOADER | | 23.Autoexposure | Y | Y | Y | S | S | S | N | S | | | FREE_SLOT | | | | | | | | | | From 56f788858264e9b7894e8c02212bb2cbe80ee8aa Mon Sep 17 00:00:00 2001 From: devsh Date: Wed, 16 Mar 2022 14:29:15 +0100 Subject: [PATCH 91/91] Example 9 bugs: - RLE TGA loader doesn't work. - Visualization of array/cubemap not correct - screenshot doesn't work sometimes (maybe for certain formats) --- .../09.ColorSpaceTest/imagesTestList.txt | 52 +++++++++---------- examples_tests/09.ColorSpaceTest/main.cpp | 2 +- examples_tests/Readme.md | 4 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/examples_tests/09.ColorSpaceTest/imagesTestList.txt b/examples_tests/09.ColorSpaceTest/imagesTestList.txt index 1ef7db839b..198e960f7d 100644 --- a/examples_tests/09.ColorSpaceTest/imagesTestList.txt +++ b/examples_tests/09.ColorSpaceTest/imagesTestList.txt @@ -1,23 +1,23 @@ -; This is the testing suite for various IrrlichtBAW loaders/writers (JPG/PNG/TGA/BMP/DDS/KTX). +; This is the testing suite for various Nabla loaders/writers (JPG/PNG/TGA/BMP/DDS/KTX). ; BMP is currently unsupported for now. ; 16-bit PNG & 8-bit RLE (compressed) TGA is not supported. ; For licensing attribution, see LICENSE. ; JPG, colored & 8-bit grayscale -; ../../media/color_space_test/R8G8B8_1.jpg -; ../../media/color_space_test/R8G8B8_2.jpg +../../media/color_space_test/R8G8B8_1.jpg +../../media/color_space_test/R8G8B8_2.jpg -;../../media/color_space_test/R8_1.jpg -;../../media/color_space_test/R8_2.jpg +../../media/color_space_test/R8_1.jpg +../../media/color_space_test/R8_2.jpg ; PNG, 24/32-bit & 8-bit grayscale -;../../media/color_space_test/R8G8B8_1.png -;../../media/color_space_test/R8G8B8_2.png -;../../media/color_space_test/R8G8B8A8_1.png -; ../../media/color_space_test/R8G8B8A8_2.png +../../media/color_space_test/R8G8B8_1.png +../../media/color_space_test/R8G8B8_2.png +../../media/color_space_test/R8G8B8A8_1.png +../../media/color_space_test/R8G8B8A8_2.png -;../../media/color_space_test/R8_1.png -;../../media/color_space_test/R8_2.png +../../media/color_space_test/R8_1.png +../../media/color_space_test/R8_2.png ; TGA, 24/32-bit & 8-bit grayscale (+RLE) ;../../media/color_space_test/R8G8B8_RLE.tga @@ -25,23 +25,23 @@ ../../media/color_space_test/R8G8B8A8.tga ;../../media/color_space_test/R8G8B8A8_RLE.tga -;../../media/color_space_test/R8.tga +../../media/color_space_test/R8.tga ; DDS, RGBA Block Compression with mipmaps, cubemaps, arrays, cubemap mipmap images, grayscale -;../../media/GLI/kueken7_rgba_dxt1_srgb.dds -;../../media/GLI/kueken7_rgba_dxt3_unorm.dds -;../../media/GLI/kueken7_rgba_dxt5_srgb.dds -;../../media/GLI/earth-cubemap.dds -;../../media/GLI/kueken7_rgba8_unorm.dds -;../../media/GLI/earth-array.dds -;../../media/GLI/R8_1_unorm.dds +../../media/GLI/kueken7_rgba_dxt1_srgb.dds +../../media/GLI/kueken7_rgba_dxt3_unorm.dds +../../media/GLI/kueken7_rgba_dxt5_srgb.dds +../../media/GLI/earth-cubemap.dds +../../media/GLI/kueken7_rgba8_unorm.dds +../../media/GLI/earth-array.dds +../../media/GLI/R8_1_unorm.dds ; KTX, RGBA Block Compression with mipmaps, cubemaps, arrays, cubemap mipmap images, grayscale -;../../media/GLI/kueken7_rgba_dxt1_srgb.ktx -;../../media/GLI/kueken7_rgba_dxt3_unorm.ktx -;../../media/GLI/kueken7_rgba_dxt5_srgb.ktx -;../../media/GLI/earth-cubemap.ktx -;../../media/GLI/kueken7_rgba8_unorm.ktx -;../../media/GLI/earth-array.ktx -;../../media/GLI/R8_1_unorm.ktx \ No newline at end of file +../../media/GLI/kueken7_rgba_dxt1_srgb.ktx +../../media/GLI/kueken7_rgba_dxt3_unorm.ktx +../../media/GLI/kueken7_rgba_dxt5_srgb.ktx +../../media/GLI/earth-cubemap.ktx +../../media/GLI/kueken7_rgba8_unorm.ktx +../../media/GLI/earth-array.ktx +../../media/GLI/R8_1_unorm.ktx \ No newline at end of file diff --git a/examples_tests/09.ColorSpaceTest/main.cpp b/examples_tests/09.ColorSpaceTest/main.cpp index b0e4b4e709..f3f771ccbc 100644 --- a/examples_tests/09.ColorSpaceTest/main.cpp +++ b/examples_tests/09.ColorSpaceTest/main.cpp @@ -77,7 +77,7 @@ class ColorSpaceTestSampleApp : public ApplicationBase initOutput.window = core::smart_refctd_ptr(window); CommonAPI::InitWithDefaultExt( initOutput, - video::EAT_VULKAN, + video::EAT_OPENGL, "09.ColorSpaceTest", WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, diff --git a/examples_tests/Readme.md b/examples_tests/Readme.md index a48afac411..2953c3e88a 100644 --- a/examples_tests/Readme.md +++ b/examples_tests/Readme.md @@ -40,7 +40,7 @@ N = No support | 06.MeshLoaders | Y | Y | Y | S | S | S | Y | Y | | | 07.SubpassBaking | Y | Y | Y | S | S | S | S | S | | | FREE_SLOT | | | | | | | | | | -| 09.ColorSpaceTest | W | W | W | W | W | W | W | W | | +| 09.ColorSpaceTest | B | B | B | W | W | W | W | W | | | 10.AllocatorTest | Y | Y | Y | S | S | S | N | N | | | 11.LoDSystem | Y | Y | B | S | N | S | N | S | | | 12.glTF | W | N | W | W | N | W | N | W | COMPILE_WITH_GLTF_LOADER | @@ -51,7 +51,7 @@ N = No support | 17.SimpleBulletIntegration | B | N | B | S | N | S | N | N | BUILD_BULLET | | 18.MitsubaLoader | S | N | S | S | N | S | N | N | BUILD_MITSUBA_LOADER | | FREE_SLOT | | | | | | | | | | -| 20.Megatexture | S | S | S | S | S | S | N | S | | +| 20.Megatexture | W | W | W | S | S | S | N | S | | | 21.DynamicTextureIndexing | B | B | B | S | N | S | N | S | | | 22.RaytracedAO | N | N | W | N | N | W | N | N | BUILD_MITSUBA_LOADER | | 23.Autoexposure | Y | Y | Y | S | S | S | N | S | |