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,304 @@
/**
* @file cal.h
* @brief CAL Interface Header
* @version 1.00.0 Beta
*/
/* ============================================================
Copyright (c) 2007 Advanced Micro Devices, Inc. All rights reserved.
Redistribution and use of this material is permitted under the following
conditions:
Redistributions must retain the above copyright notice and all terms of this
license.
In no event shall anyone redistributing or accessing or using this material
commence or participate in any arbitration or legal action relating to this
material against Advanced Micro Devices, Inc. or any copyright holders or
contributors. The foregoing shall survive any expiration or termination of
this license or any agreement or access or use related to this material.
ANY BREACH OF ANY TERM OF THIS LICENSE SHALL RESULT IN THE IMMEDIATE REVOCATION
OF ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE THIS MATERIAL.
THIS MATERIAL IS PROVIDED BY ADVANCED MICRO DEVICES, INC. AND ANY COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" IN ITS CURRENT CONDITION AND WITHOUT ANY
REPRESENTATIONS, GUARANTEE, OR WARRANTY OF ANY KIND OR IN ANY WAY RELATED TO
SUPPORT, INDEMNITY, ERROR FREE OR UNINTERRUPTED OPERATION, OR THAT IT IS FREE
FROM DEFECTS OR VIRUSES. ALL OBLIGATIONS ARE HEREBY DISCLAIMED - WHETHER
EXPRESS, IMPLIED, OR STATUTORY - INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
ACCURACY, COMPLETENESS, OPERABILITY, QUALITY OF SERVICE, OR NON-INFRINGEMENT.
IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, REVENUE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED OR BASED ON ANY THEORY OF LIABILITY
ARISING IN ANY WAY RELATED TO THIS MATERIAL, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE. THE ENTIRE AND AGGREGATE LIABILITY OF ADVANCED MICRO DEVICES,
INC. AND ANY COPYRIGHT HOLDERS AND CONTRIBUTORS SHALL NOT EXCEED TEN DOLLARS
(US $10.00). ANYONE REDISTRIBUTING OR ACCESSING OR USING THIS MATERIAL ACCEPTS
THIS ALLOCATION OF RISK AND AGREES TO RELEASE ADVANCED MICRO DEVICES, INC. AND
ANY COPYRIGHT HOLDERS AND CONTRIBUTORS FROM ANY AND ALL LIABILITIES,
OBLIGATIONS, CLAIMS, OR DEMANDS IN EXCESS OF TEN DOLLARS (US $10.00). THE
FOREGOING ARE ESSENTIAL TERMS OF THIS LICENSE AND, IF ANY OF THESE TERMS ARE
CONSTRUED AS UNENFORCEABLE, FAIL IN ESSENTIAL PURPOSE, OR BECOME VOID OR
DETRIMENTAL TO ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
CONTRIBUTORS FOR ANY REASON, THEN ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE
THIS MATERIAL SHALL TERMINATE IMMEDIATELY. MOREOVER, THE FOREGOING SHALL
SURVIVE ANY EXPIRATION OR TERMINATION OF THIS LICENSE OR ANY AGREEMENT OR
ACCESS OR USE RELATED TO THIS MATERIAL.
NOTICE IS HEREBY PROVIDED, AND BY REDISTRIBUTING OR ACCESSING OR USING THIS
MATERIAL SUCH NOTICE IS ACKNOWLEDGED, THAT THIS MATERIAL MAY BE SUBJECT TO
RESTRICTIONS UNDER THE LAWS AND REGULATIONS OF THE UNITED STATES OR OTHER
COUNTRIES, WHICH INCLUDE BUT ARE NOT LIMITED TO, U.S. EXPORT CONTROL LAWS SUCH
AS THE EXPORT ADMINISTRATION REGULATIONS AND NATIONAL SECURITY CONTROLS AS
DEFINED THEREUNDER, AS WELL AS STATE DEPARTMENT CONTROLS UNDER THE U.S.
MUNITIONS LIST. THIS MATERIAL MAY NOT BE USED, RELEASED, TRANSFERRED, IMPORTED,
EXPORTED AND/OR RE-EXPORTED IN ANY MANNER PROHIBITED UNDER ANY APPLICABLE LAWS,
INCLUDING U.S. EXPORT CONTROL LAWS REGARDING SPECIFICALLY DESIGNATED PERSONS,
COUNTRIES AND NATIONALS OF COUNTRIES SUBJECT TO NATIONAL SECURITY CONTROLS.
MOREOVER, THE FOREGOING SHALL SURVIVE ANY EXPIRATION OR TERMINATION OF ANY
LICENSE OR AGREEMENT OR ACCESS OR USE RELATED TO THIS MATERIAL.
NOTICE REGARDING THE U.S. GOVERNMENT AND DOD AGENCIES: This material is
provided with "RESTRICTED RIGHTS" and/or "LIMITED RIGHTS" as applicable to
computer software and technical data, respectively. Use, duplication,
distribution or disclosure by the U.S. Government and/or DOD agencies is
subject to the full extent of restrictions in all applicable regulations,
including those found at FAR52.227 and DFARS252.227 et seq. and any successor
regulations thereof. Use of this material by the U.S. Government and/or DOD
agencies is acknowledgment of the proprietary rights of any copyright holders
and contributors, including those of Advanced Micro Devices, Inc., as well as
the provisions of FAR52.227-14 through 23 regarding privately developed and/or
commercial computer software.
This license forms the entire agreement regarding the subject matter hereof and
supersedes all proposals and prior discussions and writings between the parties
with respect thereto. This license does not affect any ownership, rights, title,
or interest in, or relating to, this material. No terms of this license can be
modified or waived, and no breach of this license can be excused, unless done
so in a writing signed by all affected parties. Each term of this license is
separately enforceable. If any term of this license is determined to be or
becomes unenforceable or illegal, such term shall be reformed to the minimum
extent necessary in order for this license to remain in effect in accordance
with its terms as modified by such reformation. This license shall be governed
by and construed in accordance with the laws of the State of Texas without
regard to rules on conflicts of law of any state or jurisdiction or the United
Nations Convention on the International Sale of Goods. All disputes arising out
of this license shall be subject to the jurisdiction of the federal and state
courts in Austin, Texas, and all defenses are hereby waived concerning personal
jurisdiction and venue of these courts.
============================================================ */
#ifndef __CAL_H__
#define __CAL_H__
#ifdef __cplusplus
extern "C" {
#endif
typedef void CALvoid; /**< void type */
typedef char CALchar; /**< ASCII character */
typedef signed char CALbyte; /**< 1 byte signed integer value */
typedef unsigned char CALubyte; /**< 1 byte unsigned integer value */
typedef signed short CALshort; /**< 2 byte signed integer value */
typedef unsigned short CALushort; /**< 2 byte unsigned integer value */
typedef signed int CALint; /**< 4 byte signed integer value */
typedef unsigned int CALuint; /**< 4 byte unsigned intger value */
typedef float CALfloat; /**< 32-bit IEEE floating point value */
typedef double CALdouble; /**< 64-bit IEEE floating point value */
typedef signed long CALlong; /**< long value */
typedef unsigned long CALulong; /**< unsigned long value */
#if defined(_MSC_VER)
typedef signed __int64 CALint64; /**< 8 byte signed integer value */
typedef unsigned __int64 CALuint64; /**< 8 byte unsigned integer value */
#elif defined(__GNUC__)
typedef signed long long CALint64; /**< 8 byte signed integer value */
typedef unsigned long long CALuint64; /**< 8 byte unsigned integer value */
#else
#error "Unsupported compiler type."
#endif
/** Boolean type */
typedef enum CALbooleanEnum {
CAL_FALSE = 0, /**< Boolean false value */
CAL_TRUE = 1 /**< Boolean true value */
} CALboolean;
/** Device Kernel ISA */
typedef enum CALtargetEnum {
CAL_TARGET_600, /**< R600 GPU ISA */
CAL_TARGET_610, /**< RV610 GPU ISA */
CAL_TARGET_630, /**< RV630 GPU ISA */
CAL_TARGET_670, /**< RV670 GPU ISA */
CAL_TARGET_7XX, /**< R700 class GPU ISA */
CAL_TARGET_770, /**< RV770 GPU ISA */
CAL_TARGET_710, /**< RV710 GPU ISA */
CAL_TARGET_730, /**< RV730 GPU ISA */
CAL_TARGET_CYPRESS, /**< CYPRESS GPU ISA */
CAL_TARGET_JUNIPER, /**< JUNIPER GPU ISA */
CAL_TARGET_REDWOOD, /**< REDWOOD GPU ISA */
CAL_TARGET_CEDAR, /**< CEDAR GPU ISA */
//##BEGIN_PRIVATE##
CAL_TARGET_SUMO, /**< SUMO GPU ISA */
CAL_TARGET_SUPERSUMO, /**< SUPERSUMO GPU ISA */
CAL_TARGET_WRESTLER, /**< WRESTLER GPU ISA */
CAL_TARGET_CAYMAN, /**< CAYMAN GPU ISA */
CAL_TARGET_KAUAI, /**< KAUAI GPU ISA */
CAL_TARGET_BARTS , /**< BARTS GPU ISA */
CAL_TARGET_TURKS , /**< TURKS GPU ISA */
CAL_TARGET_CAICOS, /**< CAICOS GPU ISA */
CAL_TARGET_TAHITI, /**< TAHITI GPU ISA*/
CAL_TARGET_PITCAIRN, /**< PITCAIRN GPU ISA*/
CAL_TARGET_CAPEVERDE, /**< CAPE VERDE GPU ISA*/
CAL_TARGET_DEVASTATOR, /**< DEVASTATOR GPU ISA*/
CAL_TARGET_SCRAPPER, /**< SCRAPPER GPU ISA*/
CAL_TARGET_OLAND, /**< OLAND GPU ISA*/
CAL_TARGET_BONAIRE, /**< BONAIRE GPU ISA*/
CAL_TARGET_SPECTRE, /**< KAVERI1 GPU ISA*/
CAL_TARGET_SPOOKY, /**< KAVERI2 GPU ISA*/
CAL_TARGET_KALINDI, /**< KALINDI GPU ISA*/
CAL_TARGET_HAINAN, /**< HAINAN GPU ISA*/
CAL_TARGET_HAWAII, /**< HAWAII GPU ISA*/
CAL_TARGET_ICELAND, /**< ICELAND GPU ISA*/
CAL_TARGET_TONGA, /**< TONGA GPU ISA*/
CAL_TARGET_GODAVARI, /**< MULLINS GPU ISA*/
CAL_TARGET_BERMUDA, /**< BERMUDA GPU ISA*/
CAL_TARGET_FIJI, /**< FIJI GPU ISA*/
CAL_TARGET_CARRIZO, /**< CARRIZO GPU ISA*/
CAL_TARGET_LAST = CAL_TARGET_CARRIZO, /**< last */
//##END_PRIVATE##
} CALtarget;
/** CAL image container */
typedef struct CALimageRec* CALimage;
#define CAL_ASIC_INFO_MAX_LEN 128
/** CAL computational domain */
typedef struct CALdomainRec {
CALuint x; /**< x origin of domain */
CALuint y; /**< y origin of domain */
CALuint width; /**< width of domain */
CALuint height; /**< height of domain */
} CALdomain;
/** CAL device attributes */
typedef struct CALdeviceattribsRec {
CALuint struct_size; /**< Client filled out size of CALdeviceattribs struct */
CALtarget target; /**< Asic identifier */
CALuint localRAM; /**< Amount of local GPU RAM in megabytes */
CALuint uncachedRemoteRAM; /**< Amount of uncached remote GPU memory in megabytes */
CALuint cachedRemoteRAM; /**< Amount of cached remote GPU memory in megabytes */
CALuint engineClock; /**< GPU device clock rate in megahertz */
CALuint memoryClock; /**< GPU memory clock rate in megahertz */
CALuint wavefrontSize; /**< Wavefront size */
CALuint numberOfSIMD; /**< Number of SIMDs */
bool doublePrecision; /**< double precision supported */
bool localDataShare; /**< local data share supported */
bool globalDataShare; /**< global data share supported */
bool globalGPR; /**< global GPR supported */
bool computeShader; /**< compute shader supported */
bool memExport; /**< memexport supported */
CALuint pitch_alignment; /**< Required alignment for calCreateRes allocations (in data elements) */
CALuint surface_alignment; /**< Required start address alignment for calCreateRes allocations (in bytes) */
CALuint numberOfUAVs; /**< Number of UAVs */
bool bUAVMemExport; /**< Hw only supports mem export to simulate 1 UAV */
CALuint numberOfShaderEngines; /**< Number of shader engines */
CALuint targetRevision; /**< Asic family revision */
CALuint totalVisibleHeap; /**< Amount of visible local GPU RAM in megabytes */
CALuint totalInvisibleHeap; /**< Amount of invisible local GPU RAM in megabytes */
CALuint totalDirectHeap; /**< Amount of direct GPU memory in megabytes */
CALuint totalCoherentHeap; /**< Amount of coherent GPU memory in megabytes */
CALuint totalRemoteSharedHeap; /**< Amount of remote Shared GPU memory in megabytes */
CALuint totalCachedRemoteSharedHeap; /**< Amount of cached remote Shared GPU memory in megabytes */
CALuint totalSDIHeap; /**< Amount of SDI memory allocated in CCC */
CALuint pciTopologyInformation; /**< PCI topology information contains: bus, device and function number. */
CALchar boardName[CAL_ASIC_INFO_MAX_LEN]; /**< Actual ASIC board name and not the internal name. */
bool vectorBufferInstructionAddr64; /**< Vector buffer instructions support ADDR64 mode */
bool memRandomAccessTargetInstructions; /**< hw/sc supports memory RAT (Random Access Target) instructions e.g. mem0.x_z_ supported */
CALuint memBusWidth; /**< Memory busw width */
CALuint numMemBanks; /**< Number of memory banks */
CALuint counterFreq; /**< Ref clock counter frequency */
double nanoSecondsPerTick; /**< Nano seconds per GPU tick */
bool longIdleDetect; /**< Whether LongIdleDetect enabled */
bool priSupport; /**< IOMMUv2 ATS/PRI support */
CALuint64 vaStart; /**< VA start address */
CALuint64 vaEnd; /**< VA end address */
bool isWorkstation; /**< Whether Device is a Workstation/Server part */
} CALdeviceattribs;
/** CAL device status */
typedef struct CALdevicestatusRec {
CALuint struct_size; /**< Client filled out size of CALdevicestatus struct */
CALuint availLocalRAM; /**< Amount of available local GPU RAM in megabytes */
CALuint availUncachedRemoteRAM; /**< Amount of available uncached remote GPU memory in megabytes */
CALuint availCachedRemoteRAM; /**< Amount of available cached remote GPU memory in megabytes */
CALuint availVisibleHeap; /**< Amount of available visible local GPU RAM in megabytes */
CALuint availInvisibleHeap; /**< Amount of available invisible local GPU RAM in megabytes */
CALuint availDirectHeap; /**< Amount of available direct GPU memory in megabytes */
CALuint availCoherentHeap; /**< Amount of available coherent GPU memory in megabytes */
CALuint availRemoteSharedHeap; /**< Amount of available remote Shared GPU memory in megabytes */
CALuint availCachedRemoteSharedHeap; /**< Amount of available cached remote Shared GPU memory in megabytes */
CALuint largestBlockVisibleHeap; /**< Largest block available visible local GPU RAM in megabytes */
CALuint largestBlockInvisibleHeap; /**< Largest block available invisible local GPU RAM in megabytes */
CALuint largestBlockRemoteHeap; /**< Largest block available remote GPU memory in megabytes */
CALuint largestBlockCachedRemoteHeap; /**< Largest block available cached remote GPU memory in megabytes */
CALuint largestBlockDirectHeap; /**< Largest block available direct GPU memory in megabytes */
CALuint largestBlockCoherentHeap; /**< Largest block available coherent GPU memory in megabytes */
CALuint largestBlockRemoteSharedHeap; /**< Largest block available remote Shared GPU memory in megabytes */
CALuint largestBlockCachedRemoteSharedHeap; /**< Largest block available cached remote Shared GPU memory in megabytes */
} CALdevicestatus;
/** CAL resource allocation flags **/
typedef enum CALresallocflagsEnum {
CAL_RESALLOC_GLOBAL_BUFFER = 1, /**< used for global import/export buffer */
} CALresallocflags;
/** CAL function information **/
typedef struct CALfuncInfoRec
{
CALuint maxScratchRegsNeeded; /**< Maximum number of scratch regs needed */
CALuint numSharedGPRUser; /**< Number of shared GPRs */
CALuint numSharedGPRTotal; /**< Number of shared GPRs including ones used by SC */
bool eCsSetupMode; /**< Slow mode */
CALuint numThreadPerGroup; /**< Flattend umber of threads per group */
CALuint numThreadPerGroupX; /**< x dimension of numThreadPerGroup */
CALuint numThreadPerGroupY; /**< y dimension of numThreadPerGroup */
CALuint numThreadPerGroupZ; /**< z dimension of numThreadPerGroup */
CALuint totalNumThreadGroup; /**< Total number of thread groups */
CALuint numWavefrontPerSIMD; /**< Number of wavefronts per SIMD */
bool isMaxNumWavePerSIMD; /**< Is this the max num active wavefronts per SIMD */
bool setBufferForNumGroup; /**< Need to set up buffer for info on number of thread groups? */
CALuint wavefrontSize; /**< number of threads per wavefront. */
CALuint numGPRsAvailable; /**< number of GPRs available to the program */
CALuint numGPRsUsed; /**< number of GPRs used by the program */
CALuint LDSSizeAvailable; /**< LDS size available to the program */
CALuint LDSSizeUsed; /**< LDS size used by the program */
CALuint stackSizeAvailable; /**< stack size availabe to the program */
CALuint stackSizeUsed; /**< stack size use by the program */
CALuint numSGPRsAvailable; /**< number of SGPRs available to the program */
CALuint numSGPRsUsed; /**< number of SGPRs used by the program */
CALuint numVGPRsAvailable; /**< number of VGPRs available to the program */
CALuint numVGPRsUsed; /**< number of VGPRs used by the program */
} CALfuncInfo;
#ifdef __cplusplus
} /* extern "C" { */
#endif
#endif /* __CAL_H__ */
@@ -0,0 +1,660 @@
/**
* @file calcl.h
* @brief CAL Compiler Interface Header
* @version 1.00.0 Beta
*/
/* ============================================================
Copyright (c) 2007 Advanced Micro Devices, Inc. All rights reserved.
Redistribution and use of this material is permitted under the following
conditions:
Redistributions must retain the above copyright notice and all terms of this
license.
In no event shall anyone redistributing or accessing or using this material
commence or participate in any arbitration or legal action relating to this
material against Advanced Micro Devices, Inc. or any copyright holders or
contributors. The foregoing shall survive any expiration or termination of
this license or any agreement or access or use related to this material.
ANY BREACH OF ANY TERM OF THIS LICENSE SHALL RESULT IN THE IMMEDIATE REVOCATION
OF ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE THIS MATERIAL.
THIS MATERIAL IS PROVIDED BY ADVANCED MICRO DEVICES, INC. AND ANY COPYRIGHT
HOLDERS AND CONTRIBUTORS "AS IS" IN ITS CURRENT CONDITION AND WITHOUT ANY
REPRESENTATIONS, GUARANTEE, OR WARRANTY OF ANY KIND OR IN ANY WAY RELATED TO
SUPPORT, INDEMNITY, ERROR FREE OR UNINTERRUPTED OPERATION, OR THAT IT IS FREE
FROM DEFECTS OR VIRUSES. ALL OBLIGATIONS ARE HEREBY DISCLAIMED - WHETHER
EXPRESS, IMPLIED, OR STATUTORY - INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
ACCURACY, COMPLETENESS, OPERABILITY, QUALITY OF SERVICE, OR NON-INFRINGEMENT.
IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, REVENUE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED OR BASED ON ANY THEORY OF LIABILITY
ARISING IN ANY WAY RELATED TO THIS MATERIAL, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE. THE ENTIRE AND AGGREGATE LIABILITY OF ADVANCED MICRO DEVICES,
INC. AND ANY COPYRIGHT HOLDERS AND CONTRIBUTORS SHALL NOT EXCEED TEN DOLLARS
(US $10.00). ANYONE REDISTRIBUTING OR ACCESSING OR USING THIS MATERIAL ACCEPTS
THIS ALLOCATION OF RISK AND AGREES TO RELEASE ADVANCED MICRO DEVICES, INC. AND
ANY COPYRIGHT HOLDERS AND CONTRIBUTORS FROM ANY AND ALL LIABILITIES,
OBLIGATIONS, CLAIMS, OR DEMANDS IN EXCESS OF TEN DOLLARS (US $10.00). THE
FOREGOING ARE ESSENTIAL TERMS OF THIS LICENSE AND, IF ANY OF THESE TERMS ARE
CONSTRUED AS UNENFORCEABLE, FAIL IN ESSENTIAL PURPOSE, OR BECOME VOID OR
DETRIMENTAL TO ADVANCED MICRO DEVICES, INC. OR ANY COPYRIGHT HOLDERS OR
CONTRIBUTORS FOR ANY REASON, THEN ALL RIGHTS TO REDISTRIBUTE, ACCESS OR USE
THIS MATERIAL SHALL TERMINATE IMMEDIATELY. MOREOVER, THE FOREGOING SHALL
SURVIVE ANY EXPIRATION OR TERMINATION OF THIS LICENSE OR ANY AGREEMENT OR
ACCESS OR USE RELATED TO THIS MATERIAL.
NOTICE IS HEREBY PROVIDED, AND BY REDISTRIBUTING OR ACCESSING OR USING THIS
MATERIAL SUCH NOTICE IS ACKNOWLEDGED, THAT THIS MATERIAL MAY BE SUBJECT TO
RESTRICTIONS UNDER THE LAWS AND REGULATIONS OF THE UNITED STATES OR OTHER
COUNTRIES, WHICH INCLUDE BUT ARE NOT LIMITED TO, U.S. EXPORT CONTROL LAWS SUCH
AS THE EXPORT ADMINISTRATION REGULATIONS AND NATIONAL SECURITY CONTROLS AS
DEFINED THEREUNDER, AS WELL AS STATE DEPARTMENT CONTROLS UNDER THE U.S.
MUNITIONS LIST. THIS MATERIAL MAY NOT BE USED, RELEASED, TRANSFERRED, IMPORTED,
EXPORTED AND/OR RE-EXPORTED IN ANY MANNER PROHIBITED UNDER ANY APPLICABLE LAWS,
INCLUDING U.S. EXPORT CONTROL LAWS REGARDING SPECIFICALLY DESIGNATED PERSONS,
COUNTRIES AND NATIONALS OF COUNTRIES SUBJECT TO NATIONAL SECURITY CONTROLS.
MOREOVER, THE FOREGOING SHALL SURVIVE ANY EXPIRATION OR TERMINATION OF ANY
LICENSE OR AGREEMENT OR ACCESS OR USE RELATED TO THIS MATERIAL.
NOTICE REGARDING THE U.S. GOVERNMENT AND DOD AGENCIES: This material is
provided with "RESTRICTED RIGHTS" and/or "LIMITED RIGHTS" as applicable to
computer software and technical data, respectively. Use, duplication,
distribution or disclosure by the U.S. Government and/or DOD agencies is
subject to the full extent of restrictions in all applicable regulations,
including those found at FAR52.227 and DFARS252.227 et seq. and any successor
regulations thereof. Use of this material by the U.S. Government and/or DOD
agencies is acknowledgment of the proprietary rights of any copyright holders
and contributors, including those of Advanced Micro Devices, Inc., as well as
the provisions of FAR52.227-14 through 23 regarding privately developed and/or
commercial computer software.
This license forms the entire agreement regarding the subject matter hereof and
supersedes all proposals and prior discussions and writings between the parties
with respect thereto. This license does not affect any ownership, rights, title,
or interest in, or relating to, this material. No terms of this license can be
modified or waived, and no breach of this license can be excused, unless done
so in a writing signed by all affected parties. Each term of this license is
separately enforceable. If any term of this license is determined to be or
becomes unenforceable or illegal, such term shall be reformed to the minimum
extent necessary in order for this license to remain in effect in accordance
with its terms as modified by such reformation. This license shall be governed
by and construed in accordance with the laws of the State of Texas without
regard to rules on conflicts of law of any state or jurisdiction or the United
Nations Convention on the International Sale of Goods. All disputes arising out
of this license shall be subject to the jurisdiction of the federal and state
courts in Austin, Texas, and all defenses are hereby waived concerning personal
jurisdiction and venue of these courts.
============================================================ */
#ifndef __CALCL_H__
#define __CALCL_H__
#include "cal.h"
#include "gsl_enum.h"
#include "gsl_types.h"
#include "cm_enum.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ProgramGridRec
{
gslDomain3D gridBlock; /**< size of a block of data */
gslDomain3D gridSize; /**< size of 'blocks' to execute. */
gslDomain3D partialGridBlock;/** Partial grid block */
CALuint localSize; /** size of OpenCL Local Memory in bytes */
} ProgramGrid;
// flags for calCtxWaitForEvents
typedef enum CALwaitTypeEnum
{
CAL_WAIT_POLLING = 0,
CAL_WAIT_LOW_CPU_UTILIZATION = 1,
} CALwaitType;
//
// calResAllocView typedefs
//
typedef enum CALresallocviewflagsRec {
CAL_RESALLOCVIEW_GLOBAL_BUFFER = CAL_RESALLOC_GLOBAL_BUFFER, /**< used for global import/export buffer */
CAL_RESALLOCVIEW_LINEAR_ALIGNED = CAL_RESALLOC_GLOBAL_BUFFER, /**< 256 byte alignment restriction. */
CAL_RESALLOCVIEW_LINEAR_UNALIGNED = 3, /**< no alignment restrictions */
} CALresallocviewflags;
typedef struct CALresourceDescRec {
gslMemObjectAttribLocation type;
gslResource3D size;
cmSurfFmt format;
gslChannelOrder channelOrder;
gslMemObjectAttribType dimension;
CALuint mipLevels;
CALvoid* systemMemory;
CALuint flags;
CALuint systemMemorySize;
CALuint64 busAddress[2];
mcaddr vaBase;
gslMemObjectAttribSection section;
} CALresourceDesc;
typedef enum CALresallocsliceviewflagsRec {
CAL_RESALLOCSLICEVIEW_GLOBAL_BUFFER = CAL_RESALLOC_GLOBAL_BUFFER, /**< used for global import/export buffer */
CAL_RESALLOCSLICEVIEW_LINEAR_ALIGNED = CAL_RESALLOC_GLOBAL_BUFFER, /**< 256 byte alignment restriction. */
CAL_RESALLOCSLICEVIEW_LINEAR_UNALIGNED = CAL_RESALLOCVIEW_LINEAR_UNALIGNED, /**< no alignment restrictions */
CAL_RESALLOCSLICEVIEW_LEVEL = 0x10, /**< sliceDesc.layer is not used, the whole level is only*/
CAL_RESALLOCSLICEVIEW_LAYER = 0x20, /**< sliceDesc.layer is not used, the whole level is only*/
CAL_RESALLOCSLICEVIEW_LEVEL_AND_LAYER = CAL_RESALLOCSLICEVIEW_LEVEL | CAL_RESALLOCSLICEVIEW_LAYER,
} CALresallocsliceviewflags;
//
// Thread Trace Extension
//
typedef struct CALthreadTraceConfigRec CALthreadTraceConfig;
//
// Video Extension
//
typedef struct CALvideoPropertiesRec CALvideoProperties;
typedef struct CALprogramVideoRec CALprogramVideo;
typedef struct CALdeviceVideoAttribsRec CALdeviceVideoAttribs;
typedef struct CALcontextPropertiesRec CALcontextProperties;
typedef struct CALprogramVideoDecodeRec CALprogramVideoDecode;
typedef struct CALprogramVideoEncodeRec CALprogramVideoEncode;
typedef struct CALvideoAttribRec CALvideoAttrib;
typedef struct CALvideoEncAttribRec CALvideoEncAttrib;
// VCE
typedef struct CALEncodeCreateVCERec CALEncodeCreateVCE;
typedef struct CALEncodeGetDeviceInfoRec CALEncodeGetDeviceInfo;
typedef struct CALEncodeGetNumberOfModesRec CALEncodeGetNumberOfModes;
typedef struct CALEncodeGetModesRec CALEncodeGetModes;
typedef struct CALEncodeGetDeviceCAPRec CALEncodeGetDeviceCAP;
typedef struct CALEncodeSetStateRec CALEncodeSetState;
typedef struct CALEncodeGetPictureControlConfigRec CALEncodeGetPictureControlConfig;
typedef struct CALEncodeGetRateControlConfigRec CALEncodeGetRateControlConfig;
typedef struct CALEncodeGetMotionEstimationConfigRec CALEncodeGetMotionEstimationConfig;
typedef struct CALEncodeGetRDOControlConfigRec CALEncodeGetRDOControlConfig;
typedef enum
{
CAL_VID_NV12_INTERLEAVED = 1,// NV12
CAL_VID_YV12_INTERLEAVED, // YV12
} CALdecodeFormat;
typedef enum
{
CAL_VID_H264_BASELINE = 1, // H.264 bitstream acceleration baseline profile
CAL_VID_H264_MAIN, // H.264 bitstream acceleration main profile
CAL_VID_H264_HIGH, // H.264 bitstream acceleration high profile
CAL_VID_VC1_SIMPLE, // VC-1 bitstream acceleration simple profile
CAL_VID_VC1_MAIN, // VC-1 bitstream acceleration main profile
CAL_VID_VC1_ADVANCED, // VC-1 bitstream acceleration advanced profile
CAL_VID_MPEG2_VLD, // MPEG2 bitstream acceleration VLD profile
} CALdecodeProfile;
typedef enum
{
CAL_VID_ENC_H264_BASELINE = 1, // H.264 bitstream acceleration baseline profile
CAL_VID_ENC_H264_MAIN, // H.264 bitstream acceleration main profile
CAL_VID_ENC_H264_HIGH, // H.264 bitstream acceleration high profile
} CALencodeProfile;
typedef enum
{
CAL_CONTEXT_VIDEO = 1,
CAL_CONTEXT_3DCOMPUTE = 2,
CAL_CONTEXT_COMPUTE0 = 3,
CAL_CONTEXT_COMPUTE1 = 4,
CAL_CONTEXT_DRMDMA0 = 5,
CAL_CONTEXT_DRMDMA1 = 6,
CAL_CONTEXT_VIDEO_VCE,
CALcontextEnum_FIRST = CAL_CONTEXT_VIDEO,
CALcontextEnum_LAST = CAL_CONTEXT_VIDEO_VCE,
} CALcontextEnum;
typedef enum
{
CAL_PRIORITY_NEUTRAL = 0,
CAL_PRIORITY_HIGH = 1,
CAL_PRIORITY_LOW = 2
} CALpriorityEnum;
typedef enum
{
CAL_VIDEO_DECODE = 1,
CAL_VIDEO_ENCODE = 2
} CALvideoType;
struct CALcontextPropertiesRec
{
CALcontextEnum name;
CALpriorityEnum priority;
CALvoid* data;
};
struct CALthreadTraceConfigRec
{
CALuint cu; // target compute unit [cu]
CALuint sh; // target shader array [sh],that contains target cu
CALuint simd_mask; // bitmask to enable or disable target tokens for different SIMDs
CALuint vm_id_mask; // virtual memory [vm] IDs to capture
CALuint token_mask; // bitmask indicating which trace token IDs will be included in the trace
CALuint reg_mask; // bitmask indicating which register types should be included in the trace
CALuint inst_mask; // types of instruction scheduling updates which should be recorded
CALuint random_seed; // linear feedback shift register [LFSR] seed
CALuint user_data; // user data ,which is written as payload
CALuint capture_mode; // indicator for the way how THREAD_TRACE_START / STOP events affect token collection
CALboolean is_user_data; // indicator if user_data is set
CALboolean is_wrapped; // indicator if the memory buffer should be wrapped around instead of stopping at the end
};
struct CALvideoPropertiesRec
{
CALuint size;
CALuint flags;
CALdecodeProfile profile;
CALdecodeFormat format;
CALuint width;
CALuint height;
CALcontextEnum VideoEngine_name;
};
struct CALprogramVideoRec
{
CALuint size;
CALvideoType type;
CALuint flags;
};
struct CALprogramVideoDecodeRec
{
CALprogramVideo videoType;
void* picture_parameter_1;
void* picture_parameter_2;
CALuint picture_parameter_2_size;
void* bitstream_data;
CALuint bitstream_data_size;
void* slice_data_control;
CALuint slice_data_size;
};
struct CALprogramVideoEncodeRec
{
CALprogramVideo videoType;
CALuint pictureParam1Size;
CALuint pictureParam2Size;
void* pictureParam1;
void* pictureParam2;
CALuint uiTaskID;
};
struct CALvideoAttribRec
{
CALdecodeProfile decodeProfile;
CALdecodeFormat decodeFormat;
};
struct CALvideoEncAttribRec
{
CALencodeProfile encodeProfile;
CALdecodeFormat encodeFormat; // decode format is the same as the encode format
};
struct CALdeviceVideoAttribsRec
{
CALuint data_size; // in - size of the struct,
// out - bytes of data incl. pointed to
CALuint max_decode_sessions;
const CALvideoAttrib* video_attribs; // list of supported
// profile/format pairs
const CALvideoEncAttrib* video_enc_attribs;
};
////// VCE
struct CALEncodeCreateVCERec
{
CALvoid* VCEsession;
};
struct CALEncodeGetDeviceInfoRec
{
unsigned int device_id;
unsigned int max_encode_stream;
unsigned int encode_cap_list_size;
};
struct CALEncodeGetNumberOfModesRec
{
unsigned int num_of_encode_Mode;
};
typedef enum
{
CAL_VID_encode_MODE_NONE = 0,
CAL_VID_encode_AVC_FULL = 1,
CAL_VID_encode_AVC_ENTROPY = 2,
} CALencodeMode;
struct CALEncodeGetModesRec
{
CALuint NumEncodeModesToRetrieve;
CALencodeMode *pEncodeModes;
};
typedef enum
{
CAL_VID_ENCODE_JOB_PRIORITY_NONE = 0,
CAL_VID_ENCODE_JOB_PRIORITY_LEVEL1 = 1, // Always in normal queue
CAL_VID_ENCODE_JOB_PRIORITY_LEVEL2 = 2 // possibly in low-latency queue
} CAL_VID_ENCODE_JOB_PRIORITY;
typedef struct _CAL_VID_PROFILE_LEVEL
{
CALuint profile; //based on H.264 standard
CALuint level;
} CAL_VID_PROFILE_LEVEL;
typedef enum
{
CAL_VID_PICTURE_NONOE = 0,
CAL_VID_PICTURE_NV12 = 1,
} CAL_VID_PICTURE_FORMAT;
#define CAL_VID_MAX_NUM_PICTURE_FORMATS_H264_AVC 10
#define CAL_VID_MAX_NUM_PROFILE_LEVELS_H264_AVC 20
typedef struct
{
CALuint maxPicSizeInMBs; // Max picture size in MBs
CALuint minPicSizeInMBs; // Min picture size in MBs
CALuint numPictureFormats; // number of supported picture formats
CAL_VID_PICTURE_FORMAT supportedPictureFormats[CAL_VID_MAX_NUM_PICTURE_FORMATS_H264_AVC];
CALuint numProfileLevels; // number of supported profiles/levels returne;
CAL_VID_PROFILE_LEVEL supportedProfileLevel[CAL_VID_MAX_NUM_PROFILE_LEVELS_H264_AVC];
CALuint maxBitRate; // Max bit rate
CALuint minBitRate; // min bit rate
CAL_VID_ENCODE_JOB_PRIORITY supportedJobPriority;// supported max level of job priority
}CAL_VID_ENCODE_CAPS_FULL;
typedef struct
{
CAL_VID_ENCODE_JOB_PRIORITY supportedJobPriority;// supported max level of job priority
CALuint maxJobQueueDepth; // Max job queue depth
}CAL_VID_ENCODE_CAPS_ENTROPY;
typedef struct
{
CALencodeMode EncodeModes;
CALuint encode_cap_size;
union
{
CAL_VID_ENCODE_CAPS_FULL *encode_cap_full;
CAL_VID_ENCODE_CAPS_ENTROPY *encode_cap_entropy;
void *encode_cap;
} caps;
} CAL_VID_ENCODE_CAPS;
struct CALEncodeGetDeviceCAPRec
{
CALuint num_of_encode_cap;
CAL_VID_ENCODE_CAPS *encode_caps;
};
typedef enum
{
CAL_VID__ENCODE_STATE_START = 1,
CAL_VID__ENCODE_STATE_PAUSE = 2,
CAL_VID__ENCODE_STATE_RESUME = 3,
CAL_VID__ENCODE_STATE_STOP = 4
} CAL_VID_ENCODE_STATE ;
typedef struct
{
CALuint size; // structure size
CALuint useConstrainedIntraPred; // binary var - force the use of constrained intra prediction when set to 1
//CABAC options
CALuint cabacEnable; // Enable CABAC entropy coding
CALuint cabacIDC; // cabac_init_id = 0; cabac_init_id = 1; cabac_init_id = 2;
CALuint loopFilterDisable; // binary var - disable loop filter when 1 - enable loop filter when 0 (0 and 1 are the only two supported cases)
int encLFBetaOffset; // -- move with loop control flag , Loop filter control, slice_beta_offset (N.B. only used if deblocking filter is not disabled, and there is no div2 as defined in the h264 bitstream syntax)
int encLFAlphaC0Offset; // Loop filter control, slice_alpha_c0_offset (N.B. only used if deblocking filter is not disabled, and there is no div2 as defined in the h264 bitstream syntax)
CALuint encIDRPeriod;
CALuint encIPicPeriod; // spacing for I pictures, in case driver doesnt force/select a picture type, this will be used for inference
int encHeaderInsertionSpacing; // spacing for inserting SPS/PPS. Example usage cases are: 0 for inserting at the beginning of the stream only, 1 for every picture, "GOP size" to align it with GOP boundaries etc. For compliance reasons, these headers might be inserted when SPS/PPS parameters change from the config packages.
CALuint encCropLeftOffset;
CALuint encCropRightOffset;
CALuint encCropTopOffset;
CALuint encCropBottomOffset;
CALuint encNumMBsPerSlice; // replaces encSliceArgument - Slice control - number of MBs per slice
CALuint encNumSlicesPerFrame; // Slice control - number of slices in this frame, pre-calculated to avoid DIV operation in firmware
CALuint encForceIntraRefresh; // 1 serves to load intra refresh bitmap from address force_intra_refresh_bitmap_mc_addr when equal to 1, 3 also loads dirty clean bitmap on top of the intra refresh
CALuint encForceIMBPeriod; // --- package with intra referesh -Intra MB spacing. if encForceIntraRefresh = 2, shifts intra refreshed MBs by frame number
CALuint encInsertVUIParam; // insert VUI params in SPS
CALuint encInsertSEIMsg; // insert SEI messages (bit 0 for buffering period; bit 1 for picture timing; bit 2 for pan scan)
} CAL_VID_ENCODE_PICTURE_CONTROL;
typedef struct
{
CALuint size; // structure size
CALuint encRateControlMethod; // rate control method to be used
CALuint encRateControlTargetBitRate; // target bit rate
CALuint encRateControlPeakBitRate; // peak bit rate
CALuint encRateControlFrameRateNumerator; // target frame rate
CALuint encGOPSize; // RC GOP size
CALuint encRCOptions; // packed bitfield definition for extending options here, bit 0: RC will not generate skipped frames in order to meet GOP target, bits 1-30: up for grabs by the RC alg designer
CALuint encQP_I; // I frame quantization only if rate control is disabled
CALuint encQP_P; // P frame quantization if rate control is disabled
CALuint encQP_B; // B frame quantization if rate control is disabled
CALuint encVBVBufferSize; // VBV buffer size - this is CPB Size, and the default is per Table A-1 of the spec
CALuint encRateControlFrameRateDenominator;// target frame rate
} CAL_VID_ENCODE_RATE_CONTROL;
// mode estimation control options
typedef struct
{
CALuint size; // structure size
CALuint imeDecimationSearch; // decimation search is on
CALuint motionEstHalfPixel; // enable half pel motion estimation
CALuint motionEstQuarterPixel; // enable quarter pel motion estimation
CALuint disableFavorPMVPoint; // disable favorization of PMV point
CALuint forceZeroPointCenter; // force [0,0] point as search window center in IME
CALuint lsmVert; // Luma Search window in MBs, set to either VCE_ENC_SEARCH_WIND_5x3 or VCE_ENC_SEARCH_WIND_9x5 or VCE_ENC_SEARCH_WIND_13x7
CALuint encSearchRangeX; // forward prediction - Manual limiting of horizontal motion vector range (for performance) in pel resolution
CALuint encSearchRangeY; // forward prediction - Manual limiting of vertical motion vector range (for performance)
CALuint encSearch1RangeX; // for 2nd ref - curr IME_SEARCH_SIZE doesn't have SIZE__SEARCH1_X bitfield
CALuint encSearch1RangeY; // for 2nd ref
CALuint disable16x16Frame1; // second reference (B frame) limitation
CALuint disableSATD; // Disable SATD cost calculation (SAD only)
CALuint enableAMD; // FME advanced mode decision
CALuint encDisableSubMode; // --- FME
CALuint encIMESkipX; // sub sample search window horz --- UENC_IME_OPTIONS.SKIP_POINT_X
CALuint encIMESkipY; // sub sample search window vert --- UENC_IME_OPTIONS.SKIP_POINT_Y
CALuint encEnImeOverwDisSubm; // Enable overwriting of fme_disable_submode in IME with enabled mode number equal to ime_overw_dis_subm_no (only 8x8 and above could be enabled)
CALuint encImeOverwDisSubmNo; // Numbers of mode IME will pick if en_ime_overw_dis_subm equal to 1.
CALuint encIME2SearchRangeX; // IME Additional Search Window Size: horizontal 1-4 (+- this value left and right from center)
CALuint encIME2SearchRangeY; // IME Additional Search Window Size: vertical not-limited (+- this value up and down from center)
// (+- this value up and down from center)
} CAL_VID_ENCODE_MOTION_ESTIMATION_CONTROL; // structure aligned to 88 bytes
typedef struct
{
CALuint size; // structure size
CALuint encDisableTbePredIFrame; // Disable Prediction Modes For I-Frames
CALuint encDisableTbePredPFrame; // same as above for P frames
CALuint useFmeInterpolY; // zero_residues_luma
CALuint useFmeInterpolUV; // zero_residues_chroma
CALuint enc16x16CostAdj; // --- UENC_FME_MD.M16x16_COST_ADJ
CALuint encSkipCostAdj; // --- UENC_FME_MD.MSkip_COST_ADJ
unsigned char encForce16x16skip;
} CAL_VID_ENCODE_RDO_CONTROL;
struct CALEncodeSetStateRec
{
CAL_VID_ENCODE_STATE encode_states;
};
struct CALEncodeGetPictureControlConfigRec
{
CAL_VID_ENCODE_PICTURE_CONTROL encode_picture_control;
};
struct CALEncodeGetRateControlConfigRec
{
CAL_VID_ENCODE_RATE_CONTROL encode_rate;
};
struct CALEncodeGetMotionEstimationConfigRec
{
CAL_VID_ENCODE_MOTION_ESTIMATION_CONTROL encode_motion_estimation;
};
struct CALEncodeGetRDOControlConfigRec
{
CAL_VID_ENCODE_RDO_CONTROL encode_RDO;
};
typedef enum
{
CAL_VID_CONFIG_TYPE_NONE = 0,
CAL_VID_CONFIG_TYPE_PICTURECONTROL = 1,
CAL_VID_CONFIG_TYPE_RATECONTROL = 2,
CAL_VID_CONFIG_TYPE_MOTIONSESTIMATION = 3,
CAL_VID_CONFIG_TYPE_RDO = 4
} CAL_VID_CONFIG_TYPE;
typedef struct
{
CAL_VID_CONFIG_TYPE configType;
union
{
CAL_VID_ENCODE_PICTURE_CONTROL* pPictureControl;
CAL_VID_ENCODE_RATE_CONTROL* pRateControl;
CAL_VID_ENCODE_MOTION_ESTIMATION_CONTROL* pMotionEstimation;
CAL_VID_ENCODE_RDO_CONTROL* pRDO;
} config;
} CAL_VID_CONFIG;
typedef enum
{
CAL_VID_PICTURE_STRUCTURE_H264_NONE = 0,
CAL_VID_PICTURE_STRUCTURE_H264_FRAME = 1,
CAL_VID_PICTURE_STRUCTURE_H264_TOP_FIELD = 2,
CAL_VID_PICTURE_STRUCTURE_H264_BOTTOM_FIELD = 3
} CAL_VID_PICTURE_STRUCTURE_H264;
// Used to force picture type
typedef enum _CU_VID_PICTURE_TYPE_H264
{
CAL_VID_PICTURE_TYPE_H264_NONE = 0,
CAL_VID_PICTURE_TYPE_H264_SKIP = 1,
CAL_VID_PICTURE_TYPE_H264_IDR = 2,
CAL_VID_PICTURE_TYPE_H264_I = 3,
CAL_VID_PICTURE_TYPE_H264_P = 4
} CAL_VID_PICTURE_TYPE_H264;
typedef union _CAL_VID_ENCODE_PARAMETERS_H264_FLAGS
{
struct
{
// enable/disable features
unsigned int reserved : 32; // reserved fields must be set to zero
} flags;
unsigned int value;
}CAL_VID_ENCODE_PARAMETERS_H264_FLAGS;
typedef struct
{
CALuint size; // structure size. Must be always set to the size of AVE_ENCODE_PARAMETERS_H264.
CAL_VID_ENCODE_PARAMETERS_H264_FLAGS flags; // enable/disable any supported features
CALboolean insertSPS;
CAL_VID_PICTURE_STRUCTURE_H264 pictureStructure;
CALboolean forceRefreshMap;
CALuint forceIMBPeriod;
CAL_VID_PICTURE_TYPE_H264 forcePicType;
} CAL_VID_ENCODE_PARAMETERS_H264;
typedef enum
{
CAL_VID_BUFFER_TYPE_NONE = 0,
CAL_VID_BUFFER_TYPE_ENCODE_PARAM_H264 = 1,
CAL_VID_BUFFER_TYPE_PICTURE = 2,
CAL_VID_BUFFER_TYPE_SLICE_HEADER = 3,
CAL_VID_BUFFER_TYPE_SLICE = 4,
CAL_VID_BUFFER_TYPE_RECONSTRUCTED_PICTURE_OUTPUT = 5
} CAL_VID_BUFFER_TYPE;
#define CAL_VID_SURFACE_HANDLE void*
typedef struct
{
CAL_VID_BUFFER_TYPE bufferType;
union
{
CAL_VID_ENCODE_PARAMETERS_H264* pEncodeParamH264;
CAL_VID_SURFACE_HANDLE pPicture;
CAL_VID_SURFACE_HANDLE pSliceHeader;
CAL_VID_SURFACE_HANDLE pSlice;
CAL_VID_SURFACE_HANDLE pReconstructedPictureOutput;
} buffer;
} CAL_VID_BUFFER_DESCRIPTION;
typedef enum
{
CAL_VID_TASK_STATUS_NONE = 0,
CAL_VID_TASK_STATUS_COMPLETE = 1, // encoding task has finished successfully.
CAL_VID_TASK_STATUS_FAILED = 2 // encoding task has finished but failed.
} CAL_VID_TASK_STATUS;
typedef struct
{
CALuint size; // structure size
CALuint taskID; // task ID
CAL_VID_TASK_STATUS status; // Task status. May be duplicated if current task has multiple output blocks.
CALuint size_of_bitstream_data; // data size of the output block
void* bitstream_data; // read pointer the top portion of the generated bitstream data for the current task
} CAL_VID_OUTPUT_DESCRIPTION;
typedef enum CALmemcopyflagsEnum
{
CAL_MEMCOPY_DEFAULT = 0, /**< default CAL behavior of partial sync */
CAL_MEMCOPY_SYNC = 1, /**< used to synchronize with the specified CAL context */
CAL_MEMCOPY_ASYNC = 2, /**< used to indicate completely asynchronous behavior */
} CALmemcopyflags;
typedef enum CALResGLBufferTypeEnum{
CAL_RES_GL_BUFFER_TYPE_TEXTURE = 0,
CAL_RES_GL_BUFFER_TYPE_FRAMEBUFFER = 1,
CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER = 2,
CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER = 3
}CALResGLBufferType;
typedef struct CALDeviceGLParamsRec {
CALvoid *GLplatformContext;
CALvoid *GLdeviceContext;
CALuint flags;
} CALDeviceGLParams;
#ifdef __cplusplus
} /* extern "C" { */
#endif
#endif /* __CALCL_H__ */
@@ -0,0 +1,284 @@
/*****************************************************************************
*
*
*
* Trade secret of ATI Technologies, Inc.
* Copyright 2006, 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.
*
*
****************************************************************************
*/
#ifndef __CALIF_H__
#define __CALIF_H__
#define CALIF_VERSION_MAJOR 1
#define CALIF_VERSION_MINOR 1
#define CALIF_HELPER_SURF_WIDTH 256
#define CALIF_HELPER_SURF_HEIGHT 8
#define CALIF_SEMAPHORE_SURF_WIDTH 8
#define CALIF_SEMAPHORE_SURF_HEIGHT 1
// Structure for commuticating with driver through Lock backdoor
typedef struct _CALIF_LOCK_COMM_HEADER
{
UINT uCmd;
UINT *puRes;
PVOID pInputBuffer;
UINT uInputBufferSize;
PVOID pOutputBuffer;
UINT uOutputBufferSize;
} CALIF_LOCK_COMM_HEADER, *PCALIF_LOCK_COMM_HEADER;
// Commands for LOCK backdoor
typedef enum _CALIF_LOCK_CMD
{
CALIF_LOCK_CMD_GET_VERSION = 1,
CALIF_LOCK_CMD_NEXT_SURF_INFO = 2,
CALIF_LOCK_CMD_GET_SURF_INFO = 3,
CALIF_LOCK_CMD_SET_ALIAS_INFO = 4,
CALIF_LOCK_CMD_SET_CAL_TARGET = 5,
CALIF_LOCK_CMD_GET_CAL_STATUS = 6,
CALIF_LOCK_CMD_GET_RENDER_STATUS = 7,
CALIF_LOCK_CMD_INVALID = 0xFFFFFFFF,
} CALIF_LOCK_CMD;
typedef enum _CALIF_LOCK_CMD_RES
{
CALIF_LOCK_CMD_RES_OK = 0,
CALIF_LOCK_CMD_RES_ERROR = 1,
CALIF_LOCK_CMD_RES_INVALID = 0xFFFFFFFF,
} CALIF_LOCK_CMD_RES;
// Input structure
typedef struct _CALIF_CAL_TARGET
{
ULONG ulSize;
ULONG ulFlags;
ULONG ulNumTargets;
ULONG ulTargets[MAX_CAL_TARGETS];
ULONG ulReserved[1]; // 16 byte alignment
} CALIF_CAL_TARGET, *PCALIF_CAL_TARGET;
#define CALIF_DEV_CAP_CAPABLE 0x00000001
#define CALIF_DEV_CAP_ENABLE 0x00000002
#define CALIF_DEV_CAP_PRIMARY 0x80000000
typedef struct _CALIF_DEV_INFO
{
ULONG ulIndex;
ULONG ulCaps; // CALIF_DEV_CAP_XXX
ULONG ulFBSize;
LONGLONG llFBSharedSize;
UCHAR ucDevicePath[MAX_REGISTRY_PATH];
ULONG ulReserved[2];
} CALIF_DEV_INFO, *PCALIF_DEV_INFO;
// Output structure
typedef struct _CALIF_CAL_STATUS
{
ULONG ulSize;
ULONG ulFlags;
ULONG ulCurrentIndex;
ULONG ulAdapterCount;
LONGLONG llSharedCacheableSize;
LONGLONG llSharedUSWCSize;
ULONG ulLinkCount;
ULONG ulLinkAdaper[MAX_CAL_TARGETS];
BOOL bP2PCap[MAX_CAL_DEVICE][MAX_CAL_DEVICE];
CALIF_DEV_INFO devInfo[MAX_CAL_DEVICE];
ULONG ulReserved[3];
} CALIF_CAL_STATUS, *PCALIF_CAL_STATUS;
// Output structure
typedef struct _CALIF_VERSION
{
ULONG ulSize;
ULONG ulFlags;
UINT uMajor; // Major version
UINT uMinor; // Minor version
} CALIF_VERSION, *PCALIF_VERSION;
// Surface heap choice
typedef enum _CALIF_SURF_HEAP
{
CALIF_SURF_HEAP_UNKNOWN = 0, // VCAM real mode or dummy surf
CALIF_SURF_HEAP_LOCAL = 1, // Local Visible + Local Invisible
CALIF_SURF_HEAP_LOCALIF_VISIBLE = 2,
CALIF_SURF_HEAP_USWC = 3,
CALIF_SURF_HEAP_CACHEABLE = 4,
CALIF_SURF_HEAP_SHARED_USWC = 5,
CALIF_SURF_HEAP_SHARED_CACHEABLE = 6,
CALIF_SURF_HEAP_INVALID = 0xFFFFFFFF,
} CALIF_SURF_HEAP;
// Surface flag
#define CALIF_NEXT_SURF_FLAG_DUMMY 0x80000000
#define CALIF_NEXT_SURF_FLAG_LINEAR 0x40000000
#define CALIF_NEXT_SURF_FLAG_ARENA 0x20000000
// Input structure
typedef struct _CALIF_NEXT_SURF_INFO
{
ULONG ulSize;
ULONG ulFlags;
// to match it later at surface creation time
UINT uWidth;
UINT uHeight;
D3DFORMAT d3dFormat;
ULONG_PTR lpProcessID;
// info
CALIF_SURF_HEAP uHeap;
UINT uFlags;
#if _WIN64
ULONG ulReserved[3];
#endif
} CALIF_NEXT_SURF_INFO, *PCALIF_NEXT_SURF_INFO;
// Output structure
typedef struct _CALIF_SURF_INFO
{
ULONG ulSize;
ULONG ulFlags;
ULONG ulDeviceIndex; // current device id
ULONG_PTR lpSurfHandle; // VCAM handle if VCAM is on
LARGE_INTEGER gpuDevAddr; // mc address of the surface
LONGLONG llHeapOffset; // offset from the beginning of the heap
UINT uMemSize; // total memory size
CALIF_SURF_HEAP uHeap; // memory pool
UINT uGranularity; // minimum RT aligment
UINT uBitsPerPixel; // bits per pixel
UINT uActualWidth; // padded width pixel pitch
UINT uActualHeight; // padded height pitch
UINT uPitch; // padded width byte pitch
UINT uTile; // Tiling of surface
UINT uTileSwizzle; // Tile swizzle of surface
#if !_WIN64
ULONG ulReserved[1];
#endif
} CALIF_SURF_INFO, *PCALIF_SURF_INFO;
// Input structure
typedef struct _CALIF_ALIAS_SURF_INFO
{
ULONG ulSize;
ULONG ulFlags;
ULONG ulDeviceIndex; // device id we want to alias to
ULONG_PTR lpSurfHandle;
LONGLONG llHeapOffset; // offset from the beginning of the heap
UINT uMemSize; // total memory size
CALIF_SURF_HEAP uHeap; // memory pool
UINT uGranularity; // minimum RT aligment
UINT uBitsPerPixel; // bits per pixel
UINT uActualWidth; // padded width pixel pitch
UINT uActualHeight; // padded height pitch
UINT uPitch; // padded width byte pitch
#if _WIN64
ULONG ulReserved[3];
#endif
} CALIF_ALIAS_SURF_INFO, *PCALIF_ALIAS_SURF_INFO;
// Output structure
typedef struct _CALIF_RENDER_STATUS
{
ULONG ulSize;
ULONG ulFlags;
BOOL bSurfBusy;
ULONG ulReserved[1];
} CALIF_RENDER_STATUS, *PCALIF_RENDER_STATUS;
// Commands for StretchBlt backdoor
typedef enum _CALIF_SBLT_CMD
{
CALIF_SBLT_CMD_SURF_MARK_HELPER = 0x2200,
CALIF_SBLT_CMD_SURF_GET_SURF_INFO = 0x2400,
CALIF_SBLT_CMD_SURF_ALIAS = 0x2600,
CALIF_SBLT_CMD_SEMAPHORE_WAIT = 0x4200,
CALIF_SBLT_CMD_SEMAPHORE_SIGNAL = 0x4400,
CALIF_SBLT_CMD_OUTPUT_CACHE_FLUSH = 0x4600,
CALIF_SBLT_CMD_INPUT_CACHE_INVALIDATE = 0x6200,
CALIF_SBLT_CMD_GET_RENDER_STATUS = 0x6400,
CALIF_SBLT_CMD_PIN_SURF = 0x6600,
CALIF_SBLT_CMD_INVALID = 0xFFFF,
} CALIF_SBLT_CMD;
#define CALIF_SBLT_CMD_RECT_MASK__LEFT 0x000F
#define CALIF_SBLT_CMD_RECT_MASK__TOP 0x00F0
#define CALIF_SBLT_CMD_RECT_MASK__RIGHT 0x0F00
#define CALIF_SBLT_CMD_RECT_MASK__BOTTOM 0xF000
#define CALIF_SBLT_CMD_RECT_SHIFT__LEFT 0
#define CALIF_SBLT_CMD_RECT_SHIFT__TOP 4
#define CALIF_SBLT_CMD_RECT_SHIFT__RIGHT 8
#define CALIF_SBLT_CMD_RECT_SHIFT__BOTTOM 12
#endif//__CALIF_H__
@@ -0,0 +1,99 @@
/*****************************************************************************
*
*
*
* Trade secret of ATI Technologies, Inc.
* Copyright 2000, 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.
*
*
****************************************************************************
*/
#ifndef __D3DSHADERDEFS_H__
#define __D3DSHADERDEFS_H__
#define D3DSI_OPCODE_PARAM (1 << 31)
#define D3DSI_GETCOMMENTSIZE(token) (((token) & D3DSI_COMMENTSIZE_MASK) >> \
D3DSI_COMMENTSIZE_SHIFT)
#define D3DSI_GETDSTSHIFT(token) (((token) & D3DSP_DSTSHIFT_MASK) >> D3DSP_DSTSHIFT_SHIFT)
// D3D uses 2 swizzle bits per component. Define them since they are not
// available in d3d header files.
#define D3DSP_SWIZZLE_BITS_PER_COMP 2
#define D3DSP_SWIZZLE_XYZW_MASK 0x3
// DST related: Parameter definition writemask shifts - missing from D3D header
#define D3DSP_WRITEMASK_SHIFT 16
#define D3DSP_WRITEMASK_ASHIFT 19
// DX9 Ref uses 7. But if only upto _X8 & _D8 are supported, the mask should be 3
#define D3DSP_D3D_DSTSHIFT_MASK 3
#define D3DSP_SHADER_TYPE_MASK 0xFFFF0000
#define D3DSP_PS_TYPE 0xFFFF0000
#define D3DSP_VS_TYPE 0xFFFE0000
// This is necessary to avoid a duplicate definition of these functions
// in C++ source files that use this header. These functions are already
// defined in d3dhal.h inside a "#ifdef __cplusplus" block.
#ifndef __cplusplus
// This gets regtype, and also maps D3DSPR_CONSTn to D3DSPR_CONST
// (for easier parsing)
ATI_INLINE DWORD D3DSI_GETREGTYPE_RESOLVING_CONSTANTS(DWORD token)
{
DWORD RegType = D3DSI_GETREGTYPE(token);
switch (RegType)
{
case D3DSPR_CONST4:
case D3DSPR_CONST3:
case D3DSPR_CONST2:
return D3DSPR_CONST;
default:
return RegType;
}
}
// The inline function below retrieves register number for an opcode,
// taking into account that: if the type is a
// D3DSPR_CONSTn, the register number needs to be remapped.
//
// D3DSPR_CONST is for c0-c2047
// D3DSPR_CONST2 is for c2048-c4095
// D3DSPR_CONST3 is for c4096-c6143
// D3DSPR_CONST4 is for c6144-c8191
//
// For example if the instruction token specifies type D3DSPR_CONST4, reg# 3,
// the register number retrieved is 6147.
// For other register types, the register number is just returned unchanged.
ATI_INLINE DWORD D3DSI_GETREGNUM_RESOLVING_CONSTANTS(DWORD token)
{
DWORD RegType = D3DSI_GETREGTYPE(token);
DWORD RegNum = D3DSI_GETREGNUM(token);
switch(RegType)
{
case D3DSPR_CONST4:
return RegNum + 6144;
case D3DSPR_CONST3:
return RegNum + 4096;
case D3DSPR_CONST2:
return RegNum + 2048;
default:
return RegNum;
}
}
#endif // __cplusplus
#define PSTR_MAX_NUMSRCPARAMS 6
#define PSTR_NUM_COMPONENTS_IN_REGISTER 4
#endif // __D3DSHADERDEFS_H__
@@ -0,0 +1,110 @@
//
// Workfile: fourcc.h
//
// Description: FourCC definitions
//
// Trade secret of ATI Technologies, Inc.
// Copyright 1999, 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.
//
//
#ifndef _FOURCC_H_
#define _FOURCC_H_
//#include "atidxinc.h"
#define FOURCC_YUY2 MAKEFOURCC('Y','U','Y','2')
#define FOURCC_UYVY MAKEFOURCC('U','Y','V','Y')
#define FOURCC_YV12 MAKEFOURCC('Y','V','1','2')
#define FOURCC_YUV12 FOURCC_YV12
#define FOURCC_YVU9 MAKEFOURCC('Y','V','U','9')
#define FOURCC_IF09 MAKEFOURCC('I','F','0','9')
#define FOURCC_IMC4 MAKEFOURCC('I','M','C','4')
#define FOURCC_IYUV MAKEFOURCC('I','Y','U','V')
#define FOURCC_NV11 MAKEFOURCC('N','V','1','1')
#define FOURCC_NV12 MAKEFOURCC('N','V','1','2')
#define FOURCC_NV21 MAKEFOURCC('N','V','2','1')
//Microsoft specific format for WebTV
#define FOURCC_VBID MAKEFOURCC('V','B','I','D')
#define FOURCC_MCAM MAKEFOURCC('M','C','A','M')
#define FOURCC_MC12 MAKEFOURCC('M','C','1','2')
#define FOURCC_MCR4 MAKEFOURCC('M','C','R','4')
#define FOURCC_M2IA MAKEFOURCC('M','2','I','A')
#define FOURCC_M2AM MAKEFOURCC('M','2','A','M')
#define FOURCC_M2R4 MAKEFOURCC('M','2','R','4')
#define FOURCC_AYUV MAKEFOURCC('A','Y','U','V')
#define FOURCC_AI44 MAKEFOURCC('A','I','4','4')
#define FOURCC_XENC MAKEFOURCC('X','E','N','C')
// OpenGL Surfaces
#define FOURCC_OGLZ MAKEFOURCC('O','G','L','Z')
#define FOURCC_OGNZ MAKEFOURCC('O','G','N','Z')
#define FOURCC_OGLS MAKEFOURCC('O','G','L','S')
#define FOURCC_OGNS MAKEFOURCC('O','G','N','S')
#define FOURCC_OGLT MAKEFOURCC('O','G','L','T')
#define FOURCC_OGNT MAKEFOURCC('O','G','N','T')
#define FOURCC_OGLB MAKEFOURCC('O','G','L','B')
#define FOURCC_DDES MAKEFOURCC('D','D','E','S')
#define FOURCC_PBSM MAKEFOURCC('P','B','S','M')
#define FOURCC_ATI1 MAKEFOURCC('A','T','I','1')
#define FOURCC_ATI2 MAKEFOURCC('A','T','I','2')
// Alias of ARGB-8888 for special MM app. to store security content
#define FOURCC_SORT MAKEFOURCC('S','O','R','T')
// Alias of YUY2 for special MM app. to store security content
#define FOURCC_SYV2 MAKEFOURCC('S','Y','V','2')
// Communication surface for special MM app. to enable security content playback
#define FOURCC_EAPI MAKEFOURCC('E','A','P','I')
// Communication surface
#define FOURCC_ATIC MAKEFOURCC('A','T','I','C')
// Fake format for exposing DX9c geometry instancing
#define FOURCC_INST MAKEFOURCC('I','N','S','T')
// Fake format for exposing R2VB support
// must match FOURCC_R2VB in d3d/atir2vb.h
#define FOURCC_R2VB MAKEFOURCC('R','2','V','B')
// Depth Stencil Texture formats.
#define FOURCC_DF16 MAKEFOURCC('D','F','1','6')
#define FOURCC_DF24 MAKEFOURCC('D','F','2','4')
// FP_11_11_10 format - used internally for optimization
#define FOURCC_FP11 MAKEFOURCC('F','P','1','1')
// Fetch4:
// GET4 is used both as fake format for exposing Fetch4 and as enable value.
// GET1 is used only as disable value.
#define FOURCC_GET4 MAKEFOURCC('G','E','T','4')
#define FOURCC_GET1 MAKEFOURCC('G','E','T','1')
// ATI Compute Abstraction Layer (CAL)
// U8X1 stands for unsigned 8 bits by 1 component
// S6X4 stands for signed 16 bits by 4 components
#define FOURCC_ATIP MAKEFOURCC('A','T','I','P')
#define FOURCC_U8X1 MAKEFOURCC('U','8','X','1')
#define FOURCC_S8X1 MAKEFOURCC('S','8','X','1')
#define FOURCC_U8X2 MAKEFOURCC('U','8','X','2')
#define FOURCC_S8X2 MAKEFOURCC('S','8','X','2')
#define FOURCC_S8X4 MAKEFOURCC('S','8','X','4')
#define FOURCC_U6X1 MAKEFOURCC('U','6','X','1')
#define FOURCC_S6X1 MAKEFOURCC('S','6','X','1')
#define FOURCC_S6X2 MAKEFOURCC('S','6','X','2')
#define FOURCC_S6X4 MAKEFOURCC('S','6','X','4')
// ATI semaphore, currently used by CAL
#define FOURCC_SEMA MAKEFOURCC('S','E','M','A')
#endif // _FOURCC_H_
@@ -0,0 +1,2 @@
Promotions directory contains functionality from other staging branches copied
(promoted) into the CAL tree.
@@ -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