From 32bca519066ec3e3d82003e07fa414b8ddd9d522 Mon Sep 17 00:00:00 2001 From: foreman Date: Tue, 8 May 2018 15:07:44 -0400 Subject: [PATCH] P4 to Git Change 1551967 by gandryey@gera-w8 on 2018/05/08 14:11:14 SWDEV-151981 - Removal of CPU support on Windows - Part 4. Remove CPU specific logic for CL-GL interop Affected files ... ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10.cpp#17 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp#10 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11.cpp#26 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp#14 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9.cpp#35 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp#18 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_gl.cpp#58 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_gl_amd.hpp#21 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/interop.hpp#13 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#103 edit --- opencl/api/opencl/amdocl/cl_d3d10.cpp | 304 ------------------- opencl/api/opencl/amdocl/cl_d3d10_amd.hpp | 16 - opencl/api/opencl/amdocl/cl_d3d11.cpp | 344 ---------------------- opencl/api/opencl/amdocl/cl_d3d11_amd.hpp | 16 - opencl/api/opencl/amdocl/cl_d3d9.cpp | 42 --- opencl/api/opencl/amdocl/cl_d3d9_amd.hpp | 4 - opencl/api/opencl/amdocl/cl_gl.cpp | 172 +---------- opencl/api/opencl/amdocl/cl_gl_amd.hpp | 8 - 8 files changed, 9 insertions(+), 897 deletions(-) diff --git a/opencl/api/opencl/amdocl/cl_d3d10.cpp b/opencl/api/opencl/amdocl/cl_d3d10.cpp index 074f5cd736..23840737ef 100644 --- a/opencl/api/opencl/amdocl/cl_d3d10.cpp +++ b/opencl/api/opencl/amdocl/cl_d3d10.cpp @@ -1404,99 +1404,6 @@ void BufferD3D10::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool BufferD3D10::mapExtObjectInCQThread() { - void* pCpuMem = NULL; - HRESULT hr; - D3D10_MAP gpuMap; - UINT cpuAccess; - - - if (getMemFlags() & CL_MEM_READ_WRITE) { - gpuMap = D3D10_MAP_READ_WRITE; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_READ_ONLY) { - gpuMap = D3D10_MAP_READ; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - gpuMap = D3D10_MAP_WRITE; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else { - // Should not get here, the flags had been checked before - LogError("\nInvalid memrory flags"); - return false; - } - - if (getUsage() == D3D10_USAGE_STAGING) { - // Can map directly - hr = reinterpret_cast(getD3D10Resource())->Map(gpuMap, 0, &pCpuMem); - if (hr != S_OK || !pCpuMem) { - LogError("Cannot map ID3D10Buffer object to CPU memory"); - return false; - } - } else { - // The buffer need to be mapped indirectly - // Create auxiliary buffer - ID3D10Device* pD3D10Dev; - getD3D10Resource()->GetDevice(&pD3D10Dev); - if (!pD3D10Dev) { - LogError("\nCannot get D3D10 device"); - return false; - } - pD3D10Dev->Release(); - D3D10_BUFFER_DESC bufDesc = {getResourceByteSize(), D3D10_USAGE_STAGING, 0, cpuAccess, 0}; - ID3D10Buffer* pAuxBuf; - hr = pD3D10Dev->CreateBuffer(&bufDesc, NULL, &pAuxBuf); - if (hr != S_OK || !pAuxBuf) { - LogError("\nCannot create auxiliary buffer"); - return false; - } - setD3D10AuxRes(pAuxBuf); - // Copy contents of original buffer to auxiliary - pD3D10Dev->CopyResource(pAuxBuf, getD3D10Resource()); - // Now map the aux buffer - hr = pAuxBuf->Map(gpuMap, 0, &pCpuMem); - if (hr != S_OK || !pCpuMem) { - LogError("Cannot map D3D10 auxiliary buffer to CPU memory"); - return false; - } - } - - setHostMem(pCpuMem); - return true; -} - -bool BufferD3D10::unmapExtObjectInCQThread() { - if (getMemFlags() & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) { - if (getD3D10AuxRes()) { - // Need to copy data from aux to original - reinterpret_cast(getD3D10AuxRes())->Unmap(); - ID3D10Device* pD3D10Dev; - getD3D10AuxRes()->GetDevice(&pD3D10Dev); - if (!pD3D10Dev) { - LogError("\nCannot get D3D10 device"); - return false; - } - pD3D10Dev->Release(); - pD3D10Dev->CopyResource(getD3D10Resource(), getD3D10AuxRes()); - getD3D10AuxRes()->Release(); - setD3D10AuxRes(NULL); - } else { - reinterpret_cast(getD3D10Resource())->Unmap(); - } - } else { - // Just unmap everything, no need to copy contents - if (getD3D10AuxRes()) { - reinterpret_cast(getD3D10AuxRes())->Unmap(); - getD3D10AuxRes()->Release(); - setD3D10AuxRes(NULL); - } else { - reinterpret_cast(getD3D10Resource())->Unmap(); - } - } - setHostMem(NULL); - return true; -} - // // Class Image1DD3D10 implementation // @@ -1507,16 +1414,6 @@ void Image1DD3D10::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool Image1DD3D10::mapExtObjectInCQThread() { - LogError("\nImage1DD3D10::mapExtObjectInCQThread() is not implemented yet\n"); - return false; -} - -bool Image1DD3D10::unmapExtObjectInCQThread() { - LogError("\nImage1DD3D10::unmapExtObjectInCQThread() is not implemented yet\n"); - return false; -} - // // Class Image2DD3D10 implementation // @@ -1527,106 +1424,6 @@ void Image2DD3D10::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool Image2DD3D10::mapExtObjectInCQThread() { - D3D10_MAPPED_TEXTURE2D texture2D; - HRESULT hr; - D3D10_MAP gpuMap; - UINT cpuAccess; - - - if (getMemFlags() & CL_MEM_READ_WRITE) { - gpuMap = D3D10_MAP_READ_WRITE; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_READ_ONLY) { - gpuMap = D3D10_MAP_READ; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - gpuMap = D3D10_MAP_WRITE; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else { - // Should not get here, the flags had been checked before - LogError("\nInvalid memrory flags"); - return false; - } - - if (getUsage() == D3D10_USAGE_STAGING) { - // Can map directly - hr = reinterpret_cast(getD3D10Resource()) - ->Map(getSubresource(), gpuMap, 0, &texture2D); - if (hr != S_OK || !texture2D.pData) { - LogError("Cannot map ID3D10Texture2D object to CPU memory"); - return false; - } - } else { - // The texture needs to be mapped indirectly. - // Create auxiliary texture. - ID3D10Device* pD3D10Dev; - getD3D10Resource()->GetDevice(&pD3D10Dev); - if (!pD3D10Dev) { - LogError("\nCannot get D3D10 device"); - return false; - } - pD3D10Dev->Release(); - D3D10_TEXTURE2D_DESC texDesc; - reinterpret_cast(getD3D10Resource())->GetDesc(&texDesc); - texDesc.Usage = D3D10_USAGE_STAGING; - texDesc.MipLevels = 1; - texDesc.BindFlags = 0; - texDesc.CPUAccessFlags = cpuAccess; - texDesc.MiscFlags = 0; - ID3D10Texture2D* pAuxTex; - hr = pD3D10Dev->CreateTexture2D(&texDesc, NULL, &pAuxTex); - if (hr != S_OK) { - LogError("\nCannot create auxiliary 2D texture"); - return false; - } - setD3D10AuxRes(pAuxTex); - // Copy contents of original texture to auxiliary - pD3D10Dev->CopyResource(pAuxTex, getD3D10Resource()); - // Now map the aux texture - hr = pAuxTex->Map(0, gpuMap, 0, &texture2D); - if (hr != S_OK || !texture2D.pData) { - LogError("Cannot map D3D10 auxiliary 2D texture to CPU memory"); - return false; - } - } - - setHostMem(texture2D.pData); - return true; -} - -bool Image2DD3D10::unmapExtObjectInCQThread() { - if (getMemFlags() & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) { - if (getD3D10AuxRes()) { - // Need to copy data from aux to original - reinterpret_cast(getD3D10AuxRes())->Unmap(0); - ID3D10Device* pD3D10Dev; - getD3D10AuxRes()->GetDevice(&pD3D10Dev); - if (!pD3D10Dev) { - LogError("\nCannot get D3D10 device"); - return false; - } - pD3D10Dev->Release(); - pD3D10Dev->CopyResource(getD3D10Resource(), getD3D10AuxRes()); - getD3D10AuxRes()->Release(); - setD3D10AuxRes(NULL); - } else { - reinterpret_cast(getD3D10Resource())->Unmap(getSubresource()); - } - } else { - // Just unmap everything, no need to copy contents - if (getD3D10AuxRes()) { - reinterpret_cast(getD3D10AuxRes())->Unmap(0); - getD3D10AuxRes()->Release(); - setD3D10AuxRes(NULL); - } else { - reinterpret_cast(getD3D10Resource())->Unmap(getSubresource()); - } - } - setHostMem(NULL); - return true; -} - // // Class Image3DD3D10 implementation // @@ -1636,107 +1433,6 @@ void Image3DD3D10::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } - -bool Image3DD3D10::mapExtObjectInCQThread() { - D3D10_MAPPED_TEXTURE3D texture3D; - HRESULT hr; - D3D10_MAP gpuMap; - UINT cpuAccess; - - - if (getMemFlags() & CL_MEM_READ_WRITE) { - gpuMap = D3D10_MAP_READ_WRITE; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_READ_ONLY) { - gpuMap = D3D10_MAP_READ; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - gpuMap = D3D10_MAP_WRITE; - cpuAccess = D3D10_CPU_ACCESS_READ | D3D10_CPU_ACCESS_WRITE; - } else { - // Should not get here, the flags had been checked before - LogError("\nInvalid memrory flags"); - return false; - } - - if (getUsage() == D3D10_USAGE_STAGING) { - // Can map directly - hr = reinterpret_cast(getD3D10Resource()) - ->Map(getSubresource(), gpuMap, 0, &texture3D); - if (hr != S_OK || !texture3D.pData) { - LogError("Cannot map ID3D10Texture3D object to CPU memory"); - return false; - } - } else { - // The texture needs to be mapped indirectly. - // Create auxiliary texture. - ID3D10Device* pD3D10Dev; - getD3D10Resource()->GetDevice(&pD3D10Dev); - if (!pD3D10Dev) { - LogError("\nCannot get D3D10 device"); - return false; - } - pD3D10Dev->Release(); - D3D10_TEXTURE3D_DESC texDesc; - reinterpret_cast(getD3D10Resource())->GetDesc(&texDesc); - texDesc.Usage = D3D10_USAGE_STAGING; - texDesc.MipLevels = 1; - texDesc.BindFlags = 0; - texDesc.CPUAccessFlags = cpuAccess; - texDesc.MiscFlags = 0; - ID3D10Texture3D* pAuxTex; - hr = pD3D10Dev->CreateTexture3D(&texDesc, NULL, &pAuxTex); - if (hr != S_OK) { - LogError("\nCannot create auxiliary 3D texture"); - return false; - } - setD3D10AuxRes(pAuxTex); - // Copy contents of original texture to auxiliary - pD3D10Dev->CopyResource(pAuxTex, getD3D10Resource()); - // Now map the aux texture - hr = pAuxTex->Map(0, gpuMap, 0, &texture3D); - if (hr != S_OK || !texture3D.pData) { - LogError("Cannot map D3D10 auxiliary 3D texture to CPU memory"); - return false; - } - } - - setHostMem(texture3D.pData); - return true; -} - -bool Image3DD3D10::unmapExtObjectInCQThread() { - if (getMemFlags() & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) { - if (getD3D10AuxRes()) { - // Need to copy data from aux to original - reinterpret_cast(getD3D10AuxRes())->Unmap(0); - ID3D10Device* pD3D10Dev; - getD3D10AuxRes()->GetDevice(&pD3D10Dev); - if (!pD3D10Dev) { - LogError("\nCannot get D3D10 device"); - return false; - } - pD3D10Dev->Release(); - pD3D10Dev->CopyResource(getD3D10Resource(), getD3D10AuxRes()); - getD3D10AuxRes()->Release(); - setD3D10AuxRes(NULL); - } else { - reinterpret_cast(getD3D10Resource())->Unmap(getSubresource()); - } - } else { - // Just unmap everything, no need to copy contents - if (getD3D10AuxRes()) { - reinterpret_cast(getD3D10AuxRes())->Unmap(0); - getD3D10AuxRes()->Release(); - setD3D10AuxRes(NULL); - } else { - reinterpret_cast(getD3D10Resource())->Unmap(getSubresource()); - } - } - setHostMem(NULL); - return true; -} - } // namespace amd #endif //_WIN32 diff --git a/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp b/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp index 79f1de7d66..0bcea8bfef 100644 --- a/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp +++ b/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp @@ -240,10 +240,6 @@ public: setInteropObj(this); } virtual ~BufferD3D10() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; //! Class Image1DD3D10 is derived from classes Image1D and D3D10Object @@ -278,10 +274,6 @@ public: setInteropObj(this); } virtual ~Image1DD3D10() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; //! Class Image2DD3D10 is derived from classes Image2D and D3D10Object @@ -316,10 +308,6 @@ public: setInteropObj(this); } virtual ~Image2DD3D10() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; //! Class Image3DD3D10 is derived from classes Image3D and D3D10Object @@ -354,10 +342,6 @@ public: setInteropObj(this); } virtual ~Image3DD3D10() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; //! Functions for executing the D3D10 related stuff diff --git a/opencl/api/opencl/amdocl/cl_d3d11.cpp b/opencl/api/opencl/amdocl/cl_d3d11.cpp index cbef266a32..3c31a87c28 100644 --- a/opencl/api/opencl/amdocl/cl_d3d11.cpp +++ b/opencl/api/opencl/amdocl/cl_d3d11.cpp @@ -962,114 +962,6 @@ void BufferD3D11::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool BufferD3D11::mapExtObjectInCQThread() { - D3D11_MAPPED_SUBRESOURCE mappedResource; - HRESULT hr; - D3D11_MAP gpuMap; - UINT cpuAccess; - - - if (getMemFlags() & CL_MEM_READ_WRITE) { - gpuMap = D3D11_MAP_READ_WRITE; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_READ_ONLY) { - gpuMap = D3D11_MAP_READ; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - gpuMap = D3D11_MAP_WRITE; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else { - // Should not get here, the flags had been checked before - LogError("\nInvalid memrory flags"); - return false; - } - - ID3D11Device* pD3D11Dev; - getD3D11Resource()->GetDevice(&pD3D11Dev); - if (!pD3D11Dev) { - LogError("\nCannot get D3D11 device"); - return false; - } - pD3D11Dev->Release(); - ID3D11DeviceContext* pImmediateContext = NULL; - pD3D11Dev->GetImmediateContext(&pImmediateContext); - if (!pImmediateContext) { - LogError("\nCannot get D3D11 device context"); - return false; - } - pImmediateContext->Release(); - if (getUsage() == D3D11_USAGE_STAGING) { - // XXX Christophe: Use DeviceContext to map - //// Can map directly - hr = pImmediateContext->Map(getD3D11Resource(), 0, gpuMap, 0, &mappedResource); - if (hr != S_OK || !mappedResource.pData) { - LogError("Cannot map ID3D11Buffer object to CPU memory"); - return false; - } - } else { - // The buffer need to be mapped indirectly - // Create auxiliary buffer - D3D11_BUFFER_DESC bufDesc = {getResourceByteSize(), D3D11_USAGE_STAGING, 0, cpuAccess, 0}; - ID3D11Buffer* pAuxBuf; - hr = pD3D11Dev->CreateBuffer(&bufDesc, NULL, &pAuxBuf); - if (hr != S_OK || !pAuxBuf) { - LogError("\nCannot create auxiliary buffer"); - return false; - } - setD3D11AuxRes(pAuxBuf); - // Copy contents of original buffer to auxiliary - pImmediateContext->CopyResource(pAuxBuf, getD3D11Resource()); - // Now map the aux buffer - hr = pImmediateContext->Map(pAuxBuf, 0, gpuMap, 0, &mappedResource); - if (hr != S_OK || !mappedResource.pData) { - LogError("Cannot map D3D11 auxiliary buffer to CPU memory"); - return false; - } - } - - setHostMem(mappedResource.pData); - return true; -} - -bool BufferD3D11::unmapExtObjectInCQThread() { - ID3D11Device* pD3D11Dev; - getD3D11AuxRes()->GetDevice(&pD3D11Dev); - if (!pD3D11Dev) { - LogError("\nCannot get D3D11 device"); - return false; - } - pD3D11Dev->Release(); - ID3D11DeviceContext* pImmediateContext = NULL; - pD3D11Dev->GetImmediateContext(&pImmediateContext); - if (!pImmediateContext) { - LogError("\nCannot get D3D11 device context"); - return false; - } - pImmediateContext->Release(); - if (getMemFlags() & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) { - if (getD3D11AuxRes()) { - // Need to copy data from aux to original - pImmediateContext->Unmap(getD3D11AuxRes(), 0); - pImmediateContext->CopyResource(getD3D11Resource(), getD3D11AuxRes()); - getD3D11AuxRes()->Release(); - setD3D11AuxRes(NULL); - } else { - pImmediateContext->Unmap(getD3D11Resource(), 0); - } - } else { - // Just unmap everything, no need to copy contents - if (getD3D11AuxRes()) { - pImmediateContext->Unmap(getD3D11AuxRes(), 0); - getD3D11AuxRes()->Release(); - setD3D11AuxRes(NULL); - } else { - pImmediateContext->Unmap(getD3D11Resource(), 0); - } - } - setHostMem(NULL); - return true; -} - // // Class Image1DD3D11 implementation // @@ -1079,16 +971,6 @@ void Image1DD3D11::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool Image1DD3D11::mapExtObjectInCQThread() { - LogError("\nImage1DD3D11::mapExtObjectInCQThread() is not implemented yet\n"); - return false; -} - -bool Image1DD3D11::unmapExtObjectInCQThread() { - LogError("\nImage1DD3D11::unmapExtObjectInCQThread() is not implemented yet\n"); - return false; -} - // // Class Image2DD3D11 implementation // @@ -1099,119 +981,6 @@ void Image2DD3D11::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool Image2DD3D11::mapExtObjectInCQThread() { - D3D11_MAPPED_SUBRESOURCE texture2D; - HRESULT hr; - D3D11_MAP gpuMap; - UINT cpuAccess; - - - if (getMemFlags() & CL_MEM_READ_WRITE) { - gpuMap = D3D11_MAP_READ_WRITE; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_READ_ONLY) { - gpuMap = D3D11_MAP_READ; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - gpuMap = D3D11_MAP_WRITE; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else { - // Should not get here, the flags had been checked before - LogError("\nInvalid memrory flags"); - return false; - } - - ID3D11Device* pD3D11Dev; - getD3D11Resource()->GetDevice(&pD3D11Dev); - if (!pD3D11Dev) { - LogError("\nCannot get D3D11 device"); - return false; - } - pD3D11Dev->Release(); - ID3D11DeviceContext* pImmediateContext = NULL; - pD3D11Dev->GetImmediateContext(&pImmediateContext); - if (!pImmediateContext) { - LogError("\nCannot get D3D11 device context"); - return false; - } - pImmediateContext->Release(); - if (getUsage() == D3D11_USAGE_STAGING) { - // Can map directly - hr = pImmediateContext->Map(getD3D11Resource(), getSubresource(), gpuMap, 0, &texture2D); - if (hr != S_OK || !texture2D.pData) { - LogError("Cannot map ID3D11Texture2D object to CPU memory"); - return false; - } - } else { - // The texture needs to be mapped indirectly. - // Create auxiliary texture. - D3D11_TEXTURE2D_DESC texDesc; - reinterpret_cast(getD3D11Resource())->GetDesc(&texDesc); - texDesc.Usage = D3D11_USAGE_STAGING; - texDesc.MipLevels = 1; - texDesc.BindFlags = 0; - texDesc.CPUAccessFlags = cpuAccess; - texDesc.MiscFlags = 0; - ID3D11Texture2D* pAuxTex; - hr = pD3D11Dev->CreateTexture2D(&texDesc, NULL, &pAuxTex); - if (hr != S_OK) { - LogError("\nCannot create auxiliary 2D texture"); - return false; - } - setD3D11AuxRes(pAuxTex); - // Copy contents of original texture to auxiliary - pImmediateContext->CopyResource(pAuxTex, getD3D11Resource()); - // Now map the aux texture - hr = pImmediateContext->Map(pAuxTex, 0, gpuMap, 0, &texture2D); - if (hr != S_OK || !texture2D.pData) { - LogError("Cannot map D3D11 auxiliary 2D texture to CPU memory"); - return false; - } - } - - setHostMem(texture2D.pData); - return true; -} - -bool Image2DD3D11::unmapExtObjectInCQThread() { - ID3D11Device* pD3D11Dev; - getD3D11AuxRes()->GetDevice(&pD3D11Dev); - if (!pD3D11Dev) { - LogError("\nCannot get D3D11 device"); - return false; - } - pD3D11Dev->Release(); - ID3D11DeviceContext* pImmediateContext = NULL; - pD3D11Dev->GetImmediateContext(&pImmediateContext); - if (!pImmediateContext) { - LogError("\nCannot get D3D11 device context"); - return false; - } - pImmediateContext->Release(); - if (getMemFlags() & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) { - if (getD3D11AuxRes()) { - // Need to copy data from aux to original - pImmediateContext->Unmap(getD3D11AuxRes(), 0); - pImmediateContext->CopyResource(getD3D11Resource(), getD3D11AuxRes()); - getD3D11AuxRes()->Release(); - setD3D11AuxRes(NULL); - } else { - pImmediateContext->Unmap(getD3D11Resource(), getSubresource()); - } - } else { - // Just unmap everything, no need to copy contents - if (getD3D11AuxRes()) { - pImmediateContext->Unmap(getD3D11AuxRes(), 0); - getD3D11AuxRes()->Release(); - setD3D11AuxRes(NULL); - } else { - pImmediateContext->Unmap(getD3D11Resource(), getSubresource()); - } - } - setHostMem(NULL); - return true; -} - // // Class Image3DD3D11 implementation // @@ -1221,119 +990,6 @@ void Image3DD3D11::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool Image3DD3D11::mapExtObjectInCQThread() { - D3D11_MAPPED_SUBRESOURCE texture3D; - HRESULT hr; - D3D11_MAP gpuMap; - UINT cpuAccess; - - - if (getMemFlags() & CL_MEM_READ_WRITE) { - gpuMap = D3D11_MAP_READ_WRITE; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_READ_ONLY) { - gpuMap = D3D11_MAP_READ; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - gpuMap = D3D11_MAP_WRITE; - cpuAccess = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; - } else { - // Should not get here, the flags had been checked before - LogError("\nInvalid memrory flags"); - return false; - } - - ID3D11Device* pD3D11Dev; - getD3D11AuxRes()->GetDevice(&pD3D11Dev); - if (!pD3D11Dev) { - LogError("\nCannot get D3D11 device"); - return false; - } - pD3D11Dev->Release(); - ID3D11DeviceContext* pImmediateContext = NULL; - pD3D11Dev->GetImmediateContext(&pImmediateContext); - if (!pImmediateContext) { - LogError("\nCannot get D3D11 device context"); - return false; - } - pImmediateContext->Release(); - if (getUsage() == D3D11_USAGE_STAGING) { - // Can map directly - hr = pImmediateContext->Map(getD3D11Resource(), getSubresource(), gpuMap, 0, &texture3D); - if (hr != S_OK || !texture3D.pData) { - LogError("Cannot map ID3D11Texture3D object to CPU memory"); - return false; - } - } else { - // The texture needs to be mapped indirectly. - // Create auxiliary texture. - D3D11_TEXTURE3D_DESC texDesc; - reinterpret_cast(getD3D11Resource())->GetDesc(&texDesc); - texDesc.Usage = D3D11_USAGE_STAGING; - texDesc.MipLevels = 1; - texDesc.BindFlags = 0; - texDesc.CPUAccessFlags = cpuAccess; - texDesc.MiscFlags = 0; - ID3D11Texture3D* pAuxTex; - hr = pD3D11Dev->CreateTexture3D(&texDesc, NULL, &pAuxTex); - if (hr != S_OK) { - LogError("\nCannot create auxiliary 3D texture"); - return false; - } - setD3D11AuxRes(pAuxTex); - // Copy contents of original texture to auxiliary - pImmediateContext->CopyResource(pAuxTex, getD3D11Resource()); - // Now map the aux texture - hr = pImmediateContext->Map(pAuxTex, 0, gpuMap, 0, &texture3D); - if (hr != S_OK || !texture3D.pData) { - LogError("Cannot map D3D11 auxiliary 3D texture to CPU memory"); - return false; - } - } - - setHostMem(texture3D.pData); - return true; -} - -bool Image3DD3D11::unmapExtObjectInCQThread() { - ID3D11Device* pD3D11Dev; - getD3D11AuxRes()->GetDevice(&pD3D11Dev); - if (!pD3D11Dev) { - LogError("\nCannot get D3D11 device"); - return false; - } - pD3D11Dev->Release(); - ID3D11DeviceContext* pImmediateContext = NULL; - pD3D11Dev->GetImmediateContext(&pImmediateContext); - if (!pImmediateContext) { - LogError("\nCannot get D3D11 device context"); - return false; - } - pImmediateContext->Release(); - if (getMemFlags() & (CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) { - if (getD3D11AuxRes()) { - // Need to copy data from aux to original - pImmediateContext->Unmap(getD3D11AuxRes(), 0); - pImmediateContext->CopyResource(getD3D11Resource(), getD3D11AuxRes()); - getD3D11AuxRes()->Release(); - setD3D11AuxRes(NULL); - } else { - pImmediateContext->Unmap(getD3D11Resource(), getSubresource()); - } - } else { - // Just unmap everything, no need to copy contents - if (getD3D11AuxRes()) { - pImmediateContext->Unmap(getD3D11AuxRes(), 0); - getD3D11AuxRes()->Release(); - setD3D11AuxRes(NULL); - } else { - pImmediateContext->Unmap(getD3D11Resource(), getSubresource()); - } - } - setHostMem(NULL); - return true; -} - // // Helper function SyncD3D11Objects // diff --git a/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp b/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp index f2ba1ce726..3da64be895 100644 --- a/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp +++ b/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp @@ -251,10 +251,6 @@ public: setInteropObj(this); } virtual ~BufferD3D11() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; //! Class Image1DD3D11 is derived from classes Image1D and D3D11Object @@ -289,10 +285,6 @@ public: setInteropObj(this); } virtual ~Image1DD3D11() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; //! Class Image2DD3D11 is derived from classes Image2D and D3D11Object @@ -327,10 +319,6 @@ public: setInteropObj(this); } virtual ~Image2DD3D11() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; //! Class Image3DD3D11 is derived from classes Image3D and D3D11Object @@ -365,10 +353,6 @@ public: setInteropObj(this); } virtual ~Image3DD3D11() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; //! Functions for executing the D3D11 related stuff diff --git a/opencl/api/opencl/amdocl/cl_d3d9.cpp b/opencl/api/opencl/amdocl/cl_d3d9.cpp index d63658a809..d1eb396c52 100644 --- a/opencl/api/opencl/amdocl/cl_d3d9.cpp +++ b/opencl/api/opencl/amdocl/cl_d3d9.cpp @@ -816,48 +816,6 @@ void Image2DD3D9::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool Image2DD3D9::mapExtObjectInCQThread() { - void* pCpuMem = NULL; - HRESULT hr; - DWORD lockFlags = 0; - - if (getMemFlags() & CL_MEM_READ_WRITE) { - lockFlags = 0; - } else if (getMemFlags() & CL_MEM_READ_ONLY) { - lockFlags = D3DLOCK_READONLY; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - lockFlags = D3DLOCK_DISCARD; - } else { - // Should not get here, the flags had been checked before - LogError("\nInvalid memrory flags"); - return false; - } - ScopedLock sl(getResLock()); - - D3DLOCKED_RECT lockedRect; - hr = getD3D9Resource()->LockRect(&lockedRect, NULL, lockFlags); - if ((hr != D3D_OK) || !lockedRect.pBits) { - LogError("Cannot lock D3D9 surface for CPU access"); - return false; - } - - setHostMem(lockedRect.pBits); - return true; -} - -bool Image2DD3D9::unmapExtObjectInCQThread() { - HRESULT hr; - ScopedLock sl(getResLock()); - hr = getD3D9Resource()->UnlockRect(); - if (hr != D3D_OK) { - LogError("Cannot unlock D3D9 surface"); - return false; - } - - setHostMem(NULL); - return true; -} - } // namespace amd #endif //_WIN32 diff --git a/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp b/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp index 2bf5bd2f34..a291f86c40 100644 --- a/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp +++ b/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp @@ -311,10 +311,6 @@ public: setInteropObj(this); } virtual ~Image2DD3D9() {} - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; cl_mem clCreateImage2DFromD3D9ResourceAMD( diff --git a/opencl/api/opencl/amdocl/cl_gl.cpp b/opencl/api/opencl/amdocl/cl_gl.cpp index 5bc3cec800..f7781e2f36 100644 --- a/opencl/api/opencl/amdocl/cl_gl.cpp +++ b/opencl/api/opencl/amdocl/cl_gl.cpp @@ -814,9 +814,7 @@ RUNTIME_ENTRY(cl_int, clGetGLContextInfoKHR, size_t param_value_size, void* param_value, size_t* param_value_size_ret)) { cl_int errcode; cl_device_id* gpu_devices; - cl_device_id* cpu_devices; cl_uint num_gpu_devices = 0; - cl_uint num_cpu_devices = 0; amd::Context::Info info; static const bool VALIDATE_ONLY = true; @@ -835,12 +833,8 @@ RUNTIME_ENTRY(cl_int, clGetGLContextInfoKHR, if (errcode != CL_SUCCESS && errcode != CL_DEVICE_NOT_FOUND) { return CL_INVALID_VALUE; } - errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_CPU, 0, NULL, &num_cpu_devices); - if (errcode != CL_SUCCESS && errcode != CL_DEVICE_NOT_FOUND) { - return CL_INVALID_VALUE; - } - if (!num_gpu_devices && !num_cpu_devices) { + if (!num_gpu_devices) { return CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR; } @@ -865,25 +859,17 @@ RUNTIME_ENTRY(cl_int, clGetGLContextInfoKHR, } *not_null(param_value_size_ret) = 0; - } else { - cpu_devices = (cl_device_id*)alloca(num_cpu_devices * sizeof(cl_device_id)); - - errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_CPU, num_cpu_devices, cpu_devices, NULL); - if (errcode != CL_SUCCESS) { - return errcode; - } - return amd::clGetInfo(cpu_devices[0], param_value_size, param_value, param_value_size_ret); } break; case CL_DEVICES_FOR_GL_CONTEXT_KHR: { // List of all CL devices that can be associated with the specified OpenGL context. - cl_uint total_devices = num_gpu_devices + num_cpu_devices; + cl_uint total_devices = num_gpu_devices; size_t size = total_devices * sizeof(cl_device_id); cl_device_id* devices = (cl_device_id*)alloca(size); - errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_CPU, total_devices, + errcode = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, total_devices, devices, NULL); if (errcode != CL_SUCCESS) { return errcode; @@ -1310,58 +1296,6 @@ void BufferGL::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool BufferGL::mapExtObjectInCQThread() { - assert(!context_().glenv()->isEGL()); - GLFunctions::SetIntEnv ie(context_().glenv()); - if (!ie.isValid()) { - return false; - } - - GLenum glAccess = GL_READ_WRITE; // Default - if (getMemFlags() & CL_MEM_READ_ONLY) { - glAccess = GL_READ_ONLY; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - glAccess = GL_WRITE_ONLY; - } - clearGLErrors(context_()); - context_().glenv()->glBindBuffer_(GL_ARRAY_BUFFER, gluiName_); - - void* pCpuMem = context_().glenv()->glMapBuffer_(GL_ARRAY_BUFFER, glAccess); - - if (checkForGLError(context_()) != GL_NO_ERROR || !pCpuMem) { - LogError("cannot map GL buffer"); - return false; - } - - setHostMem(pCpuMem); - - return true; -} - -bool BufferGL::unmapExtObjectInCQThread() { - assert(!context_().glenv()->isEGL()); - GLFunctions::SetIntEnv ie(context_().glenv()); - if (!ie.isValid()) { - return false; - } - - clearGLErrors(context_()); - context_().glenv()->glBindBuffer_(GL_ARRAY_BUFFER, gluiName_); - - if (GL_FALSE == context_().glenv()->glUnmapBuffer_(GL_ARRAY_BUFFER)) { - LogError("context_().glenv()->glUnmapBuffer_ returned GL_FALSE - buffer may be corrupted"); - return false; - } - if (checkForGLError(context_()) != GL_NO_ERROR) { - LogWarning("Error unmapping GL buffer"); - return false; - } - - setHostMem(NULL); - - return true; -} - static GLenum clChannelDataTypeToGlType(cl_channel_type channel_type) { // Pick // GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, @@ -1433,92 +1367,6 @@ void ImageGL::initDeviceMemory() { memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); } -bool ImageGL::mapExtObjectInCQThread() { - assert(!context_().glenv()->isEGL()); - GLFunctions::SetIntEnv ie(context_().glenv()); - if (!ie.isValid()) { - return false; - } - - GLenum glAccess = GL_READ_WRITE; // Default - - if (getMemFlags() & CL_MEM_READ_ONLY) { - glAccess = GL_READ_ONLY; - } else if (getMemFlags() & CL_MEM_WRITE_ONLY) { - glAccess = GL_WRITE_ONLY; - } - clearGLErrors(context_()); - context_().glenv()->glBindTexture_(getGLTarget(), gluiName_); - - size_t mem_size = getSize(); - - char* pCpuMem = new char[mem_size]; - if (pCpuMem == NULL) { - LogError("Cannot alloc host memory for ImageGL"); - return false; - } - - context_().glenv()->glGetTexImage_( - getGLTarget(), gliMipLevel_, glInternalFormatToGlFormat(glInternalFormat_), - clChannelDataTypeToGlType(getImageFormat().image_channel_data_type), pCpuMem); - - if (checkForGLError(context_()) != GL_NO_ERROR) { - LogError("cannot map GL texture"); - delete[] pCpuMem; - return false; - } - - setHostMem(pCpuMem); - - return true; -} - -bool ImageGL::unmapExtObjectInCQThread() { - assert(!context_().glenv()->isEGL()); - GLFunctions::SetIntEnv ie(context_().glenv()); - if (!ie.isValid()) { - return false; - } - - bool status = true; - - clearGLErrors(context_()); - context_().glenv()->glBindTexture_(getGLTarget(), gluiName_); - - char* pCpuMem = (char*)getHostMem(); - - if (checkForGLError(context_()) != GL_NO_ERROR) { - LogError("Cannot map GL texture"); - status = false; - goto cleanup; - } - - context_().glenv()->glTexImage2D_( - getGLTarget(), // target - gliMipLevel_, // miplevel - glInternalFormat_, // internalFormat or bytes per pixel - gliWidth_, // width - gliHeight_, // height - 0, // border - // format - glInternalFormatToGlFormat(glInternalFormat_), - // type - clChannelDataTypeToGlType(getImageFormat().image_channel_data_type), - pCpuMem); // data - - if (checkForGLError(context_()) != GL_NO_ERROR) { - LogError("Cannot update GL texture"); - status = false; - goto cleanup; - } - -cleanup: - delete[] pCpuMem; - setHostMem(NULL); - - return status; -} - //******************************************************************* // // Internal implementation of CL API functions @@ -1615,15 +1463,13 @@ cl_mem clCreateFromGLBufferAMD(Context& amdContext, cl_mem_flags flags, GLuint b const auto it = amdContext.devices().cbegin(); const amd::Device& dev = *(*it); - if (dev.type() != CL_DEVICE_TYPE_CPU) { - device::Memory* mem = pBufferGL->getDeviceMemory(dev); - if (NULL == mem) { - LogPrintfError("Can't allocate memory size - 0x%08X bytes!", pBufferGL->getSize()); - *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; - return (cl_mem)0; - } - mem->processGLResource(device::Memory::GLDecompressResource); + device::Memory* mem = pBufferGL->getDeviceMemory(dev); + if (NULL == mem) { + LogPrintfError("Can't allocate memory size - 0x%08X bytes!", pBufferGL->getSize()); + *not_null(errcode_ret) = CL_INVALID_GL_OBJECT; + return (cl_mem)0; } + mem->processGLResource(device::Memory::GLDecompressResource); return as_cl(pBufferGL); } diff --git a/opencl/api/opencl/amdocl/cl_gl_amd.hpp b/opencl/api/opencl/amdocl/cl_gl_amd.hpp index 9adeeaaf60..148ae322a2 100644 --- a/opencl/api/opencl/amdocl/cl_gl_amd.hpp +++ b/opencl/api/opencl/amdocl/cl_gl_amd.hpp @@ -131,10 +131,6 @@ public: virtual ~BufferGL() {} virtual BufferGL* asBufferGL() { return this; } - - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); }; @@ -173,10 +169,6 @@ public: virtual ~ImageGL() {} - //! For CPU device only! - virtual bool mapExtObjectInCQThread(void); - virtual bool unmapExtObjectInCQThread(void); - protected: //! Initializes the device memory array which is nested // after'BufferGL' object in memory layout.