diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2022-07-25 13:36:43 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-25 13:36:43 -0700 |
| commit | ce6e946f6f4882aba8a62392ae791c948633e2e3 (patch) | |
| tree | fde46847900ef80ee111a6b612f7e0931b15fdf2 /tools/gfx/cuda/cuda-helper-functions.cpp | |
| parent | 129294a58d2a51308af78ad5d8d436c026863259 (diff) | |
Split render-cuda.cpp into smaller files (#2334)
* render-cuda split, compile errors galore due to missing includes etc.
* render-cuda split and fully compiles
* Ran premake.bat to disable cuda; Added all new files
* Removed render-cuda files
* CI fixes
* Rerun CI
Diffstat (limited to 'tools/gfx/cuda/cuda-helper-functions.cpp')
| -rw-r--r-- | tools/gfx/cuda/cuda-helper-functions.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tools/gfx/cuda/cuda-helper-functions.cpp b/tools/gfx/cuda/cuda-helper-functions.cpp new file mode 100644 index 000000000..6325d9fc6 --- /dev/null +++ b/tools/gfx/cuda/cuda-helper-functions.cpp @@ -0,0 +1,91 @@ +// cuda-helper-functions.cpp +#include "cuda-helper-functions.h" + +#include "cuda-device.h" + +namespace gfx +{ +#ifdef GFX_ENABLE_CUDA +using namespace Slang; + +namespace cuda +{ +SlangResult CUDAErrorInfo::handle() const +{ + StringBuilder builder; + builder << "Error: " << m_filePath << " (" << m_lineNo << ") :"; + + if (m_errorName) + { + builder << m_errorName << " : "; + } + if (m_errorString) + { + builder << m_errorString; + } + + getDebugCallback()->handleMessage(DebugMessageType::Error, DebugMessageSource::Driver, + builder.getUnownedSlice().begin()); + + // Slang::signalUnexpectedError(builder.getBuffer()); + return SLANG_FAIL; +} + +SlangResult _handleCUDAError(CUresult cuResult, const char* file, int line) +{ + CUDAErrorInfo info(file, line); + cuGetErrorString(cuResult, &info.m_errorString); + cuGetErrorName(cuResult, &info.m_errorName); + return info.handle(); +} + +SlangResult _handleCUDAError(cudaError_t error, const char* file, int line) +{ + return CUDAErrorInfo(file, line, cudaGetErrorName(error), cudaGetErrorString(error)).handle(); +} + +# ifdef RENDER_TEST_OPTIX + +static bool _isError(OptixResult result) +{ + return result != OPTIX_SUCCESS; +} + +# if 1 +static SlangResult _handleOptixError(OptixResult result, char const* file, int line) +{ + fprintf( + stderr, + "%s(%d): optix: %s (%s)\n", + file, + line, + optixGetErrorString(result), + optixGetErrorName(result)); + return SLANG_FAIL; +} + +void _optixLogCallback(unsigned int level, const char* tag, const char* message, void* userData) +{ + fprintf(stderr, "optix: %s (%s)\n", message, tag); +} +# endif +# endif +} // namespace cuda + +Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) +{ +RefPtr<cuda::DeviceImpl> result = new cuda::DeviceImpl(); +SLANG_RETURN_ON_FAIL(result->initialize(*desc)); +returnComPtr(outDevice, result); +return SLANG_OK; +} +#else +Result SLANG_MCALL createCUDADevice(const IDevice::Desc* desc, IDevice** outDevice) +{ +SLANG_UNUSED(desc); +*outDevice = nullptr; +return SLANG_FAIL; +} +#endif + +} // namespace gfx |
