#include "EmberCLPch.h"
#include "RendererClDevice.h"
namespace EmberCLns
{
///
/// Constructor that assigns members.
/// The object is not fully initialized at this point, the caller
/// must manually call Init().
///
/// The index of the platform to use
/// The index device of the device to use
/// True if shared with OpenGL, else false.
/// True if success, else false.
RendererClDevice::RendererClDevice(size_t platform, size_t device, bool shared)
{
m_Init = false;
m_Shared = shared;
m_NVidia = false;
m_WarpSize = 0;
m_Calls = 0;
m_PlatformIndex = platform;
m_DeviceIndex = device;
m_Info = OpenCLInfo::Instance();
}
///
/// Initialization of the OpenCLWrapper member.
///
/// True if success, else false.
bool RendererClDevice::Init()
{
bool b = true;
if (!m_Wrapper.Ok())
{
m_Init = false;
b = m_Wrapper.Init(m_PlatformIndex, m_DeviceIndex, m_Shared);
}
if (b && m_Wrapper.Ok() && !m_Init)
{
m_NVidia = Find(ToLower(m_Info->PlatformName(m_PlatformIndex)), "nvidia") && m_Wrapper.LocalMemSize() > (32 * 1024);
m_WarpSize = m_NVidia ? 32 : 64;
m_Init = true;
}
return b;
}
///
/// OpenCL property accessors, getters only.
///
bool RendererClDevice::Ok() const { return m_Init; }
bool RendererClDevice::Shared() const { return m_Shared; }
bool RendererClDevice::Nvidia() const { return m_NVidia; }
size_t RendererClDevice::WarpSize() const { return m_WarpSize; }
size_t RendererClDevice::PlatformIndex() const { return m_PlatformIndex; }
size_t RendererClDevice::DeviceIndex() const { return m_DeviceIndex; }
///
/// Clear the error report for this class as well as the wrapper.
///
void RendererClDevice::ClearErrorReport()
{
EmberReport::ClearErrorReport();
m_Wrapper.ClearErrorReport();
}
///
/// Concatenate and return the error report for this class and the
/// wrapper as a single string.
///
/// The concatenated error report string
string RendererClDevice::ErrorReportString()
{
const auto s = EmberReport::ErrorReportString();
return s + m_Wrapper.ErrorReportString();
}
///
/// Concatenate and return the error report for this class and the
/// wrapper as a vector of strings.
///
/// The concatenated error report vector of strings
vector RendererClDevice::ErrorReport()
{
auto ours = EmberReport::ErrorReport();
const auto s = m_Wrapper.ErrorReport();
ours.insert(ours.end(), s.begin(), s.end());
return ours;
}
}