diff --git a/build_files/cmake/Modules/FindHIP.cmake b/build_files/cmake/Modules/FindHIP.cmake index c6358c9ef7b..8c034b0189f 100644 --- a/build_files/cmake/Modules/FindHIP.cmake +++ b/build_files/cmake/Modules/FindHIP.cmake @@ -1,12 +1,9 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2021 Blender Foundation. -# - Find HIP compiler -# -# This module defines +# Find HIP compiler. This module defines # HIP_HIPCC_EXECUTABLE, the full path to the hipcc executable # HIP_VERSION, the HIP compiler version -# # HIP_FOUND, if the HIP toolkit is found. # If HIP_ROOT_DIR was defined in the environment, use it. @@ -27,12 +24,21 @@ find_program(HIP_HIPCC_EXECUTABLE bin ) -if(HIP_HIPCC_EXECUTABLE AND NOT EXISTS ${HIP_HIPCC_EXECUTABLE}) - message(WARNING "Cached or directly specified hipcc executable does not exist.") - set(HIP_FOUND FALSE) -elseif(HIP_HIPCC_EXECUTABLE) - set(HIP_FOUND TRUE) +if(WIN32) + # Needed for HIP-RT on Windows. + find_program(HIP_LINKER_EXECUTABLE + NAMES + clang++ + HINTS + ${_hip_SEARCH_DIRS} + PATH_SUFFIXES + bin + NO_DEFAULT_PATH + NO_CMAKE_PATH + ) +endif() +if(HIP_HIPCC_EXECUTABLE) set(HIP_VERSION_MAJOR 0) set(HIP_VERSION_MINOR 0) set(HIP_VERSION_PATCH 0) @@ -54,33 +60,31 @@ elseif(HIP_HIPCC_EXECUTABLE) # Strip the HIP prefix and get list of individual version components. string(REGEX REPLACE ".*HIP version: ([.0-9]+).*" "\\1" - HIP_SEMANTIC_VERSION "${_hip_version_raw}") - string(REPLACE "." ";" HIP_VERSION_PARTS "${HIP_SEMANTIC_VERSION}") - list(LENGTH HIP_VERSION_PARTS NUM_HIP_VERSION_PARTS) + _hip_semantic_version "${_hip_version_raw}") + string(REPLACE "." ";" _hip_version_parts "${_hip_semantic_version}") + list(LENGTH _hip_version_parts _num_hip_version_parts) # Extract components into corresponding variables. - if(NUM_HIP_VERSION_PARTS GREATER 0) - list(GET HIP_VERSION_PARTS 0 HIP_VERSION_MAJOR) + if(_num_hip_version_parts GREATER 0) + list(GET _hip_version_parts 0 HIP_VERSION_MAJOR) endif() - if(NUM_HIP_VERSION_PARTS GREATER 1) - list(GET HIP_VERSION_PARTS 1 HIP_VERSION_MINOR) + if(_num_hip_version_parts GREATER 1) + list(GET _hip_version_parts 1 HIP_VERSION_MINOR) endif() - if(NUM_HIP_VERSION_PARTS GREATER 2) - list(GET HIP_VERSION_PARTS 2 HIP_VERSION_PATCH) + if(_num_hip_version_parts GREATER 2) + list(GET _hip_version_parts 2 HIP_VERSION_PATCH) endif() # Unset temp variables. - unset(NUM_HIP_VERSION_PARTS) - unset(HIP_SEMANTIC_VERSION) - unset(HIP_VERSION_PARTS) + unset(_num_hip_version_parts) + unset(_hip_semantic_version) + unset(_hip_version_parts) endif() # Construct full semantic version. set(HIP_VERSION "${HIP_VERSION_MAJOR}.${HIP_VERSION_MINOR}.${HIP_VERSION_PATCH}") unset(_hip_version_raw) unset(_hipcc_executable) -else() - set(HIP_FOUND FALSE) endif() include(FindPackageHandleStandardArgs) diff --git a/build_files/cmake/Modules/FindHIPRT.cmake b/build_files/cmake/Modules/FindHIPRT.cmake new file mode 100644 index 00000000000..6bda351ff54 --- /dev/null +++ b/build_files/cmake/Modules/FindHIPRT.cmake @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright 2021 Blender Foundation. + +# Find HIPRT SDK. This module defines: +# HIPRT_INCLUDE_DIR, path to HIPRT include directory +# HIPRT_BITCODE, bitcode file with ray-tracing functionality +# HIPRT_FOUND, if SDK found + +# If HIPRT_ROOT_DIR was defined in the environment, use it. +if(NOT HIPRT_ROOT_DIR AND NOT $ENV{HIPRT_ROOT_DIR} STREQUAL "") + set(HIPRT_ROOT_DIR $ENV{HIPRT_ROOT_DIR}) +endif() + +set(_hiprt_SEARCH_DIRS + ${HIPRT_ROOT_DIR} +) + +find_path(HIPRT_INCLUDE_DIR + NAMES + hiprt/hiprt.h + HINTS + ${_hiprt_SEARCH_DIRS} +) + +if(HIPRT_INCLUDE_DIR) + file(STRINGS "${HIPRT_INCLUDE_DIR}/hiprt/hiprt.h" _hiprt_version + REGEX "^#define HIPRT_VERSION_STR[ \t]\".*\"$") + string(REGEX MATCHALL "[0-9]+[.0-9]+" _hiprt_version ${_hiprt_version}) + + find_file(HIPRT_BITCODE + NAMES + hiprt${_hiprt_version}_amd_lib_win.bc + HINTS + ${HIPRT_INCLUDE_DIR}/hiprt/win + NO_DEFAULT_PATH + ) + + unset(_hiprt_version) +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(HIPRT DEFAULT_MSG + HIPRT_INCLUDE_DIR HIPRT_BITCODE) + +mark_as_advanced( + HIPRT_INCLUDE_DIR +) diff --git a/build_files/config/pipeline_config.yaml b/build_files/config/pipeline_config.yaml index 832a9b119e6..6edc4801bf6 100644 --- a/build_files/config/pipeline_config.yaml +++ b/build_files/config/pipeline_config.yaml @@ -10,6 +10,8 @@ buildbot: version: '11.4.1' hip: version: '5.5.30571' + hiprt: + version: '2.0.0' optix: version: '7.3.0' ocloc: diff --git a/extern/hipew/CMakeLists.txt b/extern/hipew/CMakeLists.txt index 7ecd2a17300..f2d1f143222 100644 --- a/extern/hipew/CMakeLists.txt +++ b/extern/hipew/CMakeLists.txt @@ -12,11 +12,21 @@ set(INC_SYS set(SRC src/hipew.c - include/hipew.h ) set(LIB ) +if(HIPRT_INCLUDE_DIR) + list(APPEND INC_SYS + ${HIPRT_INCLUDE_DIR} + ) + + list(APPEND SRC + src/hiprtew.cc + include/hiprtew.h + ) +endif() + blender_add_lib(extern_hipew "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/extern/hipew/include/hipew.h b/extern/hipew/include/hipew.h index 1333efba951..f82654ffe93 100644 --- a/extern/hipew/include/hipew.h +++ b/extern/hipew/include/hipew.h @@ -43,9 +43,9 @@ extern "C" { #define HIP_TRSA_OVERRIDE_FORMAT 0x01 #define HIP_TRSF_READ_AS_INTEGER 0x01 #define HIP_TRSF_NORMALIZED_COORDINATES 0x02 -#define HIP_LAUNCH_PARAM_END ((void*)0x00) #define HIP_LAUNCH_PARAM_BUFFER_POINTER ((void*)0x01) #define HIP_LAUNCH_PARAM_BUFFER_SIZE ((void*)0x02) +#define HIP_LAUNCH_PARAM_END ((void*)0x03) /* Functions which changed 3.1 -> 3.2 for 64 bit stuff, * the cuda library has both the old ones for compatibility and new @@ -55,6 +55,7 @@ extern "C" { #define hipMemGetInfo hipMemGetInfo #define hipMemAllocPitch hipMemAllocPitch #define hipMemGetAddressRange hipMemGetAddressRange +#define hipMemcpy hipMemcpy #define hipMemcpyHtoD hipMemcpyHtoD #define hipMemcpyDtoH hipMemcpyDtoH #define hipMemcpyDtoD hipMemcpyDtoD @@ -68,6 +69,7 @@ extern "C" { #define hipMemsetD32 hipMemsetD32 #define hipArrayCreate hipArrayCreate #define hipArray3DCreate hipArray3DCreate +#define hipPointerGetAttributes hipPointerGetAttributes #define hipTexRefSetAddress hipTexRefSetAddress #define hipTexRefGetAddress hipTexRefGetAddress #define hipStreamDestroy hipStreamDestroy @@ -108,11 +110,20 @@ typedef struct hipMipmappedArray_st* hipMipmappedArray_t; typedef struct ihipEvent_t* hipEvent_t; typedef struct ihipStream_t* hipStream_t; typedef unsigned long long hipTextureObject_t; +typedef void* hipExternalMemory_t; typedef struct HIPuuid_st { char bytes[16]; } HIPuuid; +typedef enum hipMemcpyKind { + hipMemcpyHostToHost = 0, + hipMemcpyHostToDevice = 1, + hipMemcpyDeviceToHost = 2, + hipMemcpyDeviceToDevice = 3, + hipMemcpyDefault = 4 +} hipMemcpyKind; + typedef enum hipChannelFormatKind { hipChannelFormatKindSigned = 0, hipChannelFormatKindUnsigned = 1, @@ -1048,28 +1059,105 @@ typedef enum HIPGLmap_flags_enum { HIP_GL_MAP_RESOURCE_FLAGS_WRITE_DISCARD = 0x02, } HIPGLmap_flags; +typedef enum hipExternalMemoryHandleType_enum { + hipExternalMemoryHandleTypeOpaqueFd = 1, + hipExternalMemoryHandleTypeOpaqueWin32 = 2, + hipExternalMemoryHandleTypeOpaqueWin32Kmt = 3, + hipExternalMemoryHandleTypeD3D12Heap = 4, + hipExternalMemoryHandleTypeD3D12Resource = 5, + hipExternalMemoryHandleTypeD3D11Resource = 6, + hipExternalMemoryHandleTypeD3D11ResourceKmt = 7, +} hipExternalMemoryHandleType; + +typedef struct hipExternalMemoryHandleDesc_st { + hipExternalMemoryHandleType type; + union { + int fd; + struct { + void *handle; + const void *name; + } win32; + } handle; + unsigned long long size; + unsigned int flags; +} hipExternalMemoryHandleDesc; + +typedef struct hipExternalMemoryBufferDesc_st { + unsigned long long offset; + unsigned long long size; + unsigned int flags; +} hipExternalMemoryBufferDesc; + /** * hipRTC related */ typedef struct _hiprtcProgram* hiprtcProgram; typedef enum hiprtcResult { - HIPRTC_SUCCESS = 0, - HIPRTC_ERROR_OUT_OF_MEMORY = 1, - HIPRTC_ERROR_PROGRAM_CREATION_FAILURE = 2, - HIPRTC_ERROR_INVALID_INPUT = 3, - HIPRTC_ERROR_INVALID_PROGRAM = 4, - HIPRTC_ERROR_INVALID_OPTION = 5, - HIPRTC_ERROR_COMPILATION = 6, - HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE = 7, - HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION = 8, - HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = 9, - HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID = 10, - HIPRTC_ERROR_INTERNAL_ERROR = 11 + HIPRTC_SUCCESS = 0, + HIPRTC_ERROR_OUT_OF_MEMORY = 1, + HIPRTC_ERROR_PROGRAM_CREATION_FAILURE = 2, + HIPRTC_ERROR_INVALID_INPUT = 3, + HIPRTC_ERROR_INVALID_PROGRAM = 4, + HIPRTC_ERROR_INVALID_OPTION = 5, + HIPRTC_ERROR_COMPILATION = 6, + HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE = 7, + HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION = 8, + HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = 9, + HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID = 10, + HIPRTC_ERROR_INTERNAL_ERROR = 11, + HIPRTC_ERROR_LINKING = 100 } hiprtcResult; +typedef enum hiprtcJIT_option { + HIPRTC_JIT_MAX_REGISTERS = 0, + HIPRTC_JIT_THREADS_PER_BLOCK, + HIPRTC_JIT_WALL_TIME, + HIPRTC_JIT_INFO_LOG_BUFFER, + HIPRTC_JIT_INFO_LOG_BUFFER_SIZE_BYTES, + HIPRTC_JIT_ERROR_LOG_BUFFER, + HIPRTC_JIT_ERROR_LOG_BUFFER_SIZE_BYTES, + HIPRTC_JIT_OPTIMIZATION_LEVEL, + HIPRTC_JIT_TARGET_FROM_HIPCONTEXT, + HIPRTC_JIT_TARGET, + HIPRTC_JIT_FALLBACK_STRATEGY, + HIPRTC_JIT_GENERATE_DEBUG_INFO, + HIPRTC_JIT_LOG_VERBOSE, + HIPRTC_JIT_GENERATE_LINE_INFO, + HIPRTC_JIT_CACHE_MODE, + HIPRTC_JIT_NEW_SM3X_OPT, + HIPRTC_JIT_FAST_COMPILE, + HIPRTC_JIT_GLOBAL_SYMBOL_NAMES, + HIPRTC_JIT_GLOBAL_SYMBOL_ADDRESS, + HIPRTC_JIT_GLOBAL_SYMBOL_COUNT, + HIPRTC_JIT_LTO, + HIPRTC_JIT_FTZ, + HIPRTC_JIT_PREC_DIV, + HIPRTC_JIT_PREC_SQRT, + HIPRTC_JIT_FMA, + HIPRTC_JIT_NUM_OPTIONS, +} hiprtcJIT_option; + +typedef enum hiprtcJITInputType { + HIPRTC_JIT_INPUT_CUBIN = 0, + HIPRTC_JIT_INPUT_PTX, + HIPRTC_JIT_INPUT_FATBINARY, + HIPRTC_JIT_INPUT_OBJECT, + HIPRTC_JIT_INPUT_LIBRARY, + HIPRTC_JIT_INPUT_NVVM, + HIPRTC_JIT_NUM_LEGACY_INPUT_TYPES, + HIPRTC_JIT_INPUT_LLVM_BITCODE = 100, + HIPRTC_JIT_INPUT_LLVM_BUNDLED_BITCODE = 101, + HIPRTC_JIT_INPUT_LLVM_ARCHIVES_OF_BUNDLED_BITCODE = 102, + HIPRTC_JIT_NUM_INPUT_TYPES = ( HIPRTC_JIT_NUM_LEGACY_INPUT_TYPES + 3 ) +} hiprtcJITInputType; + +typedef struct ihiprtcLinkState* hiprtcLinkState; + /* Function types. */ typedef hipError_t HIPAPI thipGetErrorName(hipError_t error, const char** pStr); +typedef const char* HIPAPI thipGetErrorString(hipError_t error); +typedef hipError_t HIPAPI thipGetLastError(hipError_t error); typedef hipError_t HIPAPI thipInit(unsigned int Flags); typedef hipError_t HIPAPI thipDriverGetVersion(int* driverVersion); typedef hipError_t HIPAPI thipGetDevice(int* device); @@ -1078,6 +1166,8 @@ typedef hipError_t HIPAPI thipGetDeviceProperties(hipDeviceProp_t* props, int de typedef hipError_t HIPAPI thipDeviceGet(hipDevice_t* device, int ordinal); typedef hipError_t HIPAPI thipDeviceGetName(char* name, int len, hipDevice_t dev); typedef hipError_t HIPAPI thipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attrib, hipDevice_t dev); +typedef hipError_t HIPAPI thipDeviceGetLimit(size_t* pValue, enum hipLimit_t limit); +typedef hipError_t HIPAPI thipDeviceSetLimit(enum hipLimit_t limit, size_t value); typedef hipError_t HIPAPI thipDeviceComputeCapability(int* major, int* minor, hipDevice_t dev); typedef hipError_t HIPAPI thipDevicePrimaryCtxRetain(hipCtx_t* pctx, hipDevice_t dev); typedef hipError_t HIPAPI thipDevicePrimaryCtxRelease(hipDevice_t dev); @@ -1114,13 +1204,14 @@ typedef hipError_t HIPAPI thipMemGetAddressRange(hipDeviceptr_t* pbase, size_t* typedef hipError_t HIPAPI thipHostMalloc(void** pp, size_t bytesize, unsigned int flags); typedef hipError_t HIPAPI thipHostFree(void* p); typedef hipError_t HIPAPI thipMemHostAlloc(void** pp, size_t bytesize, unsigned int Flags); +typedef hipError_t HIPAPI thipHostRegister(void* p, size_t bytesize, unsigned int Flags); typedef hipError_t HIPAPI thipHostGetDevicePointer(hipDeviceptr_t* pdptr, void* p, unsigned int Flags); typedef hipError_t HIPAPI thipHostGetFlags(unsigned int* pFlags, void* p); typedef hipError_t HIPAPI thipMallocManaged(hipDeviceptr_t* dptr, size_t bytesize, unsigned int flags); typedef hipError_t HIPAPI thipDeviceGetByPCIBusId(hipDevice_t* dev, const char* pciBusId); typedef hipError_t HIPAPI thipDeviceGetPCIBusId(char* pciBusId, int len, hipDevice_t dev); -typedef hipError_t HIPAPI thipMemHostUnregister(void* p); -typedef hipError_t HIPAPI thipMemcpy(hipDeviceptr_t dst, hipDeviceptr_t src, size_t ByteCount); +typedef hipError_t HIPAPI thipHostUnregister(void* p); +typedef hipError_t HIPAPI thipMemcpy(void* dst, const void* src, size_t ByteCount, hipMemcpyKind kind); typedef hipError_t HIPAPI thipMemcpyPeer(hipDeviceptr_t dstDevice, hipCtx_t dstContext, hipDeviceptr_t srcDevice, hipCtx_t srcContext, size_t ByteCount); typedef hipError_t HIPAPI thipMemcpyHtoD(hipDeviceptr_t dstDevice, void* srcHost, size_t ByteCount); typedef hipError_t HIPAPI thipMemcpyDtoH(void* dstHost, hipDeviceptr_t srcDevice, size_t ByteCount); @@ -1130,8 +1221,10 @@ typedef hipError_t HIPAPI thipMemcpyParam2D(const hip_Memcpy2D* pCopy); typedef hipError_t HIPAPI thipDrvMemcpy3D(const HIP_MEMCPY3D* pCopy); typedef hipError_t HIPAPI thipMemcpyHtoDAsync(hipDeviceptr_t dstDevice, const void* srcHost, size_t ByteCount, hipStream_t hStream); typedef hipError_t HIPAPI thipMemcpyDtoHAsync(void* dstHost, hipDeviceptr_t srcDevice, size_t ByteCount, hipStream_t hStream); +typedef hipError_t HIPAPI thipMemcpyDtoDAsync(hipDeviceptr_t dstDevice, hipDeviceptr_t srcDevice, size_t ByteCount, hipStream_t hStream); typedef hipError_t HIPAPI thipMemcpyParam2DAsync(const hip_Memcpy2D* pCopy, hipStream_t hStream); typedef hipError_t HIPAPI thipDrvMemcpy3DAsync(const HIP_MEMCPY3D* pCopy, hipStream_t hStream); +typedef hipError_t HIPAPI thipMemset(void* dstDevice, int value, size_t sizeBytes); typedef hipError_t HIPAPI thipMemsetD8(hipDeviceptr_t dstDevice, unsigned char uc, size_t N); typedef hipError_t HIPAPI thipMemsetD16(hipDeviceptr_t dstDevice, unsigned short us, size_t N); typedef hipError_t HIPAPI thipMemsetD32(hipDeviceptr_t dstDevice, unsigned int ui, size_t N); @@ -1144,7 +1237,8 @@ typedef hipError_t HIPAPI thipMemsetD2D32Async(hipDeviceptr_t dstDevice, size_t typedef hipError_t HIPAPI thipArrayCreate(hArray ** pHandle, const HIP_ARRAY_DESCRIPTOR* pAllocateArray); typedef hipError_t HIPAPI thipArrayDestroy(hArray hArray); typedef hipError_t HIPAPI thipArray3DCreate(hArray * pHandle, const HIP_ARRAY3D_DESCRIPTOR* pAllocateArray); -typedef hipError_t HIPAPI hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr); +typedef hipError_t HIPAPI thipPointerGetAttributes(hipPointerAttribute_t* attributes, const void* ptr); +typedef hipError_t HIPAPI thipStreamCreate(hipStream_t* phStream); typedef hipError_t HIPAPI thipStreamCreateWithFlags(hipStream_t* phStream, unsigned int Flags); typedef hipError_t HIPAPI thipStreamCreateWithPriority(hipStream_t* phStream, unsigned int flags, int priority); typedef hipError_t HIPAPI thipStreamGetPriority(hipStream_t hStream, int* priority); @@ -1189,7 +1283,10 @@ typedef hipError_t HIPAPI thipGraphicsMapResources(unsigned int count, hipGraphi typedef hipError_t HIPAPI thipGraphicsUnmapResources(unsigned int count, hipGraphicsResource* resources, hipStream_t hStream); typedef hipError_t HIPAPI thipGraphicsGLRegisterBuffer(hipGraphicsResource* pCudaResource, GLuint buffer, unsigned int Flags); typedef hipError_t HIPAPI thipGLGetDevices(unsigned int* pHipDeviceCount, int* pHipDevices, unsigned int hipDeviceCount, hipGLDeviceList deviceList); -typedef hiprtcResult HIPAPI thiprtcGetErrorString(hiprtcResult result); +typedef hipError_t HIPAPI thipImportExternalMemory(hipExternalMemory_t* extMem_out, const hipExternalMemoryHandleDesc* memHandleDesc); +typedef hipError_t HIPAPI thipExternalMemoryGetMappedBuffer(void **devPtr, hipExternalMemory_t extMem, const hipExternalMemoryBufferDesc *bufferDesc); +typedef hipError_t HIPAPI thipDestroyExternalMemory(hipExternalMemory_t extMem); +typedef const char* HIPAPI thiprtcGetErrorString(hiprtcResult result); typedef hiprtcResult HIPAPI thiprtcAddNameExpression(hiprtcProgram prog, const char* name_expression); typedef hiprtcResult HIPAPI thiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char** options); typedef hiprtcResult HIPAPI thiprtcCreateProgram(hiprtcProgram* prog, const char* src, const char* name, int numHeaders, const char** headers, const char** includeNames); @@ -1197,20 +1294,30 @@ typedef hiprtcResult HIPAPI thiprtcDestroyProgram(hiprtcProgram* prog); typedef hiprtcResult HIPAPI thiprtcGetLoweredName(hiprtcProgram prog, const char* name_expression, const char** lowered_name); typedef hiprtcResult HIPAPI thiprtcGetProgramLog(hiprtcProgram prog, char* log); typedef hiprtcResult HIPAPI thiprtcGetProgramLogSize(hiprtcProgram prog, size_t* logSizeRet); +typedef hiprtcResult HIPAPI thiprtcGetBitcode( hiprtcProgram prog, char* bitcode ); +typedef hiprtcResult HIPAPI thiprtcGetBitcodeSize( hiprtcProgram prog, size_t* bitcodeSizeRet ); typedef hiprtcResult HIPAPI thiprtcGetCode(hiprtcProgram prog, char* code); typedef hiprtcResult HIPAPI thiprtcGetCodeSize(hiprtcProgram prog, size_t* codeSizeRet); - +typedef hiprtcResult HIPAPI thiprtcLinkCreate( unsigned int num_options, hiprtcJIT_option* option_ptr, void** option_vals_pptr, hiprtcLinkState* hip_link_state_ptr ); +typedef hiprtcResult HIPAPI thiprtcLinkAddFile( hiprtcLinkState hip_link_state, hiprtcJITInputType input_type, const char* file_path, unsigned int num_options, hiprtcJIT_option* options_ptr, void** option_values ); +typedef hiprtcResult HIPAPI thiprtcLinkAddData( hiprtcLinkState hip_link_state, hiprtcJITInputType input_type, void* image, size_t image_size, const char* name, unsigned int num_options, hiprtcJIT_option* options_ptr, void** option_values ); +typedef hiprtcResult HIPAPI thiprtcLinkComplete( hiprtcLinkState hip_link_state, void** bin_out, size_t* size_out ); +typedef hiprtcResult HIPAPI thiprtcLinkDestroy( hiprtcLinkState hip_link_state ); /* Function declarations. */ extern thipGetErrorName *hipGetErrorName; +extern thipGetErrorString* hipGetErrorString; +extern thipGetLastError* hipGetLastError; extern thipInit *hipInit; extern thipDriverGetVersion *hipDriverGetVersion; extern thipGetDevice *hipGetDevice; extern thipGetDeviceCount *hipGetDeviceCount; extern thipGetDeviceProperties *hipGetDeviceProperties; -extern thipDeviceGet* hipDeviceGet; +extern thipDeviceGet *hipDeviceGet; extern thipDeviceGetName *hipDeviceGetName; extern thipDeviceGetAttribute *hipDeviceGetAttribute; +extern thipDeviceGetLimit *hipDeviceGetLimit; +extern thipDeviceSetLimit *hipDeviceSetLimit; extern thipDeviceComputeCapability *hipDeviceComputeCapability; extern thipDevicePrimaryCtxRetain *hipDevicePrimaryCtxRetain; extern thipDevicePrimaryCtxRelease *hipDevicePrimaryCtxRelease; @@ -1246,11 +1353,14 @@ extern thipFree *hipFree; extern thipMemGetAddressRange *hipMemGetAddressRange; extern thipHostMalloc *hipHostMalloc; extern thipHostFree *hipHostFree; +extern thipHostRegister *hipHostRegister; extern thipHostGetDevicePointer *hipHostGetDevicePointer; extern thipHostGetFlags *hipHostGetFlags; +extern thipHostUnregister *hipHostUnregister; extern thipMallocManaged *hipMallocManaged; extern thipDeviceGetByPCIBusId *hipDeviceGetByPCIBusId; extern thipDeviceGetPCIBusId *hipDeviceGetPCIBusId; +extern thipMemcpy *hipMemcpy; extern thipMemcpyPeer *hipMemcpyPeer; extern thipMemcpyHtoD *hipMemcpyHtoD; extern thipMemcpyDtoH *hipMemcpyDtoH; @@ -1260,8 +1370,10 @@ extern thipMemcpyParam2D *hipMemcpyParam2D; extern thipDrvMemcpy3D *hipDrvMemcpy3D; extern thipMemcpyHtoDAsync *hipMemcpyHtoDAsync; extern thipMemcpyDtoHAsync *hipMemcpyDtoHAsync; +extern thipMemcpyDtoDAsync *hipMemcpyDtoDAsync; extern thipMemcpyParam2DAsync *hipMemcpyParam2DAsync; extern thipDrvMemcpy3DAsync *hipDrvMemcpy3DAsync; +extern thipMemset *hipMemset; extern thipMemsetD8 *hipMemsetD8; extern thipMemsetD16 *hipMemsetD16; extern thipMemsetD32 *hipMemsetD32; @@ -1271,6 +1383,8 @@ extern thipMemsetD32Async *hipMemsetD32Async; extern thipArrayCreate *hipArrayCreate; extern thipArrayDestroy *hipArrayDestroy; extern thipArray3DCreate *hipArray3DCreate; +extern thipPointerGetAttributes *hipPointerGetAttributes; +extern thipStreamCreate* hipStreamCreate; extern thipStreamCreateWithFlags *hipStreamCreateWithFlags; extern thipStreamCreateWithPriority *hipStreamCreateWithPriority; extern thipStreamGetPriority *hipStreamGetPriority; @@ -1316,6 +1430,9 @@ extern thipGraphicsUnmapResources *hipGraphicsUnmapResources; extern thipGraphicsGLRegisterBuffer *hipGraphicsGLRegisterBuffer; extern thipGLGetDevices *hipGLGetDevices; +extern thipImportExternalMemory *hipImportExternalMemory; +extern thipExternalMemoryGetMappedBuffer *hipExternalMemoryGetMappedBuffer; +extern thipDestroyExternalMemory *hipDestroyExternalMemory; extern thiprtcGetErrorString* hiprtcGetErrorString; extern thiprtcAddNameExpression* hiprtcAddNameExpression; @@ -1325,9 +1442,17 @@ extern thiprtcDestroyProgram* hiprtcDestroyProgram; extern thiprtcGetLoweredName* hiprtcGetLoweredName; extern thiprtcGetProgramLog* hiprtcGetProgramLog; extern thiprtcGetProgramLogSize* hiprtcGetProgramLogSize; +extern thiprtcGetBitcode* hiprtcGetBitcode; +extern thiprtcGetBitcodeSize* hiprtcGetBitcodeSize; extern thiprtcGetCode* hiprtcGetCode; extern thiprtcGetCodeSize* hiprtcGetCodeSize; +extern thiprtcLinkCreate* hiprtcLinkCreate; +extern thiprtcLinkAddFile* hiprtcLinkAddFile; +extern thiprtcLinkAddData* hiprtcLinkAddData; +extern thiprtcLinkComplete* hiprtcLinkComplete; +extern thiprtcLinkDestroy* hiprtcLinkDestroy; +/* HIPEW API. */ enum { HIPEW_SUCCESS = 0, @@ -1344,7 +1469,6 @@ int hipewInit(hipuint32_t flags); const char *hipewErrorString(hipError_t result); const char *hipewCompilerPath(void); int hipewCompilerVersion(void); -int hipewNvrtcVersion(void); #ifdef __cplusplus } diff --git a/extern/hipew/include/hiprtew.h b/extern/hipew/include/hiprtew.h new file mode 100644 index 00000000000..a5472896dd9 --- /dev/null +++ b/extern/hipew/include/hiprtew.h @@ -0,0 +1,102 @@ +/* + * Copyright 2011-2021 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __HIPRTEW_H__ +#define __HIPRTEW_H__ + +#include + +#define HIPRT_MAJOR_VERSION 2 +#define HIPRT_MINOR_VERSION 0 +#define HIPRT_PATCH_VERSION 0xb68861 + +#define HIPRT_API_VERSION 2000 +#define HIPRT_VERSION_STR "02000" + +typedef unsigned int hiprtuint32_t; + +/* Function types. */ +typedef hiprtError(thiprtCreateContext)(hiprtuint32_t hiprtApiVersion, + hiprtContextCreationInput &input, + hiprtContext *outContext); +typedef hiprtError(thiprtDestroyContext)(hiprtContext context); +typedef hiprtError(thiprtCreateGeometry)(hiprtContext context, + const hiprtGeometryBuildInput *buildInput, + const hiprtBuildOptions *buildOptions, + hiprtGeometry *outGeometry); +typedef hiprtError(thiprtDestroyGeometry)(hiprtContext context, + hiprtGeometry outGeometry); +typedef hiprtError(thiprtBuildGeometry)(hiprtContext context, + hiprtBuildOperation buildOperation, + const hiprtGeometryBuildInput *buildInput, + const hiprtBuildOptions *buildOptions, + hiprtDevicePtr temporaryBuffer, + hiprtApiStream stream, + hiprtGeometry outGeometry); +typedef hiprtError(thiprtGetGeometryBuildTemporaryBufferSize)( + hiprtContext context, + const hiprtGeometryBuildInput *buildInput, + const hiprtBuildOptions *buildOptions, + size_t *outSize); +typedef hiprtError(thiprtCreateScene)(hiprtContext context, + const hiprtSceneBuildInput *buildInput, + const hiprtBuildOptions *buildOptions, + hiprtScene *outScene); +typedef hiprtError(thiprtDestroyScene)(hiprtContext context, hiprtScene outScene); +typedef hiprtError(thiprtBuildScene)(hiprtContext context, + hiprtBuildOperation buildOperation, + const hiprtSceneBuildInput *buildInput, + const hiprtBuildOptions *buildOptions, + hiprtDevicePtr temporaryBuffer, + hiprtApiStream stream, + hiprtScene outScene); +typedef hiprtError(thiprtGetSceneBuildTemporaryBufferSize)( + hiprtContext context, + const hiprtSceneBuildInput *buildInput, + const hiprtBuildOptions *buildOptions, + size_t *outSize); +typedef hiprtError(thiprtCreateFuncTable)(hiprtContext context, + hiprtuint32_t numGeomTypes, + hiprtuint32_t numRayTypes, + hiprtFuncTable *outFuncTable); +typedef hiprtError(thiprtSetFuncTable)(hiprtContext context, + hiprtFuncTable funcTable, + hiprtuint32_t geomType, + hiprtuint32_t rayType, + hiprtFuncDataSet set); +typedef hiprtError(thiprtDestroyFuncTable)(hiprtContext context, + hiprtFuncTable funcTable); + +/* Function declarations. */ +extern thiprtCreateContext *hiprtCreateContext; +extern thiprtDestroyContext *hiprtDestroyContext; +extern thiprtCreateGeometry *hiprtCreateGeometry; +extern thiprtDestroyGeometry *hiprtDestroyGeometry; +extern thiprtBuildGeometry *hiprtBuildGeometry; +extern thiprtGetGeometryBuildTemporaryBufferSize *hiprtGetGeometryBuildTemporaryBufferSize; +extern thiprtCreateScene *hiprtCreateScene; +extern thiprtDestroyScene *hiprtDestroyScene; +extern thiprtBuildScene *hiprtBuildScene; +extern thiprtGetSceneBuildTemporaryBufferSize *hiprtGetSceneBuildTemporaryBufferSize; +extern thiprtCreateFuncTable *hiprtCreateFuncTable; +extern thiprtSetFuncTable *hiprtSetFuncTable; +extern thiprtDestroyFuncTable *hiprtDestroyFuncTable; + +/* HIPEW API. */ + +bool hiprtewInit(); + +#endif /* __HIPRTEW_H__ */ diff --git a/extern/hipew/src/hipew.c b/extern/hipew/src/hipew.c index 7cafe7727f5..fda27f66aa1 100644 --- a/extern/hipew/src/hipew.c +++ b/extern/hipew/src/hipew.c @@ -1,5 +1,5 @@ /* - * Copyright 2011-2021 Blender Foundation + * Copyright 2011-2023 Blender Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,14 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License */ -#ifdef _MSC_VER -# if _MSC_VER < 1900 -# define snprintf _snprintf -# endif -# define popen _popen -# define pclose _pclose -# define _CRT_SECURE_NO_WARNINGS -#endif +#include "util.h" #include #include @@ -28,44 +21,18 @@ #include #include -#ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# define VC_EXTRALEAN -# include - -/* Utility macros. */ - -typedef HMODULE DynamicLibrary; - -# define dynamic_library_open(path) LoadLibraryA(path) -# define dynamic_library_close(lib) FreeLibrary(lib) -# define dynamic_library_find(lib, symbol) GetProcAddress(lib, symbol) -#else -# include - -typedef void* DynamicLibrary; - -# define dynamic_library_open(path) dlopen(path, RTLD_NOW) -# define dynamic_library_close(lib) dlclose(lib) -# define dynamic_library_find(lib, symbol) dlsym(lib, symbol) -#endif - -#define _LIBRARY_FIND_CHECKED(lib, name) \ - name = (t##name *)dynamic_library_find(lib, #name); \ - assert(name); - -#define _LIBRARY_FIND(lib, name) \ - name = (t##name *)dynamic_library_find(lib, #name); +static DynamicLibrary hip_lib; #define HIP_LIBRARY_FIND_CHECKED(name) \ - _LIBRARY_FIND_CHECKED(hip_lib, name) -#define HIP_LIBRARY_FIND(name) _LIBRARY_FIND(hip_lib, name) - - -static DynamicLibrary hip_lib; + name = (t##name *)dynamic_library_find(hip_lib, #name); \ + assert(name); +#define HIP_LIBRARY_FIND(name) \ + name = (t##name *)dynamic_library_find(hip_lib, #name); /* Function definitions. */ thipGetErrorName *hipGetErrorName; +thipGetErrorString *hipGetErrorString; +thipGetLastError *hipGetLastError; thipInit *hipInit; thipDriverGetVersion *hipDriverGetVersion; thipGetDevice *hipGetDevice; @@ -74,6 +41,8 @@ thipGetDeviceProperties *hipGetDeviceProperties; thipDeviceGet* hipDeviceGet; thipDeviceGetName *hipDeviceGetName; thipDeviceGetAttribute *hipDeviceGetAttribute; +thipDeviceGetLimit *hipDeviceGetLimit; +thipDeviceSetLimit *hipDeviceSetLimit; thipDeviceComputeCapability *hipDeviceComputeCapability; thipDevicePrimaryCtxRetain *hipDevicePrimaryCtxRetain; thipDevicePrimaryCtxRelease *hipDevicePrimaryCtxRelease; @@ -109,11 +78,14 @@ thipFree *hipFree; thipMemGetAddressRange *hipMemGetAddressRange; thipHostMalloc *hipHostMalloc; thipHostFree *hipHostFree; +thipHostRegister *hipHostRegister; thipHostGetDevicePointer *hipHostGetDevicePointer; thipHostGetFlags *hipHostGetFlags; +thipHostUnregister *hipHostUnregister; thipMallocManaged *hipMallocManaged; thipDeviceGetByPCIBusId *hipDeviceGetByPCIBusId; thipDeviceGetPCIBusId *hipDeviceGetPCIBusId; +thipMemcpy *hipMemcpy; thipMemcpyPeer *hipMemcpyPeer; thipMemcpyHtoD *hipMemcpyHtoD; thipMemcpyDtoH *hipMemcpyDtoH; @@ -123,8 +95,10 @@ thipMemcpyParam2D *hipMemcpyParam2D; thipDrvMemcpy3D *hipDrvMemcpy3D; thipMemcpyHtoDAsync *hipMemcpyHtoDAsync; thipMemcpyDtoHAsync *hipMemcpyDtoHAsync; +thipMemcpyDtoDAsync *hipMemcpyDtoDAsync; thipMemcpyParam2DAsync *hipMemcpyParam2DAsync; thipDrvMemcpy3DAsync *hipDrvMemcpy3DAsync; +thipMemset *hipMemset; thipMemsetD8 *hipMemsetD8; thipMemsetD16 *hipMemsetD16; thipMemsetD32 *hipMemsetD32; @@ -134,6 +108,8 @@ thipMemsetD32Async *hipMemsetD32Async; thipArrayCreate *hipArrayCreate; thipArrayDestroy *hipArrayDestroy; thipArray3DCreate *hipArray3DCreate; +thipPointerGetAttributes* hipPointerGetAttributes; +thipStreamCreate* hipStreamCreate; thipStreamCreateWithFlags *hipStreamCreateWithFlags; thipStreamCreateWithPriority *hipStreamCreateWithPriority; thipStreamGetPriority *hipStreamGetPriority; @@ -179,6 +155,9 @@ thipGraphicsResourceGetMappedPointer *hipGraphicsResourceGetMappedPointer; thipGraphicsGLRegisterBuffer *hipGraphicsGLRegisterBuffer; thipGLGetDevices *hipGLGetDevices; +thipImportExternalMemory *hipImportExternalMemory; +thipExternalMemoryGetMappedBuffer *hipExternalMemoryGetMappedBuffer; +thipDestroyExternalMemory *hipDestroyExternalMemory; thiprtcGetErrorString* hiprtcGetErrorString; thiprtcAddNameExpression* hiprtcAddNameExpression; @@ -188,10 +167,15 @@ thiprtcDestroyProgram* hiprtcDestroyProgram; thiprtcGetLoweredName* hiprtcGetLoweredName; thiprtcGetProgramLog* hiprtcGetProgramLog; thiprtcGetProgramLogSize* hiprtcGetProgramLogSize; +thiprtcGetBitcode* hiprtcGetBitcode; +thiprtcGetBitcodeSize* hiprtcGetBitcodeSize; thiprtcGetCode* hiprtcGetCode; thiprtcGetCodeSize* hiprtcGetCodeSize; - - +thiprtcLinkCreate* hiprtcLinkCreate; +thiprtcLinkAddFile* hiprtcLinkAddFile; +thiprtcLinkAddData* hiprtcLinkAddData; +thiprtcLinkComplete* hiprtcLinkComplete; +thiprtcLinkDestroy* hiprtcLinkDestroy; static DynamicLibrary dynamic_library_open_find(const char **paths) { int i = 0; @@ -217,14 +201,14 @@ static void hipewHipExit(void) { #ifdef _WIN32 static int hipewHasOldDriver(const char *hip_path) { DWORD verHandle = 0; - DWORD verSize = GetFileVersionInfoSize(hip_path, &verHandle); + DWORD verSize = GetFileVersionInfoSizeA(hip_path, &verHandle); int old_driver = 0; if (verSize != 0) { LPSTR verData = (LPSTR)malloc(verSize); - if (GetFileVersionInfo(hip_path, verHandle, verSize, verData)) { + if (GetFileVersionInfoA(hip_path, verHandle, verSize, verData)) { LPBYTE lpBuffer = NULL; UINT size = 0; - if (VerQueryValue(verData, "\\", (VOID FAR * FAR *)&lpBuffer, &size)) { + if (VerQueryValueA(verData, "\\", (VOID FAR * FAR *)&lpBuffer, &size)) { if (size) { VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer; /* Magic value from @@ -247,8 +231,9 @@ static int hipewHasOldDriver(const char *hip_path) { static int hipewHipInit(void) { /* Library paths. */ #ifdef _WIN32 - /* Expected in c:/windows/system or similar, no path needed. */ + /* Expected in C:/Windows/System32 or similar, no path needed. */ const char *hip_paths[] = {"amdhip64.dll", NULL}; + #elif defined(__APPLE__) /* Default installation path. */ const char *hip_paths[] = {"", NULL}; @@ -289,6 +274,8 @@ static int hipewHipInit(void) { /* Fetch all function pointers. */ HIP_LIBRARY_FIND_CHECKED(hipGetErrorName); + HIP_LIBRARY_FIND_CHECKED(hipGetErrorString); + HIP_LIBRARY_FIND_CHECKED(hipGetLastError); HIP_LIBRARY_FIND_CHECKED(hipInit); HIP_LIBRARY_FIND_CHECKED(hipDriverGetVersion); HIP_LIBRARY_FIND_CHECKED(hipGetDevice); @@ -297,6 +284,8 @@ static int hipewHipInit(void) { HIP_LIBRARY_FIND_CHECKED(hipDeviceGet); HIP_LIBRARY_FIND_CHECKED(hipDeviceGetName); HIP_LIBRARY_FIND_CHECKED(hipDeviceGetAttribute); + HIP_LIBRARY_FIND(hipDeviceGetLimit); + HIP_LIBRARY_FIND(hipDeviceSetLimit); HIP_LIBRARY_FIND_CHECKED(hipDeviceComputeCapability); HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxRetain); HIP_LIBRARY_FIND_CHECKED(hipDevicePrimaryCtxRelease); @@ -332,11 +321,14 @@ static int hipewHipInit(void) { HIP_LIBRARY_FIND_CHECKED(hipMemGetAddressRange); HIP_LIBRARY_FIND_CHECKED(hipHostMalloc); HIP_LIBRARY_FIND_CHECKED(hipHostFree); + HIP_LIBRARY_FIND_CHECKED(hipHostRegister); HIP_LIBRARY_FIND_CHECKED(hipHostGetDevicePointer); HIP_LIBRARY_FIND_CHECKED(hipHostGetFlags); + HIP_LIBRARY_FIND_CHECKED(hipHostUnregister); HIP_LIBRARY_FIND_CHECKED(hipMallocManaged); HIP_LIBRARY_FIND_CHECKED(hipDeviceGetByPCIBusId); HIP_LIBRARY_FIND_CHECKED(hipDeviceGetPCIBusId); + HIP_LIBRARY_FIND_CHECKED(hipMemcpy); HIP_LIBRARY_FIND_CHECKED(hipMemcpyPeer); HIP_LIBRARY_FIND_CHECKED(hipMemcpyHtoD); HIP_LIBRARY_FIND_CHECKED(hipMemcpyDtoH); @@ -345,9 +337,11 @@ static int hipewHipInit(void) { HIP_LIBRARY_FIND_CHECKED(hipDrvMemcpy3D); HIP_LIBRARY_FIND_CHECKED(hipMemcpyHtoDAsync); HIP_LIBRARY_FIND_CHECKED(hipMemcpyDtoHAsync); + HIP_LIBRARY_FIND_CHECKED(hipMemcpyDtoDAsync); HIP_LIBRARY_FIND_CHECKED(hipDrvMemcpy2DUnaligned); HIP_LIBRARY_FIND_CHECKED(hipMemcpyParam2DAsync); HIP_LIBRARY_FIND_CHECKED(hipDrvMemcpy3DAsync); + HIP_LIBRARY_FIND_CHECKED(hipMemset); HIP_LIBRARY_FIND_CHECKED(hipMemsetD8); HIP_LIBRARY_FIND_CHECKED(hipMemsetD16); HIP_LIBRARY_FIND_CHECKED(hipMemsetD32); @@ -357,6 +351,8 @@ static int hipewHipInit(void) { HIP_LIBRARY_FIND_CHECKED(hipArrayCreate); HIP_LIBRARY_FIND_CHECKED(hipArrayDestroy); HIP_LIBRARY_FIND_CHECKED(hipArray3DCreate); + HIP_LIBRARY_FIND_CHECKED(hipPointerGetAttributes); + HIP_LIBRARY_FIND_CHECKED(hipStreamCreate); HIP_LIBRARY_FIND_CHECKED(hipStreamCreateWithFlags); HIP_LIBRARY_FIND_CHECKED(hipStreamCreateWithPriority); HIP_LIBRARY_FIND_CHECKED(hipStreamGetPriority); @@ -399,16 +395,10 @@ static int hipewHipInit(void) { HIP_LIBRARY_FIND_CHECKED(hipGraphicsGLRegisterBuffer); HIP_LIBRARY_FIND_CHECKED(hipGLGetDevices); #endif - HIP_LIBRARY_FIND_CHECKED(hiprtcGetErrorString); - HIP_LIBRARY_FIND_CHECKED(hiprtcAddNameExpression); - HIP_LIBRARY_FIND_CHECKED(hiprtcCompileProgram); - HIP_LIBRARY_FIND_CHECKED(hiprtcCreateProgram); - HIP_LIBRARY_FIND_CHECKED(hiprtcDestroyProgram); - HIP_LIBRARY_FIND_CHECKED(hiprtcGetLoweredName); - HIP_LIBRARY_FIND_CHECKED(hiprtcGetProgramLog); - HIP_LIBRARY_FIND_CHECKED(hiprtcGetProgramLogSize); - HIP_LIBRARY_FIND_CHECKED(hiprtcGetCode); - HIP_LIBRARY_FIND_CHECKED(hiprtcGetCodeSize); + HIP_LIBRARY_FIND_CHECKED(hipImportExternalMemory); + HIP_LIBRARY_FIND_CHECKED(hipExternalMemoryGetMappedBuffer); + HIP_LIBRARY_FIND_CHECKED(hipDestroyExternalMemory); + result = HIPEW_SUCCESS; return result; } diff --git a/extern/hipew/src/hiprtew.cc b/extern/hipew/src/hiprtew.cc new file mode 100644 index 00000000000..84403bb2283 --- /dev/null +++ b/extern/hipew/src/hiprtew.cc @@ -0,0 +1,97 @@ +/* + * Copyright 2011-2023 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include "util.h" + +#include +#include +#include +#include +#include + +static DynamicLibrary hiprt_lib; + +#define HIPRT_LIBRARY_FIND(name) \ + name = (t##name *)dynamic_library_find(hiprt_lib, #name); + +/* Function definitions. */ +thiprtCreateContext *hiprtCreateContext; +thiprtDestroyContext *hiprtDestroyContext; +thiprtCreateGeometry *hiprtCreateGeometry; +thiprtDestroyGeometry *hiprtDestroyGeometry; +thiprtBuildGeometry *hiprtBuildGeometry; +thiprtGetGeometryBuildTemporaryBufferSize *hiprtGetGeometryBuildTemporaryBufferSize; +thiprtCreateScene *hiprtCreateScene; +thiprtDestroyScene *hiprtDestroyScene; +thiprtBuildScene *hiprtBuildScene; +thiprtGetSceneBuildTemporaryBufferSize *hiprtGetSceneBuildTemporaryBufferSize; +thiprtCreateFuncTable *hiprtCreateFuncTable; +thiprtSetFuncTable *hiprtSetFuncTable; +thiprtDestroyFuncTable *hiprtDestroyFuncTable; + +static void hipewHipRtExit(void) +{ + if (hiprt_lib != NULL) { + /* Ignore errors. */ + dynamic_library_close(hiprt_lib); + hiprt_lib = NULL; + } +} + +bool hiprtewInit() +{ + static bool result = false; + static bool initialized = false; + + if (initialized) { + return result; + } + +#ifdef _WIN32 + initialized = true; + + if (atexit(hipewHipRtExit)) { + return false; + } + + std::string hiprt_ver(HIPRT_VERSION_STR); + std::string hiprt_path = "hiprt" + hiprt_ver + "64.dll"; + + hiprt_lib = dynamic_library_open(hiprt_path.c_str()); + + if (hiprt_lib == NULL) { + return false; + } + + HIPRT_LIBRARY_FIND(hiprtCreateContext) + HIPRT_LIBRARY_FIND(hiprtDestroyContext) + HIPRT_LIBRARY_FIND(hiprtCreateGeometry) + HIPRT_LIBRARY_FIND(hiprtDestroyGeometry) + HIPRT_LIBRARY_FIND(hiprtBuildGeometry) + HIPRT_LIBRARY_FIND(hiprtGetGeometryBuildTemporaryBufferSize) + HIPRT_LIBRARY_FIND(hiprtCreateScene) + HIPRT_LIBRARY_FIND(hiprtDestroyScene) + HIPRT_LIBRARY_FIND(hiprtBuildScene) + HIPRT_LIBRARY_FIND(hiprtGetSceneBuildTemporaryBufferSize) + HIPRT_LIBRARY_FIND(hiprtCreateFuncTable) + HIPRT_LIBRARY_FIND(hiprtSetFuncTable) + HIPRT_LIBRARY_FIND(hiprtDestroyFuncTable) + + result = true; +#endif + + return result; +} diff --git a/extern/hipew/src/util.h b/extern/hipew/src/util.h new file mode 100644 index 00000000000..2aafc4b7f9b --- /dev/null +++ b/extern/hipew/src/util.h @@ -0,0 +1,51 @@ +/* + * Copyright 2011-2023 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#pragma once + +/* Portable snprintf and popen/pclose. */ + +#ifdef _MSC_VER +# if _MSC_VER < 1900 +# define snprintf _snprintf +# endif +# define popen _popen +# define pclose _pclose +# define _CRT_SECURE_NO_WARNINGS +#endif + +/* Macros for loading libraries. */ + +#ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# define VC_EXTRALEAN +# include + +typedef HMODULE DynamicLibrary; + +# define dynamic_library_open(path) LoadLibraryA(path) +# define dynamic_library_close(lib) FreeLibrary(lib) +# define dynamic_library_find(lib, symbol) GetProcAddress(lib, symbol) +#else +# include + +typedef void* DynamicLibrary; + +# define dynamic_library_open(path) dlopen(path, RTLD_NOW) +# define dynamic_library_close(lib) dlclose(lib) +# define dynamic_library_find(lib, symbol) dlsym(lib, symbol) +#endif +