initial commit

[ROCm/clr commit: 3694ab2ce8]
This commit is contained in:
foreman
2014-07-04 16:17:05 -04:00
parent b0b5b33fcf
commit f80f2f233c
351 changed files with 113713 additions and 1 deletions
@@ -0,0 +1,88 @@
#ifndef __DXXOPENCLINTEROPEXT_H__
#define __DXXOPENCLINTEROPEXT_H__
// Abstract extension interface class
// Each extension interface (e.g. OpenCL Interop extension) will derive from this class
class IAmdDxExtInterface
{
public:
virtual unsigned int AddRef(void) = 0;
virtual unsigned int Release(void) = 0;
protected:
IAmdDxExtInterface() {};
virtual ~IAmdDxExtInterface() = 0 {};
};
// forward declaration for d3d specific interfaces
interface ID3D10Device;
interface ID3D11Device;
interface IDirect3DDevice9Ex;
interface ID3D10Resource;
interface ID3D11Resource;
interface IDirect3DSurface9;
// forward declaration of extended primitive topology enumeration
enum AmdDxExtPrimitiveTopology;
// Extension version information
struct AmdDxExtVersion
{
unsigned int majorVersion;
unsigned int minorVersion;
};
// This class serves as the main extension interface.
// AmdDxExtCreate returns a pointer to an instantiation of this interface.
// This object is used to retrieve extension version information
// and to get specific extension interfaces desired.
class IAmdDxExt : public IAmdDxExtInterface
{
public:
virtual HRESULT GetVersion(AmdDxExtVersion* pExtVer) = 0;
virtual IAmdDxExtInterface* GetExtInterface(unsigned int iface) = 0;
// General extensions
virtual HRESULT IaSetPrimitiveTopology(unsigned int topology) = 0;
virtual HRESULT IaGetPrimitiveTopology(AmdDxExtPrimitiveTopology* pExtTopology) = 0;
virtual HRESULT SetSingleSampleRead(ID3D10Resource* pResource, BOOL singleSample) = 0;
virtual HRESULT SetSingleSampleRead11(ID3D11Resource* pResource, BOOL singleSample) = 0;
virtual HRESULT SetSingleSampleRead9(IDirect3DSurface9* pResource, BOOL singleSample) = 0;
protected:
IAmdDxExt() {};
virtual ~IAmdDxExt() = 0 {};
};
// OpenCL Interop extension ID passed to IAmdDxExt::GetExtInterface()
const unsigned int AmdDxExtCLInteropID = 7;
// Abstract OpenCL Interop extension interface class
class IAmdDxExtCLInterop : public IAmdDxExtInterface
{
public:
virtual HRESULT QueryInteropGpuMask(UINT* gpuIdBitmask) = 0;
virtual HRESULT CLAcquireResource(ID3D10Resource* pResource, UINT* gpuIdBitmask) = 0;
virtual HRESULT CLReleaseResource(ID3D10Resource* pResource, UINT* gpuIdBitmask) = 0;
virtual HRESULT CLAcquireResource11(ID3D11Resource* pResource, UINT* gpuIdBitmask) = 0;
virtual HRESULT CLReleaseResource11(ID3D11Resource* pResource, UINT* gpuIdBitmask) = 0;
virtual HRESULT CLAcquireResource9(IDirect3DSurface9* pResource, UINT* gpuIdBitmask) = 0;
virtual HRESULT CLReleaseResource9(IDirect3DSurface9* pResource, UINT* gpuIdBitmask) = 0;
};
// Use GetProcAddress, etc. to retrieve exported functions
// The associated typedef provides a convenient way to define the function pointer
HRESULT __cdecl AmdDxExtCreate(ID3D10Device* pDevice, IAmdDxExt** ppExt);
typedef HRESULT (__cdecl *PFNAmdDxExtCreate)(ID3D10Device* pDevice, IAmdDxExt** ppExt);
HRESULT __cdecl AmdDxExtCreate11(ID3D11Device* pDevice, IAmdDxExt** ppExt);
typedef HRESULT (__cdecl *PFNAmdDxExtCreate11)(ID3D11Device* pDevice, IAmdDxExt** ppExt);
HRESULT __cdecl AmdDxExtCreate9(IDirect3DDevice9Ex* pDevice, IAmdDxExt** ppExt);
typedef HRESULT (__cdecl *PFNAmdDxExtCreate9)(IDirect3DDevice9Ex* pDevice, IAmdDxExt** ppExt);
#endif
@@ -0,0 +1,202 @@
#include "EventQueue.h"
#include "query/QueryObject.h"
#include "gsl_ctx.h"
EventQueue::EventQueue()
{
m_cs = NULL;
m_queueSize = c_staticQueueSize;
memset(m_queries,0,sizeof(m_queries));
memset(m_flushed,0,sizeof(m_flushed));
m_latestRetired = 0;
m_headId = m_queueSize - 1 ;
m_tail = 0;
}
EventQueue::~EventQueue()
{
for (unsigned int i = 0; i < c_staticQueueSize; i++)
{
assert(m_queries[i] == 0);
}
}
bool
EventQueue::open(gsCtx* cs, gslQueryTarget target, EQManagerConfig config, uint32 engineMask)
{
assert((config == EQManager_HIGH) || (config == EQManager_LOW));
setSlotCount((int) config);
assert((GpuEvent::InvalidID+1) % m_queueSize == 0);
m_cs = cs;
m_headId = m_queueSize - 1 ;
m_tail = 0;
m_latestRetired = 0;
m_target = target;
m_engineMask = engineMask;
for (unsigned int i = 0; i < m_queueSize; i++)
{
m_queries[i] = cs->createQuery(target);
}
return true;
}
void
EventQueue::close()
{
if (!m_cs) // the queue is unintialized.
{
return;
}
for (unsigned int i = 0; i < m_queueSize; i++)
{
m_cs->destroyQuery(m_queries[i]);
}
memset(m_queries, 0, sizeof(m_queries));
memset(m_flushed, 0, sizeof(m_flushed));
m_latestRetired = 0;
m_headId = m_queueSize - 1 ;
m_tail = 0;
m_cs = NULL;
}
void
EventQueue::begin()
{
const CALuint slot = m_headId % m_queueSize;
gslErrorCode ec = m_queries[slot]->BeginQuery(m_cs, m_target, 0, m_engineMask);
assert(ec == GSL_NO_ERROR);
m_flushed[slot] = false; // we've started a query, but it hasn't been checked yet...
}
uint32
EventQueue::end()
{
uint32 ret = m_headId;
const uint32 slot = m_headId % m_queueSize;
m_queries[slot]->EndQuery(m_cs, 0);
m_headId++;
m_tail++;
if (GpuEvent::InvalidID == m_headId)
{
// Flush on an event ID wrap around or when the Queue is going to wrap in
flush();
//roll numbers back to the beginning
m_latestRetired = 0;
m_headId = m_headId % m_queueSize;
m_tail = m_tail % m_queueSize;
}
return ret;
}
bool
EventQueue::isDone(uint32 event)
{
assert((event < GpuEvent::InvalidID) && "illegal event handle");
// if the event is older the the last known retired event we
// do not need to process it.
if (event <= m_latestRetired)
{
return true;
}
// if the event is older than the oldest event handle we have
// we synchronize with the oldest event.
if (event < m_tail)
{
return waitForEvent(m_tail, CAL_WAIT_LOW_CPU_UTILIZATION);
}
//
// If we've never called flush on the query object, go ahead flush the first time to ensure
// we never infinite loop
//
const uint32 slot = event % m_queueSize;
if (!m_flushed[slot])
{
flush();
}
//
// Since we're in between, we actually have to check to see if things are truely done
//
bool retVal = m_queries[slot]->IsResultAvailable(m_cs);
// cache the most recently retired event
if (retVal && (event < m_headId) && (event > m_latestRetired))
{
m_latestRetired = event;
}
return retVal;
}
bool
EventQueue::waitForEvent(uint32 event, uint32 waitType)
{
// if we already retired a younger event we don't to process current events
if (event <= m_latestRetired)
{
return true;
}
// if the event is older than the oldest event handle we have
// we synchronize with the oldest event
if (event < m_tail)
{
event = m_tail;
}
//
// If we've never called flush on the query object, go ahead flush the first time to ensure
// we never infinite loop
//
const uint32 slot = event % m_queueSize;
if (!m_flushed[slot])
{
flush();
}
uint64 param;
m_queries[slot]->GetResult(m_cs, &param, waitType);
// cache the most recently retired event
if ((event < m_headId) && (event > m_latestRetired))
{
m_latestRetired = event;
}
return (param != 0);
}
bool
EventQueue::flush()
{
m_cs->Flush(false, m_engineMask);
memset(m_flushed, 1, sizeof(m_flushed));
return true;
}
void
EventQueue::setSlotCount(uint32 slotCount)
{
if (slotCount < c_staticQueueSize)
{
m_queueSize = slotCount;
}
else
{
m_queueSize = c_staticQueueSize;
}
}
@@ -0,0 +1,57 @@
#ifndef __EventQueue_h__
#define __EventQueue_h__
#include "cal.h"
#include "backend.h"
#include "atitypes.h"
#include "gsl_types.h"
#include "gsl_config.h"
//#define USE_3D_SYNC 1
namespace gsl
{
class gsCtx;
};
enum EQManagerConfig
{
EQManager_HIGH = 512,
EQManager_LOW = 32
};
class EventQueue {
public:
static const unsigned int c_staticQueueSize = EQManager_HIGH;
EventQueue();
~EventQueue();
bool open(gsl::gsCtx* cs, gslQueryTarget target, EQManagerConfig config, uint32 engineMask = GSL_ENGINEMASK_ALL_BUT_UVD_VCE);
void close();
void begin();
uint32 end();
bool isDone(uint32 event);
bool waitForEvent(uint32 event, uint32 waitType);
bool flush();
private:
gsl::gsCtx* m_cs;
uint32 m_queueSize;
gslQueryTarget m_target;
uint32 m_engineMask; // EngineMask for this Query
uint32 m_tail; //represents the oldest event we have
uint32 m_headId;
uint32 m_latestRetired; //!< most recentyl retired event.
gslQueryObject m_queries[c_staticQueueSize];
bool m_flushed[c_staticQueueSize];
///////////////////////
// private functions //
///////////////////////
void setSlotCount(uint32 slotCount);
};
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,180 @@
#ifndef __GSLContext_h__
#define __GSLContext_h__
#include "atitypes.h"
#include "gsl_types.h"
#include "gsl_vid_if.h"
#include "cal.h"
#include "calcl.h"
#include "EventQueue.h"
#include "amuABI.h"
#define SC_INFO_CONSTANTBUFFER (147-128)
#define SC_SR_INIT_CONSTANTBUFFER 0
#define HW_R800_MAX_UAV 12
#define SC_R800_ARENA_UAV_SHORT_ID 9
#define SC_R800_ARENA_UAV_BYTE_ID 10
#define SC_R800_ARENA_UAV_DWORD_ID 11
class CALGSLDevice;
namespace gsl
{
class gsAdaptor;
};
class CALGSLContext
{
public:
CALGSLContext();
~CALGSLContext();
bool open(const CALGSLDevice* pDeviceObject, uint32 nEngines, gslEngineDescriptor *engines);
void close(gsl::gsAdaptor* native);
bool setInput(uint32 physUnit, gslMemObject mem);
bool setOutput(uint32 physUnit, gslMemObject mem);
bool setConstantBuffer(uint32 physUnit, gslMemObject mem, CALuint offset, size_t size);
bool setUAVBuffer(uint32 physUnit, gslMemObject mem, gslUAVType uavType);
void setUavMask(const CALUavMask& uavMask);
void setUAVChannelOrder(uint32 physUnit, gslMemObject mem);
void setProgram(gslProgramObject func);
bool runProgramGrid(GpuEvent& event, const ProgramGrid* pProgramGrid, const gslMemObject* mems, uint32 numMems);
bool runProgramVideoDecode(GpuEvent& event, gslMemObject mo, const CALprogramVideoDecode& decode);
void runAqlDispatch(GpuEvent& event, const void* aqlPacket, const gslMemObject* mems,
uint32 numMems, gslMemObject scratch, const void* cpuKernelCode, uint64 hsaQueueVA);
mcaddr virtualQueueDispatcherStart();
void virtualQueueDispatcherEnd(GpuEvent& event, const gslMemObject* mems, uint32 numMems, mcaddr signal, mcaddr loopStart);
void virtualQueueHandshake(GpuEvent& event, const gslMemObject mem, mcaddr parentState, uint32 newStateValue, mcaddr parentChildCounter, mcaddr signal);
bool isDone(GpuEvent* event);
void waitForEvent(GpuEvent* event);
void flushIOCaches() const;
void flushL1Cache() const;
void eventBegin(EngineType engId)
{
m_eventQueue[engId].begin();
const static bool Begin = true;
profileEvent(engId, Begin);
}
void eventEnd(EngineType engId, GpuEvent& event)
{
const static bool End = false;
profileEvent(engId, End);
event.id = m_eventQueue[engId].end();
event.engineId_ = engId;
}
gslProgramObject createProgramObject(uint32 type);
void destroyProgramObject(gslProgramObject func);
bool copyPartial(GpuEvent& event, gslMemObject srcMem, size_t* srcOffset,
gslMemObject destMem, size_t* destOffset, size_t* size, CALmemcopyflags flags, bool enableCopyRect);
void setSamplerParameter(uint32 sampler, gslTexParameterPname param, CALvoid* vals);
gslQueryObject createCounter(gslQueryTarget target) const;
void configPerformanceCounter(gslQueryObject counter, CALuint block, CALuint index, CALuint event) const;
void destroyCounter(gslQueryObject counter) const;
void beginCounter(gslQueryObject counter, gslQueryTarget target) const;
void endCounter(gslQueryObject counter, GpuEvent& event);
void getCounter(uint64* result, gslQueryObject counter) const;
gslMemObject createConstants(uint32 count) const;
void setConstants(gslMemObject constants) const;
void destroyConstants(gslMemObject constants) const;
bool recompileShader(CALimage srcImage, CALimage* newImage, const CALuint type);
bool getMachineType(CALuint* pMachine, CALuint* pType, CALimage image);
void getFuncInfo(gslProgramObject func, gslProgramTarget target, CALfuncInfo* pInfo);
bool openVideoSession(CALvideoProperties& properties);
void closeVideoSession(void);
void bindAtomicCounter(uint32 index, gslMemObject obj);
void syncAtomicCounter(GpuEvent& event, uint32 index, bool read);
void setGWSResource(uint32 index, uint32 value);
void createVCE(CALEncodeCreateVCE* pEncodeVCE, CALuint flags);
void destroyVCE(CALuint flags);
void getDeviceInfoVCE(CALuint *num_device, CALEncodeGetDeviceInfo* pEncodeDeviceInfo, CALuint flags);
void getNumberOfModesVCE(CALEncodeGetNumberOfModes* pEncodeNumberOfModes, CALuint flags);
void getModesVCE(CALuint device_id, CALuint NumEncodeModesToRetrieve, CALEncodeGetModes* pEncodeMode, CALuint flags);
void getDeviceCAPVCE(CALuint device_id, CALuint encode_cap_total_size, CALEncodeGetDeviceCAP *pEncodeCAP, CALuint flags);
void createEncodeSession(CALuint device_id, CALencodeMode encode_mode, CAL_VID_PROFILE_LEVEL encode_profile_level,
CAL_VID_PICTURE_FORMAT encode_formatm, CALuint encode_width, CALuint encode_height,
CALuint frameRateNum, CALuint frameRateDenom, CAL_VID_ENCODE_JOB_PRIORITY encode_priority_level);
void closeVideoEncodeSession(CALuint device_id);
void setState(CALEncodeSetState state, CALuint flags);
void getPictureConfig(CALEncodeGetPictureControlConfig *pPictureControlConfig, CALuint flags);
void getRateControlConfig(CALEncodeGetRateControlConfig *pRateControConfig, CALuint flags);
void getMotionEstimationConfig(CALEncodeGetMotionEstimationConfig *pMotionEstimationConfig, CALuint flags);
void getRDOConfig(CALEncodeGetRDOControlConfig *pRODConfig, CALuint flags);
void SendConfig(CALuint num_of_config_buffers, CAL_VID_CONFIG *pConfigBuffers, CALuint flags);
void EncodeePicture(GpuEvent& event, CALuint num_of_encode_task_input_buffer, CAL_VID_BUFFER_DESCRIPTION *encode_task_input_buffer_list, void *picture_parameter, CALuint *pTaskID, gslMemObject input_NV12_surface, CALuint flags);
void QueryTaskDescription(CALuint num_of_task_description_request, CALuint *num_of_task_description_return, CAL_VID_OUTPUT_DESCRIPTION *task_description_list, CALuint flags);
void ReleaseOutputResource(CALuint taskID, CALuint flags);
bool moduleLoad(CALimage image, gslProgramObject* func, gslMemObject* constants, CALUavMask* uavMask);
bool WaitSignal(gslMemObject mem, CALuint value);
bool WriteSignal(gslMemObject mem, CALuint value, CALuint64 offset);
bool MakeBuffersResident(CALuint numObjects, gslMemObject* pMemObjects, CALuint64* surfBusAddress, CALuint64* markerBusAddress);
gslQueryObject createThreadTrace(void) const;
void destroyThreadTrace(gslQueryObject) const;
gslShaderTraceBufferObject CreateThreadTraceBuffer(void) const;
void DestroyThreadTraceBuffer(gslShaderTraceBufferObject,uint32) const;
uint32 getThreadTraceQueryRes(gslQueryObject) const;
void configMemThreadTrace(gslShaderTraceBufferObject,gslMemObject,uint32,uint32) const;
void beginThreadTrace(gslQueryObject,gslQueryObject, gslQueryTarget,uint32,CALthreadTraceConfig&) const;
void endThreadTrace(gslQueryObject,uint32) const;
void pauseThreadTrace(uint32) const;
void resumeThreadTrace(uint32) const;
void writeTimer(bool sdma, const gslMemObject mem, uint32 offset) const;
void writeSurfRaw(GpuEvent& event, gslMemObject mem, size_t size, const void* data);
protected:
void setScratchBuffer(gslMemObject mem, int32 engineId);
virtual void profileEvent(EngineType engine, bool type) const {}
CALwaitType m_waitType; //!< Wait type
private:
enum {
MAX_OUTPUTS = 12,
MAX_CONSTANTBUFFERS = 20,
MAX_APICONSTANTBUFFERS = 16,
MAX_SAMPLERS = 16,
MAX_RESOURCES = 128,
MAX_SCRATCHBUFFERS = 1,
MAX_SHADERENGINES = 4,
MAX_UAVS = 1024,
};
const CALGSLDevice* m_Dev;
const CALGSLDevice* dev() const { return m_Dev; }
gsl::gsCtx* m_cs;
gslRenderState m_rs;
gslConstantBufferObject m_constantBuffers[MAX_CONSTANTBUFFERS];
gslUAVObject m_uavResources[MAX_UAVS];
gslTextureResourceObject m_textureResources[MAX_RESOURCES];
gslSamplerObject m_textureSamplers[MAX_SAMPLERS];
gslDrawBuffers m_drawBuffers;
gslFramebufferObject m_fb;
gslScratchBufferObject m_scratchBuffers;
EventQueue m_eventQueue[AllEngines];
bool m_allowDMA;
gslVidSession m_videoSession;
gslVideoContext m_videocontext;
gslVidSession m_EncodevideoSession;
};
#endif // __GSLContext_h__
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,229 @@
#ifndef __GSLDevice_h__
#define __GSLDevice_h__
#include "cal.h"
#include "calcl.h"
#include "atitypes.h"
#include "gsl_types.h"
#include "gsl_config.h"
#include "gsl_vid_if.h"
#include "thread/monitor.hpp"
#ifdef ATI_OS_LINUX
typedef unsigned int IDirect3DDevice9;
typedef unsigned int IDirect3DSurface9;
typedef unsigned int IDirect3DQuery9;
typedef unsigned int RECT;
#else
#undef APIENTRY
#include <d3d9.h>
#endif
#include <map>
namespace gsl
{
class gsAdaptor;
};
typedef enum
{
USE_NONE,
USE_CPDMA,
USE_DRMDMA,
USE_DRMDMA_L2T,
USE_DRMDMA_T2L,
} CopyType;
class CALGSLDevice
{
public:
struct GLResAssociate {
void* GLContext; //(IN) handle to HGLRC or GLXContext
void* GLdeviceContext; //(IN) a handle to device context
uint name; //(IN) gl identifier of the object
CALResGLBufferType type; // (IN) type of the interop object .
uint flags; // (IN) flags assigned to 'GLResource' struct
void* mbResHandle; // (OUT) Internal GL driver handle for the resource
gslMemObject mem_base; // (OUT) Base memory object for the resource
gslMemObject memObject; //(OUT) Alias gsl memory object for the resource
gslMemObject fMaskObject; //(OUT) gsl memobject of the an MSAA resource F-mask.
};
CALGSLDevice();
~CALGSLDevice();
bool open(uint32 gpuIndex, bool enableHighPerformanceState, bool reportAsOCL12Device);
void close();
gslMemObject resAlloc(const CALresourceDesc* desc) const;
bool resMapLocal(void*& pPtr, size_t& pitch, gslMemObject res, gslMapAccessType flags);
bool resUnmapLocal(gslMemObject res);
void resFree(gslMemObject mem) const;
bool resMapRemote(void*& pPtr, size_t& pitch, gslMemObject res, gslMapAccessType flags) const;
bool resUnmapRemote(gslMemObject res) const;
gslMemObject resGetHeap(size_t size) const;
gslMemObject resAllocView(gslMemObject res, gslResource3D size,
CALdomain offset, cmSurfFmt format, gslChannelOrder channelOrder,
gslMemObjectAttribType resType, uint32 level, uint32 layer,
uint32 flags, uint64 bytePitch = (uint64)-1) const;
bool associateD3D11Device(void* d3d11Device); //void* is of type ID3D11Device*
bool associateD3D10Device(void* d3d10Device); //void* is of type ID3D10Device*
bool associateD3D9Device(void* d3d9Device); //void* is of type IDirect3DDevice9*
gslMemObject resMapD3DResource(
const CALresourceDesc* desc, uint64 sharedhandle, bool displayable) const;
bool glAssociate(CALvoid *GLplatformContext, CALvoid* GLdeviceContext);
bool glDissociate(CALvoid *GLplatformContext, CALvoid* GLdeviceContext);
//! @brief This function is called once for every interop resource on the first clEnqeueuAcquireGL.
bool resGLAssociate(GLResAssociate & resData) const;
//! @brief This function is called once for every interop resource on resource destruction.
bool resGLFree (CALvoid* GLplatformContext,
CALvoid* GLdeviceContext, gslMemObject mem, gslMemObject mem_base,
CALvoid* mbResHandle, CALuint type) const;
//! @brief Decompresses depth/MSAA surfaces.This function is called on every 'clEnqeueuAcquireGLObject'.
bool resGLAcquire( CALvoid* GLplatformContext,CALvoid* mbResHandle, CALuint type) const;
//! @brief This function is called on every 'clEnqeueuReleaseGLObject'.
bool resGLRelease(CALvoid* GLplatformContext,CALvoid* mbResHandle) const;
gsl::gsAdaptor* getNative() const;
CALuint getElfMachine() const { return m_elfmachine; };
uint32 getGpuIndex() const { return m_gpuIndex; };
uint32 getMaxTextureSize() const;
const CALdeviceattribs& getAttribs() const { return m_attribs; }
const CALdeviceVideoAttribs& getVideoAttribs() const { return m_videoAttribs; }
const CALdevicestatus& getStatus() const {return m_deviceStatus; }
void getMemInfo(gslMemInfo* memInfo) const;
bool isVmMode() const { return m_vmMode; };
void closeNativeDisplayHandle();
uint32 getVPUCount();
void setVPUMask(uint32 mask);
uint32 getVPUMask() const { return m_vpuMask; }
bool uavInCB() const { return m_uavInCB; }
bool canDMA() const { return m_canDMA; }
gslMemObject m_srcDRMDMAMem, m_dstDRMDMAMem; // memory object of flush buffer, used for DRMDMA flush
void resCopy(gslMemObject srcRes, gslMemObject dstRes, uint32 flags) const;
void PerformAdapterInitialization() const;
void PerformFullInitialization() const;
void queryDeviceEngines(uint32* nEngines, gslEngineDescriptor* engines);
CopyType GetCopyType(gslMemObject srcMem, gslMemObject destMem, size_t* srcOffset,
size_t* destOffset, bool allowDMA, uint32 flags, uint64& surfaceSize,
size_t size, bool enableCopyRect) const;
uint32 calcScratchBufferSize(uint32 regNum) const;
amd::Monitor& gslDeviceOps() const { return *gslDeviceOps_; }
void fillImageHwState(gslMemObject mem, void* hwState, uint32 hwStateSize) const;
void fillSamplerHwState(bool unnorm, uint32 min, uint32 mag, uint32 addr, void* hwState, uint32 hwStateSize) const;
gslSamplerObject txSampler() const { return m_textureSampler; }
void convertInputChannelOrder(intp *channelOrder) const;
gsl::gsCtx* gslCtx() const { return m_cs; }
protected:
//
/// channel order enumerants
//
//channelSwizzleMode and channelSwizzle match the hwl equivalent hwtxSwizzleMode and hwtxUnitSwizzle in hwl_tx_if.h.
enum channelSwizzleMode {
SWIZZLE_COMPONENT0, ///< Select Component0
SWIZZLE_COMPONENT1, ///< Select Component1
SWIZZLE_COMPONENT2, ///< Select Component2
SWIZZLE_COMPONENT3, ///< Select Component3
SWIZZLE_ZERO, ///< Select Zero
SWIZZLE_ONE, ///< Select One
};
//
/// channel order swizzle type
//
typedef struct channelSwizzleRec
{
channelSwizzleMode r : 8; ///< Red channel of texture
channelSwizzleMode g : 8; ///< Green channel of texture
channelSwizzleMode b : 8; ///< Blue channel of texture
channelSwizzleMode a : 8; ///< Alpha channel of texture
} channelSwizzle;
private:
gsl::gsAdaptor* m_adp;
gsl::gsCtx* m_cs;
gslRenderState m_rs;
CALtarget m_target;
CALuint m_elfmachine;
uint32 m_revision;
uint32 m_vpuMask;
uint32 m_chainIndex;
int32 m_vpucount;
int32 m_maxtexturesize;
uint32 m_gpuIndex;
void* m_nativeDisplayHandle;
gslDeviceModeEnum m_deviceMode;
typedef std::map<gslMemObject, intp> Hack;
Hack m_hack;
gslQueryObject m_mapQuery;
gslQueryObject m_mapDMAQuery;
gslQueryObject m_mapUVDQuery;
gslQueryObject m_mapVCEQuery;
gslStaticRuntimeConfig m_scfg;
gslDynamicRuntimeConfig m_dcfg;
//GL Extension specific
void initGLInteropPrivateExt(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) const;
bool glCanInterop(CALvoid* GLplatformContext, CALvoid* GLdeviceContext);
bool PerformDMACopy(gslMemObject srcMem, gslMemObject destMem, cmSurfFmt format, CALuint flags);
void Initialize(void);
bool SetupAdapter(int32 &asic_id);
bool SetupContext(int32 &asic_id);
void PerformAdapterInitialization_int();
void PerformFullInitialization_int();
void getAttribs_int(gsl::gsCtx* cs);
void getVideoAttribs_int(gslVideoContext* vsHandle);
void getStatus_int(gsl::gsCtx* cs);
bool ResolveAperture(const gslMemObjectAttribTiling tiling) const;
CALdeviceattribs m_attribs;
CALdeviceVideoAttribs m_videoAttribs;
CALdevicestatus m_deviceStatus;
gslTextureResourceObject m_textureResource;
gslSamplerObject m_textureSampler;
union {
struct {
uint m_canDMA : 1;
uint m_allowDMA : 1;
uint m_computeRing : 1;
uint m_usePerVPUAdapterModel : 1;
uint m_PerformLazyDeviceInit : 1;
uint m_vmMode : 1;
uint m_uavInCB : 1;
};
};
amd::Monitor* gslDeviceOps_; //!< Lock to serialize GSL device
};
#endif // __GSLDevice_h__
@@ -0,0 +1,231 @@
#include "gsl_ctx.h"
#include "GSLDevice.h"
#if defined(ATI_OS_WIN)
#include <D3D10_1.h>
/**************************************************************************************************************
* Note: ideally the DXX extension interfaces should be mapped from the DXX perforce branch.
* This means CAL client spec will need to change to include headers directly from the DXX perforce tree.
* However, CAL only cares about the DXX OpenCL extension interface class. The spec cannot change
* without notification. So it is safe to use a local copy of the relevant DXX extension interface classes.
**************************************************************************************************************/
#include "DxxOpenCLInteropExt.h"
static bool
queryD3D10DeviceGPUMask(ID3D10Device* pd3d10Device, UINT* pd3d10DeviceGPUMask)
{
HMODULE hDLL = NULL;
IAmdDxExt* pExt = NULL;
IAmdDxExtCLInterop* pCLExt = NULL;
PFNAmdDxExtCreate AmdDxExtCreate;
HRESULT hr = S_OK;
// Get a handle to the DXX DLL with extension API support
#if defined _WIN64
static const CHAR dxxModuleName[13] = "atidxx64.dll";
#else
static const CHAR dxxModuleName[13] = "atidxx32.dll";
#endif
hDLL = GetModuleHandle(dxxModuleName);
if (hDLL == NULL)
{
hr = E_FAIL;
}
// Get the exported AmdDxExtCreate() function pointer
if (SUCCEEDED(hr))
{
AmdDxExtCreate = reinterpret_cast<PFNAmdDxExtCreate>(GetProcAddress(hDLL, "AmdDxExtCreate"));
if (AmdDxExtCreate == NULL)
{
hr = E_FAIL;
}
}
// Create the extension object
if (SUCCEEDED(hr))
{
hr = AmdDxExtCreate(pd3d10Device, &pExt);
}
// Get the extension version information
if (SUCCEEDED(hr))
{
AmdDxExtVersion extVersion;
hr = pExt->GetVersion(&extVersion);
if (extVersion.majorVersion == 0)
{
hr = E_FAIL;
}
}
// Get the OpenCL Interop interface
if (SUCCEEDED(hr))
{
pCLExt = static_cast<IAmdDxExtCLInterop*>(pExt->GetExtInterface(AmdDxExtCLInteropID));
if (pCLExt != NULL)
{
// Get the GPU mask using the CL Interop extension.
pCLExt->QueryInteropGpuMask(pd3d10DeviceGPUMask);
}
else
{
hr = E_FAIL;
}
}
if (pCLExt != NULL)
{
pCLExt->Release();
}
if (pExt != NULL)
{
pExt->Release();
}
return (SUCCEEDED(hr));
}
bool
CALGSLDevice::associateD3D10Device(void* d3d10Device)
{
bool canInteroperate = false;
LUID calDevAdapterLuid = {0, 0};
UINT calDevChainBitMask = 0;
UINT d3d10DeviceGPUMask = 0;
ID3D10Device* pd3d10Device = static_cast<ID3D10Device*>(d3d10Device);
IDXGIDevice* pDXGIDevice;
pd3d10Device->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);
IDXGIAdapter* pDXGIAdapter;
pDXGIDevice->GetAdapter(&pDXGIAdapter);
DXGI_ADAPTER_DESC adapterDesc;
pDXGIAdapter->GetDesc(&adapterDesc);
// match the adapter
if (m_adp->getMVPUinfo(&calDevAdapterLuid, &calDevChainBitMask))
{
canInteroperate = ((calDevAdapterLuid.HighPart == adapterDesc.AdapterLuid.HighPart) &&
(calDevAdapterLuid.LowPart == adapterDesc.AdapterLuid.LowPart));
}
// match the chain ID
if (canInteroperate)
{
if (queryD3D10DeviceGPUMask(pd3d10Device, &d3d10DeviceGPUMask))
{
canInteroperate = (calDevChainBitMask & d3d10DeviceGPUMask) != 0;
}
else
{
// special handling for Intel iGPU + AMD dGPU in LDA mode (only occurs on a PX platform) where
// the D3D10Device object is created on the Intel iGPU and passed to AMD dGPU (secondary) to interoperate.
if (calDevChainBitMask > 1)
{
canInteroperate = false;
}
}
}
pDXGIDevice->Release();
pDXGIAdapter->Release();
return canInteroperate;
}
gslMemObject
CALGSLDevice::resMapD3DResource(const CALresourceDesc* desc, uint64 sharedhandle, bool displayable) const
{
//! @note: GSL device isn't thread safe
amd::ScopedLock k(gslDeviceOps_);
gslMemObject mem = NULL;
gslMemObjectAttribs attribs(
GSL_MOA_TEXTURE_2D, // type
GSL_MOA_MEMORY_ALIAS, // location
GSL_MOA_TILING_TILED, // tiling
GSL_MOA_DISPLAYABLE_NO, // displayable
ATIGL_FALSE, // mipmap
1, // samples
0, // cpu_address
GSL_MOA_SIGNED_NO, // signed_format
GSL_MOA_FORMAT_DERIVED, // numFormat
DRIVER_MODULE_GLL, // module
GSL_ALLOCATION_INSTANCED // alloc_type
);
HANDLE h = (HANDLE)sharedhandle;
attribs.cpu_address = h;
attribs.alias_swizzle = 0;
attribs.channelOrder = desc->channelOrder;
attribs.type = desc->dimension;
switch (desc->dimension)
{
case GSL_MOA_BUFFER:
attribs.tiling = GSL_MOA_TILING_LINEAR;
mem = m_cs->createMemObject1D(desc->format, desc->size.width, &attribs);
break;
case GSL_MOA_TEXTURE_1D:
attribs.tiling = GSL_MOA_TILING_LINEAR;
mem = m_cs->createMemObject1D(desc->format, desc->size.width, &attribs);
break;
case GSL_MOA_TEXTURE_2D:
{
uint32 height = (uint32)desc->size.height;
if (displayable)
{
attribs.displayable = GSL_MOA_DISPLAYABLE_YES;
}
mem = m_cs->createMemObject2D(desc->format, desc->size.width, height, &attribs);
}
break;
case GSL_MOA_TEXTURE_3D:
mem = m_cs->createMemObject3D(desc->format, desc->size.width,
(uint32)desc->size.height, (uint32)desc->size.depth, &attribs);
break;
case GSL_MOA_TEXTURE_BUFFER:
attribs.type = GSL_MOA_TEXTURE_BUFFER;
mem = m_cs->createMemObject1D(desc->format, desc->size.width, &attribs);
break;
case GSL_MOA_TEXTURE_1D_ARRAY:
mem = m_cs->createMemObject3D(desc->format, desc->size.width,
1, (uint32)desc->size.height, &attribs);
break;
case GSL_MOA_TEXTURE_2D_ARRAY:
mem = m_cs->createMemObject3D(desc->format, desc->size.width,
(uint32)desc->size.height, (uint32)desc->size.depth, &attribs);
break;
default:
break;
}
return mem;
}
#else // !ATI_OS_WIN
bool
CALGSLDevice::associateD3D10Device(void* d3d10Device)
{
return false;
}
gslMemObject
CALGSLDevice::resMapD3DResource(const CALresourceDesc* desc, uint64 sharedhandle, bool displayable) const
{
return 0;
}
#endif // !ATI_OS_WIN
@@ -0,0 +1,154 @@
#include "gsl_ctx.h"
#include "GSLDevice.h"
#if defined(ATI_OS_WIN)
#include <D3D11.h>
/**************************************************************************************************************
* Note: ideally the DXX extension interfaces should be mapped from the DXX perforce branch.
* This means CAL client spec will need to change to include headers directly from the DXX perforce tree.
* However, CAL only cares about the DXX OpenCL extension interface class. The spec cannot change
* without notification. So it is safe to use a local copy of the relevant DXX extension interface classes.
**************************************************************************************************************/
#include "DxxOpenCLInteropExt.h"
static bool
queryD3D11DeviceGPUMask(ID3D11Device* pd3d11Device, UINT* pd3d11DeviceGPUMask)
{
HMODULE hDLL = NULL;
IAmdDxExt* pExt = NULL;
IAmdDxExtCLInterop* pCLExt = NULL;
PFNAmdDxExtCreate11 AmdDxExtCreate11;
HRESULT hr = S_OK;
// Get a handle to the DXX DLL with extension API support
#if defined _WIN64
static const CHAR dxxModuleName[13] = "atidxx64.dll";
#else
static const CHAR dxxModuleName[13] = "atidxx32.dll";
#endif
hDLL = GetModuleHandle(dxxModuleName);
if (hDLL == NULL)
{
hr = E_FAIL;
}
// Get the exported AmdDxExtCreate() function pointer
if (SUCCEEDED(hr))
{
AmdDxExtCreate11 = reinterpret_cast<PFNAmdDxExtCreate11>(GetProcAddress(hDLL, "AmdDxExtCreate11"));
if (AmdDxExtCreate11 == NULL)
{
hr = E_FAIL;
}
}
// Create the extension object
if (SUCCEEDED(hr))
{
hr = AmdDxExtCreate11(pd3d11Device, &pExt);
}
// Get the extension version information
if (SUCCEEDED(hr))
{
AmdDxExtVersion extVersion;
hr = pExt->GetVersion(&extVersion);
if (extVersion.majorVersion == 0)
{
hr = E_FAIL;
}
}
// Get the OpenCL Interop interface
if (SUCCEEDED(hr))
{
pCLExt = static_cast<IAmdDxExtCLInterop*>(pExt->GetExtInterface(AmdDxExtCLInteropID));
if (pCLExt != NULL)
{
// Get the GPU mask using the CL Interop extension.
pCLExt->QueryInteropGpuMask(pd3d11DeviceGPUMask);
}
else
{
hr = E_FAIL;
}
}
if (pCLExt != NULL)
{
pCLExt->Release();
}
if (pExt != NULL)
{
pExt->Release();
}
return (SUCCEEDED(hr));
}
bool
CALGSLDevice::associateD3D11Device(void* d3d11Device)
{
bool canInteroperate = false;
LUID calDevAdapterLuid = {0, 0};
UINT calDevChainBitMask = 0;
UINT d3d11DeviceGPUMask = 0;
ID3D11Device* pd3d11Device = static_cast<ID3D11Device*>(d3d11Device);
IDXGIDevice* pDXGIDevice;
pd3d11Device->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);
IDXGIAdapter* pDXGIAdapter;
pDXGIDevice->GetAdapter(&pDXGIAdapter);
DXGI_ADAPTER_DESC adapterDesc;
pDXGIAdapter->GetDesc(&adapterDesc);
// match the adapter
if (m_adp->getMVPUinfo(&calDevAdapterLuid, &calDevChainBitMask))
{
canInteroperate = ((calDevAdapterLuid.HighPart == adapterDesc.AdapterLuid.HighPart) &&
(calDevAdapterLuid.LowPart == adapterDesc.AdapterLuid.LowPart));
}
// match the chain ID
if (canInteroperate)
{
if (queryD3D11DeviceGPUMask(pd3d11Device, &d3d11DeviceGPUMask))
{
canInteroperate = (calDevChainBitMask & d3d11DeviceGPUMask) != 0;
}
else
{
// special handling for Intel iGPU + AMD dGPU in LDA mode (only occurs on a PX platform) where
// the D3D11Device object is created on the Intel iGPU and passed to AMD dGPU (secondary) to interoperate.
if (calDevChainBitMask > 1)
{
canInteroperate = false;
}
}
}
pDXGIDevice->Release();
pDXGIAdapter->Release();
return canInteroperate;
}
#else // !ATI_OS_WIN
bool
CALGSLDevice::associateD3D11Device(void* d3d11Device)
{
return false;
}
#endif // !ATI_OS_WIN
@@ -0,0 +1,56 @@
#include "gsl_ctx.h"
#include "GSLDevice.h"
#if defined(ATI_OS_WIN)
#include <d3d9.h>
#include <dxgi.h>
/**************************************************************************************************************
* Note: ideally the DXX extension interfaces should be mapped from the DXX perforce branch.
* This means CAL client spec will need to change to include headers directly from the DXX perforce tree.
* However, CAL only cares about the DXX OpenCL extension interface class. The spec cannot change
* without notification. So it is safe to use a local copy of the relevant DXX extension interface classes.
**************************************************************************************************************/
#include "DxxOpenCLInteropExt.h"
bool
CALGSLDevice::associateD3D9Device(void* d3d9Device)
{
bool canInteroperate = false;
D3DCAPS9 pCaps;
LUID calDevAdapterLuid = {0, 0};
UINT calDevChainBitMask = 0;
IDirect3D9* p3d9dev;
LUID d3d9deviceLuid = {0, 0};
IDirect3DDevice9* pd3d9Device = static_cast<IDirect3DDevice9*>(d3d9Device);
// Get D3D9 Device caps
pd3d9Device->GetDeviceCaps(&pCaps);
// Get 3D9 Device
pd3d9Device->GetDirect3D(&p3d9dev);
IDirect3D9Ex* p3d9devEx = static_cast<IDirect3D9Ex*>(p3d9dev);
p3d9devEx->GetAdapterLUID(pCaps.AdapterOrdinal, &d3d9deviceLuid);
// match the adapter
if (m_adp->getMVPUinfo(&calDevAdapterLuid, &calDevChainBitMask))
{
canInteroperate = ((calDevAdapterLuid.HighPart == d3d9deviceLuid.HighPart) &&
(calDevAdapterLuid.LowPart == d3d9deviceLuid.LowPart));
}
return canInteroperate;
}
#else // !ATI_OS_WIN
bool
CALGSLDevice::associateD3D9Device(void* d3dDevice)
{
return false;
}
#endif // !ATI_OS_WIN
@@ -0,0 +1,883 @@
#include "gsl_ctx.h"
#include "GSLDevice.h"
#include "component_types.h"
#include "cwddeci.h"
#include <GL/gl.h>
#include "GL/glATIInternal.h"
#ifdef ATI_OS_LINUX
#include <stdlib.h>
#include <dlfcn.h>
#include "GL/glx.h"
#include "GL/glxext.h"
#include "GL/glXATIPrivate.h"
#else
#include "GL/wglATIPrivate.h"
#endif
#include "memory/MemObject.h"
typedef struct cmFormatXlateRec{
cmSurfFmt raw_cmFormat;
cmSurfFmt cal_cmFormat;
gslChannelOrder channelOrder;
} cmFormatXlateParams;
// relates full range of cm surface formats to those supported by CAL
static const cmFormatXlateParams cmFormatXlateTable [] = {
{CM_SURF_FMT_LUMINANCE8, CM_SURF_FMT_R8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE16, CM_SURF_FMT_R16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE16F, CM_SURF_FMT_R16F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE32F, CM_SURF_FMT_R32F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_INTENSITY8, CM_SURF_FMT_INTENSITY8, GSL_CHANNEL_ORDER_REPLICATE_R},
{CM_SURF_FMT_INTENSITY16, CM_SURF_FMT_R16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_INTENSITY16F, CM_SURF_FMT_R16F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_INTENSITY32F, CM_SURF_FMT_R32F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_ALPHA8, CM_SURF_FMT_R8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_ALPHA16, CM_SURF_FMT_R16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_ALPHA16F, CM_SURF_FMT_R16F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_ALPHA32F, CM_SURF_FMT_R32F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE8_ALPHA8, CM_SURF_FMT_RG8I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_LUMINANCE16_ALPHA16, CM_SURF_FMT_RG16I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_LUMINANCE16F_ALPHA16F, CM_SURF_FMT_RG16F, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_LUMINANCE32F_ALPHA32F, CM_SURF_FMT_RG16F, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_B2_G3_R3, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_B5_G6_R5, CM_SURF_FMT_B5_G6_R5, GSL_CHANNEL_ORDER_RGB},
{CM_SURF_FMT_BGRX4, (cmSurfFmt)500, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGR5_X1, CM_SURF_FMT_BGR5_X1, GSL_CHANNEL_ORDER_RGB},
{CM_SURF_FMT_BGRX8, CM_SURF_FMT_RGBA8, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGR10_X2, CM_SURF_FMT_BGR10_X2, GSL_CHANNEL_ORDER_RGB},
{CM_SURF_FMT_BGRX16, CM_SURF_FMT_RGBA16, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGRX16F, CM_SURF_FMT_RGBA16F, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGRX32F, CM_SURF_FMT_RGBA32F, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_RGBX4, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGB5_X1, CM_SURF_FMT_BGR5_X1, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBX8, CM_SURF_FMT_RGBA8, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGB10_X2, CM_SURF_FMT_BGR10_X2, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBX16, CM_SURF_FMT_RGBA16, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBX16F, CM_SURF_FMT_RGBA16F, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBX32F, CM_SURF_FMT_RGBA32F, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_BGRA4, (cmSurfFmt)500, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGR5_A1, CM_SURF_FMT_BGR5_X1, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGRA8, CM_SURF_FMT_RGBA8, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGR10_A2, CM_SURF_FMT_BGR10_X2, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGRA16, CM_SURF_FMT_RGBA16, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGRA16F, CM_SURF_FMT_RGBA16, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_BGRA32F, CM_SURF_FMT_RGBA32F, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_RGBA4, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGB5_A1, CM_SURF_FMT_BGR5_X1, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBA8, CM_SURF_FMT_RGBA8, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGB10_A2, CM_SURF_FMT_BGR10_X2, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBA16, CM_SURF_FMT_RGBA16, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBA16F, CM_SURF_FMT_RGBA16F, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBA32I, CM_SURF_FMT_RGBA32I, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBA32F, CM_SURF_FMT_RGBA32F, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_DUDV8, CM_SURF_FMT_RG8I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_DXT1, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DXT2_3, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DXT4_5, (cmSurfFmt)00, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_ATI1N, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_ATI2N, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DEPTH16, CM_SURF_FMT_DEPTH16, GSL_CHANNEL_ORDER_REPLICATE_R},
{CM_SURF_FMT_DEPTH16F, CM_SURF_FMT_R16F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DEPTH24_X8, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DEPTH24F_X8, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DEPTH24_STEN8, CM_SURF_FMT_DEPTH24_STEN8, GSL_CHANNEL_ORDER_REPLICATE_R},
{CM_SURF_FMT_DEPTH24F_STEN8, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DEPTH32F_X24_STEN8, CM_SURF_FMT_RG32I, GSL_CHANNEL_ORDER_REPLICATE_R},
{CM_SURF_FMT_DEPTH32F, CM_SURF_FMT_R32F, GSL_CHANNEL_ORDER_REPLICATE_R},
{CM_SURF_FMT_sR11_sG11_sB10, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sU16, CM_SURF_FMT_sU16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sUV16, CM_SURF_FMT_sUV16, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sUVWQ16, CM_SURF_FMT_sUVWQ16, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RG16, CM_SURF_FMT_RG16, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_RG16F, CM_SURF_FMT_RG16F, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_RG32F, CM_SURF_FMT_RG32F, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_ABGR4, (cmSurfFmt)500, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_A1_BGR5, CM_SURF_FMT_BGR5_X1, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_ABGR8, CM_SURF_FMT_RGBA8, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_A2_BGR10, CM_SURF_FMT_BGR10_X2, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_ABGR16, CM_SURF_FMT_RGBA16, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_ABGR16F, CM_SURF_FMT_RGBA16F, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_ABGR32F, CM_SURF_FMT_RGBA32F, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_DXT1A, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sRGB10_A2, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_sR8, CM_SURF_FMT_sR8, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sRG8, CM_SURF_FMT_sRG8, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sR32I, CM_SURF_FMT_sR32I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sRG32I, CM_SURF_FMT_sRG32I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sRGBA32I, CM_SURF_FMT_sRGBA32I, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_R32I, CM_SURF_FMT_R32I, GSL_CHANNEL_ORDER_REPLICATE_R},
{CM_SURF_FMT_RG32I, CM_SURF_FMT_RG32I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_RG8, CM_SURF_FMT_RG8, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sRGBA8, CM_SURF_FMT_sRGBA8, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_R11F_G11F_B10F, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGB9_E5, CM_SURF_FMT_RGBA8, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_LUMINANCE_LATC1, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_SIGNED_LUMINANCE_LATC1,(cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_LUMINANCE_ALPHA_LATC2, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_SIGNED_LUMINANCE_ALPHA_LATC2, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RED_RGTC1, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_SIGNED_RED_RGTC1, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RED_GREEN_RGTC2, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_SIGNED_RED_GREEN_RGTC2,(cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_R8, CM_SURF_FMT_INTENSITY8, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_R16, CM_SURF_FMT_R16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_R16F, CM_SURF_FMT_R16F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_R32F, CM_SURF_FMT_R32F, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_R8I, CM_SURF_FMT_R8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sR8I, CM_SURF_FMT_sR8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_RG8I, CM_SURF_FMT_RG8I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sRG8I, CM_SURF_FMT_sRG8I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_R16I, CM_SURF_FMT_R16I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sR16I, CM_SURF_FMT_sR16I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_RG16I, CM_SURF_FMT_RG16I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sRG16I, CM_SURF_FMT_sRG16I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_RGBA32UI, CM_SURF_FMT_RGBA32UI, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBX32UI, CM_SURF_FMT_RGBA32UI, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_ALPHA32UI, CM_SURF_FMT_R32I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_INTENSITY32UI, CM_SURF_FMT_R32I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE32UI, CM_SURF_FMT_R32I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE_ALPHA32UI, CM_SURF_FMT_RG32I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_RGBA16UI, CM_SURF_FMT_RGBA16UI, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBX16UI, CM_SURF_FMT_RGBA16UI, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_ALPHA16UI, CM_SURF_FMT_R16I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_INTENSITY16UI, CM_SURF_FMT_R16I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE16UI, CM_SURF_FMT_R16I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE_ALPHA16UI, CM_SURF_FMT_R32I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_RGBA8UI, CM_SURF_FMT_RGBA8UI, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBX8UI, CM_SURF_FMT_RGBA8UI, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_ALPHA8UI, CM_SURF_FMT_R8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_INTENSITY8UI, CM_SURF_FMT_R8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE8UI, CM_SURF_FMT_R8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE_ALPHA8UI, CM_SURF_FMT_RG8I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sRGBA32I_EXT, CM_SURF_FMT_sRGBA32I, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_sRGBX32I, CM_SURF_FMT_sRGBA32I, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_sALPHA32I, CM_SURF_FMT_sR32I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sINTENSITY32I, CM_SURF_FMT_sR32I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sLUMINANCE32I, CM_SURF_FMT_sR32I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sLUMINANCE_ALPHA32I, CM_SURF_FMT_sRG32I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sRGBA16I, CM_SURF_FMT_sRGBA16I, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_sRGBX16I, CM_SURF_FMT_sRGBA16I, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_sALPHA16I, CM_SURF_FMT_sR16I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sINTENSITY16I, CM_SURF_FMT_sR16I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sLUMINANCE16I, CM_SURF_FMT_sR16I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sLUMINANCE_ALPHA16I, CM_SURF_FMT_sRG16I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sRGBA8I, CM_SURF_FMT_sRGBA8I, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_sRGBX8I, CM_SURF_FMT_sRGBA8I, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_sALPHA8I, CM_SURF_FMT_sR8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sINTENSITY8I, CM_SURF_FMT_sR8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sLUMINANCE8I, CM_SURF_FMT_sR8I, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_sLUMINANCE_ALPHA8I, CM_SURF_FMT_sRG8I, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_sDXT6, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DXT6, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_DXT7, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE8_SNORM, CM_SURF_FMT_sR8, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE16_SNORM, CM_SURF_FMT_sU16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_INTENSITY8_SNORM, CM_SURF_FMT_sR8, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_INTENSITY16_SNORM, CM_SURF_FMT_sU16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_ALPHA8_SNORM, CM_SURF_FMT_sR8, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_ALPHA16_SNORM, CM_SURF_FMT_sU16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_LUMINANCE_ALPHA8_SNORM,CM_SURF_FMT_sRG8, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_LUMINANCE_ALPHA16_SNORM,CM_SURF_FMT_sUV16, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_R8_SNORM, CM_SURF_FMT_sR8, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_R16_SNORM, CM_SURF_FMT_sU16, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_RG8_SNORM, CM_SURF_FMT_sRG8, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_RG16_SNORM, CM_SURF_FMT_sUV16, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_RGBX8_SNORM, CM_SURF_FMT_sRGBA8, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBX16_SNORM, CM_SURF_FMT_sUVWQ16, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBA8_SNORM, CM_SURF_FMT_sRGBA8, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBA16_SNORM, CM_SURF_FMT_sUVWQ16, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGB8_ETC2, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGB},
{CM_SURF_FMT_SRGB8_ETC2, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGB},
{CM_SURF_FMT_RGB8_PT_ALPHA1_ETC2, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_SRGB8_PT_ALPHA1_ETC2, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_RGBA8_ETC2_EAC, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_SRGB8_ALPHA8_ETC2_EAC, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_R11_EAC, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_SIGNED_R11_EAC, (cmSurfFmt)500, GSL_CHANNEL_ORDER_R},
{CM_SURF_FMT_RG11_EAC, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_SIGNED_RG11_EAC, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RG},
{CM_SURF_FMT_BGR10_A2UI, (cmSurfFmt)501, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_A2_BGR10UI, (cmSurfFmt)501, GSL_CHANNEL_ORDER_ARGB},
{CM_SURF_FMT_A2_RGB10UI, (cmSurfFmt)501, GSL_CHANNEL_ORDER_ABGR},
{CM_SURF_FMT_B5_G6_R5UI, (cmSurfFmt)500, GSL_CHANNEL_ORDER_BGRA},
{CM_SURF_FMT_R5_G6_B5UI, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_DEPTH32F_X24_STEN8_UNCLAMPED, CM_SURF_FMT_RG32I, GSL_CHANNEL_ORDER_REPLICATE_R},
{CM_SURF_FMT_DEPTH32F_UNCLAMPED, CM_SURF_FMT_R32F, GSL_CHANNEL_ORDER_REPLICATE_R},
{CM_SURF_FMT_L8_X16_A8_SRGB, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_L8_X24_SRGB, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA},
{CM_SURF_FMT_STENCIL8, CM_SURF_FMT_R8I, GSL_CHANNEL_ORDER_R},
};
FINLINE void
dummyAssertIfCmSurfFmtChanges(void)
{
//
// Assert if cmSurfFmt defined in ugl/src/include/cmndefs.h changes.
//
COMPILE_TIME_ASSERT(cmSurfFmt_FIRST == CM_SURF_FMT_LUMINANCE8);
COMPILE_TIME_ASSERT( 0 == CM_SURF_FMT_LUMINANCE8);
COMPILE_TIME_ASSERT( 1 == CM_SURF_FMT_LUMINANCE16);
COMPILE_TIME_ASSERT( 2 == CM_SURF_FMT_LUMINANCE16F);
COMPILE_TIME_ASSERT( 3 == CM_SURF_FMT_LUMINANCE32F);
COMPILE_TIME_ASSERT( 4 == CM_SURF_FMT_INTENSITY8);
COMPILE_TIME_ASSERT( 5 == CM_SURF_FMT_INTENSITY16);
COMPILE_TIME_ASSERT( 6 == CM_SURF_FMT_INTENSITY16F);
COMPILE_TIME_ASSERT( 7 == CM_SURF_FMT_INTENSITY32F);
COMPILE_TIME_ASSERT( 8 == CM_SURF_FMT_ALPHA8);
COMPILE_TIME_ASSERT( 9 == CM_SURF_FMT_ALPHA16);
COMPILE_TIME_ASSERT( 10 == CM_SURF_FMT_ALPHA16F);
COMPILE_TIME_ASSERT( 11 == CM_SURF_FMT_ALPHA32F);
COMPILE_TIME_ASSERT( 12 == CM_SURF_FMT_LUMINANCE8_ALPHA8);
COMPILE_TIME_ASSERT( 13 == CM_SURF_FMT_LUMINANCE16_ALPHA16);
COMPILE_TIME_ASSERT( 14 == CM_SURF_FMT_LUMINANCE16F_ALPHA16F);
COMPILE_TIME_ASSERT( 15 == CM_SURF_FMT_LUMINANCE32F_ALPHA32F);
COMPILE_TIME_ASSERT( 16 == CM_SURF_FMT_B2_G3_R3);
COMPILE_TIME_ASSERT( 17 == CM_SURF_FMT_B5_G6_R5);
COMPILE_TIME_ASSERT( 18 == CM_SURF_FMT_BGRX4);
COMPILE_TIME_ASSERT( 19 == CM_SURF_FMT_BGR5_X1);
COMPILE_TIME_ASSERT( 20 == CM_SURF_FMT_BGRX8);
COMPILE_TIME_ASSERT( 21 == CM_SURF_FMT_BGR10_X2);
COMPILE_TIME_ASSERT( 22 == CM_SURF_FMT_BGRX16);
COMPILE_TIME_ASSERT( 23 == CM_SURF_FMT_BGRX16F);
COMPILE_TIME_ASSERT( 24 == CM_SURF_FMT_BGRX32F);
COMPILE_TIME_ASSERT( 25 == CM_SURF_FMT_RGBX4);
COMPILE_TIME_ASSERT( 26 == CM_SURF_FMT_RGB5_X1);
COMPILE_TIME_ASSERT( 27 == CM_SURF_FMT_RGBX8);
COMPILE_TIME_ASSERT( 28 == CM_SURF_FMT_RGB10_X2);
COMPILE_TIME_ASSERT( 29 == CM_SURF_FMT_RGBX16);
COMPILE_TIME_ASSERT( 30 == CM_SURF_FMT_RGBX16F);
COMPILE_TIME_ASSERT( 31 == CM_SURF_FMT_RGBX32F);
COMPILE_TIME_ASSERT( 32 == CM_SURF_FMT_BGRA4);
COMPILE_TIME_ASSERT( 33 == CM_SURF_FMT_BGR5_A1);
COMPILE_TIME_ASSERT( 34 == CM_SURF_FMT_BGRA8);
COMPILE_TIME_ASSERT( 35 == CM_SURF_FMT_BGR10_A2);
COMPILE_TIME_ASSERT( 36 == CM_SURF_FMT_BGRA16);
COMPILE_TIME_ASSERT( 37 == CM_SURF_FMT_BGRA16F);
COMPILE_TIME_ASSERT( 38 == CM_SURF_FMT_BGRA32F);
COMPILE_TIME_ASSERT( 39 == CM_SURF_FMT_RGBA4);
COMPILE_TIME_ASSERT( 40 == CM_SURF_FMT_RGB5_A1);
COMPILE_TIME_ASSERT( 41 == CM_SURF_FMT_RGBA8);
COMPILE_TIME_ASSERT( 42 == CM_SURF_FMT_RGB10_A2);
COMPILE_TIME_ASSERT( 43 == CM_SURF_FMT_RGBA16);
COMPILE_TIME_ASSERT( 44 == CM_SURF_FMT_RGBA16F);
COMPILE_TIME_ASSERT( 45 == CM_SURF_FMT_RGBA32I);
COMPILE_TIME_ASSERT( 46 == CM_SURF_FMT_RGBA32F);
COMPILE_TIME_ASSERT( 47 == CM_SURF_FMT_DUDV8);
COMPILE_TIME_ASSERT( 48 == CM_SURF_FMT_DXT1);
COMPILE_TIME_ASSERT( 49 == CM_SURF_FMT_DXT2_3);
COMPILE_TIME_ASSERT( 50 == CM_SURF_FMT_DXT4_5);
COMPILE_TIME_ASSERT( 51 == CM_SURF_FMT_ATI1N);
COMPILE_TIME_ASSERT( 52 == CM_SURF_FMT_ATI2N);
COMPILE_TIME_ASSERT( 53 == CM_SURF_FMT_DEPTH16);
COMPILE_TIME_ASSERT( 54 == CM_SURF_FMT_DEPTH16F);
COMPILE_TIME_ASSERT( 55 == CM_SURF_FMT_DEPTH24_X8);
COMPILE_TIME_ASSERT( 56 == CM_SURF_FMT_DEPTH24F_X8);
COMPILE_TIME_ASSERT( 57 == CM_SURF_FMT_DEPTH24_STEN8);
COMPILE_TIME_ASSERT( 58 == CM_SURF_FMT_DEPTH24F_STEN8);
COMPILE_TIME_ASSERT( 59 == CM_SURF_FMT_DEPTH32F_X24_STEN8);
COMPILE_TIME_ASSERT( 60 == CM_SURF_FMT_DEPTH32F);
COMPILE_TIME_ASSERT( 61 == CM_SURF_FMT_sR11_sG11_sB10);
COMPILE_TIME_ASSERT( 62 == CM_SURF_FMT_sU16);
COMPILE_TIME_ASSERT( 63 == CM_SURF_FMT_sUV16);
COMPILE_TIME_ASSERT( 64 == CM_SURF_FMT_sUVWQ16);
COMPILE_TIME_ASSERT( 65 == CM_SURF_FMT_RG16);
COMPILE_TIME_ASSERT( 66 == CM_SURF_FMT_RG16F);
COMPILE_TIME_ASSERT( 67 == CM_SURF_FMT_RG32F);
COMPILE_TIME_ASSERT( 68 == CM_SURF_FMT_ABGR4);
COMPILE_TIME_ASSERT( 69 == CM_SURF_FMT_A1_BGR5);
COMPILE_TIME_ASSERT( 70 == CM_SURF_FMT_ABGR8);
COMPILE_TIME_ASSERT( 71 == CM_SURF_FMT_A2_BGR10);
COMPILE_TIME_ASSERT( 72 == CM_SURF_FMT_ABGR16);
COMPILE_TIME_ASSERT( 73 == CM_SURF_FMT_ABGR16F);
COMPILE_TIME_ASSERT( 74 == CM_SURF_FMT_ABGR32F);
COMPILE_TIME_ASSERT( 75 == CM_SURF_FMT_DXT1A);
COMPILE_TIME_ASSERT( 76 == CM_SURF_FMT_sRGB10_A2);
COMPILE_TIME_ASSERT( 77 == CM_SURF_FMT_sR8);
COMPILE_TIME_ASSERT( 78 == CM_SURF_FMT_sRG8);
COMPILE_TIME_ASSERT( 79 == CM_SURF_FMT_sR32I);
COMPILE_TIME_ASSERT( 80 == CM_SURF_FMT_sRG32I);
COMPILE_TIME_ASSERT( 81 == CM_SURF_FMT_sRGBA32I);
COMPILE_TIME_ASSERT( 82 == CM_SURF_FMT_R32I);
COMPILE_TIME_ASSERT( 83 == CM_SURF_FMT_RG32I);
COMPILE_TIME_ASSERT( 84 == CM_SURF_FMT_RG8);
COMPILE_TIME_ASSERT( 85 == CM_SURF_FMT_sRGBA8);
COMPILE_TIME_ASSERT( 86 == CM_SURF_FMT_R11F_G11F_B10F);
COMPILE_TIME_ASSERT( 87 == CM_SURF_FMT_RGB9_E5);
COMPILE_TIME_ASSERT( 88 == CM_SURF_FMT_LUMINANCE_LATC1);
COMPILE_TIME_ASSERT( 89 == CM_SURF_FMT_SIGNED_LUMINANCE_LATC1);
COMPILE_TIME_ASSERT( 90 == CM_SURF_FMT_LUMINANCE_ALPHA_LATC2);
COMPILE_TIME_ASSERT( 91 == CM_SURF_FMT_SIGNED_LUMINANCE_ALPHA_LATC2);
COMPILE_TIME_ASSERT( 92 == CM_SURF_FMT_RED_RGTC1);
COMPILE_TIME_ASSERT( 93 == CM_SURF_FMT_SIGNED_RED_RGTC1);
COMPILE_TIME_ASSERT( 94 == CM_SURF_FMT_RED_GREEN_RGTC2);
COMPILE_TIME_ASSERT( 95 == CM_SURF_FMT_SIGNED_RED_GREEN_RGTC2);
COMPILE_TIME_ASSERT( 96 == CM_SURF_FMT_R8);
COMPILE_TIME_ASSERT( 97 == CM_SURF_FMT_R16);
COMPILE_TIME_ASSERT( 98 == CM_SURF_FMT_R16F);
COMPILE_TIME_ASSERT( 99 == CM_SURF_FMT_R32F);
COMPILE_TIME_ASSERT(100 == CM_SURF_FMT_R8I);
COMPILE_TIME_ASSERT(101 == CM_SURF_FMT_sR8I);
COMPILE_TIME_ASSERT(102 == CM_SURF_FMT_RG8I);
COMPILE_TIME_ASSERT(103 == CM_SURF_FMT_sRG8I);
COMPILE_TIME_ASSERT(104 == CM_SURF_FMT_R16I);
COMPILE_TIME_ASSERT(105 == CM_SURF_FMT_sR16I);
COMPILE_TIME_ASSERT(106 == CM_SURF_FMT_RG16I);
COMPILE_TIME_ASSERT(107 == CM_SURF_FMT_sRG16I);
COMPILE_TIME_ASSERT(108 == CM_SURF_FMT_RGBA32UI);
COMPILE_TIME_ASSERT(109 == CM_SURF_FMT_RGBX32UI);
COMPILE_TIME_ASSERT(110 == CM_SURF_FMT_ALPHA32UI);
COMPILE_TIME_ASSERT(111 == CM_SURF_FMT_INTENSITY32UI);
COMPILE_TIME_ASSERT(112 == CM_SURF_FMT_LUMINANCE32UI);
COMPILE_TIME_ASSERT(113 == CM_SURF_FMT_LUMINANCE_ALPHA32UI);
COMPILE_TIME_ASSERT(114 == CM_SURF_FMT_RGBA16UI);
COMPILE_TIME_ASSERT(115 == CM_SURF_FMT_RGBX16UI);
COMPILE_TIME_ASSERT(116 == CM_SURF_FMT_ALPHA16UI);
COMPILE_TIME_ASSERT(117 == CM_SURF_FMT_INTENSITY16UI);
COMPILE_TIME_ASSERT(118 == CM_SURF_FMT_LUMINANCE16UI);
COMPILE_TIME_ASSERT(119 == CM_SURF_FMT_LUMINANCE_ALPHA16UI);
COMPILE_TIME_ASSERT(120 == CM_SURF_FMT_RGBA8UI);
COMPILE_TIME_ASSERT(121 == CM_SURF_FMT_RGBX8UI);
COMPILE_TIME_ASSERT(122 == CM_SURF_FMT_ALPHA8UI);
COMPILE_TIME_ASSERT(123 == CM_SURF_FMT_INTENSITY8UI);
COMPILE_TIME_ASSERT(124 == CM_SURF_FMT_LUMINANCE8UI);
COMPILE_TIME_ASSERT(125 == CM_SURF_FMT_LUMINANCE_ALPHA8UI);
COMPILE_TIME_ASSERT(126 == CM_SURF_FMT_sRGBA32I_EXT);
COMPILE_TIME_ASSERT(127 == CM_SURF_FMT_sRGBX32I);
COMPILE_TIME_ASSERT(128 == CM_SURF_FMT_sALPHA32I);
COMPILE_TIME_ASSERT(129 == CM_SURF_FMT_sINTENSITY32I);
COMPILE_TIME_ASSERT(130 == CM_SURF_FMT_sLUMINANCE32I);
COMPILE_TIME_ASSERT(131 == CM_SURF_FMT_sLUMINANCE_ALPHA32I);
COMPILE_TIME_ASSERT(132 == CM_SURF_FMT_sRGBA16I);
COMPILE_TIME_ASSERT(133 == CM_SURF_FMT_sRGBX16I);
COMPILE_TIME_ASSERT(134 == CM_SURF_FMT_sALPHA16I);
COMPILE_TIME_ASSERT(135 == CM_SURF_FMT_sINTENSITY16I);
COMPILE_TIME_ASSERT(136 == CM_SURF_FMT_sLUMINANCE16I);
COMPILE_TIME_ASSERT(137 == CM_SURF_FMT_sLUMINANCE_ALPHA16I);
COMPILE_TIME_ASSERT(138 == CM_SURF_FMT_sRGBA8I);
COMPILE_TIME_ASSERT(139 == CM_SURF_FMT_sRGBX8I);
COMPILE_TIME_ASSERT(140 == CM_SURF_FMT_sALPHA8I);
COMPILE_TIME_ASSERT(141 == CM_SURF_FMT_sINTENSITY8I);
COMPILE_TIME_ASSERT(142 == CM_SURF_FMT_sLUMINANCE8I);
COMPILE_TIME_ASSERT(143 == CM_SURF_FMT_sLUMINANCE_ALPHA8I);
COMPILE_TIME_ASSERT(144 == CM_SURF_FMT_sDXT6);
COMPILE_TIME_ASSERT(145 == CM_SURF_FMT_DXT6);
COMPILE_TIME_ASSERT(146 == CM_SURF_FMT_DXT7);
COMPILE_TIME_ASSERT(147 == CM_SURF_FMT_LUMINANCE8_SNORM);
COMPILE_TIME_ASSERT(148 == CM_SURF_FMT_LUMINANCE16_SNORM);
COMPILE_TIME_ASSERT(149 == CM_SURF_FMT_INTENSITY8_SNORM);
COMPILE_TIME_ASSERT(150 == CM_SURF_FMT_INTENSITY16_SNORM);
COMPILE_TIME_ASSERT(151 == CM_SURF_FMT_ALPHA8_SNORM);
COMPILE_TIME_ASSERT(152 == CM_SURF_FMT_ALPHA16_SNORM);
COMPILE_TIME_ASSERT(153 == CM_SURF_FMT_LUMINANCE_ALPHA8_SNORM);
COMPILE_TIME_ASSERT(154 == CM_SURF_FMT_LUMINANCE_ALPHA16_SNORM);
COMPILE_TIME_ASSERT(155 == CM_SURF_FMT_R8_SNORM);
COMPILE_TIME_ASSERT(156 == CM_SURF_FMT_R16_SNORM);
COMPILE_TIME_ASSERT(157 == CM_SURF_FMT_RG8_SNORM);
COMPILE_TIME_ASSERT(158 == CM_SURF_FMT_RG16_SNORM);
COMPILE_TIME_ASSERT(159 == CM_SURF_FMT_RGBX8_SNORM);
COMPILE_TIME_ASSERT(160 == CM_SURF_FMT_RGBX16_SNORM);
COMPILE_TIME_ASSERT(161 == CM_SURF_FMT_RGBA8_SNORM);
COMPILE_TIME_ASSERT(162 == CM_SURF_FMT_RGBA16_SNORM);
COMPILE_TIME_ASSERT(163 == CM_SURF_FMT_RGB10_A2UI);
COMPILE_TIME_ASSERT(164 == CM_SURF_FMT_RGB32F);
COMPILE_TIME_ASSERT(165 == CM_SURF_FMT_RGB32I);
COMPILE_TIME_ASSERT(166 == CM_SURF_FMT_RGB32UI);
COMPILE_TIME_ASSERT(167 == CM_SURF_FMT_RGBX8_SRGB);
COMPILE_TIME_ASSERT(168 == CM_SURF_FMT_RGBA8_SRGB);
COMPILE_TIME_ASSERT(169 == CM_SURF_FMT_DXT1_SRGB);
COMPILE_TIME_ASSERT(170 == CM_SURF_FMT_DXT1A_SRGB);
COMPILE_TIME_ASSERT(171 == CM_SURF_FMT_DXT2_3_SRGB);
COMPILE_TIME_ASSERT(172 == CM_SURF_FMT_DXT4_5_SRGB);
COMPILE_TIME_ASSERT(173 == CM_SURF_FMT_DXT7_SRGB);
COMPILE_TIME_ASSERT(174 == CM_SURF_FMT_RGB8_ETC2);
COMPILE_TIME_ASSERT(175 == CM_SURF_FMT_SRGB8_ETC2);
COMPILE_TIME_ASSERT(176 == CM_SURF_FMT_RGB8_PT_ALPHA1_ETC2);
COMPILE_TIME_ASSERT(177 == CM_SURF_FMT_SRGB8_PT_ALPHA1_ETC2);
COMPILE_TIME_ASSERT(178 == CM_SURF_FMT_RGBA8_ETC2_EAC);
COMPILE_TIME_ASSERT(179 == CM_SURF_FMT_SRGB8_ALPHA8_ETC2_EAC);
COMPILE_TIME_ASSERT(180 == CM_SURF_FMT_R11_EAC);
COMPILE_TIME_ASSERT(181 == CM_SURF_FMT_SIGNED_R11_EAC);
COMPILE_TIME_ASSERT(182 == CM_SURF_FMT_RG11_EAC);
COMPILE_TIME_ASSERT(183 == CM_SURF_FMT_SIGNED_RG11_EAC);
COMPILE_TIME_ASSERT(184 == CM_SURF_FMT_BGR10_A2UI);
COMPILE_TIME_ASSERT(185 == CM_SURF_FMT_A2_BGR10UI);
COMPILE_TIME_ASSERT(186 == CM_SURF_FMT_A2_RGB10UI);
COMPILE_TIME_ASSERT(187 == CM_SURF_FMT_B5_G6_R5UI);
COMPILE_TIME_ASSERT(188 == CM_SURF_FMT_R5_G6_B5UI);
COMPILE_TIME_ASSERT(189 == CM_SURF_FMT_DEPTH32F_X24_STEN8_UNCLAMPED);
COMPILE_TIME_ASSERT(190 == CM_SURF_FMT_DEPTH32F_UNCLAMPED);
COMPILE_TIME_ASSERT(191 == CM_SURF_FMT_L8_X16_A8_SRGB);
COMPILE_TIME_ASSERT(192 == CM_SURF_FMT_L8_X24_SRGB);
COMPILE_TIME_ASSERT(193 == CM_SURF_FMT_STENCIL8);
COMPILE_TIME_ASSERT(cmSurfFmt_LAST == CM_SURF_FMT_STENCIL8);
COMPILE_TIME_ASSERT(cmSurfFmt_LAST < 501);
}
#ifdef ATI_OS_LINUX
typedef void* (*PFNGlxGetProcAddress)(const GLubyte* procName);
static PFNGlxGetProcAddress pfnGlxGetProcAddress=NULL;
static PFNGLXBEGINCLINTEROPAMD glXBeginCLInteropAMD = NULL;
static PFNGLXENDCLINTEROPAMD glXEndCLInteropAMD = NULL;
static PFNGLXRESOURCEATTACHAMD glXResourceAttachAMD = NULL;
static PFNGLXRESOURCEDETACHAMD glxResourceAcquireAMD = NULL;
static PFNGLXRESOURCEDETACHAMD glxResourceReleaseAMD = NULL;
static PFNGLXRESOURCEDETACHAMD glXResourceDetachAMD = NULL;
static PFNGLXGETCONTEXTMVPUINFOAMD glXGetContextMVPUInfoAMD = NULL;
#else
static PFNWGLBEGINCLINTEROPAMD wglBeginCLInteropAMD = NULL;
static PFNWGLENDCLINTEROPAMD wglEndCLInteropAMD = NULL;
static PFNWGLRESOURCEATTACHAMD wglResourceAttachAMD = NULL;
static PFNWGLRESOURCEDETACHAMD wglResourceAcquireAMD = NULL;
static PFNWGLRESOURCEDETACHAMD wglResourceReleaseAMD = NULL;
static PFNWGLRESOURCEDETACHAMD wglResourceDetachAMD = NULL;
static PFNWGLGETCONTEXTGPUINFOAMD wglGetContextGPUInfoAMD = NULL;
#endif
void
CALGSLDevice::initGLInteropPrivateExt(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) const
{
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLplatformContext;
void * pModule = dlopen("libGL.so.1",RTLD_NOW);
if(NULL == pModule){
return;
}
pfnGlxGetProcAddress = (PFNGlxGetProcAddress) dlsym(pModule,"glXGetProcAddress");
if (NULL == pfnGlxGetProcAddress){
return;
}
if (!glXBeginCLInteropAMD || !glXEndCLInteropAMD || !glXResourceAttachAMD || !glXResourceDetachAMD || !glXGetContextMVPUInfoAMD)
{
glXBeginCLInteropAMD = (PFNGLXBEGINCLINTEROPAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXBeginCLInteroperabilityAMD");
glXEndCLInteropAMD = (PFNGLXENDCLINTEROPAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXEndCLInteroperabilityAMD");
glXResourceAttachAMD = (PFNGLXRESOURCEATTACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceAttachAMD");
glxResourceAcquireAMD = (PFNGLXRESOURCEDETACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceAcquireAMD");
glxResourceReleaseAMD = (PFNGLXRESOURCEDETACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceReleaseAMD");
glXResourceDetachAMD = (PFNGLXRESOURCEDETACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceDetachAMD");
glXGetContextMVPUInfoAMD = (PFNGLXGETCONTEXTMVPUINFOAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXGetContextMVPUInfoAMD");
}
#else
if (!wglBeginCLInteropAMD || !wglEndCLInteropAMD || !wglResourceAttachAMD || !wglResourceDetachAMD || !wglGetContextGPUInfoAMD)
{
HGLRC fakeRC = NULL;
if (!wglGetCurrentContext())
{
fakeRC = wglCreateContext((HDC)GLdeviceContext);
wglMakeCurrent((HDC)GLdeviceContext, fakeRC);
}
wglBeginCLInteropAMD = (PFNWGLBEGINCLINTEROPAMD) wglGetProcAddress ("wglBeginCLInteroperabilityAMD");
wglEndCLInteropAMD = (PFNWGLENDCLINTEROPAMD) wglGetProcAddress ("wglEndCLInteroperabilityAMD");
wglResourceAttachAMD = (PFNWGLRESOURCEATTACHAMD) wglGetProcAddress ("wglResourceAttachAMD");
wglResourceAcquireAMD = (PFNWGLRESOURCEDETACHAMD) wglGetProcAddress ("wglResourceAcquireAMD");
wglResourceReleaseAMD = (PFNWGLRESOURCEDETACHAMD) wglGetProcAddress ("wglResourceReleaseAMD");
wglResourceDetachAMD = (PFNWGLRESOURCEDETACHAMD) wglGetProcAddress ("wglResourceDetachAMD");
wglGetContextGPUInfoAMD = (PFNWGLGETCONTEXTGPUINFOAMD) wglGetProcAddress ("wglGetContextGPUInfoAMD");
if (fakeRC)
{
wglMakeCurrent(NULL, NULL);
wglDeleteContext(fakeRC);
}
}
#endif
}
bool
CALGSLDevice::glCanInterop(CALvoid* GLplatformContext, CALvoid* GLdeviceContext)
{
bool canInteroperate = false;
#ifdef ATI_OS_WIN
LUID glAdapterLuid = {0, 0};
UINT glChainBitMask = 0;
LUID calAdapterLuid = {0, 0};
UINT calChainBitMask = 0;
HGLRC hRC = (HGLRC)GLplatformContext;
//get GL context's LUID and chainBitMask from UGL
if (wglGetContextGPUInfoAMD && wglGetContextGPUInfoAMD(hRC, &glAdapterLuid, &glChainBitMask))
{
//now check against the CAL device' LUID and chainBitMask.
if (m_adp->getMVPUinfo(&calAdapterLuid, &calChainBitMask))
{
canInteroperate = ((glAdapterLuid.HighPart == calAdapterLuid.HighPart) &&
(glAdapterLuid.LowPart == calAdapterLuid.LowPart) &&
(glChainBitMask == calChainBitMask));
}
}
#elif defined (ATI_OS_LINUX)
//if the extension is supported by the base driver
if (NULL != glXGetContextMVPUInfoAMD)
{
GLuint glDeviceId = 0 ;
GLuint glChainMask = 0 ;
GLXContext ctx = (GLXContext)GLplatformContext;
if ( glXGetContextMVPUInfoAMD(ctx,&glDeviceId,&glChainMask)){
GLuint deviceId = 0 ;
GLuint chainMask = 0 ;
if (m_adp->getMVPUinfo(&deviceId, &chainMask))
{
// we allow intoperability only with GL context
// reside on a single GPU
if (deviceId == glDeviceId && chainMask == glChainMask){
canInteroperate = true;
}
}
}
}
#endif
return canInteroperate;
}
bool
CALGSLDevice::glAssociate(CALvoid* GLplatformContext, CALvoid* GLdeviceContext)
{
//initialize pointers to the gl extension that supports interoperability
initGLInteropPrivateExt(GLplatformContext, GLdeviceContext);
bool canInterop = glCanInterop(GLplatformContext, GLdeviceContext);
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLplatformContext;
if (canInterop && glXBeginCLInteropAMD && glXBeginCLInteropAMD(ctx, 0))
{
return true;
}
#else
HGLRC hRC = (HGLRC)GLplatformContext;
if (canInterop && wglBeginCLInteropAMD && wglBeginCLInteropAMD(hRC, 0))
{
return true;
}
#endif
return false;
}
bool
CALGSLDevice::glDissociate(CALvoid* GLplatformContext, CALvoid* GLdeviceContext)
{
initGLInteropPrivateExt(GLplatformContext, GLdeviceContext);
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLplatformContext;
if(glXEndCLInteropAMD && glXEndCLInteropAMD(ctx, 0))
{
return true;
}
#else
HGLRC hRC = (HGLRC)GLplatformContext;
if (wglEndCLInteropAMD && wglEndCLInteropAMD(hRC, 0))
{
return true;
}
#endif
return false;
}
bool
CALGSLDevice::resGLAssociate(GLResAssociate & resData) const
{
//! @note: GSL device isn't thread safe
amd::ScopedLock k(gslDeviceOps());
GLResource hRes = {0};
bool status = false;
cmSurfFmt cal_cmFormat;
uint32 depth;
gslMemObjectAttribs attribs(
GSL_MOA_TEXTURE_2D, // type
GSL_MOA_MEMORY_ALIAS, // location
GSL_MOA_TILING_TILED, // tiling
GSL_MOA_DISPLAYABLE_NO, // displayable
ATIGL_FALSE, // mipmap
1, // samples
0, // cpu_address
GSL_MOA_SIGNED_NO, // signed_format
GSL_MOA_FORMAT_DERIVED, // numFormat
DRIVER_MODULE_GLL, // module
GSL_ALLOCATION_INSTANCED // alloc_type
);
switch(resData.type)
{
case CAL_RES_GL_BUFFER_TYPE_TEXTURE:
hRes.type = GL_RESOURCE_ATTACH_TEXTURE_AMD;
break;
case CAL_RES_GL_BUFFER_TYPE_FRAMEBUFFER:
hRes.type = GL_RESOURCE_ATTACH_FRAMEBUFFER_AMD;
break;
case CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER:
hRes.type = GL_RESOURCE_ATTACH_RENDERBUFFER_AMD;
break;
case CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER:
hRes.type = GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD;
break;
default:
return false;
}
GLResourceData* hData = new GLResourceData;
if (NULL == hData)
{
return false;
}
memset(hData, 0, sizeof(GLResourceData));
hRes.name = resData.name;
hRes.flags = resData.flags;
hData->version = GL_RESOURCE_DATA_VERSION;
initGLInteropPrivateExt(resData.GLContext, resData.GLdeviceContext);
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)resData.GLContext;
if (glXResourceAttachAMD && glXResourceAttachAMD(ctx, &hRes, hData))
{
attribs.dynamicSharedBufferID = hData->sharedBufferID ;
status = true;
}
#else
HGLRC hRC = (HGLRC)resData.GLContext;
if (wglResourceAttachAMD && wglResourceAttachAMD(hRC, &hRes, hData))
{
status = true;
}
#endif
if (!status)
{
return false;
}
// for now, to be safe, allow only textures to have a depth other than 1
if (hRes.type == GL_RESOURCE_ATTACH_TEXTURE_AMD)
{
depth = hData->rawDimensions.depth;
}
else
{
depth = 1;
}
attribs.type = static_cast<gslMemObjectAttribType>(hData->objectAttribType);
osAssert(depth <= GLRDATA_MAX_LAYERS);
osAssert(depth >= 1);
attribs.alias_swizzles = (uint32*)malloc(depth * 2 * sizeof(uint32));
osAssert(attribs.alias_swizzles);
memcpy (attribs.alias_swizzles, hData->swizzles, sizeof(uint32) * depth);
if (hData->levels > 1)
{
attribs.mipmap = ATIGL_TRUE;
attribs.levels = static_cast<GLuint>(hData->levels);
memcpy (&attribs.alias_swizzles[depth], hData->swizzlesMip, sizeof(uint32) * depth);
}
attribs.cpu_address = (void*)hData->handle;
attribs.alias_subtile = hData->tilingMode;
attribs.mcaddress = hData->cardAddr;
// VBOs are hardcoded to have a UINT8 type format
if (hRes.type == GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD)
{
hData->format = CM_SURF_FMT_LUMINANCE8;
}
// CAL supports only a limited number of cm_surf formats, so we
// have to translate incoming cm_surf formats
uint32 index = hData->format - (uint32)CM_SURF_FMT_LUMINANCE8;
if (index >= sizeof(cmFormatXlateTable)/sizeof(cmFormatXlateParams))
{
free(attribs.alias_swizzles);
delete hData;
return false;
}
osAssert(static_cast<cmSurfFmt>(hData->format) == cmFormatXlateTable[index].raw_cmFormat);
cal_cmFormat = cmFormatXlateTable[index].cal_cmFormat;
if (cal_cmFormat == 500)
{
free(attribs.alias_swizzles);
delete hData;
return false; // format is not supported by CAL
}
attribs.channelOrder = cmFormatXlateTable[index].channelOrder;
attribs.alias_perSurfTileInfo = hData->perSurfTileInfo;
attribs.alias_GLInterop = ATIGL_TRUE;
attribs.numFormat = GSL_MOA_FORMAT_DERIVED;
gslMemObject mem;
if (hData->offset != 0)
{
osAssert((hData->rawDimensions.height == 1) && (depth == 1));
mem = m_cs->createMemObject2D(CM_SURF_FMT_LUMINANCE8, hData->surfaceSize, 1, &attribs);
}
else
{
mem = m_cs->createMemObject3D(cal_cmFormat, hData->paddedDimensions.width,
hData->rawDimensions.height, depth, &attribs);
}
if (hRes.type == GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD)
{
attribs.tiling = mem->getAttribs().tiling;
resData.mem_base = mem;
mem = m_cs->createOffsetMemObject2D(resData.mem_base, (static_cast<uintp>(hData->offset)),
cal_cmFormat,
hData->paddedDimensions.width,
1, &attribs);
}
else if ((hData->offset != 0) && (hData->rawDimensions.height == 1) && (depth == 1))
{
resData.mem_base = mem;
attribs.tiling = mem->getAttribs().tiling;
mem = m_cs->createOffsetMemObject3D(resData.mem_base, (static_cast<uintp>(hData->offset)),
cal_cmFormat, hData->paddedDimensions.width,
hData->rawDimensions.height, depth, &attribs);
}
free (attribs.alias_swizzles);
resData.mbResHandle = (CALvoid*)hData->mbResHandle;
resData.memObject = mem;
delete hData;
return mem != 0;
}
bool
CALGSLDevice::resGLAcquire(CALvoid* GLplatformContext,
CALvoid* mbResHandle,
CALuint type) const
{
//! @note: GSL device isn't thread safe
amd::ScopedLock k(gslDeviceOps());
GLResource hRes;
osAssert(mbResHandle);
hRes.mbResHandle = (GLuintp)mbResHandle;
switch(type)
{
case CAL_RES_GL_BUFFER_TYPE_TEXTURE:
hRes.type = GL_RESOURCE_ATTACH_TEXTURE_AMD;
break;
case CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER:
hRes.type = GL_RESOURCE_ATTACH_RENDERBUFFER_AMD;
break;
break;
default:
return false;
}
bool status = false;
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext) GLplatformContext;
if (glxResourceAcquireAMD && glxResourceAcquireAMD(ctx, &hRes))
{
status = true;
}
#else
HGLRC hRC = wglGetCurrentContext();
if ( wglResourceAcquireAMD && wglResourceAcquireAMD(hRC, &hRes))
{
status = true;
}
#endif
return status;
}
bool
CALGSLDevice::resGLRelease(CALvoid* GLplatformContext,
CALvoid* mbResHandle) const
{
//! @note: GSL device isn't thread safe
amd::ScopedLock k(gslDeviceOps());
GLResource hRes;
osAssert(mbResHandle);
bool status = false;
hRes.mbResHandle = (GLuintp)mbResHandle;
#ifdef ATI_OS_LINUX
//TODO : make sure the application GL context is current. if not no
// point calling into the GL RT.
GLXContext ctx = (GLXContext) GLplatformContext;
if ((0 != ctx) && glxResourceReleaseAMD && glxResourceReleaseAMD(ctx, &hRes))
{
status = true;
}
#else
//make the call into the GL driver only if the application GL context is current
HGLRC hRC = wglGetCurrentContext();
if ( (0 != hRC) && wglResourceReleaseAMD && wglResourceReleaseAMD(hRC, &hRes))
{
status = true;
}
#endif
return status;
}
bool
CALGSLDevice::resGLFree (
CALvoid* GLplatformContext,
CALvoid* GLdeviceContext,
gslMemObject mem,
gslMemObject mem_base,
CALvoid* mbResHandle,
CALuint type) const
{
//! @note: GSL device isn't thread safe
amd::ScopedLock k(gslDeviceOps());
GLResource hRes;
osAssert(mbResHandle);
hRes.mbResHandle = (GLuintp)mbResHandle;
switch(type)
{
case CAL_RES_GL_BUFFER_TYPE_TEXTURE:
hRes.type = GL_RESOURCE_ATTACH_TEXTURE_AMD;
break;
case CAL_RES_GL_BUFFER_TYPE_FRAMEBUFFER:
hRes.type = GL_RESOURCE_ATTACH_FRAMEBUFFER_AMD;
break;
case CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER:
hRes.type = GL_RESOURCE_ATTACH_RENDERBUFFER_AMD;
break;
case CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER:
hRes.type = GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD;
break;
default:
return false;
}
initGLInteropPrivateExt(GLplatformContext, GLdeviceContext);
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLplatformContext;
if (!glXResourceDetachAMD || !glXResourceDetachAMD(ctx, &hRes))
{
return true;
}
#else
HGLRC hRC = (HGLRC)GLplatformContext;
if (!wglResourceDetachAMD || !wglResourceDetachAMD(hRC, &hRes))
{
return false;
}
#endif
m_cs->Flush();
if (mem_base)
{
m_cs->destroyMemObject(mem_base);
}
m_cs->destroyMemObject(mem);
return true;
};
@@ -0,0 +1,9 @@
#include <X11/Xlib.h>
#include "GSLDevice.h"
#include <stdio.h>
void CALGSLDevice::closeNativeDisplayHandle()
{
//do nothing native handle should be close by lower layers
}
@@ -0,0 +1,9 @@
#include "gsl_ctx.h"
#include "GSLDevice.h"
#include <windows.h>
void CALGSLDevice::closeNativeDisplayHandle()
{
DeleteDC((HDC)m_nativeDisplayHandle);
m_nativeDisplayHandle = NULL;
}
@@ -0,0 +1,134 @@
#include "os_if.h"
#include "osws_if.h"
#include "atidefines.h"
#include "atitypes.h"
#include "scl_types.h"
#include "SCInterface.h"
//
// This file represents the entry points that are stubbed out to satisfy the
// linker, but aren't used in the runtime of GSL operations.
//
enum fsComponentType {
FS_BYTE,
FS_UNSIGNED_BYTE,
FS_SHORT,
FS_UNSIGNED_SHORT,
FS_INT,
FS_UNSIGNED_INT,
FS_FLOAT,
FS_FLOAT16,
};
enum fsInstrSet {
FS_INSTR_KHAN, ///< Generate Khan based instruction set
FS_INSTR_PELE ///< Generate Pele based instruction set
};
enum fsUsage {
FS_USAGE_HW, ///< An actual hardware stream
FS_USAGE_SW ///< A place holder stream (to support SW path)
};
struct fsInstr {
fsUsage usage; ///< How the stream is going to be used (place holder or actual hardware stream)
uint32 components; ///< Number of components to the input vector
fsComponentType type; ///< Type of each component
bool32 normalize; ///< Should the components be normalized to the -1..1 range
uint32 stride; ///< Stride between vectors
uint32 ivmOffset; ///< location in input vector memory
};
sclHandle CONV
sclInit(const sclShaderConstantAddress* shaderStateConstTable,
const sclProfile& profile,
const sclLimits& fpLimits,
const sclLimits& vpLimits)
{
return 0;
}
void CONV
sclDestroy(sclHandle hSCL)
{
}
sclProgram* CONV
sclCompile(sclHandle hSCL,
const sclInputShader& shader,
const sclCompilerParams& params,
const sclLimits& limits)
{
return 0;
}
sclProgramPair* CONV
sclLink(sclHandle hSCL,
const sclInputMultShaderPair *shader,
const sclCompilerParams& params,
const sclLimits& fpLimits,
const sclLimits& vpLimits)
{
return 0;
}
void CONV
sclFreeProgram(sclHandle hSCL,
sclProgram* program)
{
}
sclShaderReplaceHandle CONV
sclRegisterShaderString(sclHandle hSCL,
const sclInputShader& src,
const sclInputShader& dst)
{
return 0;
}
void CONV
sclUnregisterShaderString(sclHandle hSCL,
sclShaderReplaceHandle hReplacement)
{
}
bool32 CONV
fsCompile(fsInstrSet instrSet,
uint32 instrCount,
const fsInstr* instr,
void*& binary,
uint32& length,
bool32 dumpShader,
bool32 doCacheOpt,
const sclCompilerParamTessellation& tessParams)
{
return ATIGL_TRUE;
}
void CONV
fsFreeBinary(void* binary)
{
}
void CONV
oswsInit(HOSInstance hOSInst)
{
//
// do nothing...
//
}
void CONV
oswsExit()
{
//
// do nothing...
//
}
@@ -0,0 +1,206 @@
#include "gsl_ctx.h"
#include "GSLContext.h"
#include "backend.h"
#include "GSLDevice.h"
#include "os_if.h"
#include <stdlib.h>
#ifdef ATI_OS_LINUX
#include <X11/Xlib.h>
#endif
#include "amuABI.h"
bool
getFuncInfoFromImage(CALimage image, CALfuncInfo *pFuncInfo)
{
if (image == 0)
{
return false;
}
if (pFuncInfo == 0)
{
return false;
}
//Initialize the pFuncInfo
pFuncInfo->maxScratchRegsNeeded = 0;
pFuncInfo->numSharedGPRUser = 0;
pFuncInfo->numSharedGPRTotal = 0;
pFuncInfo->eCsSetupMode = false;
pFuncInfo->numThreadPerGroup = 0;
pFuncInfo->numThreadPerGroupX = 0;
pFuncInfo->numThreadPerGroupY = 0;
pFuncInfo->numThreadPerGroupZ = 0;
pFuncInfo->totalNumThreadGroup = 0;
pFuncInfo->numWavefrontPerSIMD = 0;
pFuncInfo->isMaxNumWavePerSIMD = false;
pFuncInfo->setBufferForNumGroup = false;
pFuncInfo->wavefrontSize = 0;
pFuncInfo->numGPRsAvailable = 0;
pFuncInfo->numGPRsUsed = 0;
pFuncInfo->numSGPRsAvailable = 0;
pFuncInfo->numSGPRsUsed = 0;
pFuncInfo->numVGPRsAvailable = 0;
pFuncInfo->numVGPRsUsed = 0;
pFuncInfo->LDSSizeAvailable = 0;
pFuncInfo->LDSSizeUsed = 0;
pFuncInfo->stackSizeAvailable = 0;
pFuncInfo->stackSizeUsed = 0;
//read data from image file
AMUabiMultiBinary mb;
amuABIMultiBinaryCreate(&mb);
if (!amuABIMultiBinaryUnpack(mb, (void*) image))
{
amuABIMultiBinaryDestroy(mb);
return false;
}
unsigned int encodingCount;
if (!amuABIMultiBinaryGetEncodingCount(&encodingCount, mb))
{
amuABIMultiBinaryDestroy(mb);
return false;
}
AMUabiEncoding encoding;
//get encoding info for the first encoding
if ((encodingCount > 0)&& !amuABIMultiBinaryGetEncoding( &encoding, mb, 0))
{
amuABIMultiBinaryDestroy(mb);
return false;
}
unsigned int machine, type;
if (!amuABIEncodingGetSignature(&machine, &type, encoding))
{
amuABIMultiBinaryDestroy(mb);
return false;
}
if (!amuABIMultiBinaryFindEncoding(&encoding, mb, machine, type))
{
amuABIMultiBinaryDestroy(mb);
return false;
}
unsigned int progInfosCount = 0;
CALProgramInfoEntry* pInfos = 0;
if (!amuABIEncodingGetProgInfos(&progInfosCount, &pInfos, encoding))
{
amuABIMultiBinaryDestroy(mb);
return false;
}
for (CALuint i =0; i < progInfosCount; i++)
{
switch(pInfos[i].address)
{
case AMU_ABI_CS_MAX_SCRATCH_REGS:
pFuncInfo->maxScratchRegsNeeded = pInfos[i].value;
break;
case AMU_ABI_CS_NUM_SHARED_GPR_USER:
pFuncInfo->numSharedGPRUser = pInfos[i].value;
break;
case AMU_ABI_CS_NUM_SHARED_GPR_TOTAL:
pFuncInfo->numSharedGPRTotal = pInfos[i].value;
break;
case AMU_ABI_ECS_SETUP_MODE:
pFuncInfo->eCsSetupMode = (0 != pInfos[i].value) ? true : false;
break;
case AMU_ABI_NUM_THREAD_PER_GROUP:
pFuncInfo->numThreadPerGroup = pInfos[i].value;
break;
case AMU_ABI_NUM_THREAD_PER_GROUP_X:
pFuncInfo->numThreadPerGroupX = pInfos[i].value;
break;
case AMU_ABI_NUM_THREAD_PER_GROUP_Y:
pFuncInfo->numThreadPerGroupY = pInfos[i].value;
break;
case AMU_ABI_NUM_THREAD_PER_GROUP_Z:
pFuncInfo->numThreadPerGroupZ = pInfos[i].value;
break;
case AMU_ABI_TOTAL_NUM_THREAD_GROUP:
pFuncInfo->totalNumThreadGroup = pInfos[i].value;
break;
case AMU_ABI_NUM_WAVEFRONT_PER_SIMD:
case AMU_ABI_MAX_WAVEFRONT_PER_SIMD: //CAL_USE_SC_PRM
pFuncInfo->numWavefrontPerSIMD = pInfos[i].value;
break;
case AMU_ABI_IS_MAX_NUM_WAVE_PER_SIMD:
pFuncInfo->isMaxNumWavePerSIMD = (0 != pInfos[i].value) ? true : false;
break;
case AMU_ABI_SET_BUFFER_FOR_NUM_GROUP:
pFuncInfo->setBufferForNumGroup = (0 != pInfos[i].value) ? true : false;
break;
case AMU_ABI_WAVEFRONT_SIZE:
pFuncInfo->wavefrontSize = pInfos[i].value;
break;
case AMU_ABI_NUM_GPR_AVAIL:
pFuncInfo->numGPRsAvailable = pInfos[i].value;
break;
case AMU_ABI_NUM_GPR_USED:
pFuncInfo->numGPRsUsed = pInfos[i].value;
break;
case AMU_ABI_LDS_SIZE_AVAIL:
pFuncInfo->LDSSizeAvailable = pInfos[i].value;
break;
case AMU_ABI_LDS_SIZE_USED:
pFuncInfo->LDSSizeUsed = pInfos[i].value;
break;
case AMU_ABI_STACK_SIZE_AVAIL:
pFuncInfo->stackSizeAvailable = pInfos[i].value;
break;
case AMU_ABI_STACK_SIZE_USED:
pFuncInfo->stackSizeUsed = pInfos[i].value;
break;
case AMU_ABI_SI_NUM_SGPRS_AVAIL:
pFuncInfo->numSGPRsAvailable = pInfos[i].value;
break;
case AMU_ABI_SI_NUM_SGPRS:
pFuncInfo->numSGPRsUsed = pInfos[i].value;
break;
case AMU_ABI_SI_NUM_VGPRS_AVAIL:
pFuncInfo->numVGPRsAvailable = pInfos[i].value;
break;
case AMU_ABI_SI_NUM_VGPRS:
pFuncInfo->numVGPRsUsed = pInfos[i].value;
break;
default:
//GSLAssert(0 && "Unknown address in program info");
break;
}
}
amuABIEncodingGetScratchRegisterCount(&pFuncInfo->maxScratchRegsNeeded, encoding);
amuABIMultiBinaryDestroy(mb);
return true;
}
gslMemObjectAttribTiling g_CALBETiling_Tiled = GSL_MOA_TILING_TILED;
void
calInit(void)
{
gslInit(); // initialize GSL
}
void
calShutdown(void)
{
gslExit();
}
uint32
calGetDeviceCount()
{
return gsAdaptor::enumerateAdaptors();
}
@@ -0,0 +1,54 @@
#ifndef __BACKEND_H__
#define __BACKEND_H__
#include "cal.h"
#include "calcl.h"
//internal
#include <vector>
#include <cassert>
class CALGSLDevice;
//! Engine types
enum EngineType
{
MainEngine = 0,
SdmaEngine,
AllEngines
};
struct GpuEvent
{
static const unsigned int InvalidID = ((1<<30) - 1);
EngineType engineId_; ///< type of the id
unsigned int id; ///< actual event id
//! GPU event default constructor
GpuEvent(): engineId_(MainEngine), id(InvalidID) {}
//! Returns true if the current event is valid
bool isValid() const { return (id != InvalidID) ? true : false; }
//! Set invalid event id
void invalidate() { id = InvalidID; }
};
typedef enum CALBEtilingEnum
{
CALBE_TILING_DEFAULT,
CALBE_TILING_LINEAR,
CALBE_TILING_TILED,
CALBEtiling_FIRST = CALBE_TILING_DEFAULT,
CALBEtiling_LAST = CALBE_TILING_TILED,
} CALBEtiling;
/*
* GPU Backend functions
*/
void calInit(void);
void calShutdown(void);
uint32 calGetDeviceCount();
#endif
@@ -0,0 +1,95 @@
#include "inifile.h"
#include "ini_export.h"
#include "ini_values.h"
#include "gsl_enum.h"
extern gslMemObjectAttribTiling g_CALBETiling_Tiled;
void
getConfigFromFile(gslStaticRuntimeConfig& scfg,
gslDynamicRuntimeConfig& dcfg)
{
const char* calIniFile = getenv("CAL_INI_FILE");
IniFile iniFile(cmString(calIniFile ? calIniFile : INI_FILE));
CALboolean dumpIL = CAL_FALSE;
CALboolean dumpISA = CAL_FALSE;
CALboolean macro = CAL_TRUE;
CALboolean micro = CAL_TRUE;
CALboolean breakonload = CAL_FALSE;
CALint useRectPrim = 0;
CALboolean forceRemoteMemory = CAL_FALSE;
CALboolean disableAsyncDma = CAL_FALSE;
CALboolean disableVM = CAL_FALSE;
dcfg.bEmulator.hasValue = ATIGL_TRUE;
dcfg.DropFlush.hasValue = ATIGL_TRUE;
dcfg.EnableCommandbufferDump.hasValue = ATIGL_TRUE;
dcfg.WaitForIdleAfterSubmit.hasValue = ATIGL_TRUE;
dcfg.FlushAfterRender.hasValue = ATIGL_TRUE;
dcfg.nPatchDumpLevel.hasValue = ATIGL_TRUE;
cmString commandbufferDumpFilename;
iniFile.getValue(section, CAL_EMULATOR, (CALboolean*) &dcfg.bEmulator.value);
iniFile.getValue(section, CAL_ENABLE_FORCE_ASIC_ID, (CALboolean*) &dcfg.forceAsicID.hasValue);
iniFile.getValue(section, CAL_FORCE_ASIC_ID, (CALint*) &dcfg.forceAsicID.value);
iniFile.getValue(section, CAL_DROPFLUSH, (CALboolean*) &dcfg.DropFlush.value);
iniFile.getValue(section, CAL_ENABLEPACKETDUMP, (CALboolean*) &dcfg.EnableCommandbufferDump.value);
// Check if location string is longer than 128 then assign, if not default location will be C:\packet.txt in gsl_ctx.cpp: gsCtxManager::PacketDump()
uintp length = commandbufferDumpFilename.length();
if (length > 0 && length < sizeof(dcfg.CommandbufferDumpFilename))
strcpy(dcfg.CommandbufferDumpFilename, commandbufferDumpFilename.c_str());
iniFile.getValue(section, CAL_ENABLEPATCHDUMP, (CALint*) &dcfg.nPatchDumpLevel.value);
iniFile.getValue(section, CAL_ENABLEMACROTILE, (CALboolean*) &macro);
iniFile.getValue(section, CAL_ENABLEMICROTILE, (CALboolean*) &micro);
iniFile.getValue(section, CAL_BREAK_ON_LOAD, (CALboolean*) &breakonload);
iniFile.getValue(section, CAL_FORCE_REMOTE_MEMORY, (CALboolean*) &forceRemoteMemory);
iniFile.getValue(section, CAL_DISABLE_ASYNC_DMA, (CALboolean*) &disableAsyncDma);
iniFile.getValue(section, CAL_WAITFORIDLEAFTERSUBMIT, (CALboolean*) &dcfg.WaitForIdleAfterSubmit.value);
iniFile.getValue(section, CAL_ENABLE_DUMP_IL, (CALboolean*) &dumpIL);
iniFile.getValue(section, CAL_ENABLE_DUMP_ISA, (CALboolean*) &dumpISA);
iniFile.getValue(section, CAL_ENABLE_FLUSH_AFTER_RENDER, (CALboolean*) &dcfg.FlushAfterRender.value);
iniFile.getValue(section, CAL_DISABLE_VM, (CALboolean*) &disableVM);
if (disableVM)
{
scfg.VMMode = GSL_CONFIG_VM_MODE_FORCE_OFF;
}
if (!macro && !micro)
{
g_CALBETiling_Tiled = GSL_MOA_TILING_LINEAR;
}
if (breakonload)
{
#ifndef ATI_OS_LINUX
__debugbreak();
#endif
}
switch (forceRemoteMemory)
{
case 1:
//
// Also set linear, due to CAL expectations about different memory regions
//
g_CALBETiling_Tiled = GSL_MOA_TILING_LINEAR;
break;
default:
break;
}
if (disableAsyncDma)
{
dcfg.drmdmaMode.hasValue = ATIGL_TRUE;
dcfg.drmdmaMode.value = GSL_CONFIG_DRMDMA_MODE_FORCE_OFF;
}
}
@@ -0,0 +1,13 @@
#ifndef __INI_EXPORT_H__
#define __INI_EXPORT_H__
#include "gsl_config.h"
void
getConfigFromFile(gslStaticRuntimeConfig& scfg,
gslDynamicRuntimeConfig& dcfg);
#endif
@@ -0,0 +1,334 @@
#ifndef __INI_VALUES_H__
#define __INI_VALUES_H__
#include "cm_string.h"
const cmString section("CAL");
const cmString INI_FILE("cal.ini");
/* VSYNC COMMENTS
0 - always off
1 - app preference (default off)
2 - app preference (default on)
3 - always on
*/
const cmString CAL_OGLWAITVERTICALSYNC("VSyncControl");
// Private panel setting for V-sync control
const cmString CAL_ENABLETEARFREESWAP("VSyncControl");
// Public panel setting to set max anisotropy: 0=app pref, 2=2x, 4=4x, 8=8x, 16=16x
const cmString CAL_OGLMAXANISOTROPY("MaxAnisotropy");
// Public panel setting to select performance Aniso
const cmString CAL_OGLANISOPERF("AnisoPerf");
// Public panel setting to select quality mode
const cmString CAL_OGLANISOQUAL("AnisoQuality");
// Public panel setting
const cmString CAL_OGLANISOTYPE("AnisoType");
// Private panel
const cmString CAL_ENABLEANISOTROPICFILTERING("AnisoFiltering");
// Public panel setting
const cmString CAL_OGLALIASSLIDER("AnisoDegree");
// Public panel setting for LOD bias; ranges from 0(high quality) to 3(high performance);
const cmString CAL_OGLLODBIAS("TextureLod");
// Public panel setting to force Z buffer depth
const cmString CAL_OGLFORCEZBUFFERDEPTH("ForceZBufferDepth");
// Public panel setting to select alpha dither method
const cmString CAL_OGLALPHADITHERMETHOD("DitherAlpha");
// Private Panel Setting for setting multisample value for FSAA
const cmString CAL_MULTISAMPLE("Multisample");
// Public Panel setting for forcing AA
const cmString CAL_ACE_OGLENABLEFSAA("AntiAlias");
// Public panel setting to Enable fast full scene anti-aliasing
const cmString CAL_OGLENABLEFASTFULLSCENEAA("FSAAPerfMode");
//Private Panel setting to force FSAA on
const cmString CAL_ENABLEFASTFULLSCENEAA("FastFullSceneAntiAlias");
// Public panel setting to set full scene anti-aliasing scale.
// Acceptable values are 0, 2-6
const cmString CAL_OGLFULLSCENEAASCALE("AntiAliasSamples");
// Private panel setting to force FSAA, Acceptable values are 0, 2-6.
const cmString CAL_FULLSCENEAASCALE("FullSceneAntiAliasScale");
// Public panel setting to enable triple-buffering
const cmString CAL_OGLENABLETRIPLEBUFFERING("EnableTripleBuffering");
// Public panel setting to set texture optimization
const cmString CAL_OGLTEXTUREOPT("TextureOpt");
// Public panel settings to set postprocessing shaders
const cmString CAL_OGLSELECTEDSWAPEFFECT("SwapEffect");
// Public panel settings to control CatalystAI settings
const cmString CAL_OGLCATALYSTAI("CatalystAI");
// Public panel settings to set postprocessing shaders
const cmString CAL_OGLSUPPORTEDSWAPEFFECTS("SupportedSwapEffects");
const cmString CAL_OGLCUSTOMSWAPSOURCEFILE("CustomSwapSourceFile");
//Public panel setting for allowing special pixel shaders to be applied at swap time.
const cmString CAL_SPECIALSWAP("SpecialSwap");
//Public panel setting for special swap file
const cmString CAL_SPECIALSWAPFILE("SpecialSwapFile");
// Private Panel specific Defines
//
// Private panel setting to force SW path
const cmString CAL_PICKSOFTWARE("PickSoftware");
// Private panel setting to force Microsoft path
const cmString CAL_PICKSOFTWAREMICROSOFT("PickSoftwareMicrosoft");
// Private Panel setting to enable TCL (versus forcing SW TCL)
const cmString CAL_ENABLETCL("EnableTCL");
// Private Panel setting to control HW Flips
const cmString CAL_ALLOWHWFLIP("AllowHWFlip");
// Private Panel setting to allow Z compression
const cmString CAL_ENABLEZCOMPRESSION("ZCompression");
// Private Panel setting to use fast z clears
const cmString CAL_ENABLEFASTZMASKCLEAR("FastZMaskClear");
// Private Panel setting to enable hierarchical Z
const cmString CAL_ENABLEHIERARCHICALZ("HierachicalZ");
// Private Panel setting to enable/disable cmask clears
const cmString CAL_ENABLECMASKCLEARS("MaskClears");
// Private Panel setting to force cmask clear after swap
const cmString CAL_CLEARCMASKAFTERSWAP("ClearCMaskAfterSwap");
// Private Panel setting to enable cmask compression
const cmString CAL_ENABLECMASKCOMPRESSION("CMaskCompression");
// Private Panel setting to force LOD Bias
const cmString CAL_LODBIAS("LODBias");
// Private Panel setting enable fast trilinear
const cmString CAL_FASTTRILINEAR("FastTrilinear");
// Private Panel setting to force clears to be skipped
const cmString CAL_DISABLECLEAR("DisableClear");
// Private Panel setting to control swapping
const cmString CAL_DISABLESWAP("DisableSwap");
// Private Panel setting to force HW idle after submit
const cmString CAL_WAITFORIDLEAFTERSUBMIT("WaitForIdleAfterSubmit");
// Private Panel setting to force single buffered rendering
const cmString CAL_FORCESINGLEBUFFER("ForceSingleBuffer");
// Private Panel setting to force buffer config for single buffered
// configs
const cmString CAL_SINGLE_BUF_CONFIG("SingleBufferConfig");
// Private Panel setting to force buffer config for double buffered
const cmString CAL_DOUBLE_BUF_CONFIG("DoubleBufferConfig");
// Private Panel setting to cause driver to breka on load
const cmString CAL_BREAK_ON_LOAD("BreakOnLoad");
// Private Panel setting for asserting when we set an error
const cmString CAL_ASSERTONERROR("AssertOnError");
// Private Panel setting to turn on shader dumping
const cmString CAL_ENABLESHADERDUMP("EnableShaderDump");
// Private Panel setting to turn on packet dumping
const cmString CAL_ENABLEPACKETDUMP("EnablePacketDump");
// Private Panel setting to set location of packet dump
const cmString CAL_PACKETDUMPLOCATION("PacketDumpLocation");
// Private Panel setting to set what type of file to be written
const cmString CAL_PACKETDUMPTYPE("PacketDumpType");
// Private Panel setting to select file overwrite
const cmString CAL_ONLYSAVELASTPACKET("OnlySaveLastPacket");
// Private Panel setting to turn on vcop patchlist dumping
const cmString CAL_ENABLEPATCHDUMP("EnablePatchDump");
// Private Panel setting to set dump file name
const cmString CAL_DUMPFILENAME("DumpFilename");
// Private Panel setting to control level of HW detail dumped
const cmString CAL_DUMPADDITIONALHWINFO("DumpAdditionalHWInfo");
// Private Panel setting to select frames to dump
const cmString CAL_FRAMESTORECORD("FrameStoreCord");
// Private Panel setting to drop all PM4 packets
const cmString CAL_DROPFLUSH("DropFlush");
// Private Panel setting to furce use of dummy QS
const cmString CAL_ENABLEDUMMYQS("DummyQS");
// Private Panel setting to stub post setup
const cmString CAL_STUBPOSTSETUP("StubPostSetup");
// Private Panel setting to stub post TCL
const cmString CAL_STUBPOSTTCL("StubPostTCL");
// Private Panel setting to disable RB3D
const cmString CAL_DISABLERB3D("DisableR3D");
// Private Panel setting to disable alpha blend
const cmString CAL_DISABLEALPHABLEND("DisableAlphaBlend");
// Private Panel setting to force use of tiny textures
const cmString CAL_FORCETINYTEXTURES("ForceTinyTextures");
// Private Panel setting to prevent object allocation in AGP
const cmString CAL_OBJBUFINAGP("OBJBufferInAGP");
// Private Panel setting to prevent object allcoation in local
const cmString CAL_OBJBUFINLOCAL("OBJBufferInLocal");
// Private Panel setting to set the length of the swap queue
const cmString CAL_SWAPQUEUELENGTH("SwapQueueLength");
// Private Panel setting to enable macro tiling for textures
const cmString CAL_ENABLEMACROTILE("MacroTile");
// Private Panel setting to enable micro tiling for textures
const cmString CAL_ENABLEMICROTILE("MicroTile");
// Private Panel setting for allowing early z
const cmString CAL_ALLOWEARLYZ("AllowEarlyZ");
//Private Panel setting to allow for window to be broken into
// multiple pieces(allows full use of C and Z mask on R300 at high res);
const cmString CAL_ALLOWSPLITSCREEN("AllowSplitScreen");
//Private Panel setting for aniso threshold
const cmString CAL_ANISOTHRESHOLD("AnisoThreshold");
//Private Panel setting for aniso bias
const cmString CAL_ANISOLOD("AnisoLod");
//Private Panel setting fpr aniso bias
const cmString CAL_ANISOBIAS("AnisoBias");
//Private Panel setting to control ainos theshold mode
const cmString CAL_ANISOTHRESHMODE("AnisoThreshmode");
// Private Panel Setting for turnning off multi vpu mode(ie render everything to both) for the rest of a frame after a glCopyTexImage or glCopyTexSubImage happen.
const cmString CAL_DISABLEMVPUONCOPYTEX("DisableMVPUOnCopyTexture");
// Private Panel Setting for forcing swap to happen on slave vpu(useful for debugging);
const cmString CAL_FORCEMVPUSWAPONSLAVE("ForceMVPUSwapOnSlave");
// Private Panel Setting for skipping multi-vpu synchronization
const cmString CAL_SKIPMVPUSYNCH("SkipMVPUSynch");
// Private Panel Setting for controlling the percent of screen rendered on the master vpu
const cmString CAL_PERCENTONMASTERMVPU("PercentOnMasterMVPU");
// Private Panel Setting for controlling the mode of mvpu operation
const cmString CAL_MODEMVPU("ModeMVPU");
// Private Panel Setting for drawing a line where the scissored split happened in mvpu mode
const cmString CAL_DRAWSPLITLINEMVPU("DrawSplitLineMVPU");
// Private Panel Setting for controlling whether or not to unroll loops in the GLSL parser
const cmString CAL_UNROLL_LOOPS("UnrollLoops");
// Private Panel Spare setting 1
const cmString CAL_SPARE1("Spare1");
// Private Panel Spare setting 2
const cmString CAL_SPARE2("Spare2");
// Private Panel Spare setting 3
const cmString CAL_SPARE3("Spare3");
// Private Panel Spare setting 4
const cmString CAL_SPARE4("Spare4");
// Private Panel Spare setting 5
const cmString CAL_SPARE5("Spare5");
// Private Panel Spare setting 6
const cmString CAL_SPARE6("Spare6");
// Private Panel Spare setting 7
const cmString CAL_SPARE7("Spare7");
// Private Panel Spare setting 8
const cmString CAL_SPARE8("Spare8");
// Private Panel Spare setting 9
const cmString CAL_SPARE9("Spare9");
// Private Panel Spare setting 10
const cmString CAL_SPARE10("Spare10");
// Private Panel Spare setting 11 - accepts numbers, not just 0 and 1
const cmString CAL_SPARE11("Spare11");
// Private Panel Spare setting 12 - accepts numbers, not just 0 and 1
const cmString CAL_SPARE12("Spare12");
// Private Panel Spare setting 12 - accepts numbers, not just 0 and 1
const cmString CAL_PS3ENABLE("PS3Enable");
// Private Panel setting for asserting when we punt to SW
const cmString CAL_ASSERTONSWPUNT("OrcaAssertOnSWPunt");
// Private Panel setting for logging when we punt to SW
const cmString CAL_LOGSWPUNTCASES("OrcaLogSWPuntCases");
// Private Panel setting to set punt log file name
const cmString CAL_PUNTLOGFILENAME("OrcaPuntLogFileName");
// softVAP mode
const cmString CAL_SOFTVAP("SoftVAP");
// softVAP il compile mode
const cmString CAL_SVPOFFLINECOMPILE("SvpOfflineCompile");
const cmString CAL_EMULATOR("Emulator");
const cmString CAL_ENABLE_FORCE_ASIC_ID("EnableForceAsicID");
const cmString CAL_FORCE_ASIC_ID("ForceAsicID");
const cmString CAL_FORCE_REMOTE_MEMORY("ForceRemoteMemory");
const cmString CAL_DISABLE_ASYNC_DMA("DisableAsyncDma");
const cmString CAL_ENABLE_DUMP_IL("DumpIL");
const cmString CAL_ENABLE_DUMP_ISA("DumpISA");
// TDR
const cmString CAL_ENABLE_FLUSH_AFTER_RENDER("FlushAfterRender");
// VM Disabling
const cmString CAL_DISABLE_VM("DisableVM");
#endif
@@ -0,0 +1,537 @@
//
// Trade secret of ATI Technologies, Inc.
// Copyright 2005, ATI Technologies, Inc., (unpublished)
//
// All rights reserved. This notice is intended as a precaution against
// inadvertent publication and does not imply publication or any waiver
// of confidentiality. The year included in the foregoing notice is the
// year of creation of the work.
//
/// @file inifile.cpp
/// @brief INI File Parser
#include "inifile.h"
#include "cm_string.h"
#include "inifile_parser.h"
#include "cal.h"
#include "assert.h"
#include <iostream>
#include <istream>
#include <fstream>
#ifdef DEBUG
#include <sstream>
#include <string>
#endif
/**
* IniValueString members
*/
IniValueString::IniValueString()
{
value = cmString("");
}
IniValueString::IniValueString(const IniValueString& val)
{
value = val.value;
}
IniValueString::IniValueString(cmString val)
{
value = val;
}
IniValueString& IniValueString::operator=(IniValueString& v)
{
value = v.value;
return *this;
}
CALboolean IniValueString::getValue(cmString* value)
{
*value = this->value;
return CAL_TRUE;
}
/**
* IniValueBool members
*/
IniValueBool::IniValueBool()
{
value = CAL_FALSE;
}
IniValueBool::IniValueBool(const IniValueBool& val)
{
value = val.value;
}
IniValueBool::IniValueBool(CALboolean val)
{
value = val;
}
IniValueBool& IniValueBool::operator=(IniValueBool& v)
{
value = v.value;
return *this;
}
CALboolean IniValueBool::getValue(CALboolean* value)
{
*value = this->value;
return CAL_TRUE;
}
/**
* IniValueInt members
*/
IniValueInt::IniValueInt()
{
value = 0;
}
IniValueInt::IniValueInt(const IniValueInt& val)
{
value = val.value;
}
IniValueInt::IniValueInt(CALint val)
{
value = val;
}
IniValueInt& IniValueInt::operator=(IniValueInt& v)
{
value = v.value;
return *this;
}
CALboolean IniValueInt::getValue(CALint* value)
{
*value = this->value;
return CAL_TRUE;
}
/**
* IniValueFloat members
*/
IniValueFloat::IniValueFloat()
{
value = 0;
}
IniValueFloat::IniValueFloat(const IniValueFloat& val)
{
value = val.value;
}
IniValueFloat::IniValueFloat(CALfloat val)
{
value = val;
}
IniValueFloat& IniValueFloat::operator=(IniValueFloat& v)
{
value = v.value;
return *this;
}
CALboolean IniValueFloat::getValue(CALfloat* value)
{
*value = this->value;
return CAL_TRUE;
}
/**
* IniSection Members
*/
IniSection::IniSection()
{
name = cmString("");
}
IniSection::IniSection(const IniSection& s)
{
name = s.name;
for(EntryDBIterator iter = s.entryDB.begin() ; iter != s.entryDB.end(); iter++)
{
entryDB[iter->first] = iter->second;
}
}
IniSection::IniSection(cmString n)
{
name = n;
}
IniSection::~IniSection()
{
for(EntryDBIterator iter = entryDB.begin() ; iter != entryDB.end(); iter++)
{
delete iter->second;
}
entryDB.clear();
}
IniSection& IniSection::operator=(IniSection& s)
{
name = s.name;;
entryDB.clear();
for(EntryDBIterator iter = s.entryDB.begin() ; iter != s.entryDB.end(); iter++)
{
entryDB[iter->first] = iter->second;
}
return *this;
}
void IniSection::addEntry(cmString name, IniValue* value)
{
IniValue* v = findEntry(name);
if (v)
{
delete v;
}
entryDB[name] = value;
}
IniValue* IniSection::findEntry(cmString name)
{
EntryDBIterator iter = entryDB.find(name);
if(iter != entryDB.end())
{
return iter->second;
}
else
{
return NULL;
}
}
/**
* IniFile members
*/
IniFile::IniFile(cmString filename)
{
#ifdef DEBUG
SanityTest();
#endif
std::ifstream in(filename.c_str());
IniFileParser::Parse(in, *this);
}
IniFile::IniFile(std::istream& in)
{
IniFileParser::Parse(in, *this);
}
IniFile::~IniFile()
{
for(SectionDBIterator iter = sectionDB.begin() ; iter != sectionDB.end(); iter++)
{
delete iter->second;
}
sectionDB.clear();
}
const cmString IniSection::getName()
{
return name;
}
void IniFile::addSection(IniSection* section)
{
IniSection* v = findSection(section->getName());
if (v)
{
delete v;
}
sectionDB[section->getName()] = section;
}
IniSection* IniFile::findSection(cmString section)
{
SectionDBIterator iter = sectionDB.find(section);
if (iter != sectionDB.end())
{
return iter->second;
}
else
{
return NULL;
}
}
IniValue* IniFile::getValue(cmString section, cmString entry)
{
IniSection* s = findSection(section);
if(s == NULL)
{
return NULL;
}
return s->findEntry(entry);
}
CALboolean IniFile::getValue(cmString section, cmString entry, CALboolean* value)
{
IniValue* v = getValue(section, entry);
if (v != NULL)
{
return v->getValue(value);
}
return CAL_FALSE;
}
CALboolean IniFile::getValue(cmString section, cmString entry, CALint* value)
{
IniValue* v = getValue(section, entry);
if (v != NULL)
{
return v->getValue(value);
}
return CAL_FALSE;
}
CALboolean IniFile::getValue(cmString section, cmString entry, CALfloat* value)
{
IniValue* v = getValue(section, entry);
if (v != NULL)
{
return v->getValue(value);
}
return CAL_FALSE;
}
CALboolean IniFile::getValue(cmString section, cmString entry, cmString* value)
{
IniValue* v = getValue(section, entry);
if (v != NULL)
{
return v->getValue(value);
}
return CAL_FALSE;
}
/**
* Debug only methods
*
*/
#ifdef DEBUG
void IniValueString::printAST()
{
std::cerr << value.c_str() << " [string]\n";
}
void IniValueBool::printAST()
{
std::cerr << value << " [bool]\n";
}
void IniValueInt::printAST()
{
std::cerr << value << " [int]\n";
}
void IniValueFloat::printAST()
{
std::cerr << value << " [float]\n";
}
void IniSection::printAST()
{
for(EntryDBIterator iter = entryDB.begin() ; iter != entryDB.end(); iter++)
{
cmString name = iter->first;
IniValue *v = iter->second;
std::cerr << name.c_str() << " = ";
v->printAST();
}
}
void IniFile::printAST()
{
for(SectionDBIterator iter = sectionDB.begin() ; iter != sectionDB.end(); iter++)
{
IniSection* s = iter->second;
std::cerr << "[" << s->getName().c_str() << "]\n";
s->printAST();
}
std::cerr << "\n";
}
void IniFile::SanityTest()
{
//std::cerr << "Running IniFile Sanity...\n";
static const cmString section("section");
static const std::string file1(
"[section]\n\
bool1=true\n\
bool2=false\n\
int=3\n\
float=1.1111\n\
string=abc def\n");
std::istringstream s1(file1);
IniFile* iniFile = new IniFile(s1);
//iniFile->printAST();
CALboolean b;
assert(iniFile->getValue(section, cmString("bool1"), &b) == CAL_TRUE);
assert(b == CAL_TRUE);
assert(iniFile->getValue(section, cmString("bool2"), &b) == CAL_TRUE);
assert(b == CAL_FALSE);
CALint i;
assert(iniFile->getValue(section, cmString("int"), &i) == CAL_TRUE);
assert(i == 3);
CALfloat f;
assert(iniFile->getValue(section, cmString("float"), &f) == CAL_TRUE);
assert(f == 1.1111f);
cmString s;
assert(iniFile->getValue(section, cmString("string"), &s) == CAL_TRUE);
assert(s == cmString("abc def"));
i = -1;
// Wrong section
assert(iniFile->getValue(cmString("dummy"), cmString("int"), &i) == CAL_FALSE);
assert(i == -1);
// Wrong entry
assert(iniFile->getValue(section, cmString("dummy"), &i) == CAL_FALSE);
assert(i == -1);
static const std::string file2(
"[section]\n\
bool1=1true\n\
bool2=false2\n\
int=3a\n\
float=1.1111b\n\
string=1\n");
delete iniFile;
std::istringstream s2(file2);
iniFile = new IniFile(s2);
//iniFile->printAST();
cmString str;
b = CAL_FALSE;
// try to get a bool, then a string
assert(iniFile->getValue(section, cmString("bool1"), &b) == CAL_FALSE);
assert(b == CAL_FALSE);
assert(iniFile->getValue(section, cmString("bool1"), &str) == CAL_TRUE);
assert(str == cmString("1true"));
// try to get a bool, then a string
assert(iniFile->getValue(section, cmString("bool2"), &b) == CAL_FALSE);
assert(b == CAL_FALSE);
assert(iniFile->getValue(section, cmString("bool2"), &str) == CAL_TRUE);
assert(str == cmString("false2"));
i = -1;
// try to get an int, then a string
assert(iniFile->getValue(section, cmString("int"), &i) == CAL_FALSE);
assert(i == -1);
assert(iniFile->getValue(section, cmString("int"), &str) == CAL_TRUE);
assert(str == cmString("3a"));
f = -1.1f;
// try to get a float, then a string
assert(iniFile->getValue(section, cmString("float"), &f) == CAL_FALSE);
assert(f == -1.1f);
assert(iniFile->getValue(section, cmString("float"), &str) == CAL_TRUE);
assert(str == cmString("1.1111b"));
// try to get a string, value is an int
assert(iniFile->getValue(section, cmString("string"), &str) == CAL_FALSE);
assert(str == cmString("1.1111b"));
assert(iniFile->getValue(section, cmString("string"), &i) == CAL_TRUE);
assert(i == 1);
static const cmString section1("section1");
static const cmString section2("section2");
static const cmString section3("section3");
static const std::string file3(
"[section1\n\
bool1=false\n\
bool2=false\n\
int=1\n\
float=1.1\n\
string=abc\n\
[section2]\n\
bool1=true\n\
bool2=true\n\
int=2\n\
float=1.2\n\
string=def\n\
[section3]\n\
int=3\n\
[section2]\n\
float=1.3\n");
delete iniFile;
std::istringstream s3(file3);
iniFile = new IniFile(s3);
//iniFile->printAST();
// section1 should not exist (syntax error)
assert(iniFile->getValue(section1, cmString("bool1"), &str) == CAL_FALSE);
assert(iniFile->getValue(section1, cmString("bool2"), &str) == CAL_FALSE);
assert(iniFile->getValue(section1, cmString("int"), &str) == CAL_FALSE);
assert(iniFile->getValue(section1, cmString("float"), &str) == CAL_FALSE);
assert(iniFile->getValue(section1, cmString("string"), &str) == CAL_FALSE);
// section2 should exist, only with the float
assert(iniFile->getValue(section2, cmString("bool1"), &b) == CAL_FALSE);
assert(iniFile->getValue(section2, cmString("bool2"), &b) == CAL_FALSE);
assert(iniFile->getValue(section2, cmString("int"), &i) == CAL_FALSE);
// overridden
assert(iniFile->getValue(section2, cmString("float"), &f) == CAL_TRUE);
assert(f == 1.3f);
assert(iniFile->getValue(section2, cmString("string"), &str) == CAL_FALSE);
// section3 had a differant int
assert(iniFile->getValue(section3, cmString("int"), &i) == CAL_TRUE);
assert(i == 3);
delete iniFile;
//std::cerr << "Done!";
}
#endif
@@ -0,0 +1,164 @@
#ifndef INIFILE_H
#define INIFILE_H
//
// Trade secret of ATI Technologies, Inc.
// Copyright 2005, ATI Technologies, Inc., (unpublished)
//
// All rights reserved. This notice is intended as a precaution against
// inadvertent publication and does not imply publication or any waiver
// of confidentiality. The year included in the foregoing notice is the
// year of creation of the work.
//
/// @file inifile.h
/// @brief INI File Parser
#include "cm_string.h"
#include "cal.h"
#include <map>
#include <istream>
class IniValue
{
public:
virtual ~IniValue() {}
virtual CALboolean getValue(CALboolean* value) { return CAL_FALSE; };
virtual CALboolean getValue(CALint* value) { return CAL_FALSE; };
virtual CALboolean getValue(CALfloat* value) { return CAL_FALSE; };
virtual CALboolean getValue(cmString* value) { return CAL_FALSE; };
#ifdef DEBUG
virtual void printAST() {};
#endif
private:
};
class IniValueBool : public IniValue
{
public:
IniValueBool();
IniValueBool(const IniValueBool& val);
IniValueBool(CALboolean val);
IniValueBool& operator=(IniValueBool& v);
CALboolean getValue(CALboolean* value);
#ifdef DEBUG
void printAST();
#endif
private:
CALboolean value;
};
class IniValueString : public IniValue
{
public:
IniValueString();
IniValueString(const IniValueString& val);
IniValueString(cmString val);
IniValueString& operator=(IniValueString& v);
CALboolean getValue(cmString* value);
#ifdef DEBUG
void printAST();
#endif
private:
cmString value;
};
class IniValueInt : public IniValue
{
public:
IniValueInt();
IniValueInt(const IniValueInt& val);
IniValueInt(CALint val);
IniValueInt& operator=(IniValueInt& v);
CALboolean getValue(CALint* value);
void printAST();
private:
CALint value;
};
class IniValueFloat : public IniValue
{
public:
IniValueFloat();
IniValueFloat(const IniValueFloat& val);
IniValueFloat(CALfloat val);
IniValueFloat& operator=(IniValueFloat& v);
CALboolean getValue(CALfloat* value);
#ifdef DEBUG
void printAST();
#endif
private:
CALfloat value;
};
class IniSection
{
public:
IniSection();
IniSection(const IniSection& s);
IniSection(cmString n);
~IniSection();
IniSection& operator=(IniSection& s);
void addEntry(cmString name, IniValue* value);
IniValue* findEntry(cmString name);
const cmString getName();
#ifdef DEBUG
void printAST();
#endif
private:
typedef std::map<cmString, IniValue*> EntryDB;
typedef EntryDB::const_iterator EntryDBIterator;
typedef std::pair<cmString, IniValue*> EntryDBPair;
cmString name;
EntryDB entryDB;
};
class IniFile
{
public:
IniFile(cmString filename);
IniFile(std::istream& in);
~IniFile();
CALboolean getValue(cmString section, cmString entry, CALboolean* value);
CALboolean getValue(cmString section, cmString entry, CALint* value);
CALboolean getValue(cmString section, cmString entry, CALfloat* value);
CALboolean getValue(cmString section, cmString entry, cmString* value);
// should be protected
void addSection(IniSection* section);
IniSection* findSection(cmString section);
#ifdef DEBUG
void printAST();
static void SanityTest();
#endif
private:
typedef std::map<cmString, IniSection*> SectionDB;
typedef SectionDB::const_iterator SectionDBIterator;
typedef std::pair<cmString, IniSection*> SectionDBPair;
IniValue* getValue(cmString section, cmString entry);
SectionDB sectionDB;
};
#endif
@@ -0,0 +1,225 @@
//
// Trade secret of ATI Technologies, Inc.
// Copyright 2005, ATI Technologies, Inc., (unpublished)
//
// All rights reserved. This notice is intended as a precaution against
// inadvertent publication and does not imply publication or any waiver
// of confidentiality. The year included in the foregoing notice is the
// year of creation of the work.
//
/// @file inifile_parser.cpp
/// @brief INI File Parser Implementation
#include "inifile.h"
#include "inifile_parser.h"
#include "cm_string.h"
#include <cctype>
#include <string>
#include <istream>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cctype>
void IniFileParser::Parse(std::istream& in, IniFile& iniFile)
{
CALuint count = 0;
std::string line;
bool inSection = false;
std::string sectionName;
IniSection* section = NULL;
while(std::getline(in, line)) {
count++;
cleanup(line);
if(line.empty())
{
continue;
}
if(parseSectionName(line, sectionName))
{
section = new IniSection(cmString(sectionName.c_str()));
iniFile.addSection(section);
inSection = true;
}
else if(inSection)
{
parseLine(line, section, count);
}
}
}
void IniFileParser::parseLine( std::string line, IniSection* section, CALuint count ) {
std::string::size_type equals = line.find( '=' );
if ( equals == std::string::npos ) {
#ifdef DEBUG
std::cerr << "IniFileParser: Could not parse line " << count << ", ignoring.\n";
#endif
return;
}
std::string name( line, 0, equals );
IniValue* value = parseValue( std::string( line, equals + 1, std::string::npos));
section->addEntry(cmString(trim(name).c_str()), value);
}
void IniFileParser::cleanup( std::string& line ) {
std::string copy = line;
unsigned int begin = 0;
while ( begin != line.size() && isspace(line[begin]))
{
++begin;
}
bool inQuote = false;
unsigned int end;
for(end = begin; end != line.size(); ++end)
{
if ( line[end] == '\"' )
{
inQuote = !inQuote;
}
// comments starts with # or ;
else if ( (line[end] == '#' || line[end] == ';') && !inQuote )
{
break;
}
else if ( line[ end ] == '\\' )
{
++end; // ignore next character
if ( end == line.size() ) {
#ifdef DEBUG
std::cerr << "INIFileParser: Error parsing file: \\ character "
"at the end of line (sorry, not supported)\n";
#endif
break;
}
}
}
while ( end > begin && isspace( line[ end - 1 ] ) ) --end;
// This is used over assign so that we don't have memcpy overrun
// errors in valgrind.
line = line.substr(begin, end - begin);
}
class isint
{
public:
isint()
{
is_int = true;
}
void operator() (char c)
{
is_int = is_int && isdigit(c);
}
bool is_int;
};
class isfloat
{
public:
isfloat()
{
is_float = true;
}
void operator() (char c)
{
is_float = is_float && (isdigit(c) || c == '.');
}
bool is_float;
};
int cmp_nocase(const std::string s1, const std::string s2)
{
std::string::const_iterator p1 = s1.begin();
std::string::const_iterator p2 = s2.begin();
while( p1 != s1.end() && p2 != s2.end())
{
if(toupper(*p1) != toupper(*p2))
{
return (toupper(*p1) < toupper(*p2)) ? -1 : 1;
}
++p1;
++p2;
}
return static_cast<int>(s2.size()-s1.size());
}
IniValue* IniFileParser::parseValue(std::string value ) {
std::string trimmed = trim(value);
std::stringstream ss(trimmed);
// look for a boolean
static const std::string strTrue("true");
static const std::string strFalse("false");
if(cmp_nocase(trimmed, strTrue) == 0)
{
return new IniValueBool(CAL_TRUE);
}
if(cmp_nocase(trimmed, strFalse) == 0)
{
return new IniValueBool(CAL_FALSE);
}
// try now to get an int
isint ii;
ii = std::for_each(trimmed.begin(),trimmed.end(), ii);
if(ii.is_int)
{
CALint intValue = 0;
ss >> intValue;
return new IniValueInt(intValue);
}
// if not an int, try to get a float
isfloat isf;
isf = std::for_each(trimmed.begin(),trimmed.end(), isf);
if(isf.is_float)
{
CALfloat floatValue;
// mbeuchat: Remove STL conversion of string to float. When compiled
// on Linux, DK g++ with optimization requires linking against
// libstdc++-6.0.9 which is not available on all Linux systems.
// ss >> floatValue;
floatValue = (float)atof(ss.str().c_str());
return new IniValueFloat(floatValue);
}
// finally, default to a string
return new IniValueString(cmString(trimmed.c_str()));
}
bool IniFileParser::parseSectionName(std::string line, std::string& section )
{
if ( line[ 0 ] != '[' ) return false;
if ( line[ line.size() - 1 ] != ']' ) return false;
section.assign( line, 1, line.size() - 2 );
return true;
}
std::string IniFileParser::trim(std::string const& source, char const* delims) {
std::string result(source);
std::string::size_type index = result.find_last_not_of(delims);
if(index != std::string::npos)
result.erase(++index);
index = result.find_first_not_of(delims);
if(index != std::string::npos)
result.erase(0, index);
else
result.erase();
return result;
}
@@ -0,0 +1,42 @@
#ifndef INIFILE_PARSER_H
#define INIFILE_PARSER_H
//
// Trade secret of ATI Technologies, Inc.
// Copyright 2005, ATI Technologies, Inc., (unpublished)
//
// All rights reserved. This notice is intended as a precaution against
// inadvertent publication and does not imply publication or any waiver
// of confidentiality. The year included in the foregoing notice is the
// year of creation of the work.
//
/// @file inifile_parser.h
/// @brief INI File Parser Implementation
// if compiled from OGTST, add the following, normally defined in atitypes.h
#include "inifile.h"
#include "cm_string.h"
#include "cal.h"
#include <istream>
#include <iostream>
#include <string>
class IniFileParser
{
public:
static void Parse(std::istream& in, IniFile& iniFile);
private:
static void parseLine( std::string line, IniSection* section, CALuint count );
static bool parseSectionName(std::string line, std::string& section );
static IniValue* parseValue(std::string value );
static void cleanup( std::string& line );
static std::string trim(std::string const& source, char const* delims = " \t\r\n");
};
#endif