| 42 | CudaInterop::~CudaInterop() {} |
| 43 | |
| 44 | void CudaInterop::onLoad(RenderContext* pRenderContext) |
| 45 | { |
| 46 | // Initialize CUDA device |
| 47 | if (!getDevice()->initCudaDevice()) |
| 48 | FALCOR_THROW("Failed to initialize CUDA device."); |
| 49 | |
| 50 | // Create our input and output textures |
| 51 | mpInputTex = Texture::createFromFile( |
| 52 | getDevice(), AssetResolver::getDefaultResolver().resolvePath(kTexturePath), false, false, ResourceBindFlags::Shared |
| 53 | ); |
| 54 | if (!mpInputTex) |
| 55 | FALCOR_THROW("Failed to load texture '{}'", kTexturePath); |
| 56 | |
| 57 | mWidth = mpInputTex->getWidth(); |
| 58 | mHeight = mpInputTex->getHeight(); |
| 59 | mpOutputTex = getDevice()->createTexture2D( |
| 60 | mWidth, mHeight, mpInputTex->getFormat(), 1, 1, nullptr, ResourceBindFlags::Shared | ResourceBindFlags::ShaderResource |
| 61 | ); |
| 62 | |
| 63 | // Define our usage flags and then map the textures to CUDA surfaces. Surface values of 0 |
| 64 | // indicate an error during mapping. We need to cache mInputSurf and mOutputSurf as |
| 65 | // mapTextureToSurface() can only be called once per resource. |
| 66 | uint32_t usageFlags = cudaArrayColorAttachment; |
| 67 | |
| 68 | mInputSurf = cuda_utils::mapTextureToSurface(mpInputTex, usageFlags); |
| 69 | if (mInputSurf == 0) |
| 70 | FALCOR_THROW("Input texture to surface mapping failed"); |
| 71 | |
| 72 | mOutputSurf = cuda_utils::mapTextureToSurface(mpOutputTex, usageFlags); |
| 73 | if (mOutputSurf == 0) |
| 74 | FALCOR_THROW("Output texture to surface mapping failed"); |
| 75 | } |
| 76 | |
| 77 | void CudaInterop::onFrameRender(RenderContext* pRenderContext, const ref<Fbo>& pTargetFbo) |
| 78 | { |
nothing calls this directly
no test coverage detected